fix bug in RegionFinder.updateControlStatistics that was causing crash
[erange.git] / binstocdf.py
1 import sys
2 import string
3
4 print "binstocdf: version 1.1"
5
6 def main(argv=None):
7     if not argv:
8         argv = sys.argv
9
10     if len(argv) < 3:
11         print "usage: python %s infile outfile" % sys.argv[0]
12         sys.exit(1)
13
14     infilename = argv[1]
15     outfilename = argv[2]
16
17     binToCDF(infilename, outfilename)
18
19
20 def binToCDF(infilename, outfilename):
21     infile = open(infilename)
22     outfile = open(outfilename, "w")
23
24     for line in infile:
25         fields = line.strip().split()
26         if len(fields) < 4:
27             continue
28
29         total = int(fields[2])
30         if total == 0:
31             outfile.write(line)
32             continue
33
34         outputFields = fields[:4]
35         runningTotal = 0
36         for bin in fields[4:]:
37             runningTotal += int(bin)
38             percent = 100 * runningTotal / total
39             outputFields.append("%d" % percent)
40
41         outputLine = string.join(outputFields, "\t")
42         outfile.write("%s\n" % outputLine)
43
44     infile.close()
45     outfile.close()
46
47 if __name__ == "__main__":
48     main(sys.argv)