-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpl2.py
executable file
·63 lines (52 loc) · 981 Bytes
/
expl2.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import sys
from collections import Counter
import numpy as np
#if len(sys.argv) < 2:
# print "Usage: expl.py <HDB>"
# sys.exit(1)
bimFn = "chip-sorted.bim"
pedFn = "SPARK-sorted.ped"
"""
bim = []
with open(bimFn, 'r') as f:
for l in f:
cs = l.strip("\n\r").split("\t")
bim.append([cs[0],cs[3],cs[4],cs[5]])
"""
keys = ['00',
'AA',
'AC',
'AG',
'AT',
'CA',
'CC',
'CG',
'CT',
'GA',
'GC',
'GG',
'GT',
'TA',
'TC',
'TG',
'TT']
hom = ['AA','CC','GG','TT']
PF = open(pedFn)
F = open("D2.txt", 'w')
n = 0
CNT = []
start = True
for l in PF:
cs = l.strip("\n\r").split("\t")
fmId,prId,fId,mId,gender,aff = cs[:6]
D = Counter([cs[6+2*k]+cs[6+2*k+1] for k in range(len(cs[6:])/2)])
H = sum([D[k] for k in hom])
F.write('\t'.join(map(str,[D[k] for k in keys] + [H])) +"\n")
if n % 1000 == 0:
print("n", n, file=sys.stderr)
n += 1
#if n == 10:
# break
PF.close()
F.close()