Simulate models =============== cameo uses and extends the model data structures defined by `cobrapy `__, our favorite COnstraints-Based Reconstruction and Analysis tool for Python. cameo is thus 100% compatible with cobrapy. For efficiency reasons, however, cameo implements its own simulation methods that take advantage of a more advanced solver interface. Primer: Constraint-Based Modeling --------------------------------- Constraint-based modeling is a powerful modeling framework for analyzing metabolism on the genome scale (`McCloskey et al., 2013 `__). For a model that encompasses :math:`n` reactions that involve :math:`m` metabolites, :math:`\mathbf{S}` is a matrix of dimension :math:`m \times n` that encodes the stoichiometry of the metabolic reaction system; it is usually referred to as stoichiometric matrix. Assuming that the system is in a steady state—the concentration of metabolites are constant—the system of flux-balances can be formulated as .. math:: \begin{align} \mathbf{S} \mathbf{v} = 0\,, \end{align} where :math:`\mathbf{v}` is the vector of flux rates. With the addition of a biologically meaningful objective, flux capacity constraints, information about the reversibility of reactions under physiological conditions, an optimization problem can be formulated that can easily be solved using `linear programming `__. , e.g., maximimization of biomass production,Given the maximization of growth rate as one potential biological objective :math:`v_{biomass}`, i.e., the flux of an artificial reaction that consumes biomass components in empirically determined proportions, and assuming that the cell is evolutionary optimized to achieve that objective, and incorporating knowledge about reaction reversibility, uptake and secretion rates, and maximum flux capacities in the form of lower and uppers bounds (:math:`\mathbf{v}_{lb}` and :math:`\mathbf{v}_{ub}`) on the flux variables :math:`\mathbf{v}`, one can formulate and solve an optimization problem to identify an optimal set of flux rates using flux balance analysis (FBA): .. math:: \begin{align} Max ~ & ~ Z_{obj} = \mathbf{c}^{T} \mathbf{v}\\ \text{s.t.}~ & ~ \mathbf{S} \mathbf{v} = 0 \\ ~ & ~ \mathbf{v}_{lb} \leq \mathbf{v} \leq \mathbf{v}_{ub} \,. \end{align} Flux Balance Analysis --------------------- Load a model. .. code:: python from cameo import load_model model = load_model('iJO1366') .. raw:: html In cameo, flux balance analysis can be performed with the function ``fba``. .. code:: python from cameo import fba %time fba_result = fba(model) .. parsed-literal:: CPU times: user 348 ms, sys: 5.36 ms, total: 353 ms Wall time: 378 ms Basically, ``fba`` calls ``model.solve()`` and wraps the optimization solution in a ``FluxDistributionResult`` object. The maximum objective values (corresponding to a maximum growth rate) can obtained throug ``result.objective_value``. .. code:: python fba_result.data_frame .. raw:: html
flux
DM_4crsol_c 0.000219
DM_5drib_c 0.000221
DM_aacald_c 0.000000
DM_amob_c 0.000002
DM_mththf_c 0.000440
DM_oxam_c 0.000000
BIOMASS_Ec_iJO1366_WT_53p95M 0.000000
... ...
XYLt2pp 0.000000
XYLtex 0.000000
ZN2abcpp 0.000000
ZN2t3pp 0.000000
ZN2tpp 0.000335
ZNabcpp 0.000000
Zn2tex 0.000335

2583 rows × 1 columns

Flux distributions can be visualized using `*escher* `__ : .. code:: python fba_result.display_on_map("iJO1366.Central metabolism") .. raw:: html
Parsimonious Flux Balance Analysis ---------------------------------- Parsimonious flux balance analysis (`Lewis et al., 2010 `__), a variant of FBA, performs FBA in in a first step to determine the maximum objective value :math:`Z_{obj}`, fixes it in form of an additional model constraint (:math:`\mathbf{c}^{T} \mathbf{v} \ge Z_{obj}`), and then minimizes in a second optimization the :math:`L_1` norm of :math:`\mathbf{v}`. The assumption behind pFBA is that cells try to minimize flux magnitude as well in order to keep protein costs low. .. math:: \begin{align} Max ~ & ~ \lvert \mathbf{v} \rvert\\ \text{s.t.}~ & ~ \mathbf{S} \mathbf{v} = 0 \\ & ~ \mathbf{c}^{T} \mathbf{v} \ge Z_{obj} \\ ~ & ~ \mathbf{v}_{lb} \leq \mathbf{v} \leq \mathbf{v}_{ub} \,. \end{align} In cameo, pFBA can be performed with the function ``pfba``. .. code:: python from cameo import pfba %time pfba_result = pfba(model) .. parsed-literal:: CPU times: user 382 ms, sys: 15.3 ms, total: 398 ms Wall time: 494 ms The ``objective_function`` value is :math:`\lvert \mathbf{v} \rvert` ... .. code:: python pfba_result.objective_value .. parsed-literal:: 699.0222751839442 ... which is smaller than flux vector of the original FBA solution. .. code:: python abs(fba_result.data_frame.flux).sum() .. parsed-literal:: 701.81777502444379 Setp 2: Simulate knockouts phenotypes ------------------------------------- Although PFBA and FBA can be used to simulate the effect of knockouts, other methods have been proven more valuable for that task: MOMA and ROOM. In *cameo* we implement a linear version of MOMA. -------------- Simulating knockouts: - Manipulate the bounds of the reaction (or use the shorthand method knock\_out) .. code:: python model.reactions.PGI .. raw:: html
IdPGI
NameGlucose-6-phosphate isomerase
Stoichiometryg6p_c <=> f6p_c
Lower bound-1000.000000
Upper bound1000.000000
.. code:: python model.reactions.PGI.knock_out() model.reactions.PGI .. raw:: html
IdPGI
NameGlucose-6-phosphate isomerase
Stoichiometryg6p_c --> f6p_c
Lower bound0.000000
Upper bound0.000000
- Simulate using different methods: .. code:: python %time fba_knockout_result = fba(model) fba_knockout_result[model.reactions.BIOMASS_Ec_iJO1366_core_53p95M] .. parsed-literal:: CPU times: user 257 ms, sys: 6.5 ms, total: 264 ms Wall time: 359 ms .. parsed-literal:: 0.9761293262973523 .. code:: python %time pfba_knockout_result = pfba(model) pfba_knockout_result[model.reactions.BIOMASS_Ec_iJO1366_core_53p95M] .. parsed-literal:: CPU times: user 664 ms, sys: 21.4 ms, total: 685 ms Wall time: 1.05 s .. parsed-literal:: 0.9761293262947272 MOMA and ROOM relly on a reference (wild-type) flux distribution and we can use the one previously computed. **Parsimonious FBA references seem to produce better results using this methods** .. code:: python from cameo.flux_analysis.simulation import room, lmoma .. code:: python %time lmoma_result = lmoma(model, reference=pfba_result.fluxes) lmoma_result[model.reactions.BIOMASS_Ec_iJO1366_core_53p95M] .. parsed-literal:: CPU times: user 8.07 s, sys: 120 ms, total: 8.19 s Wall time: 8.93 s .. parsed-literal:: 0.8724092397035627 ROOM is a dificult computational problem. If the bounds of the system are not large enought, it can take many hours to simulate. To improve the speed of the simulation and the chances of finding a solution, we increase the bounds. .. code:: python for reaction in model.reactions: if reaction.upper_bound == 1000: reaction.upper_bound = 99999999 if reaction.lower_bound == -1000: reaction.lower_bound = -99999999 .. code:: python %time room_result = room(model, reference=pfba_result.fluxes) room_result[model.reactions.BIOMASS_Ec_iJO1366_core_53p95M] .. parsed-literal:: CPU times: user 11.5 s, sys: 83 ms, total: 11.6 s Wall time: 11.8 s .. parsed-literal:: 0.8724092397035627