Skip to content

Commit e3aba1e

Browse files
committed
🧹 tidy up having file input close
1 parent 9b7f82f commit e3aba1e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

scripts/cnv_1_genome2gene.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ def process_cnv(cpath):
1818
root = os.path.basename(cpath)
1919
temp_filtered_fname = root + ".CNVs_0.05_filtered.bed"
2020
with open(out_dir + temp_filtered_fname, "w") as temp_filtered:
21-
in_cnv = open(cpath)
22-
head = next(in_cnv)
23-
header = head.rstrip('\n').split('\t')
24-
wilcox_idx = header.index('WilcoxonRankSumTestPvalue')
25-
ks_idx = header.index('KolmogorovSmirnovPvalue')
26-
for cnv in in_cnv:
27-
ct_dict["total_cnvs"] += 1
28-
cnv_data = cnv.rstrip("\n").split("\t")
29-
if cnv_data[wilcox_idx] == "NA" or cnv_data[ks_idx] == "NA":
30-
ct_dict["NA"] += 1
31-
elif float(cnv_data[wilcox_idx]) < 0.05 and float(cnv_data[ks_idx]) < 0.05:
32-
print("\t".join(cnv_data[0:5]), file=temp_filtered)
33-
else:
34-
ct_dict["p_value_filter"] += 1
21+
with open(cpath) as in_cnv:
22+
head = next(in_cnv)
23+
header = head.rstrip('\n').split('\t')
24+
wilcox_idx = header.index('WilcoxonRankSumTestPvalue')
25+
ks_idx = header.index('KolmogorovSmirnovPvalue')
26+
for cnv in in_cnv:
27+
ct_dict["total_cnvs"] += 1
28+
cnv_data = cnv.rstrip("\n").split("\t")
29+
if cnv_data[wilcox_idx] == "NA" or cnv_data[ks_idx] == "NA":
30+
ct_dict["NA"] += 1
31+
elif float(cnv_data[wilcox_idx]) < 0.05 and float(cnv_data[ks_idx]) < 0.05:
32+
print("\t".join(cnv_data[0:5]), file=temp_filtered)
33+
else:
34+
ct_dict["p_value_filter"] += 1
3535
temp_genes_fname = root + ".CNVs.Genes"
3636
to_genes_cmd = "{} intersect -a {}{} -b {} -wb > {}{}".format(bedtools, out_dir, temp_filtered_fname, bed_file, out_dir, temp_genes_fname)
3737
subprocess.call(to_genes_cmd, shell=True)

0 commit comments

Comments
 (0)