{ "cells": [ { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from pandas import options\n", "options.display.max_rows = 8\n", "from cameo import load_model\n", "model = load_model(\"iJO1366\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Simulating models with\n", "\n", "\n", "\n", "**c**omputer **a**ided **m**etabolic **e**ngineering and **o**ptimization\n", "\n", "**cameo** uses and extends the model data structures defined by [cobrapy](https://opencobra.github.io/cobrapy/), our favorite **CO**nstraints-**B**ased **R**econstruction and **A**nalysis tool for **Py**thon. **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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Primer: Constraint-Based Modeling\n", "\n", "Constraint-based modeling is a powerful modeling framework for analyzing metabolism on the genome scale ([McCloskey et al., 2013](http://www.ncbi.nlm.nih.gov/pubmed/23632383)). For a model that encompasses $n$ reactions that involve $m$ metabolites, $\\mathbf{S}$ is a matrix of dimension $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\n", "\n", "$$\n", "\\begin{align}\n", "\\mathbf{S} \\mathbf{v} = 0\\,,\n", "\\end{align}\n", "$$\n", "\n", "where $\\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](https://en.wikipedia.org/wiki/Linear_programming).\n", "\n", "\n", ", e.g., maximimization of biomass production,Given the maximization of growth rate as one potential biological objective $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 ($\\mathbf{v}_{lb}$ and $\\mathbf{v}_{ub}$) on the flux variables $\\mathbf{v}$, one can formulate and solve an optimization problem to identify an optimal set of flux rates using flux balance analysis (FBA):\n", "\n", "$$\n", "\\begin{align}\n", " Max ~ & ~ Z_{obj} = \\mathbf{c}^{T} \\mathbf{v}\\\\\n", " \\text{s.t.}~ & ~ \\mathbf{S} \\mathbf{v} = 0 \\\\\n", " ~ & ~ \\mathbf{v}_{lb} \\leq \\mathbf{v} \\leq \\mathbf{v}_{ub} \\,.\n", "\\end{align}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Flux Balance Analysis\n", "\n", "In **cameo**, flux balance analysis can be performed with the function `fba`." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from cameo import fba\n", "fba_result = fba(model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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`." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0.9823718127269799" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fba_result.objective_value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parsimonious Flux Balance Analysis\n", "\n", "Parsimonious flux balance analysis ([Lewis et al., 2010](http://www.ncbi.nlm.nih.gov/pubmed/20664636)), a variant of FBA, performs FBA in in a first step to determine the maximum objective value $Z_{obj}$, fixes it in form of an additional model constraint ($\\mathbf{c}^{T} \\mathbf{v} \\ge Z_{obj}$), and then minimizes in a second optimization the $L_1$ norm of $\\mathbf{v}$. The assumption behind the pFBA is that cells try to minimize flux magnitude as well in order to keep the costs of protein low.\n", "\n", "$$\n", "\\begin{align}\n", " Max ~ & ~ \\lvert \\mathbf{v} \\rvert\\\\\n", " \\text{s.t.}~ & ~ \\mathbf{S} \\mathbf{v} = 0 \\\\\n", " & ~ \\mathbf{c}^{T} \\mathbf{v} \\ge Z_{obj} \\\\\n", " ~ & ~ \\mathbf{v}_{lb} \\leq \\mathbf{v} \\leq \\mathbf{v}_{ub} \\,.\n", "\\end{align}\n", "$$\n", "\n", "In **cameo**, pFBA can be performed with the function `pfba`." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "from cameo import pfba\n", "pfba_result = pfba(model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `objective_function` value is $\\lvert \\mathbf{v} \\rvert$ ..." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "699.0222751839377" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pfba_result.objective_value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... whis is significantly smaller than flux vector of the original FBA solution." ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "764.91487969777245" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(fba_result.data_frame.flux).sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setp 2: Simulate knockouts phenotypes\n", "-----------------------------------\n", "\n", "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.\n", "\n", "*******************************************\n", "Simulating knockouts:\n", "\n", "* Manipulate the bounds of the reaction (or use the shorthand method knock_out)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IdPGI
Stoichiometryg6p_c <=> f6p_c
Lower bound-999999.000000
Upper bound999999.000000
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.reactions.PGI" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IdPGI
Stoichiometryg6p_c --> f6p_c
Lower bound0.000000
Upper bound0.000000
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.reactions.PGI.knock_out()\n", "model.reactions.PGI" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Simulate using different methods:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 2 µs, sys: 0 ns, total: 2 µs\n", "Wall time: 5.01 µs\n" ] }, { "data": { "text/plain": [ "0.905983" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time\n", "fba_knockout_result = simulation.fba(model)\n", "fba_knockout_result[model.objective]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0.905983" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pfba_knockout_result = simulation.pfba(model)\n", "pfba_knockout_result[model.objective]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "MOMA and ROOM relly on a reference (wild-type) flux distribution and we can use the one previously computed.\n", "\n", "**Parsimonious FBA references seem to produce better results using this methods**" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-18.7358" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lmoma_result[\"2 * EX_glc_lp_e_rp_\"]" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 2 µs, sys: 1 µs, total: 3 µs\n", "Wall time: 5.01 µs\n" ] }, { "data": { "text/plain": [ "0.791393" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time\n", "lmoma_result = simulation.lmoma(model, reference=pfba_result.fluxes)\n", "lmoma_result[model.objective]" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 2 µs, sys: 1 µs, total: 3 µs\n", "Wall time: 5.01 µs\n" ] }, { "data": { "text/plain": [ "0.887440" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time\n", "room_result = simulation.room(model, reference=pfba_result.fluxes)\n", "room_result[model.objective]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "room_result" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }