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} ...@@ -35,6 +35,45 @@ function get_optional_string(x::VPtr, fn_sym)::Maybe{String}
end end
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 function readSBML(fn::String)::Model
...@@ -143,12 +182,24 @@ function extractModel(mdl::VPtr)::Model ...@@ -143,12 +182,24 @@ function extractModel(mdl::VPtr)::Model
end end
# parse out compartment names # parse out compartment names
compartments = [ compartments = Dict{String,Compartment}()
get_string( for i = 1:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl)
ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i - 1), co = ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i - 1)
:Compartment_getId,
) for i = 1:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl) 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 # parse out species
species = Dict{String,Species}() species = Dict{String,Species}()
...@@ -183,7 +234,11 @@ function extractModel(mdl::VPtr)::Model ...@@ -183,7 +234,11 @@ function extractModel(mdl::VPtr)::Model
formula, formula,
charge, charge,
ia, ia,
ccall(sbml(:Species_getHasOnlySubstanceUnits), Cint, (VPtr,), sp) != 0, get_optional_bool(
sp,
:Species_isSetHasOnlySubstanceUnits,
:Species_getHasOnlySubstanceUnits,
),
get_notes(sp), get_notes(sp),
get_annotation(sp), get_annotation(sp),
) )
......
...@@ -90,6 +90,20 @@ struct MathLambda <: Math ...@@ -90,6 +90,20 @@ struct MathLambda <: Math
body::Math body::Math
end 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 Reaction with stoichiometry that assigns reactants and products their relative
consumption/production rates (accessible in field `stoichiometry`), lower/upper consumption/production rates (accessible in field `stoichiometry`), lower/upper
...@@ -118,7 +132,7 @@ struct Species ...@@ -118,7 +132,7 @@ struct Species
formula::Maybe{String} formula::Maybe{String}
charge::Maybe{Int} charge::Maybe{Int}
initial_amount::Maybe{Tuple{Float64,String}} initial_amount::Maybe{Tuple{Float64,String}}
only_substance_units::Bool only_substance_units::Maybe{Bool}
notes::Maybe{String} notes::Maybe{String}
annotation::Maybe{String} annotation::Maybe{String}
Species(na, co, f, ch, ia, osu, no = nothing, a = nothing) = Species(na, co, f, ch, ia, osu, no = nothing, a = nothing) =
...@@ -157,7 +171,7 @@ objects. ...@@ -157,7 +171,7 @@ objects.
struct Model struct Model
parameters::Dict{String,Float64} parameters::Dict{String,Float64}
units::Dict{String,Vector{UnitPart}} units::Dict{String,Vector{UnitPart}}
compartments::Vector{String} compartments::Dict{String,Compartment}
species::Dict{String,Species} species::Dict{String,Species}
reactions::Dict{String,Reaction} reactions::Dict{String,Reaction}
gene_products::Dict{String,GeneProduct} 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