17.1.1.7. cobra.summary

17.1.1.7.1. Submodules

17.1.1.7.2. Package Contents

17.1.1.7.2.1. Classes

Summary

Define the abstract base summary.

MetaboliteSummary

Define the metabolite summary.

ModelSummary

Define the model summary.

class cobra.summary.Summary(**kwargs)[source]

Bases: abc.ABC

Define the abstract base summary.

See also

MetaboliteSummary, ReactionSummary, ModelSummary

_generate(self, model: Model, solution: Optional['Solution'], fva: Optional[Union[float, pd.DataFrame]]) → None

Prepare the data for the summary instance.

Parameters
  • model (cobra.Model) – The metabolic model for which to generate a metabolite summary.

  • solution (cobra.Solution, optional) – A previous model solution to use for generating the summary. If None, the summary method will generate a parsimonious flux distribution.

  • fva (pandas.DataFrame or float, optional) – 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.

__str__(self) → str

Return a string representation of the summary.

_repr_html_(self) → str

Return a rich HTML representation of the summary.

property tolerance(self) → float

Return the set threshold.

_normalize_threshold(self, threshold: Optional[float])

Return a sensible threshold value.

abstract to_string(self, names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G', column_width: int = 79) → str

Return a pretty string representation of the summary.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

  • column_width (int, optional) – The maximum column width for each row (default 79).

Returns

The summary formatted as a pretty string.

Return type

str

abstract to_html(self, names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G') → str

Return a rich HTML representation of the metabolite summary.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

Returns

The summary formatted as HTML.

Return type

str

to_frame(self) → pd.DataFrame

Return the a data frame representation of the summary.

class cobra.summary.MetaboliteSummary(*, metabolite: Metabolite, model: Model, solution: Optional['Solution'] = None, fva: Optional[Union[float, pd.DataFrame]] = None, **kwargs)[source]

Bases: cobra.summary.Summary

Define the metabolite summary.

producing_flux

A pandas DataFrame of only the producing fluxes.

Type

pandas.DataFrame

consuming_flux

A pandas DataFrame of only the consuming fluxes.

Type

pandas.DataFrame

See also

Summary

Parent that defines further attributes.

ReactionSummary, ModelSummary

_generate(self, model: Model, solution: Optional['Solution'], fva: Optional[Union[float, pd.DataFrame]]) → None

Prepare the data for the summary instance.

Parameters
  • model (cobra.Model) – The metabolic model for which to generate a metabolite summary.

  • solution (cobra.Solution, optional) – A previous model solution to use for generating the summary. If None, the summary method will generate a parsimonious flux distribution.

  • fva (pandas.DataFrame or float, optional) – 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.

_display_flux(self, frame: pd.DataFrame, names: bool, threshold: float) → pd.DataFrame

Transform a flux data frame for display.

Parameters
  • frame (pandas.DataFrame) – Either the producing or the consuming fluxes.

  • names (bool) – Whether or not elements should be displayed by their common names.

  • threshold (float) – Hide fluxes below the threshold from being displayed.

Returns

The transformed pandas DataFrame with flux percentages and reaction definitions.

Return type

pandas.DataFrame

static _string_table(frame: pd.DataFrame, float_format: str, column_width: int) → str

Create a pretty string representation of the data frame.

Parameters
  • frame (pandas.DataFrame) – A pandas DataFrame of fluxes.

  • float_format (str) – Format string for floats.

  • column_width (int) – The maximum column width for each row.

Returns

The data frame formatted as a pretty string.

Return type

str

static _html_table(frame: pd.DataFrame, float_format: str) → str

Create an HTML representation of the data frame.

Parameters
  • frame (pandas.DataFrame) – A pandas DataFrame of fluxes.

  • float_format (str) – Format string for floats.

Returns

The data frame formatted as HTML.

Return type

str

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

Return a pretty string representation of the metabolite summary.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

  • column_width (int, optional) – The maximum column width for each row (default 79).

Returns

The summary formatted as a pretty string.

Return type

str

to_html(self, names: bool = False, threshold: Optional[float] = None, float_format: str = '.4G') → str

Return a rich HTML representation of the metabolite summary.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

Returns

The summary formatted as HTML.

Return type

str

class cobra.summary.ModelSummary(*, model: Model, solution: Optional['Solution'] = None, fva: Optional[Union[float, pd.DataFrame]] = None, **kwargs)[source]

Bases: cobra.summary.Summary

Define the model summary.

uptake_flux

A pandas DataFrame of only the uptake fluxes.

Type

pandas.DataFrame

secretion_flux

A pandas DataFrame of only the consuming fluxes.

Type

pandas.DataFrame

See also

Summary

Parent that defines further attributes.

MetaboliteSummary, ReactionSummary

_generate(self, model: Model, solution: Optional['Solution'], fva: Optional[Union[float, pd.DataFrame]]) → None

Prepare the data for the summary instance.

Parameters
  • model (cobra.Model) – The metabolic model for which to generate a metabolite summary.

  • solution (cobra.Solution, optional) – A previous model solution to use for generating the summary. If None, the summary method will generate a parsimonious flux distribution.

  • fva (pandas.DataFrame or float, optional) – 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.

_display_flux(self, frame: pd.DataFrame, names: bool, element: str, threshold: float) → pd.DataFrame

Transform a flux data frame for display.

Parameters
  • frame (pandas.DataFrame) – Either the producing or the consuming fluxes.

  • names (bool) – Whether or not elements should be displayed by their common names.

  • element (str) – The atomic element to summarize fluxes for.

  • threshold (float) – Hide fluxes below the threshold from being displayed.

Returns

The transformed pandas DataFrame with flux percentages and reaction definitions.

Return type

pandas.DataFrame

static _string_table(frame: pd.DataFrame, float_format: str, column_width: int) → str

Create a pretty string representation of the data frame.

Parameters
  • frame (pandas.DataFrame) – A pandas DataFrame of fluxes.

  • float_format (str) – Format string for floats.

  • column_width (int) – The maximum column width for each row.

Returns

The data frame formatted as a pretty string.

Return type

str

static _html_table(frame: pd.DataFrame, float_format: str) → str

Create an HTML representation of the data frame.

Parameters
  • frame (pandas.DataFrame) – A pandas DataFrame of fluxes.

  • float_format (str) – Format string for floats.

Returns

The data frame formatted as HTML.

Return type

str

_string_objective(self, names: bool) → str

Return a string representation of the objective.

Parameters

names (bool, optional) – Whether or not elements should be displayed by their common names.

Returns

The objective expression and value as a string.

Return type

str

to_string(self, 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.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • element (str, optional) – The atomic element to summarize uptake and secretion for (default ‘C’).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

  • column_width (int, optional) – The maximum column width for each row (default 79).

Returns

The summary formatted as a pretty string.

Return type

str

to_html(self, names: bool = False, element: str = 'C', threshold: Optional[float] = None, float_format: str = '.4G') → str

Return a rich HTML representation of the model summary.

Parameters
  • names (bool, optional) – Whether or not elements should be displayed by their common names (default False).

  • element (str, optional) – The atomic element to summarize uptake and secretion for (default ‘C’).

  • threshold (float, optional) – Hide fluxes below the threshold from being displayed. If no value is given, the model tolerance is used (default None).

  • float_format (str, optional) – Format string for floats (default ‘.4G’).

Returns

The summary formatted as HTML.

Return type

str