straindesign.lptools
A collection of functions for the LP-based analysis of metabolic networks
Module Contents
- straindesign.lptools.fba(model, **kwargs) cobra.core.Solution [source]
Flux Balance Analysis (FBA), parsimonius Flux Balance Analysis (pFBA),
Flux Balance Analysis optimizes a linear objective function in a space of steady-state flux vectors given by a constraint-based metabolic model. FVA is often used to determine the (stoichiometrically) maximal possible growth rate, or flux rate towards a particular product. This FBA function allows to us a custom objective function and sense and allows the user to narrow down the flux states with additional constraints. In addition, one may use different types of parsimonious FBAs to either reduce the total sum of fluxes or the total number of active reactions after the primary objective is optimized.
Example
optim = fba(model, constraints=’EX_o2_e=0’, solver=’gurobi’, pfba=1)
- Parameters:
model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class. If no custom objective function is provided, the model’s objective function is retrieved from the fields model.reactions[i].objective_coefficient.
solver (optional (str)) – The solver that should be used for FBA.
constraints (optional (str) or (list of str) or (list of [dict,str,float])) – (Default: ‘’) List of linear constraints to be applied on top of the model: signs + or -, scalar factors for reaction rates, inclusive (in)equalities and a float value on the right hand side. The parsing of the constraints input allows for some flexibility. Correct (and identical) inputs are, for instance: constraints=’-EX_o2_e <= 5, ATPM = 20’ or constraints=[‘-EX_o2_e <= 5’, ‘ATPM = 20’] or constraints=[[{‘EX_o2_e’:-1},’<=’,5], [{‘ATPM’:1},’=’,20]]
obj (optional (str) or (dict)) – As a custom objective function, any linear expression can be used, either provided as a single string or as a dict. Correct (and identical) inputs are, for instance: inner_objective=’BIOMASS_Ecoli_core_w_GAM’ inner_objective={‘BIOMASS_Ecoli_core_w_GAM’: 1}
obj_sense (optional (str)) – (Default: ‘maximize’) The optimization direction can be set either to ‘maximize’ (or ‘max’) or ‘minimize’ (or ‘min’).
pfba (optional (int)) – (Default: 0) The level of parsimonious FBA that should be applied. 0: no pFBA, only optmize the primary objective, 1: minimize sum of fluxes after the primary objective is optimized, 2: minimize the number of active reactions after the primary objective is optimized.
- Returns:
A solution object that contains the objective value, an optimal flux vector and the optmization status.
- Return type:
(cobra.core.Solution)
- straindesign.lptools.fva(model, **kwargs) pandas.DataFrame [source]
Flux Variability Analysis (FVA)
Flux Variability Analysis determines the global flux ranges of reactions by minimizing and maximizing the flux through all reactions of a given metabolic network. This FVA function additionally allows the user to narrow down the flux states with additional constraints.
Example
flux_ranges = fva(model, constraints=’EX_o2_e=0’, solver=’gurobi’)
- Parameters:
model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class.
solver (optional (str)) – The solver that should be used for FVA.
constraints (optional (str) or (list of str) or (list of [dict,str,float])) – (Default: ‘’) List of linear constraints to be applied on top of the model: signs + or -, scalar factors for reaction rates, inclusive (in)equalities and a float value on the right hand side. The parsing of the constraints input allows for some flexibility. Correct (and identical) inputs are, for instance: constraints=’-EX_o2_e <= 5, ATPM = 20’ or constraints=[‘-EX_o2_e <= 5’, ‘ATPM = 20’] or constraints=[[{‘EX_o2_e’:-1},’<=’,5], [{‘ATPM’:1},’=’,20]]
- Returns:
A data frame containing the minimum and maximum attainable flux rates for all reactions.
- Return type:
(pandas.DataFrame)
- straindesign.lptools.fva_worker_compute(i) Tuple[int, float] [source]
Helper function for parallel FVA
Run a single LP as a step of FVA. Is executed on workers, not on main thread.
- Parameters:
i (int) – Index of the computation step.
- straindesign.lptools.fva_worker_compute_glpk(i) Tuple[int, float] [source]
Helper function for parallel FVA
Run a single LP for GLPK as a step of FVA. Is executed on workers, not on main thread.
- Parameters:
i (int) – Index of the computation step.
- straindesign.lptools.fva_worker_init(A_ineq, b_ineq, A_eq, b_eq, lb, ub, solver)[source]
Helper function for parallel FVA
Initialize the LP that will be solved iteratively. Is executed on workers, not on main thread.
- Parameters:
A_ineq – The LP.
b_ineq – The LP.
A_eq – The LP.
b_eq – The LP.
lb – The LP.
ub – The LP.
solver (str) – Solver to be used.
- straindesign.lptools.fva_worker_init_glpk(A_ineq, b_ineq, A_eq, b_eq, lb, ub)[source]
Helper function for parallel FVA
Initialize the LP for GLPK that will be solved iteratively. Is executed on workers, not on main thread.
- Parameters:
A_ineq – The LP.
b_ineq – The LP.
A_eq – The LP.
b_eq – The LP.
lb – The LP.
ub – The LP.
- straindesign.lptools.idx2c(i, prev) list [source]
Helper function for parallel FVA
Builds the objective function for minimizing or maximizing the flux through the reaction with the index floor(i / 2). If i is even, there is a maximization.
- straindesign.lptools.plot_flux_space(model, axes, **kwargs) Tuple[list, list, list] [source]
Plot projections of the space of steady-state flux vectors onto two or three dimensions.
This function uses LP and matplotlib to generate lower dimensional representations of the flux space. Custom linear or fractional-linear expressions can be used for the plot axis. The most commonly used flux space reprentations are the production envelope that plots the growth rate (x) vs the product synthesis rate (y) and the yield space plot that plots the biomass yield (x) vs the product yiel (y). One may specify additional constraints to investigate subspaces of the metabolic steady-state flux space.
Example
plot_flux_space(model,(‘BIOMASS_Ecoli_core_w_GAM’,’EX_etoh_e’))
- Parameters:
model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class.
axes ((list of lists) or (list of str)) – A set of linear expressions that specify which reactions/expressions/dimensions should be used on the axis. Examples: axes=[‘BIOMASS_Ecoli_core_w_GAM’,’EX_etoh_e’] or axes=[[‘BIOMASS_Ecoli_core_w_GAM’,’-EX_glc_e’],[‘EX_etoh_e’,’-EX_glc_e’]] or axes=[[‘BIOMASS_Ecoli_core_w_GAM’],[‘EX_etoh_e’,’-EX_glc_e’]]
solver (optional (str)) – The solver that should be used for scanning the flux space.
constraints (optional (str) or (list of str) or (list of [dict,str,float])) – (Default: ‘’) List of linear constraints to be applied on top of the model: signs + or -, scalar factors for reaction rates, inclusive (in)equalities and a float value on the right hand side. The parsing of the constraints input allows for some flexibility. Correct (and identical) inputs are, for instance: constraints=’-EX_o2_e <= 5, ATPM = 20’ or constraints=[‘-EX_o2_e <= 5’, ‘ATPM = 20’] or constraints=[[{‘EX_o2_e’:-1},’<=’,5], [{‘ATPM’:1},’=’,20]]
plt_backend (optional (str)) –
The matplotlib backend that should be used for plotting: interactive backends: GTK3Agg, GTK3Cairo, GTK4Agg, GTK4Cairo, MacOSX, nbAgg, QtAgg, QtCairo,
TkAgg, TkCairo, WebAgg, WX, WXAgg, WXCairo, Qt5Agg, Qt5Cairo
non-interactive backends: agg, cairo, pdf, pgf, ps, svg, template
show (optional (bool)) – (Default: True) Should matplotlib show the plot or should it stop after plot generation. show=False can be useful if multiple flux spaces should be plotted at once or the plot should be modified before been shown.
points (optional (int)) – (Default: 25 (3D) or 40 (2D)) The number of intervals in which the flux space should be sampled along each axis. A higher number will increase resoltion but also computation time.
- Returns:
(datapoints, triang, plot1). The array of datapoints from which the plot was generated. These datapoints are optimal values for different optimizations within the flux space. The triang variable contains information about which datapoints need to be connected in triangles to render a consistend 3-D surface with Delaunay triangles (Delaunay triangulation). The last variable contains the matplotlib object.
- Return type:
(Tuple)
- straindesign.lptools.select_solver(solver=None, model=None) str [source]
Select a solver for subsequent MILP/LP computations
This function will determine the solver to be used for subsequend MILP/LP computations. If no argument is provided, this function will try to determine the currently selected solver from the COBRA configuration. If unavailable, the solver will be inferred from the packages available at package initialization and one of the solvers will be picked and retured in the prioritized order: ‘glpk’, ‘cplex’, ‘gurobi’, ‘scip’ One may provide a solver or a model manually. This function then checks if the selected solver is available, or else, if the solver indicated in the model is available. If yes, this function returns the name of the solver as a str. If both arguments are specified, the function prefers ‘solver’ over ‘model’.
Example
solver = select_solver(‘cplex’)
- Parameters:
solver (optional (str)) – A user preferred solver, that should be checked for availability: ‘glpk’, ‘cplex’, ‘gurobi’ or ‘scip’.
model (optional (cobra.Model)) – A metabolic model that is an instance of the cobra.Model class. The function will try to dertermine the selected solver by accessing the field model.solver.
- Returns:
The selected solver name as a str (one of the following: ‘glpk’, ‘cplex’, ‘gurobi’, ‘scip’).
- Return type:
(str)
- straindesign.lptools.yopt(model, **kwargs) cobra.core.Solution [source]
Yield optmization (YOpt)
Yield optimization optimizes a fractional objective function in a space of steady-state flux vectors given by a constraint-based metabolic model. Yield optimization employs linear fractional programming, and is often utilized to determine the (stoichiometrically) maximal possible product yield, that is, the fraction between the product exchange and the substrate uptake flux. This function requires a custom fractional objective function specified by a linear numerator and denominator terms. Coefficients in the linear numerator or denominator expression can be used to optimize for carbon recovery, for instance: objective: (3*pyruvate_ex)/(2*ac_up+6*glc_up) The user may also specify the optimization sense. In addition, additional constraints can be specified to narrow down the flux space.
Yield optimization can fail because of several reasons. Here is how the function reacts:
- The model is infeasible:
The function returns infeasible with no flux vector
- The denominator is fixed to zero:
The function returns infeasible with no flux vector
- The numerator is unbounded:
The function returns unbounded with no flux vector
- The denominator can become zero:
The function returns unbounded, and a flux vector is computed by fixing the the denominator
Example
optim = yopt(model, obj_num=’2 EX_etoh_e’, obj_den=’-6 EX_glc__D_e’, constraints=’EX_o2_e=0’)
- Parameters:
model (cobra.Model) – A metabolic model that is an instance of the cobra.Model class.
obj_num ((str) or (dict)) – The numerator of the fractional objective function, provided as a linear expression, either as a character string or as a dict. E.g.: obj_num=’EX_prod_e’ or obj_num={‘EX_prod_e’: 1}
obj_den ((str) or (dict)) – The denominator of the fractional objective function, provided as a linear expression, either as a character string or as a dict. E.g.: obj_num=’1.0 EX_subst_e’ or obj_num={‘EX_subst_e’: 1}
obj_sense (optional (str)) – (Default: ‘maximize’) The optimization direction can be set either to ‘maximize’ (or ‘max’) or ‘minimize’ (or ‘min’).
solver (optional (str)) – The solver that should be used for YOpt.
constraints (optional (str) or (list of str) or (list of [dict,str,float])) – (Default: ‘’) List of linear constraints to be applied on top of the model: signs + or -, scalar factors for reaction rates, inclusive (in)equalities and a float value on the right hand side. The parsing of the constraints input allows for some flexibility. Correct (and identical) inputs are, for instance: constraints=’-EX_o2_e <= 5, ATPM = 20’ or constraints=[‘-EX_o2_e <= 5’, ‘ATPM = 20’] or constraints=[[{‘EX_o2_e’:-1},’<=’,5], [{‘ATPM’:1},’=’,20]]
- Returns:
A solution object that contains the objective value, an optimal flux vector and the optmization status.
- Return type:
(cobra.core.Solution)