def test_phosphorylation(): tp = trips.process_text('BRAF phosphorylates MEK1 at Ser222.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Phosphorylation)) assert(st.residue == 'S') assert(st.position == '222')
def test_phosphorylation_noresidue(): tp = trips.process_text('BRAF phosphorylates MEK1.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Phosphorylation)) assert(st.residue is None) assert(st.position is None)
def test_actmod(): tp = trips.process_text('MEK1 phosphorylated at Ser222 is activated.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.ActiveForm)) assert(isinstance(st.agent.mods[0], ist.ModCondition)) assert(st.agent.mods[0].mod_type == 'phosphorylation') assert(st.agent.mods[0].residue == 'S') assert(st.agent.mods[0].position == '222')
def test_actmods(): tp = trips.process_text('BRAF phosphorylated at Ser536 binds MEK1.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Complex)) braf = st.members[0] assert(braf.mods[0].mod_type == 'phosphorylation') assert(braf.mods[0].residue == 'S') assert(braf.mods[0].position == '536')
def test_ubiquitination(): tp = trips.process_text('MDM2 ubiquitinates TP53.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.Ubiquitination)) assert unicode_strs((tp, st)) assert_grounding_value_or_none(st) assert_if_hgnc_then_up(st) assert (st.evidence)
def test_ubiquitination(): tp = trips.process_text('MDM2 ubiquitinates TP53.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Ubiquitination)) assert unicode_strs((tp, st)) assert_grounding_value_or_none(st) assert_if_hgnc_then_up(st) assert(st.evidence)
def test_phosphorylation_nosite(): tp = trips.process_text('BRAF phosphorylates MEK1 at Serine.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.Phosphorylation)) assert (st.residue == 'S') assert (st.position is None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_degradation(): tp = trips.process_text('MDM2 degrades TP53.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.DecreaseAmount)) assert (st.subj is not None) assert (st.obj is not None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_synthesis(): tp = trips.process_text('NFKB transcribes IKB.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.IncreaseAmount)) assert (st.subj is not None) assert (st.obj is not None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_phosphorylation_nosite(): tp = trips.process_text('BRAF phosphorylates MEK1 at Serine.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Phosphorylation)) assert(st.residue == 'S') assert(st.position is None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_bind(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The receptor tyrosine kinase EGFR binds the growth factor ligand EGF.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (has_hgnc_ref(st.members[0])) assert (has_hgnc_ref(st.members[1])) os.remove(fname)
def test_degradation(): tp = trips.process_text('MDM2 degrades TP53.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.DecreaseAmount)) assert(st.subj is not None) assert(st.obj is not None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_synthesis(): tp = trips.process_text('NFKB transcribes IKB.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.IncreaseAmount)) assert(st.subj is not None) assert(st.obj is not None) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_bind(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The receptor tyrosine kinase EGFR binds the growth factor ligand EGF.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(has_hgnc_ref(st.members[0])) assert(has_hgnc_ref(st.members[1])) os.remove(fname)
def test_actform_bound(): tp = trips.process_text('HRAS bound to GTP is activated.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.ActiveForm)) assert (isinstance(st.agent.bound_conditions[0], ist.BoundCondition)) assert (st.agent.bound_conditions[0].agent.name == 'GTP') assert (st.agent.bound_conditions[0].is_bound == True) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_not_bound_to3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'SOS1 bound to GRB2 binds NRAS that is not bound to BRAF and GTP.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (st.members[0].name == 'SOS1') assert (st.members[1].name == 'NRAS') assert (len(st.members[0].bound_conditions) == 1) assert (len(st.members[1].bound_conditions) == 2) os.remove(fname)
def test_actform_bound(): tp = trips.process_text('HRAS bound to GTP is activated.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.ActiveForm)) assert(isinstance(st.agent.bound_conditions[0], ist.BoundCondition)) assert(st.agent.bound_conditions[0].agent.name == 'GTP') assert(st.agent.bound_conditions[0].is_bound == True) assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_not_bound_to3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'SOS1 bound to GRB2 binds NRAS that is not bound to BRAF and GTP.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(st.members[0].name == 'SOS1') assert(st.members[1].name == 'NRAS') assert(len(st.members[0].bound_conditions) == 1) assert(len(st.members[1].bound_conditions) == 2) os.remove(fname)
def test_complex_bind3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'RAF binds to the RAS-GTP complex.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(st.members[0].name == 'RAF') assert(st.members[1].name == 'RAS') assert(len(st.members[1].bound_conditions) == 1) assert(st.members[1].bound_conditions[0].agent.name == 'GTP') os.remove(fname)
def test_actmod(): tp = trips.process_text('MEK1 phosphorylated at Ser222 is activated.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.ActiveForm)) assert(isinstance(st.agent.mods[0], ist.ModCondition)) assert(st.agent.mods[0].mod_type == 'phosphorylation') assert(st.agent.mods[0].residue == 'S') assert(st.agent.mods[0].position == '222') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_actmods2(): tp = trips.process_text('BRAF phosphorylated at Ser536 binds MEK1.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Complex)) braf = st.members[0] assert(braf.mods[0].mod_type == 'phosphorylation') assert(braf.mods[0].residue == 'S') assert(braf.mods[0].position == '536') assert unicode_strs((tp, st, braf)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_actform_muts(): tp = trips.process_text('BRAF V600E is activated.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.ActiveForm)) assert (isinstance(st.agent.mutations[0], ist.MutCondition)) assert (st.agent.mutations[0].residue_from == 'V') assert (st.agent.mutations[0].residue_to == 'E') assert (st.agent.mutations[0].position == '600') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_actmods2(): tp = trips.process_text('BRAF phosphorylated at Ser536 binds MEK1.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.Complex)) braf = st.members[0] assert (braf.mods[0].mod_type == 'phosphorylation') assert (braf.mods[0].residue == 'S') assert (braf.mods[0].position == '536') assert unicode_strs((tp, st, braf)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_complex_bind2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The EGFR-EGFR complex binds GRB2.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(st.members[0].name == 'EGFR') assert(st.members[1].name == 'GRB2') assert(len(st.members[0].bound_conditions) == 1) assert(st.members[0].bound_conditions[0].agent.name == 'EGFR') os.remove(fname)
def test_not_bound_to4(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF that is not bound to NRAS and Vemurafenib binds BRAF ' +\ 'that is not bound to Vemurafenib.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (st.members[0].name == 'BRAF') assert (st.members[1].name == 'BRAF') assert (len(st.members[0].bound_conditions) == 2) assert (len(st.members[1].bound_conditions) == 1) os.remove(fname)
def trips_process_text(): """Process text with TRIPS and return INDRA Statements.""" response = request.body.read().decode('utf-8') body = json.loads(response) text = body.get('text') tp = trips.process_text(text) if tp and tp.statements: stmts = stmts_to_json(tp.statements) res = {'statements': stmts} return res else: res = {'statements': []} return res
def test_not_bound_to4(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF that is not bound to NRAS and Vemurafenib binds BRAF ' +\ 'that is not bound to Vemurafenib.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(st.members[0].name == 'BRAF') assert(st.members[1].name == 'BRAF') assert(len(st.members[0].bound_conditions) == 2) assert(len(st.members[1].bound_conditions) == 1) os.remove(fname)
def test_complex_bind3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'RAF binds to the RAS-GTP complex.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (st.members[0].name == 'RAF') assert (st.members[1].name == 'RAS') assert (len(st.members[1].bound_conditions) == 1) assert (st.members[1].bound_conditions[0].agent.name == 'GTP') os.remove(fname)
def test_bound_phosphorylate(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'RAF, bound to RAF, phosphorylates MEK1.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_phosphorylation(st)) assert(st.enz is not None) assert(st.enz.name == 'RAF') assert(st.sub is not None) assert(st.sub.name == 'MAP2K1') assert(st.residue == None) os.remove(fname)
def test_actmod(): tp = trips.process_text('MEK1 phosphorylated at Ser222 is activated.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.ActiveForm)) assert (isinstance(st.agent.mods[0], ist.ModCondition)) assert (st.agent.mods[0].mod_type == 'phosphorylation') assert (st.agent.mods[0].residue == 'S') assert (st.agent.mods[0].position == '222') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_bound_phosphorylate(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'RAF, bound to RAF, phosphorylates MEK1.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_phosphorylation(st)) assert (st.enz is not None) assert (st.enz.name == 'RAF') assert (st.sub is not None) assert (st.sub.name == 'MAP2K1') assert (st.residue == None) os.remove(fname)
def test_complex_bind(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The EGFR-EGF complex binds another EGFR-EGF complex.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (has_hgnc_ref(st.members[0])) assert (has_hgnc_ref(st.members[1])) assert (st.members[0].bound_conditions) assert (st.members[1].bound_conditions) os.remove(fname)
def test_actform_muts(): tp = trips.process_text('BRAF V600E is activated.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.ActiveForm)) assert(isinstance(st.agent.mutations[0], ist.MutCondition)) assert(st.agent.mutations[0].residue_from == 'V') assert(st.agent.mutations[0].residue_to == 'E') assert(st.agent.mutations[0].position == '600') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_complex_bind(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The EGFR-EGF complex binds another EGFR-EGF complex.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(has_hgnc_ref(st.members[0])) assert(has_hgnc_ref(st.members[1])) assert(st.members[0].bound_conditions) assert(st.members[1].bound_conditions) os.remove(fname)
def test_complex_bind2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The EGFR-EGFR complex binds GRB2.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (st.members[0].name == 'EGFR') assert (st.members[1].name == 'GRB2') assert (len(st.members[0].bound_conditions) == 1) assert (st.members[0].bound_conditions[0].agent.name == 'EGFR') os.remove(fname)
def test_bound_mod(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The adaptor protein GRB2 can bind EGFR that is phosphorylated on tyrosine.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (has_hgnc_ref(st.members[0])) assert (has_hgnc_ref(st.members[1])) assert (st.members[1].mods) assert (st.members[1].mods[0].mod_type == 'phosphorylation') assert (st.members[1].mods[0].residue == 'Y') os.remove(fname)
def test_dephosphorylate(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'DUSP6 dephosphorylates ERK2 at Tyr187.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_dephosphorylation(st)) assert (st.enz is not None) assert (st.enz.name == 'DUSP6') assert (st.sub is not None) assert (st.sub.name == 'MAPK1') assert (st.residue == 'Y') assert (st.position == '187') os.remove(fname)
def test_transphosphorylate2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'EGFR, bound to EGFR, transphosphorylates itself on a tyrosine residue.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_transphosphorylation(st)) assert (st.enz is not None) assert (st.enz.name == 'EGFR') assert (has_hgnc_ref(st.enz)) assert (st.residue == 'Y') assert (len(st.enz.bound_conditions) == 1) assert (st.enz.bound_conditions[0].agent.name == 'EGFR') os.remove(fname)
def test_bound_to3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'SOS1, bound to GRB2 binds RAS.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (st.members[0].name == 'SOS1') assert (has_hgnc_ref(st.members[0])) assert (st.members[1].name == 'RAS') assert (len(st.members[0].bound_conditions) == 1) assert (st.members[0].bound_conditions[0].agent.name == 'GRB2') os.remove(fname)
def test_bound_mod(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'The adaptor protein GRB2 can bind EGFR that is phosphorylated on tyrosine.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(has_hgnc_ref(st.members[0])) assert(has_hgnc_ref(st.members[1])) assert(st.members[1].mods) assert(st.members[1].mods[0].mod_type == 'phosphorylation') assert(st.members[1].mods[0].residue == 'Y') os.remove(fname)
def test_transphosphorylate2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'EGFR, bound to EGFR, transphosphorylates itself on a tyrosine residue.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_transphosphorylation(st)) assert(st.enz is not None) assert(st.enz.name == 'EGFR') assert(has_hgnc_ref(st.enz)) assert(st.residue == 'Y') assert(len(st.enz.bound_conditions) == 1) assert(st.enz.bound_conditions[0].agent.name == 'EGFR') os.remove(fname)
def test_bound_to3(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'SOS1, bound to GRB2 binds RAS.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(st.members[0].name == 'SOS1') assert(has_hgnc_ref(st.members[0])) assert(st.members[1].name == 'RAS') assert(len(st.members[0].bound_conditions) == 1) assert(st.members[0].bound_conditions[0].agent.name == 'GRB2') os.remove(fname)
def test_dephosphorylate(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'DUSP6 dephosphorylates ERK2 at Tyr187.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_dephosphorylation(st)) assert(st.enz is not None) assert(st.enz.name == 'DUSP6') assert(st.sub is not None) assert(st.sub.name == 'MAPK1') assert(st.residue == 'Y') assert(st.position == '187') os.remove(fname)
def test_act_mod(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'MEK1, phosphorylated at Ser218 and Ser222, is activated.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_actmod(st)) assert (st.agent is not None) assert (st.agent.name == 'MAP2K1') residues = [m.residue for m in st.agent.mods] positions = [m.position for m in st.agent.mods] assert (residues == ['S', 'S']) assert (positions == ['218', '222']) assert (st.is_active) os.remove(fname)
def test_mod_cond(): tp = trips.process_text('Phosphorylated BRAF binds ubiquitinated MAP2K1.') assert(len(tp.statements) == 1) st = tp.statements[0] assert(isinstance(st, ist.Complex)) braf = st.members[0] mek = st.members[1] assert(len(braf.mods) == 1) assert(braf.mods[0].mod_type == 'phosphorylation') assert(len(mek.mods) == 1) assert(mek.mods[0].mod_type == 'ubiquitination') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert(st.evidence)
def test_mod_cond(): tp = trips.process_text('Phosphorylated BRAF binds ubiquitinated MAP2K1.') assert (len(tp.statements) == 1) st = tp.statements[0] assert (isinstance(st, ist.Complex)) braf = st.members[0] mek = st.members[1] assert (len(braf.mods) == 1) assert (braf.mods[0].mod_type == 'phosphorylation') assert (len(mek.mods) == 1) assert (mek.mods[0].mod_type == 'ubiquitination') assert unicode_strs((tp, st)) assert_if_hgnc_then_up(st) assert_grounding_value_or_none(st) assert (st.evidence)
def test_act_mod(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'MEK1, phosphorylated at Ser218 and Ser222, is activated.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_actmod(st)) assert(st.agent is not None) assert(st.agent.name == 'MAP2K1') residues = [m.residue for m in st.agent.mods] positions = [m.position for m in st.agent.mods] assert(residues == ['S', 'S']) assert(positions == ['218', '222']) assert(st.is_active) os.remove(fname)
def test_not_bound_to(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF that is not bound to Vemurafenib binds MEK1.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_complex(st)) assert(len(st.members) == 2) assert(st.members[0].name == 'BRAF') assert(has_hgnc_ref(st.members[0])) assert(st.members[1].name == 'MAP2K1') assert(has_hgnc_ref(st.members[1])) assert(len(st.members[0].bound_conditions) == 1) assert(st.members[0].bound_conditions[0].agent.name.lower() == 'vemurafenib') assert(st.members[0].bound_conditions[0].is_bound == False) os.remove(fname)
def test_not_bound_to(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF that is not bound to Vemurafenib binds MEK1.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_complex(st)) assert (len(st.members) == 2) assert (st.members[0].name == 'BRAF') assert (has_hgnc_ref(st.members[0])) assert (st.members[1].name == 'MAP2K1') assert (has_hgnc_ref(st.members[1])) assert (len(st.members[0].bound_conditions) == 1) assert ( st.members[0].bound_conditions[0].agent.name.lower() == 'vemurafenib') assert (st.members[0].bound_conditions[0].is_bound == False) os.remove(fname)
def test_not_bound_to2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF, not bound to Vemurafenib, phosphorylates MEK1.' tp = trips.process_text(txt, fname, False) assert (len(tp.statements) == 1) st = tp.statements[0] assert (is_phosphorylation(st)) assert (st.enz is not None) assert (st.sub is not None) assert (st.enz.name == 'BRAF') assert (has_hgnc_ref(st.enz)) assert (st.sub.name == 'MAP2K1') assert (has_hgnc_ref(st.sub)) assert (len(st.enz.bound_conditions) == 1) assert (st.enz.bound_conditions[0].agent.name.lower() == 'vemurafenib') assert (st.enz.bound_conditions[0].is_bound == False) os.remove(fname)
def test_not_bound_to2(): fname = sys._getframe().f_code.co_name + '.xml' txt = 'BRAF, not bound to Vemurafenib, phosphorylates MEK1.' tp = trips.process_text(txt, fname, False) assert(len(tp.statements) == 1) st = tp.statements[0] assert(is_phosphorylation(st)) assert(st.enz is not None) assert(st.sub is not None) assert(st.enz.name == 'BRAF') assert(has_hgnc_ref(st.enz)) assert(st.sub.name == 'MAP2K1') assert(has_hgnc_ref(st.sub)) assert(len(st.enz.bound_conditions) == 1) assert(st.enz.bound_conditions[0].agent.name.lower() == 'vemurafenib') assert(st.enz.bound_conditions[0].is_bound == False) os.remove(fname)
def process_trips(txt, reread=True): print('Using TRIPS') ts = time.time() if reread: stmts = [] sentences = txt.strip().split('\n') for sentence in sentences: print(sentence) tp = trips.process_text(sentence) stmts += tp.statements else: tp = trips.process_xml(open('trips_output.xml', 'r').read()) stmts = tp.statements te = time.time() print('Time taken: %.2fs' % (te - ts)) for st in stmts: print('%s\t%s' % (st, st.evidence[0].text)) return stmts
def assemble_model(model_name, reread=False): xml_fname = model_name + '.xml' if not reread: print('Processing %s' % xml_fname) if os.path.exists(xml_fname): with open(xml_fname, 'rb') as fh: tp = trips.process_xml(fh.read()) else: reread = True if reread: fname = model_name + '.txt' print('Reading %s' % fname) with open(fname, 'rb') as fh: ts = time.time() tp = trips.process_text(fh.read(), xml_fname) te = time.time() print('Reading took %.2fs' % (te - ts)) print('Assembling statements:') for i, st in enumerate(tp.statements): print('%d: %s' % (i, st)) print('----------------------') pa = PysbAssembler() pa.add_statements(tp.statements) ts = time.time() model = pa.make_model() te = time.time() print('Assembly took %.2fs' % (te - ts)) model.name = model_name add_observable(model) set_parameters(model) # Save and return model pa.model = model pa.save_model('%s.py' % model_name) return model
def remove_mechanism(text, user_name): global stmts import ipdb ipdb.set_trace() tp = trips.process_text(text) gmapper = gm.GroundingMapper(gm.default_grounding_map) tp_stmts = gmapper.map_agents(tp.statements) print "Statements to remove:", tp.statements stmts_to_keep = [] for model_stmt in stmts: remove_stmt = False for stmt_to_remove in tp_stmts: if model_stmt.refinement_of(stmt_to_remove, hierarchies): remove_stmt = True break if not remove_stmt: stmts_to_keep.append(model_stmt) if stmts_to_keep == stmts: say("Sorry, I couldn't find any matching mechanisms to remove.") else: say("OK, I removed it.") stmts = stmts_to_keep assemble_model(user_name)
def assemble_model(model_id, reread=False): model_name = 'model%d' % model_id # If model has already been read, just process the EKB XML if os.path.exists(model_name + '.xml') and not reread: tp = trips.process_xml(open(model_name + '.xml').read()) else: # Start with the basic model model_txt = open('model1.txt').read() # Apply patches one by one to get to the current model text for j in range(1, model_id): patch_txt = open('model%d_from%d.txt' % (j + 1, j)).read() model_txt = apply_patch(model_txt, patch_txt) print('Reading model %d text:' % model_id) print(model_txt) # Process model text and save result EKB XML tp = trips.process_text(model_txt, model_name + '.xml') print('Assembling statements:') for i, st in enumerate(tp.statements): print('%d: %s' % (i, st)) # Assemble the PySB model pa = PysbAssembler() pa.add_statements(tp.statements) model = pa.make_model(policies='two_step') # Set initial conditions erk = model.monomers['ERK'] obs = Observable(b'ERK_p', erk(phospho='p')) model.add_component(obs) vem = model.monomers['VEMURAFENIB'] obs = Observable(b'Vem_free', vem(map3k=None)) model.add_component(obs) ras = model.monomers['RAS'] obs = Observable(b'RAS_active', ras(gtp=ANY)) model.add_component(obs) braf = model.monomers['BRAF'] obs = Observable(b'BRAF_active', braf(vemurafenib=None)) model.add_component(obs) model.parameters[b'BRAF_0'].value = 0 egf = model.monomers['EGF'] obs = Observable(b'EGF_free', egf(erbb=None)) model.add_component(obs) # Add mutated form of BRAF as initial condition sites_dict = {} for site in braf.sites: if site in braf.site_states: sites_dict[site] = braf.site_states[site][0] else: sites_dict[site] = None sites_dict['V600'] = 'E' model.add_component(Parameter('BRAF_mut_0', 1e5)) model.initial(braf(**sites_dict), model.parameters['BRAF_mut_0']) # Set up model parameters model.parameters['kf_ee_bind_1'].value = 1 model.parameters['kr_ee_bind_1'].value = 0.1 model.parameters['kf_ee_bind_2'].value = 1 model.parameters['kr_ee_bind_2'].value = 0.1 model.parameters['kf_eg_bind_1'].value = 1 model.parameters['kr_eg_bind_1'].value = 0.1 model.parameters['kf_gs_bind_1'].value = 1 model.parameters['kr_gs_bind_1'].value = 0.1 model.parameters['kf_sr_bind_1'].value = 1 model.parameters['kr_sr_bind_1'].value = 50 model.parameters['kf_rg_bind_1'].value = 50 model.parameters['kr_rg_bind_1'].value = 0.5 model.parameters['kf_rb_bind_1'].value = 1 model.parameters['kr_rb_bind_1'].value = 0.5 model.parameters['kf_vb_bind_1'].value = 10 model.parameters['kr_vb_bind_1'].value = 1 model.parameters['kf_bm_bind_1'].value = 1 model.parameters['kr_bm_bind_1'].value = 0.1 model.parameters['kc_bm_phosphorylation_1'].value = 3 model.parameters['kf_pm_bind_1'].value = 1 model.parameters['kr_pm_bind_1'].value = 0.001 model.parameters['kc_pm_dephosphorylation_1'].value = 10 model.parameters['kf_me_bind_1'].value = 1 model.parameters['kr_me_bind_1'].value = 0.1 model.parameters['kc_me_phosphorylation_1'].value = 10 model.parameters['kf_de_bind_1'].value = 1 model.parameters['kr_de_bind_1'].value = 0.001 model.parameters['kc_de_dephosphorylation_1'].value = 10 model.parameters['VEMURAFENIB_0'].value = 0 model.parameters['EGF_0'].value = 1e3 model.parameters['EGFR_0'].value = 1e5 model.parameters['SOS_0'].value = 1e3 model.parameters['GRB2_0'].value = 1e5 model.parameters['RAS_0'].value = 2e5 model.parameters['GTP_0'].value = 1e7 model.parameters['MEK_0'].value = 1e5 model.parameters['ERK_0'].value = 1e5 model.parameters['DUSP6_0'].value = 1e3 model.parameters['PPP2CA_0'].value = 1e5 if model_id >= 2: model.parameters['Phosphatase_0'].value = 1e2 model.parameters['kf_es_bind_1'].value = 1e-05 model.parameters['kr_es_bind_1'].value = 1e-04 model.parameters['kc_es_phosphorylation_1'].value = 1 model.parameters['kf_ps_bind_1'].value = 1 model.parameters['kr_ps_bind_1'].value = 0.1 model.parameters['kc_ps_dephosphorylation_1'].value = 1e-04 if model_id >= 3: model.parameters['kf_bb_bind_1'].value = 10 model.parameters['kr_bb_bind_1'].value = 1 model.parameters['kf_vb_bind_2'].value = 1e-04 pa.model = model pa.save_model('model%d.py' % model_id) return model
def test_trips_processor_online(): """Smoke test to see if imports and executes without error. Doesn't check for correctness of parse or of assembled model.""" tp = trips.process_text('BRAF phosphorylates MEK1 at Ser222.')
def make_ekb(txt): fname = re.sub('[^a-zA-Z0-9]', '_', txt[:-1]) + '.ekb' tp = trips.process_text(txt, save_xml_name=fname) print(txt) print(tp.statements)
import numpy as np from pysb.integrate import Solver from matplotlib import pyplot as plt from indra import bel, biopax, trips from indra.util import plot_formatting as pf from indra.assemblers import PysbAssembler # 1. TEXT # User defines text: text = ('MEK1 phosphorylates ERK2 on threonine 185 and tyrosine 187.') # Show round trip going out to TRIPS/DRUM web service, # return logical form to INDRA, which is queried by # INDRA for relevant statements tp = trips.process_text(text) # Now generate PySB model stmts = tp.statements # Don't show this one pa = PysbAssembler() pa.add_statements(stmts) pa.make_model() t = np.linspace(0, 25000) sol = Solver(pa.model, t) sol.run() pf.set_fig_params() plt.ion() plt.figure(figsize=(1, 1), dpi=300) species_names = [str(s) for s in pa.model.species] plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='u', Y187='u')")],
import numpy as np from pysb.integrate import Solver from matplotlib import pyplot as plt from indra import bel, biopax, trips from indra.util import plot_formatting as pf from indra.assemblers import PysbAssembler # 1. TEXT # User defines text: text = ('MEK1 phosphorylates ERK2 on threonine 185 and tyrosine 187.') # Show round trip going out to TRIPS/DRUM web service, # return logical form to INDRA, which is queried by # INDRA for relevant statements tp = trips.process_text(text) # Now generate PySB model stmts = tp.statements # Don't show this one pa = PysbAssembler() pa.add_statements(stmts) pa.make_model() t = np.linspace(0, 25000) sol = Solver(pa.model, t) sol.run() pf.set_fig_params() plt.ion() plt.figure(figsize=(1, 1), dpi=300) species_names = [str(s) for s in pa.model.species] plt.plot(t,
def update_model_from_text(text, requester_name): global stmts say("%s: Got it. Assembling model..." % requester_name) tp = trips.process_text(text) stmts += tp.statements assemble_model(requester_name)