#!/usr/bin/python import sys 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 = 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