Skip to content
Snippets Groups Projects
Commit b2953ef6 authored by Laurent Heirendt's avatar Laurent Heirendt :airplane: Committed by GitHub
Browse files

Merge pull request #46 from LCSB-BioCore/mk-fix-nice-fba-variants

fix the nice FBA variants (again)
parents 3c09bc0f d04cff63
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,35 @@ Returns a solved model from [`optimize_model`](@ref).
flux_balance_analysis(model::M, optimizer) where {M<:MetabolicModel} =
optimize_model(model, optimizer; sense = MOI.MAX_SENSE)
"""
flux_balance_analysis_vec(args...)::Union{Vector{Float64},Nothing}
A variant of FBA that returns a vector of fluxes in the same order as reactions
of the model, if the solution is found.
Arguments are passed to [`flux_balance_analysis`](@ref).
"""
function flux_balance_analysis_vec(args...)::Union{Vector{Float64},Nothing}
(optmodel, vars) = flux_balance_analysis(args...)
termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
value.(vars)
end
"""
flux_balance_analysis_dict(model::M, args...)::Union{Dict{String, Float64},Nothing} where {M <: MetabolicModel}
A variant of FBA that returns a dictionary assigning fluxes to reactions, if
the solution is found. Arguments are passed to [`flux_balance_analysis`](@ref).
"""
function flux_balance_analysis_dict(
model::M,
args...,
)::Union{Dict{String,Float64},Nothing} where {M<:MetabolicModel}
v = flux_balance_analysis_vec(model, args...)
isnothing(v) && return nothing
Dict(zip(reactions(model), v))
end
"""
fba(model::CobraModel, optimizer; objective_func::Union{Reaction, Array{Reaction, 1}}=Reaction[], weights=Float64[], solver_attributes=Dict{Any, Any}(), constraints=Dict{String, Tuple{Float64,Float64}}())
......
......@@ -34,12 +34,11 @@
@test cp.c' * sol expected_optimum
# test the "nicer output" variants
@test_broken false # reminder to implement these methods
# fluxes_vec = flux_balance_analysis_vec(cp, GLPK.Optimizer)
# @test_broken all(fluxes_vec .== sol)
# fluxes_dict = flux_balance_analysis_dict(cp, GLPK.Optimizer)
# rxns = reactions(cp)
# @test all([fluxes_dict[rxns[i]] == sol[i] for i in eachindex(rxns)])
fluxes_vec = flux_balance_analysis_vec(cp, GLPK.Optimizer)
@test all(fluxes_vec .== sol)
fluxes_dict = flux_balance_analysis_dict(cp, GLPK.Optimizer)
rxns = reactions(cp)
@test all([fluxes_dict[rxns[i]] == sol[i] for i in eachindex(rxns)])
end
@testset "Flux balance analysis with CobraModel" begin
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment