{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **Course**: BIO-341 [_Dynamical systems in biology_](https://moodle.epfl.ch/course/info.php?id=14291)\n",
    "\n",
    "**Professor**: _Julian Shillcock_ & _Felix Naef_\n",
    "\n",
    "SSV, BA5, 2025\n",
    "\n",
    "Note that this document is primarily aimed at being consulted as a Jupyter notebook, the PDF rendering being not optimal."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/vq/knfnd3fs6x19mn5xcw685flr0000gq/T/ipykernel_10015/1896525300.py:6: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`\n",
      "  set_matplotlib_formats('png', 'pdf')\n"
     ]
    }
   ],
   "source": [
    "# the libraries you will need\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from ipywidgets import interact\n",
    "from scipy.integrate import odeint\n",
    "from IPython.display import set_matplotlib_formats\n",
    "set_matplotlib_formats('png', 'pdf')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Biochemical circuits based on reciprocal feedback"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The goal is to study two different genetic network architectures that are related to the one described in “Construction of a genetic toggle switch in E.Coli” (Gardner, Cantor and Collins et al.  Nature, 2000). This paper discusses a model based on reciprocal negative feedback inhibition. Here, we first ask you to consider\n",
    "positive feedbacks and then a combination of both positive and negative feedbacks."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A genetic toggle switch based on reciprocal positive feedback"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**1) Read the paper “Construction of a genetic toggle switch in E. Coli” on moodle (“Nature2000.pdf”).**\n",
    "\n",
    "**2) Describe the meaning of each interaction, represented as arrows in Figure 1 in the paper.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's look at the equations: \n",
    "\n",
    "$$ \\binom{\\dot{u}}{\\dot{v}}= \\binom{\\frac{\\alpha_{1}}{1+v^{\\beta}} -u}{  \\frac{\\alpha_{2}}{1+u^{\\gamma}} -v} \\,\\, \\quad(Model\\,\\, 1) $$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**3) What are the degradation rates for $u$ and $v$ ?**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**4) What is the meaning of the parameters $\\beta$ and  $\\gamma$?**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5) Where do the terms $\\frac{1}{1+v^{\\beta}}$ and $\\frac{1}{1+u^{\\gamma}}$ come from? What is the meaning of the “$1+$” in the denominator?**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**6) Write a model (Model 2) representing a pair of reciprocal\n",
    "\t\t*activators*. Use the variables $u,v$ and write down the production and degradation terms as in Model 1. Suppose that the activating mechanism is similar to the autocatalytic switch. Namely, the production rate is proportional to the $\\underline{occupied}$ $\\underline{fraction}$ of the promoter, and suppose that the promoter has *two binding sites* for proteins. *Hint*:\n",
    "\t\tWrite a simple model that is similar to Model 1. Do not introduce any additional parameters.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**7) Calculate by hand the Jacobian (in terms of the model parameters) of Model 2 and analyze the stability of the fixed point at $(0,0)$.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**8) Sketch the nullclines and discuss (in words) under which conditions the system has 3 fixed points, vary $\\alpha_1$ and $\\alpha_2$ but for now impose $\\alpha_1=\\alpha_2=\\alpha$**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**We will now determine when the system is bistable (two stable fixed points). Combine the two nullclines (elimination of $v$) to get a function $f(u)$ of a single variable such that fixed points correspond to the zeros of this function: $f(u^*)=0$. First look at the symmetric case when $\\alpha_{1}=\\alpha_{2}$ (so $u^*=v^*$).**\n",
    "\n",
    "**9) How many fixed points does the system have for different $\\alpha$?**\n",
    "\n",
    "**10) Do you think it is also possible to find the zeros analytically for the non-symmetric case?**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**11) Compute the stability of the fixed points for the symmetric case, for different values of $\\alpha$, both $\\alpha_{1}=\\alpha_{2} >2$ and $\\alpha_{1}=\\alpha_{2} <2$**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**12) Study the phase portrait for Model 2 in the two symmetric cases $\\alpha_{1}=\\alpha_{2} >2$ and $\\alpha_{1}=\\alpha_{2} <2$**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You could also try out the libraries ipywidgets or bokeh to interact with plots, eg, showing how the plot changes as you change alpha. Maybe ask ChatGPT for help!"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.5"
  },
  "widgets": {
   "state": {
    "37136cb5b79e4494931dff6dfd168428": {
     "views": [
      {
       "cell_index": 33
      }
     ]
    },
    "39c17ef237764e28b3052d35d050f23f": {
     "views": [
      {
       "cell_index": 25
      }
     ]
    },
    "c22241d36a014f08853721208bf13f0d": {
     "views": [
      {
       "cell_index": 20
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
