-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeFams.py
executable file
·74 lines (63 loc) · 2.04 KB
/
makeFams.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import numpy as np
from time import time
import sys,os
from collections import defaultdict
fn = os.environ['SPARKMASTERTABLE']
pFn = 'persons.txt'
persons = {}
n = 0
with open(pFn, 'r') as f:
for l in f:
persons[l.strip('\n\r')] = n
n += 1
hd = 'sp_id sf_id father_id mother_id gender asd_flag role age(year)'.split(' ')
fam = defaultdict(list)
quads = defaultdict(list)
class P:
pass
with open(fn, 'r') as f:
HD = {h:i for i,h in enumerate(f.readline().strip('\n\r').split('\t'))}
for l in f:
cs = l.strip('\n\r').split('\t')
rec = {h:cs[HD[h]] for h in hd}
p = P()
p.famId = rec['sf_id']
p.id = rec['sp_id']
p.dad = rec['father_id']
p.mom = rec['mother_id']
p.role = rec['role']
p.gender = rec['gender']
p.age = rec['age(year)']
p.aff = rec['asd_flag']
p.n = persons[p.id] if p.id in persons else -1
fam[rec['sf_id']].append(p)
def roleN(f, role):
return sum([1 for p in f if p.role == role])
for fId,f in list(fam.items()):
momN = roleN(f,'Mother')
dadN = roleN(f, 'Father')
unAffParents = sum([1 for p in f if (p.role == 'Father' and p.aff == '1')
or (p.role == 'Mother' and p.aff == '1')])
prbN = sum([1 for p in f if p.role == 'Proband' and p.aff == '2'])
unAffChildren = sum([1 for p in f if (p.aff == '1' and 'Sibling' in p.role)])
weirdN = sum([1 for p in f if not (p.role == 'Mother'
or p.role == 'Father'
or p.role == 'Proband'
or p.role == 'Older Sibling'
or p.role == 'Younger Sibling')])
N = len(f)
genN = sum([1 for p in f if p.n > -1])
if (momN == 1 and
dadN == 1 and
weirdN == 0 and
unAffParents == 2 and
unAffChildren == 1 and
N == 4 and
prbN == 1 and
genN == 4):
quads[fId] = f
"""
for q in quads:
print(q)
"""