{ "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 aniso\n", "import numpy as np\n", "import common.lin as lin\n", "import matplotlib.ticker as ticker" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def mkViolinPlot(d, ax, ws=0.7):\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.005))\n", " sns.set_style(\"whitegrid\", {'grid.linestyle':'--'})\n", " cls = sns.color_palette()\n", " ax.set_xticks(xs)\n", " ax.set_xticklabels(xs_labs)\n", " violin_parts = ax.violinplot(ys, xs, showmeans=True, widths=ws)\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", " plt.xticks(rotation=90)\n", " " ] }, { "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})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "G = p.mkTGraphN()\n", "regs = seg.getCellRegions(dataDir=dataDir, fid='01', d=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gans = p.calcAnisotropies(regs, tss, linss)\n", "gans_pat = p.addCombPatterns(gans, tss)\n", "gans_state = p.getGAnisosPerPattern(G, gans_pat)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.rcParams.update({'font.size': 12})\n", "fig = plt.figure(figsize=(9, 4.5))\n", "ax = fig.add_subplot('111')\n", "\n", "ax.set_xlabel(\"cell state\")\n", "ax.set_ylabel(r'anisotropy rate ($h^{-1}$)')\n", "ax.yaxis.set_major_locator(ticker.MultipleLocator(0.05))\n", "\n", "mkViolinPlot(gans_state, ax)\n", "\n", "fout = \"pattern_anisotropy.png\"\n", "plt.savefig(fout, dpi=300, bbox_inches='tight')\n", "plt.show()" ] }, { "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": "markdown", "metadata": {}, "source": [ "## Per pattern on graph" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "G = p.mkTGraphN()\n", "p.addGAnisos(G, gans_pat)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.drawTGraph(G, p.ganiso)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Per gene" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gans_gene = p.getGAnisosPerGene(tss, gans)" ] }, { "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'anisotropy ($h^{-1}$)')\n", "ax.yaxis.set_major_locator(ticker.MultipleLocator(0.05))\n", "\n", "mkViolinPlot(gans_gene, ax)\n", "\n", "fout = \"gene_anisotropy.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": [ "gans_gene_time = p.getGAnisosPerGeneTime(tss, gans)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for t in sorted(gans_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'anisotropy ($h^{-1}$)')\n", " ax.set_ylim((0.0, 0.03))\n", " ax.yaxis.set_major_locator(ticker.MultipleLocator(0.05))\n", "\n", " mkViolinPlot(gans_gene_time[t], ax, ws=0.4)\n", "\n", " fout = \"gene_anisotropy_{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 }