Skip to content

Commit

Permalink
fixing displaced columns in runmetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bioinfo-chru-strasbourg committed Apr 12, 2022
1 parent 097d45f commit 3dcf6d5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions bin/runmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,29 @@ def get_total_mapped_duplicate_reads(sampleDir, sample, aligner):
"""
flagstatFile = osj(sampleDir, sample+"."+aligner+".bam.metrics", sample+"."+aligner+".flagstat")
assert_file_exists_and_is_readable(flagstatFile)

stats = {}
with open(flagstatFile, "r") as f:
col1 = [int(line.split()[0]) for line in f]
if col1[0] != 0:
return [col1[0], col1[4], format(col1[4]/col1[0]*100, ".2f"), col1[3], format(col1[3]/col1[0]*100, ".2f")]
for l in f:
if l.rstrip().endswith("in total (QC-passed reads + QC-failed reads)"):
stats["total"] = int(l.split(" ")[0])
elif "mapped" in l and "primary mapped" not in l and "different chr" not in l:
stats["mapped"] = int(l.split(" ")[0])
elif l.rstrip().endswith("duplicates") and "primary duplicates" not in l:
stats["dup"] = int(l.split(" ")[0])

assert all([k in stats.keys() for k in ("total", "mapped", "dup")])

if stats["total"] == 0:
return [stats["total"], stats["mapped"], "NA", stats["dup"], "NA"]
else:
return [col1[0], col1[4], "NA", col1[3], "NA"]
return [
stats["total"],
stats["mapped"],
format(stats["mapped"] / stats["total"] * 100, ".2f"),
stats["dup"],
format(stats["dup"] / stats["total"] * 100, ".2f"),
]

def get_on_target_reads(sampleDir, sample, aligner, bed):
"""
Expand Down

0 comments on commit 3dcf6d5

Please sign in to comment.