def getLineageInfo(blastHits, db=None): """ For each taxID present in blastHits, walk through the taxonomic tree, starting from that taxID, and for each node, store the information about the node (rank, taxID, parent_taxID, scientificName). @param blastHits: A L{dark.blast.BlastHits} instance. @param db: A database connection, with C{cursor} and C{close} methods. @return: A C{dict} where each key is a taxID and the value is the taxonomic information """ if db is None: openedDb = True db = mysql.getDatabaseConnection() else: openedDb = False cursor = db.cursor() taxIDLookUpDict = {} for title in blastHits.titles: taxID = blastHits.titles[title]['taxID'] if taxID not in taxIDLookUpDict: taxIDLookUpDict[taxID] = _getLineageInfoPerTaxID(taxID, cursor) cursor.close() if openedDb: db.close() return taxIDLookUpDict
def __init__(self): self._db = mysql.getDatabaseConnection() self._cursor = self._db.cursor() self._cache = {}