-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfamStruct.py
executable file
·57 lines (46 loc) · 1.45 KB
/
famStruct.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
#!/usr/bin/env python
import sys, os, gzip
import numpy as np
from famSummary import *
#quads = 'goodFam-noMZ.txt'
#quadsFn = 'quads.txt'
#quadsFn = 'multiplex.txt'
if len(sys.argv) <2:
print("Usage: famStruct.py <file with the list of families>")
exit()
famType = sys.argv[1]
if famType == 'Q':
fams = quads
elif famType == 'T':
fams = trios
elif famType == 'M':
fams = multiplex
else:
print("wrong famType", famType, "should be on of Q, T, M")
exit()
#with open(quadsFn, 'r') as f:
# for l in f:
# quadFams.append(l.strip('\n\r'))
GEN = {'1':'M','2':'F', 1:'M', 2:'F'}
AFF = {'1':'sib', '2':'prb', 1:'sib',2:'prb'}
ROLE = {'Mother':'mom', 'Father':'dad', 'Older Sibling':'sib1', 'Younger Sibling':'sib2', 'Proband':'prb'}
persons = {}
famCnt = {f:defaultdict(int) for f in fams}
for f in fams:
fam = cleanFMS[f]
for p in fam:
if ROLE[p[6]] == 'mom':
pId = p[1]+'.mo'
famCnt[f]['mom'] += 1
elif ROLE[p[6]] == 'dad':
pId = p[1]+'.fa'
famCnt[f]['dad'] += 1
elif AFF[p[5]] == 'prb':
famCnt[f]['prb'] += 1
pId = p[1]+'.p' + str(famCnt[f]['prb'])
elif AFF[p[5]] == 'sib':
famCnt[f]['sib'] += 1
pId = p[1]+'.s' + str(famCnt[f]['sib'])
persons[p[0]] = [p[0], p[1], pId,GEN[p[4]]]
for p,v in sorted(list(persons.items()), key=lambda x: [x[1][1],x[1][2]]):
print('\t'.join(persons[p]))