Esempio n. 1
0
 def test_initialization(self, known_microbiome, random_microbiome):
     known = Microbiota(known_microbiome, init_abund=[1.0, 1.0])
     assert len(known) == len(known_microbiome)
     rand = Microbiota(random_microbiome, init_abund=[10.0, 1.0, 0.5])
     assert len(rand) == len(random_microbiome)
     with pytest.raises(ValueError):
         Microbiota(known_microbiome, init_abund=[-1.0, 1.0])
Esempio n. 2
0
 def test_eat_order(self, random_microbiome):
     rand1 = Microbiota(random_microbiome, init_abund=[1.0, 3.0, 2.0])
     order = rand1.eat_order
     assert len(order) == 3
     assert set(order.pop() for _ in range(3)) == set(random_microbiome)
     rand2 = Microbiota(random_microbiome, init_abund=[0.0, 0.0, 0.0])
     order = rand2.eat_order
     assert len(order) == 3
     assert set(order.pop() for _ in range(3)) == set(random_microbiome)
Esempio n. 3
0
 def test_select_action(self, core_regulator_inst):
     microbe, regulator = core_regulator_inst
     media = Media(Microbiota([microbe], [1.0]), {})
     flux_dict = microbe.ex_fluxes
     conc_dict = microbe.get_model_media(media.concentrations)
     action = regulator.select_action(conc_dict, flux_dict)
     [(action_value, _)] = action.phi.values()
     assert np.isclose(action_value, 0.0)
Esempio n. 4
0
 def test__encode_state(self, core_regulator_inst):
     microbe, regulator = core_regulator_inst
     media = Media(Microbiota([microbe], [1.0]), {})
     flux_dict = microbe.ex_fluxes
     conc_dict = microbe.get_model_media(media.concentrations)
     state = regulator._encode_state(conc_dict, flux_dict)
     conc_state = state[:len(conc_dict)]
     assert 0 <= conc_state.mean() <= 1
     assert conc_state.std() <= 1
     flux_state = state[len(conc_dict):]
     assert -1 <= flux_state.mean() <= 1
     assert flux_state.std() <= 1
Esempio n. 5
0
 def test_abundances(self, random_microbiome):
     rand = Microbiota(random_microbiome, init_abund=[1.0, 3.0, 2.0])
     expected_abund = dict(
         zip([m.id for m in random_microbiome], [1.0, 3.0, 2.0]))
     assert rand.abundances == expected_abund
Esempio n. 6
0
 def test_ex_metabolites(self, random_microbiome):
     rand = Microbiota(random_microbiome, init_abund=[1.0, 1.0, 1.0])
     all_exmets = 0
     for microbe in rand:
         all_exmets += len(microbe.ex_metabolites)
     assert len(rand.ex_metabolites) == all_exmets
Esempio n. 7
0
 def test_ex_reactions(self, random_microbiome):
     rand = Microbiota(random_microbiome, init_abund=[1.0, 1.0, 1.0])
     all_exrxns = 0
     for microbe in rand:
         all_exrxns += len(microbe.ex_reactions)
     assert len(rand.ex_reactions) == all_exrxns
Esempio n. 8
0
 def test_get_microbe_byid(self, known_microbiome):
     known = Microbiota(known_microbiome, init_abund=[1.0, 1.0])
     core_microbe = known.get_microbe_byid('e_coli_core')
     assert core_microbe.id == 'e_coli_core'