# Buggy code
def quast_predicted_genes_barplot(self):
    """
    Make a bar plot showing the number and length of predicted genes
    for each assembly
    """

    # Prep the data
    # extract the ranges given to quast with "--gene-thresholds"
    prefix = "# predicted genes (>= "
    suffix = " bp)"
    all_thresholds = sorted(
        list(
            set(
                [
                    int(key[len(prefix) : -len(suffix)])
                    for _, d in self.quast_data.items()
                    for key in d.keys()
                    if key.startswith(prefix)
                ]
            )
        )
    )

    data = {}
    ourpat = ">= {}{} bp"
    theirpat = prefix + "{}" + suffix
    for s_name, d in self.quast_data.items():
        thresholds = sorted(
            list(
                set(
                    [
                        int(key[len(prefix) : -len(suffix)])
                        for _, x in self.quast_data.items()
                        for key in x.keys()
                        if key.startswith(prefix)
                    ]
                )
            )
        )
        if len(thresholds) < 2:
            continue

        p = dict()
        try:
            p = {ourpat.format(thresholds[-1], ""): d[theirpat.format(thresholds[-1])]}
            for low, high in zip(thresholds[:-1], thresholds[1:]):
                p[ourpat.format(low, -high)] = (
                    d[theirpat.format(low)] - d[theirpat.format(high)]
                )

            assert sum(p.values()) == d[theirpat.format(0)]
        except AssertionError:
            log.warning(
                'Predicted gene counts didn\'t add up properly for "{}"'.format(s_name)
            )
        except KeyError:
            log.warning(
                'Not all predicted gene thresholds available for "{}"'.format(s_name)
            )
        data[s_name] = p

    cats = [
        ourpat.format(low, -high if high else "")
        for low, high in zip(all_thresholds, all_thresholds[1:] + [None])
    ]

    if len(cats) > 0:
        return bargraph.plot(
            data,
            cats,
            {
                "id": "quast_predicted_genes",
                "title": "QUAST: Number of predicted genes",
                "ylab": "Number of predicted genes",
            },
        )
    else:
        return None


# Traceback (ValueError)
[INFO   ]         multiqc : This is MultiQC v1.7
[INFO   ]         multiqc : Template    : default
[INFO   ]         multiqc : Prepending directory to sample names
[INFO   ]         multiqc : Searching 'outputs'
[INFO   ]         multiqc : Only using modules quast
[INFO   ]           quast : Found 16 reports
[ERROR  ]         multiqc : Oops! The 'quast' MultiQC module broke...
Please copy the following traceback and report it at https://github.com/ewels/MultiQC/issues
If possible, please include a log file that triggers the error - the last file found was:
outputs/NRS6065/quast/report.tsv
============================================================
Module quast raised an exception: Traceback (most recent call last):
File "/homes/jabbott/NSW_assembly/.snakemake/conda/a820f7a0/bin/multiqc", line 440, in multiqc
output = mod()
File "/homes/jabbott/NSW_assembly/.snakemake/conda/a820f7a0/lib/python3.6/site-packages/multiqc/modules/quast/quast.py", line 75, in __init__
ng_pdata = self.quast_predicted_genes_barplot()
File "/homes/jabbott/NSW_assembly/.snakemake/conda/a820f7a0/lib/python3.6/site-packages/multiqc/modules/quast/quast.py", line 305, in quast_predicted_genes_barplot
for _, d in self.quast_data.items()
File "/homes/jabbott/NSW_assembly/.snakemake/conda/a820f7a0/lib/python3.6/site-packages/multiqc/modules/quast/quast.py", line 307, in <listcomp>
if key.startswith(prefix)
ValueError: invalid literal for int() with base 10: '0 bp)_par'
============================================================

# Fixed code
def quast_predicted_genes_barplot(self, partial=False):
    """
    Make a bar plot showing the number and length of predicted genes
    for each assembly
    """

    # Prep the data
    # extract the ranges given to quast with "--gene-thresholds"
    # keys look like:
    #   `# predicted genes (>= 300 bp)`
    #   `# predicted genes (>= 300 bp)_partial`
    pattern = re.compile(
        r"# predicted genes \(>= (\d+) bp\)" + ("_partial" if partial else "")
    )

    data = {}
    all_categories = []
    data_key = "# predicted genes (>= {} bp)" + ("_partial" if partial else "")
    for s_name, d in self.quast_data.items():
        thresholds = []
        for k in d.keys():
            m = re.match(pattern, k)
            if m:
                thresholds.append(int(m.groups()[0]))
        thresholds = sorted(list(set(thresholds)))
        if len(thresholds) < 2:
            continue

        highest_threshold = thresholds[-1]
        highest_cat = (
            highest_threshold,
            ">= {} bp".format(highest_threshold),
        )  # tuple (key-for-sorting, label)
        all_categories.append(highest_cat)
        plot_data = {highest_cat[1]: d[data_key.format(highest_threshold)]}

        # converting >=T1, >=T2,.. into 0-T1, T1-T2,..
        for low, high in zip(thresholds[:-1], thresholds[1:]):
            cat = (low, "{}-{} bp".format(low, high))
            all_categories.append(cat)
            plot_data[cat[1]] = d[data_key.format(low)] - d[data_key.format(high)]

        try:
            assert sum(plot_data.values()) == d[data_key.format(0)]
        except AssertionError:
            raise UserWarning(
                'Predicted gene counts didn\'t add up properly for "{}"'.format(s_name)
            )

        data[s_name] = plot_data

    all_categories = [label for k, label in sorted(list(set(all_categories)))]

    if len(all_categories) > 0:
        return bargraph.plot(
            data,
            all_categories,
            {
                "id": "quast_" + ("partially_" if partial else "") + "predicted_genes",
                "title": "QUAST: Number of "
                + ("partially " if partial else "")
                + "predicted genes",
                "ylab": "Number of "
                + ("partially " if partial else "")
                + "predicted genes",
            },
        )
    else:
        return None