Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if merge:
groups = group_and_sort_statements(stmts)
for group in groups:
group_stmts = group[-1]
stmt_type = group[0][-1]
agent_names = group[0][1]
if len(agent_names) < 2:
continue
if stmt_type == 'Influence':
stmt = get_class_from_name(stmt_type, Statement)(
Event(Concept(agent_names[0])),
Event(Concept(agent_names[1])))
elif stmt_type == 'Conversion':
stmt = get_class_from_name(stmt_type, Statement)(
Agent(agent_names[0]),
[Agent(ag) for ag in agent_names[1]],
[Agent(ag) for ag in agent_names[2]])
else:
try:
stmt = get_class_from_name(stmt_type, Statement)(
Agent(agent_names[0]), Agent(agent_names[1]))
except ValueError:
stmt = get_class_from_name(stmt_type, Statement)(
[Agent(ag_name) for ag_name in agent_names])
ea = EnglishAssembler([stmt])
sentence = ea.make_model()
stmt_hashes = [gr_st.get_hash() for gr_st in group_stmts]
url_param = parse.urlencode(
{'stmt_hash': stmt_hashes, 'source': 'model_statement',
'model': self.model.name}, doseq=True)
link = f'/evidence?{url_param}'
sentences.append((link, sentence, ''))
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 _agent_from_ns_id(ag_ns, ag_id):
# Add the ID as a placeholder name
agent = Agent(ag_id)
# If we have a proper grounding, add to db_refs
if ag_id is not None:
agent.db_refs[ag_ns] = ag_id
# Now standardize db_refs and set standardized name
standardize_agent_name(agent, standardize_refs=True)
agent.db_refs['TEXT'] = agent.name
return agent
def _assemble_agent_str(agent):
"""Assemble an Agent object to AgentWithCoordinates object."""
agent_str = agent.name
# Only do the more detailed assembly for molecular agents
if not isinstance(agent, ist.Agent):
return AgentWithCoordinates(agent_str, agent.name, agent.db_refs)
# Handle mutation conditions
if agent.mutations:
is_generic = False
mut_strs = []
for mut in agent.mutations:
res_to = mut.residue_to if mut.residue_to else ''
res_from = mut.residue_from if mut.residue_from else ''
pos = mut.position if mut.position else ''
mut_str = '%s%s%s' % (res_from, pos, res_to)
# If this is the only mutation and there are no details
# then this is a generic mutant
if not mut_str and len(agent.mutations) == 1:
is_generic = True
break
def __init__(self, name, mods=None, activity=None,
bound_conditions=None, mutations=None,
location=None, db_refs=None):
super(Agent, self).__init__(name, db_refs=db_refs)
if mods is None:
self.mods = []
# Promote to list
elif isinstance(mods, ModCondition):
self.mods = [mods]
else:
self.mods = mods
if bound_conditions is None:
self.bound_conditions = []
# Promote to list
elif isinstance(bound_conditions, BoundCondition):
self.bound_conditions = [bound_conditions]
else:
self.bound_conditions = bound_conditions
ns, _id = None, None
else:
name = term['entry_name']
ns, _id = term['db'], term['id']
db_refs = {'TEXT': txt}
if ns is not None and _id is not None:
db_refs[ns] = _id
if ns == 'HGNC':
up_id = hgnc_client.get_uniprot_id(_id)
if up_id:
db_refs['UP'] = up_id
name = hgnc_client.get_hgnc_name(_id)
elif ns == 'FPLX':
name = _id
return Agent(name, db_refs=db_refs)
def get_grounded_agent(gene_name):
"""Return a grounded Agent based on an HGNC symbol."""
db_refs = {'TEXT': gene_name}
if gene_name in hgnc_map:
gene_name = hgnc_map[gene_name]
hgnc_id = hgnc_client.get_hgnc_id(gene_name)
if not hgnc_id:
hgnc_id = hgnc_client.get_current_hgnc_id(gene_name)
if hgnc_id:
db_refs['HGNC'] = hgnc_id
up_id = hgnc_client.get_uniprot_id(hgnc_id)
if up_id:
db_refs['UP'] = up_id
agent = Agent(gene_name, db_refs=db_refs)
return agent
def get_agent(raw_name, entrez_id):
db_refs = {'TEXT': raw_name, 'EGID': entrez_id}
logger.debug('Looking up grounding data for Entrez #%s' % entrez_id)
hgnc_id = hgc.get_hgnc_from_entrez(entrez_id)
if hgnc_id:
db_refs['HGNC'] = hgnc_id
agent = Agent(raw_name, db_refs=db_refs)
standardize_agent_name(agent, standardize_refs=True)
return agent
def get_agent_from_upid(up_id):
"""Get an Agent based on a UniProt ID."""
gene_name = uniprot_client.get_gene_name(up_id)
hgnc_id = hgnc_client.get_hgnc_id(gene_name)
a = Agent(gene_name, db_refs={'HGNC': hgnc_id, 'UP': up_id})
return a