first pass cleanup of cistematic/genomes; change bamPreprocessing
[erange.git] / fraction.py
1 #
2 #  fraction.py
3 #  ENRAGE
4 #
5
6 try:
7     import psyco
8     psyco.full()
9 except:
10     pass
11
12 import sys
13 from random import random
14
15
16 print "fraction: version 1.1"
17
18 def main(argv=None):
19     if not argv:
20         argv = sys.argv
21
22     if len(sys.argv) < 4:
23         print "usage: python %s fraction infile outfile" % sys.argv[0]
24         sys.exit(1)
25
26     fraction = float(sys.argv[1])
27     infile = sys.argv[2]
28     outfile = argv[3]
29
30     doFraction(fraction, infile, outfile)
31
32
33 def doFraction(fraction, inFileName, outFileName):
34     infile = open(inFileName)
35     outfile = open(outFileName, "w")
36
37     totalIndex = 0
38     fractionIndex = 0
39     for line in infile:
40         totalIndex += 1
41         if random() <= fraction:
42             outfile.write(line)
43             fractionIndex += 1
44
45     infile.close()
46     outfile.close()
47
48     print "%d / %d = %.2f" % (fractionIndex, totalIndex, float(fractionIndex) / totalIndex)
49
50
51 if __name__ == "__main__":
52     main(sys.argv)