-
Notifications
You must be signed in to change notification settings - Fork 0
/
beagle4.py
52 lines (37 loc) · 1.75 KB
/
beagle4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import optparse
import tempfile
import shutil
from subprocess import call
import gzip
def main():
parser = optparse.OptionParser()
parser.add_option('--jar', dest='jarfile', default=None)
parser.add_option('--gtgl',dest='gtgl',default='gt')
parser.add_option('--gfile',dest='gfile',default=None)
parser.add_option('--ref', dest='ref',default=None )
parser.add_option('--impute-its',dest='impits', default="5")
parser.add_option('--phase-its',dest='phits',default="5")
parser.add_option('--out', dest='outfile', default='out.beagle4')
(options, args) = parser.parse_args()
if not options.jarfile:
parser.error('Jar option is not optional. Please provide full path to beagle4 jar file')
if not options.gfile:
parser.error('Genotype file not optional. Can be genotype or genotype likelihood. Please provide --gfile argument.')
print options.jarfile
cwd = os.getcwd()
outdir = tempfile.mkdtemp(dir=cwd)
outprefix = 'bglout'
if options.ref:
call(['java', '-Xmx2g', '-jar', options.jarfile, 'ref='+options.ref, options.gtgl+'='+options.gfile, 'phase-its='+options.phits,'impute-its='+options.impits , 'out='+outdir+'/'+outprefix ])
else:
call(['java', '-Xmx2g', '-jar', options.jarfile, options.gtgl+'='+options.gfile,'phase-its='+options.phits, 'impute-its='+options.impits , 'out='+outdir+'/'+outprefix ])
#shutil.move(outdir+'/'+outprefix+'.vcf.gz',options.outfile)
#shutil.rmtree(outdir)
with gzip.open(outdir+os.sep+outprefix+'.vcf.gz','rb') as gzinfile:
with open(options.outfile,'w') as vcfoutfile:
for line in gzinfile:
vcfoutfile.write(line)
shutil.rmtree(outdir)
if __name__=='__main__':
main()