15 from commoncode import getConfigParser, getConfigOption, getConfigBoolOption
17 print "combinerds: version 1.2"
24 usage = "usage: python %s destinationRDS inputrds1 [inputrds2 ....] [-table table_name] [--init] [--initrna] [--index] [--cache pages]" % argv[0]
25 parser = makeParser(usage)
26 (options, args) = parser.parse_args(argv[1:])
35 combinerds(datafile, infileList, options.tableList, options.withFlag, options.doIndex, options.cachePages, options.doInit, options.initRNA)
41 parser = optparse.OptionParser(usage=usage)
42 parser.add_option("--table", action="append", dest="tablelist")
43 parser.add_option("--init", action="store_true", dest="doInit")
44 parser.add_option("--initrna", action="store_true", dest="initRNA")
45 parser.add_option("--index", action="store_true", dest="doIndex")
46 parser.add_option("--cache", type="int", dest="cachePages")
47 parser.add_option("--flag", dest="withFlag")
49 configParser = getConfigParser()
50 section = "combinerds"
51 doInit = getConfigBoolOption(configParser, section, "doInit", False)
52 initRNA = getConfigBoolOption(configParser, section, "initRNA", False)
53 doIndex = getConfigBoolOption(configParser, section, "doIndex", False)
54 cachePages = getConfigOption(configParser, section, "cachePages", None)
55 withFlag = getConfigOption(configParser, section, "withFlag", "")
57 parser.set_defaults(tableList=[], doInit=doInit, initRNA=initRNA, doIndex=doIndex, cachePages=cachePages,
63 def combinerds(datafile, infileList, tableList=[], withFlag="", doIndex=False, cachePages=None, doInit=False, initRNA=False):
65 print "destination RDS: %s" % datafile
72 if cachePages is not None:
77 rds = ReadDataset.ReadDataset(datafile, verbose=True, cache=doCache, initialize=doInit, datasetType=datasetType)
78 if cachePages > rds.getDefaultCacheSize():
79 rds.setDBcache(cachePages)
81 cachePages = rds.getDefaultCacheSize()
84 tableList = rds.getTables()
87 print "restrict to flag = %s" % withFlag
89 metaDict = rds.getMetadata()
90 if "numberImports" not in metaDict:
92 rds.insertMetadata([("numberImports", "0")])
94 origIndex = int(metaDict["numberImports"])
97 for inputfile in infileList:
98 dbName = "input%s" % str(index)
99 rds.attachDB(inputfile, dbName)
100 for table in tableList:
101 print "importing table %s from file %s" % (table, inputfile)
104 dbColumns = "NULL, '%s' || readID, chrom, start, stop, sense, weight, flag, mismatch" % dbName
105 elif table == "multi":
106 dbColumns = "NULL, '%s' || readID, chrom, start, stop, sense, weight, flag, mismatch" % dbName
107 elif table == "splices":
108 dbColumns = "NULL, '%s' || readID, chrom, startL, stopL, startR, stopR, sense, weight, flag, mismatch" % dbName
110 if table == "metadata":
111 dbColumns = "name, value || ' (import_%d)'" % index
112 rds.importFromDB(dbName, table, dbColumns)
114 rds.importFromDB(dbName, table, dbColumns, withFlag)
117 rds.insertMetadata([("import_%s" % str(index), "%s %s" % (inputfile, str(tableList)))])
120 rds.updateMetadata("numberImports", index, origIndex)
122 print "building index...."
124 rds.buildIndex(cachePages)
129 rds.saveCacheDB(datafile)
132 if __name__ == "__main__":