Skip to content

Commit

Permalink
style: pycodestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
elleira committed May 8, 2024
1 parent 8171f82 commit a611de2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
33 changes: 22 additions & 11 deletions workflow/scripts/manta_to_tsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
vcf = vcf.Reader(open(input_file, "r"))

with open(output_file, "wt") as tsv:
tsv_writer = csv.writer(tsv, delimiter='\t')
tsv_writer = csv.writer(tsv, delimiter="\t")
tsv_writer.writerow(["#POSITION1", "MANTAID", "BREAKEND", "GENES", "DEPTH", "ANNOTATIONINFO", "PR_ALT_FREQ", "SR_ALT_FREQ"])
for row in vcf:
if "MantaBND" in row.ID and not any(x in ["MinQUAL", "MinGQ", "MinSomaticScore",
"Ploidy", "MaxDepth", "MaxMQ0Frac", "NoPairSupport",
"SampleFT", "HomRef"] for x in row.FILTER):
if "MantaBND" in row.ID and not any(
x
in ["MinQUAL", "MinGQ", "MinSomaticScore", "Ploidy", "MaxDepth", "MaxMQ0Frac", "NoPairSupport", "SampleFT", "HomRef"]
for x in row.FILTER
):
try:
genes = row.INFO["ANN"][0].split("|")
except KeyError:
genes = ["NA", "NA", "NA", "NA", "NA"]
manta_id = ":".join(row.ID.split(":")[0:2])
last_sample_index = len(row.samples) - 1
last_sample = row.samples[last_sample_index]
pr_values = last_sample.data.PR if hasattr(last_sample.data, 'PR') else None
sr_values = last_sample.data.SR if hasattr(last_sample.data, 'SR') else None
pr_values = last_sample.data.PR if hasattr(last_sample.data, "PR") else None
sr_values = last_sample.data.SR if hasattr(last_sample.data, "SR") else None
if pr_values:
pr_denominator, pr_numerator = pr_values
pr_frequency = pr_numerator / (pr_denominator + pr_numerator) if pr_denominator + pr_numerator != 0 else None
Expand All @@ -39,8 +41,17 @@
sr_frequency = None

# Format frequencies only if they are not None
pr_formatted = f"{pr_frequency:.4f}" if pr_frequency is not None else 'NA'
sr_formatted = f"{sr_frequency:.4f}" if sr_frequency is not None else 'NA'
tsv_writer.writerow([row.CHROM + ":" + str(row.POS), manta_id, str(row.ALT)[1:-1],
genes[3] + "(" + genes[4] + ")", row.INFO["BND_DEPTH"],
row.FILTER, str(pr_formatted), str(sr_formatted)])
pr_formatted = f"{pr_frequency:.4f}" if pr_frequency is not None else "NA"
sr_formatted = f"{sr_frequency:.4f}" if sr_frequency is not None else "NA"
tsv_writer.writerow(
[
row.CHROM + ":" + str(row.POS),
manta_id,
str(row.ALT)[1:-1],
genes[3] + "(" + genes[4] + ")",
row.INFO["BND_DEPTH"],
row.FILTER,
str(pr_formatted),
str(sr_formatted),
]
)
3 changes: 2 additions & 1 deletion workflow/scripts/sample_order_multiqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
for sample_line in sample_order:
replacement_line = [sample_line[sample_order_index.index("sample")]]
order_line = [sample_line[sample_order_index.index("sample")], sample_line[sample_order_index.index("lab_id")]]
if sample_line[sample_order_index.index("type")].lower() == "t" or sample_line[sample_order_index.index("type")].lower() == "n":
if (sample_line[sample_order_index.index("type")].lower() == "t" or
sample_line[sample_order_index.index("type")].lower() == "n"):
replacement_tsv_dna.write("\t".join(replacement_line + ["sample_"+str(f"{i:03}")]) + "\n")
order_tsv_dna.write("\t".join(["sample_"+str(f"{i:03}")] + order_line) + "\n")
dna_table.write("\t".join(["sample_"+str(f"{i:03}")] + order_line)+"\n")
Expand Down

0 comments on commit a611de2

Please sign in to comment.