{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Flux Balance Analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load a few packages and functions." ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas\n", "pandas.options.display.max_rows = 12\n", "import escher\n", "from cameo import models, fba\n", "from cameo.exceptions import Infeasible" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Predict maximum growth rate and metabolic fluxes of wildtype _E. coli_." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we load a model from the [BiGG](http://bigg.ucsd.edu/) database (and make a copy of it)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "model = models.bigg.e_coli_core.copy()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Maximize\n", "1.0*BIOMASS_Ecoli_core_w_GAM - 1.0*BIOMASS_Ecoli_core_w_GAM_reverse_712e5\n" ] } ], "source": [ "print(model.objective)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run flux balance analysis." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "result = fba(model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The predicted growth rate is $0.87 \\ h^{-1}$." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0.8739215069684306" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.objective_value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Take a look at the predicted metabolic fluxes." ] }, { "cell_type": "code", "execution_count": 7, "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", "
flux
ACALD0.000000
ACALDt0.000000
ACKr0.000000
ACONTa6.007250
ACONTb6.007250
ACt2r0.000000
......
SUCOAS-5.064376
TALA1.496984
THD20.000000
TKT11.496984
TKT21.181498
TPI7.477382
\n", "

95 rows × 1 columns

\n", "
" ], "text/plain": [ " flux\n", "ACALD 0.000000\n", "ACALDt 0.000000\n", "ACKr 0.000000\n", "ACONTa 6.007250\n", "ACONTb 6.007250\n", "ACt2r 0.000000\n", "... ...\n", "SUCOAS -5.064376\n", "TALA 1.496984\n", "THD2 0.000000\n", "TKT1 1.496984\n", "TKT2 1.181498\n", "TPI 7.477382\n", "\n", "[95 rows x 1 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.data_frame" ] }, { "cell_type": "code", "execution_count": 8, "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", "
flux
count95.000000
mean2.627753
std10.698095
min-29.175827
25%0.000000
50%0.000000
75%4.959985
max45.514010
\n", "
" ], "text/plain": [ " flux\n", "count 95.000000\n", "mean 2.627753\n", "std 10.698095\n", "min -29.175827\n", "25% 0.000000\n", "50% 0.000000\n", "75% 4.959985\n", "max 45.514010" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.data_frame.describe()" ] }, { "cell_type": "code", "execution_count": 19, "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", "
flux
H2Ot-29.175827
CO2t-22.809833
EX_o2_e-21.799493
PGK-16.023526
PGM-14.716140
EX_glc__D_e-10.000000
......
O2t21.799493
EX_co2_e22.809833
EX_h2o_e29.175827
NADH1638.534610
CYTBD43.598985
ATPS4r45.514010
\n", "

48 rows × 1 columns

\n", "
" ], "text/plain": [ " flux\n", "H2Ot -29.175827\n", "CO2t -22.809833\n", "EX_o2_e -21.799493\n", "PGK -16.023526\n", "PGM -14.716140\n", "EX_glc__D_e -10.000000\n", "... ...\n", "O2t 21.799493\n", "EX_co2_e 22.809833\n", "EX_h2o_e 29.175827\n", "NADH16 38.534610\n", "CYTBD 43.598985\n", "ATPS4r 45.514010\n", "\n", "[48 rows x 1 columns]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "active_fluxes = result.data_frame[result.data_frame.flux != 0].sort_values(by='flux')\n", "active_fluxes" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IdATPS4r
NameATP synthase (four protons for one ATP)
Stoichiometryadp_c + pi_c + 4.0 h_e <=> 3.0 h_c + atp_c + h2o_c
Lower bound-1000.000000
Upper bound1000.000000
\n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.reactions.ATPS4r" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import escher\n", "import jupyter" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'1.4.4'" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "escher.__version__" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "---\r\n", "Metadata-Version: 2.0\r\n", "Name: jupyter\r\n", "Version: 1.0.0\r\n", "Summary: Jupyter metapackage. Install all the Jupyter components in one go.\r\n", "Home-page: http://jupyter.org\r\n", "Author: Jupyter Development Team\r\n", "Author-email: jupyter@googlegroups.org\r\n", "Installer: pip\r\n", "License: BSD\r\n", "Location: /opt/conda/lib/python3.5/site-packages\r\n", "Requires: nbconvert, qtconsole, notebook, ipywidgets, ipykernel, jupyter-console\r\n", "Classifiers:\r\n", " Intended Audience :: Developers\r\n", " Intended Audience :: System Administrators\r\n", " Intended Audience :: Science/Research\r\n", " License :: OSI Approved :: BSD License\r\n", " Programming Language :: Python\r\n", " Programming Language :: Python :: 2\r\n", " Programming Language :: Python :: 2.7\r\n", " Programming Language :: Python :: 3\r\n", " Programming Language :: Python :: 3.3\r\n", " Programming Language :: Python :: 3.4\r\n", "\u001b[33mThe directory '/home/jovyan/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.\u001b[0m\r\n" ] } ], "source": [ "!pip show jupyter" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "
\n", "\n", " \n" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "escher.Builder('e_coli_core.Core metabolism', reaction_data=active_fluxes.flux.to_dict()).display_in_notebook()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "
\n", "\n", " \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result.display_on_map('e_coli_core.Core metabolism')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Exercise" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Try a few different objectives.\n", "* Assess the effects of gene deletions.\n", " * Hint: a gene can be knocked out by running `model.genes.get_by_id('').knock_out()` where needs to be replace with an actual gene identifier." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solutions" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "b0351 0.8739215069684306\n", "b1241 0.8739215069684306\n", "s0001 0.21114065257211675\n", "b1849 0.8739215069684306\n", "b3115 0.8739215069684306\n", "b2296 0.8739215069684306\n", "b1276 0.8739215069684306\n", "b0118 0.8739215069684306\n", "b0474 0.8739215069684306\n", "b0116 0.7823510529477393\n", "b0726 0.858307408022689\n", "b0727 0.858307408022689\n", "b2587 0.8739215069684306\n", "b0356 0.8739215069684306\n", "b1478 0.8739215069684306\n", "b3731 0.3742298749331099\n", "b3733 0.3742298749331099\n", "b3735 0.3742298749331099\n", "b3739 0.8739215069684306\n", "b3732 0.3742298749331099\n", "b3737 0.3742298749331099\n", "b3736 0.3742298749331099\n", "b3738 0.3742298749331099\n", "b3734 0.3742298749331099\n", "b0720 6.871561491399276e-32\n", "b0979 0.8739215069684306\n", "b0978 0.8739215069684306\n", "b0733 0.8739215069684306\n", "b0734 0.8739215069684306\n", "b2975 0.8739215069684306\n", "b3603 0.8739215069684306\n", "b2779 5.794860387693435e-18\n", "b2925 0.8739215069684306\n", "b1773 0.8739215069684306\n", "b2097 0.8739215069684306\n", "b3925 0.8739215069684306\n", "b4232 0.8739215069684306\n", "b0904 0.8739215069684306\n", "b2492 0.8739215069684306\n", "b4151 0.8739215069684306\n", "b4154 0.8739215069684306\n", "b4152 0.8739215069684306\n", "b4153 0.8739215069684306\n", "b1817 0.8739215069684306\n", "b2415 0\n", "b1818 0.8739215069684306\n", "b1819 0.8739215069684306\n", "b2416 0\n", "b4122 0.8739215069684306\n", "b1612 0.8739215069684306\n", "b1611 0.8739215069684306\n", "b3528 0.8739215069684306\n", "b1852 0.8638133095040006\n", "b1779 2.817340211473703e-30\n", "b1101 0.8739215069684306\n", "b1621 0.8739215069684306\n", "b2417 0.8739215069684306\n", "b3870 0.8739215069684306\n", "b1297 0.8739215069684306\n", "b0810 0.8739215069684306\n", "b0809 0.8739215069684306\n", "b0811 0.8739215069684306\n", "b1761 0.8513885233462087\n", "b1524 0.8739215069684306\n", "b1812 0.8739215069684306\n", "b0485 0.8739215069684306\n", "b3213 0.8739215069684306\n", "b3212 0.8739215069684306\n", "b4077 0.8739215069684306\n", "b2029 0.8638133095040006\n", "b0875 0.8739215069684306\n", "b1136 1.2368810684518696e-30\n", "b4015 0.8739215069684306\n", "b2133 0.8739215069684306\n", "b1380 0.8739215069684306\n", "b4014 0.8739215069684306\n", "b2976 0.8739215069684306\n", "b3236 0.8258192905969889\n", "b1479 0.8739215069684306\n", "b2463 0.8739215069684306\n", "b2279 0.21166294973531039\n", "b2282 0.21166294973531039\n", "b2284 0.21166294973531039\n", "b2287 0.21166294973531039\n", "b2276 0.21166294973531039\n", "b2278 0.21166294973531039\n", "b2288 0.21166294973531039\n", "b2285 0.21166294973531039\n", "b2280 0.21166294973531039\n", "b2281 0.21166294973531039\n", "b2283 0.21166294973531039\n", "b2286 0.21166294973531039\n", "b2277 0.21166294973531039\n", "b1602 0.8739215069684306\n", "b3962 0.8739215069684306\n", "b1603 0.8739215069684306\n", "b0451 0.8739215069684306\n", "b0114 0.7966959254309568\n", "b0115 0.7966959254309568\n", "b3916 0.8739215069684306\n", "b1723 0.8739215069684306\n", "b3114 0.8739215069684306\n", "b3951 0.8739215069684306\n", "b0902 0.8739215069684306\n", "b2579 0.8739215069684306\n", "b0903 0.8739215069684306\n", "b3952 0.8739215069684306\n", "b4025 0.8631595522084183\n", "b2926 3.152630951113317e-18\n", "b0767 0.8638133095040006\n", "b3612 0.8739215069684306\n", "b4395 0.8739215069684306\n", "b0755 0.8739215069684306\n", "b2987 0.8739215069684306\n", "b3493 0.8739215069684306\n", "b3956 0.8707448062160253\n", "b3403 0.8739215069684306\n", "b1702 0.8739215069684306\n", "b2297 0.8739215069684306\n", "b2458 0.8739215069684306\n", "b1676 0.8739215069684306\n", "b1854 0.8739215069684306\n", "b4301 0.8739215069684306\n", "b3386 0.8739215069684306\n", "b2914 0.8739215069684306\n", "b4090 0.8739215069684306\n", "b0722 0.8142975075325306\n", "b0724 0.8142975075325306\n", "b0723 0.8142975075325306\n", "b0721 0.8142975075325306\n", "b0729 0.858307408022689\n", "b0728 0.858307408022689\n", "b0008 0.8739215069684306\n", "b2464 0.8739215069684306\n", "b2935 0.8739215069684306\n", "b2465 0.8739215069684306\n", "b3919 0.7040369478590238\n" ] } ], "source": [ "gene_essentiality = {}\n", "for gene in model.genes:\n", " mutant = model.copy()\n", " mutant.genes.get_by_id(gene.id).knock_out()\n", " try:\n", " print(gene, fba(mutant).objective_value)\n", " gene_essentiality[gene] = fba(mutant).objective_value\n", " except Infeasible:\n", " print(gene, 0)\n", " gene_essentiality[gene] = 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.4", "language": "python", "name": "python3.4" }, "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.4" }, "widgets": { "state": {}, "version": "1.1.2" } }, "nbformat": 4, "nbformat_minor": 0 }