Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_id2gos(file_id2gos, godag, name2go, name2num):
"""Get annotations"""
if os.path.exists(file_id2gos):
return IdToGosReader(file_id2gos, godag=godag).get_id2gos('CC')
go2genes = cx.defaultdict(set)
genenum = 0
for name, qty in name2num.items():
goid = name2go[name]
for _ in range(qty):
go2genes[goid].add(genenum)
genenum += 1
id2gos = get_b2aset(go2genes)
IdToGosReader.wr_id2gos(file_id2gos, id2gos)
return id2gos
def _get_id2gos(file_id2gos, godag, name2go, name2num):
"""Get annotations"""
if os.path.exists(file_id2gos):
return IdToGosReader(file_id2gos, godag=godag).get_id2gos('CC')
go2genes = cx.defaultdict(set)
genenum = 0
for name, qty in name2num.items():
goid = name2go[name]
for _ in range(qty):
go2genes[goid].add(genenum)
genenum += 1
id2gos = get_b2aset(go2genes)
IdToGosReader.wr_id2gos(file_id2gos, id2gos)
return id2gos
def _get_id2gos(file_id2gos, godag, name2go):
"""Get annotations"""
if os.path.exists(file_id2gos):
return IdToGosReader(file_id2gos, godag=godag).get_id2gos('CC')
id2num = {
name2go['A']: 1,
name2go['B']: 1,
name2go['C']: 10,
name2go['D']: 10,
name2go['E']: 10,
name2go['F']: 10,
name2go['G']: 10,
name2go['H']: 10,
name2go['I']: 18,
}
go2genes = cx.defaultdict(set)
genenum = 0
for goid, qty in id2num.items():
for _ in range(qty):
go2genes[goid].add(genenum)
def _get_id2gos(file_id2gos, godag, name2go):
"""Get annotations"""
if os.path.exists(file_id2gos):
return IdToGosReader(file_id2gos, godag=godag).get_id2gos('CC')
id2num = {
name2go['A']: 10,
name2go['B']: 10,
name2go['C']: 10,
name2go['D']: 10,
name2go['E']: 10,
name2go['F']: 10,
name2go['G']: 10,
name2go['H']: 10,
name2go['I']: 30,
name2go['L']: 30,
name2go['M']: 20,
name2go['N']: 30,
}
go2genes = cx.defaultdict(set)
genenum = 0
name2go['C']: 10,
name2go['D']: 10,
name2go['E']: 10,
name2go['F']: 10,
name2go['G']: 10,
name2go['H']: 10,
name2go['I']: 18,
}
go2genes = cx.defaultdict(set)
genenum = 0
for goid, qty in id2num.items():
for _ in range(qty):
go2genes[goid].add(genenum)
genenum += 1
id2gos = get_b2aset(go2genes)
IdToGosReader.wr_id2gos(file_id2gos, id2gos)
return id2gos
def __init__(self, filename=None, **kws):
self.id2gos = None # ID to GO ID set as loaded from annotations file
super(IdToGosReader, self).__init__('id2gos', filename,
godag=kws.get('godag'),
namespaces=kws.get('namespaces'))
# kws get_objanno: taxids hdr_only prt allow_missing_symbol
anno_type = get_anno_desc(fin_anno, anno_type)
if anno_type is not None:
if anno_type == 'gene2go':
# kws: taxid taxids
kws_ncbi = {k:kws[k] for k in Gene2GoReader.exp_kws.intersection(kws.keys())}
return Gene2GoReader(fin_anno, **kws_ncbi)
if anno_type == 'gaf':
kws_gaf = {k:kws[k] for k in GafReader.exp_kws.intersection(kws.keys())}
return GafReader(fin_anno, **kws_gaf)
if anno_type == 'gpad':
kws_gpad = {k:kws[k] for k in GpadReader.exp_kws.intersection(kws.keys())}
return GpadReader(fin_anno, **kws_gpad)
if anno_type == 'id2gos':
kws_id2go = {k:kws[k] for k in IdToGosReader.exp_kws.intersection(kws.keys())}
return IdToGosReader(fin_anno, **kws_id2go)
raise RuntimeError('UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'.format(
F=fin_anno, D=anno_type))