Exemple #1
0
 def test_attach_regulation(self, random_model):
     random_microbe = Microbe(random_model)
     random_microbe.attach_regulation(Regulator)
     reg = random_microbe.regulator
     rxns = random_microbe.ex_reactions
     mets = random_microbe.ex_metabolites
     assert len(reg.state_space) == len(rxns) + len(mets)
     assert len(reg.action_space) == 2 * len(rxns)
Exemple #2
0
 def test_death(self, core_model):
     microbe = Microbe(core_model)
     glc_rxn = microbe.get_rxn_byid('EX_glc__D_e')
     glc_rxn.fix_rxn_bound(1.0, 'fixed')  # because fix tolerance is +-1
     obj_val, status, penalty = microbe.optimize()
     assert np.isclose(obj_val, 0.0, rtol=1e-2)
     assert status == 'failed'
     assert penalty == Microbe.death_penalty
Exemple #3
0
 def test_optimization(self, core_model):
     microbe = Microbe(core_model)
     obj_val, status, death_penalty = microbe.growth
     assert np.isclose(obj_val, 0.874, rtol=1e-2)
     assert status == 'optimal'
     assert np.isclose(death_penalty, 0.2)
     obj_val1, status1, death_penalty1 = microbe.optimize(
         opt_type='default')
     assert obj_val == obj_val1
     assert status == status1
     assert death_penalty == death_penalty1
Exemple #4
0
 def test_initialization(self, random_model):
     random_microbe = Microbe(random_model, init_biomass=1.0)
     assert random_microbe._model == random_model
     assert random_microbe.id == random_model.id
     assert random_microbe.abundance == 1.0
     assert len(random_microbe.metabolites) == len(random_model.metabolites)
     assert len(random_microbe.reactions) == len(random_model.reactions)
Exemple #5
0
 def check_solver(self, random_model):
     random_microbe = Microbe(random_model)
     solvers = optlang.list_available_solvers()
     assert any(self.solvers.values)  # any solver available
     if solvers['GUORBI']:
         assert random_microbe.solver == 'gurobi'
     if solvers['GLPK']:
         assert random_microbe.solver == 'glpk'
def core_regulator_inst(core_model):
    core_microbe = Microbe(core_model)
    rxn_list = [rxn.id for rxn in core_microbe.ex_reactions]
    comp_list = [met.id for met in core_microbe.ex_metabolites]
    return core_microbe, Regulator(rxn_list, comp_list)
def random_regulator_inst(random_model):
    random_microbe = Microbe(random_model)
    rxn_list = [rxn.id for rxn in random_microbe.ex_reactions]
    comp_list = [met.id for met in random_microbe.ex_metabolites]
    return random_microbe, Regulator(rxn_list, comp_list)
Exemple #8
0
def random_microbiome(random_microbes):
    return [Microbe(m) for m in random_microbes]
Exemple #9
0
def known_microbiome(known_microbes):
    return [Microbe(m) for m in known_microbes]
Exemple #10
0
 def calc_reward(self, core_model):
     core_microbe = Microbe(core_model, init_biomass=1.0)
     reward = core_microbe.calc_reward(-0.1)
     a = Microbe.alpha
     b = Microbe.beta
     assert np.isclose(reward, (a * 0.874 + b * -0.1), rtol=1e-2)
Exemple #11
0
 def test_update_abundance(self, core_model):
     core_microbe = Microbe(core_model, init_biomass=1.0)
     core_microbe.optimize()
     core_microbe.update_abundance(dt=0.1)
     assert np.isclose(core_microbe.abundance, (1.0 + 1.0 * 0.874 * 0.1),
                       rtol=1e-2)
Exemple #12
0
 def test_get_metbyid(self, core_model):
     microbe = Microbe(core_model)
     glc_met = microbe.get_met_byid('glc__D_e')
     assert glc_met.id == 'glc__D_e'
     assert glc_met._met.id == 'glc__D_e'
Exemple #13
0
 def test_get_rxn_byid(self, core_model):
     microbe = Microbe(core_model)
     glc_rxn = microbe.get_rxn_byid('EX_glc__D_e')
     assert glc_rxn.id == 'EX_glc__D_e'
     assert glc_rxn._rxn.id == 'EX_glc__D_e'
Exemple #14
0
 def test_ex_reactions_and_fluxes(self, random_model):
     microbe = Microbe(random_model)
     ex_reactions = microbe.ex_reactions
     assert len(microbe.ex_fluxes) == len(ex_reactions)
Exemple #15
0
 def test_eq_hash(self, random_model):
     model1 = Microbe(random_model, init_biomass=1.0)
     model2 = Microbe(random_model, init_biomass=5.0)
     assert model1 == model2
     assert len(set([model1, model2])) == 1