def test_export_ignore_results(self): des = exp_repr.ExperimentDescription(exp_repr.DetectionEntity('e1')) res1 = exp_repr.Result('res1', des, None) res2 = exp_repr.Result('res2', des, None) out = exporter.export_ignore_results([res1, res2]) self.assertIn('\n#modeh ignored(res1) =1 @2.', out) self.assertIn('\n#modeh ignored(res2) =1 @2.', out)
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_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_calculate_max_number_activities(self): # model with activities, archive with results that have add activity in interventions a1 = mnm_repr.Activity('act1', None, ['a'], []) a2 = mnm_repr.Activity('act1', None, ['b'], []) a3 = mnm_repr.Activity('act1', None, ['c'], []) a4 = mnm_repr.Activity('act1', None, ['d'], []) base_model = mnm_repr.Model('m1', [], [a1], []) des1 = exp_repr.ExperimentDescription( None, [mnm_repr.Add(a2), mnm_repr.Add(a1)]) des2 = exp_repr.ExperimentDescription(None, [mnm_repr.Add(a3)]) des3 = exp_repr.ExperimentDescription( None, [mnm_repr.Add(a4), mnm_repr.Add(a3)]) res1 = exp_repr.Result('r1', des1, None) res2 = exp_repr.Result('r2', des2, None) res3 = exp_repr.Result('r3', des3, None) exp1 = exp_repr.Experiment('exp1', [res1]) exp2 = exp_repr.Experiment('exp2', [res2]) exp3 = exp_repr.Experiment('exp3', [res3]) arch = Archive() arch.known_results = [exp1, exp2, exp3] rev = RevisionModule(arch) out = rev.calculate_max_number_activities(base_model) self.assertEqual(out, 4)
def test_export_relevancy_results_consistency(self): # one ignored result, one not ignored res1 = exp_repr.Result('res1', None, None) res2 = exp_repr.Result('res2', None, None) m = mnm_repr.Model('m1', [], [], []) m.ignored_results = frozenset([res1]) base_model = m models_results = {m: [res1, res2]} exported = exporter.export_relevancy_results_consistency( models_results, base_model) self.assertNotIn('\nrelevant(res1, m1).', exported) self.assertNotIn('\n:- inconsistent(m1, res1).', exported) self.assertIn('\nrelevant(res2, m1).', exported) self.assertIn('\n:- inconsistent(m1, res2).', exported)
def test_export_results(self): # one of exp types; no need to test all (they do the same thing) exp_type = exp_repr.LocalisationEntity('p1', 'c_02') res = exp_repr.Result('res1', exp_repr.ExperimentDescription(exp_type, []), True) exported = exporter.export_results([res]) self.assertIn( '\nresult(res1, experiment(localisation_entity_exp, p1, c_02), True).', exported)
def setUp(self): # models: self.g1 = Gene('g1') self.p1 = Protein('p1') self.met1 = Metabolite('met1') self.met2 = Metabolite('met2') self.cplx1 = Complex('cplx1') self.cytosol = Cytosol() self.cond1 = PresentEntity(self.met1, self.cytosol) self.cond2 = PresentEntity(self.met2, self.cytosol) self.cond3 = PresentEntity(self.p1, self.cytosol) self.cond4 = PresentEntity(self.cplx1, self.cytosol) self.growth = Growth('growth', [self.cond2]) self.growth.reversibility = False self.r1 = Reaction('r1', [self.cond1], [self.cond2]) self.r2 = Reaction('r2', [self.cond3], [self.cond4]) self.r1.reversibility = False self.r2.reversibility = False self.entities = [self.g1, self.p1, self.met1, self.met2, self.cplx1] self.compartments = [self.cytosol] self.activities = [self.growth, self.r1, self.r2] self.setup_conds = [self.cond1, self.cond3] self.mod1 = Model('m0', self.setup_conds, [self.growth, self.r1], []) self.mod2 = Model('m1', self.setup_conds, [self.growth, self.r2], []) # cost_module: self.cost_model = CostModel(self.entities, self.compartments, self.activities, self.setup_conds) self.cost_model.set_all_basic_costs_to_1() self.cost_model.calculate_derived_costs(self.activities) self.cost_model.remove_None_valued_elements() # known results (one exp, both models consistent) self.exd = exp_repr.ExperimentDescription( exp_repr.DetectionEntity('met1'), []) self.res = exp_repr.Result('res1', self.exd, 'true') self.exp = exp_repr.Experiment('exp1', [self.res]) # archive self.arch = Archive() self.arch.working_models = [self.mod1, self.mod2] self.arch.known_results = [self.exp] self.arch.mnm_compartments = self.compartments self.arch.mnm_entities = self.entities self.arch.mnm_activities = self.activities # exp module self.exp_module = ExperimentModule(self.arch, self.cost_model, False)
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)