{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Growth media\n", "\n", "In many instances you might be interested what metabolites your microbial community consumes and produces. `micom` provides facilities to make this simple. Since flux distributions are usually not unique we will usually analyze the \"minimal medium\", meaning the smallest set of import fluxes that allow optimal growth. We will again use our *E. coli* test case. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4bf3d74bdbab4aba9d578d380212053e", "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" ] } ], "source": [ "from micom import Community, data\n", "\n", "tax = data.test_taxonomy()\n", "com = Community(tax)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The easiest case would be that we have a particular community growth rate we want to enforce. In this case we can get the minimal medium with: " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "EX_o2_m 1.398333\n", "EX_glc__D_m 1.398333\n", "dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from micom.media import minimal_medium\n", "\n", "med = minimal_medium(com, 0.8)\n", "med" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default this gives the solution with the smallest total import flux. We could also minimize the *number* of used import fluxes:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "EX_glc__D_m 3.499375\n", "dtype: float64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "minimal_medium(com, 0.8, minimize_components=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, this will be unfeasibly slow and complicated for larger (ergo real) community models so we recommend using the default instead." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As argued before there are many unrealistic growth rate distributions that can be used for a given optimal community growth rate. It is also possible to use the results from cooperative tradeoff as additional constraints in the minimal media calculation. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "EX_pi_m 3.214886\n", "EX_o2_m 21.799487\n", "EX_nh4_m 4.765318\n", "EX_glc__D_m 10.000000\n", "dtype: float64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol = com.cooperative_tradeoff()\n", "rates = sol.members.growth_rate.drop(\"medium\") # extracellular medium has no growth rate\n", "med = minimal_medium(com, sol.growth_rate, min_growth=rates)\n", "med" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In practice you might want to lower the required growth rates a bit to avoid the inclusion of particular imports just to push you the last few percent to the optimum. For instance to only require 95% of the community and individual growth rates:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "EX_pi_m 3.054150\n", "EX_o2_m 19.895954\n", "EX_nh4_m 4.527052\n", "EX_glc__D_m 10.000000\n", "dtype: float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "med = minimal_medium(com, 0.95*sol.growth_rate, min_growth=0.95*rates)\n", "med" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export fluxes\n", "\n", "Sometimes you will also be interested in which metabolites the community produces. This information can be obtained with the `exports` argument of the `minimal_medium` function which will also return the active exports (metabolites produced by the community) under minimal growth." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "EX_h_m -17.530883\n", "EX_pi_m 3.214886\n", "EX_o2_m 21.799487\n", "EX_nh4_m 4.765318\n", "EX_glc__D_m 10.000000\n", "EX_co2_m -22.809827\n", "EX_h2o_m -29.175810\n", "dtype: float64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "med = minimal_medium(com, sol.growth_rate, min_growth=rates, exports=True)\n", "med" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By convention exports have a negative sign and imports a positive one." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Applying growth media\n", "\n", "`micom` pretty much uses the [cobrapy method](https://cobrapy.readthedocs.io/en/stable/_autogen/cobra.core.model.html?highlight=medium#cobra.core.model.Model.medium) of assigning media. Essentially you will need a dictionary-like structure that maps exchange reactions to their upper import flux bound. Fortunately, the output of `minimal_medium` can be used directly for that. So to calculate the minimal medium and use it as the actual growth medium afterwards we can do the following:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "community growth: 0.800
status: optimal
taxa:
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abundancegrowth_ratereactionsmetabolites
compartments
Escherichia_coli_10.250.89572
Escherichia_coli_20.250.89572
Escherichia_coli_30.250.89572
Escherichia_coli_40.250.89572
mediumNaNNaN2020
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "med = minimal_medium(com, 0.8, min_growth=0.8)\n", "com.medium = med\n", "com.cooperative_tradeoff()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we see the new medium has been applied and as a consequence the growth rate has been lowered to the one specified in the minimal medium calculation." ] } ], "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 }