13 from commoncode import readDataset
15 print "%prog: version 2.7"
22 usage = "usage: python %prog rdsfile [propertyName1::propertyValue1] ... [propertyNameN::propertyValueN] [options]"
24 parser = optparse.OptionParser(usage=usage)
25 parser.add_option("--defaultcache", type="int", dest="cacheVal")
26 parser.add_option("--index", action="store_true", dest="buildIndex")
27 parser.add_option("--dropindex", action="store_true", dest="dropIndex")
28 parser.add_option("--nocount", action="store_false", dest="doCount")
29 parser.add_option("--complexity", action="store_true", dest="doComplexity")
30 parser.add_option("--reset", action="store_true", dest="resetFlags")
31 parser.add_option("--initrna", action="store_true", dest="rnaDataType")
32 parser.add_option("--cache", type="int", dest="cachePages")
33 parser.set_defaults(cacheVal=0, buildIndex=False, dropIndex=False, doCount=True,
34 doComplexity=False, resetFlags=False, rnaDataType=False,
37 (options, args) = parser.parse_args(argv[1:])
41 print "where the optional metadata name::value pairs are added to the existing dataset"
49 (pname, pvalue) = arg.strip().split("::")
50 print "adding %s : %s" % (pname, pvalue)
51 propertyList.append((pname, pvalue))
53 rdsmetadata(datafile, propertyList, options.cacheVal, options.buildIndex,
54 options.dropIndex, options.doCount, options.doComplexity,
55 options.resetFlags, options.rnaDataType, options.cachePages)
58 def rdsmetadata(datafile, propertyList=[], cacheVal=0, buildIndex=False,
59 dropIndex=False, doCount=True, doComplexity=False, resetFlags=False,
60 rnaDataType=False, cachePages=-1):
67 rds = readDataset(datafile, initialize=True, datasetType="RNA", verbose=True, cache=doCache)
69 rds = readDataset(datafile, verbose=True, reportCount=doCount, cache=doCache)
71 if cachePages > rds.getDefaultCacheSize():
72 rds.setDBcache(cachePages)
75 rds.setDBcache(cacheVal, default=True)
76 print "set default cache size to %d pages" % cacheVal
79 print "clearing read flags"
86 print "could not drop index"
89 print "building index...."
91 rds.buildIndex(cacheVal)
96 print "calculating uniq read complexity..."
97 uniqs = rds.getUniqsCount(distinct=False)
98 distincts = rds.getUniqsCount(distinct=True)
99 print "%d distincts / %d uniqs = %.2f" % (distincts, uniqs, float(distincts) / uniqs)
101 if len(propertyList) > 0:
102 rds.insertMetadata(propertyList)
105 if __name__ == "__main__":