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

fun accessors for initial amounts and concentrations

parent a4ed3eae
......@@ -52,3 +52,75 @@ 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
"""
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.
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))
else
return broadcast(
x -> isnothing(x.initial_amount) ? nothing : x.initial_amount[1],
values(m.species),
)
end
end
"""
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.
"""
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))
else
broadcast(
x -> isnothing(x.initial_concentration) ? nothing : x.initial_concentration[1],
values(m.species),
)
end
end
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