Commit 6daf9850 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

import more Compartment metadata, mainly the sizes

parent b55ca9f8
......@@ -35,6 +35,45 @@ function get_optional_string(x::VPtr, fn_sym)::Maybe{String}
end
end
"""
get_optional_bool(x::VPtr, is_sym, get_sym)::Maybe{Bool}
Helper for getting out boolean flags.
"""
function get_optional_bool(x::VPtr, is_sym, get_sym)::Maybe{Bool}
if ccall(sbml(is_sym), Cint, (VPtr,), x) != 0
return ccall(sbml(get_sym), Cint, (VPtr,), x) != 0
else
return nothing
end
end
"""
get_optional_int(x::VPtr, is_sym, get_sym)::Maybe{UInt}
Helper for getting out unsigned integers.
"""
function get_optional_int(x::VPtr, is_sym, get_sym)::Maybe{Int}
if ccall(sbml(is_sym), Cint, (VPtr,), x) != 0
return ccall(sbml(get_sym), Cint, (VPtr,), x)
else
return nothing
end
end
"""
get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
Helper for getting out C doubles aka Float64s.
"""
function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
if ccall(sbml(is_sym), Cint, (VPtr,), x) != 0
return ccall(sbml(get_sym), Cdouble, (VPtr,), x)
else
return nothing
end
end
"""
function readSBML(fn::String)::Model
......@@ -143,12 +182,24 @@ function extractModel(mdl::VPtr)::Model
end
# parse out compartment names
compartments = [
get_string(
ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i - 1),
:Compartment_getId,
) for i = 1:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl)
]
compartments = Dict{String,Compartment}()
for i = 1:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl)
co = ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i - 1)
compartments[get_string(co, :Compartment_getId)] = Compartment(
get_optional_string(co, :Compartment_getName),
get_optional_bool(co, :Compartment_isSetConstant, :Compartment_getConstant),
get_optional_int(
co,
:Compartment_isSetSpatialDimensions,
:Compartment_getSpatialDimensions,
),
get_optional_double(co, :Compartment_isSetSize, :Compartment_getSize),
get_optional_string(co, :Compartment_getUnits),
get_notes(co),
get_annotation(co),
)
end
# parse out species
species = Dict{String,Species}()
......@@ -183,7 +234,11 @@ function extractModel(mdl::VPtr)::Model
formula,
charge,
ia,
ccall(sbml(:Species_getHasOnlySubstanceUnits), Cint, (VPtr,), sp) != 0,
get_optional_bool(
sp,
:Species_isSetHasOnlySubstanceUnits,
:Species_getHasOnlySubstanceUnits,
),
get_notes(sp),
get_annotation(sp),
)
......
......@@ -90,6 +90,20 @@ struct MathLambda <: Math
body::Math
end
"""
SBML Compartment with sizing information.
"""
struct Compartment
name::Maybe{String}
constant::Maybe{Bool}
spatial_dimensions::Maybe{Int}
size::Maybe{Float64}
units::Maybe{String}
notes::Maybe{String}
annotation::Maybe{String}
Compartment(na, c, sd, s, u, no = nothing, an = nothing) = new(na, c, sd, s, u, no, an)
end
"""
Reaction with stoichiometry that assigns reactants and products their relative
consumption/production rates (accessible in field `stoichiometry`), lower/upper
......@@ -118,7 +132,7 @@ struct Species
formula::Maybe{String}
charge::Maybe{Int}
initial_amount::Maybe{Tuple{Float64,String}}
only_substance_units::Bool
only_substance_units::Maybe{Bool}
notes::Maybe{String}
annotation::Maybe{String}
Species(na, co, f, ch, ia, osu, no = nothing, a = nothing) =
......@@ -157,7 +171,7 @@ objects.
struct Model
parameters::Dict{String,Float64}
units::Dict{String,Vector{UnitPart}}
compartments::Vector{String}
compartments::Dict{String,Compartment}
species::Dict{String,Species}
reactions::Dict{String,Reaction}
gene_products::Dict{String,GeneProduct}
......
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