Commit f2db233d authored by St. Elmo's avatar St. Elmo Committed by Miroslav Kratochvil
Browse files

read notes from species, reactions and models


Co-authored-by: Miroslav Kratochvil's avatarMirek Kratochvil <miroslav.kratochvil@uni.lu>
parent 8b58a03a
......@@ -11,6 +11,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, Model, Maybe, UnitPart, Species, Reaction, getS, getLBs, getUBs, getOCs
end # module
......@@ -31,6 +31,15 @@ function readSBML(fn::String)::Model
end
end
function getNotes(x::VPtr)::Maybe{String}
str = ccall(sbml(:SBase_getNotesString), Cstring, (VPtr,), x)
if str != C_NULL
return unsafe_string(str)
else
return nothing
end
end
function extractModel(mdl::VPtr)::Model
mdl_fbc = ccall(sbml(:SBase_getPlugin), VPtr, (VPtr, Cstring), mdl, "fbc")
......@@ -104,6 +113,7 @@ function extractModel(mdl::VPtr)::Model
unsafe_string(ccall(sbml(:Species_getCompartment), Cstring, (VPtr,), sp)),
formula,
charge,
getNotes(sp),
)
end
......@@ -193,9 +203,14 @@ function extractModel(mdl::VPtr)::Model
end
reid = unsafe_string(ccall(sbml(:Reaction_getId), Cstring, (VPtr,), re))
reactions[reid] =
Reaction(stoi, lb, ub, haskey(objectives_fbc, reid) ? objectives_fbc[reid] : oc)
reactions[reid] = Reaction(
stoi,
lb,
ub,
haskey(objectives_fbc, reid) ? objectives_fbc[reid] : oc,
getNotes(re),
)
end
return Model(parameters, units, compartments, species, reactions)
return Model(parameters, units, compartments, species, reactions, getNotes(mdl))
end
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:
......@@ -31,7 +33,8 @@ struct Reaction
lb::Tuple{Float64,String}
ub::Tuple{Float64,String}
oc::Float64
Reaction(s, l, u, o) = new(s, l, u, o)
notes::Maybe{String}
Reaction(s, l, u, o, n) = new(s, l, u, o, n)
end
"""
......@@ -42,8 +45,9 @@ struct Species
name::String
compartment::String
formula::String
charge::Union{Nothing,Int}
Species(n, co, f, ch) = new(n, co, f, ch)
charge::Maybe{Int}
notes::Maybe{String}
Species(na, co, f, ch, no) = new(na, co, f, ch, no)
end
"""
......@@ -57,5 +61,6 @@ struct Model
compartments::Vector{String}
species::Dict{String,Species}
reactions::Dict{String,Reaction}
Model(p, u, c, s, r) = new(p, u, c, s, r)
notes::Maybe{String}
Model(p, u, c, s, r, n) = new(p, u, c, s, r, n)
end
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