-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertBim.py
executable file
·48 lines (38 loc) · 1.09 KB
/
convertBim.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
#!/usr/bin/env python
import sys, os
if len(sys.argv) < 3:
print("Usage: convertBim.py <old bim> <helper file>")
exit()
bimFn = sys.argv[1]
print(bimFn, file=sys.stderr)
helpFn = sys.argv[2]
print(helpFn, file=sys.stderr)
bim = []
n = 0
with open(bimFn, 'r') as f:
for l in f:
cs = l.strip('\n\r').split('\t')
bim.append(cs)
n += 1
helper={}
M = {x:y for x,y in zip(list('ACGT0'),list('TGCA0'))}
with open(helpFn, 'r') as f:
for l in f:
cs = l.strip('\n\r').split('\t')
helper[cs[2]] = cs
out = []
for i in range(len(bim)):
snpId = bim[i][1]
if snpId in helper and len(helper[snpId][0]) < 6:
out.append([helper[snpId][0],
snpId, bim[i][2],
helper[snpId][1],
helper[snpId][4],
helper[snpId][3]])
print(bim[i], helper[snpId][4], helper[snpId][3], file=sys.stderr)
else:
out.append(bim[i])
out[i][3] = -1
out[i][0] = 'chr'+out[i][0]
for i in range(len(out)):
print('\t'.join(map(str, out[i])))