def get_agent_from_grounding(grounding, up_web_fallback=False): """Return an INDRA Agent based on a grounding annotation.""" db_ns, db_id = grounding.split(':') # Assume UniProt or RefSeq IDs assert db_ns in {'uniprotkb', 'refseq', 'ddbj/embl/genbank'}, db_ns if db_ns == 'uniprotkb': if '-' in db_id: up_id, feat_id = db_id.split('-') # Assume it's a feature ID assert feat_id.startswith('PRO'), feat_id db_refs = {'UP': up_id, 'UPPRO': feat_id} else: db_refs = {'UP': db_id} elif db_ns == 'refseq': db_refs = {'REFSEQ_PROT': db_id} else: db_refs = {'GENBANK': db_id} agent = Agent(db_id, db_refs=db_refs) standardized = standardize_agent_name(agent) if up_web_fallback: # Handle special case of unreviewed UP entries if not standardized and 'UP' in db_refs: name = uniprot_client.get_gene_name(db_refs['UP'], web_fallback=True) if name: agent.name = name return agent
def get_virus_agent(name): db_ns, db_id = virus_grounding_map[name].split(':') db_refs = {db_ns: db_id} ag = Agent(name, db_refs=db_refs) mapped_label = virus_label_map.get('%s:%s' % (db_ns, db_id)) if mapped_label: ag.name = mapped_label else: standardize_agent_name(ag, standardize_refs=True) return ag