Unverified Commit 5d007ed5 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

enforce JuliaFormatter

parent 71ba9317
......@@ -97,7 +97,7 @@ function flux_balance_analysis_dict(
model::M,
args...;
kwargs...,
)::Union{Dict{String,Float64},Nothing} where {M <: MetabolicModel}
)::Union{Dict{String,Float64},Nothing} where {M<:MetabolicModel}
v = flux_balance_analysis_vec(model, args...; kwargs...)
isnothing(v) && return nothing
Dict(zip(reactions(model), v))
......@@ -141,8 +141,8 @@ solved_model = fba(model, optimizer; modifications=[modify_objective(biomass)])
function flux_balance_analysis(
model::M,
optimizer;
modifications=[(model, opt_model) -> nothing],
) where {M <: MetabolicModel}
modifications = [(model, opt_model) -> nothing],
) where {M<:MetabolicModel}
opt_model = make_optimization_model(model, optimizer)
......
......@@ -9,25 +9,25 @@ function add_cycle_free(fluxes::Dict{String,Float64})
boundary_ids = _get_boundary_reaction_ids(model)
min_objectives = zeros(Int64, 1, length(v))
for (i, reaction) in enumerate(model.reactions)
id = reaction.id
if v[i] in old_objective.terms.keys
continue
end
flux = fluxes[id]
if id in boundary_ids
lb = flux
ub = flux
elseif flux >= 0
id = reaction.id
if v[i] in old_objective.terms.keys
continue
end
flux = fluxes[id]
if id in boundary_ids
lb = flux
ub = flux
elseif flux >= 0
lb = max(0, reaction.lb)
ub = max(flux, reaction.ub)
min_objectives[i] = 1
min_objectives[i] = 1
else
lb = min(flux, reaction.lb)
ub = min(0, reaction.ub)
ub = min(0, reaction.ub)
min_objectives[i] = -1
end
set_bound(i, opt_model; ub = ub, lb = lb)
end
set_bound(i, opt_model; ub=ub, lb=lb)
end
@objective(opt_model, Min, dot(min_objectives, v))
end
end
......@@ -44,10 +44,14 @@ References:
G, Lercher MJ. Bioinformatics. 2015 Jul 1;31(13):2159-65. doi:
10.1093/bioinformatics/btv096.
"""
function add_loopless(model::M, opt_model, fluxes::Dict{String,Float64})::Union{COBREXA.JuMP.Model,Nothing} where {M <: MetabolicModel}
function add_loopless(
model::M,
opt_model,
fluxes::Dict{String,Float64},
)::Union{COBREXA.JuMP.Model,Nothing} where {M<:MetabolicModel}
constrain_objective_value(1)(model, opt_model)
add_cycle_free(fluxes)(model, opt_model)
COBREXA.JuMP.optimize!(opt_model)
COBREXA.JuMP.optimize!(opt_model)
termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
return opt_model
end
......@@ -63,7 +67,11 @@ References:
G, Lercher MJ. Bioinformatics. 2015 Jul 1;31(13):2159-65. doi:
10.1093/bioinformatics/btv096.
"""
function add_loopless_vec(model::M, opt_model, fluxes::Dict{String,Float64})::Union{Array{Float64,1},Nothing} where {M <: MetabolicModel}
function add_loopless_vec(
model::M,
opt_model,
fluxes::Dict{String,Float64},
)::Union{Array{Float64,1},Nothing} where {M<:MetabolicModel}
opt_model = add_loopless(model, opt_model, fluxes)
termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
return value.(opt_model[:x])
......@@ -80,7 +88,11 @@ References:
G, Lercher MJ. Bioinformatics. 2015 Jul 1;31(13):2159-65. doi:
10.1093/bioinformatics/btv096.
"""
function add_loopless_dict(model::M, opt_model, fluxes::Dict{String,Float64})::Union{Dict{String,Float64},Nothing} where {M <: MetabolicModel}
function add_loopless_dict(
model::M,
opt_model,
fluxes::Dict{String,Float64},
)::Union{Dict{String,Float64},Nothing} where {M<:MetabolicModel}
v = add_loopless_vec(model, opt_model, fluxes)
isnothing(v) && return nothing
return Dict(zip(reactions(model), v))
......@@ -100,17 +112,12 @@ References:
function loopless_flux_balance_analysis(
model::M,
optimizer;
modifications=[(model, opt_model) -> nothing],
)::Union{COBREXA.JuMP.Model,Nothing} where {M <: MetabolicModel}
opt_model = flux_balance_analysis(model, optimizer, modifications=modifications)
modifications = [(model, opt_model) -> nothing],
)::Union{COBREXA.JuMP.Model,Nothing} where {M<:MetabolicModel}
opt_model = flux_balance_analysis(model, optimizer, modifications = modifications)
termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
fluxes = Dict(zip(reactions(model), value.(opt_model[:x])))
return add_loopless(
model,
opt_model,
fluxes,
)
return add_loopless(model, opt_model, fluxes)
end
"""
......@@ -127,10 +134,10 @@ References:
function loopless_flux_balance_analysis_vec(
model::M,
optimizer;
modifications=[(model, opt_model) -> nothing],
)::Union{Array{Float64,1},Nothing} where {M <: MetabolicModel}
opt_model = loopless_flux_balance_analysis(model, optimizer, modifications=modifications)
modifications = [(model, opt_model) -> nothing],
)::Union{Array{Float64,1},Nothing} where {M<:MetabolicModel}
opt_model =
loopless_flux_balance_analysis(model, optimizer, modifications = modifications)
termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
return value.(opt_model[:x])
end
......@@ -149,10 +156,9 @@ References:
function loopless_flux_balance_analysis_dict(
model::M,
optimizer;
modifications=[(model, opt_model) -> nothing],
)::Union{Dict{String,Float64},Nothing} where {M <: MetabolicModel}
v = loopless_flux_balance_analysis_vec(model, optimizer, modifications=modifications)
modifications = [(model, opt_model) -> nothing],
)::Union{Dict{String,Float64},Nothing} where {M<:MetabolicModel}
v = loopless_flux_balance_analysis_vec(model, optimizer, modifications = modifications)
isnothing(v) && return nothing
return Dict(zip(reactions(model), v))
end
......@@ -52,9 +52,6 @@ function constrain_objective_value(optimum_bound)
λmin = min(optimum_bound * λ, λ * 1.0 / optimum_bound)
λmax = max(optimum_bound * λ, λ * 1.0 / optimum_bound)
old_objective = objective_function(opt_model)
@constraint(
opt_model,
λmin <= sum(old_objective) <= λmax
)
@constraint(opt_model, λmin <= sum(old_objective) <= λmax)
end
end
......@@ -29,7 +29,7 @@ function create_loopless_test_model()
add!(model, A)
add!(model, B)
add!(model, C)
@add_reactions! model begin
v1, A, 0, 1
v2, A B
......@@ -46,12 +46,20 @@ end
optimizer = Tulip.Optimizer
# first test that fba in fact does not give the loopless solution
objective = findfirst(model.reactions, "v5")
res_fba = flux_balance_analysis_dict(model, optimizer, modifications=[change_objective(objective)])
res_fba = flux_balance_analysis_dict(
model,
optimizer,
modifications = [change_objective(objective)],
)
# Check if there is any flux that exceeds the input
@test !all(abs.(values(res_fba)) .<= 1)
# Now check that the flux we get the right solution
res_loopless = loopless_flux_balance_analysis_dict(model, optimizer, modifications=[change_objective(objective)])
res_loopless = loopless_flux_balance_analysis_dict(
model,
optimizer,
modifications = [change_objective(objective)],
)
# Check that there is no flux that exceeds the input
@test all(abs.(values(res_loopless)) .<= 1)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment