-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_count.py
More file actions
executable file
·68 lines (61 loc) · 1.85 KB
/
test_count.py
File metadata and controls
executable file
·68 lines (61 loc) · 1.85 KB
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
61
62
63
64
65
66
67
68
import argparse as ap
import gzip
import sys
def main():
parser = ap.ArgumentParser()
parser.add_argument('phenotypes')
parser.add_argument('ibd')
args = parser.parse_args()
pheno = {}
with open(args.phenotypes, 'r') as f:
for l in f:
l = l.strip().split()
if l[1] == 'NA':
continue
pheno[l[0]] = int(l[1])
cscs = 0
cscn = 0
cncn = 0
seen = set()
duplicates = 0
autozygous = 0
with gzip.open(args.ibd, 'rt') as f:
for l in f:
if l.startswith('chr'):
continue
chrom, pos, segs, pairs, add, dele = l.strip().split('\t')
for p in add.split():
try:
a, b = p.split(':')[1].split('-')
except:
print(p)
sys.exit()
if a == b:
autozygous += 1
continue
if f'{a},{b}' in seen or f'{b},{a}' in seen:
duplicates += 1
continue
else:
if a <= b:
seen.add(f'{a},{b}')
else:
seen.add(f'{b},{a}')
if a in pheno and b in pheno:
x = pheno[a]
y = pheno[b]
if x == 1 and y == 1:
cscs += 1
elif x == 1 and y == 0:
cscn += 1
elif x == 0 and y == 1:
cscn += 1
else:
cncn += 1
break
print(f'cscs: {cscs} cscn: {cscn} cncn: {cncn}')
print(f'duplicates: {duplicates}')
print(f'autozygous: {autozygous}')
print(f'total: {cscs + cscn + cncn}')
if __name__ == "__main__":
main()