12 if len(sys.argv) != 4 and len(sys.argv) != 5:
13 print "usage: ./meanstep.py <datadir> <matching col 1>,...,<matching col n> <mean col 1>,...,<mean col n> [<outdir>]"
16 matchcols = sys.argv[2].split(",")
17 meancols = sys.argv[3].split(",")
19 if len(sys.argv) == 5:
25 for root, dirs, filenames in os.walk(sys.argv[1]):
30 if not f[:-4] in results:
32 print "Found new fileid: " + f[:-4]
34 with open(root + "/" + f) as inf:
39 linecols = line.split()
41 for imatchcol in range(0,len(matchcols)):
42 matchkey = matchkey + linecols[int(matchcols[imatchcol])-1]
44 if not matchkey in results[f[:-4]]:
45 results[f[:-4]][matchkey] = linecols + [1]
47 results[f[:-4]][matchkey][ len(results[f[:-4]][matchkey]) - 1 ] = \
48 results[f[:-4]][matchkey][ len(results[f[:-4]][matchkey]) - 1 ] + 1
50 for imeancol in range(0,len(meancols)):
51 results[f[:-4]][matchkey][int(meancols[imeancol])-1] = \
52 float(results[f[:-4]][matchkey][int(meancols[imeancol])-1]) + \
53 float(linecols[int(meancols[imeancol])-1])
55 for fileid in results:
56 print "\n[" + fileid + "]"
59 outfile = open(outdir + "/" + fileid + "_meanstep.dat", "w+")
61 for matchkey in results[fileid]:
62 for imeancol in range(0,len(meancols)):
63 results[fileid][matchkey][int(meancols[imeancol])-1] = \
64 float(results[fileid][matchkey][int(meancols[imeancol])-1]) / \
65 results[fileid][matchkey][ len(results[f[:-4]][matchkey]) - 1 ]
67 for icol in range(0,len(results[fileid][matchkey])-1):
68 sys.stdout.write(str(results[fileid][matchkey][icol]))
70 outfile.write(str(results[fileid][matchkey][icol]));
72 if icol != len(results[fileid][matchkey])-2:
73 sys.stdout.write("\t")