Mercurial > repos > artbio > varscan_vaf
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0b6ec297a6bc |
---|---|
1 #!/usr/bin/python3 | |
2 | |
3 import argparse | |
4 | |
5 | |
6 def Parser(): | |
7 the_parser = argparse.ArgumentParser() | |
8 the_parser.add_argument( | |
9 '--input', action="store", type=str, | |
10 help="varscan vcf file with normal and tumor genotypes \ | |
11 (columns 10 and 11)") | |
12 the_parser.add_argument( | |
13 '--output', action="store", type=str, | |
14 help="vcf with computed VAFs") | |
15 args = the_parser.parse_args() | |
16 return args | |
17 | |
18 | |
19 def main(input, output): | |
20 with open(input, 'r') as f: | |
21 myinput = f.read() | |
22 mylines = myinput.split('\n') | |
23 entete = [i for i in mylines[:-1] if i[0] == '#'] | |
24 variant = [i for i in mylines[:-1] if i[0] != '#'] | |
25 out = open(output, 'w') | |
26 out.write('\n'.join(entete[:-1]) + '\n') | |
27 out.write('##FORMAT=<ID=VAF,Number=R,Type=float,Description="Variant' | |
28 'Allele Frequency">\n') | |
29 out.write(entete[-1] + '\n') | |
30 for i in variant: | |
31 fields = i.split('\t')[9:11] | |
32 af_normal = fields[0].split(':')[3] | |
33 vac_normal = af_normal.split(',') | |
34 af_tumor = fields[1].split(':')[3] | |
35 vac_tumor = af_tumor.split(',') | |
36 vaf_normal = int( | |
37 vac_normal[1]) / (int(vac_normal[0]) + int(vac_normal[1])) | |
38 vaf_tumor = int( | |
39 vac_tumor[1]) / (int(vac_tumor[0]) + int(vac_tumor[1])) | |
40 normal_list = fields[0].split(':') | |
41 normal_list.append(f'{vaf_normal:.3f}') | |
42 tumor_list = fields[1].split(':') | |
43 tumor_list.append(f'{vaf_tumor:.3f}') | |
44 normal_string = ':'.join(normal_list) | |
45 tumor_string = ':'.join(tumor_list) | |
46 fields = i.split('\t')[0:9] | |
47 fields[8] += ':VAF' | |
48 fields.append(normal_string) | |
49 fields.append(tumor_string) | |
50 out.write('\t'.join(fields) + '\n') | |
51 out.close() | |
52 | |
53 | |
54 if __name__ == "__main__": | |
55 args = Parser() | |
56 main(args.input, args.output) |