How to use the cameo.core.utils.get_reaction_for 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_solver_based_model.py View on Github external
def test_get_reaction_for(self, core_model):
        with core_model:
            for r in core_model.reactions:
                assert isinstance(get_reaction_for(core_model, r.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, r), cobra.Reaction)
            for m in core_model.metabolites:
                assert isinstance(get_reaction_for(core_model, m.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, m), cobra.Reaction)

        with pytest.raises(TypeError):
            get_reaction_for(core_model, None)
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "blablabla")
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "accoa_lp_c_lp_", add=False)
github biosustain / cameo / tests / test_solver_based_model.py View on Github external
def test_get_reaction_for(self, core_model):
        with core_model:
            for r in core_model.reactions:
                assert isinstance(get_reaction_for(core_model, r.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, r), cobra.Reaction)
            for m in core_model.metabolites:
                assert isinstance(get_reaction_for(core_model, m.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, m), cobra.Reaction)

        with pytest.raises(TypeError):
            get_reaction_for(core_model, None)
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "blablabla")
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "accoa_lp_c_lp_", add=False)
github biosustain / cameo / tests / test_solver_based_model.py View on Github external
def test_get_reaction_for(self, core_model):
        with core_model:
            for r in core_model.reactions:
                assert isinstance(get_reaction_for(core_model, r.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, r), cobra.Reaction)
            for m in core_model.metabolites:
                assert isinstance(get_reaction_for(core_model, m.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, m), cobra.Reaction)

        with pytest.raises(TypeError):
            get_reaction_for(core_model, None)
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "blablabla")
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "accoa_lp_c_lp_", add=False)
github biosustain / cameo / tests / test_solver_based_model.py View on Github external
def test_get_reaction_for(self, core_model):
        with core_model:
            for r in core_model.reactions:
                assert isinstance(get_reaction_for(core_model, r.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, r), cobra.Reaction)
            for m in core_model.metabolites:
                assert isinstance(get_reaction_for(core_model, m.id), cobra.Reaction)
                assert isinstance(get_reaction_for(core_model, m), cobra.Reaction)

        with pytest.raises(TypeError):
            get_reaction_for(core_model, None)
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "blablabla")
        with pytest.raises(KeyError):
            get_reaction_for(core_model, "accoa_lp_c_lp_", add=False)
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary_based.py View on Github external
kwargs : dict
            Arguments for the simulation method.
        seed : int
            A seed for random.
        use_nullspace_simplification : Boolean (default True)
            Use a basis for the nullspace to find groups of reactions whose fluxes are multiples of each other and dead
            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(
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary_based.py View on Github external
time_machine : TimeMachine
            See TimeMachine.
        max_results : int
            Max number of different designs to return if found.
        kwargs : dict
            Arguments for the simulation method.
        seed : int
            A seed for random.


        Returns
        -------
        HeuristicOptSwapResult
        """

        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)

        optimization_algorithm = CofactorSwapOptimization(model=self._model,
                                                          cofactor_id_swaps=self._cofactor_id_swaps,
                                                          skip_reactions=self._skip_reactions,
                                                          objective_function=objective_function)

        optimization_algorithm.simulation_kwargs = kwargs
        optimization_algorithm.simulation_method = simulation_method
        optimization_algorithm.archiver = ProductionStrainArchive()
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary_based.py View on Github external
Max number of different designs to return if found.
        kwargs : dict
            Arguments for the simulation method.
        seed : int
            A seed for random.
        use_nullspace_simplification : Boolean (default True)
            Use a basis for the nullspace to find groups of reactions whose fluxes are multiples of each other and dead
            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":
github biosustain / cameo / cameo / strain_design / heuristic / evolutionary_based.py View on Github external
See TimeMachine.
        max_results : int
            Max number of different designs to return if found.
        kwargs : dict
            Arguments for the simulation method.
        seed : int
            A seed for random.


        Returns
        -------
        HeuristicOptSwapResult
        """

        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)

        optimization_algorithm = CofactorSwapOptimization(model=self._model,
                                                          cofactor_id_swaps=self._cofactor_id_swaps,
                                                          skip_reactions=self._skip_reactions,
                                                          objective_function=objective_function)

        optimization_algorithm.simulation_kwargs = kwargs
        optimization_algorithm.simulation_method = simulation_method
        optimization_algorithm.archiver = ProductionStrainArchive()
github biosustain / cameo / cameo / strain_design / deterministic / linear_programming.py View on Github external
The design target
        biomass: str, Metabolite or Reaction
            The biomass definition in the model
        max_knockouts: int
            Max number of knockouts allowed
        max_results: int
            Max number of different designs to return if found

        Returns
        -------
        OptKnockResult
        """
        # TODO: why not required arguments?
        if biomass is None or target is None:
            raise ValueError('missing biomass and/or target reaction')
        target = get_reaction_for(self._model, target, add=False)
        biomass = get_reaction_for(self._model, biomass, add=False)

        knockout_list = []
        fluxes_list = []
        production_list = []
        biomass_list = []
        loader_id = ui.loading()
        with self._model:
            self._model.objective = target.id
            self._number_of_knockouts_constraint.lb = self._number_of_knockouts_constraint.ub - max_knockouts
            count = 0
            while count < max_results:
                try:
                    solution = self._model.optimize(raise_error=True)
                except OptimizationError as e:
                    logger.debug("Problem could not be solved. Terminating and returning " + str(count) + " solutions")
github biosustain / cameo / cameo / strain_design / deterministic / flux_variability_based.py View on Github external
The number of enforced flux levels (defaults to 10).
        exclude : Iterable of reactions or reaction ids that will not be included in the output.

        Returns
        -------
        FseofResult
            An object containing the identified reactions and the used parameters.

        References
        ----------
        .. [1] H. S. Choi, S. Y. Lee, T. Y. Kim, and H. M. Woo, 'In silico identification of gene amplification targets
        for improvement of lycopene production.,' Appl Environ Microbiol, vol. 76, no. 10, pp. 3097–3105, May 2010.

        """
        model = self.model
        target = get_reaction_for(model, target)

        simulation_kwargs = simulation_kwargs if simulation_kwargs is not None else {}
        simulation_kwargs['objective'] = self.primary_objective

        if 'reference' not in simulation_kwargs:
            reference = simulation_kwargs['reference'] = pfba(model, **simulation_kwargs)
        else:
            reference = simulation_kwargs['reference']

        ndecimals = config.ndecimals

        # Exclude list
        exclude = list(exclude) + model.boundary
        exclude_ids = [target.id]
        for reaction in exclude:
            if isinstance(reaction, Reaction):