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
bd5db6b5
Commit
bd5db6b5
authored
Jun 25, 2021
by
Miroslav Kratochvil
🚴
Browse files
initial_concentrations and _amounts return generators
...to make the work with custom datatypes easier.
parent
7c820907
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/utils.jl
View file @
bd5db6b5
...
...
@@ -56,71 +56,51 @@ end
"""
initial_amounts(m::SBML.Model; convert_concentrations = false)
Return a vector of initial amounts for each species, or `nothing` if the
information is not available. If `convert_concentrations` is true and there is
information about initial concentration available together with compartment
size, the result is computed from the species' initial concentration.
Return initial amounts for each species as a generator of pairs
`species_name => initial_amount`; the amount is set to `nothing` if not
available. If `convert_concentrations` is true and there is information about
initial concentration available together with compartment size, the result is
computed from the species' initial concentration.
In the current version, units of the measurements are completely ignored.
"""
function
initial_amounts
(
m
::
SBML
.
Model
;
convert_concentrations
=
false
,
)
::
Vector
{
Union
{
Float64
,
Nothing
}}
function
get_ia
(
x
::
Species
)
if
!
isnothing
(
x
.
initial_amount
)
x
.
initial_amount
[
1
]
elseif
!
isnothing
(
x
.
initial_concentration
)
&&
haskey
(
m
.
compartments
,
x
.
compartment
)
&&
!
isnothing
(
m
.
compartments
[
x
.
compartment
]
.
size
)
x
.
initial_concentration
[
1
]
*
m
.
compartments
[
x
.
compartment
]
.
size
else
nothing
end
end
if
convert_concentrations
get_ia
.
(
values
(
m
.
species
))
# Example
```
# get the initial amounts as dictionary
Dict(initial_amounts(model, convert_concentrations = true))
# remove the empty entries
Dict(k => v for (k,v) in initial_amounts(model) if !isnothing(v))
```
"""
const
initial_amounts
(
m
::
SBML
.
Model
;
convert_concentrations
=
false
)
=
(
k
=>
if
!
isnothing
(
s
.
initial_amount
)
s
.
initial_amount
[
1
]
elseif
convert_concentrations
&&
!
isnothing
(
s
.
initial_concentration
)
&&
haskey
(
m
.
compartments
,
s
.
compartment
)
&&
!
isnothing
(
m
.
compartments
[
s
.
compartment
]
.
size
)
s
.
initial_concentration
[
1
]
*
m
.
compartments
[
s
.
compartment
]
.
size
else
return
broadcast
(
x
->
isnothing
(
x
.
initial_amount
)
?
nothing
:
x
.
initial_amount
[
1
],
values
(
m
.
species
),
)
end
end
nothing
end
for
(
k
,
s
)
in
m
.
species
)
"""
initial_concentrations(m::SBML.Model; convert_amounts = false)
Return a vector of initial concentrations for each species, or `nothing` if
the information is not available. If `convert_amounts` is true and there is
information about initial amount available together with compartment size, the
result is computed from the species' initial amount.
In the current version, units of the measurements are completely ignored.
Return initial concentrations of the species in the model. Refer to work-alike
[`initial_amounts`](@ref) for details.
"""
function
initial_concentrations
(
m
::
SBML
.
Model
;
convert_amounts
=
false
,
)
::
Vector
{
Union
{
Float64
,
Nothing
}}
function
get_ic
(
x
::
Species
)
if
!
isnothing
(
x
.
initial_concentration
)
x
.
initial_concentration
[
1
]
elseif
!
isnothing
(
x
.
initial_amount
)
&&
haskey
(
m
.
compartments
,
x
.
compartment
)
&&
!
isnothing
(
m
.
compartments
[
x
.
compartment
]
.
size
)
x
.
initial_amount
[
1
]
/
m
.
compartments
[
x
.
compartment
]
.
size
else
nothing
end
end
if
convert_amounts
get_ic
.
(
values
(
m
.
species
))
const
initial_concentrations
(
m
::
SBML
.
Model
;
convert_amounts
=
false
)
=
(
k
=>
if
!
isnothing
(
s
.
initial_concentration
)
s
.
initial_concentration
[
1
]
elseif
convert_amounts
&&
!
isnothing
(
s
.
initial_amount
)
&&
haskey
(
m
.
compartments
,
s
.
compartment
)
&&
!
isnothing
(
m
.
compartments
[
s
.
compartment
]
.
size
)
s
.
initial_amount
[
1
]
/
m
.
compartments
[
s
.
compartment
]
.
size
else
broadcast
(
x
->
isnothing
(
x
.
initial_concentration
)
?
nothing
:
x
.
initial_concentration
[
1
],
values
(
m
.
species
),
)
end
end
nothing
end
for
(
k
,
s
)
in
m
.
species
)
test/loadmodels.jl
View file @
bd5db6b5
...
...
@@ -72,8 +72,9 @@ end
@testset
"Initial amounts and concentrations"
begin
m
=
readSBML
(
joinpath
(
@__DIR__
,
"data"
,
"sbml00852.xml"
))
@test
all
(
isnothing
.
(
SBML
.
initial_concentrations
(
m
))
)
@test
all
(
isnothing
(
ic
)
for
(
k
,
ic
)
in
SBML
.
initial_concentrations
(
m
))
@test
length
(
SBML
.
initial_amounts
(
m
))
==
4
@test
sum
(
SBML
.
initial_amounts
(
m
))
==
0.001
@test
sum
(
SBML
.
initial_concentrations
(
m
,
convert_amounts
=
true
))
==
0.001
@test
sum
(
ia
for
(
sp
,
ia
)
in
SBML
.
initial_amounts
(
m
))
==
0.001
@test
sum
(
ic
for
(
sp
,
ic
)
in
SBML
.
initial_concentrations
(
m
,
convert_amounts
=
true
))
==
0.001
end
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