Commit e3633143 authored by van den Berg's avatar van den Berg
Browse files

Integrate the picard HsMetrics into the stats.json file

parent e35be6a7
......@@ -519,7 +519,8 @@ rule multiqc:
output:
html = "multiqc_report/multiqc_report.html",
insert = "multiqc_report/multiqc_data/multiqc_picard_insertSize.json"
insert = "multiqc_report/multiqc_data/multiqc_picard_insertSize.json",
HsMetrics = "multiqc_report/multiqc_data/multiqc_picard_HsMetrics.json" if "baitsfile" in config else []
container: containers["multiqc"]
shell: "multiqc --data-format json --force --outdir multiqc_report . "
"|| touch {output}"
......@@ -530,11 +531,13 @@ rule merge_stats:
cols = expand("{sample}/{sample}.stats.json",
sample=config['samples']),
mpy = config["merge_stats"],
insertSize = rules.multiqc.output.insert
insertSize = rules.multiqc.output.insert,
HsMetrics = rules.multiqc.output.HsMetrics
output: "stats.json"
container: containers["vtools"]
shell: "python {input.mpy} --collectstats {input.cols} "
"--picard-insertSize {input.insertSize} > {output}"
"--picard-insertSize {input.insertSize} "
"--picard-HsMetrics {input.HsMetrics} > {output}"
rule stats_tsv:
"""Convert stats.json to tsv"""
......
......@@ -45,16 +45,32 @@ def add_picard_insertSize(data, filename):
raise RuntimeError(f"Unknown sample {name}")
def main(collectstats):
def add_picard_HsMetrics(data, filename):
""" Add the picard HsMetrics for each sample to data """
HsMetrics = parse_json(filename)
for sample in HsMetrics:
for d in data['sample_stats']:
if d['sample_name'] == sample:
d['picard_HsMetrics'] = HsMetrics[sample]
break
else:
raise RuntimeError(f"Unknown sample {sample}")
def main(args):
data = dict()
data["sample_stats"] = list()
for stats in collectstats:
for stats in args.collectstats:
cs = parse_json(stats)
data["sample_stats"].append(cs)
if args.picard_insertSize:
add_picard_insertSize(data, args.picard_insertSize)
if args.picard_HsMetrics:
add_picard_HsMetrics(data, args.picard_HsMetrics)
print(json.dumps(data))
......@@ -69,5 +85,10 @@ if __name__ == "__main__":
required=False,
help=('Path to multiQC json summary for picard '
'insertSize'))
parser.add_argument('--picard-HsMetrics',
required=False,
nargs='?',
help=('Path to multiQC json summary for picard '
'HsMetrics'))
args = parser.parse_args()
main(args.collectstats)
main(args)
......@@ -303,3 +303,8 @@
files:
- path: "micro/bams/micro.hs_metrics.txt"
- path: "multiqc_report/multiqc_data/multiqc_picard_HsMetrics.json"
- path: "stats.json"
contains:
- "picard_HsMetrics"
- "BAIT_SET"
- "FOLD_80_BASE_PENALTY"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment