GeckoModel.jl 3.72 KB
Newer Older
St. Elmo's avatar
St. Elmo committed
1

2
3
4
5
6
7
8
9
10
11
12
struct _gecko_column
    reaction_idx::Int
    isozyme_idx::Int
    direction::Int
    reaction_coupling_row::Int
    lb::Float64
    ub::Float64
    gene_product_coupling::Vector{Tuple{Int,Float64}}
    mass_group_row::Int
    mass_required::Float64
end
St. Elmo's avatar
St. Elmo committed
13

14
15
16
struct GeckoModel <: ModelWrapper
    columns::Vector{_gecko_column}
    coupling_row_reaction::Vector{Int}
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
17
18
    coupling_row_gene_product::Vector{Tuple{Int,Tuple{Float64,Float64}}}
    coupling_row_mass_group::Vector{Tuple{String,Float64}}
St. Elmo's avatar
St. Elmo committed
19

20
21
    inner::MetabolicModel
end
St. Elmo's avatar
St. Elmo committed
22

23
unwrap_model(model::GeckoModel) = model.inner
St. Elmo's avatar
St. Elmo committed
24
25

"""
26
    stoichiometry(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
27

28
29
30
Return a stoichiometry of the [`GeckoModel`](@ref). The enzymatic reactions are
split into unidirectional forward and reverse ones, each of which may have
multiple variants per isozyme.
St. Elmo's avatar
St. Elmo committed
31
"""
32
33
stoichiometry(model::GeckoModel) =
    stoichiometry(model.inner) * _gecko_column_reactions(model)
St. Elmo's avatar
St. Elmo committed
34
35

"""
36
    objective(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
37

38
39
Reconstruct an objective of the [`GeckoModel`](@ref), following the objective
of the inner model.
St. Elmo's avatar
St. Elmo committed
40
"""
41
objective(model::GeckoModel) = _gecko_column_reactions(model)' * objective(model.inner)
St. Elmo's avatar
St. Elmo committed
42
43
44
45

"""
    reactions(model::GeckoModel)

46
47
48
49
50
51
52
53
54
55
56
57
58
59
Returns the internal reactions in a [`GeckoModel`](@ref) (these may be split
to forward- and reverse-only parts with different isozyme indexes; reactions
IDs are mangled accordingly with suffixes).
"""
reactions(model::GeckoModel) =
    let inner_reactions = reactions(model.inner)
        [
            _gecko_reaction_name(
                inner_reactions[col.reaction_idx],
                col.direction,
                col.isozyme_idx,
            ) for col in model.columns
        ]
    end
St. Elmo's avatar
St. Elmo committed
60
61
62
63
64
65

"""
    reactions(model::GeckoModel)

Returns the number of all irreversible reactions in `model`.
"""
66
n_reactions(model::GeckoModel) = length(model.columns)
St. Elmo's avatar
St. Elmo committed
67
68

"""
69
    bounds(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
70

71
Return variable bounds for [`GeckoModel`](@ref).
St. Elmo's avatar
St. Elmo committed
72
"""
73
74
bounds(model::GeckoModel) =
    ([col.lb for col in model.columns], [col.ub for col in model.columns])
St. Elmo's avatar
St. Elmo committed
75
76

"""
77
    reaction_flux(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
78

79
80
Get the mapping of the reaction rates in [`GeckoModel`](@ref) to the original
fluxes in the wrapped model.
St. Elmo's avatar
St. Elmo committed
81
"""
82
83
reaction_flux(model::GeckoModel) =
    _gecko_column_reactions(model)' * reaction_flux(model.inner)
St. Elmo's avatar
St. Elmo committed
84
85

"""
86
    coupling(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
87

88
89
90
Return the coupling of [`GeckoModel`](@ref). That combines the coupling of
the wrapped model, coupling for split reactions, and the coupling for the total
enzyme capacity.
St. Elmo's avatar
St. Elmo committed
91
"""
92
93
94
95
coupling(model::GeckoModel) = vcat(
    coupling(model.inner) * _gecko_column_reactions(model),
    _gecko_reaction_coupling(model),
    _gecko_gene_product_coupling(model),
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
96
    _gecko_mass_group_coupling(model),
97
)
St. Elmo's avatar
St. Elmo committed
98
99

"""
100
    n_coupling_constraints(model::GeckoModel)
St. Elmo's avatar
St. Elmo committed
101

102
103
Count the coupling constraints in [`GeckoModel`](@ref) (refer to
[`coupling`](@ref) for details).
St. Elmo's avatar
St. Elmo committed
104
"""
105
106
107
n_coupling_constraints(model::GeckoModel) =
    n_coupling_constraints(model.inner) +
    length(model.coupling_row_reaction) +
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
108
109
    length(model.coupling_row_gene_product) +
    length(model.coupling_row_mass_group)
St. Elmo's avatar
St. Elmo committed
110
111
112
113

"""
    coupling_bounds(model::GeckoModel)

114
115
116
117
118
119
120
121
122
123
The coupling bounds for [`GeckoModel`](@ref) (refer to [`coupling`](@ref) for
details).
"""
function coupling_bounds(model::GeckoModel)
    (iclb, icub) = coupling_bounds(model.inner)
    (ilb, iub) = bounds(model.inner)
    return (
        vcat(
            iclb,
            ilb[model.coupling_row_reaction],
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
124
            [lb for (_, (lb, _)) in model.coupling_row_gene_product],
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
125
            [0.0 for _ in model.coupling_row_mass_group],
126
127
128
        ),
        vcat(
            icub,
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
129
130
131
            iub[model.coupling_row_reaction],
            [ub for (_, (_, ub)) in model.coupling_row_gene_product],
            [ub for (_, ub) in model.coupling_row_mass_group],
132
133
134
        ),
    )
end