{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# BE 150/Bi 250b: Introduction to Python for genetic networks\n",
"\n",
"(c) 2018 Justin Bois. This work is licensed under a [Creative Commons Attribution License CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/). All code contained herein is licensed under an [MIT license](https://opensource.org/licenses/MIT).\n",
"\n",
"This document was prepared at [Caltech](http://www.caltech.edu) with support financial support from the [Donna and Benjamin M. Rosen Bioengineering Center](http://rosen.caltech.edu).\n",
"\n",
"*This tutorial was generated from a Jupyter notebook. You can download the notebook [here](intro_to_python_for_systems_biology.ipynb).*\n",
"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You have already installed [Anaconda](https://store.continuum.io/cshop/anaconda/). Anaconda contains most of what we need to do scientific computing with Python. At the most basic level, it has Python 3.6. It contains other modules we will make heavy use of, the three most important ones being [NumPy](http://www.numpy.org/), [SciPy](http://www.scipy.org/), and [matplotlib](http://matplotlib.org/).\n",
"\n",
"In this tutorial, we will first learn some of the basics of using Python to analyze genetic networks.\n",
"\n",
"We will perform our analysis in a Jupyter notebook. Jupyter notebooks are great for creating tutorials such as this one. The beauty of using an Jupyter notebook is that you can combine nice typesetting of text and mathematical expressions with individual sections of code. The code can be run section by section, or the whole document can be run at once. You will probably want to use a Jupyter notebook for your homework, and this is what we will use interactively during when going over computational techniques in lecture.\n",
"\n",
"To launch a Jupyter notebook, enter\n",
"\n",
" jupyter notebook\n",
"\n",
"on the command line and hit enter. Jupyter will launch in a browser window. To the upper right, you can use a pulldown menu to create a new Python 3 Jupyter notebook. This will open a new tab or window with a fresh notebook.\n",
"\n",
"Optionally, you can use JupyterLab, which is my personal preference. If you have it installed, you can launch it by entering\n",
"\n",
" jupyter lab\n",
" \n",
"on the command line."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Our model system\n",
"\n",
"For the purposes of this tutorial, we will model a cascade. The genetic network is shown below.\n",
"\n",
"\\begin{align}\n",
"\\mathrm{X} \\to \\mathrm{Y} \\to \\mathrm{Z}\n",
"\\end{align}\n",
"\n",
"Here, X is our input, which we will specify. (X could be something like an externally imposed stimulus.) We are interested in the response of Y and Z as a function of input X.\n",
"\n",
"We will assume Hill-like behavior for the activation of Y by X and of Z by Y. We also neglect leakage. We define the concentrations of X, Y, and Z, respectively as $x$, $y$, and $z$. The system of ODEs describing this system is then\n",
"\n",
"\\begin{align}\n",
"\\frac{\\mathrm{d}y}{\\mathrm{d}t} &= \\beta_y\\,\\frac{(x/k_x)^{n_x}}{1+(x/k_x)^{n_x}} - \\gamma_y y, \\\\[2mm]\n",
"\\frac{\\mathrm{d}z}{\\mathrm{d}t} &= \\beta_z\\,\\frac{(y/k_y)^{n_y}}{1+(y/k_y)^{n_y}} - \\gamma_z z.\n",
"\\end{align}\n",
"\n",
"Note that $x$ is a function of time. As is generally a good idea for analysis of these systems, we will non-dimensionalize. We define dimensionless parameters as follows.\n",
"\n",
"\\begin{align}\n",
"\\tilde{t} &= \\gamma_y t, \\\\[2mm]\n",
"\\tilde{x} &= x/k_x, \\\\[2mm]\n",
"\\tilde{y} &= y/k_y, \\\\[2mm]\n",
"\\tilde{z} &= z/k_y, \\\\[2mm]\n",
"\\gamma &= \\gamma_z/\\gamma_y, \\\\[2mm]\n",
"\\tilde{\\beta}_y &= \\frac{\\beta_y}{\\gamma_y k_y}, \\\\[2mm]\n",
"\\tilde{\\beta}_z &= \\frac{\\beta_z}{\\gamma_z k_y}.\n",
"\\end{align}\n",
"\n",
"With these in hand, our dimensionless ODEs are\n",
"\n",
"\\begin{align}\n",
"\\frac{\\mathrm{d}\\tilde{y}}{\\mathrm{d}\\tilde{t}} &= \\tilde{\\beta}_y\\,\\frac{\\tilde{x}^{n_x}}{1+\\tilde{x}^{n_x}} - \\tilde{y}, \\\\[2mm]\n",
"\\gamma^{-1}\\,\\frac{\\mathrm{d}\\tilde{z}}{\\mathrm{d}\\tilde{t}} &= \\tilde{\\beta}_z\\,\\frac{\\tilde{y}^{n_y}}{1+\\tilde{y}^{n_y}} - \\tilde{z}.\n",
"\\end{align}\n",
"\n",
"For notational convenience, and since we will always be working in dimensionless units, we will drop the tildes.\n",
"\n",
"\\begin{align}\n",
"\\frac{\\mathrm{d}y}{\\mathrm{d}t} &= \\beta_y\\,\\frac{x^{n_x}}{1+x^{n_x}} - y, \\\\[2mm]\n",
"\\gamma^{-1}\\,\\frac{\\mathrm{d}z}{\\mathrm{d}t} &= \\beta_z\\,\\frac{y^{n_y}}{1+y^{n_y}} - z.\n",
"\\end{align}\n",
"\n",
"Thus, in addition to the specifics of our input $x(t)$, we have five parameters, $\\beta_y$, $\\beta_z$, $\\gamma$, $n_x$, and $n_y$.\n",
"\n",
"Our goal is to solve this system of ODEs for given parameters and $x(t)$. We will use `scipy.integrate.odeint()` to do the solutions."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Modules\n",
"\n",
"In order to do scientific computing and plotting, we need to import the modules that contain the packages we need. I will go ahead and import all modules we will need for this tutorial now. I'll talk about each module as we use them throughout the tutorial."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"