def test_run_multiobjective(self): result_file = os.path.join(CURRENT_PATH, "data", "reaction_knockout_multi_objective.pkl") objective1 = biomass_product_coupled_yield( "Biomass_Ecoli_core_N_LPAREN_w_FSLASH_GAM_RPAREN__Nmet2", "EX_ac_LPAREN_e_RPAREN_", "EX_glc_LPAREN_e_RPAREN_") objective2 = number_of_knockouts() objective = [objective1, objective2] rko = ReactionKnockoutOptimization(model=self.model, simulation_method=fba, objective_function=objective, heuristic_method=inspyred.ec.emo.NSGA2, seed=SEED) # self.assertEqual(rko.random.random(), 0.1915194503788923) results = rko.run(max_evaluations=3000, pop_size=10, view=SequentialView()) # print(rko.random.random(), 0.545818634701) with open(result_file, 'rb') as in_file: if six.PY3: expected_results = pickle.load(in_file, encoding="latin1") else: expected_results = pickle.load(in_file) assert_frame_equal(results.solutions, expected_results.solutions)
def test_run_single_objective(self): result_file = os.path.join(CURRENT_PATH, "data", "reaction_knockout_single_objective.pkl") objective = biomass_product_coupled_yield( "Biomass_Ecoli_core_N_LPAREN_w_FSLASH_GAM_RPAREN__Nmet2", "EX_ac_LPAREN_e_RPAREN_", "EX_glc_LPAREN_e_RPAREN_") rko = ReactionKnockoutOptimization(model=self.model, simulation_method=fba, objective_function=objective, seed=SEED) # self.assertEqual(rko.random.random(), 0.1915194503788923) results = rko.run(max_evaluations=3000, pop_size=10, view=SequentialView()) # self.assertEqual(rko.random.random(), 0.9268454219291495) with open(result_file, 'rb') as in_file: if six.PY3: expected_results = pickle.load(in_file, encoding="latin1") else: expected_results = pickle.load(in_file) assert_frame_equal(results.solutions, expected_results.solutions)
def __call__(self, strategy, *args, **kwargs): (host, model, pathway) = (strategy[0], strategy[1], strategy[2]) with TimeMachine() as tm: pathway.plug_model(model, tm) objective = biomass_product_coupled_yield(model.biomass, pathway.product, model.carbon_source) opt = GeneKnockoutOptimization(model=model, objective_function=objective, progress=True, plot=False) return opt.run(product=pathway.product.id, max_evaluations=10000)
def test_biomass_product_coupled_yield(self): solution = self._MockupSolution() solution.set_primal('biomass', 0.6) solution.set_primal('product', 2) solution.set_primal('substrate', -10) of = biomass_product_coupled_yield("biomass", "product", "substrate") fitness = of(None, solution, None) self.assertAlmostEqual((0.6 * 2) / 10, fitness) solution.set_primal('substrate', 0) fitness = of(None, solution, None) self.assertEquals(0, fitness)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from cobra.io import read_sbml_model from optlang import glpk_interface import inspyred from cameo.strain_design.heuristic.multiprocess import MultiprocessReactionKnockoutOptimization from cameo.strain_design.heuristic.objective_functions import biomass_product_coupled_yield from cameo.flux_analysis.simulation import fba from cameo.core.solver_based_model import to_solver_based_model model = read_sbml_model("../tests/data/iJO1366.xml") model = to_solver_based_model(model, solver_interface=glpk_interface) of = biomass_product_coupled_yield("Ec_biomass_iJO1366_core_53p95M", "EX_ac_LPAREN_e_RPAREN_", "EX_glc_LPAREN_e_RPAREN_") mp = MultiprocessReactionKnockoutOptimization(model=model, heuristic_method=inspyred.ec.GA, objective_function=of, simulation_method=fba) mp.run(max_evaluations=300, n=2)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from cobra.io import read_sbml_model from optlang import glpk_interface import inspyred from cameo.strain_design.heuristic.multiprocess import MultiprocessReactionKnockoutOptimization from cameo.strain_design.heuristic.objective_functions import biomass_product_coupled_yield from cameo.flux_analysis.simulation import fba from cameo.core.solver_based_model import to_solver_based_model model = read_sbml_model("../tests/data/iJO1366.xml") model = to_solver_based_model(model, solver_interface=glpk_interface) of = biomass_product_coupled_yield("Ec_biomass_iJO1366_core_53p95M", "EX_ac_LPAREN_e_RPAREN_", "EX_glc_LPAREN_e_RPAREN_") mp = MultiprocessReactionKnockoutOptimization(model=model, heuristic_method=inspyred.ec.GA, objective_function=of, simulation_method=fba) mp.run(max_evaluations=300, n=2)