{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Taxa knockouts\n", "\n", "An interesting question concerning any given microbial community is how dependent the growth of one bacteria is one the presence of other bacteria. One strategy to answer that is to perform *in silico* knockouts for each individual\n", "taxa in a community and observe how this changes the growth rates of other bacteria. If the knowckout of one bacteria increases the growth of another one this indicates competitivity whereas a dimished growth rate indicted cooperativity. In order to get unique growth rate solutions we will again use cooperative tradeoff.\n", "\n", "For large models as managed in micom running those knockouts can be challenging due to numerical problems and the tendency of the solvers to get stuck in a previous solutions. `micom` thus implements an optimized knockout algorithms that avoids\n", "numerical and solver issues as much as possible. \n", "\n", "Still you should be aware that knockouts are computationally instensive due to the large numbers of quadratic and linear programming problems that have to be solved. For realistic communities with 10-100 taxa and many samples you should expect a full knockout experiment to take between 1 and 5 hours. Here we will perform the knockouts for our small *E. coli* example." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9ca1f0fedae947fdb1c6a9fc8f9099d1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "75d0f69b3a6d495d92bc5dacf12c16e4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "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", "
compartmentsEscherichia_coli_1Escherichia_coli_2Escherichia_coli_3Escherichia_coli_4
Escherichia_coli_1-0.8739220.3055490.3055490.305549
Escherichia_coli_20.305549-0.8739220.3055490.305549
Escherichia_coli_30.3055490.305549-0.8739220.305549
Escherichia_coli_40.3055490.3055490.305549-0.873922
\n", "
" ], "text/plain": [ "compartments Escherichia_coli_1 Escherichia_coli_2 \\\n", "Escherichia_coli_1 -0.873922 0.305549 \n", "Escherichia_coli_2 0.305549 -0.873922 \n", "Escherichia_coli_3 0.305549 0.305549 \n", "Escherichia_coli_4 0.305549 0.305549 \n", "\n", "compartments Escherichia_coli_3 Escherichia_coli_4 \n", "Escherichia_coli_1 0.305549 0.305549 \n", "Escherichia_coli_2 0.305549 0.305549 \n", "Escherichia_coli_3 -0.873922 0.305549 \n", "Escherichia_coli_4 0.305549 -0.873922 " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from micom import Community, data\n", "\n", "tax = data.test_taxonomy()\n", "com = Community(tax)\n", "\n", "ko = com.knockout_taxa(fraction=1.0)\n", "ko" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default `knockout_species` returns the changes in growth rate meaning the difference between the growth rate after the knockout and the growth rate before. Rows denote the taxa that has been kncked out and columns the changes in growth rate. As we can see all knockouts increase the growth rates of the remaining *E. coli* strains in this example which makes sense since all of them compete for the same resources. Alternatively we can also just get the new growth rates after the knockout" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "928883ae07e8481ca13924c3fb38f918", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "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", "
compartmentsEscherichia_coli_1Escherichia_coli_2Escherichia_coli_3Escherichia_coli_4
Escherichia_coli_10.0000001.1794711.1794711.179471
Escherichia_coli_21.1794710.0000001.1794711.179471
Escherichia_coli_31.1794711.1794710.0000001.179471
Escherichia_coli_41.1794711.1794711.1794710.000000
\n", "
" ], "text/plain": [ "compartments Escherichia_coli_1 Escherichia_coli_2 \\\n", "Escherichia_coli_1 0.000000 1.179471 \n", "Escherichia_coli_2 1.179471 0.000000 \n", "Escherichia_coli_3 1.179471 1.179471 \n", "Escherichia_coli_4 1.179471 1.179471 \n", "\n", "compartments Escherichia_coli_3 Escherichia_coli_4 \n", "Escherichia_coli_1 1.179471 1.179471 \n", "Escherichia_coli_2 1.179471 1.179471 \n", "Escherichia_coli_3 0.000000 1.179471 \n", "Escherichia_coli_4 1.179471 0.000000 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "com.knockout_taxa(fraction=1.0, method=\"raw\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "...or the relative change ((new - old)/old):" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8ce9258753ee49968a268b5c718c4c6a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "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", "
compartmentsEscherichia_coli_1Escherichia_coli_2Escherichia_coli_3Escherichia_coli_4
Escherichia_coli_1-1.000000.349630.349630.34963
Escherichia_coli_20.34963-1.000000.349630.34963
Escherichia_coli_30.349630.34963-1.000000.34963
Escherichia_coli_40.349630.349630.34963-1.00000
\n", "
" ], "text/plain": [ "compartments Escherichia_coli_1 Escherichia_coli_2 \\\n", "Escherichia_coli_1 -1.00000 0.34963 \n", "Escherichia_coli_2 0.34963 -1.00000 \n", "Escherichia_coli_3 0.34963 0.34963 \n", "Escherichia_coli_4 0.34963 0.34963 \n", "\n", "compartments Escherichia_coli_3 Escherichia_coli_4 \n", "Escherichia_coli_1 0.34963 0.34963 \n", "Escherichia_coli_2 0.34963 0.34963 \n", "Escherichia_coli_3 -1.00000 0.34963 \n", "Escherichia_coli_4 0.34963 -1.00000 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "com.knockout_taxa(fraction=1.0, method=\"relative change\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In certain circumstances the diagonal entries can be confusing since the knocked out taxa always loses its entire growth. We can suppress the diagonal using the `diag` argument." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "682a06068a3046208c4d0d6ed964ddf7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "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", "
compartmentsEscherichia_coli_1Escherichia_coli_2Escherichia_coli_3Escherichia_coli_4
Escherichia_coli_1NaN0.3055490.3055490.305549
Escherichia_coli_20.305549NaN0.3055490.305549
Escherichia_coli_30.3055490.305549NaN0.305549
Escherichia_coli_40.3055490.3055490.305549NaN
\n", "
" ], "text/plain": [ "compartments Escherichia_coli_1 Escherichia_coli_2 \\\n", "Escherichia_coli_1 NaN 0.305549 \n", "Escherichia_coli_2 0.305549 NaN \n", "Escherichia_coli_3 0.305549 0.305549 \n", "Escherichia_coli_4 0.305549 0.305549 \n", "\n", "compartments Escherichia_coli_3 Escherichia_coli_4 \n", "Escherichia_coli_1 0.305549 0.305549 \n", "Escherichia_coli_2 0.305549 0.305549 \n", "Escherichia_coli_3 NaN 0.305549 \n", "Escherichia_coli_4 0.305549 NaN " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "com.knockout_taxa(diag=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }