annotate beagle4.py @ 4:b970ba62539e draft default tip

Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
author bobbledavidson
date Wed, 16 Sep 2015 05:58:13 -0400
parents c36b11eab590
children
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
4
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
6 import gzip
1
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
7
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
8 def main():
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
9
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
10 parser = optparse.OptionParser()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
11 parser.add_option('--jar', dest='jarfile', default=None)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
12 parser.add_option('--gtgl',dest='gtgl',default='gt')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
13 parser.add_option('--gfile',dest='gfile',default=None)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
14 parser.add_option('--ref', dest='ref',default=None )
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
15 parser.add_option('--impute-its',dest='impits', default="5")
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
16 parser.add_option('--phase-its',dest='phits',default="5")
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
17 parser.add_option('--out', dest='outfile', default='out.beagle4')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
18
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
19 (options, args) = parser.parse_args()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
20
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
21 if not options.jarfile:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
22 parser.error('Jar option is not optional. Please provide full path to beagle4 jar file')
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
23
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
24 if not options.gfile:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
25 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
26
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
27 print options.jarfile
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
28 cwd = os.getcwd()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
29 outdir = tempfile.mkdtemp(dir=cwd)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
30 outprefix = 'bglout'
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
31
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
32 if options.ref:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
33 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
34 else:
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
35 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
36
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
37
4
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
38 #shutil.move(outdir+'/'+outprefix+'.vcf.gz',options.outfile)
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
39 #shutil.rmtree(outdir)
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
40 with gzip.open(outdir+os.sep+outprefix+'.vcf.gz','rb') as gzinfile:
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
41 with open(options.outfile,'w') as vcfoutfile:
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
42 for line in gzinfile:
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
43 vcfoutfile.write(line)
b970ba62539e Updated beagle4.py to output uncompressed VCF files - had been outputting VCF.GZ
bobbledavidson
parents: 1
diff changeset
44
1
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
45 shutil.rmtree(outdir)
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
46
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
47
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
48 if __name__=='__main__':
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
49 main()
c36b11eab590 Beagle4 python wrapper Uploaded
bobbledavidson
parents:
diff changeset
50