snapshot of 4.0a development. initial git repo commit
[erange.git] / transcripts.py
1 #
2 #  transcripts.py
3 #  ENRAGE
4 #
5 #  Created by Ali Mortazavi on 1/25/08.
6 #
7 """ usage: python %s rpkmFile outFile [--transcriptome size] [--cells count] [--efficiency fraction]
8            where transcriptome size is in Gbp, cell count is in arbitrary units and efficiency is a fraction
9 """
10
11 import sys, optparse
12
13 def main(argv=None):
14     if not argv:
15         argv = sys.argv
16
17     print "%prog: version 3.0"
18     usage = "usage: python %prog rpkmFile outFile [options]"
19
20     parser = optparse.OptionParser(usage=usage)
21     parser.add_option("--transcriptome", type="float", dest="tSize",
22                       help="transcriptome size in Gbp [default 200000.0]")
23     parser.add_option("--cells", type="float", dest="cellCount",
24                       help="arbitrary units [default 1e6]")
25     parser.add_option("--efficiency", type="float", dest="efficiency",
26                       help="fraction [default 0.3]")
27     parser.set_defaults(tSize=200000.0, cellCount=1e6, efficiency=0.3)
28     (options, args) = parser.parse_args(argv[1:])
29
30     if len(args) < 2:
31         print usage
32         sys.exit(1)
33
34     infile = args[0]
35     outfile = args[1]
36     
37     transcripts(infile, outfile, options.tSize, options.cellCount, options.efficiency)
38
39
40 def transcripts(infilename, outfilename, tSize=200000, cellCount=1e6, efficiency=0.3):
41     infile = open(infilename)
42     outfile = open(outfilename, "w")
43     for line in infile:
44         fields = line.strip().split()
45         rpkm = float(fields[-1])
46         transcripts = rpkm * tSize
47         transPerCell = transcripts / cellCount / efficiency
48         outfile.write("%s\t%.1f\t%.1f\n" % (fields[0], transcripts, transPerCell))
49     infile.close()
50     outfile.close()
51
52 if __name__ == "__main__":
53     main(sys.argv)