Unverified Commit 81d112ec authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #50 from LCSB-BioCore/mk-merge-49

merge cleaned-up #49
parents e56c5eda e24275c8
......@@ -5,12 +5,12 @@ This package provides a straightforward way to load model- and
simulation-relevant information from SBML files.
The library provides a single function [`readSBML`](@ref) to load a
julia> using SBML
julia> mdl = readSBML("Ec_core_flux1.xml")
julia> mdl.compartments
2-element Array{String,1}:
......@@ -12,6 +12,6 @@ include("utils.jl")
sbml = (sym::Symbol) -> dlsym(SBML_jll.libsbml_handle, sym)
export SBMLVersion,
readSBML, Model, UnitPart, Species, Reaction, getS, getLBs, getUBs, getOCs
readSBML, getS, getLBs, getUBs, getOCs
end # module
......@@ -75,11 +75,11 @@ function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
function readSBML(fn::String)::Model
function readSBML(fn::String)::SBML.Model
Read the SBML from a XML file in `fn` and return the contained `Model`.
Read the SBML from a XML file in `fn` and return the contained `SBML.Model`.
function readSBML(fn::String)::Model
function readSBML(fn::String)::SBML.Model
doc = ccall(sbml(:readSBML), VPtr, (Cstring,), fn)
n_errs = ccall(sbml(:SBMLDocument_getNumErrors), Cuint, (VPtr,), doc)
......@@ -138,12 +138,12 @@ end
function extractModel(mdl::VPtr)::Model
function extractModel(mdl::VPtr)::SBML.Model
Take the `SBMLModel_t` pointer and extract all information required to make a
valid [`Model`](@ref) structure.
valid [`SBML.Model`](@ref) structure.
function extractModel(mdl::VPtr)::Model
function extractModel(mdl::VPtr)::SBML.Model
# get the FBC plugin pointer (FbcModelPlugin_t)
mdl_fbc = ccall(sbml(:SBase_getPlugin), VPtr, (VPtr, Cstring), mdl, "fbc")
......@@ -157,14 +157,14 @@ function extractModel(mdl::VPtr)::Model
# parse out the unit definitions
units = Dict{String,Vector{UnitPart}}()
units = Dict{String,Vector{SBML.UnitPart}}()
for i = 1:ccall(sbml(:Model_getNumUnitDefinitions), Cuint, (VPtr,), mdl)
ud = ccall(sbml(:Model_getUnitDefinition), VPtr, (VPtr, Cuint), mdl, i - 1)
id = get_string(ud, :UnitDefinition_getId)
units[id] = [
u = ccall(sbml(:UnitDefinition_getUnit), VPtr, (VPtr, Cuint), ud, j - 1)
......@@ -11,14 +11,14 @@ const Maybe{X} = Union{Nothing,X}
Part of a measurement unit definition that corresponds to the SBML definition
of `Unit`. For example, the unit "per square megahour", Mh^(-2), is written as:
UnitPart("second", # base SI unit, this says we are measuring time
SBML.UnitPart("second", # base SI unit, this says we are measuring time
-2, # exponent, says "per square"
6, # log-10 scale of the unit, says "mega"
1/3600) # second-to-hour multiplier
Compound units (such as "volt-amperes" and "dozens of yards per ounce") are
built from multiple `UnitPart`s; see the definition of field `units` in
struct UnitPart
function getS(m::Model; zeros=spzeros)::Tuple{Vector{String},Vector{String},AbstractMatrix{Float64}}
function getS(m::SBML.Model; zeros=spzeros)::Tuple{Vector{String},Vector{String},AbstractMatrix{Float64}}
Extract the vector of species (aka metabolite) identifiers, vector of reaction
identifiers, and the (dense) stoichiometry matrix from an existing `Model`.
identifiers, and the (dense) stoichiometry matrix from an existing `SBML.Model`.
Returns a tuple with these values.
The matrix is sparse by default (initially constructed by
......@@ -10,7 +10,7 @@ The matrix is sparse by default (initially constructed by
argument `zeros`; e.g. running with `zeros=zeros` will produce a dense matrix.
function getS(
zeros = spzeros,
rows = [k for k in keys(m.species)]
......@@ -25,30 +25,30 @@ function getS(
function getLBs(m::Model)::Vector{Tuple{Float64,String}}
function getLBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
Extract a vector of lower bounds of reaction rates from the model. All bounds
are accompanied with the unit of the corresponding value (this behavior is
based on SBML specification).
function getLBs(m::Model)::Vector{Tuple{Float64,String}}
function getLBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
return broadcast(x -> x.lb, values(m.reactions))
function getUBs(m::Model)::Vector{Tuple{Float64,String}}
function getUBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
Likewise to `getLBs`, extract the upper bounds.
function getUBs(m::Model)::Vector{Tuple{Float64,String}}
function getUBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
return broadcast(x -> x.ub, values(m.reactions))
function getOCs(m::Model)::Vector{Float64}
function getOCs(m::SBML.Model)::Vector{Float64}
Extract the vector of objective coefficients of each reaction.
function getOCs(m::Model)::Vector{Float64}
function getOCs(m::SBML.Model)::Vector{Float64}
return broadcast(x -> x.oc, values(m.reactions))
using Test, SHA, SparseArrays
using SBML
using SBML: Model, Reaction, Species
import Pkg
@testset "SBML test suite" begin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment