# 14.1.3. cobra.flux_analysis package¶

## 14.1.3.2. cobra.flux_analysis.deletion_worker module¶

class cobra.flux_analysis.deletion_worker.CobraDeletionMockPool(cobra_model, n_processes=1, solver=None, **kwargs)[source]

Bases: object

Mock pool solves LP’s in the same process

receive_all()[source]
receive_one()[source]
start()[source]
submit(indexes, label=None)[source]
terminate()[source]
class cobra.flux_analysis.deletion_worker.CobraDeletionPool(cobra_model, n_processes=None, solver=None, **kwargs)[source]

Bases: object

A pool of workers for solving deletions

submit jobs to the pool using submit and recieve results using receive_all

pids
receive_all()[source]
receive_one()[source]

This function blocks

start()[source]
submit(indexes, label=None)[source]
terminate()[source]
cobra.flux_analysis.deletion_worker.compute_fba_deletion(lp, solver_object, model, indexes, **kwargs)[source]
cobra.flux_analysis.deletion_worker.compute_fba_deletion_worker(cobra_model, solver, job_queue, output_queue, **kwargs)[source]

## 14.1.3.3. cobra.flux_analysis.double_deletion module¶

cobra.flux_analysis.double_deletion.double_deletion(cobra_model, element_list_1=None, element_list_2=None, element_type='gene', **kwargs)[source]

Wrapper for double_gene_deletion and double_reaction_deletion

Deprecated since version 0.4: Use double_reaction_deletion and double_gene_deletion

cobra.flux_analysis.double_deletion.double_gene_deletion(cobra_model, gene_list1=None, gene_list2=None, method='fba', return_frame=False, solver=None, zero_cutoff=1e-12, **kwargs)[source]

sequentially knocks out pairs of genes in a model

cobra_model : Model
cobra model in which to perform deletions
gene_list1 : [Gene:] (or their id’s)
Genes to be deleted. These will be the rows in the result. If not provided, all reactions will be used.
gene_list1 : [Gene:] (or their id’s)
Genes to be deleted. These will be the rows in the result. If not provided, reaction_list1 will be used.
method: “fba” or “moma”
Procedure used to predict the growth rate
solver: str for solver name
This must be a QP-capable solver for MOMA. If left unspecified, a suitable solver will be automatically chosen.
zero_cutoff: float
When checking to see if a value is 0, this threshold is used.
number_of_processes: int for number of processes to use.
If unspecified, the number of parallel processes to use will be automatically determined. Setting this to 1 explicitly disables used of the multiprocessing library.

Note

multiprocessing is not supported with method=moma

return_frame: bool
If true, formats the results as a pandas.Dataframe. Otherwise returns a dict of the form: {“x”: row_labels, “y”: column_labels”, “data”: 2D matrix}
cobra.flux_analysis.double_deletion.double_reaction_deletion(cobra_model, reaction_list1=None, reaction_list2=None, method='fba', return_frame=False, solver=None, zero_cutoff=1e-12, **kwargs)[source]

sequentially knocks out pairs of reactions in a model

cobra_model : Model
cobra model in which to perform deletions
reaction_list1 : [Reaction:] (or their id’s)
Reactions to be deleted. These will be the rows in the result. If not provided, all reactions will be used.
reaction_list2 : [Reaction:] (or their id’s)
Reactions to be deleted. These will be the rows in the result. If not provided, reaction_list1 will be used.
method: “fba” or “moma”
Procedure used to predict the growth rate
solver: str for solver name
This must be a QP-capable solver for MOMA. If left unspecified, a suitable solver will be automatically chosen.
zero_cutoff: float
When checking to see if a value is 0, this threshold is used.
return_frame: bool
If true, formats the results as a pandas.Dataframe. Otherwise returns a dict of the form: {“x”: row_labels, “y”: column_labels”, “data”: 2D matrix}
cobra.flux_analysis.double_deletion.format_results_frame(row_ids, column_ids, matrix, return_frame=False)[source]

format results as a pandas.DataFrame if desired/possible

Otherwise returns a dict of {“x”: row_ids, “y”: column_ids”, “data”: result_matrx}

cobra.flux_analysis.double_deletion.generate_matrix_indexes(ids1, ids2)[source]

map an identifier to an entry in the square result matrix

cobra.flux_analysis.double_deletion.yield_upper_tria_indexes(ids1, ids2, id_to_index)[source]

gives the necessary indexes in the upper triangle

ids1 and ids2 are lists of the identifiers i.e. gene id’s or reaction indexes to be knocked out. id_to_index maps each identifier to its index in the result matrix.

Note that this does not return indexes for the diagonal. Those have to be computed separately.

## 14.1.3.4. cobra.flux_analysis.essentiality module¶

cobra.flux_analysis.essentiality.assess_medium_component_essentiality(cobra_model, the_components=None, the_medium=None, medium_compartment='e', solver='glpk', the_condition=None, method='fba')[source]

Determines which components in an in silico medium are essential for growth in the context of the remaining components.

cobra_model: A Model object.

the_components: None or a list of external boundary reactions that will be sequentially disabled.

the_medium: Is None, a string, or a dictionary. If a string then the initialize_growth_medium function expects that the_model has an attribute dictionary called media_compositions, which is a dictionary of dictionaries for various medium compositions. Where a medium composition is a dictionary of external boundary reaction ids for the medium components and the external boundary fluxes for each medium component.

medium_compartment: the compartment in which the boundary reactions supplying the medium components exist

NOTE: that these fluxes must be negative because the convention is backwards means something is feed into the system.

solver: ‘glpk’, ‘gurobi’, or ‘cplex’

returns: essentiality_dict: A dictionary providing the maximum growth rate accessible when the respective component is removed from the medium.

## 14.1.3.5. cobra.flux_analysis.gapfilling module¶

cobra.flux_analysis.gapfilling.SMILEY(model, metabolite_id, Universal, dm_rxns=False, ex_rxns=False, penalties=None, **solver_parameters)[source]

runs the SMILEY algorithm to determine which gaps should be filled in order for the model to create the metabolite with the given metabolite_id.

This function is good for running the algorithm once. For more fine- grained control, create a SUXModelMILP object, add a demand reaction for the given metabolite_id, and call the solve function on the SUXModelMILP object.

class cobra.flux_analysis.gapfilling.SUXModelMILP(model, Universal=None, threshold=0.05, penalties=None, dm_rxns=True, ex_rxns=False)[source]

Model with additional Universal and Exchange reactions. Adds corresponding dummy reactions and dummy metabolites for each added reaction which are used to impose MILP constraints to minimize the total number of added reactions. See the figure for more information on the structure of the matrix.

add_reactions(reactions)[source]
solve(solver=None, iterations=1, debug=False, time_limit=100, **solver_parameters)[source]

solve the MILP problem

cobra.flux_analysis.gapfilling.growMatch(model, Universal, dm_rxns=False, ex_rxns=False, penalties=None, **solver_parameters)[source]

runs growMatch

## 14.1.3.6. cobra.flux_analysis.loopless module¶

cobra.flux_analysis.loopless.construct_loopless_model(cobra_model)[source]

construct a loopless model

This adds MILP constraints to prevent flux from proceeding in a loop, as done in http://dx.doi.org/10.1016/j.bpj.2010.12.3707 Please see the documentation for an explanation of the algorithm.

This must be solved with an MILP capable solver.

## 14.1.3.7. cobra.flux_analysis.moma module¶

cobra.flux_analysis.moma.create_euclidian_distance_lp(moma_model, solver)[source]
cobra.flux_analysis.moma.create_euclidian_distance_objective(n_moma_reactions)[source]

returns a matrix which will minimze the euclidian distance

This matrix has the structure [ I -I] [-I I] where I is the identity matrix the same size as the number of reactions in the original model.

n_moma_reactions: int
This is the number of reactions in the MOMA model, which should be twice the number of reactions in the original model
cobra.flux_analysis.moma.create_euclidian_moma_model(cobra_model, wt_model=None, **solver_args)[source]
cobra.flux_analysis.moma.moma(wt_model, mutant_model, solver=None, **solver_args)[source]
cobra.flux_analysis.moma.moma_knockout(moma_model, moma_objective, reaction_indexes, **moma_args)[source]

computes result of reaction_knockouts using moma

cobra.flux_analysis.moma.solve_moma_model(moma_model, objective_id, solver=None, **solver_args)[source]

## 14.1.3.8. cobra.flux_analysis.parsimonious module¶

cobra.flux_analysis.parsimonious.optimize_minimal_flux(cobra_model, already_irreversible=False, fraction_of_optimum=1.0, solver=None, desired_objective_value=None, **optimize_kwargs)[source]

Perform basic pFBA (parsimonius FBA) and minimize total flux.

The function attempts to act as a drop-in replacement for optimize. It will make the reaction reversible and perform an optimization, then force the objective value to remain the same and minimize the total flux. Finally, it will convert the reaction back to the irreversible form it was in before. See http://dx.doi.org/10.1038/msb.2010.47

cobra_model : Model object

By default, the model is converted to an irreversible one. However, if the model is already irreversible, this step can be skipped
fraction_of_optimum : float, optional
Fraction of optimum which must be maintained. The original objective reaction is constrained to be greater than maximal_value * fraction_of_optimum. By default, this option is specified to be 1.0
desired_objective_value : float, optional
A desired objective value for the minimal solution that bypasses the initial optimization result.
solver : string of solver name
If None is given, the default solver will be used.

Updates everything in-place, returns model to original state at end.

## 14.1.3.9. cobra.flux_analysis.phenotype_phase_plane module¶

cobra.flux_analysis.phenotype_phase_plane.calculate_phenotype_phase_plane(model, reaction1_name, reaction2_name, reaction1_range_max=20, reaction2_range_max=20, reaction1_npoints=50, reaction2_npoints=50, solver=None, n_processes=1, tolerance=1e-06)[source]

calculates the growth rates while varying the uptake rates for two reactions.

Returns: a phenotypePhasePlaneData object containing the growth rates

for the uptake rates. To plot the result, call the plot function of the returned object.

>>> import cobra.test
>>> model = cobra.test.create_test_model("textbook")
>>> ppp = calculate_phenotype_phase_plane(model, "EX_glc__D_e", "EX_o2_e")
>>> ppp.plot()

class cobra.flux_analysis.phenotype_phase_plane.phenotypePhasePlaneData(reaction1_name, reaction2_name, reaction1_range_max, reaction2_range_max, reaction1_npoints, reaction2_npoints)[source]

Bases: object

class to hold results of a phenotype phase plane analysis

plot()[source]

plot the phenotype phase plane in 3D using any available backend

plot_matplotlib(theme='Paired', scale_grid=False)[source]

Use matplotlib to plot a phenotype phase plane in 3D.

theme: color theme to use (requires palettable)

returns: maptlotlib 3d subplot object

plot_mayavi()[source]

Use mayavi to plot a phenotype phase plane in 3D. The resulting figure will be quick to interact with in real time, but might be difficult to save as a vector figure. returns: mlab figure object

segment(threshold=0.01)[source]

attempt to segment the data and identify the various phases

## 14.1.3.10. cobra.flux_analysis.reaction module¶

cobra.flux_analysis.reaction.assess(model, reaction, flux_coefficient_cutoff=0.001, solver=None)[source]

Assesses the capacity of the model to produce the precursors for the reaction and absorb the production of the reaction while the reaction is operating at, or above, the specified cutoff.

model: A Model object

reaction: A Reaction object

flux_coefficient_cutoff: Float. The minimum flux that reaction must carry to be considered active.

solver : String or solver name. If None, the default solver will be used.

returns: True if the model can produce the precursors and absorb the products for the reaction operating at, or above, flux_coefficient_cutoff. Otherwise, a dictionary of {‘precursor’: Status, ‘product’: Status}. Where Status is the results from assess_precursors and assess_products, respectively.

cobra.flux_analysis.reaction.assess_precursors(model, reaction, flux_coefficient_cutoff=0.001, solver=None)[source]

Assesses the ability of the model to provide sufficient precursors for a reaction operating at, or beyond, the specified cutoff.

model: A Model object

reaction: A Reaction object

flux_coefficient_cutoff: Float. The minimum flux that reaction must carry to be considered active.

solver : String or solver name. If None, the default solver will be used.

returns: True if the precursors can be simultaneously produced at the specified cutoff. False, if the model has the capacity to produce each individual precursor at the specified threshold but not all precursors at the required level simultaneously. Otherwise a dictionary of the required and the produced fluxes for each reactant that is not produced in sufficient quantities.

cobra.flux_analysis.reaction.assess_products(model, reaction, flux_coefficient_cutoff=0.001, solver=None)[source]

Assesses whether the model has the capacity to absorb the products of a reaction at a given flux rate. Useful for identifying which components might be blocking a reaction from achieving a specific flux rate.

model: A Model object

reaction: A Reaction object

flux_coefficient_cutoff: Float. The minimum flux that reaction must carry to be considered active.

solver : String or solver name. If None, the default solver will be used.

returns: True if the model has the capacity to absorb all the reaction products being simultaneously given the specified cutoff. False, if the model has the capacity to absorb each individual product but not all products at the required level simultaneously. Otherwise a dictionary of the required and the capacity fluxes for each product that is not absorbed in sufficient quantities.

## 14.1.3.11. cobra.flux_analysis.single_deletion module¶

cobra.flux_analysis.single_deletion.single_deletion(cobra_model, element_list=None, element_type='gene', **kwargs)[source]

Wrapper for single_gene_deletion and single_reaction_deletion

Deprecated since version 0.4: Use single_reaction_deletion and single_gene_deletion

cobra.flux_analysis.single_deletion.single_gene_deletion(cobra_model, gene_list=None, solver=None, method='fba', **solver_args)[source]

sequentially knocks out each gene in a model

gene_list: list of gene_ids or cobra.Gene

method: “fba” or “moma”

returns ({gene_id: growth_rate}, {gene_id: status})

cobra.flux_analysis.single_deletion.single_gene_deletion_fba(cobra_model, gene_list, solver=None, **solver_args)[source]
cobra.flux_analysis.single_deletion.single_gene_deletion_moma(cobra_model, gene_list, solver=None, **solver_args)[source]
cobra.flux_analysis.single_deletion.single_reaction_deletion(cobra_model, reaction_list=None, solver=None, method='fba', **solver_args)[source]

sequentially knocks out each reaction in a model

reaction_list: list of reaction_ids or cobra.Reaction

method: “fba” or “moma”

returns ({reaction_id: growth_rate}, {reaction_id: status})

cobra.flux_analysis.single_deletion.single_reaction_deletion_fba(cobra_model, reaction_list, solver=None, **solver_args)[source]

sequentially knocks out each reaction in a model using FBA

reaction_list: list of reaction_ids or cobra.Reaction

method: “fba” or “moma”

returns ({reaction_id: growth_rate}, {reaction_id: status})

cobra.flux_analysis.single_deletion.single_reaction_deletion_moma(cobra_model, reaction_list, solver=None, **solver_args)[source]

sequentially knocks out each reaction in a model using MOMA

reaction_list: list of reaction_ids or cobra.Reaction

returns ({reaction_id: growth_rate}, {reaction_id: status})

## 14.1.3.12. cobra.flux_analysis.summary module¶

cobra.flux_analysis.summary.format_long_string(string, max_length)[source]
cobra.flux_analysis.summary.metabolite_summary(met, threshold=0.01, fva=False, floatfmt='.3g', **solver_args)[source]

Print a summary of the reactions which produce and consume this metabolite

threshold: float a value below which to ignore reaction fluxes

fva: float (0->1), or None Whether or not to include flux variability analysis in the output. If given, fva should be a float between 0 and 1, representing the fraction of the optimum objective to be searched.

floatfmt: string
format method for floats, passed to tabulate. Default is ‘.3g’.
cobra.flux_analysis.summary.model_summary(model, threshold=1e-08, fva=None, floatfmt='.3g', **solver_args)[source]

Print a summary of the input and output fluxes of the model.

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’.

## 14.1.3.13. cobra.flux_analysis.variability module¶

cobra.flux_analysis.variability.calculate_lp_variability(lp, solver, cobra_model, reaction_list, **solver_args)[source]

calculate max and min of selected variables in an LP

cobra.flux_analysis.variability.find_blocked_reactions(cobra_model, reaction_list=None, solver=None, zero_cutoff=1e-09, open_exchanges=False, **solver_args)[source]

Finds reactions that cannot carry a flux with the current exchange reaction settings for cobra_model, using flux variability analysis.

cobra.flux_analysis.variability.flux_variability_analysis(cobra_model, reaction_list=None, fraction_of_optimum=1.0, solver=None, objective_sense='maximize', **solver_args)[source]

Runs flux variability analysis to find max/min flux values

cobra_model : Model:

reaction_list : list of Reaction: or their id’s
The id’s for which FVA should be run. If this is None, the bounds will be comptued for all reactions in the model.
fraction_of_optimum : fraction of optimum which must be maintained.
The original objective reaction is constrained to be greater than maximal_value * fraction_of_optimum
solver : string of solver name
If None is given, the default solver will be used.