annotate varscan_vaf.py @ 0:0b6ec297a6bc draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
author artbio
date Mon, 28 Nov 2022 21:59:34 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
1 #!/usr/bin/python3
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
2
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
3 import argparse
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
4
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
5
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
6 def Parser():
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
7 the_parser = argparse.ArgumentParser()
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
8 the_parser.add_argument(
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
9 '--input', action="store", type=str,
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
10 help="varscan vcf file with normal and tumor genotypes \
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
11 (columns 10 and 11)")
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
12 the_parser.add_argument(
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
13 '--output', action="store", type=str,
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
14 help="vcf with computed VAFs")
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
15 args = the_parser.parse_args()
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
16 return args
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
17
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
18
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
19 def main(input, output):
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
20 with open(input, 'r') as f:
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
21 myinput = f.read()
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
22 mylines = myinput.split('\n')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
23 entete = [i for i in mylines[:-1] if i[0] == '#']
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
24 variant = [i for i in mylines[:-1] if i[0] != '#']
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
25 out = open(output, 'w')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
26 out.write('\n'.join(entete[:-1]) + '\n')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
27 out.write('##FORMAT=<ID=VAF,Number=R,Type=float,Description="Variant'
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
28 'Allele Frequency">\n')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
29 out.write(entete[-1] + '\n')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
30 for i in variant:
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
31 fields = i.split('\t')[9:11]
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
32 af_normal = fields[0].split(':')[3]
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
33 vac_normal = af_normal.split(',')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
34 af_tumor = fields[1].split(':')[3]
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
35 vac_tumor = af_tumor.split(',')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
36 vaf_normal = int(
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
37 vac_normal[1]) / (int(vac_normal[0]) + int(vac_normal[1]))
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
38 vaf_tumor = int(
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
39 vac_tumor[1]) / (int(vac_tumor[0]) + int(vac_tumor[1]))
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
40 normal_list = fields[0].split(':')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
41 normal_list.append(f'{vaf_normal:.3f}')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
42 tumor_list = fields[1].split(':')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
43 tumor_list.append(f'{vaf_tumor:.3f}')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
44 normal_string = ':'.join(normal_list)
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
45 tumor_string = ':'.join(tumor_list)
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
46 fields = i.split('\t')[0:9]
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
47 fields[8] += ':VAF'
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
48 fields.append(normal_string)
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
49 fields.append(tumor_string)
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
50 out.write('\t'.join(fields) + '\n')
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
51 out.close()
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
52
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
53
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
54 if __name__ == "__main__":
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
55 args = Parser()
0b6ec297a6bc planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/varscan_vaf commit ff9426700b78da43ad64bf4905d358ee4986127b
artbio
parents:
diff changeset
56 main(args.input, args.output)