-
Notifications
You must be signed in to change notification settings - Fork 0
/
hap_to_ped.py
35 lines (32 loc) · 1.25 KB
/
hap_to_ped.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 numpy as np
import sys
def convert_haps(hapAddr,size,dim,outputAddr):
print("making the matrix")
haps = np.zeros((size*2,dim),dtype=np.dtype('uint8'))
counter= 0
flag = True
print("opening the file")
with open(hapAddr,'r') as file:
for line in file:
# if flag:
# flag = False
# continue
# print(np.fromstring(line,dtype=int,sep=' ').shape,haps.shape)
temp_haps = line.strip().split()[5:]
haps[:,counter] = [int(item) for item in temp_haps]#np.fromstring(line,dtype=np.dtype('uint8'),sep=' ')[5:]
counter += 1
print("File is loaded")
haps[haps == 0] = 2
with open(outputAddr,'w') as output:
for i in range(haps.shape[0]//2):
prepended = '%05d' % i
output.write('0 ' + prepended + ' 0 0 0 -9 ')
for j in range((haps.shape[1])-1):
output.write('{} {} '.format(haps[2*i,j],haps[2*i +1,j]))
output.write('{} {}\n'.format(haps[2*i,haps.shape[1]-1],haps[2*i+1,haps.shape[1]-1]))
if __name__ == '__main__':
inputAddr = sys.argv[1]
size = int(sys.argv[2])
dim = int(sys.argv[3])
outputAddr = sys.argv[4]
convert_haps(inputAddr,size,dim,outputAddr)