def test_combine_duplicates(): raf = Agent('RAF1') mek = Agent('MEK1') erk = Agent('ERK2') p1 = Phosphorylation(raf, mek, evidence=Evidence(text='foo')) p2 = Phosphorylation(raf, mek, evidence=Evidence(text='bar')) p3 = Phosphorylation(raf, mek, evidence=Evidence(text='baz')) p4 = Phosphorylation(raf, mek, evidence=Evidence(text='beep')) p5 = Phosphorylation(mek, erk, evidence=Evidence(text='foo2')) p6 = Dephosphorylation(mek, erk, evidence=Evidence(text='bar2')) p7 = Dephosphorylation(mek, erk, evidence=Evidence(text='baz2')) p8 = Dephosphorylation(mek, erk, evidence=Evidence(text='beep2')) p9 = Dephosphorylation(Agent('SRC'), Agent('KRAS'), evidence=Evidence(text='beep')) stmts = [p1, p2, p3, p4, p5, p6, p7, p8, p9] pa = Preassembler(hierarchies, stmts=stmts) pa.combine_duplicates() # The statements come out sorted by their matches_key assert len(pa.unique_stmts) == 4, len(pa.unique_stmts) num_evs = [len(s.evidence) for s in pa.unique_stmts] assert pa.unique_stmts[0].matches(p6) # MEK dephos ERK assert num_evs[0] == 3, num_evs[0] assert pa.unique_stmts[1].matches(p9) # SRC dephos KRAS assert num_evs[1] == 1, num_evs[1] assert pa.unique_stmts[2].matches(p5) # MEK phos ERK assert num_evs[2] == 1, num_evs[2] assert pa.unique_stmts[3].matches(p1) # RAF phos MEK assert num_evs[3] == 4, num_evs[3]
def test_find_contradicts_refinement(): ras = Agent('RAS', db_refs={'FPLX': 'RAS'}) kras = Agent('KRAS', db_refs={'HGNC': '6407'}) hras = Agent('HRAS', db_refs={'HGNC': '5173'}) st1 = Phosphorylation(Agent('x'), ras) st2 = Dephosphorylation(Agent('x'), kras) st3 = Dephosphorylation(Agent('x'), hras) pa = Preassembler(hierarchies, [st1, st2, st3]) contradicts = pa.find_contradicts() assert len(contradicts) == 2 for s1, s2 in contradicts: assert {s1.uuid, s2.uuid} in ({st1.uuid, st2.uuid}, {st1.uuid, st3.uuid})
def get_observed_stmts(target_agent, observed_agent_forms, fold_change): stmts = [] for obsf in observed_agent_forms: obs_agent = Agent(obsf.name, db_refs=obsf.db_refs) # If the agent has a modification then we make Modification # statements to check if obsf.mods: for mod in obsf.mods: # Create a Phosphorylation statement corresponding to # this drug/Ab pair if fold_change < 1: stmt = Phosphorylation(target_agent, obs_agent, mod.residue, mod.position) else: stmt = Dephosphorylation(target_agent, obs_agent, mod.residue, mod.position) # Otherwise the observed change is in protein amounts so we make # RegulateAmount statements else: if fold_change < 1: stmt = IncreaseAmount(target_agent, obs_agent) else: stmt = DecreaseAmount(target_agent, obs_agent) stmts.append(stmt) return stmts
def _get_gk_model_indra(): kras = Agent('KRAS', db_refs={'HGNC': '6407', 'UP': 'P01116'}) braf = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'}) pp2a = Agent('PPP2CA') st1 = Phosphorylation(kras, braf) st2 = Dephosphorylation(pp2a, braf) stmts = [st1, st2] stmts_json = json.dumps(stmts_to_json(stmts)) return stmts_json
def process_phosphorylation_statements(self): """Looks for Phosphorylation events in the graph and extracts them into INDRA statements. In particular, looks for a Positive_regulation event node with a child Phosphorylation event node. If Positive_regulation has an outgoing Cause edge, that's the subject If Phosphorylation has an outgoing Theme edge, that's the object If Phosphorylation has an outgoing Site edge, that's the site """ G = self.G statements = [] pwcs = self.find_event_parent_with_event_child('Positive_regulation', 'Phosphorylation') for pair in pwcs: (pos_reg, phos) = pair cause = self.get_entity_text_for_relation(pos_reg, 'Cause') theme = self.get_entity_text_for_relation(phos, 'Theme') print('Cause:', cause, 'Theme:', theme) # If the trigger word is dephosphorylate or similar, then we # extract a dephosphorylation statement trigger_word = self.get_entity_text_for_relation( phos, 'Phosphorylation') if 'dephos' in trigger_word: deph = True else: deph = False site = self.get_entity_text_for_relation(phos, 'Site') theme_node = self.get_related_node(phos, 'Theme') assert (theme_node is not None) evidence = self.node_to_evidence(theme_node, is_direct=False) if theme is not None: if deph: statements.append( Dephosphorylation(s2a(cause), s2a(theme), site, evidence=evidence)) else: statements.append( Phosphorylation(s2a(cause), s2a(theme), site, evidence=evidence)) return statements
def test_multiprocessing(): braf = Agent('BRAF', db_refs={'HGNC': '1097'}) mek1 = Agent('MAP2K1', db_refs={'HGNC': '6840'}) mek = Agent('MEK', db_refs={'FPLX': 'MEK'}) # Statements p0 = Phosphorylation(braf, mek) p1 = Phosphorylation(braf, mek1) p2 = Phosphorylation(braf, mek1, position='218') p3 = Phosphorylation(braf, mek1, position='222') p4 = Phosphorylation(braf, mek1, 'serine') p5 = Phosphorylation(braf, mek1, 'serine', '218') p6 = Phosphorylation(braf, mek1, 'serine', '222') p7 = Dephosphorylation(braf, mek1) stmts = [p0, p1, p2, p3, p4, p5, p6, p7] pa = Preassembler(hierarchies, stmts=stmts) # Size cutoff set to a low number so that one group will run remotely # and one locally toplevel = pa.combine_related(return_toplevel=True, poolsize=1, size_cutoff=2) assert len(toplevel) == 3, 'Got %d toplevel statements.' % len(toplevel)