Skip to content

Commit

Permalink
split off the enzyme FBA frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jan 31, 2024
1 parent 1e3f78d commit b07ba69
Showing 1 changed file with 69 additions and 60 deletions.
129 changes: 69 additions & 60 deletions src/frontend/enzymes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@ export Isozyme
"""
$(TYPEDSIGNATURES)
Run a basic enzyme-constrained flux balance analysis on `model`. The enzyme
model is parameterized by `reaction_isozymes`, which is a mapping of reaction
Construct a enzyme-constrained flux-balance constraint system. The model is
parameterized by `reaction_isozymes`, which is a mapping of reaction
identifiers to [`Isozyme`](@ref) descriptions.
Additionally, one typically wants to supply `gene_product_molar_masses` to
describe the weights of enzyme building material, and `capacity` which limits
the mass of enzymes in the whole model.
Additionally, the computation requires `gene_product_molar_masses` to describe
the weights of enzyme building material, and `capacity`, which limits the mass
of enzymes in the whole model.
`capacity` may be a single number, which sets the limit for "all described
enzymes". Alternatively, `capacity` may be a vector of identifier-genes-limit
triples that make a constraint (identified by the given identifier) that limits
the listed genes to the given limit.
"""
function enzyme_constrained_flux_balance_analysis(
function enzyme_constrained_flux_balance_constraints(
model::A.AbstractFBCModel;
reaction_isozymes::Dict{String,Dict{String,Isozyme}},
gene_product_molar_masses::Dict{String,Float64},
capacity::Union{Vector{Tuple{String,Vector{String},Float64}},Float64},
optimizer,
settings = [],
)
constraints = flux_balance_constraints(model)

Expand All @@ -78,63 +76,74 @@ function enzyme_constrained_flux_balance_analysis(
)

# connect all parts with constraints
constraints =
constraints *
:directional_flux_balance^sign_split_constraints(
positive = constraints.fluxes_forward,
negative = constraints.fluxes_reverse,
signed = constraints.fluxes,
) *
:isozyme_flux_forward_balance^isozyme_flux_constraints(
constraints.isozyme_forward_amounts,
constraints.fluxes_forward,
(rid, isozyme) -> maybemap(
x -> x.kcat_forward,
maybeget(reaction_isozymes, string(rid), string(isozyme)),
),
) *
:isozyme_flux_reverse_balance^isozyme_flux_constraints(
constraints.isozyme_reverse_amounts,
constraints.fluxes_reverse,
(rid, isozyme) -> maybemap(
x -> x.kcat_reverse,
maybeget(reaction_isozymes, string(rid), string(isozyme)),
),
) *
:gene_product_isozyme_balance^gene_product_isozyme_constraints(
constraints.gene_product_amounts,
(constraints.isozyme_forward_amounts, constraints.isozyme_reverse_amounts),
(rid, isozyme) -> maybemap(
x -> [(Symbol(k), v) for (k, v) in x.gene_product_stoichiometry],
maybeget(reaction_isozymes, string(rid), string(isozyme)),
constraints *
:directional_flux_balance^sign_split_constraints(
positive = constraints.fluxes_forward,
negative = constraints.fluxes_reverse,
signed = constraints.fluxes,
) *
:isozyme_flux_forward_balance^isozyme_flux_constraints(
constraints.isozyme_forward_amounts,
constraints.fluxes_forward,
(rid, isozyme) -> maybemap(
x -> x.kcat_forward,
maybeget(reaction_isozymes, string(rid), string(isozyme)),
),
) *
:isozyme_flux_reverse_balance^isozyme_flux_constraints(
constraints.isozyme_reverse_amounts,
constraints.fluxes_reverse,
(rid, isozyme) -> maybemap(
x -> x.kcat_reverse,
maybeget(reaction_isozymes, string(rid), string(isozyme)),
),
) *
:gene_product_isozyme_balance^gene_product_isozyme_constraints(
constraints.gene_product_amounts,
(constraints.isozyme_forward_amounts, constraints.isozyme_reverse_amounts),
(rid, isozyme) -> maybemap(
x -> [(Symbol(k), v) for (k, v) in x.gene_product_stoichiometry],
maybeget(reaction_isozymes, string(rid), string(isozyme)),
),
) *
:gene_product_capacity^(
capacity isa Float64 ?
C.Constraint(
value = sum(
gpa.value * gene_product_molar_masses[String(gp)] for
(gp, gpa) in constraints.gene_product_amounts
),
) *
:gene_product_capacity^(
capacity isa Float64 ?
C.Constraint(
bound = C.Between(0, capacity),
) :
C.ConstraintTree(
Symbol(id) => C.Constraint(
value = sum(
gpa.value * gene_product_molar_masses[String(gp)] for
(gp, gpa) in constraints.gene_product_amounts
constraints.gene_product_amounts[Symbol(gp)].value *
gene_product_molar_masses[gp] for gp in gps
),
bound = C.Between(0, capacity),
) :
C.ConstraintTree(
Symbol(id) => C.Constraint(
value = sum(
constraints.gene_product_amounts[Symbol(gp)].value *
gene_product_molar_masses[gp] for gp in gps
),
bound = C.Between(0, limit),
) for (id, gps, limit) in capacity_limits
)
bound = C.Between(0, limit),
) for (id, gps, limit) in capacity_limits
)

optimized_values(
constraints;
objective = constraints.objective.value,
optimizer,
settings,
)
end

export enzyme_constrained_flux_balance_constraints

"""
$(TYPEDSIGNATURES)
Perform the enzyme-constrained flux balance analysis on the `model` and return the solved constraint system.
Arguments are forwarded to
[`enzyme_constrained_flux_balance_constraints`](@ref); solver configuration
arguments are forwarded to [`optimized_values`](@ref).
"""
enzyme_constrained_flux_balance_analysis(model::A.AbstractFBCModel; kwargs...) =
frontend_optimized_values(
enzyme_constrained_flux_balance_constraints,
model;
objective = x -> x.objective.value,
kwargs...,
)

export enzyme_constrained_flux_balance_analysis

0 comments on commit b07ba69

Please sign in to comment.