annotate beagle4.py @ 2:e7e5432588ea draft

Beagle4 xml wrapper uploaded
author bobbledavidson
date Wed, 08 Jul 2015 10:19:11 -0400
parents c36b11eab590
children b970ba62539e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
1 import os
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
2 import optparse
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
3 import tempfile
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
4 import shutil
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
5 from subprocess import call
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
6
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
7 def main():
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
8
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
9 parser = optparse.OptionParser()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
10 parser.add_option('--jar', dest='jarfile', default=None)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
11 parser.add_option('--gtgl',dest='gtgl',default='gt')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
12 parser.add_option('--gfile',dest='gfile',default=None)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
13 parser.add_option('--ref', dest='ref',default=None )
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
14 parser.add_option('--impute-its',dest='impits', default="5")
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
15 parser.add_option('--phase-its',dest='phits',default="5")
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
16 parser.add_option('--out', dest='outfile', default='out.beagle4')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
17
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
18 (options, args) = parser.parse_args()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
19
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
20 if not options.jarfile:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
21 parser.error('Jar option is not optional. Please provide full path to beagle4 jar file')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
22
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
23 if not options.gfile:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
24 parser.error('Genotype file not optional. Can be genotype or genotype likelihood. Please provide --gfile argument.')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
25
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
26 print options.jarfile
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
27 cwd = os.getcwd()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
28 outdir = tempfile.mkdtemp(dir=cwd)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
29 outprefix = 'bglout'
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
30
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
31 if options.ref:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
32 call(['java', '-Xmx2g', '-jar', options.jarfile, 'ref='+options.ref, options.gtgl+'='+options.gfile, 'phase-its='+options.phits,'impute-its='+options.impits , 'out='+outdir+'/'+outprefix ])
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
33 else:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
34 call(['java', '-Xmx2g', '-jar', options.jarfile, options.gtgl+'='+options.gfile,'phase-its='+options.phits, 'impute-its='+options.impits , 'out='+outdir+'/'+outprefix ])
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
35
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
36
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
37 shutil.move(outdir+'/'+outprefix+'.vcf.gz',options.outfile)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
38 shutil.rmtree(outdir)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
39
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
40
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
41
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
42 if __name__=='__main__':
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
43 main()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
44