# Buggy code
def parse_htseq_report(self, f):
    """Parse the HTSeq Count log file."""
    keys = [
        "__no_feature",
        "__ambiguous",
        "__too_low_aQual",
        "__not_aligned",
        "__alignment_not_unique",
    ]
    parsed_data = dict()
    assigned_counts = 0
    for l in f["f"]:
        s = l.split("\t")
        if s[0] in keys:
            parsed_data[s[0][2:]] = int(s[1])
        else:
            assigned_counts += int(s[1])
    if len(parsed_data) > 0:
        parsed_data["assigned"] = assigned_counts
        parsed_data["total_count"] = sum([v for v in parsed_data.values()])
        parsed_data["percent_assigned"] = (
            float(parsed_data["assigned"]) / float(parsed_data["total_count"])
        ) * 100.0
        return parsed_data
    return None


# Traceback (IndexError)
[INFO   ]         multiqc : This is MultiQC v1.0.dev0
[INFO   ]         multiqc : Template    : default
[INFO   ]         multiqc : Searching '/home/mlotshwa/RNA_Seq_TB_project/Run2'
[ERROR  ]         multiqc : Oops! The 'htseq' MultiQC module broke...
Please copy the following traceback and report it at https://github.com/ewels/MultiQC/issues
(if possible, include a log file that triggers the error)
============================================================
Module htseq raised an exception: Traceback (most recent call last):
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/EGG-INFO/scripts/multiqc", line 346, in multiqc
output = mod()
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/multiqc/modules/htseq/htseq.py", line 31, in __init__
parsed_data = self.parse_htseq_report(f)
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/multiqc/modules/htseq/htseq.py", line 62, in parse_htseq_report
assigned_counts += int(s[1])
IndexError: list index out of range
============================================================
[INFO   ]        samtools : Found 1 rmdup reports
[ERROR  ]         multiqc : Oops! The 'slamdunk' MultiQC module broke...
Please copy the following traceback and report it at https://github.com/ewels/MultiQC/issues
(if possible, include a log file that triggers the error)
============================================================
Module slamdunk raised an exception: Traceback (most recent call last):
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/EGG-INFO/scripts/multiqc", line 346, in multiqc
output = mod()
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/multiqc/modules/slamdunk/slamdunk.py", line 42, in __init__
self.parseSummary(f)
File "/home/mlotshwa/miniconda2/envs/snowflakes/lib/python2.7/site-packages/multiqc-1.0.dev0-py2.7.egg/multiqc/modules/slamdunk/slamdunk.py", line 295, in parseSummary
self.slamdunk_data[s_name]['sequenced'] = int(fields[4])
IndexError: list index out of range
============================================================
[INFO   ]          fastqc : Found 112 reports
[WARNING]          fastqc : Multiple FastQC Theoretical GC Content files found, now using fastqc_theoretical_gc_hg38_genome.txt
[WARNING]          fastqc : Multiple FastQC Theoretical GC Content files found, now using fastqc_theoretical_gc_hg38_txome.txt
[WARNING]          fastqc : Multiple FastQC Theoretical GC Content files found, now using fastqc_theoretical_gc_mm10_txome.txt
[INFO   ]         multiqc : Report      : multiqc_report.html
[INFO   ]         multiqc : Data        : multiqc_data
[INFO   ]         multiqc : MultiQC complete

# Fixed code
def parse_htseq_report(self, f):
    """Parse the HTSeq Count log file."""
    keys = [
        "__no_feature",
        "__ambiguous",
        "__too_low_aQual",
        "__not_aligned",
        "__alignment_not_unique",
    ]
    parsed_data = dict()
    assigned_counts = 0
    for l in f["f"]:
        s = l.split("\t")
        if s[0] in keys:
            parsed_data[s[0][2:]] = int(s[1])
        else:
            try:
                assigned_counts += int(s[1])
            except (ValueError, IndexError):
                pass
    if len(parsed_data) > 0:
        parsed_data["assigned"] = assigned_counts
        parsed_data["total_count"] = sum([v for v in parsed_data.values()])
        parsed_data["percent_assigned"] = (
            float(parsed_data["assigned"]) / float(parsed_data["total_count"])
        ) * 100.0
        return parsed_data
    return None