Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
position = None
ps = row['phosphosite']
kin_upid = row['KIN_ID']
if not pandas.isnull(kin_upid):
if kin_upid.find('-') != -1:
kin_upid = kin_upid.split('-')[0]
if not uniprot_client.is_human(kin_upid):
continue
kin_hgnc_symbol = uniprot_client.get_gene_name(kin_upid)
kin_hgnc = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
else:
kin_hgnc_symbol = row['KINASE_GENE_SYMBOL']
if pandas.isnull(kin_hgnc_symbol):
continue
kin_hgnc_id = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
kin_upid = hgnc_client.get_uniprot_id(kin_hgnc_id)
if kin_upid is None:
continue
kin = Agent(kin_hgnc_symbol,
db_refs={'UP': kin_upid, 'HGNC': kin_hgnc})
ev = Evidence(source_api='phosphosite')
st = Phosphorylation(kin, sub, residue, position, evidence = [ev])
statements.append(st)
return statements
def get_kinase_activities():
kinase_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../resources/kinases.tsv')
kinases = []
with open(kinase_file, 'rt') as fh:
lines = [l.strip() for l in fh.readlines()]
for lin in lines[1:]:
up_id, hgnc_name, _, _ = lin.split('\t')
hgnc_id = hgnc_client.get_hgnc_id(hgnc_name)
agent = Agent(hgnc_name, db_refs={'UP': up_id, 'HGNC': hgnc_id})
kinases.append(agent)
kin_activities = []
from indra.statements import HasActivity
for kin in kinases:
stmt = HasActivity(kin, 'kinase', True)
kin_activities.append(stmt)
return kin_activities
db_refs={'UP': sub_upid,'HGNC': sub_hgnc})
residue = row['Actual_site'][0]
if len(row['Actual_site']) > 1:
position = row['Actual_site'][1:]
else:
position = None
ps = row['phosphosite']
kin_upid = row['KIN_ID']
if not pandas.isnull(kin_upid):
if kin_upid.find('-') != -1:
kin_upid = kin_upid.split('-')[0]
if not uniprot_client.is_human(kin_upid):
continue
kin_hgnc_symbol = uniprot_client.get_gene_name(kin_upid)
kin_hgnc = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
else:
kin_hgnc_symbol = row['KINASE_GENE_SYMBOL']
if pandas.isnull(kin_hgnc_symbol):
continue
kin_hgnc_id = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
kin_upid = hgnc_client.get_uniprot_id(kin_hgnc_id)
if kin_upid is None:
continue
kin = Agent(kin_hgnc_symbol,
db_refs={'UP': kin_upid, 'HGNC': kin_hgnc})
ev = Evidence(source_api='phosphosite')
st = Phosphorylation(kin, sub, residue, position, evidence = [ev])
statements.append(st)
return statements
def agent_from_gene_name(gene_name):
"""Return an Agent based on a gene name."""
hgnc_id = hgnc_client.get_hgnc_id(gene_name)
up_id = hgnc_client.get_uniprot_id(hgnc_id)
agent = Agent(gene_name, db_refs={'HGNC': hgnc_id,
'UP': up_id})
return agent
def get_relevant_nodes(self, pct_heat_threshold):
"""Return a list of the relevant nodes in the prior.
Heat diffusion is applied to the prior network based on initial
heat on nodes that are mutated according to patient statistics.
"""
logger.info('Setting heat for relevant nodes in prior network')
heats = np.zeros(len(self.prior_graph))
mut_nodes = {}
for gene_name, muts in self.norm_mutations.items():
if muts:
hgnc_id = get_hgnc_id(gene_name)
node_key = 'HGNC:%s' % hgnc_id
mut_nodes[node_key] = muts
for idx, node in enumerate(self.prior_graph.nodes()):
if node in mut_nodes:
heats[idx] = mut_nodes[node]
gamma = -0.1
logger.info('Calculating Laplacian matrix')
lp_mx = nx.normalized_laplacian_matrix(self.prior_graph,
weight='weight')
logger.info('Diffusing heat')
Df = expm_multiply(gamma * lp_mx, heats)
heat_thresh = np.percentile(Df, pct_heat_threshold)
logger.info('Filtering to relevant nodes with heat threshold %.2f '
'(%s percentile)' % (heat_thresh, pct_heat_threshold))
def get_gene_agents(gene_names):
agents = []
for gn in gene_names:
hgnc_id = hgnc_client.get_hgnc_id(gn)
if not hgnc_id:
logger.warning('Invalid HGNC gene symbol: %s' % gn)
continue
db_refs = {'HGNC': hgnc_id}
up_id = hgnc_client.get_uniprot_id(hgnc_id)
if up_id:
db_refs['UP'] = up_id
agent = Agent(gn, db_refs=db_refs)
agents.append(agent)
return agents
up_id = cx_db_refs.get('UP')
if up_id:
db_refs = {'UP': up_id, 'TEXT': node_name}
hgnc_id = uniprot_client.get_hgnc_id(up_id)
if hgnc_id:
db_refs['HGNC'] = hgnc_id
gene_name = hgnc_client.get_hgnc_name(hgnc_id)
else:
gene_name = uniprot_client.get_gene_name(up_id)
agent = Agent(gene_name, db_refs=db_refs)
self._node_names[id] = gene_name
self._node_agents[id] = agent
continue
else:
self._node_names[id] = node_name
hgnc_id = hgnc_client.get_hgnc_id(node_name)
db_refs = {'TEXT': node_name}
if not hgnc_id:
if not self.require_grounding:
self._node_agents[id] = \
Agent(node_name, db_refs=db_refs)
invalid_genes.append(node_name)
else:
db_refs.update({'HGNC': hgnc_id})
up_id = hgnc_client.get_uniprot_id(hgnc_id)
# It's possible that a valid HGNC ID will not have a
# Uniprot ID, as in the case of HOTAIR (HOX transcript
# antisense RNA, HGNC:33510)
if up_id:
db_refs.update({'UP': up_id})
self._node_agents[id] = Agent(node_name, db_refs=db_refs)
if invalid_genes:
def _get_agent_ref(agent):
"""Get the preferred ref for an agent for db web api."""
if agent is None:
return None
ag_hgnc_id = hgnc_client.get_hgnc_id(agent.name)
if ag_hgnc_id is not None:
return ag_hgnc_id + "@HGNC"
db_refs = agent.db_refs
for namespace in ['HGNC', 'FPLX', 'CHEBI', 'TEXT']:
if namespace in db_refs.keys():
return '%s@%s' % (db_refs[namespace], namespace)
return '%s@%s' % (agent.name, 'TEXT')
all_pathways.update(additional_pathways)
all_genes = set([])
for pathway in all_pathways:
additional_genes = get_genes_contained_in_pathway(pathway)
if additional_genes is not None:
all_genes.update(additional_genes)
gene_terms = []
for uniprot_id in all_genes:
hgnc_name = get_gene_name(uniprot_id)
if hgnc_name is None:
logger.warning('Could not get HGNC name for UniProt ID'
f' {uniprot_id}')
continue
hgnc_id = get_hgnc_id(hgnc_name)
if not hgnc_id:
logger.warning('Could not find HGNC ID for HGNC symbol'
f' {hgnc_name} with corresonding Uniprot ID'
f' {uniprot_id}')
continue
term = SearchTerm(type='gene', name=hgnc_name,
search_term=f'"{hgnc_name}"',
db_refs={'HGNC': hgnc_id,
'UP': uniprot_id})
gene_terms.append(term)
return sorted(gene_terms, key=lambda x: x.name)
def get_target_agent(target):
target_hgnc_id = hgnc_client.get_hgnc_id(target)
target_up_id = hgnc_client.get_uniprot_id(target_hgnc_id)
target_agent = Agent(target, db_refs={'HGNC': target_hgnc_id,
'UP': target_up_id})
return target_agent