17.1.3. cobra.flux_analysis
¶
Provide functions related to Flux Analysis.
Submodules¶
cobra.flux_analysis.deletion
cobra.flux_analysis.fastcc
cobra.flux_analysis.gapfilling
cobra.flux_analysis.geometric
cobra.flux_analysis.helpers
cobra.flux_analysis.loopless
cobra.flux_analysis.moma
cobra.flux_analysis.parsimonious
cobra.flux_analysis.phenotype_phase_plane
cobra.flux_analysis.reaction
cobra.flux_analysis.room
cobra.flux_analysis.variability
Package Contents¶
Functions¶

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

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

Knock out each gene from gene_list. 

Knock out each reaction from reaction_list. 

Check consistency of a metabolic network using FASTCC [1]_. 

Perform gap filling on a model. 

Perform geometric FBA to obtain a unique, centered flux distribution. 

Convert an existing solution to a loopless one. 

Modify a model so all feasible flux distributions are loopless. 

Add MOMA constraints and objective representing to the model. 

Compute a single solution based on (linear) MOMA. 

Perform basic pFBA (parsimonious Enzyme Usage Flux Balance Analysis). 

Find reactions that cannot carry any flux. 

Return a set of essential genes. 

Return a set of essential reactions. 

Determine the minimum and maximum flux value for each reaction. 

Calculate the objective value conditioned on all flux combinations. 

Add constraints and objective for ROOM. 

Compute a solution based on regulatory on/off minimization (ROOM). 
 cobra.flux_analysis.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 [source]¶
Knock out each gene pair from the combination of two given lists.
We say ‘pair’ here but the order order does not matter.
 Parameters
model (cobra.Model) – The metabolic model to perform deletions in.
gene_list1 (list of cobra.Gene or str, optional) – The first gene list to be deleted. If not passed, all the genes from the model are used (default None).
gene_list2 (list of cobra.Gene or str, optional) – The second gene list to be deleted. If not passed, all the genes from the model are used (default None).
method ({"fba", "moma", "linear moma", "room", "linear room"}, optional) – Method used to predict the growth rate (default None).
solution (cobra.Solution, optional) – A previous solution to use as a reference for (linear) MOMA or ROOM (default None).
processes (int, optional) – 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).
**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
 indextuple(str)
The gene identifiers that were knocked out.
 growthfloat
The growth rate of the adjusted model.
 statusstr
The solution’s status.
 Return type
pandas.DataFrame
 cobra.flux_analysis.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 [source]¶
Knock out each reaction pair from the combinations of two given lists.
We say ‘pair’ here but the order order does not matter.
 Parameters
model (cobra.Model) – The metabolic model to perform deletions in.
reaction_list1 (list of cobra.Reaction or str, optional) – The first reaction list to be deleted. If not passed, all the reactions from the model are used (default None).
reaction_list2 (list of cobra.Reaction or str, optional) – The second reaction list to be deleted. If not passed, all the reactions from the model are used (default None).
method ({"fba", "moma", "linear moma", "room", "linear room"}, optional) – Method used to predict the growth rate (default “fba”).
solution (cobra.Solution, optional) – A previous solution to use as a reference for (linear) MOMA or ROOM (default None).
processes (int, optional) – 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).
**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
 indextuple(str)
The reaction identifiers that were knocked out.
 growthfloat
The growth rate of the adjusted model.
 statusstr
The solution’s status.
 Return type
pandas.DataFrame
 cobra.flux_analysis.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 [source]¶
Knock out each gene from gene_list.
 Parameters
model (cobra.Model) – The metabolic model to perform deletions in.
gene_list (list of cobra.Gene or str, optional) – The gene objects to be deleted. If not passed, all the genes from the model are used (default None).
method ({"fba", "moma", "linear moma", "room", "linear room"}, optional) – Method used to predict the growth rate (default “fba”).
solution (cobra.Solution, optional) – A previous solution to use as a reference for (linear) MOMA or ROOM (default None).
processes (int, optional) – 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).
**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
 indextuple(str)
The gene identifier that was knocked out.
 growthfloat
The growth rate of the adjusted model.
 statusstr
The solution’s status.
 Return type
pandas.DataFrame
 cobra.flux_analysis.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 [source]¶
Knock out each reaction from reaction_list.
 Parameters
model (cobra.Model) – The metabolic model to perform deletions in.
reaction_list (list of cobra.Reaction or str, optional) – The reactions be knocked out. If not passed, all the reactions from the model are used (default None).
method ({"fba", "moma", "linear moma", "room", "linear room"}, optional) – Method used to predict the growth rate (default “fba”).
solution (cobra.Solution, optional) – A previous solution to use as a reference for (linear) MOMA or ROOM (default None).
processes (int, optional) – 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).
**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
 indextuple(str)
The reaction identifier that was knocked out.
 growthfloat
The growth rate of the adjusted model.
 statusstr
The solution’s status.
 Return type
pandas.DataFrame
 cobra.flux_analysis.fastcc(model: cobra.core.Model, flux_threshold: float = 1.0, zero_cutoff: Optional[float] = None) cobra.core.Model [source]¶
Check consistency of a metabolic network using FASTCC [1]_.
FASTCC (Fast Consistency Check) is an algorithm for rapid and efficient consistency check in metabolic networks. FASTCC is a pure LP implementation and is low on computation resource demand. FASTCC also circumvents the problem associated with reversible reactions for the purpose. Given a global model, it will generate a consistent global model i.e., remove blocked reactions. For more details on FASTCC, please check [1]_.
 Parameters
model (cobra.Model) – The model to operate on.
flux_threshold (float, optional) – The flux threshold to consider (default 1.0).
zero_cutoff (float, optional) – The cutoff to consider for zero flux (default model.tolerance).
 Returns
The consistent model.
 Return type
Notes
The LP used for FASTCC is like so: maximize: sum_{i in J} z_i s.t. : z_i in [0, varepsilon] forall i in J, z_i in mathbb{R}_+
v_i ge z_i forall i in J Sv = 0 v in B
References
 1
Vlassis N, Pacheco MP, Sauter T (2014) Fast Reconstruction of Compact ContextSpecific Metabolic Network Models. PLoS Comput Biol 10(1): e1003424. doi:10.1371/journal.pcbi.1003424
 cobra.flux_analysis.gapfill(model: cobra.core.Model, universal: Optional[cobra.core.Model] = None, lower_bound: float = 0.05, penalties: Optional[Dict[str, cobra.Reaction]] = None, demand_reactions: bool = True, exchange_reactions: bool = False, iterations: int = 1)[source]¶
Perform gap filling on a model.
 Parameters
model (cobra.Model) – The model to perform gap filling on.
universal (cobra.Model, optional) – A universal model with reactions that can be used to complete the model. Only gapfill considering demand and exchange reactions if left missing (default None).
lower_bound (float, optional) – The minimally accepted flux for the objective in the filled model. (default 0.05).
penalties (dict, optional) – A dictionary with keys being ‘universal’ (all reactions included in the universal model), ‘exchange’ and ‘demand’ (all additionally added exchange and demand reactions) for the three reaction types. Can also have reaction identifiers for reaction specific costs. Defaults are 1, 100 and 1 respectively (default None).
exchange_reactions (bool, optional) – Consider adding exchange (uptake) reactions for all metabolites in the model (default False).
demand_reactions (bool, optional) – Consider adding demand reactions for all metabolites (default True).
iterations (int, optional) – The number of rounds of gap filling to perform. For every iteration, the penalty for every used reaction increases linearly. This way, the algorithm is encouraged to search for alternative solutions which may include previously used reactions i.e., with enough iterations pathways including 10 steps will eventually be reported even if the shortest pathway is a single reaction (default 1).
 Returns
A list of lists with on set of reactions that completes the model per requested iteration.
 Return type
list of list of cobra.Reaction
Examples
>>> from cobra.io import load_model >>> from cobra import Model >>> from cobra.flux_analysis import gapfill >>> model = load_model("iYS1720") >>> universal = Model("universal") >>> universal.add_reactions([model.reactions.GF6PTA.copy()]) >>> model.remove_reactions([model.reactions.GF6PTA]) >>> gapfill(model, universal) [[<Reaction GF6PTA at 0x12206a280>]]
 cobra.flux_analysis.geometric_fba(model: cobra.Model, epsilon: float = 1e06, max_tries: int = 200, processes: Optional[int] = None) cobra.Solution [source]¶
Perform geometric FBA to obtain a unique, centered flux distribution.
Geometric FBA [1]_ formulates the problem as a polyhedron and then solves it by bounding the convex hull of the polyhedron. The bounding forms a box around the convex hull which reduces with every iteration and extracts a unique solution in this way.
 Parameters
model (cobra.Model) – The model to perform geometric FBA on.
epsilon (float, optional) – The convergence tolerance of the model (default 1E06).
max_tries (int, optional) – Maximum number of iterations (default 200).
processes (int, optional) – The number of parallel processes to run. If not explicitly passed, will be set from the global configuration singleton (default None).
 Returns
The solution object containing all the constraints required for geometric FBA.
 Return type
 Raises
RuntimeError – If iteration count becomes equal to max_tries.
References
 1
Smallbone, Kieran & Simeonidis, Vangelis. (2009). Flux balance analysis: A geometric perspective. Journal of theoretical biology.258. 3115. 10.1016/j.jtbi.2009.01.027.
 cobra.flux_analysis.loopless_solution(model: cobra.Model, fluxes: Optional[Dict[str, float]] = None) cobra.Solution [source]¶
Convert an existing solution to a loopless one.
Removes as many loops as possible (see Notes).
Uses the method from CycleFreeFlux [1]_ and is much faster than add_loopless and should therefore be the preferred option to get loopless flux distributions.
 Parameters
model (cobra.Model) – The model to which to add the constraints.
fluxes (dict of {str, float}, optional) – A dictionary having keys as reaction IDs and values as their flux values. If not None will use the provided flux values to obtain a close loopless solution (default None).
 Returns
A solution object containing the fluxes with the least amount of loops possible or None if the optimization failed (usually happening if the flux distribution in fluxes is infeasible).
 Return type
Notes
The returned flux solution has the following properties:
It contains the minimal number of loops possible and no loops at all if all flux bounds include zero and the objective is not in a cycle.
It has the same objective value as the original flux solution and assumes that the objective does not participate in a cycle (which is usually true since it consumes metabolites).
It has the same exact exchange fluxes as the previous solution.
All fluxes have the same sign (flow in the same direction) as the previous solution.
When providing fluxes to the method, please note that those have to come from the exact same model that you provided, meaning that no bounds or coefficients have been changed, and the optimum has remained the same.
References
 1
CycleFreeFlux: efficient removal of thermodynamically infeasible loops from flux distributions. Desouki AA, Jarre F, GeliusDietrich G, Lercher MJ. Bioinformatics. 2015 Jul 1;31(13):215965. doi: 10.1093/bioinformatics/btv096.
 cobra.flux_analysis.add_loopless(model: cobra.Model, zero_cutoff: Optional[float] = None) None [source]¶
Modify a model so all feasible flux distributions are loopless.
It adds variables and constraints to a model which will disallow flux distributions with loops. The used formulation is described in [1]_. This function will modify your model.
In most cases you probably want to use the much faster loopless_solution. May be used in cases where you want to add complex constraints and objecives (for instance quadratic objectives) to the model afterwards or use an approximation of Gibbs free energy directions in your model.
 Parameters
model (cobra.Model) – The model to which to add the constraints.
zero_cutoff (positive float, optional) – Cutoff used for null space. Coefficients with an absolute value smaller than zero_cutoff are considered to be zero. The default uses the model.tolerance (default None).
References
 1
Elimination of thermodynamically infeasible loops in steadystate metabolic models. Schellenberger J, Lewis NE, Palsson BO. Biophys J. 2011 Feb 2;100(3):54453. doi: 10.1016/j.bpj.2010.12.3707. Erratum in: Biophys J. 2011 Mar 2;100(5):1381.
 cobra.flux_analysis.add_moma(model: cobra.core.Model, solution: Optional[cobra.core.Solution] = None, linear: bool = True) None [source]¶
Add MOMA constraints and objective representing to the model.
This adds variables and constraints for the minimization of metabolic adjustment (MOMA) to the model.
 Parameters
model (cobra.Model) – The model to add MOMA constraints and objective to.
solution (cobra.Solution, optional) – A previous solution to use as a reference. If no solution is given, one will be computed using pFBA (default None).
linear (bool, optional) – Whether to use the linear MOMA formulation or not (default True).
Notes
In the original MOMA [1]_ specification, one looks for the flux distribution of the deletion (v^d) closest to the fluxes without the deletion (v). In math this means:
minimize: sum_i (v^d_i  v_i)^2 s.t. : Sv^d = 0
lb_i le v^d_i le ub_i
Here, we use a variable transformation v^t := v^d_i  v_i. Substituting and using the fact that Sv = 0 gives:
minimize: sum_i (v^t_i)^2 s.t. : Sv^d = 0
v^t = v^d_i  v_i lb_i le v^d_i le ub_i
So, basically we just recenter the flux space at the old solution and then find the flux distribution closest to the new zero (center). This is the same strategy as used in cameo.
In the case of linear MOMA [2]_, we instead minimize sum_i abs(v^t_i). The linear MOMA is typically significantly faster. Also, quadratic MOMA tends to give flux distributions in which all fluxes deviate from the reference fluxes a little bit whereas linear MOMA tends to give flux distributions where the majority of fluxes are the same reference with few fluxes deviating a lot (typical effect of L2 norm vs L1 norm).
The former objective function is saved in the optlang solver interface as
"moma_old_objective"
and this can be used to immediately extract the value of the former objective after MOMA optimization.See also
pfba
parsimonious FBA
References
 1
Segrè, Daniel, Dennis Vitkup, and George M. Church. “Analysis of Optimality in Natural and Perturbed Metabolic Networks.” Proceedings of the National Academy of Sciences 99, no. 23 (November 12, 2002): 15112. https://doi.org/10.1073/pnas.232349399.
 2
Becker, Scott A, Adam M Feist, Monica L Mo, Gregory Hannum, Bernhard Ø Palsson, and Markus J Herrgard. “Quantitative Prediction of Cellular Metabolism with ConstraintBased Models: The COBRA Toolbox.” Nature Protocols 2 (March 29, 2007): 727.
 cobra.flux_analysis.moma(model: cobra.core.Model, solution: Optional[cobra.core.Solution] = None, linear: bool = True) cobra.core.Solution [source]¶
Compute a single solution based on (linear) MOMA.
Compute a new flux distribution that is at a minimal distance to a previous reference solution solution. Minimization of metabolic adjustment (MOMA) is generally used to assess the impact of knockouts. Thus, the typical usage is to provide a wildtype flux distribution as reference and a model in knockout state.
 Parameters
model (cobra.Model) – The model state to compute a MOMAbased solution for.
solution (cobra.Solution, optional) – A (wildtype) reference solution (default None).
linear (bool, optional) – Whether to use the linear MOMA formulation or not (default True).
 Returns
A flux distribution that is at a minimal distance compared to the reference solution.
 Return type
See also
add_moma
add MOMA constraints and objective
 cobra.flux_analysis.pfba(model: cobra.Model, fraction_of_optimum: float = 1.0, objective: Union[Dict, optlang.interface.Objective, None] = None, reactions: Optional[List[cobra.Reaction]] = None) cobra.Solution [source]¶
Perform basic pFBA (parsimonious Enzyme Usage Flux Balance Analysis).
pFBA [1] adds the minimization of all fluxes the the objective of the model. This approach is motivated by the idea that high fluxes have a higher enzyme turnover and that since producing enzymes is costly, the cell will try to minimize overall flux while still maximizing the original objective function, e.g. the growth rate.
 Parameters
model (cobra.Model) – The model to perform pFBA on.
fraction_of_optimum (float, optional) – The fraction of optimum which must be maintained. The original objective reaction is constrained to be greater than maximal value times the fraction_of_optimum (default 1.0).
objective (dict or cobra.Model.objective, optional) – A desired objective to use during optimization in addition to the pFBA objective. Dictionaries (reaction as key, coefficient as value) can be used for linear objectives (default None).
reactions (list of cobra.Reaction, optional) – List of cobra.Reaction. Implies return_frame to be true. Only return fluxes for the given reactions. Faster than fetching all fluxes if only a few are needed (default None).
 Returns
The solution object to the optimized model with pFBA constraints added.
 Return type
References
 1
Lewis, N. E., Hixson, K. K., Conrad, T. M., Lerman, J. A., Charusanti, P., Polpitiya, A. D., Palsson, B. O. (2010). Omic data from evolved E. coli are consistent with computed optimal growth from genomescale models. Molecular Systems Biology, 6, 390. doi:10.1038/msb.2010.47
 cobra.flux_analysis.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] [source]¶
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.
 Parameters
model (cobra.Model) – The model to analyze.
reaction_list (list of cobra.Reaction or str, optional) – List of reactions to consider, the default includes all model reactions (default None).
zero_cutoff (float, optional) – Flux value which is considered to effectively be zero. The default is set to use model.tolerance (default None).
open_exchanges (bool, optional) – Whether or not to open all exchange reactions to very high flux ranges (default False).
processes (int, optional) – 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).
 Returns
List with the identifiers of blocked reactions.
 Return type
Notes
Sink and demand reactions are left untouched. Please modify them manually.
 cobra.flux_analysis.find_essential_genes(model: cobra.Model, threshold: Optional[float] = None, processes: Optional[int] = None) Set[cobra.Gene] [source]¶
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.
 Parameters
model (cobra.Model) – The model to find the essential genes for.
threshold (float, optional) – Minimal objective flux to be considered viable. By default this is 1% of the maximal objective (default None).
processes (int, optional) – 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).
 Returns
Set of essential genes.
 Return type
set of cobra.Gene
 cobra.flux_analysis.find_essential_reactions(model: cobra.Model, threshold: Optional[float] = None, processes: Optional[int] = None) Set[cobra.Reaction] [source]¶
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.
 Parameters
model (cobra.Model) – The model to find the essential reactions for.
threshold (float, optional) – Minimal objective flux to be considered viable. By default this is 1% of the maximal objective (default None).
processes (int, optional) – 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).
 Returns
Set of essential reactions.
 Return type
 cobra.flux_analysis.flux_variability_analysis(model: cobra.Model, reaction_list: Optional[List[Union[cobra.Reaction, str]]] = None, loopless: bool = False, fraction_of_optimum: float = 1.0, pfba_factor: Optional[float] = None, processes: Optional[int] = None) pandas.DataFrame [source]¶
Determine the minimum and maximum flux value for each reaction.
 Parameters
model (cobra.Model) – The model for which to run the analysis. It will not be modified.
reaction_list (list of cobra.Reaction or str, optional) – The reactions for which to obtain min/max fluxes. If None will use all reactions in the model (default None).
loopless (bool, optional) – Whether to return only loopless solutions. This is significantly slower. Please also refer to the notes (default False).
fraction_of_optimum (float, optional) – 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).
pfba_factor (float, optional) – 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).
processes (int, optional) – The number of parallel processes to run. If not explicitly passed, will be set from the global configuration singleton (default None).
 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
 Return type
pandas.DataFrame
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 suboptimal.
Using the loopless option will lead to a significant increase in computation time (about a factor of 100 for large models). However, the algorithm used here (see [2]_) is still more than 1000x faster than the “naive” version using add_loopless(model). Also note that if you have included constraints that force a loop (for instance by setting all fluxes in a loop to be nonzero) this loop will be included in the solution.
References
 1
Computationally efficient flux variability analysis. Gudmundsson S, Thiele I. BMC Bioinformatics. 2010 Sep 29;11:489. doi: 10.1186/1471210511489, PMID: 20920235
 2
CycleFreeFlux: efficient removal of thermodynamically infeasible loops from flux distributions. Desouki AA, Jarre F, GeliusDietrich G, Lercher MJ. Bioinformatics. 2015 Jul 1;31(13):215965. doi: 10.1093/bioinformatics/btv096.
 cobra.flux_analysis.production_envelope(model: cobra.Model, reactions: List[cobra.Reaction], objective: Union[Dict, optlang.interface.Objective, None] = None, carbon_sources: Optional[List[cobra.Reaction]] = None, points: int = 20, threshold: Optional[float] = None) pandas.DataFrame [source]¶
Calculate the objective value conditioned on all flux combinations.
The production envelope can be used to analyze a model’s ability to produce a given compound conditional on the fluxes for another set of reactions, such as the uptake rates. The model is alternately optimized with respect to minimizing and maximizing the objective and the obtained fluxes are recorded. Ranges to compute production is set to the effective bounds, i.e., the minimum / maximum fluxes that can be obtained given current reaction bounds.
 Parameters
model (cobra.Model) – The model to compute the production envelope for.
reactions (list of cobra.Reaction) – A list of reaction objects.
objective (dict or cobra.Model.objective, optional) – The objective (reaction) to use for the production envelope. Use the model’s current objective if left missing (default None).
carbon_sources (list of cobra.Reaction, optional) – One or more reactions that are the source of carbon for computing carbon (mol carbon in output over mol carbon in input) and mass yield (gram product over gram output). Only objectives with a carbon containing input and output metabolite is supported. Will identify active carbon sources in the medium if none are specified (default None).
points (int, optional) – The number of points to calculate production for (default 20).
threshold (float, optional) – A cutoff under which flux values will be considered to be zero. If not specified, it defaults to model.tolerance (default None).
 Returns
A DataFrame with fixed columns as:  carbon_source : identifiers of carbon exchange reactions  flux_maximum : maximum objective flux  flux_minimum : minimum objective flux  carbon_yield_maximum : maximum yield of a carbon source  carbon_yield_minimum : minimum yield of a carbon source  mass_yield_maximum : maximum mass yield of a carbon source  mass_yield_minimum : minimum mass yield of a carbon source
and variable columns (for each input reactions) as:  reaction_id : flux at each given point
 Return type
pandas.DataFrame
 Raises
ValueError – If model’s objective is comprised of multiple reactions.
Examples
>>> import cobra.io >>> from cobra.flux_analysis import production_envelope >>> model = cobra.io.load_model("textbook") >>> production_envelope(model, ["EX_glc__D_e", "EX_o2_e"]) carbon_source flux_minimum carbon_yield_minimum mass_yield_minimum ... 0 EX_glc__D_e 0.0 0.0 NaN ... 1 EX_glc__D_e 0.0 0.0 NaN ... 2 EX_glc__D_e 0.0 0.0 NaN ... 3 EX_glc__D_e 0.0 0.0 NaN ... 4 EX_glc__D_e 0.0 0.0 NaN ... .. ... ... ... ... ... 395 EX_glc__D_e NaN NaN NaN ... 396 EX_glc__D_e NaN NaN NaN ... 397 EX_glc__D_e NaN NaN NaN ... 398 EX_glc__D_e NaN NaN NaN ... 399 EX_glc__D_e NaN NaN NaN ...
[400 rows x 9 columns]
 cobra.flux_analysis.add_room(model: cobra.Model, solution: Optional[cobra.Solution] = None, linear: bool = False, delta: float = 0.03, epsilon: float = 0.001) None [source]¶
Add constraints and objective for ROOM.
This function adds variables and constraints for applying regulatory on/off minimization (ROOM) to the model.
 Parameters
model (cobra.Model) – The model to add ROOM constraints and objective to.
solution (cobra.Solution, optional) – A previous solution to use as a reference. If no solution is given, one will be computed using pFBA (default None).
linear (bool, optional) – Whether to use the linear ROOM formulation or not (default False).
delta (float, optional) – The relative tolerance range which is additive in nature (default 0.03).
epsilon (float, optional) – The absolute range of tolerance which is multiplicative (default 0.001).
Notes
The formulation used here is the same as stated in the original paper [1]_. The mathematical expression is given below:
minimize: sum_{i=1}^m y^i s.t. : Sv = 0
v_min le v le v_max v_j = 0 j in A for 1 le i le m v_i  y_i(v_{max,i}  w_i^u) le w_i^u (1) v_i  y_i(v_{min,i}  w_i^l) le w_i^l (2) y_i in {0,1} (3) w_i^u = w_i + deltaw_i + epsilon w_i^l = w_i  deltaw_i  epsilon
So, for the linear version of the ROOM , constraint (3) is relaxed to 0 le y_i le 1.
See also
pfba
parsimonious FBA
References
 1
Tomer Shlomi, Omer Berkman and Eytan Ruppin, “Regulatory on/off minimization of metabolic flux changes after genetic perturbations”, PNAS 2005 102 (21) 76957700; doi:10.1073/pnas.0406346102
 cobra.flux_analysis.room(model: cobra.Model, solution: Optional[cobra.Solution] = None, linear: bool = False, delta: float = 0.03, epsilon: float = 0.001) cobra.Solution [source]¶
Compute a solution based on regulatory on/off minimization (ROOM).
Compute a new flux distribution that minimizes the number of active reactions needed to accommodate a previous reference solution. Regulatory on/off minimization (ROOM) is generally used to assess the impact of knockouts. Thus, the typical usage is to provide a wildtype flux distribution as reference and a model in knockout state.
 Parameters
model (cobra.Model) – The model state to compute a ROOMbased solution for.
solution (cobra.Solution, optional) – A (wildtype) reference solution (default None).
linear (bool, optional) – Whether to use the linear ROOM formulation or not (default False).
delta (float, optional) – The relative tolerance range (additive) (default 0.03).
epsilon (float, optional) – The absolute tolerance range (multiplicative) (default 0.001).
 Returns
A flux distribution with minimal active reaction changes compared to the reference.
 Return type
See also
add_room
add ROOM constraints and objective