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
|
#!/usr/bin/python
import sys
import re
sk_file = open(sys.argv[1])
labels = sk_file.readline().strip().split(',')
limbs = [('RHML','LHML'),('RRML','LRML'),('RFML','LFML'),('RTML','LTML'),('RIBL','LIBL'),('RAcH','LAcH')]
index = map(lambda x: (labels.index(x[0]),labels.index(x[1])),limbs)
sid = 1
for line in sk_file:
line = ''.join(re.split('"[^"]+"',line.strip())).split(',')
try:
lidx = map(lambda x: (line[x[0]],line[x[1]]),index)
except:
continue
out = [str(sid)]
for (l,r) in lidx:
if l == r != '':
out += [l]
elif l != r:
if l == '':
out += [r]
elif r == '':
out += [l]
else:
out += [str((float(l)+float(r))/2)]
else:
out = None
break
if out:
print ','.join(out)
sid += 1
|