Skip to content

Commit

Permalink
New Tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
rionbr committed Feb 19, 2018
1 parent 8eb28f1 commit 731dd81
Show file tree
Hide file tree
Showing 5 changed files with 1,707 additions and 480 deletions.
272 changes: 272 additions & 0 deletions tutorials/Tutorial - Canalization - BioModels - LUT.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Tutorial - Plotting LUT\n",
"This tutorial shows how to plot Prime Implicants (F') and Two-Symbol (F'') schematas"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import os\n",
"import numpy as np\n",
"import matplotlib as mpl\n",
"import matplotlib.style\n",
"mpl.style.use('classic')\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.text import Text\n",
"from matplotlib.patches import Circle, Rectangle, RegularPolygon\n",
"from matplotlib.collections import PatchCollection\n",
"from copy import copy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from cana.datasets.bio import THALIANA, DROSOPHILA, BUDDING_YEAST"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<BNetwork(Name='Arabidopsis Thaliana', N=15, Nodes=['AP3', 'UFO', 'FUL', 'FT', 'AP1', 'EMF1', 'LFY', 'AP2', 'WUS', 'AG', 'LUG', 'CLF', 'TFL1', 'PI', 'SEP'])>\n"
]
}
],
"source": [
"N = THALIANA()\n",
"#N = DROSOPHILA()\n",
"#N = BUDDING_YEAST()\n",
"print N"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"if N.name == 'Arabidopsis Thaliana':\n",
" foldername = 'thaliana'\n",
"elif N.name == 'Drosophila Melanogaster':\n",
" foldername = 'drosophila'\n",
"elif N.name == 'Budding Yeast Cell Cycle':\n",
" foldername = 'yeast'"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"def plot_look_up_table(nid, n):\n",
" # Init values from BooleanNode\n",
" k = n.k if n.k>=1 else 1\n",
" inputs = n.inputs if not n.constant else [n.name]\n",
" LUT = n.look_up_table().sort_index(ascending=False)\n",
" # Count number of F in the LUT\n",
" n_fs = LUT.shape[0]\n",
" # Schemata Cell Width and spacing\n",
" cwidth = 60.\n",
" cxspace = 0\n",
" cyspace = 6\n",
" border = 1\n",
" sepcxspace = 21\n",
" sepcyspace = 15\n",
" dpi = 150.\n",
" # Margins\n",
" top, right, bottom, left, hs = 120, 25, 25, 60, 25\n",
" # Axes Width & Height\n",
" ax1width = ((k*(cwidth+cxspace))+sepcxspace+(cwidth))\n",
" ax1height = (n_fs*(cwidth+cyspace)-cyspace)\n",
" # Figure Width & Height\n",
" fwidth = (left + ax1width + hs + right)\n",
" fheight = (bottom + ax1height + top)\n",
" # Percentages for Axes location\n",
" _ax1w = ((ax1width*100) / fwidth) / 100\n",
" _ax1h = ((ax1height*100) / fheight) / 100\n",
" _bottom = ((bottom*100) / fheight) / 100\n",
" _left = ((left*100) / fwidth) / 100\n",
" _hs = ((hs*100) / fwidth) / 100\n",
" # Init Figure\n",
" fig = plt.figure(figsize=(fwidth/dpi,fheight/dpi), dpi=dpi)\n",
" ax1 = fig.add_axes((_left,_bottom,_ax1w,_ax1h), aspect=1, label='LUT')\n",
"\n",
" ### LUT Plot ###\n",
"\n",
" yticks = []\n",
" patches = []\n",
" x,y = 0.,0.\n",
" #\n",
" for i,r in LUT.iterrows():\n",
" ins = str(r['In:'])\n",
" out = r['Out:']\n",
" x = 0.\n",
" xticks = []\n",
" for input in ins:\n",
" if input == '0':\n",
" facecolor = 'white'\n",
" textcolor = 'black'\n",
" elif input == '1':\n",
" facecolor = 'black'\n",
" textcolor = 'white' \n",
" text = '%s'%(input)\n",
" ax1.add_artist(Text(x+cwidth/2,y+cwidth/10*4, text=text, color=textcolor, va='center', ha='center',fontsize=14,family='serif'))\n",
" r = Rectangle((x,y), width=cwidth, height=cwidth, facecolor=facecolor, edgecolor='black')\n",
" patches.append(r)\n",
" xticks.append(x+cwidth/2)\n",
" x += cwidth + cxspace\n",
"\n",
" x += sepcxspace\n",
" r = Rectangle((x,y), width=cwidth, height=cwidth, facecolor='black' if (out==1) else 'white', edgecolor='black')\n",
" ax1.add_artist(Text(x-(sepcxspace/2)-(cxspace/2),y+cwidth/10*4, text=':', color='black', va='center', ha='center',fontsize=14,weight='bold',family='serif'))\n",
" ax1.add_artist(Text(x+(cwidth/2),y+cwidth/10*4, text=out, color='white' if (out==1) else 'black', va='center', ha='center',fontsize=14,family='serif'))\n",
" patches.append(r)\n",
" xticks.append(x+cwidth/2)\n",
" yticks.append(y+cwidth/2)\n",
" y += cwidth + cyspace\n",
"\n",
" #y += sepcyspace\n",
"\n",
" ax1.add_collection(PatchCollection(patches,match_original=True))\n",
" #\n",
" ax1.set_yticks(yticks)\n",
" ax1.set_yticklabels([r\"$f_{%d}$\"%(i+1) for i in range(n_fs)[::-1]], fontsize=14)\n",
" ax1.set_xticks(xticks)\n",
" ax1.set_xticklabels(inputs + ['%s'%(n.name)], rotation=90, fontsize=14)\n",
" #\n",
" ax1.xaxis.tick_top()\n",
" # Remove Tick\n",
" ax1.tick_params(which='major',pad=7)\n",
" for tic in ax1.xaxis.get_major_ticks():\n",
" tic.tick1On = tic.tick2On = False\n",
" for tic in ax1.yaxis.get_major_ticks():\n",
" tic.tick1On = tic.tick2On = False\n",
" # Remove Border\n",
" ax1.spines['top'].set_visible(False)\n",
" ax1.spines['right'].set_visible(False)\n",
" ax1.spines['bottom'].set_visible(False)\n",
" ax1.spines['left'].set_visible(False)\n",
" # Limits\n",
" ax1.set_xlim(-border,ax1width+border)\n",
" ax1.set_ylim(-border,ax1height+border)\n",
" #ax1.invert_yaxis() \n",
"\n",
" # FileName\n",
" filename = n.name\n",
" filename = filename.replace('/','_')\n",
" filename = filename.replace(',','_')\n",
" ### SAVE to FILE ###\n",
" plt.savefig('%s/../experiments/2017 - BioModels/%s/LUT/%s-%s' % (os.getcwd(), foldername, nid, filename), dpi=dpi)\n",
" plt.close()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Plotting: 0 - CellSize\n",
"Plotting: 1 - Cln3\n",
"Plotting: 2 - SBF\n",
"Plotting: 3 - MBF\n",
"Plotting: 4 - Cln1,2\n",
"Plotting: 5 - Sic1\n",
"Plotting: 6 - Clb5,6\n",
"Plotting: 7 - Cdh1\n",
"Plotting: 8 - Clb1,2\n",
"Plotting: 9 - Mcm1/SFF\n",
"Plotting: 10 - Cdc20/14\n",
"Plotting: 11 - Swi5\n"
]
}
],
"source": [
"for nid,n in enumerate(N.nodes):\n",
" print 'Plotting: %s - %s' % (nid,n.name)\n",
" # Plot\n",
" plot_look_up_table(nid,n)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nid = 12\n",
"n = N.nodes[nid]\n",
"plot_look_up_table(nid,n)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
12 changes: 4 additions & 8 deletions tutorials/Tutorial - Canalization - BioModels - Schematas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -271,8 +271,7 @@
" ax2.set_ylim(-border,ax2height+border)\n",
"\n",
" # FileName\n",
" filename = n.name\n",
" filename = filename.replace('/','_')\n",
" filename = n.name.replace('/','_')\n",
" filename = filename.replace(',','_')\n",
" ### SAVE to FILE ###\n",
" plt.savefig('%s/../experiments/2017 - BioModels/%s/schematas/%s-%s' % (os.getcwd(), foldername, nid, filename), dpi=dpi)\n",
Expand All @@ -281,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
Expand All @@ -299,10 +298,7 @@
"Plotting: 5 - Sic1\n",
"Plotting: 6 - Clb5,6\n",
"Plotting: 7 - Cdh1\n",
"Plotting: 8 - Clb1,2\n",
"Plotting: 9 - Mcm1/SFF\n",
"Plotting: 10 - Cdc20/14\n",
"Plotting: 11 - Swi5\n"
"Plotting: 8 - Clb1,2"
]
}
],
Expand Down
Loading

0 comments on commit 731dd81

Please sign in to comment.