def test_make_derivative_models(self): rev = RevisionModule('archive') cond_subst_1 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met1'), mnm_repr.Medium()) cond_subst_2 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met2'), mnm_repr.Medium()) base_model = mnm_repr.Model( 'm1', [cond_subst_1], [], []) #model that is compatible with interventions second_mod = mnm_repr.Model('deriv_m1_0', [cond_subst_1, cond_subst_2], [], []) third_mod = mnm_repr.Model('deriv_m1_1', [], [], []) exd1 = exp_repr.ExperimentDescription(None, [mnm_repr.Add(cond_subst_2)]) exd2 = exp_repr.ExperimentDescription(None, [mnm_repr.Remove(cond_subst_1)]) res1 = exp_repr.Result('r1', exd1, True) res2 = exp_repr.Result('r2', exd2, True) extracted_results = [res1, res2] #need interventions in description models_results = rev.make_derivative_models(base_model, extracted_results) self.assertEqual(models_results, { base_model: [], second_mod: [res1], third_mod: [res2] })
def test_export_activity(self): # one substrate, one catalyst, one transporter; one product cond_subst = mnm_repr.PresentEntity(mnm_repr.Metabolite('met1'), mnm_repr.Medium()) cond_cat = mnm_repr.PresentCatalyst(mnm_repr.Medium()) cond_trp = mnm_repr.PresentTransporter(mnm_repr.Medium()) prod = mnm_repr.PresentEntity(mnm_repr.Metabolite('met2'), mnm_repr.Medium()) act = mnm_repr.Activity('a1', 'none', [cond_subst, cond_cat, cond_trp], [prod]) act.reversibility = True exported = exporter.export_activity(act) # forward self.assertIn('\nsubstrate(met1,none,c_01,a1).', exported) self.assertIn('\nenz_required(a1).', exported) self.assertIn('\nenz_compartment(c_01,a1).', exported) self.assertIn('\ntransp_required(a1).', exported) self.assertIn('\ntransp_compartment(c_01,a1).', exported) self.assertIn('\nproduct(met2,none,c_01,a1).', exported) # reversed self.assertIn('\nproduct(met1,none,c_01,a1_rev).', exported) self.assertIn('\nenz_required(a1_rev).', exported) self.assertIn('\nenz_compartment(c_01,a1_rev).', exported) self.assertIn('\ntransp_required(a1_rev).', exported) self.assertIn('\ntransp_compartment(c_01,a1_rev).', exported) self.assertIn('\nsubstrate(met2,none,c_01,a1_rev).', exported)
def test_export_termination_conds_consistency(self): # one cond cond_subst_1 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met1'), mnm_repr.Medium()) cond_subst_2 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met2'), mnm_repr.Medium()) m = mnm_repr.Model('m1', [], [], [cond_subst_1, cond_subst_2]) exported = exporter.export_termination_conds_consistency(m) self.assertIn('\n:- not synthesizable(met1, none, c_01, m1).', exported) self.assertIn('\n:- not synthesizable(met2, none, c_01, m1).', exported)
def test_export_compartments(self): # a couple of compartments c1 = mnm_repr.Medium() c2 = mnm_repr.CellMembrane() c3 = mnm_repr.CellMembraneOuterSide() exported = exporter.export_compartments([c1, c2, c3]) self.assertEqual("\ncompartment(c_01;c_02;c_03).", exported[0])
def test_RevCIAddB_revise_ignoring(self): met1 = mnm_repr.Metabolite('met1') met2 = mnm_repr.Metabolite('met2') comp1 = mnm_repr.Medium() cond_subst_1 = mnm_repr.PresentEntity(met1, comp1) cond_subst_2 = mnm_repr.PresentEntity(met2, comp1) a1 = mnm_repr.Reaction('act1', [], [cond_subst_1, cond_subst_2]) a1.remove_cost = None a1.reversibility = False a2 = mnm_repr.Reaction('act1', [], [cond_subst_1]) a2.reversibility = False # model to be revised mod = mnm_repr.Model('m_0', [], [a1], []) # results des1 = exp_repr.ExperimentDescription(exp_repr.DetectionEntity('met1'), []) des2 = exp_repr.ExperimentDescription(exp_repr.DetectionEntity('met2'), []) res1 = exp_repr.Result('res_0', des1, 'false') res2 = exp_repr.Result('res_1', des2, 'true') exp1 = exp_repr.Experiment('exp_0', [res1]) exp2 = exp_repr.Experiment('exp_1', [res2]) # archive with results and parts for revision arch = Archive() arch.known_results = [exp1, exp2] arch.mnm_activities = [a1, a2] arch.mnm_entities = [met1, met2] arch.mnm_compartments = [comp1] rev = RevCIAddB(arch) out = rev.revise(mod) self.assertEqual(out[0], []) self.assertEqual(out[1], True)
def test_export_model_specification(self): # 2 conds + 2 activ cond_subst_1 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met1'), mnm_repr.Medium()) cond_subst_2 = mnm_repr.PresentEntity(mnm_repr.Metabolite('met2'), mnm_repr.Medium()) act_1 = mnm_repr.Activity('a1', None, ['1'], []) act_2 = mnm_repr.Activity('a2', None, ['2'], []) m = mnm_repr.Model('m1', [cond_subst_1, cond_subst_2], [act_1, act_2], []) exported = exporter.export_model_specification(m) self.assertIn('\nadded_to_model(setup_present(met1,none,c_01),m1).', exported) self.assertIn('\nadded_to_model(setup_present(met2,none,c_01),m1).', exported) self.assertIn('\nadded_to_model(a1,m1).', exported) self.assertIn('\nadded_to_model(a2,m1).', exported)
def test_ban_experiment(self): comp = mnm_repr.Medium() ent1 = mnm_repr.Metabolite('m1') cond1 = mnm_repr.PresentEntity(ent1, comp) inter1 = mnm_repr.Add(cond1) ent2 = mnm_repr.Metabolite('m2') cond2 = mnm_repr.PresentEntity(ent2, comp) inter2 = mnm_repr.Remove(cond2) exp_description = exp_repr.ExperimentDescription( exp_repr.DetectionEntity('ent1'), [inter1, inter2]) out = exporter.ban_experiment(exp_description) # print([out]) self.assertIn('\n:- designed(experiment(detection_entity_exp, ent1))', out) self.assertIn(',remove(setup_present(m2, none, c_01))', out) self.assertIn(',add(setup_present(m1, none, c_01))', out)
def test_check_consistency_negative(self): met1 = mnm_repr.Metabolite('met1') met2 = mnm_repr.Metabolite('met2') comp1 = mnm_repr.Medium() cond_subst_1 = mnm_repr.PresentEntity(met1, comp1) cond_subst_2 = mnm_repr.PresentEntity(met2, comp1) base_model = mnm_repr.Model('m1', [cond_subst_1, cond_subst_2], [], []) exd = exp_repr.ExperimentDescription(exp_repr.DetectionEntity('met1'), []) res = exp_repr.Result('r1', exd, 'false') exp = exp_repr.Experiment('exp1', [res]) arch = Archive() arch.mnm_entities = [met1, met2] arch.mnm_compartments = [comp1] ev1 = AdditionalModels([base_model]) ev2 = AcceptedResults(exp) arch.record(ev1) arch.record(ev2) rev = RevisionModule(arch) out = rev.check_consistency(base_model) self.assertEqual(False, out)