20 usage = "usage: python %prog firstRPKM expandedRPKM finalRPKM combinedOutfile [--withmultifraction]"
21 parser = optparse.OptionParser(usage=usage)
22 parser.add_option("--withmultifraction", action="store_true", dest="doFraction")
23 parser.set_defaults(doFraction=False)
24 (options, args) = parser.parse_args(argv[1:])
31 expandedfile = args[1]
35 combineRPKMs(firstfile, expandedfile, finalfile, outfile, options.doFraction)
38 def combineRPKMs(firstfileName, expandedfileName, finalfileName, outfileName, doFraction=False):
39 firstfile = open(firstfileName)
40 expandedfile = open(expandedfileName)
41 finalfile = open(finalfileName)
42 outfile = open(outfileName, "w")
48 for line in firstfile:
49 fields = line.strip().split()
50 firstDict[fields[1]] = fields[-1]
54 for line in expandedfile:
55 fields = line.strip().split()
56 expandedDict[fields[1]] = fields[-1]
57 gidDict[fields[1]] = fields[0]
62 header = "gid\tRNAkb\tgene\tfirstRPKM\texpandedRPKM\tfinalRPKM\tfractionMulti\n"
64 header = "gid\tRNAkb\tgene\tfirstRPKM\texpandedRPKM\tfinalRPKM\n"
68 for line in finalfile:
69 fields = line.strip().split()
73 firstRPKM = firstDict.get(gene, "")
74 outline = "%s\t%s\t%s\t%s\t%s\t%s" % (gidDict[gene], rnakb, gene, firstRPKM, expandedDict[gene], finalRPKM)
78 outline += "\t%s" % fraction
80 outfile.write(outline + '\n')
86 if __name__ == "__main__":