def test_modeh_replacement(self): # prepare the cost model g1 = mnm_repr.Gene('g1') p1 = mnm_repr.Protein('p1') met1 = mnm_repr.Metabolite('met1') met2 = mnm_repr.Metabolite('met2') cplx1 = mnm_repr.Complex('cplx1') cytosol = mnm_repr.Cytosol() cond1 = mnm_repr.PresentEntity(met1, cytosol) cond2 = mnm_repr.PresentEntity(met2, cytosol) cond3 = mnm_repr.PresentEntity(p1, cytosol) cond4 = mnm_repr.PresentEntity(cplx1, cytosol) growth = mnm_repr.Growth('growth', [cond2]) r1 = mnm_repr.Reaction('r1', [cond1], [cond2]) r2 = mnm_repr.Reaction('r2', [cond3], [cond4]) entities = [g1, p1, met1, met2, cplx1] compartments = [cytosol] activities = [growth, r1, r2] setup_conds = [cond1, cond3] model = CostModel(entities, compartments, activities, setup_conds) model.set_all_basic_costs_to_1() model.calculate_derived_costs(activities) # test out = exporter.modeh_replacement(model) self.assertIsInstance(out, str)
def setUp(self): self.con1 = mnm_repr.PresentEntity('ent1', 'comp1') self.con2 = mnm_repr.PresentEntity('ent2', 'comp2') self.con3 = mnm_repr.PresentEntity('ent3', 'comp3') self.con4 = mnm_repr.PresentEntity('ent4', 'comp4') self.act1 = mnm_repr.Activity('ID1', 'name1', [self.con1], []) self.act2 = mnm_repr.Activity('ID2', 'name2', [self.con2], [])
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_cost_rules(self): # prepare the cost model g1 = mnm_repr.Gene('g1') p1 = mnm_repr.Protein('p1') met1 = mnm_repr.Metabolite('met1') met2 = mnm_repr.Metabolite('met2') cplx1 = mnm_repr.Complex('cplx1') cytosol = mnm_repr.Cytosol() cond1 = mnm_repr.PresentEntity(met1, cytosol) cond2 = mnm_repr.PresentEntity(met2, cytosol) cond3 = mnm_repr.PresentEntity(p1, cytosol) cond4 = mnm_repr.PresentEntity(cplx1, cytosol) growth = mnm_repr.Growth('growth', [cond2]) r1 = mnm_repr.Reaction('r1', [cond1], [cond2]) r2 = mnm_repr.Reaction('r2', [cond3], [cond4]) entities = [g1, p1, met1, met2, cplx1] compartments = [cytosol] activities = [growth, r1, r2] setup_conds = [cond1, cond3] model = CostModel(entities, compartments, activities, setup_conds) model.set_all_basic_costs_to_1() model.calculate_derived_costs(activities) # test out = exporter.cost_rules(model) # self.assertIn('\ncost(1, 0) :- add(setup_present(met1, none, c_01)).', out) self.assertEqual(len(out), 55)
def test_export_experiment_specification_elements(self): # prepare the cost model g1 = mnm_repr.Gene('g1') p1 = mnm_repr.Protein('p1') met1 = mnm_repr.Metabolite('met1') met2 = mnm_repr.Metabolite('met2') cplx1 = mnm_repr.Complex('cplx1') cytosol = mnm_repr.Cytosol() cond1 = mnm_repr.PresentEntity(met1, cytosol) cond2 = mnm_repr.PresentEntity(met2, cytosol) cond3 = mnm_repr.PresentEntity(p1, cytosol) cond4 = mnm_repr.PresentEntity(cplx1, cytosol) growth = mnm_repr.Growth('growth', [cond2]) r1 = mnm_repr.Reaction('r1', [cond1], [cond2]) r2 = mnm_repr.Reaction('r2', [cond3], [cond4]) entities = [g1, p1, met1, met2, cplx1] compartments = [cytosol] activities = [growth, r1, r2] setup_conds = [cond1, cond3] model = CostModel(entities, compartments, activities, setup_conds) model.set_all_basic_costs_to_1() model.calculate_derived_costs(activities) # test out = exporter.export_experiment_specification_elements(model) self.assertEqual(len(out.keys()), 55) self.assertNotIn(None, out.values())
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_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_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_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_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)
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