# Buggy code
def fqscreen_simple_plot(self):
    """Makes a simple bar plot with summed alignment counts for
    each species, stacked."""

    # First, sum the different types of alignment counts
    data = OrderedDict()
    cats = OrderedDict()
    for s_name in self.fq_screen_data:
        data[s_name] = OrderedDict()
        sum_alignments = 0
        for org in self.fq_screen_data[s_name]:
            if org == "total_reads":
                continue
            data[s_name][org] = self.fq_screen_data[s_name][org]["counts"][
                "one_hit_one_library"
            ]
            try:
                data[s_name][org] += self.fq_screen_data[s_name][org]["counts"][
                    "multiple_hits_one_library"
                ]
            except KeyError:
                pass
            sum_alignments += data[s_name][org]
            if org not in cats and org != "No hits":
                cats[org] = {"name": org}

        # Calculate hits in multiple genomes
        data[s_name]["Multiple Genomes"] = (
            self.fq_screen_data[s_name]["total_reads"] - sum_alignments
        )

    pconfig = {
        "id": "fastq_screen",
        "title": "FastQ Screen",
        "cpswitch_c_active": False,
    }
    cats["Multiple Genomes"] = {"name": "Multiple Genomes", "color": "#820000"}
    cats["No hits"] = {"name": "No hits", "color": "#cccccc"}

    return bargraph.plot(data, cats, pconfig)


# Traceback (KeyError)
Module fastq_screen raised an exception: Traceback (most recent call last):
File "/home/es249628/bin/mypyenv-py3/bin/multiqc", line 364, in multiqc
output = mod()
File "/home/es249628/bin/mypyenv-py3/lib/python3.4/site-packages/multiqc/modules/fastq_screen/fastq_screen.py", line 55, in __init__
self.add_section( plot = self.fqscreen_simple_plot() )
File "/home/es249628/bin/mypyenv-py3/lib/python3.4/site-packages/multiqc/modules/fastq_screen/fastq_screen.py", line 213, in fqscreen_simple_plot
data[s_name][org] = self.fq_screen_data[s_name][org]['counts']['one_hit_one_library']
KeyError: 'counts'

# Fixed code
def fqscreen_simple_plot(self):
    """Makes a simple bar plot with summed alignment counts for
    each species, stacked."""

    # First, sum the different types of alignment counts
    data = OrderedDict()
    cats = OrderedDict()
    for s_name in self.fq_screen_data:
        data[s_name] = OrderedDict()
        sum_alignments = 0
        for org in self.fq_screen_data[s_name]:
            if org == "total_reads":
                continue
            try:
                data[s_name][org] = self.fq_screen_data[s_name][org]["counts"][
                    "one_hit_one_library"
                ]
            except KeyError:
                log.error(
                    "No counts found for '{}' ('{}'). Could be malformed or very old FastQ Screen results.".format(
                        org, s_name
                    )
                )
                continue
            try:
                data[s_name][org] += self.fq_screen_data[s_name][org]["counts"][
                    "multiple_hits_one_library"
                ]
            except KeyError:
                pass
            sum_alignments += data[s_name][org]
            if org not in cats and org != "No hits":
                cats[org] = {"name": org}

        # Calculate hits in multiple genomes
        if "total_reads" in self.fq_screen_data[s_name]:
            data[s_name]["Multiple Genomes"] = (
                self.fq_screen_data[s_name]["total_reads"] - sum_alignments
            )

    # Strip empty dicts
    data = [data[s_name] for s_name in data if len(data[s_name]) > 0]

    pconfig = {
        "id": "fastq_screen",
        "title": "FastQ Screen",
        "cpswitch_c_active": False,
    }
    cats["Multiple Genomes"] = {"name": "Multiple Genomes", "color": "#820000"}
    cats["No hits"] = {"name": "No hits", "color": "#cccccc"}

    return bargraph.plot(data, cats, pconfig)