{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Analyzing models\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 though **cameo** implements its own analysis methods that take advantage of a more advanced solver interface." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\") {\n", " window._bokeh_onload_callbacks = [];\n", " }\n", "\n", " function run_callbacks() {\n", " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " delete window._bokeh_onload_callbacks\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " window._bokeh_onload_callbacks.push(callback);\n", " if (window._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " window._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " window._bokeh_is_loading--;\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };\n", "\n", " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.1.min.js'];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " Bokeh.$(\"#a5c0cac2-673b-40c8-823b-7ad848f55392\").text(\"BokehJS successfully loaded\");\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i](window.Bokeh);\n", " }\n", " }\n", "\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(this));" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from cameo import models\n", "model = models.bigg.e_coli_core" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Flux Variability Analysis\n", "\n", "Flux variability analysis (FVA) enables the computation of lower and upper bounds of reaction fluxes." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from cameo import flux_variability_analysis" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
upper_boundlower_bound
ACALD9.375217e-16-2.000000e+01
ACALDt0.000000e+00-2.000000e+01
ACKr-1.862346e-15-2.000000e+01
ACONTa2.000000e+01-4.825168e-16
ACONTb2.000000e+01-1.999683e-16
ACt2r0.000000e+00-2.000000e+01
ADK11.666100e+020.000000e+00
.........
SUCDi1.000000e+030.000000e+00
SUCOAS-3.552714e-15-2.000000e+01
TALA2.000000e+01-1.545362e-01
THD23.332200e+020.000000e+00
TKT12.000000e+01-1.545362e-01
TKT22.000000e+01-4.663728e-01
TPI1.000000e+01-1.000000e+01
\n", "

95 rows × 2 columns

\n", "
" ], "text/plain": [ " upper_bound lower_bound\n", "ACALD 9.375217e-16 -2.000000e+01\n", "ACALDt 0.000000e+00 -2.000000e+01\n", "ACKr -1.862346e-15 -2.000000e+01\n", "ACONTa 2.000000e+01 -4.825168e-16\n", "ACONTb 2.000000e+01 -1.999683e-16\n", "ACt2r 0.000000e+00 -2.000000e+01\n", "ADK1 1.666100e+02 0.000000e+00\n", "... ... ...\n", "SUCDi 1.000000e+03 0.000000e+00\n", "SUCOAS -3.552714e-15 -2.000000e+01\n", "TALA 2.000000e+01 -1.545362e-01\n", "THD2 3.332200e+02 0.000000e+00\n", "TKT1 2.000000e+01 -1.545362e-01\n", "TKT2 2.000000e+01 -4.663728e-01\n", "TPI 1.000000e+01 -1.000000e+01\n", "\n", "[95 rows x 2 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fva_result = flux_variability_analysis(model)\n", "fva_result.data_frame" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fva_result.plot(index=fva_result.data_frame.index[:25])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One very useful application of FVA is determining if alternative optimal solution exist." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
upper_boundlower_bound
ACALD0.000000e+00-12.602453
ACALDt3.774758e-15-12.602453
ACKr0.000000e+00-13.358852
ACONTa1.383029e+010.471437
ACONTb1.383029e+010.471437
ACt2r-6.527569e-14-13.358852
ADK18.433833e+010.000000
.........
SUCDi1.000000e+030.000000
SUCOAS0.000000e+00-13.358852
TALA1.328068e+01-0.154536
THD21.686767e+020.000000
TKT11.328068e+01-0.154536
TKT21.312294e+01-0.466373
TPI9.565355e+00-3.793497
\n", "

95 rows × 2 columns

\n", "
" ], "text/plain": [ " upper_bound lower_bound\n", "ACALD 0.000000e+00 -12.602453\n", "ACALDt 3.774758e-15 -12.602453\n", "ACKr 0.000000e+00 -13.358852\n", "ACONTa 1.383029e+01 0.471437\n", "ACONTb 1.383029e+01 0.471437\n", "ACt2r -6.527569e-14 -13.358852\n", "ADK1 8.433833e+01 0.000000\n", "... ... ...\n", "SUCDi 1.000000e+03 0.000000\n", "SUCOAS 0.000000e+00 -13.358852\n", "TALA 1.328068e+01 -0.154536\n", "THD2 1.686767e+02 0.000000\n", "TKT1 1.328068e+01 -0.154536\n", "TKT2 1.312294e+01 -0.466373\n", "TPI 9.565355e+00 -3.793497\n", "\n", "[95 rows x 2 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fva_result2 = flux_variability_analysis(model,fraction_of_optimum=0.5)\n", "fva_result2.data_frame" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fva_result2.plot()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from cameo.visualization import plotting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Phenotpic Phase Plane\n", "--------------------\n", "\n", "The phenotypic phase plane is a modeling technique was developed to do a theoretical accessement of what cell can or cannot do in terms of the stoichiometric constraints [Edawards *et al.* 2001]. \n", "\n", "The phenotipic phase plane between growth and a product of interest yields the production envelope: a representation between the trade of between production of the desired product and growth." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from cameo import phenotypic_phase_plane" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "model.reactions.EX_o2_e.lower_bound = -10\n", "result = phenotypic_phase_plane(model, \n", " variables=[model.reactions.BIOMASS_Ecoli_core_w_GAM],\n", " objective=model.reactions.EX_succ_e,\n", " points=10)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The production envelope allows is a quick way to inspect the limitations of the system to design and how the production relates for with growth. In the previous example, succinate prudction is completly decoupled from growth and by decreasing the growth rate it is theoretically possible to produce up to 15 times more succinate. " ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result.plot(points=[(0.52, 0), (0.23, 12.2)], points_colors=[\"green\", \"red\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The production envelope can show the coupling between growth and production. There is no stoichiometric couple between growth and production for succinate under aerobic conditions, but that is not the case for acetate under anaerobic conditions." ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result = phenotypic_phase_plane(model, \n", " variables=[model.reactions.BIOMASS_Ecoli_core_w_GAM],\n", " objective=model.reactions.EX_ac_e)\n", "result.plot()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BIOMASS_Ecoli_core_w_GAMobjective_lower_boundobjective_upper_bound
00.5590519.9056811.503269
10.5296272.6279611.950466
20.5002030.0000012.397662
30.4707790.0000012.844858
40.4413560.0000013.292055
50.4119320.0000013.739251
60.3825080.0000014.186448
............
130.1765420.0000017.316822
140.1471190.0000017.764018
150.1176950.0000018.211215
160.0882710.0000018.658411
170.0588470.0000019.105607
180.0294240.0000019.552804
190.0000000.0000020.000000
\n", "

20 rows × 3 columns

\n", "
" ], "text/plain": [ " BIOMASS_Ecoli_core_w_GAM objective_lower_bound objective_upper_bound\n", "0 0.559051 9.90568 11.503269\n", "1 0.529627 2.62796 11.950466\n", "2 0.500203 0.00000 12.397662\n", "3 0.470779 0.00000 12.844858\n", "4 0.441356 0.00000 13.292055\n", "5 0.411932 0.00000 13.739251\n", "6 0.382508 0.00000 14.186448\n", ".. ... ... ...\n", "13 0.176542 0.00000 17.316822\n", "14 0.147119 0.00000 17.764018\n", "15 0.117695 0.00000 18.211215\n", "16 0.088271 0.00000 18.658411\n", "17 0.058847 0.00000 19.105607\n", "18 0.029424 0.00000 19.552804\n", "19 0.000000 0.00000 20.000000\n", "\n", "[20 rows x 3 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.data_frame" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One can imediatly see if a design is feasible within the new defined constraints." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result.plot(points=[(0.2, 8), (0.2, 2)], points_colors=[\"green\", \"red\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The computed data can be inspected in the format of a pandas data frame by calling `result.data_frame`" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BIOMASS_Ecoli_core_w_GAMobjective_lower_boundobjective_upper_bound
00.5590519.9056811.503269
10.5296272.6279611.950466
20.5002030.0000012.397662
30.4707790.0000012.844858
40.4413560.0000013.292055
50.4119320.0000013.739251
60.3825080.0000014.186448
............
130.1765420.0000017.316822
140.1471190.0000017.764018
150.1176950.0000018.211215
160.0882710.0000018.658411
170.0588470.0000019.105607
180.0294240.0000019.552804
190.0000000.0000020.000000
\n", "

20 rows × 3 columns

\n", "
" ], "text/plain": [ " BIOMASS_Ecoli_core_w_GAM objective_lower_bound objective_upper_bound\n", "0 0.559051 9.90568 11.503269\n", "1 0.529627 2.62796 11.950466\n", "2 0.500203 0.00000 12.397662\n", "3 0.470779 0.00000 12.844858\n", "4 0.441356 0.00000 13.292055\n", "5 0.411932 0.00000 13.739251\n", "6 0.382508 0.00000 14.186448\n", ".. ... ... ...\n", "13 0.176542 0.00000 17.316822\n", "14 0.147119 0.00000 17.764018\n", "15 0.117695 0.00000 18.211215\n", "16 0.088271 0.00000 18.658411\n", "17 0.058847 0.00000 19.105607\n", "18 0.029424 0.00000 19.552804\n", "19 0.000000 0.00000 20.000000\n", "\n", "[20 rows x 3 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.data_frame" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "model.reactions.EX_o2_e.lower_bound = 0\n", "result2 = phenotypic_phase_plane(model, \n", " variables=[model.reactions.BIOMASS_Ecoli_core_w_GAM],\n", " objective=model.reactions.EX_ac_e,\n", " points=10)\n", "result2.plot()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Flux Balance Impact Degree" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from cameo.flux_analysis.analysis import flux_balance_impact_degree" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "model.reactions.EX_o2_e.lower_bound = -10" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 312 ms, sys: 6.53 ms, total: 318 ms\n", "Wall time: 595 ms\n" ] } ], "source": [ "%time fbid = flux_balance_impact_degree(model, [\"EX_o2_e\"])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "

Flux Balance Impact Degree

\n", " \n", "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
perturbed
ACALDFalse
ACALDtFalse
ACKrFalse
ACt2rFalse
ADK1False
ALCD2xFalse
ATPMFalse
......
PYKFalse
PYRt2False
SUCCt2_2False
SUCCt3False
SUCDiFalse
THD2False
TPIFalse
\n", "

62 rows × 1 columns

\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fbid" ] } ], "metadata": { "kernelspec": { "display_name": "IPython (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.2" } }, "nbformat": 4, "nbformat_minor": 0 }