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

    # Prep the data
    data = dict()
    categories = []
    for s_name, d in self.quast_data.items():
        nums_by_t = dict()
        for k, v in d.items():
            m = re.match("# contigs \(>= (\d+) bp\)", k)
            if m and v != "-":
                nums_by_t[int(m.groups()[0])] = int(v)

        tresholds = sorted(nums_by_t.keys(), reverse=True)
        p = dict()
        cats = []
        for i, t in enumerate(tresholds):
            if i == 0:
                c = ">= " + str(t) + " bp"
                cats.append(c)
                p[c] = nums_by_t[t]
            else:
                c = str(t) + "-" + str(tresholds[i - 1]) + " bp"
                cats.append(c)
                p[c] = nums_by_t[t] - nums_by_t[tresholds[i - 1]]
        if not categories:
            categories = cats
        data[s_name] = p

    pconfig = {
        "id": "quast_num_contigs",
        "title": "QUAST: Number of Contigs",
        "ylab": "# Contigs",
        "yDecimals": False,
    }

    return bargraph.plot(data, categories, pconfig)


# 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_contigs_barplot(self):
    """Make a bar plot showing the number and length of contigs for each assembly"""

    # Prep the data
    data = dict()
    categories = []
    for s_name, d in self.quast_data.items():
        nums_by_t = dict()
        for k, v in d.items():
            m = re.match(r"# contigs \(>= (\d+) bp\)", k)
            if m and v != "-":
                nums_by_t[int(m.groups()[0])] = int(v)

        tresholds = sorted(nums_by_t.keys(), reverse=True)
        p = dict()
        cats = []
        for i, t in enumerate(tresholds):
            if i == 0:
                c = ">= " + str(t) + " bp"
                cats.append(c)
                p[c] = nums_by_t[t]
            else:
                c = str(t) + "-" + str(tresholds[i - 1]) + " bp"
                cats.append(c)
                p[c] = nums_by_t[t] - nums_by_t[tresholds[i - 1]]
        if not categories:
            categories = cats
        data[s_name] = p

    pconfig = {
        "id": "quast_num_contigs",
        "title": "QUAST: Number of Contigs",
        "ylab": "# Contigs",
        "yDecimals": False,
    }

    return bargraph.plot(data, categories, pconfig)