def check_policy(policy, result): pysba = PysbAssembler() pysba.add_statements([stmt]) pysba.make_model(policies=policy) mc = ModelChecker(pysba.model, [stmt]) checks = mc.check_model() assert len(checks) == 1 assert isinstance(checks[0], tuple) assert checks[0][0] == stmt assert checks[0][1] == result
def test_pysb_assembler_phospho_policies(): a = Agent('A', db_refs={'HGNC': '1'}) b = Agent('B', db_refs={'HGNC': '2'}) st = Phosphorylation(a, b, 'T', '185') pa = PysbAssembler() pa.add_statements([st]) # Try two step pa.make_model(policies='two_step') mc = ModelChecker(pa.model, [st]) results = mc.check_model() assert len(results) == 1 assert isinstance(results[0], tuple) assert results[0][0] == st assert results[0][1] == True # Try one step pa.make_model(policies='one_step') mc = ModelChecker(pa.model, [st]) results = mc.check_model() assert len(results) == 1 assert isinstance(results[0], tuple) assert results[0][0] == st assert results[0][1] == True # Try interactions_only pa.make_model(policies='interactions_only') mc = ModelChecker(pa.model, [st]) results = mc.check_model() assert len(results) == 1 assert isinstance(results[0], tuple) assert results[0][0] == st assert results[0][1] == False
def test_check_ubiquitination(): xiap = Agent('XIAP', db_refs={'HGNC': '592'}) casp3 = Agent('CASP3', db_refs={'HGNC': '1504'}) stmt = Ubiquitination(xiap, casp3) pysba = PysbAssembler() pysba.add_statements([stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [stmt]) checks = mc.check_model() assert len(checks) == 1 assert isinstance(checks[0], tuple) assert checks[0][0] == stmt assert checks[0][1] == True
def check_stmts(stmts): pa = PysbAssembler() pa.add_statements(stmts) pa.make_model(policies='one_step') stmts_to_check = [ Activation(egfr, kras, 'gtpbound'), Activation(egfr, braf, 'kinase') ] mc = ModelChecker(pa.model, stmts_to_check) results = mc.check_model() assert len(results) == len(stmts_to_check) assert isinstance(results[0], tuple) assert results[0][1] == True assert results[1][1] == True
def test_check_rule_subject1(): mek = Agent('MEK1', db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) stmt = Phosphorylation(mek, erk) pysba = PysbAssembler() pysba.add_statements([stmt]) pysba.make_model(policies='one_step') # Check against stmt: should not validate ERK phosphorylates ERK stmt_to_check = Phosphorylation(erk, erk) mc = ModelChecker(pysba.model, [stmt_to_check]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == stmt_to_check assert checks[0][1] == False
def test_rasgap_activation(): nf1 = Agent('NF1', db_refs={'HGNC':'1'}) ras = Agent('KRAS', db_refs={'HGNC':'2'}) rasgap_stmt = RasGap(nf1, ras) act_stmt = Inhibition(nf1, ras, 'gtpbound') # Check that the activation is satisfied by the RasGap pysba = PysbAssembler() pysba.add_statements([rasgap_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1] == True # TODO TODO TODO """
def test_check_activation(): a = Agent('A') b = Agent('B') c = Agent('C') st1 = Activation(a, b) st2 = Inhibition(b, c, 'kinase') stmts = [st1, st2] # Create the model pa = PysbAssembler() pa.add_statements(stmts) pa.make_model(policies='one_step') mc = ModelChecker(pa.model, stmts) results = mc.check_model() assert len(results) == len(stmts) assert isinstance(results[0], tuple) assert results[0][1] == True assert results[1][1] == True
def test_rasgef_rasgtp(): sos = Agent('SOS1', db_refs={'HGNC':'1'}) ras = Agent('KRAS', activity=ActivityCondition('gtpbound', True), db_refs={'HGNC':'2'}) raf = Agent('BRAF', db_refs={'HGNC':'3'}) rasgef_stmt = RasGef(sos, ras) rasgtp_stmt = RasGtpActivation(ras, raf, 'kinase') act_stmt = Activation(sos, raf, 'kinase') # Check that the activation is satisfied by the RasGef pysba = PysbAssembler() pysba.add_statements([rasgef_stmt, rasgtp_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1] == True
def test_grounded_modified_enzyme(): """Check if the model checker can use semantic annotations to match mods on the enzyme, not just the substrate, of a phosphorylation statement.""" mek_s202 = Agent('MEK1', mods=[ModCondition('phosphorylation', 'S', '202')], db_refs={'HGNC': '6840'}) mek_phos = Agent('MEK1', mods=[ModCondition('phosphorylation', None, None)], db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) stmt_to_model = Phosphorylation(mek_s202, erk, None, None) stmt_to_check = Phosphorylation(mek_phos, erk, None, None) pa = PysbAssembler() pa.add_statements([stmt_to_model]) pa.make_model(policies='one_step') mc = ModelChecker(pa.model, [stmt_to_check]) results = mc.check_model() assert len(results) == 1 assert results[0][0] == stmt_to_check assert results[0][1] == True
def test_rasgef_rasgtp_phos(): sos = Agent('SOS1', db_refs={'HGNC':'1'}) ras = Agent('KRAS', activity=ActivityCondition('gtpbound', True), db_refs={'HGNC':'2'}) raf = Agent('BRAF', db_refs={'HGNC':'3'}) mek = Agent('MEK', db_refs={'HGNC': '4'}) rasgef_stmt = RasGef(sos, ras) rasgtp_stmt = RasGtpActivation(ras, raf, 'kinase') phos = Phosphorylation(raf, mek) stmt_to_check = Phosphorylation(sos, mek) # Assemble and check pysba = PysbAssembler() pysba.add_statements([rasgef_stmt, rasgtp_stmt, phos]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [stmt_to_check]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == stmt_to_check assert checks[0][1] == True
def test_eidos_to_pysb(): stmts = __get_stmts_from_remote_jsonld() pa = PysbAssembler() # Make sure these don't error pa.add_statements(stmts) pa.make_model() for fmt in ['kappa', 'sbml', 'sbgn']: exp_str = pa.export_model(fmt) assert exp_str, "Got no exported model from eidos->psyb to %s." % fmt return
def test_stmt_from_rule(): mek = Agent('MEK1', db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) st = Phosphorylation(mek, erk, 'T', '185') pa = PysbAssembler() pa.add_statements([st]) pa.make_model() rule_name = pa.model.rules[0].name stmt = _stmt_from_rule(pa.model, rule_name, [st]) assert (stmt == st)
def test_model_check_data(): # Create a set of statements a = Agent('A', db_refs={'HGNC': '1'}) b = Agent('B', db_refs={'HGNC': '2'}) b_phos = Agent('B', mods=[ModCondition('phosphorylation')], db_refs={'HGNC': '2'}) c = Agent('C', db_refs={'HGNC': '3'}) c_phos = Agent('C', mods=[ModCondition('phosphorylation')], db_refs={'HGNC': '3'}) d = Agent('D', db_refs={'HGNC': '4'}) d_phos = Agent('D', mods=[ModCondition('phosphorylation')], db_refs={'HGNC': '4'}) # Two paths from A to D: One going through B and another through C st1 = Phosphorylation(a, b) st2 = Phosphorylation(b_phos, d) st3 = Phosphorylation(a, c) st4 = Phosphorylation(c_phos, d) # Statements/Data agents for checking stmt_to_check = Phosphorylation(a, d) agent_obs = [b_phos, c_phos, d_phos] # Make model pa = PysbAssembler() pa.add_statements([st1, st2, st3, st4]) pa.make_model(policies='one_step') mc = ModelChecker(pa.model, [stmt_to_check], agent_obs) results = mc.check_model(max_paths=5) mc.get_im().draw('im.pdf', prog='dot') # Create observable assert len(results) == 1 pr = results[0][1] res = pr.paths[0:2] assert len(res) == 2 p1 = [('A_phosphorylation_B_phospho', 1), ('B_phospho_phosphorylation_D_phospho', 1), ('D_phospho_p_obs', 1)] assert p1 in res p2 = [('A_phosphorylation_C_phospho', 1), ('C_phospho_phosphorylation_D_phospho', 1), ('D_phospho_p_obs', 1)] assert p2 in res # Now, a vector linking agents with values, expressed at first as # +/- 1 # This data should ensure that the path through B should be more highly # ranked than the path through C data = {b_phos: 1, c_phos: -1, d_phos: 1} paths = results[0][1].paths scored_paths = mc.score_paths(paths, data) assert scored_paths[0][0] == p1 assert scored_paths[0][1] == 0 assert scored_paths[1][0] == p2
def test_prune_influence_map(): kin = Agent('Kin', db_refs={'HGNC': '1'}) phos = Agent('Phos', db_refs={'HGNC': '2'}) subs = Agent('Substrate', db_refs={'HGNC': '3'}) st1 = Phosphorylation(kin, subs) st2 = Dephosphorylation(phos, subs) pa = PysbAssembler() pa.add_statements([st1, st2]) pa.make_model(policies='one_step') mc = ModelChecker(pa.model, [st1]) mc.prune_influence_map() im = mc.get_im() assert len(im.nodes()) == 3 assert len(im.edges()) == 2
def test_activate_via_mod(): mek = Agent('MEK1', db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) erka = Agent('ERK2', mods=[ModCondition('phosphorylation', 'T', '185')], db_refs={'HGNC': '6871'}) st1 = Phosphorylation(mek, erk, 'T', '185') st2 = ActiveForm(erka, 'activity', True) st3 = Activation(mek, erk) pa = PysbAssembler() pa.add_statements([st1, st2]) pa.make_model() mc = ModelChecker(pa.model, [st3]) checks = mc.check_model() # Make sure it checks out to True assert (checks[0][1].path_found)
def test_rasgap_activation(): nf1 = Agent('NF1', db_refs={'HGNC': '1'}) ras = Agent('KRAS', db_refs={'HGNC': '2'}) rasgap_stmt = RasGap(nf1, ras) act_stmt = Inhibition(nf1, ras, 'gtpbound') # Check that the activation is satisfied by the RasGap pysba = PysbAssembler() pysba.add_statements([rasgap_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1] == True # TODO TODO TODO """
def test_rasgef_activation(): sos = Agent('SOS1', db_refs={'HGNC': '1'}) ras = Agent('KRAS', db_refs={'HGNC': '2'}) rasgef_stmt = RasGef(sos, ras) act_stmt = Activation(sos, ras, 'gtpbound') # Check that the activation is satisfied by the RasGef pysba = PysbAssembler() pysba.add_statements([rasgef_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1].paths == [[('SOS1_activates_KRAS', 1), ('KRAS_gtpbound_active_obs', 1)]] # TODO TODO TODO """
def test_observables(): mek = Agent('MEK1', db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) erkp = Agent('ERK2', mods=[ModCondition('phosphorylation', 'T', '185')], db_refs={'HGNC': '6871'}) st1 = Phosphorylation(mek, erk, 'T', '185') st2 = ActiveForm(erkp, 'activity', True) st3 = Activation(mek, erk) pa = PysbAssembler() pa.add_statements([st1, st2]) pa.make_model() mc = ModelChecker(pa.model, [st1, st3], agent_obs=[erkp]) checks = mc.check_model() assert checks[0][1].path_found assert checks[1][1].path_found # Only 1 observable should be created assert len(mc.model.observables) == 1
def test_rasgef_rasgtp(): sos = Agent('SOS1', db_refs={'HGNC': '1'}) ras = Agent('KRAS', activity=ActivityCondition('gtpbound', True), db_refs={'HGNC': '2'}) raf = Agent('BRAF', db_refs={'HGNC': '3'}) rasgef_stmt = RasGef(sos, ras) rasgtp_stmt = RasGtpActivation(ras, raf, 'kinase') act_stmt = Activation(sos, raf, 'kinase') # Check that the activation is satisfied by the RasGef pysba = PysbAssembler() pysba.add_statements([rasgef_stmt, rasgtp_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1] == True
def test_check_activation(): a = Agent('A', db_refs={'HGNC': '1'}) b = Agent('B', db_refs={'HGNC': '2'}) c = Agent('C', db_refs={'HGNC': '3'}) st1 = Activation(a, b) st2 = Inhibition(b, c, 'kinase') stmts = [st1, st2] # Create the model pa = PysbAssembler() pa.add_statements(stmts) pa.make_model(policies='one_step') mc = ModelChecker(pa.model, stmts) results = mc.check_model() assert len(results) == len(stmts) assert isinstance(results[0], tuple) assert results[0][1].paths == [[('A_activates_B_activity', 1), ('B_activity_active_obs', 1)]] assert results[1][1].paths == [[('B_deactivates_C_kinase', 1), ('C_kinase_active_obs', -1)]]
def test_rasgef_rasgtp_phos(): sos = Agent('SOS1', db_refs={'HGNC': '1'}) ras = Agent('KRAS', activity=ActivityCondition('gtpbound', True), db_refs={'HGNC': '2'}) raf = Agent('BRAF', db_refs={'HGNC': '3'}) mek = Agent('MEK', db_refs={'HGNC': '4'}) rasgef_stmt = RasGef(sos, ras) rasgtp_stmt = RasGtpActivation(ras, raf, 'kinase') phos = Phosphorylation(raf, mek) stmt_to_check = Phosphorylation(sos, mek) # Assemble and check pysba = PysbAssembler() pysba.add_statements([rasgef_stmt, rasgtp_stmt, phos]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [stmt_to_check]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == stmt_to_check assert checks[0][1] == True
def test_rasgap_rasgtp(): nf1 = Agent('NF1', db_refs={'HGNC': '1'}) ras = Agent('KRAS', db_refs={'HGNC': '2'}) ras_g = Agent('KRAS', activity=ActivityCondition('gtpbound', True), db_refs={'HGNC': '2'}) raf = Agent('BRAF', db_refs={'HGNC': '3'}) rasgap_stmt = RasGap(nf1, ras) rasgtp_stmt = RasGtpActivation(ras_g, raf, 'kinase') act_stmt = Inhibition(nf1, raf, 'kinase') # Check that the activation is satisfied by the RasGap pysba = PysbAssembler() pysba.add_statements([rasgap_stmt, rasgtp_stmt]) pysba.make_model(policies='one_step') mc = ModelChecker(pysba.model, [act_stmt]) checks = mc.check_model() assert len(checks) == 1 assert checks[0][0] == act_stmt assert checks[0][1].paths == [[('NF1_deactivates_KRAS', 1), ('KRAS_activates_BRAF_kinase', -1), ('BRAF_kinase_active_obs', -1)]]