Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Update coverage_metrics.py
Browse files Browse the repository at this point in the history
Restructure coverage data input for the 'write_data_file' method to produce .json and .txt files as from the master.
  • Loading branch information
Just-Roma authored Mar 27, 2023
1 parent 7445ba2 commit 905ac99
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions multiqc/modules/dragen/coverage_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ def add_coverage_metrics(self):

# Write data to file.
out_data = make_data_for_txt_report(cov_data)
self.write_data_file(out_data, "dragen_cov_metrics")
for phenotype in out_data:
self.write_data_file(out_data[phenotype], phenotype)

# Extract coverage bed/target bed/wgs from _overall_mean_cov.csv files.
# And prepare <coverage region prefix>-specific texts.
Expand Down Expand Up @@ -639,11 +640,22 @@ def check_duplicate_samples(sample_names):

def make_data_for_txt_report(coverage_data):
"""Prepare data for the text report."""
data = {}

data = defaultdict(dict)
for sample in coverage_data:
for phenotype in coverage_data[sample]:
ID = sample + phenotype
data[ID] = coverage_data[sample][phenotype]["metrics_and_values"]
# Replace any sequence of spaces/hyphens/dots/underscores by single underscore.
new_phenotype = re.sub("(\s+|-+|\.+|_+)+", "_", phenotype)
# Append 'coverage_section' suffix as in the previous code version.
if new_phenotype == "wgs":
new_phenotype += "_cov_metrics"
elif "qc_coverage_region" in new_phenotype:
new_phenotype = new_phenotype.replace("qc_coverage_region", "qc_region") + "_coverage_metrics"
else:
new_phenotype += "_coverage_metrics"
new_phenotype = "dragen_" + new_phenotype

data[new_phenotype][sample] = coverage_data[sample][phenotype]["metrics_and_values"]
return data


Expand Down

0 comments on commit 905ac99

Please sign in to comment.