comparison tools/cgatools17/vcf_to_listVariants.py @ 1:3a2e0f376f26 draft

Minor change to tv2vcf.xml to allow for workflow automation
author dgdekoning
date Wed, 21 Oct 2015 10:09:15 -0400
parents
children
comparison
equal deleted inserted replaced
0:751b62d30ae1 1:3a2e0f376f26
1 #!/usr/bin/env python
2
3 """[License: GNU General Public License v3 (GPLv3)]
4
5 This is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Documentation as defined by:
19 <http://epydoc.sourceforge.net/manual-fields.html#fields-synonyms>
20 """
21
22 import sys,os,os.path,argparse,textwrap,datetime
23
24 def convert_vcf_to_listVariants(filename_in, filename_out):
25 if(filename_out == "-"):
26 fh_out = sys.stdout
27 else:
28 fh_out = open(filename_out,"w")
29
30 i = 1
31
32 fh_out.write("variantId\tchromosome\tbegin\tend\tvarType\treference\talleleSeq\txRef\n")
33
34 with open(filename_in, 'r') as fh_in:
35 for line in fh_in:
36 line_s = line.strip()
37 if((len(line_s) >= 6) and line_s[0] != "#"):
38 params = line.split("\t")
39
40 if(len(params[4]) == 1):# single base substitution
41 fh_out.write(str(i)) # id
42
43 fh_out.write("\t"+params[0]) # chr
44 fh_out.write("\t"+str(int(params[1])-1)) # begin
45 fh_out.write("\t"+params[1]) # end
46 fh_out.write("\tsnp")
47 fh_out.write("\t"+params[3]) # reference
48 fh_out.write("\t"+params[4]) # alleleSeq
49 fh_out.write("\t"+params[2]) # dbsnpid / annotation id
50
51 fh_out.write("\n")
52 i += 1
53 # else: # indel...
54
55 if(filename_out != "-"):
56 fh_out.close()
57
58 if __name__ == "__main__":
59 parser = argparse.ArgumentParser()
60
61 parser.add_argument("-i","--input", help="input file (VCF)")
62 parser.add_argument("-o","--output",help="output filename; '-' for stdout",default="-")
63
64 args = parser.parse_args()
65
66 convert_vcf_to_listVariants(args.input,args.output)