Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
b109dc67
Unverified
Commit
b109dc67
authored
Jun 25, 2021
by
Miroslav Kratochvil
Committed by
GitHub
Jun 25, 2021
Browse files
Merge pull request #84 from LCSB-BioCore/mk-initial-conversions
fun accessors for initial amounts and concentrations
parents
3cecd7c3
68a2fadd
Changes
3
Show whitespace changes
Inline
Side-by-side
src/utils.jl
View file @
b109dc67
...
...
@@ -25,30 +25,78 @@ function getS(
end
"""
function
getLBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
getLBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
Extract a vector of lower bounds of reaction rates from the model. All bounds
are accompanied with the unit of the corresponding value (this behavior is
based on SBML specification).
"""
function
getLBs
(
m
::
SBML
.
Model
)
::
Vector
{
Tuple
{
Float64
,
String
}}
return
broadcast
(
x
->
x
.
lb
,
values
(
m
.
reactions
))
end
getLBs
(
m
::
SBML
.
Model
)
::
Vector
{
Tuple
{
Float64
,
String
}}
=
broadcast
(
x
->
x
.
lb
,
values
(
m
.
reactions
))
"""
function
getUBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
getUBs(m::SBML.Model)::Vector{Tuple{Float64,String}}
Likewise to `getLBs`, extract the upper bounds.
Likewise to
[
`getLBs`
](@ref)
, extract the upper bounds.
"""
function
getUBs
(
m
::
SBML
.
Model
)
::
Vector
{
Tuple
{
Float64
,
String
}}
return
broadcast
(
x
->
x
.
ub
,
values
(
m
.
reactions
))
end
getUBs
(
m
::
SBML
.
Model
)
::
Vector
{
Tuple
{
Float64
,
String
}}
=
broadcast
(
x
->
x
.
ub
,
values
(
m
.
reactions
))
"""
function
getOCs(m::SBML.Model)::Vector{Float64}
getOCs(m::SBML.Model)::Vector{Float64}
Extract the vector of objective coefficients of each reaction.
"""
function
getOCs
(
m
::
SBML
.
Model
)
::
Vector
{
Float64
}
return
broadcast
(
x
->
x
.
oc
,
values
(
m
.
reactions
))
end
getOCs
(
m
::
SBML
.
Model
)
::
Vector
{
Float64
}
=
broadcast
(
x
->
x
.
oc
,
values
(
m
.
reactions
))
"""
initial_amounts(m::SBML.Model; convert_concentrations = false)
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.
# 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))
```
"""
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
nothing
end
for
(
k
,
s
)
in
m
.
species
)
"""
initial_concentrations(m::SBML.Model; convert_amounts = false)
Return initial concentrations of the species in the model. Refer to work-alike
[`initial_amounts`](@ref) for details.
"""
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
nothing
end
for
(
k
,
s
)
in
m
.
species
)
test/ecoli_flux.jl
View file @
b109dc67
...
...
@@ -18,7 +18,9 @@ end
@test
typeof
(
mdl
)
==
Model
@test_logs
(
:
error
,
"SBML reported error: File unreadable."
)
@test_throws
AssertionError
readSBML
(
sbmlfile
*
".does.not.really.exist"
)
@test_logs
(
:
error
,
"SBML reported error: File unreadable."
)
@test_throws
AssertionError
readSBML
(
sbmlfile
*
".does.not.really.exist"
,
)
@test
length
(
mdl
.
compartments
)
==
2
...
...
test/loadmodels.jl
View file @
b109dc67
...
...
@@ -68,3 +68,13 @@ end
m
=
readSBML
(
joinpath
(
@__DIR__
,
"data"
,
"sbml00852.xml"
))
@test
all
(
contains_time
.
(
r
.
kinetic_math
for
(
_
,
r
)
in
m
.
reactions
))
end
@testset
"Initial amounts and concentrations"
begin
m
=
readSBML
(
joinpath
(
@__DIR__
,
"data"
,
"sbml00852.xml"
))
@test
all
(
isnothing
(
ic
)
for
(
k
,
ic
)
in
SBML
.
initial_concentrations
(
m
))
@test
length
(
SBML
.
initial_amounts
(
m
))
==
4
@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
cylon-x
🤖
@cylon-x
mentioned in commit
ebd4c0e3
·
Jun 25, 2021
mentioned in commit
ebd4c0e3
mentioned in commit ebd4c0e393f135b8715922503e1a4cf2cb129f6f
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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