Exemplo n.º 1
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)
Exemplo n.º 2
0
    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]
        })
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
    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)