Friday, October 20, 2017

Plotting Bar graph of Species Concentrations in Tellurium

Originally Posted on  by hsauro

I had a model with 27 floating species and I wanted to plot the steady-state concentrations on a histogram where the labels were the names of the different species. Here is a general purpose script that will do that:

The function has a default width and height for the resulting plot. The default widens the usual size so that the labels don’t collide. The first argument is the libroadrunner instance.  To given a contrived example, the following is a model of 8 floating species that form a linear chain governed by simple irreversible mass-action kinetics.

The resulting plot is shown below:

Plotting Bar graph of Species Concentrations in Tellurium

October 20, 2017 10:31 am 

I had a model with 27 floating species and I wanted to plot the steady-state concentrations on a histogram where the labels were the names of the different species. Here is a general-purpose script that will do that:

def plotFloatingSpecies (r, width=12, height=6):
    import matplotlib.pyplot as plt
    xlabels = r.getFloatingSpeciesIds()
    concs = r.getFloatingSpeciesConcentrations()
    plt.figure(figsize=(width,height))
    plt.bar(xlabels, concs, label=xlabels)
    plt.xticks(range (len (xlabels)), xlabels, ha='right', rotation=45)

The function has a default width and height for the resulting plot. The default widens the usual size so that the labels don't collide. The first argument is the libroadrunner instance.  To give a contrived example, the following is a model of 8 floating species that form a linear chain governed by simple irreversible mass-action kinetics.

import tellurium as te
import roadrunner

def plotFloatingSpecies (r, width=12, height=6):
    import matplotlib.pyplot as plt
    xlabels = r.getFloatingSpeciesIds()
    concs = r.getFloatingSpeciesConcentrations()
    plt.figure(figsize=(width,height))    
    plt.bar(xlabels, concs, label=xlabels)
    plt.xticks(range (len (xlabels)), xlabels,  ha='right', rotation=45)    

r = te.loada("""
     $Xo -> S1; k1*Xo;
      S1 -> S2;  k2*S1;
      S2 -> S3;  k3*S2;
      S3 -> S4;  k3*S3;
      S4 -> S5;  k4*S4;
      S5 -> S6;  k5*S5;
      S6 -> S7;  k4*S6;
      S7 -> S8;  k3*S7;
      S8 -> ;    k4*S8;
      
      k1 = 0.3; k2 = 0.5; k3 = 0.27; k4 = 0.9; k5 = 0.14
      Xo = 10;
""")

r.steadyState()
plotFloatingSpecies (r, width=6, height=3)

The resulting plot is shown below:



 

Thursday, October 5, 2017

Multilayered Cascade using TikZ

 Originally Posted on  by hsauro

A summer student working in my lab, Ming Hong Lui from Hong Kong University (HKUST), worked on the perturbation analysis of signaling cascades and in his writeup he use TikZ to draw a nice cascade diagram which I present here.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[>=latex',node distance = 2cm]
\node (S1) {$S_1$};
\node [right of = S1] (S2) {$S_2$};
\node [right of = S1, node distance = 1.8cm] (X1) {};
\node [below of = X1] (S3) {$S_3$};
\node [right of = S3] (S4) {$S_4$};
\draw [->,very thick] (S1) to [bend left=40] node[above] {$v_1$} (S2);
\draw [->,very thick] (S2) to [bend left=40] node[below] {$v_2$} (S1);
\draw [->,very thick] (S3) to [bend left=40] node[above] {$v_3$} (S4);
\draw [->,very thick] (S4) to [bend left=40] node[below] {$v_4$} (S3);
\node [right of= S3, node distance = 1cm] (X2){};
\node [above of= X2, node distance = 1cm] (X3){};
\draw [->,very thick] (S2) to [bend left=20] (X3);
\node [right of= S4, node distance = 0.8cm] (X4){};
\node [below of= X4, node distance = 1cm] (X5){};
\draw [->,very thick] (S4) to [bend left=20] (X5);
\node [right of = S3, node distance = 1.8cm] (X3_5) {};
\node [below of = X3_5] (S5) {$S_5$};
\node [right of = S5] (S6) {$S_6$};
\node [right of = S5, node distance = 1.8cm] (X5) {};
\node [below of = X5] (S7) {$S_{2n-1}$};
\node [right of = S7] (S8) {$S_{2n}$};
\draw [->,very thick] (S5) to [bend left=40] node[above] {$v_5$} (S6);
\draw [->,very thick] (S6) to [bend left=40] node[below] {$v_6$} (S5);
\draw [->,very thick] (S7) to [bend left=40] node[above] {$v_{2n-1}$} (S8);
\draw [->,very thick] (S8) to [bend left=40] node[below] {$v_{2n}$} (S7);
\node [right of= S7, node distance = 1cm] (X6){};
\node [above of= X6, node distance = 1cm] (X7){};
%\node at ($(S6)!.5!(X7)$) {$\ddots$};
\draw [dashed, ->,very thick] (S6) to [bend left=20] (X7);
\node [right of = S1, node distance = 1cm] (T1) {$T_1, J_1$};
\node [right of = S3, node distance = 1cm] (T2) {$T_2, J_2$};
\node [right of = S5, node distance = 1cm] (T3) {$T_3, J_3$};
\node [right of = S7, node distance = 1cm] (T4) {$T_n, J_n$};
\end{tikzpicture}

\end{document}

This code draws the following figure: