utils.jl 1.53 KB
Newer Older
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
1
2
3
4
5
6
7
"""
    function getS(m::Model)::Tuple{Vector{String},Vector{String},Matrix{Float64}}

Extract the vector of species (aka metabolite) identifiers, vector of reaction
identifiers, and the (dense) stoichiometry matrix from an existing `Model`.
Returns a tuple with these values.
"""
8
function getS(m::Model)::Tuple{Vector{String},Vector{String},Matrix{Float64}}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
9
    #TODO this will need a sparse version and faster row ID lookup
10
11
12
13
14
15
16
17
18
19
    rows = [k for k in keys(m.species)] #TODO this too
    cols = [k for k in keys(m.reactions)]
    S = zeros(Float64, length(rows), length(cols))
    for ri = 1:length(cols)
        stoi = m.reactions[cols[ri]].stoichiometry
        S[indexin(keys(stoi), rows), ri] .= values(stoi)
    end
    return rows, cols, S
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
20
21
22
23
24
25
26
"""
    function getLBs(m::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).
"""
27
28
29
30
function getLBs(m::Model)::Vector{Tuple{Float64,String}}
    return broadcast(x -> x.lb, values(m.reactions))
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
31
32
33
34
35
"""
    function getUBs(m::Model)::Vector{Tuple{Float64,String}}

Likewise to `getLBs`, extract the upper bounds.
"""
36
37
38
39
function getUBs(m::Model)::Vector{Tuple{Float64,String}}
    return broadcast(x -> x.ub, values(m.reactions))
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
40
41
42
43
44
"""
    function getOCs(m::Model)::Vector{Float64}

Extract the vector of objective coefficients of each reaction.
"""
45
46
47
function getOCs(m::Model)::Vector{Float64}
    return broadcast(x -> x.oc, values(m.reactions))
end