{
"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",
" growth_rates | \n",
" status | \n",
"
\n",
" \n",
" \n",
" \n",
" b0116 | \n",
" 0.782351 | \n",
" optimal | \n",
"
\n",
" \n",
" b0118 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b0351 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b0356 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b0474 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b0726 | \n",
" 0.858307 | \n",
" optimal | \n",
"
\n",
" \n",
" b0727 | \n",
" 0.858307 | \n",
" optimal | \n",
"
\n",
" \n",
" b1241 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b1276 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b1478 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b1849 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b2296 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b2587 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b3115 | \n",
" 0.873922 | \n",
" optimal | \n",
"
\n",
" \n",
" b3732 | \n",
" 0.374230 | \n",
" optimal | \n",
"
\n",
" \n",
" b3733 | \n",
" 0.374230 | \n",
" optimal | \n",
"
\n",
" \n",
" b3734 | \n",
" 0.374230 | \n",
" optimal | \n",
"
\n",
" \n",
" b3735 | \n",
" 0.374230 | \n",
" optimal | \n",
"
\n",
" \n",
" b3736 | \n",
" 0.374230 | \n",
" optimal | \n",
"
\n",
" \n",
" s0001 | \n",
" 0.211141 | \n",
" optimal | \n",
"
\n",
" \n",
"
\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",
" growth_rates | \n",
" status | \n",
"
\n",
" \n",
" \n",
" \n",
" ACALD | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ACALDt | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ACKr | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ACONTa | \n",
" 0.0000 | \n",
" optimal | \n",
"
\n",
" \n",
" ACONTb | \n",
" 0.0000 | \n",
" optimal | \n",
"
\n",
" \n",
" ACt2r | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ADK1 | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" AKGDH | \n",
" 0.8583 | \n",
" optimal | \n",
"
\n",
" \n",
" AKGt2r | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ALCD2x | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ATPM | \n",
" 0.9166 | \n",
" optimal | \n",
"
\n",
" \n",
" ATPS4r | \n",
" 0.3742 | \n",
" optimal | \n",
"
\n",
" \n",
" Biomass_Ecoli_core | \n",
" 0.0000 | \n",
" optimal | \n",
"
\n",
" \n",
" CO2t | \n",
" 0.4617 | \n",
" optimal | \n",
"
\n",
" \n",
" CS | \n",
" -0.0000 | \n",
" optimal | \n",
"
\n",
" \n",
" CYTBD | \n",
" 0.2117 | \n",
" optimal | \n",
"
\n",
" \n",
" D_LACt2 | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" ENO | \n",
" -0.0000 | \n",
" optimal | \n",
"
\n",
" \n",
" ETOHt2r | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
" EX_ac_e | \n",
" 0.8739 | \n",
" optimal | \n",
"
\n",
" \n",
"
\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",
" b2464 | \n",
" b0008 | \n",
" b2935 | \n",
" b2465 | \n",
" b3919 | \n",
"
\n",
" \n",
" \n",
" \n",
" b2464 | \n",
" 0.8739 | \n",
" 0.8648 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.704 | \n",
"
\n",
" \n",
" b0008 | \n",
" 0.8648 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.704 | \n",
"
\n",
" \n",
" b2935 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.0000 | \n",
" 0.704 | \n",
"
\n",
" \n",
" b2465 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
" 0.0000 | \n",
" 0.8739 | \n",
" 0.704 | \n",
"
\n",
" \n",
" b3919 | \n",
" 0.7040 | \n",
" 0.7040 | \n",
" 0.7040 | \n",
" 0.7040 | \n",
" 0.704 | \n",
"
\n",
" \n",
"
\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",
" ACKr | \n",
" ACONTa | \n",
" ACONTb | \n",
" ACt2r | \n",
" ADK1 | \n",
"
\n",
" \n",
" \n",
" \n",
" ACKr | \n",
" 0.8739 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
"
\n",
" \n",
" ACONTa | \n",
" 0.0000 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0000 | \n",
" 0.0000 | \n",
"
\n",
" \n",
" ACONTb | \n",
" 0.0000 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0000 | \n",
" 0.0000 | \n",
"
\n",
" \n",
" ACt2r | \n",
" 0.8739 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
"
\n",
" \n",
" ADK1 | \n",
" 0.8739 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.8739 | \n",
" 0.8739 | \n",
"
\n",
" \n",
"
\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
}