# Buggy code
def peddy_pca_plot(self):
    ancestry_colors = {
        "SAS": "rgb(68,1,81,1)",
        "EAS": "rgb(59,81,139,1)",
        "AMR": "rgb(33,144,141,1)",
        "AFR": "rgb(92,200,99,1)",
        "EUR": "rgb(253,231,37,1)",
    }
    background_ancestry_colors = {
        "SAS": "rgb(68,1,81,0.1)",
        "EAS": "rgb(59,81,139,0.1)",
        "AMR": "rgb(33,144,141,0.1)",
        "AFR": "rgb(92,200,99,0.1)",
        "EUR": "rgb(253,231,37,0.1)",
    }
    default_color = "#000000"
    default_background_color = "rgb(211,211,211,0.05)"
    data = OrderedDict()

    # plot the background data first, so it doesn't hide the actual data points
    d = self.peddy_data.pop("background_pca", {})
    if d:
        background = [
            {
                "x": pc1,
                "y": pc2,
                "color": default_background_color,
                "name": ancestry,
                "marker_size": 1,
            }
            for pc1, pc2, ancestry in zip(d["PC1"], d["PC2"], d["ancestry"])
        ]
        data["background"] = background

    for s_name, d in self.peddy_data.items():
        if "PC1_het_check" in d and "PC2_het_check" in d:
            data[s_name] = {
                "x": d["PC1_het_check"],
                "y": d["PC2_het_check"],
                "color": ancestry_colors.get(d["ancestry-prediction"], default_color),
            }

    pconfig = {
        "id": "peddy_pca_plot",
        "title": "Peddy: PCA Plot",
        "xlab": "PC1",
        "ylab": "PC2",
        "marker_size": 5,
        "marker_line_width": 0,
    }

    if len(data) > 0:
        self.add_section(
            name="PCA Plot", anchor="peddy-pca-plot", plot=scatter.plot(data, pconfig)
        )


# Traceback (KeyError)
[INFO   ]         multiqc : This is MultiQC v1.7
[INFO   ]         multiqc : Template    : default
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/multiqc/report/metrics/target_info.yaml'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/contamination/ts_bcbio-verifybamid.failed'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Per_base_N_content.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Per_base_sequence_content.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Per_base_sequence_quality.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Per_sequence_GC_content.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Per_sequence_quality_scores.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Sequence_Duplication_Levels.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/Sequence_Length_Distribution.tsv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/fastqc_data.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/fastqc_report.html'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/fastqc/ts_bcbio.zip'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.background_pca.json'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.het_check.csv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.html'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.ped_check.csv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.ped_check.rel-difference.csv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.peddy.ped'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.sex_check.csv'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/samtools/ts_bcbio-idxstats.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/samtools/ts_bcbio.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/variants/ts_bcbio.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/variants/ts_bcbio_bcftools_stats.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/variants/ts_bcbio_bcftools_stats_germline.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/viral/ts_bcbio-gdc-viral-completeness.txt'
[INFO   ]         multiqc : Searching '/home/ubuntu/naumenko/sample_b2/work/qc/multiqc/report/metrics/ts_bcbio_bcbio.txt'
[INFO   ]           bcbio : Found 1 reports
/bcbio/anaconda/lib/python3.6/site-packages/multiqc_bcbio/bcbio.py:77: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
add_project_info(yaml.load(target_infos[0]['f']))
[INFO   ]        samtools : Found 1 idxstats reports
[ERROR  ]         multiqc : Oops! The 'peddy' 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:
/home/ubuntu/naumenko/sample_b2/work/qc/ts_bcbio/peddy/ts_bcbio.sex_check.csv
============================================================
Module peddy raised an exception: Traceback (most recent call last):
File "/bcbio/anaconda/lib/python3.6/site-packages/multiqc/modules/peddy/peddy.py", line 58, in __init__
self.peddy_data[s_name].update(parsed_data[s_name])
KeyError: 'ts'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/bcbio/tools/bin/multiqc", line 440, in multiqc
output = mod()
File "/bcbio/anaconda/lib/python3.6/site-packages/multiqc/modules/peddy/peddy.py", line 60, in __init__
self.peddy_data[s_name] = parsed_data[s_name]
KeyError: 'ts'
============================================================
[INFO   ]        bcftools : Found 1 stats reports
[INFO   ]        bcftools : Found 1 stats reports
[INFO   ]          fastqc : Found 1 reports
[INFO   ]         multiqc : Compressing plot data
[INFO   ]         multiqc : Report      : ../../bcbiotx/tmp1n5rgkh7/multiqc_report.html
[INFO   ]         multiqc : Data        : ../../bcbiotx/tmp1n5rgkh7/multiqc_data
[INFO   ]         multiqc : MultiQC complete
' returned non-zero exit status 1.

# Fixed code
def peddy_pca_plot(self):
    ancestry_colors = {
        "SAS": "rgb(68,1,81,1)",
        "EAS": "rgb(59,81,139,1)",
        "AMR": "rgb(33,144,141,1)",
        "AFR": "rgb(92,200,99,1)",
        "EUR": "rgb(253,231,37,1)",
    }
    background_ancestry_colors = {
        "SAS": "rgb(68,1,81,0.1)",
        "EAS": "rgb(59,81,139,0.1)",
        "AMR": "rgb(33,144,141,0.1)",
        "AFR": "rgb(92,200,99,0.1)",
        "EUR": "rgb(253,231,37,0.1)",
    }
    default_color = "#000000"
    default_background_color = "rgb(211,211,211,0.05)"
    data = OrderedDict()

    # plot the background data first, so it doesn't hide the actual data points
    d = self.peddy_data.pop("background_pca", {})
    if d:
        background = [
            {
                "x": pc1,
                "y": pc2,
                "color": default_background_color,
                "name": ancestry,
                "marker_size": 1,
            }
            for pc1, pc2, ancestry in zip(d["PC1"], d["PC2"], d["ancestry"])
        ]
        data["background"] = background

    for s_name, d in self.peddy_data.items():
        if "PC1_het_check" in d and "PC2_het_check" in d:
            data[s_name] = {"x": d["PC1_het_check"], "y": d["PC2_het_check"]}
            try:
                data[s_name]["color"] = ancestry_colors.get(
                    d["ancestry-prediction"], default_color
                )
            except KeyError:
                pass

    pconfig = {
        "id": "peddy_pca_plot",
        "title": "Peddy: PCA Plot",
        "xlab": "PC1",
        "ylab": "PC2",
        "marker_size": 5,
        "marker_line_width": 0,
    }

    if len(data) > 0:
        self.add_section(
            name="PCA Plot", anchor="peddy-pca-plot", plot=scatter.plot(data, pconfig)
        )