Skip to content

Commit

Permalink
fix: allow multiple exchanges in summary (#718)
Browse files Browse the repository at this point in the history
* fix: allow multiple exchanges in summary

* Correct a problem with multiple exchanges for one metabolite.
* Enhance printing by giving an option to display names.
* Allow passing in of an FVA solution.
* Many internal changes related to data frame handling.
  • Loading branch information
Midnighter authored Jun 4, 2018
1 parent b1d0029 commit 47414ed
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 165 deletions.
28 changes: 15 additions & 13 deletions cobra/core/metabolite.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,40 @@ def remove_from_model(self, destructive=False):
"""
self._model.remove_metabolites(self, destructive)

def summary(self, solution=None, threshold=0.01, fva=False,
def summary(self, solution=None, threshold=0.01, fva=None, names=False,
floatfmt='.3g'):
"""Print a summary of the reactions which produce and consume this
metabolite.
"""
Print a summary of the production and consumption fluxes.
This method requires the model for which this metabolite is a part
to be solved.
Parameters
----------
solution : cobra.core.Solution
solution : cobra.Solution, optional
A previously solved model solution to use for generating the
summary. If none provided (default), the summary method will
resolve the model. Note that the solution object must match the
model, i.e., changes to the model such as changed bounds,
added or removed reactions are not taken into account by this
method.
threshold : float
a value below which to ignore reaction fluxes
fva : float (0->1), or None
threshold : float, optional
Threshold below which fluxes are not reported.
fva : pandas.DataFrame, float or None, optional
Whether or not to include flux variability analysis in the output.
If given, fva should be a float between 0 and 1, representing the
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.
names : bool, optional
Emit reaction and metabolite names rather than identifiers (default
False).
floatfmt : string, optional
Format string for floats (default '.3g').
floatfmt : string
format method for floats, passed to tabulate. Default is '.3g'.
"""
from cobra.flux_analysis.summary import metabolite_summary
return metabolite_summary(self, solution=solution, threshold=threshold,
fva=fva, floatfmt=floatfmt)
fva=fva, names=names, floatfmt=floatfmt)

def _repr_html_(self):
return """
Expand Down
33 changes: 18 additions & 15 deletions cobra/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,34 +934,37 @@ def objective_direction(self, value):
else:
raise ValueError("Unknown objective direction '{}'.".format(value))

def summary(self, solution=None, threshold=1E-8, fva=None, floatfmt='.3g'):
"""Print a summary of the input and output fluxes of the model. This
method requires the model to have been previously solved.
def summary(self, solution=None, threshold=1E-06, fva=None, names=False,
floatfmt='.3g'):
"""
Print a summary of the input and output fluxes of the model.
Parameters
----------
solution: cobra.core.Solution
solution: cobra.Solution, optional
A previously solved model solution to use for generating the
summary. If none provided (default), the summary method will
resolve the model. Note that the solution object must match the
model, i.e., changes to the model such as changed bounds,
added or removed reactions are not taken into account by this
method.
threshold : float
tolerance for determining if a flux is zero (not printed)
fva : int or None
Whether or not to calculate and report flux variability in the
output summary
floatfmt : string
format method for floats, passed to tabulate. Default is '.3g'.
threshold : float, optional
Threshold below which fluxes are not reported.
fva : pandas.DataFrame, float or None, 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.
names : bool, optional
Emit reaction and metabolite names rather than identifiers (default
False).
floatfmt : string, optional
Format string for floats (default '.3g').
"""
from cobra.flux_analysis.summary import model_summary
return model_summary(self, solution=solution, threshold=threshold,
fva=fva, floatfmt=floatfmt)
fva=fva, names=names, floatfmt=floatfmt)

def __enter__(self):
"""Record all future changes to the model, undoing them when a call to
Expand Down
Loading

0 comments on commit 47414ed

Please sign in to comment.