def test_kappa_cm_export(): stmts = [Complex([Agent('a'), Agent('b')])] pa = PysbAssembler(stmts) pa.make_model() graph = pa.export_model('kappa_cm', '/dev/null') assert len(graph.nodes()) == 2 assert len(graph.edges()) == 1
def test_convert_subj(): stmt = Conversion(Agent('PIK3CA'), [Agent('PIP2')], [Agent('PIP3')]) pa = PysbAssembler([stmt]) pa.make_model() assert len(pa.model.parameters) == 4 assert len(pa.model.rules) == 1 assert len(pa.model.monomers) == 3
def test_annotation_regamount(): st1 = IncreaseAmount(Agent('BRAF', db_refs = {'UP': 'P15056'}), Agent('MAP2K2', db_refs = {'HGNC': '6842'})) st2 = DecreaseAmount(Agent('BRAF', db_refs = {'UP': 'P15056'}), Agent('MAP2K2', db_refs = {'HGNC': '6842'})) pa = PysbAssembler([st1, st2]) pa.make_model() assert len(pa.model.annotations) == 8
def test_agent_loc(): st = Phosphorylation(Agent('BRAF', location='cytoplasm'), Agent('MEK')) pa = PysbAssembler([st]) pa.make_model() assert len(pa.model.rules) == 1 r = pa.model.rules[0] braf = r.reactant_pattern.complex_patterns[0].monomer_patterns[0] assert braf.site_conditions == {'loc': 'cytoplasm'}
def test_non_python_name_phos(): st = Phosphorylation(Agent('14-3-3'), Agent('BRAF kinase')) pa = PysbAssembler([st]) pa.make_model() names = [m.name for m in pa.model.monomers] assert 'BRAF_kinase' in names assert 'p14_3_3' in names bng.generate_equations(pa.model)
def test_set_context(): st = Phosphorylation(Agent('MAP2K1'), Agent('MAPK3')) pa = PysbAssembler([st]) pa.make_model() assert pa.model.parameters['MAP2K1_0'].value == pa.default_initial_amount assert pa.model.parameters['MAPK3_0'].value == pa.default_initial_amount pa.set_context('A375_SKIN') assert pa.model.parameters['MAP2K1_0'].value > 10000 assert pa.model.parameters['MAPK3_0'].value > 10000
def test_activity_agent_rule_name(): stmt = Phosphorylation( Agent('BRAF', activity=ActivityCondition('kinase', True)), Agent('MAP2K1', activity=ActivityCondition('activity', False))) pa = PysbAssembler([stmt]) pa.make_model() assert pa.model.rules[0].name == \ 'BRAF_kin_phosphorylation_MAP2K1_act_inact_phospho', \ pa.model.rules[0].name
def test_pysb_assembler_twostep_mixed(): member1 = Agent('BRAF') member2 = Agent('RAF1') st1 = Complex([member1, member2]) st2 = Phosphorylation(Agent('MAP2K1'), Agent('MAPK3')) pa = PysbAssembler([st1, st2]) pa.make_model(policies='two_step') assert len(pa.model.rules) == 5 assert len(pa.model.monomers) == 4
def test_export_model(): st = Phosphorylation(Agent('MAP2K1'), Agent('MAPK3')) pa = PysbAssembler([st]) pa.make_model() exp_str = pa.export_model('kappa') assert exp_str exp_str = pa.export_model('bngl') assert exp_str exp_str = pa.export_model('sbml', file_name='/dev/null') assert exp_str
def test_mut_missing4(): mut = MutCondition(None, None, None) st = Phosphorylation(Agent('BRAF', mutations=[mut]), Agent('MEK')) pa = PysbAssembler([st]) pa.make_model() assert len(pa.model.rules) == 1 r = pa.model.rules[0] braf = r.reactant_pattern.complex_patterns[0].monomer_patterns[0] assert braf.monomer.name == 'BRAF' assert braf.site_conditions == {'mut': 'X'}
def test_neg_agent_mod(): mc = ModCondition('phosphorylation', 'serine', '123', False) st = Phosphorylation(Agent('BRAF', mods=[mc]), Agent('MAP2K2')) pa = PysbAssembler([st]) pa.make_model(policies='one_step') assert len(pa.model.rules) == 1 r = pa.model.rules[0] braf = r.reactant_pattern.complex_patterns[0].monomer_patterns[0] assert braf.monomer.name == 'BRAF' assert braf.site_conditions == {'S123': ('u', WILD)}
def test_kappa_im_export(): stmts = [Activation(Agent('a'), Agent('b')), Activation(Agent('b', activity=ActivityCondition('activity', True)), Agent('c'))] pa = PysbAssembler(stmts) pa.make_model() graph = pa.export_model('kappa_im', '/dev/null') assert len(graph.nodes) == 2 assert len(graph.edges) == 1
def test_pysb_assembler_phos_twostep_local_to_global(): enz = Agent('BRAF') sub = Agent('MEK1') stmt = Phosphorylation(enz, sub, 'serine', '222') pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step') # This call should have reverted to default policy model = pa.make_model() assert len(model.rules) == 1 assert len(model.monomers) == 2
def test_translocation_loc_special_char(): st = Translocation(Agent('KSR1'), 'cytoplasm', 'cell surface') pa = PysbAssembler([st]) pa.make_model() assert len(pa.model.rules) == 1 r = pa.model.rules[0] f1 = r.reactant_pattern.complex_patterns[0].monomer_patterns[0] assert f1.site_conditions == {'loc': 'cytoplasm'} f2 = r.product_pattern.complex_patterns[0].monomer_patterns[0] assert f2.site_conditions == {'loc': 'cell_surface'} assert r.rate_forward.name == 'kf_ksr1_cytoplasm_cell_surface_1'
def test_translocation_to(): st = Translocation(Agent('FOXO3A'), None, 'nucleus') pa = PysbAssembler([st]) pa.make_model() assert len(pa.model.rules) == 1 r = pa.model.rules[0] f1 = r.reactant_pattern.complex_patterns[0].monomer_patterns[0] assert f1.site_conditions == {'loc': 'cytoplasm'} f2 = r.product_pattern.complex_patterns[0].monomer_patterns[0] assert f2.site_conditions == {'loc': 'nucleus'} assert r.rate_forward.name == 'kf_foxo3a_cytoplasm_nucleus_1'
def test_activity_agent_rule_name(): stmt = Phosphorylation(Agent('BRAF', activity=ActivityCondition('kinase', True)), Agent('MAP2K1', activity=ActivityCondition('activity', False))) pa = PysbAssembler([stmt]) pa.make_model() assert pa.model.rules[0].name == \ 'BRAF_kin_phosphorylation_MAP2K1_act_inact_phospho', \ pa.model.rules[0].name
def test_set_context_monomer_notfound(): st = Phosphorylation(Agent('MAP2K1'), Agent('XYZ')) pa = PysbAssembler([st]) pa.make_model() assert pa.model.parameters['MAP2K1_0'].value == pa.default_initial_amount assert pa.model.parameters['XYZ_0'].value == pa.default_initial_amount pa.add_default_initial_conditions(100) assert pa.model.parameters['MAP2K1_0'].value == 100 assert pa.model.parameters['XYZ_0'].value == 100 pa.set_context('A375_SKIN') assert pa.model.parameters['MAP2K1_0'].value > 10000 assert pa.model.parameters['XYZ_0'].value == pa.default_initial_amount
def test_activation_subj1(): """No subject activity is defined.""" st = Activation(Agent('a'), Agent('b')) pa = PysbAssembler([st]) pa.make_model() assert pa.model.monomers['a'].sites == [] left = pa.model.rules[0].reactant_pattern subj_left = left.complex_patterns[0].monomer_patterns[0] right = pa.model.rules[0].product_pattern subj_right = right.complex_patterns[0].monomer_patterns[0] assert subj_left.site_conditions == {} assert subj_right.site_conditions == {}
def test_convert_subj(): stmt = Conversion(Agent('PIK3CA'), [Agent('PIP2')], [Agent('PIP3')]) pa = PysbAssembler([stmt]) pa.make_model() assert len(pa.model.parameters) == 4 assert len(pa.model.rules) == 1 assert len(pa.model.monomers) == 3 # We need to make sure that these are Kappa-compatible, and the easiest # way to do that is by making a ModelChecker and getting the IM without # error from indra.explanation.model_checker import PysbModelChecker pmc = PysbModelChecker(pa.model) pmc.get_im()
def test_missing_catalytic_default_site(): c8 = Agent('CASP8', activity=ActivityCondition('catalytic', True)) c3 = Agent('CASP3') stmt = Activation(c8, c3, 'catalytic') # Interactions only pa = PysbAssembler([stmt]) model = pa.make_model(policies='interactions_only') # One step pa = PysbAssembler([stmt]) model = pa.make_model(policies='one_step') # Two step pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step')
def test_missing_transcription_default_site(): p53 = Agent('TP53', activity=ActivityCondition('transcription', True)) bax = Agent('BAX') stmt = Activation(p53, bax) # Interactions only pa = PysbAssembler([stmt]) model = pa.make_model(policies='interactions_only') # One step pa = PysbAssembler([stmt]) model = pa.make_model(policies='one_step') # Two step pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step')
def test_contact_map_cycles_1(): stmts = [Complex([Agent('a'), Agent('b')]), Complex([Agent('a'), Agent('c')]), Complex([Agent('b'), Agent('c')])] pa = PysbAssembler(stmts) pa.make_model() graph = export_cm_network(pa.model) assert len(graph.nodes()) == 9, len(graph.nodes) assert len(graph.edges()) == 9, len(graph.edges) cycles = get_cm_cycles(graph) assert len(cycles) == 1, cycles assert cycles[0] == ['a(b)', 'b(a)', 'b(c)', 'c(b)', 'c(a)', 'a(c)']
def test_activation_subj3(): """Subject activity is defined implicitly by another statement.""" a_act = Agent('a', activity=ActivityCondition('activity', True)) st = Activation(a_act, Agent('b')) st2 = Activation(Agent('c'), Agent('a')) pa = PysbAssembler([st, st2]) pa.make_model() assert len(pa.model.rules) == 2 assert pa.model.monomers['a'].sites == ['activity'] left = pa.model.rules[0].reactant_pattern subj_left = left.complex_patterns[0].monomer_patterns[0] right = pa.model.rules[0].product_pattern subj_right = right.complex_patterns[0].monomer_patterns[0] assert subj_left.site_conditions == {u'activity': (u'active')} assert subj_right.site_conditions == {u'activity': (u'active')}
def test_activation_subj2(): """Subject activity is defined explicitly.""" a_act = Agent('a', activity=ActivityCondition('activity', True)) st = Activation(a_act, Agent('b')) st2 = ActiveForm(Agent('a', mods=[ModCondition('phosphorylation')]), 'activity', True) pa = PysbAssembler([st, st2]) pa.make_model() assert pa.model.monomers['a'].sites == ['phospho'] left = pa.model.rules[0].reactant_pattern subj_left = left.complex_patterns[0].monomer_patterns[0] right = pa.model.rules[0].product_pattern subj_right = right.complex_patterns[0].monomer_patterns[0] assert subj_left.site_conditions == {u'phospho': (u'p', WILD)} assert subj_right.site_conditions == {u'phospho': (u'p', WILD)}
def test_pysb_assembler_actmod1(): mek = Agent('MEK') erk = Agent('ERK') stmts = [] mc1 = ModCondition('phosphorylation', 'serine', '218') mc2 = ModCondition('phosphorylation', 'serine', '222') stmts.append(ActiveForm(Agent('MEK', mods=[mc1, mc2]), 'activity', True)) stmts.append(Phosphorylation(mek, erk, 'threonine', '185')) stmts.append(Phosphorylation(mek, erk, 'tyrosine', '187')) pa = PysbAssembler(stmts) model = pa.make_model() assert len(model.rules) == 2 assert len(model.monomers) == 2 model = pa.make_model(policies='two_step') assert len(model.rules) == 5
def test_pysb_assembler_actsub(): stmt = ActiveForm(Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')]), 'activity', True) pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step') assert len(model.rules) == 0 assert len(model.monomers) == 1
def test_policy_object(): stmt = Phosphorylation(Agent('a'), Agent('b')) pa = PysbAssembler([stmt]) pol = Policy('two_step') model = pa.make_model(policies={stmt.uuid: pol}) assert len(model.rules) == 3 assert str(pol) == 'Policy(two_step)'
def test_pysb_assembler_autophos1(): enz = Agent('MEK1') stmt = Autophosphorylation(enz, 'serine', '222') pa = PysbAssembler([stmt]) model = pa.make_model() assert len(model.rules) == 1 assert len(model.monomers) == 1
def test_contact_map_cycles_2(): erk1 = Agent('MAPK1', db_refs={'HGNC': '6871'}) erk2 = Agent('MAPK3', db_refs={'HGNC': '6877'}) # In this case there will be no cycles because the binding site on x # for ERK1 and ERK2 is generated to be competitive. stmts = [Complex([Agent('x'), erk1]), Complex([Agent('x'), erk2]), Complex([erk1, erk2])] pa = PysbAssembler(stmts) pa.make_model() graph = export_cm_network(pa.model) assert len(graph.nodes()) == 8, len(graph.nodes) assert len(graph.edges()) == 8, len(graph.edges) cycles = get_cm_cycles(graph) assert not cycles, cycles
def test_pysb_assembler_dephos_twostep1(): phos = Agent('PP2A') sub = Agent('MEK1') stmt = Dephosphorylation(phos, sub, 'serine', '222') pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step') assert len(model.rules) == 3 assert len(model.monomers) == 2
def test_pysb_assembler_complex_twostep(): member1 = Agent('BRAF') member2 = Agent('MEK1') stmt = Complex([member1, member2]) pa = PysbAssembler([stmt]) model = pa.make_model(policies='two_step') assert len(model.rules) == 2 assert len(model.monomers) == 2
def test_activity_activity3(): subj = Agent('Vemurafenib') obj = Agent('BRAF') stmt = Inhibition(subj, obj) pa = PysbAssembler([stmt]) model = pa.make_model(policies='one_step') assert len(model.rules) == 1 assert len(model.monomers) == 2
def test_activity_activity2(): subj = Agent('KRAS') obj = Agent('BRAF') stmt = Activation(subj, obj) pa = PysbAssembler([stmt]) model = pa.make_model(policies='one_step') assert len(model.rules) == 1 assert len(model.monomers) == 2
def test_pysb_assembler_dephos_noenz(): enz = None sub = Agent('MEK1') stmt = Phosphorylation(enz, sub, 'serine', '222') pa = PysbAssembler([stmt]) model = pa.make_model() assert len(model.rules) == 0 assert len(model.monomers) == 0