Skip to content

Commit

Permalink
Merge pull request #82 from COBREXA/sew-generalize-enzymes
Browse files Browse the repository at this point in the history
Generalize enzymes
  • Loading branch information
exaexa authored Jan 7, 2025
2 parents ed2e260 + 04c054b commit d6004be
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
version:
- '1' # This is always the latest stable release in the 1.X series
- '1.6' # LTS
- '1.10' # LTS
#- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1.9'
- uses: julia-actions/cache@v2
- name: Install dependencies
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "COBREXA"
uuid = "babc4406-5200-4a30-9033-bf5ae714c842"
authors = ["The developers of COBREXA.jl"]
version = "2.4.0"
version = "2.5.0"

[deps]
AbstractFBCModels = "5a4f3dfa-1789-40f8-8221-69268c29937c"
Expand All @@ -19,7 +19,7 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
AbstractFBCModels = "1"
Aqua = "0.7"
Clarabel = "0.6"
ConstraintTrees = "1.1"
ConstraintTrees = "1.4"
DocStringExtensions = "0.8, 0.9"
Downloads = "1"
HiGHS = "1.9"
Expand Down
8 changes: 4 additions & 4 deletions src/builders/enzymes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ function enzyme_constraints(;
) *
gene_product_amounts_name^gene_product_amounts *
gene_product_capacity_name^C.ConstraintTree(
id => C.Constraint(;
value = C.sum(
id => C.Constraint(
C.sum(
gene_product_amounts[gp].value * gpmm for
(gp, gpmm) in ((gp, gene_product_molar_mass(gp)) for gp in gps) if
!isnothing(gpmm) && haskey(gene_product_amounts, gp);
Expand Down Expand Up @@ -292,10 +292,10 @@ function simplified_enzyme_constraints(;
id => C.Constraint(;
value = C.sum(
contribution(fluxes_forward, mass_cost_forward, f) for f in fs;
init = zero(C.LinearValue),
init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64}
) + C.sum(
contribution(fluxes_reverse, mass_cost_reverse, f) for f in fs;
init = zero(C.LinearValue),
init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64}
),
bound,
) for (id, fs, bound) in capacity_limits
Expand Down
37 changes: 23 additions & 14 deletions src/frontend/enzymes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ subunit stoichiometry and turnover numbers. Use with
# Fields
$(TYPEDFIELDS)
"""
Base.@kwdef mutable struct Isozyme
Base.@kwdef mutable struct IsozymeT{T<:Real}
"""
Mapping of gene product identifiers ("genes" in FBC model nomenclature)
to their relative amount required to construct one unit of the isozyme.
"""
gene_product_stoichiometry::Dict{String,Float64}
gene_product_stoichiometry::Dict{String,T}

"Turnover number for this isozyme catalyzing the forward direction of the
reaction."
kcat_forward::Maybe{Float64} = nothing
kcat_forward::Maybe{T} = nothing

"Turnover number for this isozyme catalyzing the reverse direction of the
reaction."
kcat_reverse::Maybe{Float64} = nothing
kcat_reverse::Maybe{T} = nothing
end

export IsozymeT

"""
$(TYPEDEF)
Shortcut for `[IsozymeT](@ref){Float64}`.
"""
const Isozyme = IsozymeT{Float64}

export Isozyme

"""
Expand Down Expand Up @@ -68,12 +77,12 @@ that limits the total sum of the listed genes to the given limit.
"""
function enzyme_constrained_flux_balance_constraints(
model::A.AbstractFBCModel;
reaction_isozymes::Dict{String,Dict{String,Isozyme}},
reaction_isozymes::Dict{String,Dict{String,IsozymeT{R}}},
gene_product_molar_masses::Dict{String,Float64},
capacity::Union{Vector{Tuple{String,Vector{String},Float64}},Float64},
capacity::Union{Vector{Tuple{String,Vector{String},R}},R},
interface::Maybe{Symbol} = nothing,
interface_name = :interface,
)
) where {R<:Real}
# prepare some accessor functions for the later stuff
# TODO: might be nicer to somehow parametrize the fwd/rev directions out.
# Also there is a lot of conversion between symbols and strings, might be
Expand Down Expand Up @@ -129,9 +138,9 @@ function enzyme_constrained_flux_balance_constraints(
isozyme_gene_product_stoichiometry,
gene_product_molar_mass,
capacity_limits = capacity isa Real ?
[(:total_capacity, gene_ids, C.Between(0, capacity))] :
[(:total_capacity, gene_ids, (zero(capacity), capacity))] :
[
(Symbol(k), Symbol.(gs), C.Between(0, cap)) for (k, gs, cap) in capacity
(Symbol(k), Symbol.(gs), (zero(cap), cap)) for (k, gs, cap) in capacity
],
)
end
Expand Down Expand Up @@ -177,12 +186,12 @@ products, but identifiers of reactions.
"""
function simplified_enzyme_constrained_flux_balance_constraints(
model;
reaction_isozymes::Dict{String,Dict{String,Isozyme}},
reaction_isozymes::Dict{String,Dict{String,IsozymeT{R}}},
gene_product_molar_masses::Dict{String,Float64},
capacity::Union{Vector{Tuple{String,Vector{String},Float64}},Float64},
capacity::Union{Vector{Tuple{String,Vector{String},R}},R},
interface::Maybe{Symbol} = nothing,
interface_name = :interface,
)
) where {R<:Real}
# TODO this deserves a rewrite once more -- Isozyme struct is hiding a bit
# too much of uncertainty for the code of this thing to be short and
# concise...maybe we should have an isozyme with only one kcat which is
Expand Down Expand Up @@ -245,10 +254,10 @@ function simplified_enzyme_constrained_flux_balance_constraints(
[(
:total_capacity,
keys(constraints.fluxes),
C.Between(0, capacity),
(zero(capacity), capacity),
)] :
[
(Symbol(k), Symbol.(fs), C.Between(0, cap)) for (k, fs, cap) in capacity
(Symbol(k), Symbol.(fs), (zero(cap), cap)) for (k, fs, cap) in capacity
],
) *
:gene_product_amounts^simplified_isozyme_gene_product_amount_constraints(
Expand Down

2 comments on commit d6004be

@exaexa
Copy link
Member Author

@exaexa exaexa commented on d6004be Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122599

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.5.0 -m "<description of version>" d6004bef3141a51c3db7e56798c3e140b2eccda0
git push origin v2.5.0

Please sign in to comment.