X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=erange.git;a=blobdiff_plain;f=getSNPGeneInfo.py;h=0fbc6795121db515e27151902531f0962aa05715;hp=307413b866e804e831e2288a14a6c0984a55b5bf;hb=HEAD;hpb=5e4ae21098dba3d1edcf11e7279da0d84c3422e4 diff --git a/getSNPGeneInfo.py b/getSNPGeneInfo.py index 307413b..0fbc679 100755 --- a/getSNPGeneInfo.py +++ b/getSNPGeneInfo.py @@ -16,9 +16,9 @@ import sys import optparse import string from cistematic.core import genesIntersecting, cacheGeneDB, uncacheGeneDB -from cistematic.core.geneinfo import geneinfoDB +from commoncode import getGeneInfoDict, getConfigParser, getConfigBoolOption, getConfigIntOption -print "%prog: version 4.5" +print "getSNPGeneInfo: version 4.6" def main(argv=None): if not argv: @@ -26,11 +26,7 @@ def main(argv=None): usage = "usage: python %prog genome snpsfile rpkmfile dbsnp_geneinfo_outfile [--cache] [--withoutsense] [--flank bp]" - parser = optparse.OptionParser(usage=usage) - parser.add_option("--cache", action="store_true", dest="cachePages") - parser.add_option("--withoutsense", action="store_false", dest="withSense") - parser.add_option("--flank", type="int", dest="flankBP") - parser.set_defaults(doCache=False, withSense=True, flankBP=0) + parser = makeParser(usage) (options, args) = parser.parse_args(argv[1:]) if len(args) < 4: @@ -45,6 +41,23 @@ def main(argv=None): writeSNPGeneInfo(genome, infilename, rpkmfilename, outfilename, options.doCache, options.withSense, options.flankBP) +def makeParser(usage=""): + parser = optparse.OptionParser(usage=usage) + parser.add_option("--cache", action="store_true", dest="cachePages") + parser.add_option("--withoutsense", action="store_false", dest="withSense") + parser.add_option("--flank", type="int", dest="flankBP") + + configParser = getConfigParser() + section = "getSNPGeneInfo" + doCache = getConfigBoolOption(configParser, section, "doCache", False) + withSense = getConfigBoolOption(configParser, section, "withSense", True) + flankBP = getConfigIntOption(configParser, section, "flankBP", 0) + + parser.set_defaults(doCache=doCache, withSense=withSense, flankBP=flankBP) + + return parser + + def writeSNPGeneInfo(genome, infilename, rpkmfilename, outfilename, doCache=False, withSense=True, flankBP=0): outList = getSNPGeneInfo(genome, infilename, rpkmfilename, doCache, withSense, flankBP) @@ -85,12 +98,9 @@ def getSNPGeneInfo(genome, infilename, rpkmfilename, doCache=False, withSense=Tr if doCache: cacheGeneDB(genome) - idb = geneinfoDB(cache=True) print "cached %s" % genome - else: - idb = geneinfoDB() - geneinfoDict = idb.getallGeneInfo(genome) + geneinfoDict = getGeneInfoDict(genome, cache=doCache) geneDict = {} if flankBP > 0: @@ -106,7 +116,7 @@ def getSNPGeneInfo(genome, infilename, rpkmfilename, doCache=False, withSense=Tr symbol = "LOC%s" % geneID geneDescriptor = (symbol, geneID) - if geneDict.has_key(geneDescriptor): + if geneDescriptor in geneDict: geneDict[geneDescriptor]["position"].append(pos) else: geneDict[geneDescriptor] = {"position": [pos], @@ -157,7 +167,7 @@ def getSNPGeneInfoList(geneDict, snpDict, rpkmDict, withSense): "geneID": geneID} rpkm = "N\A" - if rpkmDict.has_key(geneID): + if geneID in rpkmDict: rpkm = str(rpkmDict[geneID]) snpGeneInfoDict["rpkm"] = rpkm