DSGRN Python Interface Tutorial

This notebook shows the basics of manipulating DSGRN with the python interface.


In [1]:
import DSGRN

Network

The starting point of the DSGRN analysis is a network specification. We write each node name, a colon, and then a formula specifying how it reacts to its inputs.


In [2]:
network = DSGRN.Network("""
X1 : (X1+X2)(~X3)
X2 : (X1)
X3 : (X1)(~X2)""")

In [3]:
DSGRN.DrawGraph(network)


Out[3]:
%3 X1 X1 X1->X1 X2 X2 X1->X2 X3 X3 X1->X3 X2->X1 X2->X3 X3->X1

ParameterGraph

Given a network, there is an associated "Parameter Graph", which is a combinatorial representation of parameter space.


In [4]:
parametergraph = DSGRN.ParameterGraph(network)

In [5]:
print("There are " + str(parametergraph.size()) + " nodes in the parameter graph.")


There are 326592 nodes in the parameter graph.

Parameter

The ParameterGraph class may be regarded as a factory which produces parameter nodes. In the DSGRN code, parameter nodes are referred to simply as "parameters" and are represented as "Parameter" objects.


In [6]:
parameterindex = 34892  # An arbitrarily selected integer in [0,326592)

In [7]:
parameter = parametergraph.parameter(parameterindex)

In [8]:
print(parameter)


[["X1",[3,3,"6D9000"],[0,2,1]],["X2",[1,2,"D"],[0,1]],["X3",[2,1,"8"],[0]]]

DomainGraph

Let's compute the dynamics corresponding to this parameter node. In particular, we can instruct DSGRN to create a "domaingraph" object.


In [9]:
domaingraph = DSGRN.DomainGraph(parameter)

In [10]:
DSGRN.DrawGraph(domaingraph)


Out[10]:
%3 0 0 4 4 0->4 1 1 1->0 5 5 1->5 2 2 2->1 6 6 2->6 14 14 2->14 3 3 3->2 7 7 3->7 15 15 3->15 4->5 5->6 18 18 6->18 7->6 11 11 7->11 19 19 7->19 8 8 8->4 9 9 8->9 9->5 10 10 9->10 10->6 11->10 12 12 12->0 16 16 12->16 13 13 13->1 13->12 17 17 13->17 14->13 14->18 15->14 15->19 16->4 16->17 17->5 17->18 18->18 19->18 23 23 19->23 20 20 20->8 20->16 21 21 20->21 21->9 21->17 22 22 21->22 22->10 22->18 23->11 23->22

In [11]:
print(domaingraph.coordinates(5)) # ... I wonder what region in phase space domain 5 corresponds to.


[1, 1, 0]

MorseDecomposition

Let's compute the partially ordered set of recurrent components (strongly connected components with an edge) of the domain graph.


In [12]:
morsedecomposition = DSGRN.MorseDecomposition(domaingraph.digraph())

In [13]:
DSGRN.DrawGraph(morsedecomposition)


Out[13]:
%3 0 18

MorseGraph

The final step in our analysis is the production of an annotated Morse graph.


In [14]:
morsegraph = DSGRN.MorseGraph(domaingraph, morsedecomposition)

In [15]:
DSGRN.DrawGraph(morsegraph)


Out[15]:
%3 0 FP { 2, 1, 1 }

Drawing Tables


In [16]:
from DSGRN import *
pg = ParameterGraph(Network("X : ~Y\nY : ~X\n"))

In [17]:
Table(["Parameter Index", "Morse Graph"], 
      [ [ i, DrawGraph(MorseGraph(DomainGraph(pg.parameter(i))))] for i in range(0,pg.size())])


Out[17]:
Parameter Index
Morse Graph
0
%3 0 FP { 0, 0 }
1
%3 0 FP { 1, 0 }
2
%3 0 FP { 1, 0 }
3
%3 0 FP { 0, 1 }
4
%3 0 FP { 0, 1 } 1 FP { 1, 0 }
5
%3 0 FP { 1, 0 }
6
%3 0 FP { 0, 1 }
7
%3 0 FP { 0, 1 }
8
%3 0 FP { 1, 1 }

ParameterSampler

We can sample real-valued parameter values from combinatorial parameter regions using the ParameterSampler class. This class provides a method sample which takes an integer parameter index and returns a string describing a randomly sampled instance within the associated parameter region.


In [18]:
sampler = DSGRN.ParameterSampler(parametergraph)
sampler.sample(parameterindex)


Out[18]:
'{"ParameterIndex":34892,"Parameter":{"L[X1, X1]" : 0.26189317114915911, "L[X1, X2]" : 0.047527672343930391, "L[X1, X3]" : 0.21385722418770212, "L[X2, X1]" : 0.0083569702162772409, "L[X2, X3]" : 0.13477572472965574, "L[X3, X1]" : 0.81414161582444289, "T[X1, X1]" : 0.42280525715172884, "T[X1, X2]" : 1.6293141045393824, "T[X1, X3]" : 1.0824055111883504, "T[X2, X1]" : 0.018249770181381512, "T[X2, X3]" : 0.16314316602148091, "T[X3, X1]" : 1.5770292044658094, "U[X1, X1]" : 0.36915443410830018, "U[X1, X2]" : 1.6814679188873936, "U[X1, X3]" : 1.6853427566781969, "U[X2, X1]" : 0.97980155236308419, "U[X2, X3]" : 1.6038764331358468, "U[X3, X1]" : 0.90367375128805294}}'

In [ ]: