6 print "combineRPKMs: version 1.1"
16 from commoncode import getConfigParser, getConfigBoolOption
23 usage = "usage: python %prog firstRPKM expandedRPKM finalRPKM combinedOutfile [--withmultifraction]"
24 parser = makeParser(usage)
25 (options, args) = parser.parse_args(argv[1:])
32 expandedfile = args[1]
36 combineRPKMs(firstfile, expandedfile, finalfile, outfile, options.doFraction)
39 def makeParser(usage=""):
40 parser = optparse.OptionParser(usage=usage)
41 parser.add_option("--withmultifraction", action="store_true", dest="doFraction")
43 configParser = getConfigParser()
44 section = "combineRPKMs"
45 doFraction = getConfigBoolOption(configParser, section, "doFraction", False)
47 parser.set_defaults(doFraction=doFraction)
52 def combineRPKMs(firstfileName, expandedfileName, finalfileName, outfileName, doFraction=False):
55 firstfile = open(firstfileName)
56 for line in firstfile:
57 fields = line.strip().split()
58 firstDict[fields[1]] = fields[-1]
64 expandedfile = open(expandedfileName)
65 for line in expandedfile:
66 fields = line.strip().split()
67 expandedDict[fields[1]] = fields[-1]
68 gidDict[fields[1]] = fields[0]
73 header = "gid\tRNAkb\tgene\tfirstRPKM\texpandedRPKM\tfinalRPKM\tfractionMulti\n"
75 header = "gid\tRNAkb\tgene\tfirstRPKM\texpandedRPKM\tfinalRPKM\n"
77 outfile = open(outfileName, "w")
80 finalfile = open(finalfileName)
81 for line in finalfile:
82 fields = line.strip().split()
86 firstRPKM = firstDict.get(gene, "")
87 outputFields = [gidDict[gene], rnakb, gene, firstRPKM, expandedDict[gene], finalRPKM]
91 outputFields.append(fraction)
93 outline = "%s\n" % string.join(outputFields, "\t")
94 outfile.write(outline)
100 if __name__ == "__main__":