1
- import genome .db
1
+ import genome .db , gzip , argparse , math
2
2
3
3
def main ():
4
4
error = 0.01
5
5
args = parse_options ()
6
- infile = open (args .infile ,,"r" )
7
- outfile = open (args .outfile ,,"w" )
6
+ if args .infile [- 3 :]== ".gz" :
7
+ infile = gzip .open (args .infile ,"r" )
8
+ else :
9
+ infile = open (args .infile ,"r" )
10
+ if args .outfile [- 3 :]== ".gz" :
11
+ outfile = gzip .open (args .outfile ,"w" )
12
+ else :
13
+ outfile = open (args .outfile ,"w" )
8
14
9
15
gdb = genome .db .GenomeDB ()
10
- ref_track = gdb .open_track ("10_IND/all_counts/ref_counts_%s" % ind )
11
- alt_track = gdb .open_track ("10_IND/all_counts/alt_counts_%s" % ind )
16
+ ref_track = gdb .open_track (args . ref_track )
17
+ alt_track = gdb .open_track (args . alt_track )
12
18
13
- snp_line = infile .read_line ()
19
+ snp_line = infile .readline ()
14
20
if snp_line :
15
21
outfile .write (snp_line )
16
22
else :
17
23
sys .stderr .write ("The input file was empty.\n " )
18
24
exit ()
19
25
20
- snp_line = infile .read_line ()
26
+ snp_line = infile .readline ()
21
27
while snp_line :
22
- snpinfo = snpline .strip ().split ()
23
- new_hetps = process_one_snp (snpinfo , ref_track , alt_track ,error )
24
- outfile .write ("\t " .join (snpinfo [:10 ]+ ";" .join (new_hetps )+ snpinfo [11 :])+ "\n " )
25
- snp_line = infile .read_line ()
28
+ snpinfo = snp_line .strip ().split ()
29
+ if snpinfo [9 ]== "NA" :
30
+ outfile .write (snp_line )
31
+ else :
32
+ new_hetps = process_one_snp (snpinfo , ref_track , alt_track ,error )
33
+ outfile .write ("\t " .join (snpinfo [:10 ]+ [";" .join (new_hetps )]+ snpinfo [11 :])+ "\n " )
34
+ snp_line = infile .readline ()
26
35
27
36
28
37
def process_one_snp (snpinfo , ref_track , alt_track ,error ):
@@ -36,7 +45,7 @@ def process_one_snp(snpinfo, ref_track, alt_track,error):
36
45
pos = snplocs [i ]
37
46
adr = ref_track .get_nparray (chrm , pos , pos )[0 ]
38
47
ada = alt_track .get_nparray (chrm , pos , pos )[0 ]
39
- update_hetps .append (get_posterior_hetp (hetps [i ],adr ,ada ,error ))
48
+ update_hetps .append (str ( get_posterior_hetp (hetps [i ],adr ,ada ,error ) ))
40
49
return update_hetps
41
50
42
51
@@ -56,7 +65,9 @@ def parse_options():
56
65
parser = argparse .ArgumentParser ()
57
66
parser .add_argument ("infile" , action = 'store' , default = None )
58
67
parser .add_argument ("outfile" , action = 'store' , default = None )
59
- parser .add_argument ("reffile " , action = 'store' , default = None )
60
- parser .add_argument ("altfile " , action = 'store' , default = None )
68
+ parser .add_argument ("ref_track " , action = 'store' , default = None )
69
+ parser .add_argument ("alt_track " , action = 'store' , default = None )
61
70
62
71
return parser .parse_args ()
72
+
73
+ main ()
0 commit comments