-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinterpolate_loci.py
More file actions
49 lines (32 loc) · 796 Bytes
/
interpolate_loci.py
File metadata and controls
49 lines (32 loc) · 796 Bytes
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
import gzip
import sys
import numpy
if (len(sys.argv) < 3):
print ("Usage:\npython interpolate_loci.py <input_map_file> <vcf_input_gzip> <output_file>")
sys.exit()
map_filepath = sys.argv[1]
vcf_input = sys.argv[2]
output_file = sys.argv[3]
f = gzip.open(vcf_input ,'rt')
_started = False
_sites = []
for line in f:
if (_started):
vals = line[0:1000].split()
_sites.append(int(vals[1]))
elif ("#CHROM" in line[0:1000]):
_started = True
f.close()
f = open(map_filepath)
f_o = open(output_file,'w+')
xp = []
yp = []
for line in f:
vals = line.split()
xp.append(int(vals[1]))
yp.append(float(vals[len(vals)-1]))
_output_vals =numpy.interp(_sites,xp,yp)
for i in range(0,len(_output_vals)):
f_o.write(str(i)+ "\t" + str(_output_vals[i]) + "\n")
f.close()
f_o.close()