{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "822259e3", "metadata": {}, "outputs": [], "source": [ "import sys\n", "import os\n", "import numpy as np\n", "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "from scipy.stats import bayes_mvs as bayesest\n", "import time\n", "from tqdm import tqdm\n", "\n", "from PyEcoLib.simulator import Simulator\n", "import matplotlib.gridspec as gridspec\n", "import matplotlib" ] }, { "cell_type": "code", "execution_count": null, "id": "dc57a0e9", "metadata": {}, "outputs": [], "source": [ "mean_size = 1 # femto liter\n", "doubling_time = 1 # min\n", "tmax: int = 6 # min\n", "sample_time = 0.05 # min\n", "div_steps = 20\n", "ncells: int = 1000\n", "gr=np.log(2)\n", "sample_time=0.05\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a6dc0fe7", "metadata": {}, "outputs": [], "source": [ "def setaxis(ax):\n", " for axis in ['bottom','left']:\n", " ax.spines[axis].set_linewidth(1.5)\n", " for axis in ['top','right']:\n", " ax.spines[axis].set_linewidth(0)\n", " ax.grid()" ] }, { "cell_type": "code", "execution_count": null, "id": "00f86716", "metadata": {}, "outputs": [], "source": [ "gr = np.log(2)/doubling_time\n", "\n", "if not os.path.exists('./data'):\n", " os.makedirs('./data') # data path\n", "if not os.path.exists('./figures'):\n", " os.makedirs('./figures') # Figures path\n" ] }, { "cell_type": "markdown", "id": "5f5dd210", "metadata": {}, "source": [ "SINGLE CELL SIMULATION" ] }, { "cell_type": "code", "execution_count": null, "id": "ef4db6e5", "metadata": {}, "outputs": [], "source": [ "#Simulating some cell size trajectories\n", "from PyEcoLib.simulator import Simulator\n", "sim = Simulator(ncells=ncells, gr=gr, sb=mean_size, steps=div_steps,V0array=np.random.gamma(shape=1/0.02,scale=0.02,size=1000)) \n", "sim.szdyn(tmax=5, sample_time=0.01, nameCRM='./data/SingleLin.csv')" ] }, { "cell_type": "code", "execution_count": null, "id": "c9165d9d", "metadata": {}, "outputs": [], "source": [ "#function to bin the data for division strategy\n", "def getbins(x,y,qnt):\n", " \n", " df=pd.DataFrame({'X':x,'Y':y})\n", " quantnumber=qnt\n", "\n", " CV2d=[]\n", " delt=[]\n", " sb=[]\n", "\n", " errcv2d=[]\n", " errdelt=[]\n", " errsb=[]\n", " bins=np.linspace(np.min(x),np.max(x),qnt+1)\n", " for i in range(len(bins)-1):\n", " quanta1=df[df.X>bins[i]]\n", " quanta2=quanta1[quanta1.X 5*doubling_time]\n", "\n", "quantnumber = 5\n", "pvadd2 = data2\n", "\n", "CV2darr1 = []\n", "deltarr1 = []\n", "sbarr1 = []\n", "\n", "errcv2darr1 = []\n", "errdeltarr1 = []\n", "errsbarr1 = []\n", "for i in range(quantnumber):\n", " lperv0 = np.percentile(pvadd2.S_b, i*100/quantnumber)\n", " hperv0 = np.percentile(pvadd2.S_b, (i+1)*100/quantnumber)\n", " quanta1 = pvadd2[pvadd2.S_b > lperv0]\n", " quanta2 = quanta1[quanta1.S_b < hperv0]\n", " mean_cntr, var_cntr, std_cntr = bayesest((quanta2.S_d-quanta2.S_b)/np.mean(pvadd2.S_d-pvadd2.S_b), alpha=0.95)\n", " meanv0_cntr, varv0_cntr, stdv0_cntr = bayesest(quanta2.S_b/np.mean(pvadd2.S_b), alpha=0.95)\n", " CV2darr1.append(var_cntr[0]/mean_cntr[0]**2)\n", " deltarr1.append(mean_cntr[0])\n", " sbarr1.append(meanv0_cntr[0])\n", " errv = (var_cntr[1][1]-var_cntr[0])/mean_cntr[0]**2+2*(mean_cntr[1][1]-mean_cntr[0])*var_cntr[0]/mean_cntr[0]**3\n", " errcv2darr1.append(errv)\n", " errdeltarr1.append(mean_cntr[1][1]-mean_cntr[0])\n", " errsbarr1.append(meanv0_cntr[1][1]-meanv0_cntr[0])\n", "\n", "data3 = pd.read_csv(\"./data/dataDSMsizer.csv\")\n", "data3 = data3[data3.time>5*doubling_time]\n", "\n", "quantnumber = 5\n", "pvadd2 = data3\n", "\n", "CV2darr2 = []\n", "deltarr2 = []\n", "sbarr2 = []\n", "\n", "errcv2darr2 = []\n", "errdeltarr2 = []\n", "errsbarr2 = []\n", "for i in range(quantnumber):\n", " lperv0 = np.percentile(pvadd2.S_b, i*100/quantnumber)\n", " hperv0 = np.percentile(pvadd2.S_b, (i+1)*100/quantnumber)\n", " quanta1 = pvadd2[pvadd2.S_b > lperv0]\n", " quanta2 = quanta1[quanta1.S_b < hperv0]\n", " mean_cntr, var_cntr, std_cntr = bayesest((quanta2.S_d-quanta2.S_b)/np.mean(pvadd2.S_d-pvadd2.S_b), alpha=0.95)\n", " meanv0_cntr, varv0_cntr, stdv0_cntr = bayesest(quanta2.S_b/np.mean(pvadd2.S_b), alpha=0.95)\n", " CV2darr2.append(var_cntr[0]/mean_cntr[0]**2)\n", " deltarr2.append(mean_cntr[0])\n", " sbarr2.append(meanv0_cntr[0])\n", " errv = (var_cntr[1][1]-var_cntr[0])/mean_cntr[0]**2+2*(mean_cntr[1][1]-mean_cntr[0])*var_cntr[0]/mean_cntr[0]**3\n", " errcv2darr2.append(errv)\n", " errdeltarr2.append(mean_cntr[1][1]-mean_cntr[0])\n", " errsbarr2.append(meanv0_cntr[1][1]-meanv0_cntr[0])\n", "\n", "data4 = pd.read_csv(\"./data/dataDSMtimer.csv\")\n", "data4 = data4[data4.time>5*doubling_time]\n", "\n", "quantnumber = 5\n", "pvadd2 = data4\n", "\n", "CV2darr3 = []\n", "deltarr3 = []\n", "sbarr3 = []\n", "\n", "errcv2darr3 = []\n", "errdeltarr3 = []\n", "errsbarr3 = []\n", "for i in range(quantnumber):\n", " lperv0 = np.percentile(pvadd2.S_b,i*100/quantnumber)\n", " hperv0 = np.percentile(pvadd2.S_b,(i+1)*100/quantnumber)\n", " quanta1 = pvadd2[pvadd2.S_b>lperv0]\n", " quanta2 = quanta1[quanta1.S_b1:\n", " td=reactimes[1]\n", " gr=grarr[0]\n", " s=sbarr[0]\n", "\n", " tr=(1/gr)*np.log(1-(gr/(s*kr))*np.log(np.random.rand()))\n", "\n", " nextt=np.min([tr,td])\n", " react=np.argmin([tr,td])\n", " t=0\n", " ndivs=0\n", " dataf.append([nstps,cell,t,p,s,p/s]) #data sampling\n", " while t<=tmax:\n", " tt=dt\n", " if nextt1:\n", " td=reactimes[1]\n", " gr=grarr[0]\n", " s=sbarr[0]\n", "\n", " tr=(1/gr)*np.log(1-(gr/(s*kr))*np.log(np.random.rand()))\n", "\n", " nextt=np.min([tr,td])\n", " react=np.argmin([tr,td])\n", " t=0\n", " ndivs=0\n", " dataf.append([cv2gr,cell,t,p,s,p/s]) #data sampling\n", " while t<=tmax:\n", " tt=dt\n", " if nextt1:\n", " td=reactimes[1]\n", " gr=grarr[0]\n", " s=sbarr[0]\n", "\n", " tr=(1/gr)*np.log(1-(gr/(s*kr))*np.log(np.random.rand()))\n", "\n", " nextt=np.min([tr,td])\n", " react=np.argmin([tr,td])\n", " t=0\n", " ndivs=0\n", " dataf.append([cv2div,cell,t,p,s,p/s]) #data sampling\n", " while t<=tmax:\n", " tt=dt\n", " if nextt