{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import patternTransitions as p\n", "from itertools import repeat\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", "import common.seg as seg\n", "import _pickle as cPickle\n", "import common.lin as lin\n", "import aniso\n", "import numpy as np\n", "import matplotlib.ticker as ticker" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#load FM1 at specified timepoints\n", "tss, linss = lin.mkSeries1(d=\"../data/FM1/tv/\",\n", " dExprs=\"../data/geneExpression/\",\n", " linDataLoc=\"../data/FM1/tracking_data/\",\n", " ft=lambda t: t in {10, 40, 96, 120, 132})\n", "lin.filterL1_st(tss)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def mkViolinPlot(d, ax, ws=0.7, vert=False):\n", " xs_labs = sorted(d.keys())\n", " xs = range(len(xs_labs))\n", " ys = [d[x] for x in xs_labs]\n", " \n", " ax.yaxis.set_major_locator(ticker.MultipleLocator(0.05))\n", " sns.set_style(\"whitegrid\", {'grid.linestyle':'--'})\n", " ax.set_xticks(xs)\n", " ax.set_xticklabels(xs_labs)\n", " violin_parts = ax.violinplot(ys, xs, showmeans=True, widths=ws)\n", " \n", " for pc in violin_parts['bodies']:\n", " pc.set_facecolor(\"#f5d742\")\n", " pc.set_edgecolor('black')\n", "\n", " for partname in ('cbars','cmins','cmaxes','cmeans'):\n", " vp = violin_parts[partname]\n", " vp.set_edgecolor('red')\n", " vp.set_linewidth(0.5)\n", " \n", " if vert:\n", " plt.xticks(rotation=90)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import grates as grs\n", "\n", "G = p.mkTGraphN()\n", "grates = grs.grates_avg_cons(tss, linss)\n", "grates_pats = p.addCombPatterns(grates, tss)\n", "\n", "grs_state = p.getGAnisosPerPattern(G, grates_pats)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.rcParams.update({'font.size': 12})\n", "fig = plt.figure(figsize=(12, 5.5))\n", "ax = fig.add_subplot('111')\n", "\n", "ax.set_xlabel(\"cell state\")\n", "ax.set_ylabel(r'growth rate ($h^{-1}$)')\n", "ax.set_ylim((-0.05, 0.15))\n", "ax.yaxis.set_ticks(np.arange(-0.05, 0.15, 0.1))\n", "ax.yaxis.set_major_locator(ticker.MultipleLocator(0.1))\n", "\n", "mkViolinPlot(grs_state, ax)\n", "\n", "fout = \"state_growth_rates.png\"\n", "plt.savefig(fout, dpi=300, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per pattern on graph" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.addGRates(G, grates_pats) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.drawTGraph(G, p.gr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per gene" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import patternTransitions as p\n", "grates_gene = p.getGAnisosPerGene(tss, grates)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(10, 5))\n", "ax = fig.add_subplot('111')\n", "\n", "ax.set_xlabel(\"gene\")\n", "ax.set_ylabel(r'growth rate ($h^{-1}$)')\n", "ax.set_ylim((-0.1, 0.2))\n", "ax.yaxis.set_ticks(np.arange(-0.1, 0.2, 0.1))\n", "ax.yaxis.set_major_locator(ticker.MultipleLocator(0.1))\n", "\n", "mkViolinPlot(grates_gene, ax, vert=True)\n", "\n", "fout = \"gene_grates.png\"\n", "plt.savefig(fout, dpi=300, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per gene, per stage" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def tToStage(t):\n", " if t==10: return 0\n", " elif t==40: return 1\n", " elif t==96: return 2\n", " elif t==120: return 3\n", " elif t==132: return 4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "grates_gene_time = p.getGAnisosPerGeneTime(tss, grates)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for t in sorted(grates_gene_time.keys()):\n", " fig = plt.figure(figsize=(10, 5))\n", " ax = fig.add_subplot('111')\n", " \n", " ax.set_title(\"stage {t}\".format(t=tToStage(t)))\n", " ax.set_xlabel(\"gene\")\n", " ax.set_ylabel(r'growth rate ($h^{-1}$)')\n", " ax.set_ylim((-0.05, 0.15))\n", " ax.yaxis.set_major_locator(ticker.MultipleLocator(0.1))\n", "\n", " mkViolinPlot(grates_gene_time[t], ax, ws=0.4, vert=True)\n", "\n", " fout = \"gene_growth_{t}.png\".format(t=t)\n", " plt.savefig(fout, dpi=300, bbox_inches='tight')\n", " plt.show()" ] } ], "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }