comparison tools/refeditor/vcf2genotypes.py @ 1:85bdf226b67b default tip

add vcf2genotypes and test-data
author superyuan <shuaiyuan.emory@gmail.com>
date Mon, 30 Jun 2014 10:49:54 -0400
parents
children
comparison
equal deleted inserted replaced
0:9259f2939357 1:85bdf226b67b
1 # Filename: vcf2genotypes.py
2 # Author: Shuai Yuan
3 # Version: 06/29/2012
4 #
5 # This script is a wrapper for vcf2genotypes
6 #
7 # vcf2genotypes is launched based on these inputs:
8 # -i input VCF file
9 # -p target individual
10 # -o output genotypes file
11
12 import sys
13 import os
14 import re
15 import string
16 import commands
17 from tempfile import NamedTemporaryFile
18
19 # This function is exceedingly useful, perhaps package for reuse?
20 def getopts(argv):
21 opts = {}
22 while argv:
23 if argv[0][0] == '-':
24 opts[argv[0]] = argv[1]
25 argv = argv[2:]
26 else:
27 argv = argv[1:]
28 return opts
29
30 def main():
31 args = sys.argv[1:]
32
33 try:
34 opts = getopts(args)
35 except IndexError:
36 print "Usage:"
37 return 0
38
39 vcf = opts.get("-i")
40 if vcf == None:
41 print "No input VCF file specified."
42 return -1
43
44 individual = opts.get("-p")
45 if individual == None:
46 print "No valid individual specified."
47 return -2
48
49 outputfile = opts.get("-o")
50 if outputfile == None:
51 print "No output file specified."
52 return -6
53
54
55 # All inputs have been specified at this point, now validate.
56
57 #generate command
58 commandline = "vcf2genotypes %s %s > %s " % (vcf, individual, outputfile)
59 #run
60 errorcode, stdout = commands.getstatusoutput(commandline)
61
62 #return error code
63 return errorcode
64
65 if __name__ == "__main__":
66 main()