Compositional Modeling of Reaction Systems

Catalyst supports the construction of models in a compositional fashion, based on ModelingToolkit's subsystem functionality. In this tutorial we'll see how we can construct the earlier repressilator model by composing together three identically repressed genes, and how to use compositional modeling to create compartments.

Compositional modeling tooling

Catalyst supports two ModelingToolkit interfaces for composing multiple ReactionSystems together into a full model. The first mechanism for extending a system is the extend command

using Catalyst
basern = @reaction_network rn1 begin
  k, A + B --> C
newrn = @reaction_network rn2 begin
  r, C --> A + B
@named rn = extend(newrn, basern)

\[ \begin{align*} \mathrm{A} + \mathrm{B} &\xrightleftharpoons[r]{k} \mathrm{C} \end{align*} \]

Here we extended basern with newrn giving a system with all the reactions. Note, if a name is not specified via @named or the name keyword then rn will have the same name as newrn.

The second main compositional modeling tool is the use of subsystems. Suppose we now add to basern two subsystems, newrn and newestrn, we get a different result:

newestrn = @reaction_network rn3 begin
            v, A + D --> 2D
@named rn = compose(basern, [newrn, newestrn])

\[ \begin{align*} \mathrm{A} + \mathrm{B} &\xrightarrow{k} \mathrm{C} \\ \mathrm{rn2_{+}C} &\xrightarrow{rn2_{+}r} \mathrm{rn2_{+}A} + \mathrm{rn2_{+}B} \\ \mathrm{rn3_{+}A} + \mathrm{rn3_{+}D} &\xrightarrow{rn3_{+}v} 2 \mathrm{rn3_{+}D} \end{align*} \]

Here we have created a new ReactionSystem that adds newrn and newestrn as subsystems of basern. The variables and parameters in the sub-systems are considered distinct from those in other systems, and so are namespaced (i.e. prefaced) by the name of the system they come from.

We can see the subsystems of a given system by

2-element Vector{Any}:
 ReactionSystem{Catalyst.NetworkProperties{Int64, SymbolicUtils.BasicSymbolic{Real}}}(Union{Equation, Reaction}[r, C --> A + B], Reaction[r, C --> A + B], t, SymbolicUtils.BasicSymbolic{Real}[], SymbolicUtils.BasicSymbolic{Real}[C(t), A(t), B(t)], SymbolicUtils.BasicSymbolic{Real}[C(t), A(t), B(t)], SymbolicUtils.BasicSymbolic{Real}[r], Dict{Symbol, Any}(:A => A(t), :B => B(t), :r => r, :C => C(t)), Equation[], :rn2, Any[], Dict{Any, Any}(), nothing, Conserved Equations: 
, true, ModelingToolkit.SymbolicContinuousCallback[ModelingToolkit.SymbolicContinuousCallback(Equation[], Equation[])], ModelingToolkit.SymbolicDiscreteCallback[], false)
 ReactionSystem{Catalyst.NetworkProperties{Int64, SymbolicUtils.BasicSymbolic{Real}}}(Union{Equation, Reaction}[v, A + D --> 2*D], Reaction[v, A + D --> 2*D], t, SymbolicUtils.BasicSymbolic{Real}[], SymbolicUtils.BasicSymbolic{Real}[A(t), D(t)], SymbolicUtils.BasicSymbolic{Real}[A(t), D(t)], SymbolicUtils.BasicSymbolic{Real}[v], Dict{Symbol, Any}(:A => A(t), :D => D(t), :v => v), Equation[], :rn3, Any[], Dict{Any, Any}(), nothing, Conserved Equations: 
, true, ModelingToolkit.SymbolicContinuousCallback[ModelingToolkit.SymbolicContinuousCallback(Equation[], Equation[])], ModelingToolkit.SymbolicDiscreteCallback[], false)

They naturally form a tree-like structure

using Plots, GraphRecipes
plot(TreePlot(rn), method=:tree, fontsize=12, nodeshape=:ellipse)

rn network with subsystems

We could also have directly constructed rn using the same reaction as in basern as

@parameters k
@variables t
@species A(t), B(t), C(t)
rxs = [Reaction(k, [A,B], [C])]
@named rn = ReactionSystem(rxs, t; systems = [newrn, newestrn])

\[ \begin{align*} \mathrm{A} + \mathrm{B} &\xrightarrow{k} \mathrm{C} \\ \mathrm{rn2_{+}C} &\xrightarrow{rn2_{+}r} \mathrm{rn2_{+}A} + \mathrm{rn2_{+}B} \\ \mathrm{rn3_{+}A} + \mathrm{rn3_{+}D} &\xrightarrow{rn3_{+}v} 2 \mathrm{rn3_{+}D} \end{align*} \]

Catalyst provides several different accessors for getting information from a single system, or all systems in the tree. To get the species, parameters, and reactions only within a given system (i.e. ignoring subsystems), we can use

3-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
1-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
1-element Vector{Reaction}:
 k, A + B --> C

To see all the species, parameters and reactions in the tree we can use

species(rn)   # or states(rn)
8-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
parameters(rn)  # or reactionparameters(rn)
3-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
reactions(rn)   # or equations(rn)
3-element Vector{Reaction}:
 k, A + B --> C
 rn2₊r, rn2₊C --> rn2₊A + rn2₊B
 rn3₊v, rn3₊A + rn3₊D --> 2*rn3₊D

If we want to collapse rn down to a single system with no subsystems we can use

flatrn = Catalyst.flatten(rn)

\[ \begin{align*} \mathrm{A} + \mathrm{B} &\xrightarrow{k} \mathrm{C} \\ \mathrm{rn2_{+}C} &\xrightarrow{rn2_{+}r} \mathrm{rn2_{+}A} + \mathrm{rn2_{+}B} \\ \mathrm{rn3_{+}A} + \mathrm{rn3_{+}D} &\xrightarrow{rn3_{+}v} 2 \mathrm{rn3_{+}D} \end{align*} \]



More about ModelingToolkit's interface for compositional modeling can be found in the ModelingToolkit docs.

Compositional model of the repressilator

Let's apply the tooling we've just seen to create the repressilator in a more modular fashion. We start by defining a function that creates a negatively repressed gene, taking the repressor as input

function repressed_gene(; R, name)
  @reaction_network $name begin
    hillr($R,α,K,n), ∅ --> m
    (δ,γ), m <--> ∅
    β, m --> m + P
    μ, P --> ∅

Here we assume the user will pass in the repressor species as a ModelingToolkit variable, and specify a name for the network. We use Catalyst's interpolation ability to substitute the value of these variables into the DSL (see Interpolation of Julia Variables). To make the repressilator we now make three genes, and then compose them together

@variables t
@species G3₊P(t)
@named G1 = repressed_gene(; R=ParentScope(G3₊P))
@named G2 = repressed_gene(; R=ParentScope(G1.P))
@named G3 = repressed_gene(; R=ParentScope(G2.P))
@named repressilator = ReactionSystem(t; systems=[G1,G2,G3])

\[ \begin{align*} \varnothing &\xrightleftharpoons[G1_+\delta]{\frac{G1_+\alpha G1_{+}K^{G1_{+}n}}{G1_{+}K^{G1_{+}n} + G3_{+}P^{G1_{+}n}}} \mathrm{G1_{+}m} \\ \varnothing &\xrightarrow{G1_+\gamma} \mathrm{G1_{+}m} \\ \mathrm{G1_{+}m} &\xrightarrow{G1_+\beta} \mathrm{G1_{+}m} + \mathrm{G1_{+}P} \\ \mathrm{G1_{+}P} &\xrightarrow{G1_+\mu} \varnothing \\ \varnothing &\xrightleftharpoons[G2_+\delta]{\frac{G2_+\alpha G2_{+}K^{G2_{+}n}}{G2_{+}K^{G2_{+}n} + G1_{+}P^{G2_{+}n}}} \mathrm{G2_{+}m} \\ \varnothing &\xrightarrow{G2_+\gamma} \mathrm{G2_{+}m} \\ \mathrm{G2_{+}m} &\xrightarrow{G2_+\beta} \mathrm{G2_{+}m} + \mathrm{G2_{+}P} \\ \mathrm{G2_{+}P} &\xrightarrow{G2_+\mu} \varnothing \\ \varnothing &\xrightleftharpoons[G3_+\delta]{\frac{G3_+\alpha G3_{+}K^{G3_{+}n}}{G3_{+}K^{G3_{+}n} + G2_{+}P^{G3_{+}n}}} \mathrm{G3_{+}m} \\ \varnothing &\xrightarrow{G3_+\gamma} \mathrm{G3_{+}m} \\ \mathrm{G3_{+}m} &\xrightarrow{G3_+\beta} \mathrm{G3_{+}m} + \mathrm{G3_{+}P} \\ \mathrm{G3_{+}P} &\xrightarrow{G3_+\mu} \varnothing \end{align*} \]

Notice, in this system each gene is a child node in the system graph of the repressilator

plot(TreePlot(repressilator), method=:tree, fontsize=12, nodeshape=:ellipse)

repressilator tree plot

In building the repressilator we needed to use two new features. First, we needed to create a symbolic variable that corresponds to the protein produced by the third gene before we created the corresponding system. We did this via @variables t, G3₊P(t). We also needed to set the scope where each repressor lived. Here ParentScope(G3₊P), ParentScope(G1.P), and ParentScope(G2.P) signal Catalyst that these variables will come from parallel systems in the tree that have the same parent as the system being constructed (in this case the top-level repressilator system).

Compartment-based models

Finally, let's see how we can make a compartment-based model. Let's create a simple eukaryotic gene expression model with negative feedback by protein dimers. Transcription and gene inhibition by the protein dimer occurs in the nucleus, translation and dimerization occur in the cytosol, and nuclear import and export reactions couple the two compartments. We'll include volume parameters for the nucleus and cytosol, and assume we are working with species having units of number of molecules. Rate constants will have their common concentration units, i.e. if $V$ denotes the volume of a compartment then

Reaction TypeExampleRate Constant UnitsEffective rate constant (units of per time)
Zero order$\varnothing \overset{\alpha}{\to} A$concentration / time$\alpha V$
First order$A \overset{\beta}{\to} B$(time)⁻¹$\beta$
Second order$A + B \overset{\gamma}{\to} C$(concentration × time)⁻¹$\gamma/V$

In our model we'll therefore add the conversions of the last column to properly account for compartment volumes:

# transcription and regulation
nuc = @reaction_network nuc begin
  α, G --> G + M
  (κ₊/V,κ₋), D + G <--> DG

# translation and dimerization
cyto = @reaction_network cyto begin
  β, M --> M + P
  (k₊/V,k₋), 2P <--> D
  σ, P --> 0
  μ, M --> 0

# export reactions,
# γ,δ=probability per time to be exported/imported
model = @reaction_network model begin
  γ, $(nuc.M) --> $(cyto.M)
  δ, $(cyto.D) --> $(nuc.D)
@named model = compose(model, [nuc, cyto])

\[ \begin{align*} \mathrm{nuc_{+}M} &\xrightarrow{\gamma} \mathrm{cyto_{+}M} \\ \mathrm{cyto_{+}D} &\xrightarrow{\delta} \mathrm{nuc_{+}D} \\ \mathrm{nuc_{+}G} &\xrightarrow{nuc_+\alpha} \mathrm{nuc_{+}G} + \mathrm{nuc_{+}M} \\ \mathrm{nuc_{+}D} + \mathrm{nuc_{+}G} &\xrightleftharpoons[nuc_+\kappa_-]{\frac{nuc_+\kappa_+}{nuc_{+}V}} \mathrm{nuc_{+}DG} \\ \mathrm{cyto_{+}M} &\xrightarrow{cyto_+\beta} \mathrm{cyto_{+}M} + \mathrm{cyto_{+}P} \\ 2 \mathrm{cyto_{+}P} &\xrightleftharpoons[cyto_{+}k_-]{\frac{cyto_{+}k_+}{cyto_{+}V}} \mathrm{cyto_{+}D} \\ \mathrm{cyto_{+}P} &\xrightarrow{cyto_+\sigma} \varnothing \\ \mathrm{cyto_{+}M} &\xrightarrow{cyto_+\mu} \varnothing \end{align*} \]

A graph of the resulting network is


graph of gene regulation model