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
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
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
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
A 2-D array with shape (k, 2) where k is the number of columns in S.
This array specifies the directions of coordinates.
Each row should be:
[0, 0] for coordinates that can be only zero
[0, 1] for coordinates that can be only positive
[-1, 0] for coordinates that can be only negative
[-1, 1] for coordinates that can be both positive and negative
v_bound (float, optional) – The bound for the variables in the optimization problem (default 1e4).
zero_cutoff (float, optional) – The cutoff value to consider a coordinate value as zero (default 1e-6).
bias (float, optional) – The bias for the non-zero constraint in the optimization problem
(default 1).
required_stop_checks_num (int, optional) – The number of random checks to pass to prove that basis
could not be expanded (default 3).
Returns:
If S is an array with shape (m, k), then an array
with shape (k, n) will be returned, where n is the dimension of the
nullspace of S with directions. Each column of this array is a basis
vector for the nullspace; each element in numpy.dot(S, column) will be
approximately zero. Each coordinate in the column will have an allowed
sign according to the directions parameter.
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]_.
Find reactions, that can be in a loop in a steady state flux distribution.
Parameters:
model (cobra.Model) – The metabolic model to analyze.
zero_cutoff (float, optional) – The cutoff value to consider a flux as zero.
The default uses the model.tolerance (default None).
bound (float, optional) – The bound for the reaction fluxes in the optimization problem.
(default is 1e4).
method (str, optional) – The method to use for finding cyclic reactions.
Options are “optimized” (default) or “basic”.
See notes for details.
required_stop_checks_num (int, optional) – This parameter is used only for the “optimized” method.
The number of random checks to pass to prove that all cyclic
reactions were found. (default is 3).
Returns:
A list of reaction IDs that can be part of a loop.
A list of tuples indicating the possible directions of
reactions from the first list in the loop.
Each tuple contains two boolean values: (can_be_negative, can_be_positive).
Return type:
A tuple containing two lists
Notes
This function considers only the stoichiometric matrix and reaction directions.
Any other constraints present in the model are ignored.
* If a reaction is identified as cyclic, there may still be no feasible loop
when taking into account all bounds and additional constraints.
However, if a reaction is identified as non-cyclic, it cannot participate
in any loop in a steady-state flux distribution.
The “basic” method for each reaction and direction checks if it can be a part of
a loop by optimizing linear programming problem.
The “optimized” method uses a faster randomized approach to firstly find all
reactions that can be part of a loop and then checks their directions. This method
usually works at least 2 times faster than the “basic” method.
The required_stop_checks_num parameter is used to descrease the probability
of missing some cyclic reactions.
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.
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 1E-06).
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.
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. This function will modify your model.
The used formulation is described in [1]_. If method is set to
“fastSNP”, it uses a faster implementation based on the Fast-SNP
algorithm [2]_.
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).
method (str, "original" or "fastSNP", optional) – The method to use for finding the null space. The “original” method
uses the original method from [1]_, while “fastSNP” uses a faster
implementation based on the FastSNP algorithm. The “fastSNP” method
is much faster and should be used in most cases.
reactions (list of str, optional) – The list of reaction IDs to constrain. All cycles within these
reactions will be removed. If None, all reactions will be constrained.
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).
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.
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 re-center 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.
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 knock-outs. Thus, the typical usage is to provide a wild-type flux
distribution as reference and a model in knock-out state.
Parameters:
model (cobra.Model) – The model state to compute a MOMA-based solution for.
solution (cobra.Solution, optional) – A (wild-type) 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.
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 turn-over 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.
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.
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 cut-off 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
>>> importcobra.io>>> fromcobra.flux_analysisimportproduction_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 ...
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 + delta|w_i| + epsilon
w_i^l = w_i - delta|w_i| - epsilon
So, for the linear version of the ROOM , constraint (3) is relaxed to
0 le y_i le 1.
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 knock-outs. Thus, the typical usage is to provide a wild-type
flux distribution as reference and a model in knock-out state.
Parameters:
model (cobra.Model) – The model state to compute a ROOM-based solution for.
solution (cobra.Solution, optional) – A (wild-type) 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.
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.
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).
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).
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).
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 (str, "fastSNP" or "cycleFreeFlux", optional) – 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).
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
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.