| Title: | Read 'SBML' Models and Convert Them to Simulation Code |
|---|---|
| Description: | Reads models in the Systems Biology Markup Language ('SBML') (Hucka et al. (2003) <doi:10.1093/bioinformatics/btg015>) through the bundled 'libSBML' library (Bornstein et al. (2008) <doi:10.1093/bioinformatics/btn051>). Lists a model's species, parameters, compartments, reactions, rules, events and function definitions, and converts the model into ready-to-run simulation code for 'deSolve', 'mrgsolve', 'rxode2', 'MATLAB', 'Julia' or 'ubiquity'. Models are read, not modified. |
| Authors: | Satyaprakash Nayak [aut, cre, cph], Sarah M. Keating [ctb] (Author of 'libSBML' and of the example code adapted in src/convertReactions.cpp and src/getMath.cpp), Frank T. Bergmann [ctb] (Author of 'libSBML' and of the example code adapted in src/convertReactions.cpp and src/getMath.cpp), Lucian P. Smith [ctb] (Author of 'libSBML'), Brett G. Olivier [ctb] (Author of 'libSBML'), Akiya Jouraku [ctb] (Author of 'libSBML'), Michael Hucka [ctb] (Author of 'libSBML'), Ben Bornstein [ctb] (Author of 'libSBML'), Jeroen Ooms [ctb] (Windows build support), California Institute of Technology [cph] (Copyright holder of 'libSBML', 2002-2020), EMBL European Bioinformatics Institute [cph] (Copyright holder of 'libSBML', 2009-2018), University of Heidelberg [cph] (Copyright holder of 'libSBML', 2013-2020), University College London [cph] (Copyright holder of 'libSBML', 2020), Japan Science and Technology Agency [cph] (Copyright holder of 'libSBML', 2002-2005), Gilles Vollant [cph] (Author of MiniZip, bundled with 'libSBML'), Mathias Svensson [cph] (Contributor to MiniZip, bundled with 'libSBML'), Even Rouault [cph] (Contributor to MiniZip, bundled with 'libSBML'), Nathan Moinvaziri [cph] (Contributor to MiniZip, bundled with 'libSBML'), Terry Thorsen [cph] (Contributor to MiniZip, bundled with 'libSBML'), Info-ZIP [cph] (Copyright holder of encryption code in MiniZip, bundled with 'libSBML'), Ludwig Schwardt [cph] (Author of the zlib iostream wrappers bundled with 'libSBML'), Kevin Ruland [cph] (Author of the zlib iostream wrappers bundled with 'libSBML'), M. Petra Baranski [cph] (Author of 'maddy', bundled with 'libSBML'), Tim Gromeyer [cph] (Author of 'html2md', bundled with 'libSBML') |
| Maintainer: | Satyaprakash Nayak <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-11-03 23:54:53 UTC |
| Source: | https://github.com/cran/r2sbml |
Writes the model's mass balances, rules and parameters as code for the chosen simulation tool, ready to simulate.
convertReactions(infile, outfile, format = "R")convertReactions(infile, outfile, format = "R")
infile |
input file name |
outfile |
output file name |
format |
output code format, one of 'R'/'deSolve' (default), 'mrgsolve', 'nlmixr2' (or 'rxode2'), 'MATLAB', 'Julia' or 'ubiquity'. An unrecognised format is an error. |
NULL invisibly
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") out_file <- tempfile(fileext = ".R") convertReactions(sbml_file, out_file, format = "R") out_file_mrg <- tempfile(fileext = ".cpp") convertReactions(sbml_file, out_file_mrg, format = "mrgsolve") out_file_rx <- tempfile(fileext = ".R") convertReactions(sbml_file, out_file_rx, format = "nlmixr2") out_file_m <- tempfile(fileext = ".m") convertReactions(sbml_file, out_file_m, format = "MATLAB") out_file_jl <- tempfile(fileext = ".jl") convertReactions(sbml_file, out_file_jl, format = "Julia") out_file_ub <- tempfile(fileext = ".txt") convertReactions(sbml_file, out_file_ub, format = "ubiquity")sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") out_file <- tempfile(fileext = ".R") convertReactions(sbml_file, out_file, format = "R") out_file_mrg <- tempfile(fileext = ".cpp") convertReactions(sbml_file, out_file_mrg, format = "mrgsolve") out_file_rx <- tempfile(fileext = ".R") convertReactions(sbml_file, out_file_rx, format = "nlmixr2") out_file_m <- tempfile(fileext = ".m") convertReactions(sbml_file, out_file_m, format = "MATLAB") out_file_jl <- tempfile(fileext = ".jl") convertReactions(sbml_file, out_file_jl, format = "Julia") out_file_ub <- tempfile(fileext = ".txt") convertReactions(sbml_file, out_file_ub, format = "ubiquity")
Reads the file and prints the number of diagnostics libSBML reports, then the diagnostics themselves.
echoSBML(filename)echoSBML(filename)
filename |
input file name |
the number of diagnostics, as an integer
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") echoSBML(sbml_file)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") echoSBML(sbml_file)
Returns the name where one is set and falls back to the id otherwise,
the same rule getSpeciesNames() uses. Previously this returned the id
unconditionally while getSpeciesNames() returned the name, so the two
disagreed about what a "name" was. For a model whose compartments set no
name – which is all ten of the bundled examples – the result is unchanged.
getCmtNames(input_model)getCmtNames(input_model)
input_model |
input should be an SBML Model |
a character vector, one entry per compartment, in model order
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getCmtNames(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getCmtNames(model)
Reports each compartment's declared size, as the file states it.
getCmtSizes(input_model)getCmtSizes(input_model)
input_model |
input should be an SBML Model |
a numeric vector, one entry per compartment, in model order
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getCmtSizes(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getCmtSizes(model)
Prints each event's trigger and assignments as infix math.
getEventMath(input_model)getEventMath(input_model)
input_model |
input should be an SBML Model |
0; called for the printed output
sbml_file <- system.file("examples", "sbmlevent.xml", package = "r2sbml") model <- getModel(sbml_file) getEventMath(model)sbml_file <- system.file("examples", "sbmlevent.xml", package = "r2sbml") model <- getModel(sbml_file) getEventMath(model)
Prints each function definition's arguments and body as infix math.
getFunctionDefinition(input_model)getFunctionDefinition(input_model)
input_model |
input should be an SBML Model |
0; called for the printed output
sbml_file <- system.file("examples", "sbmlfunctiondefinition.xml", package = "r2sbml") model <- getModel(sbml_file) getFunctionDefinition(model)sbml_file <- system.file("examples", "sbmlfunctiondefinition.xml", package = "r2sbml") model <- getModel(sbml_file) getFunctionDefinition(model)
Reads an SBML file and keeps the parsed document alive for the other query functions. A file with error- or fatal-severity diagnostics is an error; lesser diagnostics are raised as warnings.
getModel(filename)getModel(filename)
filename |
input file name, should end with .xml |
an external pointer to the model, to pass to the other functions
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file)
Counts the species the model declares.
getNumSpecies(input_model)getNumSpecies(input_model)
input_model |
input should be an SBML model |
an integer, the number of species
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getNumSpecies(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getNumSpecies(model)
Lists each global parameter with its declared value and units.
getParameterTable(input_model)getParameterTable(input_model)
input_model |
input should be an SBML Model |
a data frame with one row per parameter and columns Number, ID,
Name, Value and Units
sbml_file <- system.file("examples", "sbmlassignmentrules.xml", package = "r2sbml") model <- getModel(sbml_file) getParameterTable(model)sbml_file <- system.file("examples", "sbmlassignmentrules.xml", package = "r2sbml") model <- getModel(sbml_file) getParameterTable(model)
Prints each reaction's kinetic law as infix math.
getReactionMath(input_model)getReactionMath(input_model)
input_model |
input should be an SBML Model |
0; called for the printed output
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getReactionMath(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getReactionMath(model)
Lists each reaction with its rate law written as infix math.
getReactionTable(input_model)getReactionTable(input_model)
input_model |
input should be an SBML Model |
a data frame with one row per reaction and columns Number, ID,
Name, Reversible and RateLaw
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getReactionTable(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getReactionTable(model)
Prints each rule as infix math; an algebraic rule is printed as f = 0.
getRuleMath(input_model)getRuleMath(input_model)
input_model |
input should be an SBML Model |
0; called for the printed output
sbml_file <- system.file("examples", "sbmlassignmentrules.xml", package = "r2sbml") model <- getModel(sbml_file) getRuleMath(model)sbml_file <- system.file("examples", "sbmlassignmentrules.xml", package = "r2sbml") model <- getModel(sbml_file) getRuleMath(model)
A species carries initialAmount or initialConcentration, never both,
and the unset one reads back as NaN. Asking only for the concentration
therefore returned NaN for every species in an amount-based model. This
returns whichever attribute the model actually sets.
getSpeciesIC(input_model)getSpeciesIC(input_model)
input_model |
input should be an SBML Model |
The value is reported as the file states it, with no unit conversion, so
a model that mixes amount-valued and concentration-valued species yields a
vector that mixes units too – getSpeciesTable() shows which column each
species used. This deliberately differs from convertReactions(), which
must divide an amount by the compartment volume because the ODE it generates
integrates concentrations.
A species that sets neither attribute – its value comes from an initial
assignment or a rule – is reported as NA, not 0.
a named numeric vector, one entry per species, named by species id
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesIC(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesIC(model)
SBML separates id, which every species must have, from name, which is an
optional human-readable label. Most models in the wild set only id, so
returning name alone gave a vector of empty strings. This returns the
name where one is set and falls back to the id otherwise, which is how
SBML tools conventionally display a species. getCmtNames() follows the
same rule. Use getSpeciesTable() when you need the two columns separately.
getSpeciesNames(input_model)getSpeciesNames(input_model)
input_model |
input should be an SBML Model |
a character vector, one entry per species, in model order
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesNames(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesNames(model)
Lists each species with its initial value, compartment and flags.
getSpeciesTable(input_model)getSpeciesTable(input_model)
input_model |
input should be an SBML Model |
a data frame with one row per species and columns Number, Name,
ID, InitialConcentration, InitialAmount, Compartment,
CompartmentVol, BoundaryCondition and Constant
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesTable(model)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") model <- getModel(sbml_file) getSpeciesTable(model)
Prints the file's SBML level and version and how many of each component its model has.
printSBML(filename)printSBML(filename)
filename |
filename should be the name of the xml file |
0 on success and 1 when the file has errors or no model; called for the printed summary
sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") printSBML(sbml_file)sbml_file <- system.file("examples", "sbmlsimple.xml", package = "r2sbml") printSBML(sbml_file)