Code Monkey home page Code Monkey logo

reactionnetworkimporters.jl's Introduction

ReactionNetworkImporters.jl

Join the chat at https://julialang.zulipchat.com #sciml-bridged Global Docs

codecov Build Status

ColPrac: Contributor's Guide on Collaborative Practices for Community Packages SciML Code Style

This package provides importers to load reaction networks into Catalyst.jl ReactionSystems from several file formats. Currently it supports loading networks in the following formats:

  1. A subset of the BioNetGen .net file format.
  2. Networks represented by dense or sparse substrate and product stoichiometric matrices.
  3. Networks represented by dense or sparse complex stoichiometric and incidence matrices.

SBMLToolkit.jl provides an alternative for loading SBML files into Catalyst models, offering a much broader set of supported features. It allows the import of models that include features such as constant species, boundary condition species, events, constraint equations and more. SBML files can be generated from many standard modeling tools, including BioNetGen, COPASI, and Virtual Cell.

For information on using the package, see the stable documentation. Use the in-development documentation for the version of the documentation which contains the unreleased features.

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 Catalyst ReactionSystem as:

using ReactionNetworkImporters
fname = "PATH/TO/Repressilator.net"
prnbng = loadrxnetwork(BNGNetwork(), fname)

Here BNGNetwork is a type specifying the file format that is being loaded. prnbng is a ParsedReactionNetwork structure with the following fields:

  • rn, a Catalyst ReactionSystem
  • u0, a Dict mapping initial condition symbolic variables to numeric values and/or symbolic expressions.
  • p, a Dict mapping parameter symbolic variables to numeric values and/or symbolic expressions.
  • varstonames, a Dict mapping the internal symbolic variable of a species used in the generated ReactionSystem to a String 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 with Catalyst.
  • groupstosyms, a Dict mapping the Strings representing names for any groups defined in the BioNetGen file to the corresponding symbolic variable representing the ModelingToolkit symbolic observable associated with the group.

Given prnbng, we can construct and solve the corresponding ODE model for the reaction system by

using OrdinaryDiffEq, Catalyst
rn = prnbng.rn
tf = 100000.0
oprob = ODEProblem(rn, Float64[], (0.0, tf), Float64[])
sol = solve(oprob, Tsit5(), saveat = tf / 1000.0)

Note that we specify empty parameter and initial condition vectors as these are already stored in the generated ReactionSystem, rn. A Dict mapping each symbolic species and parameter to its initial value or symbolic expression can be obtained using ModelingToolkit.defaults(rn).

See the Catalyst documentation for how to generate ODE, SDE, jump and other types of models.

Loading a matrix representation

Catalyst ReactionSystems can also be constructed from

  • substrate and product stoichiometric matrices.
  • complex stoichiometric and incidence matrices.

For example, here we both directly build a Catalyst network using the @reaction_network macro, and then show how to build the same network from these matrices using ReactionNetworkImporters:

# Catalyst network from the macro:
rs = @reaction_network testnetwork begin
    k1, 2A --> B
    k2, B --> 2A
    k3, A + B --> C
    k4, C --> A + B
    k5, 3C --> 3A
end

# network from basic stoichiometry using ReactionNetworkImporters
@parameters k1 k2 k3 k4 k5
@variables t
@species A(t) B(t) C(t)
species = [A, B, C]
pars = [k1, k2, k3, k4, k5]
substoich = [2 0 1 0 0;
             0 1 1 0 0;
             0 0 0 1 3]
prodstoich = [0 2 0 1 3;
              1 0 0 1 0;
              0 0 1 0 0]
mn = MatrixNetwork(pars, substoich, prodstoich; species = species,
                   params = pars) # a matrix network
prn = loadrxnetwork(mn; name = :testnetwork) # dense version

# test the two networks are the same
@assert rs == prn.rn

# network from reaction complex stoichiometry
stoichmat = [2 0 1 0 0 3;
             0 1 1 0 0 0;
             0 0 0 1 3 0]
incidencemat = [-1 1 0 0 0;
                1 -1 0 0 0;
                0 0 -1 1 0;
                0 0 1 -1 0;
                0 0 0 0 -1;
                0 0 0 0 1]
cmn = ComplexMatrixNetwork(pars, stoichmat, incidencemat; species = species,
                           params = pars)  # a complex matrix network
prn = loadrxnetwork(cmn)

# test the two networks are the same
@assert rs == prn.rn

The basic usages are

mn = MatrixNetwork(rateexprs, substoich, prodstoich; species = Any[],
                   params = Any[], t = nothing)
prn = loadrxnetwork(mn::MatrixNetwork)

cmn = ComplexMatrixNetwork(rateexprs, stoichmat, incidencemat; species = Any[],
                           params = Any[], t = nothing)
prn = loadrxnetwork(cmn::ComplexMatrixNetwork)

Here MatrixNetwork and ComplexMatrixNetwork are the types, which select that we are constructing a substrate/product stoichiometric matrix-based or a reaction complex matrix-based stoichiometric representation as input. See the Catalyst.jl API for more discussion on these matrix representations, and how Catalyst handles symbolic reaction rate expressions. These two types have the following fields:

  • rateexprs, any valid Symbolics.jl expression for the rates, or any basic number type. This can be a hardcoded rate constant like 1.0, a parameter like k1 above, or an general Symbolics expression involving parameters and species like k*A.

  • matrix inputs

    • For MatrixNetwork

      • substoich, a number of species by number of reactions matrix with entry (i,j) giving the stoichiometric coefficient of species i as a substrate in reaction j.
      • prodstoich, a number of species by number of reactions matrix with entry (i,j) giving the stoichiometric coefficient of species i as a product in reaction j.
    • For ComplexMatrixNetwork

  • species, an optional vector of symbolic variables representing each species in the network. Can be constructed using the Catalyst.jl @species macro. Each species should be dependent on the same time variable (t in the example above).

  • parameters, a vector of symbolic variables representing each parameter in the network. Can be constructed with the ModelingToolkit.jl @parameters macro. If no parameters are used it is an optional keyword.

  • t, an optional Symbolics.jl variable representing time as the independent variable of the reaction network. If not provided Catalyst.DEFAULT_IV is used to determine the default time variable.

For both input types, loadrxnetwork returns a ParsedReactionNetwork, prn, with only the field, prn.rn, filled in. prn.rn corresponds to the generated Catalyst.jl ReactionSystem that represents the network.

Dispatches are added if substoich and prodstoich both have the type SparseMatrixCSCin case of MatrixNetwork (or stoichmat and incidencemat both have the type SparseMatrixCSC in case of ComplexMatrixNetwork), 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, so that it does not need to be set for systems with no parameters.

reactionnetworkimporters.jl's People

Contributors

arnostrouwen avatar chrisrackauckas avatar dependabot[bot] avatar devmotion avatar fredrikekre avatar github-actions[bot] avatar isaacsas avatar juliatagbot avatar ranocha avatar thazhemadam avatar torkele avatar yewalenikhil65 avatar yingboma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactionnetworkimporters.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Graphs as input

As @ChrisRackauckas requested. Step 1 is figuring out what the graph input should be, then we can convert to an appropriate matrix input.

Make a documentation

In order for this to be included in the SciMLDocs in the model importers section, it needs a documentation

I'd like to get this rxn stoichiometry into Julia

...convert to rate equations and then use phys props datasheet to calk Keq and ks from LFER
rxn.txt is the stoichiometry, rate is set of rate eqn (dydt), LHHW is has the adsorbtion denominator.
could you see what it would take to creat the odes in Julia? I have a proplist.dat that has Hform, Gform, S for each species to get Keq

LHHW.txt
rate.txt
rxn.txt

reaction rate scalings from BioNetGen

DiffEqBio rescales ODE/SSA rates by factorials, but these seem to already be included in the BioNetGen rates/expressions.

  • The fix incorporated for the BCR network needs to be tested more generally on > second order reactions.
  • It also should be noted somewhere that the rescaling is done in the reaction definition (i.e. 2*k, A+A -->B and not in the definition of the rate k.

parameters values and u0s

  1. Handle via defaults.
  2. Currently we numerically evaluate all ps andu0s. We should see if ModelingToolkit properly handles specifying those that are functions of other parameters/u0s symbolically, and then use that via the defaults.

New release

Is it ready to do a new release with the newest MTK and Symbolics?

`functions` is not recognized

Hi, thanks for developing and maintaining the amazing tool!

Reproduce:

I am testing a simple Michaelis-Menten model provided in BioNetGen. I installed this file locally and renamed it "mm.net".

When running the following code,

using ReactionNetworkImporters
using Sundials

fname = "mm.net"
prnbng = loadrxnetwork(BNGNetwork(), fname);
rn = prnbng.rn;
tf = 1000.0
oprob = ODEProblem(rn, Float64[], (0.0, tf), Float64[])
sol = solve(oprob,CVODE_BDF(), saveat = tf / 1000.0)

Although michment is defined at line 11 (begin functions ~ end functions section), I got the following message.

UndefVarError: michment not defined

I would like to know whether the functions definition is supported in this package.

Version info

  • Julia: v1.7
  • ReactionNetworkImporters.jl: v0.14

Directly Target ModelingToolkit?

The importers in this library don't work too well when used from inside of a function or from an alternative module (distributed) because of the eval going on in there. Now that it's ready, it probably makes sense to target the intermediate language instead of a macro, which will generally have these issues. I wanna start getting some really big problems into MTK so that we can have good test cases for Julia Lab folk to work on things like SciML/ModelingToolkit.jl#366 and JuliaSymbolics/SymbolicUtils.jl#62

Internal conversion of integer Float values (e.g. `1.0`) to Int (e.g. 1)

I have a BCR model stored in a .net file. If I try this:

using Catalyst, JumpProcesses
using ReactionNetworkImporters
BCR = loadrxnetwork(BNGNetwork(), "BCR.net")

d_prob = remake(d_prob; u0=Int64.(d_prob.u0))                                 
j_prob = JumpProblem(BCR.rn, d_prob, RSSACR(); save_positions=(false,false)) 
sol = solve(j_prob, SSAStepper(); saveat=0.1);                                

I get an error since some initial condition end up as a Float. Instead, I have to add this line:

d_prob = remake(d_prob; u0=Int64.(d_prob.u0))

It would be neat to automatically convert stuff that is Float to Ints. This example is slightly more complicated, as the non-zero initial conditions are set by parameters, which values are Floats.

unify matrix network interfaces

The old MatrixNetwork should be modified to work like the new one (using a struct storing the various information).

@yewalenikhil65 we also need to update the README for the new importer you added (we can just copy and modify the current MatrixNetwork documentation in the README).

SBML import

Being able to import SBML would be highly enabling for me to switch Julia.

Example Models Database?

It would be nice to get a whole bunch of example models setup with this package so we can easily benchmark. Are there more than the 4 that are currently provided? Are there some huge examples lying around? If the issue is size we can probably find an interesting way to vender stuff via artifacts.

Change uโ‚€ fieldname to u0?

Currently, the loaded model's initial condition is stored in the field name uโ‚€, which is not always easy to type. Would it make sense to change it to u0?

Error with importing functions from .NET files

Hi all,

I am using BioNetGen to generate my reaction network and define some rate laws, different from the standard ones, as functions in the BioNetGen file. However, while the import works perfectly when I try to solve I receive an error that the function for the rate law is not defined (see attached image). Is there anything wrong with the way I am importing the .NET file?

Thank you for your time!

error_network_importer

Unable to load file .net file (generated from bngl, via BioNetGen, from Gupta&Mendes benchmark paper)

Concerning the Gupta&Mended paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6013266/) which benchmarks CRN solvers. There is one model (the one I have tried so far) which I have problems loading into Julia. First I get their .bngl file, egfr_net.bngl (attached to the post, both attached files have added an extra ".txt at the end of the name so that GitHub accepts them). I load the egfr_net.bngl into BioNetGen (2.3.1, using RuleBender). and run it with generate_network({}); at the end. This generates the "egfr_net.net" file (also attached). When trying to load this one with ReactionNetworkImporters I first gets some prints:

Parsing parameters...done
Adding parameters...done
Parsing species...done
Adding species...done
Creating ModelingToolkit versions of species and parameters...done
Parsing and adding reactions...done
Parsing groups...

followed by an error message:

ArgumentError: invalid base 10 digit '*' in "2*8"

Stacktrace:
  [1] tryparse_internal(#unused#::Type{Int64}, s::SubString{String}, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
    @ Base ./parse.jl:137
  [2] parse(::Type{Int64}, s::SubString{String}; base::Nothing)
    @ Base ./parse.jl:241
  [3] parse
    @ ./parse.jl:241 [inlined]
  [4] #14
    @ ./none:0 [inlined]
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] collect(itr::Base.Generator{Vector{SubString{String}}, ReactionNetworkImporters.var"#14#15"{Vector{Symbol}, Sym{Real, Base.ImmutableDict{DataType, Any}}, Dict{Term{Real, Base.ImmutableDict{DataType, Any}}, Int64}}})
    @ Base ./array.jl:678
  [7] parse_groups(ft::BNGNetwork, lines::Vector{String}, idx::Int64, idstoshortsyms::Vector{Symbol}, rn::ReactionSystem)
    @ ReactionNetworkImporters ~/.julia/packages/ReactionNetworkImporters/fTk6C/src/parsing_routines_bngnetworkfiles.jl:159
  [8] loadrxnetwork(ft::BNGNetwork, rxfilename::String; name::Symbol, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ReactionNetworkImporters ~/.julia/packages/ReactionNetworkImporters/fTk6C/src/parsing_routines_bngnetworkfiles.jl:237
  [9] loadrxnetwork(ft::BNGNetwork, rxfilename::String)
    @ ReactionNetworkImporters ~/.julia/packages/ReactionNetworkImporters/fTk6C/src/parsing_routines_bngnetworkfiles.jl:188
 [10] top-level scope
    @ In[10]:1
 [11] eval
    @ ./boot.jl:360 [inlined]
 [12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1094

Is this a recognisable error? I think it occurs at the end (which I basically think are some kind of observables, basically these are the 12 or something properties which are usually plotted of the network (instead of the ~350 species). The lines goes something like:

begin groups
    1 Dimers               2*8,2*9,2*10,2*13,...
    2 Sos_act              18,24,29,34,35,40,44,47,2*49,....
    ...
end groups

and are at the end of the file.

I also tried loading using SBMLToolkit, but get an: SBML models with listOfRules are not yet implemented., so probably not possible just yet.

egfr_net.net.txt
egfr_net.bngl.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.