Skip to content

Commit

Permalink
rename kwarg to be even more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
stelmo committed Feb 18, 2023
1 parent b986b68 commit f72d662
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/14_simplified_enzyme_constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ simplified_enzyme_constrained_model =
model |> with_simplified_enzyme_constraints(
reaction_isozyme = rxn_isozymes,
gene_product_molar_mass = gene_product_masses,
total_enzyme_capacity = 50.0,
total_gene_product_mass_bound = 50.0,
)

# (You could alternatively use the [`make_simplified_enzyme_constrained_model`](@ref) to create the
Expand Down
36 changes: 23 additions & 13 deletions src/reconstruction/enzyme_constrained.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"""
$(TYPEDSIGNATURES)
Wrap a model into a [`EnzymeConstrainedModel`](@ref), following the structure
given by GECKO algorithm (see [`EnzymeConstrainedModel`](@ref) documentation for
details). Multiple capacity constraints can be placed on the model using the
Wrap a model into an [`EnzymeConstrainedModel`](@ref), following the structure
given by the GECKO algorithm (see [`EnzymeConstrainedModel`](@ref) documentation
for details). Multiple capacity constraints can be placed on the model using the
kwargs.
Parameters `gene_product_mass_group` and `gene_product_mass_group_bound` specify the groups of gene products and the respective total limit of total mass of the gene products for each group. Gene products not listed in any gene product mass group are ignored.
Parameters `gene_product_mass_group` and `gene_product_mass_group_bound` specify
the groups of gene products and the respective total capacity limit of the gene
products for each group. Gene products not listed in any gene product mass group
are ignored.
For simplicity in many use cases, specifying the `total_enzyme_capacity` argument overrides the above arguments by specifying a single group called `uncategorized` of all gene products, with the corresponding mass bound.
- `gene_product_mass_group` is a dict that returns a vector of gene IDs
For simplicity, in many use cases specifying the `total_gene_product_mass_bound`
argument overrides the above arguments by specifying a single group called
`uncategorized` of all gene products, with the corresponding mass capacity
bound.
# Example
```
Expand All @@ -27,26 +32,31 @@ ecmodel = make_enzyme_constrained_model(
ecmodel2 = make_enzyme_constrained_model(
model;
total_enzyme_capacity = 0.5
)
total_gene_product_mass_bound = 0.5
)
```
# Notes
Reactions with no turnover number data, or non-enzymatic reactions that should
be ignored, *must* have `nothing` in the `gene_associations` field of the
associated reaction.
The capacity bound
"""
function make_enzyme_constrained_model(
model::AbstractMetabolicModel;
gene_product_mass_group::Maybe{Dict{String,Vector{String}}} = nothing,
gene_product_mass_group_bound::Maybe{Dict{String,Float64}} = nothing,
total_enzyme_capacity::Maybe{Float64} = nothing,
total_gene_product_mass_bound::Maybe{Float64} = nothing,
)
if !isnothing(total_enzyme_capacity)
if !isnothing(total_gene_product_mass_bound)
gene_product_mass_group = Dict("uncategorized" => genes(model))
gene_product_mass_group_bound = Dict("uncategorized" => total_enzyme_capacity)
gene_product_mass_group_bound =
Dict("uncategorized" => total_gene_product_mass_bound)
end
isnothing(gene_product_mass_group) && throw(ArgumentError("missing mass group specification"))
isnothing(gene_product_mass_group_bound) && throw(ArgumentError("missing mass group bounds"))
isnothing(gene_product_mass_group) &&
throw(ArgumentError("missing mass group specification"))
isnothing(gene_product_mass_group_bound) &&
throw(ArgumentError("missing mass group bounds"))

gpb_(gid) = (gene_product_lower_bound(model, gid), gene_product_upper_bound(model, gid))

Expand Down
6 changes: 3 additions & 3 deletions src/reconstruction/simplified_enzyme_constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Construct a model with a structure given by sMOMENT algorithm; returns a
# Arguments
- a `model` that implements the accessors `gene_product_molar_mass`,
`reaction_isozymes`.
- `total_enzyme_capacity` is the maximum "enzyme capacity" in the model.
- `total_gene_product_mass_bound` is the maximum "enzyme capacity" in the model.
# Notes
The SMOMENT algorithm only uses one [`Isozyme`](@ref) per reaction. If multiple
Expand All @@ -20,7 +20,7 @@ associated reaction.
"""
function make_simplified_enzyme_constrained_model(
model::AbstractMetabolicModel;
total_enzyme_capacity::Float64 = 0.5,
total_gene_product_mass_bound::Float64 = 0.5,
)
# helper function to rank the isozymes by relative speed
speed_enzyme(model, isozyme) =
Expand Down Expand Up @@ -88,5 +88,5 @@ function make_simplified_enzyme_constrained_model(
end
end

return SimplifiedEnzymeConstrainedModel(columns, total_enzyme_capacity, model)
return SimplifiedEnzymeConstrainedModel(columns, total_gene_product_mass_bound, model)
end
6 changes: 3 additions & 3 deletions src/types/wrappers/SimplifiedEnzymeConstrainedModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ is retained.
In the structure, the field `columns` describes the correspondence of
stoichiometry columns to the stoichiometry and data of the internal wrapped
model, and `total_enzyme_capacity` is the total bound on the enzyme capacity
model, and `total_gene_product_mass_bound` is the total bound on the enzyme capacity
consumption as specified in sMOMENT algorithm.
This implementation allows easy access to fluxes from the split reactions
Expand All @@ -59,7 +59,7 @@ $(TYPEDFIELDS)
"""
struct SimplifiedEnzymeConstrainedModel <: AbstractModelWrapper
columns::Vector{_SimplifiedEnzymeConstrainedColumn}
total_enzyme_capacity::Float64
total_gene_product_mass_bound::Float64

inner::AbstractMetabolicModel
end
Expand Down Expand Up @@ -122,5 +122,5 @@ Accessors.n_coupling_constraints(model::SimplifiedEnzymeConstrainedModel) =

Accessors.coupling_bounds(model::SimplifiedEnzymeConstrainedModel) =
let (iclb, icub) = coupling_bounds(model.inner)
(vcat(iclb, [0.0]), vcat(icub, [model.total_enzyme_capacity]))
(vcat(iclb, [0.0]), vcat(icub, [model.total_gene_product_mass_bound]))
end
7 changes: 5 additions & 2 deletions test/reconstruction/constrained_allocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
@test first(m.reactions["r6"].gene_associations).kcat_forward == 10.0


cam = make_simplified_enzyme_constrained_model(ribomodel; total_enzyme_capacity = 0.5)
cam = make_simplified_enzyme_constrained_model(
ribomodel;
total_gene_product_mass_bound = 0.5,
)

@test coupling(cam)[1, 7] == 5.0

Expand All @@ -71,7 +74,7 @@

# test inplace variant
add_virtualribosome!(m, "r6", 0.2)
cam = m |> with_simplified_enzyme_constraints(total_enzyme_capacity = 0.5)
cam = m |> with_simplified_enzyme_constraints(total_gene_product_mass_bound = 0.5)

@test coupling(cam)[1, 7] == 5.0

Expand Down
6 changes: 3 additions & 3 deletions test/reconstruction/enzyme_constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end
end

total_enzyme_capacity = 100.0
total_gene_product_mass_bound = 100.0

# set gene product bounds
for gid in genes(model)
Expand All @@ -43,7 +43,7 @@
lower_bound = [-1000.0, -1.0],
upper_bound = [nothing, 12.0],
) |>
with_enzyme_constraints(; total_enzyme_capacity)
with_enzyme_constraints(; total_gene_product_mass_bound)

opt_model = flux_balance_analysis(
gm,
Expand All @@ -64,7 +64,7 @@

@test isapprox(
sum(values(prot_concens)),
total_gene_product_mass,
total_gene_product_mass_bound,
atol = TEST_TOLERANCE,
)
@test isapprox(
Expand Down
2 changes: 1 addition & 1 deletion test/reconstruction/simplified_enzyme_constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
lower_bound = [-1000.0, -1.0],
upper_bound = [nothing, 12.0],
) |>
with_simplified_enzyme_constraints(total_enzyme_capacity = 100.0)
with_simplified_enzyme_constraints(total_gene_product_mass_bound = 100.0)

rxn_fluxes = flux_balance_analysis_dict(
simplified_enzyme_constrained_model,
Expand Down
2 changes: 1 addition & 1 deletion test/types/BalancedGrowthCommunityModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ end
ecoli |>
with_added_biomass_metabolite("BIOMASS_Ecoli_core_w_GAM") |>
with_changed_bounds(["EX_glc__D_e"]; lower_bound = [-1000.0], upper_bound = [0]) |>
with_enzyme_constraints(; total_enzyme_capacity = 100.0)
with_enzyme_constraints(; total_gene_product_mass_bound = 100.0)

ex_rxns = find_exchange_reaction_ids(ecoli)

Expand Down

0 comments on commit f72d662

Please sign in to comment.