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

fixed merge of #777 #778

Merged
merged 2 commits into from
May 3, 2023
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
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/expresisons.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