Skip to content

Commit

Permalink
Merge pull request #779 from LCSB-BioCore/develop
Browse files Browse the repository at this point in the history
Develop → master merge for 1.5.0
  • Loading branch information
exaexa authored May 8, 2023
2 parents 4927191 + c510103 commit 9cde7b4
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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 = "1.4.4"
version = "1.5"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
11 changes: 11 additions & 0 deletions src/analysis/expressions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

"""
$(TYPEDSIGNATURES)
Build an [`ExpressionLimitedModel`](@ref).
"""
make_expression_limited_model(
model::MetabolicModel;
relative_expression::Dict{String,Float64},
bounding_function::Function = expression_probabilistic_bounds,
) = ExpressionLimitedModel(; relative_expression, bounding_function, inner = model)
48 changes: 48 additions & 0 deletions src/base/types/wrappers/ExpressionLimitedModel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

"""
$(TYPEDEF)
[`ExpressionLimitedModel`](@ref) follows the methodology of the E-Flux algorithm to
constraint the flux through the reactions in order to simulate the limited
expression of genes (and thus the limited availability of the gene products).
Use [`make_expression_limited_model`](@ref) or [`with_expression_limits`](@ref)
to construct the models.
E-Flux algorithm is closer described by: *Colijn, Caroline, Aaron Brandes,
Jeremy Zucker, Desmond S. Lun, Brian Weiner, Maha R. Farhat, Tan-Yun Cheng, D.
Branch Moody, Megan Murray, and James E. Galagan. "Interpreting expression data
with metabolic flux models: predicting Mycobacterium tuberculosis mycolic acid
production." PLoS computational biology 5, no. 8 (2009): e1000489*.
# Fields
$(TYPEDFIELDS)
"""
Base.@kwdef struct ExpressionLimitedModel <: ModelWrapper
"""
Relative gene expression w.r.t. to some chosen reference; the normalization
and scale of the values should match the expectations of the
`bounding_function`.
"""
relative_expression::Dict{String,Float64}

"The wrapped model."
inner::MetabolicModel

"""
Function used to calculate the new reaction bounds from expression.
In [`make_expression_limited_model`](@ref) this defaults to
[`expression_probabilistic_bounds`](@ref).
"""
bounding_function::Function
end

COBREXA.unwrap_model(m::ExpressionLimitedModel) = m.inner

function COBREXA.bounds(m::ExpressionLimitedModel)::Tuple{Vector{Float64},Vector{Float64}}
(lbs, ubs) = bounds(m.inner)
lims = collect(
m.bounding_function(m.relative_expression, reaction_gene_association(m.inner, rid)) for rid in reactions(m.inner)
)
(lbs .* lims, ubs .* lims)
end
16 changes: 16 additions & 0 deletions src/base/utils/eflux.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

"""
$(TYPEDSIGNATURES)
Create E-Flux-like bounds for a reaction that requires gene products given by
`grr`, with expression "choke" data given by relative probabilities (between 0
and 1) in `relative_expression`.
"""
function expression_probabilistic_bounds(
relative_expression::Dict{String,Float64},
grr::Maybe{Vector{Vector{String}}},
)::Float64
isnothing(grr) && return 1.0
lup(g) = get(relative_expression, g, 1.0)
1 - prod(1 - prod(lup.(gr)) for gr in grr)
end
10 changes: 10 additions & 0 deletions src/reconstruction/expressions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
$(TYPEDSIGNATURES)
Specifies a model variant which adds extra semantics of the
[`ExpressionLimitedModel`](@ref), simulating the E-Flux algorithm. The
arguments are forwarded to [`make_expression_limited_model`](@ref). Intended
for usage with [`screen`](@ref).
"""
with_expression_limits(; kwargs...) =
model -> make_expression_limited_model(model; kwargs...)
16 changes: 16 additions & 0 deletions test/analysis/expressions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

@testset "Expression-limited models" begin
orig_model = load_model(model_paths["e_coli_core.json"])

model =
orig_model |>
with_expression_limits(relative_expression = Dict(genes(orig_model) .=> 0.5))

bs = Dict(reactions(model) .=> bounds(model)[1])

@test getindex.(Ref(bs), ["PFK", "ENO", "ACALD"]) == [0, -500, -750]

fluxes = flux_balance_analysis_dict(model, Tulip.Optimizer)

@test isapprox(fluxes["BIOMASS_Ecoli_core_w_GAM"], 0.21386, atol = TEST_TOLERANCE)
end

2 comments on commit 9cde7b4

@exaexa
Copy link
Collaborator Author

@exaexa exaexa commented on 9cde7b4 May 8, 2023

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/83092

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 v1.5.0 -m "<description of version>" 9cde7b498cdb8ea6c7e25d41518f2490835c85d7
git push origin v1.5.0

Please sign in to comment.