cobra.manipulation
==================

.. py:module:: cobra.manipulation


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/cobra/manipulation/annotate/index
   /autoapi/cobra/manipulation/delete/index
   /autoapi/cobra/manipulation/modify/index
   /autoapi/cobra/manipulation/validate/index


Functions
---------

.. autoapisummary::

   cobra.manipulation.add_SBO
   cobra.manipulation.delete_model_genes
   cobra.manipulation.knock_out_model_genes
   cobra.manipulation.prune_unused_metabolites
   cobra.manipulation.prune_unused_reactions
   cobra.manipulation.remove_genes
   cobra.manipulation.escape_ID
   cobra.manipulation.rename_genes
   cobra.manipulation.check_mass_balance
   cobra.manipulation.check_metabolite_compartment_formula


Package Contents
----------------

.. py:function:: add_SBO(model: cobra.Model) -> None

   Add SBO terms for demands and exchanges.

   This works for models which follow the standard convention for
   constructing and naming these reactions.

   The reaction should only contain the single metabolite being exchanged,
   and the id should be EX_<met_id> or DM_<met_id> .

   :param model: The model whose demand and exchange reactions need to be annotated.
   :type model: cobra.Model


.. py:function:: delete_model_genes(model: cobra.Model, gene_list: Union[List[cobra.Gene], Set[cobra.Gene], List[str], Set[str]], cumulative_deletions: bool = True, disable_orphans: bool = False) -> None

   Temporarily remove the effect of genes in `gene_list`.

   It sets the bounds to "zero" for reactions catalysed by the genes in
   `gene_list` if deleting the genes stops the reactions from proceeding.

   :param model: The model whose reaction bounds are to be set.
   :type model: cobra.Model
   :param gene_list: The list of genes to knock-out.
   :type gene_list: list of cobra.Gene
   :param cumulative_deletions: If True, then any previous deletions will be maintained in the
                                model (default True). Unused, ignored.
   :type cumulative_deletions: bool, optional
   :param disable_orphans: If True, then orphan reactions will be disabled. Currently, this
                           is not implemented (default False). Unused, ignored.
   :type disable_orphans: bool, optional
   :param .. deprecated :: 0.25: Use cobra.manipulation.knock_out_model_genes to simulate knockouts
                                 and cobra.manipulation.remove_genes to remove genes from
                                 the model.

   .. seealso:: :py:obj:`knock_out_model_genes`, :py:obj:`remove_model_genes`


.. py:function:: knock_out_model_genes(model: cobra.Model, gene_list: Iterable[Union[cobra.Gene, int, str]]) -> List[cobra.Reaction]

   Disable the genes in `gene_list`.

   It sets the bounds to "zero" for reactions catalysed by the genes in
   `gene_list` if deleting the genes would stop the reactions from proceeding.

   The changes are reverted upon exit if executed within the model as context.

   :param model: The model whose reaction bounds are to be set.
   :type model: cobra.Model
   :param gene_list: The list of genes to knock-out.
   :type gene_list: list of cobra.Gene

   :returns: A list of cobra.Reactions that had the bounds turned to zero.
   :rtype: list[cobra.Reaction]


.. py:function:: prune_unused_metabolites(model: cobra.Model) -> Tuple[cobra.Model, List[cobra.Metabolite]]

   Remove metabolites not involved in any reactions.

   :param model: The model to remove unused metabolites from.
   :type model: cobra.Model

   :returns: * *cobra.Model* -- Input model with unused metabolites removed.
             * *list of cobra.Metabolite* -- List of metabolites that were removed.


.. py:function:: prune_unused_reactions(model: cobra.Model) -> Tuple[cobra.Model, List[cobra.Reaction]]

   Remove reactions with no assigned metabolites, returns pruned model.

   :param model: The model to remove unused reactions from.
   :type model: cobra.Model

   :returns: * *cobra.Model* -- Input model with unused reactions removed.
             * *list of cobra.Reaction* -- List of reactions that were removed.


.. py:function:: remove_genes(model: cobra.Model, gene_list: Union[List[cobra.Gene], Set[cobra.Gene], List[str], Union[str]], remove_reactions: bool = True) -> None

   Remove genes entirely from the model.

   This will also simplify all gene-reaction rules with the genes
   inactivated.

   :param model: The model to remove genes from.
   :type model: cobra.Model
   :param gene_list: The list of gene objects to remove.
   :type gene_list: list of cobra.Gene or gene ids
   :param remove_reactions: Whether to remove reactions associated with genes in `gene_list`
                            (default True).
   :type remove_reactions: bool, optional


.. py:function:: escape_ID(model: cobra.Model) -> None

   Make all model component object IDs SBML compliant.

   :param model: The model to operate on.
   :type model: cobra.Model


.. py:function:: rename_genes(model: cobra.Model, rename_dict: Dict[str, str]) -> None

   Rename genes in a model from the `rename_dict`.

   :param model: The model to operate on.
   :type model: cobra.Model
   :param rename_dict: The dictionary having keys as old gene names
                       and value as new gene names.
   :type rename_dict: dict of {str: str}


.. py:function:: check_mass_balance(model: cobra.Model) -> Dict[cobra.Reaction, Dict[cobra.Metabolite, float]]

   Check mass balance for reactions of `model` and return unbalanced ones.

   :param model: The model to perform check on.
   :type model: cobra.Model

   :returns: **dict of {cobra.Reaction** -- Returns an empty dict if all components are balanced.
   :rtype: dict of {cobra.Metabolite: float}}


.. py:function:: check_metabolite_compartment_formula(model: cobra.Model) -> List[str]

   Check metabolite formulae of `model`.

   :param model: The model to perform check on.
   :type model: cobra.Model

   :returns: Returns an empty list if no errors are found.
   :rtype: list of str


