Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open the enzyme builder functions #813

Merged
merged 6 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/src/examples/05-enzyme-constrained-models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ m.enzymes.b2417.bound = C.Between(0.0, 0.1) # for fun, change the bounds of the
# attach the enzyme mass balances
m = add_enzyme_constraints!(
m,
reaction_isozymes,
gene_molar_masses,
[("total_proteome_bound", A.genes(model), total_enzyme_capacity)];
reaction_isozymes;
fluxes = m.fluxes, # mount enzyme constraints to these fluxes
enzymes = m.enzymes, # enzyme variables
)

# add capacity limitation
m *=
:total_proteome_bound^enzyme_capacity(
m.enzymes,
gene_molar_masses,
A.genes(model),
total_enzyme_capacity,
)

# solve the model
ec_solution = optimized_constraints(
m;
Expand Down
30 changes: 19 additions & 11 deletions src/builders/enzymes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,37 @@ end
"""
$(TYPEDSIGNATURES)

Create enzyme capacity limitation.
Create a enzyme capacity limitation. Bounds the gene product masses (concentration
* molar mass) of gene products in `enzyme_ids` by `capacity_bound`.
"""
function enzyme_capacity(
enzymes::C.ConstraintTree,
gene_molar_masses::Dict{String,Float64},
enzyme_ids::Vector{String},
capacity::Float64,
capacity_bound::C.Bound,
)
C.Constraint(
value = sum(
enzymes[Symbol(gid)].value * gene_molar_masses[gid] for gid in enzyme_ids
),
bound = C.Between(0.0, capacity),
bound = capacity_bound,
)
end

"""
$(TYPEDSIGNATURES)

Create an enzyme capacity limitation. Bounds the gene product masses
(concentration * molar mass) of gene products in `enzyme_ids` between `[0, capacity]`.
"""
enzyme_capacity(
enzymes::C.ConstraintTree,
gene_molar_masses::Dict{String,Float64},
enzyme_ids::Vector{String},
capacity::Float64,
) = enzyme_capacity(enzymes, gene_molar_masses, enzyme_ids, C.Between(0.0, capacity))


export enzyme_capacity

"""
Expand All @@ -164,9 +179,7 @@ assign kcats to reactions. Use [`SimpleIsozyme`](@ref) when in doubt.
"""
function add_enzyme_constraints!(
m::C.ConstraintTree,
reaction_isozymes::Dict{String,Dict{String,T}},
gene_molar_masses::Dict{String,Float64},
capacity_limitations::Vector{Tuple{String,Vector{String},Float64}};
reaction_isozymes::Dict{String,Dict{String,T}};
fluxes = m.fluxes,
enzymes = m.enzymes,
) where {T<:Isozyme}
Expand Down Expand Up @@ -225,11 +238,6 @@ function add_enzyme_constraints!(
reaction_isozymes,
)

# add capacity limitations
for (id, gids, cap) in capacity_limitations
m *= Symbol(id)^enzyme_capacity(enzymes, gene_molar_masses, gids, cap)
end

m
end

Expand Down
13 changes: 7 additions & 6 deletions src/frontend/enzyme_constrained_flux_balance_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ function enzyme_constrained_flux_balance_analysis(
# create enzyme variables
m += :enzymes^enzyme_variables(model)

m = add_enzyme_constraints!(
m,
reaction_isozymes,
gene_molar_masses,
capacity_limitations,
)
# add enzyme equality constraints (stoichiometry)
m = add_enzyme_constraints!(m, reaction_isozymes)

# add capacity limitations
for (id, gids, cap) in capacity_limitations
m *= Symbol(id)^enzyme_capacity(m.enzymes, gene_molar_masses, gids, cap)
end

for rid in Symbol.(unconstrain_reactions)
m.fluxes[rid].bound = C.Between(-1000.0, 1000.0)
Expand Down
77 changes: 0 additions & 77 deletions test/enzyme_model.jl

This file was deleted.

1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ run_test_file("data_downloaded.jl")

@testset "COBREXA test suite" begin
run_doc_examples()
include("enzyme_model.jl")
run_test_file("aqua.jl")
end

Expand Down