cobra.flux_analysis.deletion
============================

.. py:module:: cobra.flux_analysis.deletion

.. autoapi-nested-parse::

   Provide functions for reaction and gene deletions.



Attributes
----------

.. autoapisummary::

   cobra.flux_analysis.deletion.configuration


Classes
-------

.. autoapisummary::

   cobra.flux_analysis.deletion.KnockoutAccessor


Functions
---------

.. autoapisummary::

   cobra.flux_analysis.deletion._get_growth
   cobra.flux_analysis.deletion._reaction_deletion
   cobra.flux_analysis.deletion._reaction_deletion_worker
   cobra.flux_analysis.deletion._gene_deletion
   cobra.flux_analysis.deletion._gene_deletion_worker
   cobra.flux_analysis.deletion._init_worker
   cobra.flux_analysis.deletion._multi_deletion
   cobra.flux_analysis.deletion._entities_ids
   cobra.flux_analysis.deletion._element_lists
   cobra.flux_analysis.deletion.single_reaction_deletion
   cobra.flux_analysis.deletion.single_gene_deletion
   cobra.flux_analysis.deletion.double_reaction_deletion
   cobra.flux_analysis.deletion.double_gene_deletion


Module Contents
---------------

.. py:data:: configuration

.. py:function:: _get_growth(model: cobra.core.Model) -> Tuple[float, str]

   Return the growth from the `model`.

   :param model: The model to obtain growth for.
   :type model: cobra.Model

   :returns: The obtained growth value. Returns nan if there is some error while
             optimizing.
   :rtype: float


.. py:function:: _reaction_deletion(model: cobra.core.Model, reaction_ids: List[str]) -> Tuple[List[str], float, str]

   Perform reaction deletion.

   :param model: The model to perform reaction deletion on.
   :type model: cobra.Model
   :param ids: The reaction IDs to knock-out.
   :type ids: list of str

   :returns: A tuple containing reaction IDs knocked out, growth of the model and
             the solver status.
   :rtype: tuple of (list of str, float, str)


.. py:function:: _reaction_deletion_worker(ids: List[str]) -> Tuple[List[str], float, str]

   Perform reaction deletions on worker process.

   :param ids: The reaction IDs to knock-out.
   :type ids: list of str

   :returns: A tuple containing reaction IDs knocked out, growth of the model and
             the solver status.
   :rtype: tuple of (list of str, float, str)


.. py:function:: _gene_deletion(model: cobra.core.Model, gene_ids: List[str]) -> Tuple[List[str], float, str]

   Perform gene deletions.

   :param model: The model to perform gene deletion on.
   :type model: cobra.Model
   :param ids: The gene IDs to knock-out.
   :type ids: list of str

   :returns: A tuple containing gene IDs knocked out, growth of the model and
             the solver status.
   :rtype: tuple of (list of str, float, str)


.. py:function:: _gene_deletion_worker(ids: List[str]) -> Tuple[List[str], float, str]

   Perform gene deletions on worker process.

   :param ids: The gene IDs to knock-out.
   :type ids: list of str

   :returns: A tuple containing gene IDs knocked out, growth of the model and
             the solver status.
   :rtype: tuple of (list of str, float, str)


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

   Initialize worker process.


.. py:function:: _multi_deletion(model: cobra.core.Model, entity: str, element_lists: List[Union[cobra.core.Gene, cobra.core.Reaction]], method: str = 'fba', solution: Optional[cobra.Solution] = None, processes: Optional[int] = None, **kwargs) -> pandas.DataFrame

   Provide a common interface for single or multiple knockouts.

   :param model: The metabolic model to perform deletions in.
   :type model: cobra.Model
   :param entity: The entity to knockout.
   :type entity: {"gene", "reaction"}
   :param element_lists: List of cobra.Gene or cobra.Reaction to be deleted.
   :type element_lists: list of cobra.Gene or cobra.Reaction
   :param method: Method used to predict the growth rate (default "fba").
   :type method: {"fba", "moma", "linear moma", "room", "linear room"}, optional
   :param solution: A previous solution to use as a reference for (linear) MOMA or ROOM
                    (default None).
   :type solution: cobra.Solution, optional
   :param processes: The number of parallel processes to run. Can speed up the computations
                     if the number of knockouts to perform is large. If not passed,
                     will be set to `configuration.processes` (default None).
   :type processes: int, optional
   :param \*\*kwargs: Passed on to underlying simulation functions.

   :returns: A representation of all combinations of entity deletions. The
             columns are 'growth' and 'status', where

             index : tuple(str)
                 The gene or reaction identifiers that were knocked out.
             growth : float
                 The growth rate of the adjusted model.
             status : str
                 The solution's status.
   :rtype: pandas.DataFrame


.. py:function:: _entities_ids(entities: List[Union[str, cobra.core.Gene, cobra.core.Reaction]]) -> List[str]

   Return the IDs of the `entities`.

   :param entities: The list of entities whose IDs need to be returned.
   :type entities: list of str or cobra.Gene or cobra.Reaction

   :returns: The IDs of the `entities`.
   :rtype: list of str


.. py:function:: _element_lists(entities: List[Union[str, cobra.core.Gene, cobra.core.Reaction]], *ids: List[str]) -> List[str]

   Return the elements.

   :param entities: The list of entities.
   :type entities: list of str or cobra.Gene or cobra.Reaction
   :param \*ids: The list of IDs.
   :type \*ids: list of str

   :returns: The list of IDs.
   :rtype: list of str


.. py:function:: single_reaction_deletion(model: cobra.core.Model, reaction_list: Optional[List[Union[cobra.core.Reaction, str]]] = None, method: str = 'fba', solution: Optional[cobra.Solution] = None, processes: Optional[int] = None, **kwargs) -> pandas.DataFrame

   Knock out each reaction from `reaction_list`.

   :param model: The metabolic model to perform deletions in.
   :type model: cobra.Model
   :param reaction_list: The reactions be knocked out. If not passed, all the reactions from
                         the model are used (default None).
   :type reaction_list: list of cobra.Reaction or str, optional
   :param method: Method used to predict the growth rate (default "fba").
   :type method: {"fba", "moma", "linear moma", "room", "linear room"}, optional
   :param solution: A previous solution to use as a reference for (linear) MOMA or ROOM
                    (default None).
   :type solution: cobra.Solution, optional
   :param processes: The number of parallel processes to run. Can speed up the computations
                     if the number of knockouts to perform is large. If not passed,
                     will be set to `configuration.processes` (default None).
   :type processes: int, optional
   :param \*\*kwargs: Keyword arguments are passed on to underlying simulation functions
                      such as `add_room`.

   :returns: A representation of all single reaction deletions. The columns are
             'growth' and 'status', where

             index : tuple(str)
                 The reaction identifier that was knocked out.
             growth : float
                 The growth rate of the adjusted model.
             status : str
                 The solution's status.
   :rtype: pandas.DataFrame


.. py:function:: single_gene_deletion(model: cobra.core.Model, gene_list: Optional[List[Union[cobra.core.Gene, str]]] = None, method: str = 'fba', solution: Optional[cobra.Solution] = None, processes: Optional[int] = None, **kwargs) -> pandas.DataFrame

   Knock out each gene from `gene_list`.

   :param model: The metabolic model to perform deletions in.
   :type model: cobra.Model
   :param gene_list: The gene objects to be deleted. If not passed, all the genes from the
                     model are used (default None).
   :type gene_list: list of cobra.Gene or str, optional
   :param method: Method used to predict the growth rate (default "fba").
   :type method: {"fba", "moma", "linear moma", "room", "linear room"}, optional
   :param solution: A previous solution to use as a reference for (linear) MOMA or ROOM
                    (default None).
   :type solution: cobra.Solution, optional
   :param processes: The number of parallel processes to run. Can speed up the computations
                     if the number of knockouts to perform is large. If not passed,
                     will be set to `configuration.processes` (default None).
   :type processes: int, optional
   :param \*\*kwargs: Keyword arguments are passed on to underlying simulation functions
                      such as `add_room`.

   :returns: A representation of all single gene deletions. The columns are
             'growth' and 'status', where

             index : tuple(str)
                 The gene identifier that was knocked out.
             growth : float
                 The growth rate of the adjusted model.
             status : str
                 The solution's status.
   :rtype: pandas.DataFrame


.. py:function:: double_reaction_deletion(model: cobra.core.Model, reaction_list1: Optional[List[Union[cobra.core.Reaction, str]]] = None, reaction_list2: Optional[List[Union[cobra.core.Reaction, str]]] = None, method: str = 'fba', solution: Optional[cobra.Solution] = None, processes: Optional[int] = None, **kwargs) -> pandas.DataFrame

   Knock out each reaction pair from the combinations of two given lists.

   We say 'pair' here but the order order does not matter.

   :param model: The metabolic model to perform deletions in.
   :type model: cobra.Model
   :param reaction_list1: The first reaction list to be deleted. If not passed,
                          all the reactions from the model are used (default None).
   :type reaction_list1: list of cobra.Reaction or str, optional
   :param reaction_list2: The second reaction list to be deleted. If not passed,
                          all the reactions from the model are used (default None).
   :type reaction_list2: list of cobra.Reaction or str, optional
   :param method: Method used to predict the growth rate (default "fba").
   :type method: {"fba", "moma", "linear moma", "room", "linear room"}, optional
   :param solution: A previous solution to use as a reference for (linear) MOMA or ROOM
                    (default None).
   :type solution: cobra.Solution, optional
   :param processes: The number of parallel processes to run. Can speed up the computations
                     if the number of knockouts to perform is large. If not passed,
                     will be set to `configuration.processes` (default None).
   :type processes: int, optional
   :param \*\*kwargs: Keyword arguments are passed on to underlying simulation functions
                      such as `add_room`.

   :returns: A representation of all combinations of reaction deletions. The
             columns are 'growth' and 'status', where

             index : tuple(str)
                 The reaction identifiers that were knocked out.
             growth : float
                 The growth rate of the adjusted model.
             status : str
                 The solution's status.
   :rtype: pandas.DataFrame


.. py:function:: double_gene_deletion(model: cobra.core.Model, gene_list1: Optional[List[Union[cobra.core.Gene, str]]] = None, gene_list2: Optional[List[Union[cobra.core.Gene, str]]] = None, method: str = 'fba', solution: Optional[cobra.Solution] = None, processes: Optional[int] = None, **kwargs) -> pandas.DataFrame

   Knock out each gene pair from the combination of two given lists.

   We say 'pair' here but the order order does not matter.

   :param model: The metabolic model to perform deletions in.
   :type model: cobra.Model
   :param gene_list1: The first gene list to be deleted. If not passed,
                      all the genes from the model are used (default None).
   :type gene_list1: list of cobra.Gene or str, optional
   :param gene_list2: The second gene list to be deleted. If not passed,
                      all the genes from the model are used (default None).
   :type gene_list2: list of cobra.Gene or str, optional
   :param method: Method used to predict the growth rate (default None).
   :type method: {"fba", "moma", "linear moma", "room", "linear room"}, optional
   :param solution: A previous solution to use as a reference for (linear) MOMA or ROOM
                    (default None).
   :type solution: cobra.Solution, optional
   :param processes: The number of parallel processes to run. Can speed up the computations
                     if the number of knockouts to perform is large. If not passed,
                     will be set to `configuration.processes` (default None).
   :type processes: int, optional
   :param \*\*kwargs: Keyword arguments are passed on to underlying simulation functions
                      such as `add_room`.

   :returns: A representation of all combinations of gene deletions. The
             columns are 'growth' and 'status', where

             index : tuple(str)
                 The gene identifiers that were knocked out.
             growth : float
                 The growth rate of the adjusted model.
             status : str
                 The solution's status.
   :rtype: pandas.DataFrame


.. py:class:: KnockoutAccessor(pandas_obj: Union[pandas.DataFrame, pandas.Series])

   Access unique combinations of reactions in deletion results.

   This allows acces in the form of `results.knockout[rxn1]` or
   `results.knockout["rxn1_id"]`. Each individual entry will return a
   deletion so `results.knockout[rxn1, rxn2]` will return two deletions
   (for individual knockouts of rxn1 and rxn2 respectively).
   Multi-deletions can be accessed by passing in sets like
   `results.knockout[{rxn1, rxn2}]` which denotes the double deletion of
   both reactions. Thus, the following are allowed index elements:

   - single reactions or genes (depending on whether it is a gene or
     reaction deletion)
   - single reaction IDs or gene IDs
   - lists of single single reaction IDs or gene IDs (will return one row
     for each
     element in the list)
   - sets of reactions or genes (for multi-deletions)
   - sets of reactions IDs or gene IDs
   - list of sets of objects or IDs (to get several multi-deletions)

   Parameters:
   -----------
   pandas_obj : pandas.DataFrame or pandas.Series
       A result from one of the deletion methods.



   .. py:attribute:: _result


   .. py:method:: _validate(obj: pandas.DataFrame) -> None
      :staticmethod:


      Validate the object given.

      :param obj: The object to validate.
      :type obj: pandas.DataFrame

      :raises AttributeError: If the object supplied is not a DataFrame.



   .. py:method:: __getitem__(args: Union[cobra.core.Gene, List[cobra.core.Gene], Set[cobra.core.Gene], List[Set[cobra.core.Gene]], cobra.core.Reaction, List[cobra.core.Reaction], Set[cobra.core.Reaction], List[Set[cobra.core.Reaction]], str, List[str], Set[str], List[Set[str]]]) -> pandas.DataFrame

      Return the deletion result for a particular set of knocked entities.

      :param args: The deletions to be returned. Accepts:
                   - single reactions or genes
                   - single reaction IDs or gene IDs
                   - lists of single single reaction IDs or gene IDs
                   - sets of reactions or genes
                   - sets of reactions IDs or gene IDs
                   - list of sets of objects or IDs
                   See the docs for usage examples.
      :type args: cobra.Reaction, cobra.Gene, str, set, or list

      :returns: The deletion result where the chosen entities have been deleted.
                Each row denotes a deletion.
      :rtype: pandas.DataFrame

      :raises ValueError: If any other object is used as index for lookup.



