How to use the cameo.strain_design.heuristic.evolutionary.objective_functions.biomass_product_coupled_yield function in cameo

To help you get started, we’ve selected a few cameo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_run_with_time_limit(self, model):
        # TODO: make optlang deterministic so this results can be permanently stored.
        objective = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2", "EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_")

        rko = ReactionKnockoutOptimization(model=model,
                                           simulation_method=fba,
                                           objective_function=objective)

        start_time = time.time()
        rko.run(max_evaluations=3000000, pop_size=10, view=SequentialView(), seed=SEED, max_time=(1, 0))
        elapsed_time = time.time() - start_time

        assert elapsed_time < 1.25 * 60
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def reaction_ko_multi_objective(model):
    objective1 = biomass_product_coupled_yield(
        "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2", "EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_")
    objective2 = number_of_knockouts()
    objective = MultiObjectiveFunction([objective1, objective2])
    return ReactionKnockoutOptimization(model=model, simulation_method=fba, objective_function=objective,
                                        heuristic_method=inspyred.ec.emo.NSGA2)
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_initializer(self, model):
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2",
            "EX_ac_lp_e_rp_",
            "EX_glc_lp_e_rp_")
        decoder = ReactionSetDecoder(["PGI", "PDH", "FUM", "FBA", "G6PDH2r", "FRD7", "PGL", "PPC"], model)
        evaluator = KnockoutEvaluator(model, decoder, objective1, fba, {})
        assert evaluator.decoder == decoder
        assert evaluator.objective_function == objective1
        assert hasattr(evaluator, "__call__")

        objective2 = product_yield("EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_")
        evaluator = KnockoutEvaluator(model, decoder, MultiObjectiveFunction([objective1, objective2]), fba, {})
        assert evaluator.objective_function.objectives == [objective1, objective2]
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_evaluate_infeasible_solution(self, model):
        representation = ["ENO", "ATPS4r", "PYK", "GLUDy", "PPS", "CO2t", "PDH",
                          "FUM", "FBA", "G6PDH2r", "FRD7", "PGL", "PPC"]

        decoder = ReactionSetDecoder(representation, model)
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2",
            "EX_ac_lp_e_rp_",
            "EX_glc_lp_e_rp_")
        evaluator = KnockoutEvaluator(model, decoder, objective1, fba, {})
        fitness = evaluator([[0]])[0]
        assert fitness == 0
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_invalid_initializers(self, model):
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2",
            "EX_ac_lp_e_rp_",
            "EX_glc_lp_e_rp_")
        decoder = ReactionSetDecoder(["PGI", "PDH", "FUM", "FBA", "G6PDH2r", "FRD7", "PGL", "PPC"], model)
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, decoder, 1, fba, {})
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, decoder, None, fba, {})
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, decoder, [], fba, {})
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, decoder, [2, 3], fba, {})
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, decoder, [objective1], fba, {})
        with pytest.raises(ValueError):
            KnockoutEvaluator(model, None, [], fba, {})
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_evaluate_multi_objective(self, model):
        representation = ["ATPS4r", "PYK", "GLUDy", "PPS", "CO2t", "PDH",
                          "FUM", "FBA", "G6PDH2r", "FRD7", "PGL", "PPC"]
        decoder = ReactionSetDecoder(representation, model)
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2",
            "EX_ac_lp_e_rp_",
            "EX_glc_lp_e_rp_")
        objective2 = product_yield("EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_", carbon_yield=False)
        objective = MultiObjectiveFunction([objective1, objective2])
        evaluator = KnockoutEvaluator(model, decoder, objective, fba, {})
        fitness = evaluator([[0, 1, 2, 3, 4]])[0]

        assert isinstance(fitness, Pareto)
        assert abs(fitness[0] - 0.41) < 0.02
        assert abs(fitness[1] - 1.57) < 0.035
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_evaluate_single_objective(self, model):
        representation = ["ATPS4r", "PYK", "GLUDy", "PPS", "CO2t", "PDH",
                          "FUM", "FBA", "G6PDH2r", "FRD7", "PGL", "PPC"]
        decoder = ReactionSetDecoder(representation, model)
        objective1 = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2",
            "EX_ac_lp_e_rp_",
            "EX_glc_lp_e_rp_")
        evaluator = KnockoutEvaluator(model, decoder, objective1, fba, {})
        fitness = evaluator([[0, 1, 2, 3, 4]])[0]

        assert abs(fitness - 0.41) < 0.02
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def gene_ko_multi_objective(model):
    objective1 = biomass_product_coupled_yield(
        "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2", "EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_")
    objective2 = number_of_knockouts()
    objective = MultiObjectiveFunction([objective1, objective2])
    return GeneKnockoutOptimization(model=model, simulation_method=fba, objective_function=objective,
                                    heuristic_method=inspyred.ec.emo.NSGA2)
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary / objective_functions.py View on Github external
def __init__(self, biomass, product, substrate, carbon_yield=False, *args, **kwargs):
        super(biomass_product_coupled_yield, self).__init__(product, substrate,
                                                            carbon_yield=carbon_yield, *args, **kwargs)
        if isinstance(biomass, Reaction):
            biomass = biomass.id
        self.biomass = biomass
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary_based.py View on Github external
end reactions. From each of these groups only 1 reaction will be included as a possible knockout.


        Returns
        -------
        OptGeneResult
        """

        target = get_reaction_for(self._model, target)
        biomass = get_reaction_for(self._model, biomass)
        substrate = get_reaction_for(self._model, substrate)

        if growth_coupled:
            objective_function = biomass_product_coupled_min_yield(biomass, target, substrate)
        else:
            objective_function = biomass_product_coupled_yield(biomass, target, substrate)
        if self.manipulation_type == "genes":
            optimization_algorithm = GeneKnockoutOptimization(
                model=self._model,
                heuristic_method=self._algorithm,
                essential_genes=self._essential_genes,
                plot=self.plot,
                objective_function=objective_function,
                use_nullspace_simplification=use_nullspace_simplification)
        elif self.manipulation_type == "reactions":
            optimization_algorithm = ReactionKnockoutOptimization(
                model=self._model,
                heuristic_method=self._algorithm,
                essential_reactions=self._essential_reactions,
                plot=self.plot,
                objective_function=objective_function,
                use_nullspace_simplification=use_nullspace_simplification)