示例#1
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)
示例#2
0
 def test_apply_multiple_interventions(self):
     intervention1 = mnm_repr.Add(self.con1)
     intervention2 = mnm_repr.Remove(self.con1)
     intervention3 = mnm_repr.Add(self.act1)
     intervention4 = mnm_repr.Remove(self.act1)
     setup_conds = [self.con2]
     interm_activs = [self.act2]
     term_conds = [self.con3, self.con4]
     model = mnm_repr.Model('ID', setup_conds, interm_activs, term_conds)
     model.apply_interventions(
         [intervention1, intervention2, intervention3, intervention4])
     self.assertEqual(model.setup_conditions, frozenset([self.con2]))
     self.assertEqual(model.intermediate_activities, frozenset([self.act2]))
示例#3
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]
        })
示例#4
0
 def test_apply_intervention_add_activity(self):
     intervention = mnm_repr.Add(self.act1)
     setup_conds = [self.con1, self.con2]
     interm_activs = [self.act2]
     term_conds = [self.con3, self.con4]
     model = mnm_repr.Model('ID', setup_conds, interm_activs, term_conds)
     model.apply_intervention(intervention)
     self.assertEqual(model.intermediate_activities,
                      frozenset([self.act2, self.act1]))
示例#5
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)
示例#6
0
    def create_revised_models(self, base_model, solution):
        interv_add = [
            mnm_repr.Add(self.archive.get_matching_element(e_id))
            for e_id in solution[0]
        ]
        interv_rem = [
            mnm_repr.Remove(self.archive.get_matching_element(e_id))
            for e_id in solution[1]
        ]
        covered_res = [
            self.archive.get_matching_result(res_id) for res_id in solution[2]
        ]
        ignored_res = [
            self.archive.get_matching_result(res_id) for res_id in solution[3]
        ]

        new_model = copy(base_model)
        new_model.apply_interventions(interv_rem)
        new_model.apply_interventions(interv_add)
        new_model.results_covered = frozenset(covered_res)
        new_model.ignored_results = frozenset(ignored_res)

        return new_model
示例#7
0
 def generate_all_possible(self, entities, compartments, activities,
                           setup_conds, import_activities):
     # exp types:
     self.types = {
         DetectionEntity: None,
         AdamTwoFactorExperiment: None,
         ReconstructionActivity: None,
         ReconstructionEnzReaction: None,
         ReconstructionTransporterRequired: None,
         LocalisationEntity: None,
         DetectionActivity: None
     }
     # compartments for checking localisation:
     self.design_compartment = {
         'c_02': None,
         'c_03': None,
         'c_04': None,
         'c_05': None,
         'c_06': None,
         'c_07': None,
         'c_08': None,
         'c_09': None,
         'c_10': None,
         'c_11': None,
         'c_12': None,
         'c_13': None,
         'c_14': None,
         'c_15': None,
         'c_16': None,
         'c_17': None,
         'c_18': None,
         'c_19': None,
         'c_20': None,
         'c_21': None,
         'c_22': None,
         'c_23': None,
         'c_24': None,
         'c_25': None,
         'c_26': None,
         'c_27': None,
         'c_28': None,
         'c_29': None,
         'c_30': None,
         'c_31': None,
         'c_32': None,
         'c_33': None,
         'c_34': None
     }
     # rest of elements:
     self.design_deletable = {}
     self.design_available = {}
     self.design_activity_rec = {}
     self.design_activity_det = {}
     self.design_entity_loc = {}
     self.design_entity_det = {}
     self.intervention_add = {}
     self.intervention_remove = {}
     #
     for act in import_activities:
         self.intervention_add[mnm_repr.Add(act)] = 1
     #
     for st in setup_conds:
         # all genes can be removed; metabs can only be removed from medium
         if (isinstance(st.entity, mnm_repr.Gene)
                 or isinstance(st.compartment, Medium)):
             self.intervention_remove[mnm_repr.Remove(st)] = None
         if isinstance(st.entity, mnm_repr.Gene):
             self.design_deletable[st.entity] = None
     #
     for ent in entities:
         if isinstance(ent, mnm_repr.Gene):
             continue
         else:  # Met, Prot, Cplx
             self.design_available[ent] = None
             self.design_entity_det[ent] = None
         if isinstance(ent, mnm_repr.Metabolite):
             self.intervention_add[mnm_repr.Add(
                 mnm_repr.PresentEntity(ent, Medium()))] = None
         else:  # Prot, Cplx
             self.design_entity_loc[ent] = None
     #
     for act in activities:
         # don't test these additional import reactions: they're only to help with experiments
         if act in import_activities:
             continue
         elif isinstance(act, mnm_repr.Growth):
             self.design_activity_det[act] = None
         else:
             self.design_activity_rec[act] = None