ReactionNetworkImporters.jl
This package provides importers to load reaction networks from several file formats. Currently it supports loading networks in the following formats:
- A subset of the BioNetGen .net file format.
- Networks represented by dense or sparse substrate and product stoichiometric matrices.
- The basic format used by the RSSA group at COSBI in their model collection.
Imported networks are currently output as a DiffEqBiological, reaction_network
type.
Examples
Loading a BioNetGen .net file
A simple network from the builtin BioNetGen bngl examples is the repressilator. The generate_network
command in the bngl file outputs a reduced network description, i.e. a .net file, which can be loaded into a DiffEqBiological min_reaction_network
as:
using ReactionNetworkImporters
fname = "PATH/TO/Repressilator.net"
prnbng = loadrxnetwork(BNGNetwork(), "BNGRepressilator", fname)
Here BNGNetwork
is a type specifying the file format that is being loaded, and BNGRepressilator
specifies the type of the generated min_reaction_network
, see DiffEqBiological. prnbng
is a ParsedReactionNetwork
structure with the following fields:
rn
, a DiffEqBiologicalreaction_network
u₀
, the initial condition (as aVector{Float64}
)p
, the parameter vector (as aVector{Float64}
)paramexprs
, the parameter vector as a mix ofNumbers
,Symbols
andExprs
.p
is generated by evaluation of these expressions and symbols.symstonames
, aDict
mapping from the internalSymbol
of a species used in the generatedmin_reaction_network
to aSymbol
generated from the name in the .net file. This is necessary as BioNetGen can generate exceptionally long species names, involving characters that lead to malformed species names when used withDiffEqBiological
.groupstoids
, aDict
mapping theSymbols
(i.e. names) for any species groups defined in the .net file to a vector of indices intou₀
where the corresponding species are stored.
Given prnbng
, we can construct and solve the corresponding ODE model for the reaction system by
using OrdinaryDiffEq, DiffEqBiological
rn = prnbng.rn
addodes!(rn)
tf = 100000.0
oprob = ODEProblem(rn, prnbng.u₀, (0.,tf), prnbng.p)
sol = solve(oprob, Tsit5(), saveat=tf/1000.)
See the DiffEqBiological documentation for how to generate ODE, SDE, jump and other types of models.
Loading a matrix representation
DiffEqBiological reaction_networks
can also be constructed from substrate and product stoichiometric matrices. For example, here we both directly build a DiffEqBiological network using the @reaction_network
macro, and then show how to build the same network from stoichiometry matrices using ReactionNetworkImporters
:
# DiffEqBiological network from the macro:
rs = @reaction_network begin
k1, 2A --> B
k2, B --> 2A
k3, A + B --> C
k4, C --> A + B
k5, 3C --> 3A
end k1 k2 k3 k4 k5
# network from stoichiometry using ReactionNetworkImporters
species = [:A,:B,:C]
pars = [:k1, :k2, :k3, :k4, :k5]
substoich =[2 0 0;
0 1 0;
1 1 0;
0 0 1;
0 0 3]'
prodstoich = [0 1 0;
2 0 0;
0 0 1;
1 1 0;
3 0 0]'
prn = loadrxnetwork(MatrixNetwork(), "testnet2", pars, substoich, prodstoich;
species=species, params=pars)
# test the two networks are the same
@assert rs == prn.rn
The basic usage is
prn = loadrxnetwork(MatrixNetwork(), "networktypename",
rateexprs::Vector{Union{Expr,Symbol,Float64,Int}},
substoich::AbstractMatrix,
prodstoich::AbstractMatrix;
species=Symbol[],
params=Symbol[])
Here MatrixNetwork()
is the dispatch type, which selects that we are
constructing a matrix-based stoichiometric representation as input. The other
parameters are:
rateexprs
- Any DiffEqBiological valid expressions for the rates. This can be a hardcoded rate constant like1.0
, the symbol of a parameter like:k
, or an expression involving parameters and species like:(k*A)
. Note, the reactionA+B --> C
with rate:(k*B)
would have rate lawk*A*B^2
.substoich
- A number of species by number of reactions matrix with entry(i,j)
giving the stoichiometric coefficient of speciesi
as a substrate in reactionj
.prodstoich
- A number of species by number of reactions matrix with entry(i,j)
giving the stoichiometric coefficient of speciesi
as a product in reactionj
.species
- Optional symbols for each species in the network.parameters
- Symbols for each parameter in the network.
prn
is again a ParsedReactionNetwork
, with only the reaction_network
field, prn.rn
, defined.
A dispatch is added if substoich
and prodstoich
both have the type
SparseMatrixCSC
, in which case they are efficiently iterated through using the
SparseArrays
interface.
If the keyword argument species
is not set, the resulting reaction network
will simply name the species S1
, S2
,..., SN
for a system with N
total
species. params
defaults to an empty vector of Symbol
s, so that it does not
need to be set for systems with no parameters.
Loading a RSSA format network file
As the licensing is unclear we can not redistribute any example RSSA formatted networks. They can be downloaded from the model collection link listed above. Assuming you've saved both a reaction network file and corresponding initial condition file, they can be loaded as
initialconditionf = "PATH/TO/FILE"
networkf = "PATH/TO/FILE"
rssarn = loadrxnetwork(RSSANetwork(), "RSSARxSys", initialconditionf, networkf)
Here RSSANetwork
specifies the type of the file to parse, and RSSARxSys
gives the type of the generated reaction_network
. rssarn
is again a ParsedReactionNetwork
, but only the rn
and u₀
fields will now be relevant (the remaining fields will be set to nothing
).