Esempio n. 1
0
     doneEnsembl.append(ensemblID)
     if isAmigo:
         eGOs = amiGO.get(hugoID, [])
     else:
         eGOs = uniGO.get(ensemblID, [])
     for termID in eGOs:
         myGOs.setdefault(termID, []).append(ensemblID)
         try:
             myLevels.extend(list(levels[termID].keys()))
         except KeyError:
             #print >>sys.stderr, termID
             continue
         GOs[termID] = GOs.get(termID, 0) + 1
         if not args.naive:
             if termID not in GOadjusted:
                 GOadjusted[termID] = GO.getLevelIds(termID,
                                                     args.level, levels)
             #print myLevels[-1], termID, GOadjusted[termID]
             for adjustedID in GOadjusted[termID]:
                 myAdjusted[adjustedID] = myAdjusted.get(adjustedID, 0) + 1
                 myGOs.setdefault(adjustedID, []).append(ensemblID)
 GOsCnt = []
 myAdjustedCnt = []
 for id, cnt in list(GOs.items()):
     GOsCnt.append(id + "/" + str(cnt))
 if not args.naive:
     for id, cnt in list(myAdjusted.items()):
         myAdjustedCnt.append(id)
 myLevels = [str(x) for x in myLevels]
 if not args.naive:
     print("\t".join([str(chro), str(startPos), " ".join(GOsCnt),
                      " ".join(myLevels), " ".join(myAdjustedCnt)]))
Esempio n. 2
0
import MEGA
from MEGA import GO
import pickle
import bz2

onts = {}
isa = {}
levels = {}
namespaces = {}
for rec in GO.parse(bz2.open(MEGA.GOFile, 'rt', encoding='utf-8')):
    id = rec["id"][0]
    onts[id] = rec
    namespaces.setdefault(rec["namespace"][0], []).append(id)
    if "is_a" in rec:
        for ref in rec["is_a"]:
            isa.setdefault(id, []).append(ref[0])
    else:
        levels[id] = {0: set()}

cisa = dict(isa)
while len(cisa) > 0:
    dels = []
    for id, owners in list(cisa.items()):
        levels.setdefault(id, {})
        for owner in owners:
            if owner not in cisa:
                ownerLevels = list(levels[owner].keys())
                for level in ownerLevels:
                    levels[id].setdefault(level + 1, set()).add(owner)
                cisa[id].remove(owner)
        if len(cisa[id]) == 0: