comparison ratio2circos.py @ 1:1204e79d3a99 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/freec commit e0d4688a59e6eeba33adcfe803ac43d0bc2863e7"
author iuc
date Tue, 31 Aug 2021 08:10:37 +0000
parents 5330cf818142
children
comparison
equal deleted inserted replaced
0:5330cf818142 1:1204e79d3a99
1 import argparse
2 import math 1 import math
3 import os 2 import sys
4 3
5 parser = argparse.ArgumentParser() 4 ploidy = int(sys.argv[1])
6 parser.add_argument('-i', '--input', required=True, default='./output/sample.bam_ratio.BedGraph', type=str)
7 parser.add_argument('-o', '--output', required=True, default='./output/sample.bam_ratio_log2_circos.txt', type=str)
8 parser.add_argument('-p', '--ploidy', required=True, default=2, type=int)
9 args = parser.parse_args()
10 5
11 path = os.path.dirname(args.input) 6 with open("./output/sample.bam_ratio.BedGraph") as bed:
12 output = os.path.join(path, args.output) 7 with open("./output/sample.bam_ratio_log2_circos.txt", "w+") as olog2r:
8 for line in bed.readlines():
9 ls = line.split()
10 if ls[0] != "track" and float(ls[3]) > 0:
11 log2_ratio = math.log2(float(ls[3]) / ploidy)
12 olog2r.write("{}\t{}\t{}\t{}\n".format(ls[0], ls[1], ls[2], log2_ratio))
13 13
14 with open(args.input) as file: 14 with open("./genome.fa.fai") as fai:
15 for line in file.readlines(): 15 with open("./output/karyotype_circos.txt", "w+") as ochr:
16 ls = line.split() 16 for line in fai.readlines():
17 if ls[0] != "track" and float(ls[3]) > 0: 17 ls = line.split()
18 log2_ratio = math.log2(float(ls[3]) / args.ploidy) 18 ochr.write("chr - {}\t{}\t0\t{}\t{}\n".format(ls[0], ls[0].strip("chr").lower(), ls[1], ls[0]))
19 with open(output, "a") as out:
20 out.write("{}\t{}\t{}\t{}\n".format(ls[0], ls[1], ls[2], log2_ratio))