cobra.flux_analysis.variability
===============================

.. py:module:: cobra.flux_analysis.variability

.. autoapi-nested-parse::

   Provide variability based methods such as flux variability or gene essentiality.



Attributes
----------

.. autoapisummary::

   cobra.flux_analysis.variability.logger
   cobra.flux_analysis.variability.configuration


Functions
---------

.. autoapisummary::

   cobra.flux_analysis.variability._init_worker
   cobra.flux_analysis.variability._fva_step
   cobra.flux_analysis.variability.flux_variability_analysis
   cobra.flux_analysis.variability.find_blocked_reactions
   cobra.flux_analysis.variability.find_essential_genes
   cobra.flux_analysis.variability.find_essential_reactions


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

.. py:data:: logger

.. py:data:: configuration

.. py:function:: _init_worker(model: cobra.Model, loopless: bool, sense: str) -> None

   Initialize a global model object for multiprocessing.

   :param model: The model to operate on.
   :type model: cobra.Model
   :param loopless: Whether to use loopless version.
   :type loopless: bool
   :param sense: Whether to maximise or minimise objective.
   :type sense: {"max", "min"}


.. py:function:: _fva_step(reaction_id: str) -> Tuple[str, float]

   Take a step for calculating FVA.

   :param reaction_id: The ID of the reaction.
   :type reaction_id: str

   :returns: The reaction ID with the flux value.
   :rtype: tuple of (str, float)


.. py:function:: flux_variability_analysis(model: cobra.Model, reaction_list: Optional[List[Union[cobra.Reaction, str]]] = None, loopless: Union[Optional[str], bool] = None, fraction_of_optimum: float = 1.0, pfba_factor: Optional[float] = None, processes: Optional[int] = None) -> pandas.DataFrame

   Determine the minimum and maximum flux value for each reaction.

   :param model: The model for which to run the analysis. It will *not* be modified.
   :type model: cobra.Model
   :param reaction_list: The reactions for which to obtain min/max fluxes. If None will use
                         all reactions in the model (default None).
   :type reaction_list: list of cobra.Reaction or str, optional
   :param loopless: If this value is set, only loopless solutions will be returned.
                    Boolean values are deprecated. Provided value means the algorithm
                    to constrain the model to loopless solutions.
                    Please also refer to the notes (default None).
   :type loopless: str, "fastSNP" or "cycleFreeFlux", optional
   :param fraction_of_optimum: Must be <= 1.0. Requires that the objective value is at least the
                               fraction times maximum objective value. A value of 0.85 for instance
                               means that the objective has to be at least at 85% percent of its
                               maximum (default 1.0).
   :type fraction_of_optimum: float, optional
   :param pfba_factor: Add an additional constraint to the model that requires the total sum
                       of absolute fluxes must not be larger than this value times the
                       smallest possible sum of absolute fluxes, i.e., by setting the value
                       to 1.1 the total sum of absolute fluxes must not be more than
                       10% larger than the pFBA solution. Since the pFBA solution is the
                       one that optimally minimizes the total flux sum, the `pfba_factor`
                       should, if set, be larger than one. Setting this value may lead to
                       more realistic predictions of the effective flux bounds
                       (default None).
   :type pfba_factor: float, optional
   :param processes: The number of parallel processes to run. If not explicitly passed,
                     will be set from the global configuration singleton (default None).
   :type processes: int, optional

   :returns: A data frame with reaction identifiers as the index and two columns:
             - maximum: indicating the highest possible flux
             - minimum: indicating the lowest possible flux
   :rtype: pandas.DataFrame

   .. rubric:: Notes

   This implements the fast version as described in [1]_. Please note that
   the flux distribution containing all minimal/maximal fluxes does not have
   to be a feasible solution for the model. Fluxes are minimized/maximized
   individually and a single minimal flux might require all others to be
   sub-optimal.

   Using the loopless option will lead to a significant increase in
   computation time (about a factor of 100 for large models).

   If `loopless` is set to "fastSNP", the optimal loopless flux bounds will be
   found by adding the loopless constraints to the model using efficient
   Fast-SNP algorithm (see [2]_).

   If `loopless` is set to "cycleFreeFlux", the loops removal algorithm will be
   used (see [3]_). Note: this algorithm does not guarantee to find optimal bounds.

   .. rubric:: References

   .. [1] Computationally efficient flux variability analysis.
      Gudmundsson S, Thiele I.
      BMC Bioinformatics. 2010 Sep 29;11:489.
      doi: 10.1186/1471-2105-11-489, PMID: 20920235

   .. [2] Fast-SNP: a fast matrix pre-processing algorithm for efficient
      loopless flux optimization of metabolic models. Saa PA, Nielsen LK.
      Bioinformatics. 2016 Dec;32(24):3807–3814. doi: 10.1093/bioinformatics/btw555.

   .. [3] CycleFreeFlux: efficient removal of thermodynamically infeasible
      loops from flux distributions.
      Desouki AA, Jarre F, Gelius-Dietrich G, Lercher MJ.
      Bioinformatics. 2015 Jul 1;31(13):2159-65.
      doi: 10.1093/bioinformatics/btv096.


.. py:function:: find_blocked_reactions(model: cobra.Model, reaction_list: Optional[List[Union[cobra.Reaction, str]]] = None, zero_cutoff: Optional[float] = None, open_exchanges: bool = False, processes: Optional[int] = None) -> List[cobra.Reaction]

   Find reactions that cannot carry any flux.

   The question whether or not a reaction is blocked is highly dependent
   on the current exchange reaction settings for a COBRA model. Hence an
   argument is provided to open all exchange reactions.

   :param model: The model to analyze.
   :type model: cobra.Model
   :param reaction_list: List of reactions to consider, the default includes all model
                         reactions (default None).
   :type reaction_list: list of cobra.Reaction or str, optional
   :param zero_cutoff: Flux value which is considered to effectively be zero. The default
                       is set to use `model.tolerance` (default None).
   :type zero_cutoff: float, optional
   :param open_exchanges: Whether or not to open all exchange reactions to very high flux
                          ranges (default False).
   :type open_exchanges: bool, optional
   :param processes: The number of parallel processes to run. Can speed up the
                     computations if the number of reactions is large. If not explicitly
                     passed, it will be set from the global configuration singleton
                     (default None).
   :type processes: int, optional

   :returns: List with the identifiers of blocked reactions.
   :rtype: list of cobra.Reaction

   .. rubric:: Notes

   Sink and demand reactions are left untouched. Please modify them manually.


.. py:function:: find_essential_genes(model: cobra.Model, threshold: Optional[float] = None, processes: Optional[int] = None) -> Set[cobra.Gene]

   Return a set of essential genes.

   A gene is considered essential if restricting the flux of all reactions
   that depend on it to zero causes the objective, e.g., the growth rate,
   to also be zero, below the threshold, or infeasible.

   :param model: The model to find the essential genes for.
   :type model: cobra.Model
   :param threshold: Minimal objective flux to be considered viable. By default this is
                     1% of the maximal objective (default None).
   :type threshold: float, 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 explicitly
                     passed, it will be set from the global configuration singleton
                     (default None).
   :type processes: int, optional

   :returns: Set of essential genes.
   :rtype: set of cobra.Gene


.. py:function:: find_essential_reactions(model: cobra.Model, threshold: Optional[float] = None, processes: Optional[int] = None) -> Set[cobra.Reaction]

   Return a set of essential reactions.

   A reaction is considered essential if restricting its flux to zero
   causes the objective, e.g., the growth rate, to also be zero, below the
   threshold, or infeasible.


   :param model: The model to find the essential reactions for.
   :type model: cobra.Model
   :param threshold: Minimal objective flux to be considered viable. By default this is
                     1% of the maximal objective (default None).
   :type threshold: float, 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 explicitly
                     passed, it will be set from the global configuration singleton
                     (default None).
   :type processes: int, optional

   :returns: Set of essential reactions.
   :rtype: set of cobra.Reaction


