From 64023b3a2c6268a210528e58a5a88b5e117926e0 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Wed, 3 May 2023 10:43:38 +0200 Subject: [PATCH 1/3] implement expression-limited fluxes (E-Flux like algorihm) Closes #552 --- src/analysis/expressions.jl | 11 +++++ .../types/wrappers/ExpressionLimitedModel.jl | 48 +++++++++++++++++++ src/base/utils/eflux.jl | 16 +++++++ src/reconstruction/expresisons.jl | 10 ++++ test/analysis/expressions.jl | 16 +++++++ 5 files changed, 101 insertions(+) create mode 100644 src/analysis/expressions.jl create mode 100644 src/base/types/wrappers/ExpressionLimitedModel.jl create mode 100644 src/base/utils/eflux.jl create mode 100644 src/reconstruction/expresisons.jl create mode 100644 test/analysis/expressions.jl diff --git a/src/analysis/expressions.jl b/src/analysis/expressions.jl new file mode 100644 index 000000000..32e82d37e --- /dev/null +++ b/src/analysis/expressions.jl @@ -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) diff --git a/src/base/types/wrappers/ExpressionLimitedModel.jl b/src/base/types/wrappers/ExpressionLimitedModel.jl new file mode 100644 index 000000000..e4f30612e --- /dev/null +++ b/src/base/types/wrappers/ExpressionLimitedModel.jl @@ -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 diff --git a/src/base/utils/eflux.jl b/src/base/utils/eflux.jl new file mode 100644 index 000000000..f5950c6fd --- /dev/null +++ b/src/base/utils/eflux.jl @@ -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 diff --git a/src/reconstruction/expresisons.jl b/src/reconstruction/expresisons.jl new file mode 100644 index 000000000..c2bb80d2b --- /dev/null +++ b/src/reconstruction/expresisons.jl @@ -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...) diff --git a/test/analysis/expressions.jl b/test/analysis/expressions.jl new file mode 100644 index 000000000..bbd5af8fc --- /dev/null +++ b/test/analysis/expressions.jl @@ -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 From eed8be5969eb56e7d9d327b27cca0e986d72dcf7 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Wed, 3 May 2023 10:47:06 +0200 Subject: [PATCH 2/3] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9f5b2465a..1d5443614 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From 63200ef4a223277be9d9bc069c81a0a74b81a4cf Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 8 May 2023 09:30:27 +0200 Subject: [PATCH 3/3] fix filename --- src/reconstruction/{expresisons.jl => expressions.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/reconstruction/{expresisons.jl => expressions.jl} (100%) diff --git a/src/reconstruction/expresisons.jl b/src/reconstruction/expressions.jl similarity index 100% rename from src/reconstruction/expresisons.jl rename to src/reconstruction/expressions.jl