def combineRPKMs(firstfileName, expandedfileName, finalfileName, outfileName, doFraction=False):
- firstDict = {}
- firstfile = open(firstfileName)
- for line in firstfile:
- fields = line.strip().split()
- firstDict[fields[1]] = fields[-1]
-
- firstfile.close()
-
- expandedDict = {}
- gidDict = {}
- expandedfile = open(expandedfileName)
- for line in expandedfile:
- fields = line.strip().split()
- expandedDict[fields[1]] = fields[-1]
- gidDict[fields[1]] = fields[0]
-
- expandedfile.close()
+ firstDict = getRPKMDict(firstfileName)
+ gidDict, expandedDict = getRPKMDict(expandedfileName, getGIDDict=True)
if doFraction:
header = "gid\tRNAkb\tgene\tfirstRPKM\texpandedRPKM\tfinalRPKM\tfractionMulti\n"
outfile.close()
+def getRPKMDict(rpkmFileName, getGIDDict=False):
+ gidDict = {}
+ rpkmDict = {}
+ rpkmFile = open(rpkmFileName)
+ for line in rpkmFile:
+ fields = line.strip().split()
+ rpkmDict[fields[1]] = fields[-1]
+ if getGIDDict:
+ gidDict[fields[1]] = fields[0]
+
+ rpkmFile.close()
+
+ if getGIDDict:
+ return gidDict, rpkmDict
+ else:
+ return rpkmDict
+
+
if __name__ == "__main__":
- main(sys.argv)
\ No newline at end of file
+ main(sys.argv)