Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
6daf9850
Commit
6daf9850
authored
Apr 13, 2021
by
Miroslav Kratochvil
🚴
Browse files
import more Compartment metadata, mainly the sizes
parent
b55ca9f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/readsbml.jl
View file @
6daf9850
...
...
@@ -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),
)
...
...
src/structs.jl
View file @
6daf9850
...
...
@@ -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
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment