{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simulating Deletions" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas\n", "from time import time\n", "\n", "import cobra.test\n", "from cobra.flux_analysis import \\\n", " single_gene_deletion, single_reaction_deletion, \\\n", " double_gene_deletion, double_reaction_deletion\n", "\n", "cobra_model = cobra.test.create_test_model(\"textbook\")\n", "ecoli_model = cobra.test.create_test_model(\"ecoli\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Single Deletions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Perform all single gene deletions on a model" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "growth_rates, statuses = single_gene_deletion(cobra_model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These can also be done for only a subset of genes" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
growth_ratesstatus
b01160.782351optimal
b01180.873922optimal
b03510.873922optimal
b03560.873922optimal
b04740.873922optimal
b07260.858307optimal
b07270.858307optimal
b12410.873922optimal
b12760.873922optimal
b14780.873922optimal
b18490.873922optimal
b22960.873922optimal
b25870.873922optimal
b31150.873922optimal
b37320.374230optimal
b37330.374230optimal
b37340.374230optimal
b37350.374230optimal
b37360.374230optimal
s00010.211141optimal
\n", "
" ], "text/plain": [ " growth_rates status\n", "b0116 0.782351 optimal\n", "b0118 0.873922 optimal\n", "b0351 0.873922 optimal\n", "b0356 0.873922 optimal\n", "b0474 0.873922 optimal\n", "b0726 0.858307 optimal\n", "b0727 0.858307 optimal\n", "b1241 0.873922 optimal\n", "b1276 0.873922 optimal\n", "b1478 0.873922 optimal\n", "b1849 0.873922 optimal\n", "b2296 0.873922 optimal\n", "b2587 0.873922 optimal\n", "b3115 0.873922 optimal\n", "b3732 0.374230 optimal\n", "b3733 0.374230 optimal\n", "b3734 0.374230 optimal\n", "b3735 0.374230 optimal\n", "b3736 0.374230 optimal\n", "s0001 0.211141 optimal" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gr, st = single_gene_deletion(cobra_model,\n", " cobra_model.genes[:20])\n", "pandas.DataFrame.from_dict({\"growth_rates\": gr,\n", " \"status\": st})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This can also be done for reactions" ] }, { "cell_type": "code", "execution_count": 4, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
growth_ratesstatus
ACALD0.8739optimal
ACALDt0.8739optimal
ACKr0.8739optimal
ACONTa0.0000optimal
ACONTb0.0000optimal
ACt2r0.8739optimal
ADK10.8739optimal
AKGDH0.8583optimal
AKGt2r0.8739optimal
ALCD2x0.8739optimal
ATPM0.9166optimal
ATPS4r0.3742optimal
Biomass_Ecoli_core0.0000optimal
CO2t0.4617optimal
CS-0.0000optimal
CYTBD0.2117optimal
D_LACt20.8739optimal
ENO-0.0000optimal
ETOHt2r0.8739optimal
EX_ac_e0.8739optimal
\n", "
" ], "text/plain": [ " growth_rates status\n", "ACALD 0.8739 optimal\n", "ACALDt 0.8739 optimal\n", "ACKr 0.8739 optimal\n", "ACONTa 0.0000 optimal\n", "ACONTb 0.0000 optimal\n", "ACt2r 0.8739 optimal\n", "ADK1 0.8739 optimal\n", "AKGDH 0.8583 optimal\n", "AKGt2r 0.8739 optimal\n", "ALCD2x 0.8739 optimal\n", "ATPM 0.9166 optimal\n", "ATPS4r 0.3742 optimal\n", "Biomass_Ecoli_core 0.0000 optimal\n", "CO2t 0.4617 optimal\n", "CS -0.0000 optimal\n", "CYTBD 0.2117 optimal\n", "D_LACt2 0.8739 optimal\n", "ENO -0.0000 optimal\n", "ETOHt2r 0.8739 optimal\n", "EX_ac_e 0.8739 optimal" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gr, st = single_reaction_deletion(cobra_model,\n", " cobra_model.reactions[:20])\n", "pandas.DataFrame.from_dict({\"growth_rates\": gr,\n", " \"status\": st}).round(4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Double Deletions\n", "\n", "Double deletions run in a similar way. Passing in return_frame=True will cause them to format the results as a pandas Dataframe" ] }, { "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", "
b2464b0008b2935b2465b3919
b24640.87390.86480.87390.87390.704
b00080.86480.87390.87390.87390.704
b29350.87390.87390.87390.00000.704
b24650.87390.87390.00000.87390.704
b39190.70400.70400.70400.70400.704
\n", "
" ], "text/plain": [ " b2464 b0008 b2935 b2465 b3919\n", "b2464 0.8739 0.8648 0.8739 0.8739 0.704\n", "b0008 0.8648 0.8739 0.8739 0.8739 0.704\n", "b2935 0.8739 0.8739 0.8739 0.0000 0.704\n", "b2465 0.8739 0.8739 0.0000 0.8739 0.704\n", "b3919 0.7040 0.7040 0.7040 0.7040 0.704" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "double_gene_deletion(cobra_model, cobra_model.genes[-5:],\n", " return_frame=True).round(4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, the double deletion function will automatically use multiprocessing, splitting the task over up to 4 cores if they are available. The number of cores can be manually sepcified as well. Setting use of a single core will disable use of the multiprocessing library, which often aids debuggging." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Double gene deletions for 200 genes completed in 27.03 sec with 2 cores\n", "Double gene deletions for 200 genes completed in 40.73 sec with 1 core\n", "Speedup of 1.51x\n" ] } ], "source": [ "start = time() # start timer()\n", "double_gene_deletion(ecoli_model, ecoli_model.genes[:300],\n", " number_of_processes=2)\n", "t1 = time() - start\n", "print(\"Double gene deletions for 200 genes completed in \"\n", " \"%.2f sec with 2 cores\" % t1)\n", "\n", "start = time() # start timer()\n", "double_gene_deletion(ecoli_model, ecoli_model.genes[:300],\n", " number_of_processes=1)\n", "t2 = time() - start\n", "print(\"Double gene deletions for 200 genes completed in \"\n", " \"%.2f sec with 1 core\" % t2)\n", "\n", "print(\"Speedup of %.2fx\" % (t2 / t1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Double deletions can also be run for reactions" ] }, { "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", "
ACKrACONTaACONTbACt2rADK1
ACKr0.87390.00.00.87390.8739
ACONTa0.00000.00.00.00000.0000
ACONTb0.00000.00.00.00000.0000
ACt2r0.87390.00.00.87390.8739
ADK10.87390.00.00.87390.8739
\n", "
" ], "text/plain": [ " ACKr ACONTa ACONTb ACt2r ADK1\n", "ACKr 0.8739 0.0 0.0 0.8739 0.8739\n", "ACONTa 0.0000 0.0 0.0 0.0000 0.0000\n", "ACONTb 0.0000 0.0 0.0 0.0000 0.0000\n", "ACt2r 0.8739 0.0 0.0 0.8739 0.8739\n", "ADK1 0.8739 0.0 0.0 0.8739 0.8739" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "double_reaction_deletion(cobra_model,\n", " cobra_model.reactions[2:7],\n", " return_frame=True).round(4)" ] } ], "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 }