erange version 4.0a dev release
[erange.git] / normalizeFinalExonic.py
index 6053e8077865c2cfbe3142bf8d3231da70d8688f..d5a6b4b954d4a9df6cb7b749c97c513e9394dafb 100755 (executable)
@@ -4,10 +4,12 @@ try:
 except:
     pass
 
-import sys, optparse
-from commoncode import readDataset
+import sys
+import optparse
+import ReadDataset
+from commoncode import getConfigParser, getConfigBoolOption, getConfigFloatOption
 
-print "%prog: version 3.5" % sys.argv[0]
+print "normalizeFinalExonic: version 3.6"
 
 def main(argv=None):
     if not argv:
@@ -15,15 +17,7 @@ def main(argv=None):
 
     usage = "usage: python %prog rdsfile expandedRPKMfile multicountfile outfile [--multifraction] [--multifold] [--minrpkm minThreshold] [--cache] [--withGID]"
 
-    parser = optparse.OptionParser(usage=usage)
-    parser.add_option("--multifraction", action="store_true", dest="reportfraction")
-    parser.add_option("--multifold", action="store_true", dest="reportFold")
-    parser.add_option("--minrpkm", type="float", dest="minThreshold")
-    parser.add_option("--cache", action="store_true", dest="doCache")
-    parser.add_option("--withGID", action="store_true", dest="writeGID")
-    parser.set_defaults(reportFraction=False, reportFold=False, minThreshold=0.,
-                        doCache=False, writeGID=False)
-
+    parser = makeParser(usage)
     (options, args) = parser.parse_args(argv[1:])
 
     if len(args) < 4:
@@ -40,6 +34,28 @@ def main(argv=None):
                          options.doCache, options.writeGID)
 
 
+def makeParser(usage=""):
+    parser = optparse.OptionParser(usage=usage)
+    parser.add_option("--multifraction", action="store_true", dest="reportfraction")
+    parser.add_option("--multifold", action="store_true", dest="reportFold")
+    parser.add_option("--minrpkm", type="float", dest="minThreshold")
+    parser.add_option("--cache", action="store_true", dest="doCache")
+    parser.add_option("--withGID", action="store_true", dest="writeGID")
+
+    configParser = getConfigParser()
+    section = "normalizeFinalExonic"
+    reportFraction = getConfigBoolOption(configParser, section, "multifraction", False)
+    reportFold = getConfigBoolOption(configParser, section, "reportFold", False)
+    minThreshold = getConfigFloatOption(configParser, section, "minThreshold", 0.)
+    doCache = getConfigBoolOption(configParser, section, "doCache", False)
+    writeGID = getConfigBoolOption(configParser, section, "writeGID", False)
+
+    parser.set_defaults(reportFraction=reportFraction, reportFold=reportFold, minThreshold=minThreshold,
+                        doCache=doCache, writeGID=writeGID)
+
+    return parser
+
+
 def normalizeFinalExonic(rdsfilename, expandedRPKMfilename, multicountfilename, outfilename,
                          reportFraction=False, reportFold=False, minThreshold=0., doCache=False,
                          writeGID=False):
@@ -53,7 +69,7 @@ def normalizeFinalExonic(rdsfilename, expandedRPKMfilename, multicountfilename,
     elif reportFold:
         print "reporting fold contribution of multireads"
 
-    RDS = readDataset(rdsfilename, verbose=True, cache=doCache, reportCount=False)
+    RDS = ReadDataset.ReadDataset(rdsfilename, verbose=True, cache=doCache, reportCount=False)
     uniqcount = RDS.getUniqsCount()
     splicecount = RDS.getSplicesCount()
     multicount = RDS.getMultiCount()