-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolate_map.py
35 lines (33 loc) · 1.41 KB
/
interpolate_map.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
import sys
import numpy as np
def findHead(genData,index,position):
while index < genData.shape[0] and genData[index][1] < position:
index += 1
result = (position-genData[index-1][1])* (genData[index-1][2]-genData[index-2][2])/(genData[index-1][1]-genData[index-2][1])
return result+genData[index-1][2],index-1
if __name__ == '__main__':
genMapAddr = sys.argv[1]
queryAddr = sys.argv[2]
outputAddr = sys.argv[3]
queryData = np.loadtxt(queryAddr,dtype={'names': ['RSID' ,'position'],
'formats': [ 'S20' ,'i8']})
chr = '6'
'''queryDict = {}
for i in range(queryData.shape[0]):
queryDict[queryData[i][1]] = i'''
genData =np.loadtxt(genMapAddr,dtype={'names': ['RSID', 'position' ,'gen_dist' ],
'formats': ['S20' , 'i8' , 'f8']})
genDict = {}
for i in range(genData.shape[0]):
genDict[genData[i][1]] = i
lastIndex = 0
tempDist = 0
with open(outputAddr,'w') as outputFile:
for queryItem in queryData:
if queryItem[1] in genDict:
tempDist = genData[genDict[queryItem[1]]][2]
lastIndex = genDict[queryItem[1]]
else:
tempDist,lastIndex = findHead(genData,lastIndex,queryItem[1])
outputFile.write(' '.join([chr,str(queryItem[0]),str(tempDist),str(queryItem[1])])+'\n')
#outputFile.write(' '.)