cobra.summary
=============

.. py:module:: cobra.summary


Submodules
----------

.. toctree::
   :maxdepth: 1

   /autoapi/cobra/summary/metabolite_summary/index
   /autoapi/cobra/summary/model_summary/index
   /autoapi/cobra/summary/reaction_summary/index
   /autoapi/cobra/summary/summary/index


Classes
-------

.. autoapisummary::

   cobra.summary.Summary
   cobra.summary.ReactionSummary
   cobra.summary.ModelSummary


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

.. py:class:: Summary(**kwargs)

   Bases: :py:obj:`abc.ABC`


   Define the abstract base summary.

   .. seealso:: :py:obj:`MetaboliteSummary`, :py:obj:`ReactionSummary`, :py:obj:`ModelSummary`


   .. py:attribute:: _flux
      :value: None



   .. py:attribute:: _tolerance
      :value: None



   .. py:method:: _generate(model: cobra.Model, solution: Optional[cobra.Solution], fva: Optional[Union[float, pandas.DataFrame]]) -> None

      Prepare the data for the summary instance.

      :param model: The metabolic model for which to generate a metabolite summary.
      :type model: cobra.Model
      :param solution: A previous model solution to use for generating the summary. If
                       ``None``, the summary method will generate a parsimonious flux
                       distribution.
      :type solution: cobra.Solution, optional
      :param fva: Whether or not to include flux variability analysis in the output.
                  If given, `fva` should either be a previous FVA solution matching the
                  model or a float between 0 and 1 representing the fraction of the
                  optimum objective to be searched.
      :type fva: pandas.DataFrame or float, optional



   .. py:method:: __str__() -> str

      Return a string representation of the summary.



   .. py:method:: _repr_html_() -> str

      Return a rich HTML representation of the summary.



   .. py:property:: tolerance
      :type: float


      Return the set threshold.


   .. py:method:: _normalize_threshold(threshold: Optional[float])

      Return a sensible threshold value.



   .. py:method:: to_string(names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G', column_width: int = 79) -> str
      :abstractmethod:


      Return a pretty string representation of the summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional
      :param column_width: The maximum column width for each row (default 79).
      :type column_width: int, optional

      :returns: The summary formatted as a pretty string.
      :rtype: str



   .. py:method:: to_html(names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G') -> str
      :abstractmethod:


      Return a rich HTML representation of the metabolite summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional

      :returns: The summary formatted as HTML.
      :rtype: str



   .. py:method:: to_frame() -> pandas.DataFrame

      Return the a data frame representation of the summary.



.. py:class:: ReactionSummary(*, reaction: cobra.Reaction, model: cobra.Model, solution: Optional[cobra.Solution] = None, fva: Optional[Union[float, pandas.DataFrame]] = None, **kwargs)

   Bases: :py:obj:`cobra.summary.Summary`


   Define the reaction summary.

   .. seealso::

      :py:obj:`Summary`
          Parent that defines further attributes.

      :py:obj:`MetaboliteSummary`, :py:obj:`ModelSummary`


   .. py:attribute:: _reaction


   .. py:method:: _generate(model: cobra.Model, solution: Optional[cobra.Solution], fva: Optional[Union[float, pandas.DataFrame]]) -> None

      Prepare the data for the summary instance.

      :param model: The metabolic model for which to generate a metabolite summary.
      :type model: cobra.Model
      :param solution: A previous model solution to use for generating the summary. If
                       ``None``, the summary method will generate a parsimonious flux
                       distribution.
      :type solution: cobra.Solution, optional
      :param fva: Whether or not to include flux variability analysis in the output.
                  If given, `fva` should either be a previous FVA solution matching the
                  model or a float between 0 and 1 representing the fraction of the
                  optimum objective to be searched.
      :type fva: pandas.DataFrame or float, optional



   .. py:method:: _string_flux(threshold: float, float_format: str) -> str

      Transform a flux data frame to a string.

      :param threshold: Hide fluxes below the threshold from being displayed.
      :type threshold: float
      :param float_format: Format string for floats.
      :type float_format: str

      :returns: A string representation of the flux (with ranges).
      :rtype: str



   .. py:method:: to_string(names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G', column_width: int = 79) -> str

      Return a pretty string representation of the reaction summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional
      :param column_width: The maximum column width for each row (default 79).
      :type column_width: int, optional

      :returns: The summary formatted as a pretty string.
      :rtype: str



   .. py:method:: to_html(names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G') -> str

      Return a rich HTML representation of the reaction summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional

      :returns: The summary formatted as HTML.
      :rtype: str



.. py:class:: ModelSummary(*, model: cobra.core.Model, solution: Optional[cobra.core.Solution] = None, fva: Optional[Union[float, pandas.DataFrame]] = None, **kwargs)

   Bases: :py:obj:`cobra.summary.Summary`


   Define the model summary.

   .. attribute:: uptake_flux

      A pandas DataFrame of only the uptake fluxes.

      :type: pandas.DataFrame

   .. attribute:: secretion_flux

      A pandas DataFrame of only the consuming fluxes.

      :type: pandas.DataFrame

   .. seealso::

      :py:obj:`Summary`
          Parent that defines further attributes.

      :py:obj:`MetaboliteSummary`, :py:obj:`ReactionSummary`


   .. py:attribute:: _objective
      :value: None



   .. py:attribute:: _objective_value
      :value: None



   .. py:attribute:: _boundary
      :value: None



   .. py:attribute:: _boundary_metabolites
      :value: None



   .. py:attribute:: uptake_flux
      :type:  Optional[pandas.DataFrame]
      :value: None



   .. py:attribute:: secretion_flux
      :type:  Optional[pandas.DataFrame]
      :value: None



   .. py:method:: _generate(model: cobra.core.Model, solution: Optional[cobra.core.Solution], fva: Optional[Union[float, pandas.DataFrame]]) -> None

      Prepare the data for the summary instance.

      :param model: The metabolic model for which to generate a metabolite summary.
      :type model: cobra.Model
      :param solution: A previous model solution to use for generating the summary. If
                       ``None``, the summary method will generate a parsimonious flux
                       distribution.
      :type solution: cobra.Solution, optional
      :param fva: Whether or not to include flux variability analysis in the output.
                  If given, `fva` should either be a previous FVA solution matching the
                  model or a float between 0 and 1 representing the fraction of the
                  optimum objective to be searched.
      :type fva: pandas.DataFrame or float, optional



   .. py:method:: _display_flux(frame: pandas.DataFrame, names: bool, element: str, threshold: float) -> pandas.DataFrame

      Transform a flux data frame for display.

      :param frame: Either the producing or the consuming fluxes.
      :type frame: pandas.DataFrame
      :param names: Whether or not elements should be displayed by their common names.
      :type names: bool
      :param element: The atomic element to summarize fluxes for.
      :type element: str
      :param threshold: Hide fluxes below the threshold from being displayed.
      :type threshold: float

      :returns: The transformed pandas DataFrame with flux percentages and reaction
                definitions.
      :rtype: pandas.DataFrame



   .. py:method:: _string_table(frame: pandas.DataFrame, float_format: str, column_width: int) -> str
      :staticmethod:


      Create a pretty string representation of the data frame.

      :param frame: A pandas DataFrame of fluxes.
      :type frame: pandas.DataFrame
      :param float_format: Format string for floats.
      :type float_format: str
      :param column_width: The maximum column width for each row.
      :type column_width: int

      :returns: The data frame formatted as a pretty string.
      :rtype: str



   .. py:method:: _html_table(frame: pandas.DataFrame, float_format: str) -> str
      :staticmethod:


      Create an HTML representation of the data frame.

      :param frame: A pandas DataFrame of fluxes.
      :type frame: pandas.DataFrame
      :param float_format: Format string for floats.
      :type float_format: str

      :returns: The data frame formatted as HTML.
      :rtype: str



   .. py:method:: _string_objective(names: bool) -> str

      Return a string representation of the objective.

      :param names: Whether or not elements should be displayed by their common names.
      :type names: bool, optional

      :returns: The objective expression and value as a string.
      :rtype: str



   .. py:method:: to_string(names: bool = False, element: str = 'C', threshold: Optional[float] = None, float_format: str = '.4G', column_width: int = 79) -> str

      Return a pretty string representation of the model summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param element: The atomic element to summarize uptake and secretion for (default 'C').
      :type element: str, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional
      :param column_width: The maximum column width for each row (default 79).
      :type column_width: int, optional

      :returns: The summary formatted as a pretty string.
      :rtype: str



   .. py:method:: to_html(names: bool = False, element: str = 'C', threshold: Optional[float] = None, float_format: str = '.4G') -> str

      Return a rich HTML representation of the model summary.

      :param names: Whether or not elements should be displayed by their common names
                    (default False).
      :type names: bool, optional
      :param element: The atomic element to summarize uptake and secretion for (default 'C').
      :type element: str, optional
      :param threshold: Hide fluxes below the threshold from being displayed. If no value is
                        given, the model tolerance is used (default None).
      :type threshold: float, optional
      :param float_format: Format string for floats (default '.4G').
      :type float_format: str, optional

      :returns: The summary formatted as HTML.
      :rtype: str



