Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
COBREXA.jl
Commits
cc30e843
Commit
cc30e843
authored
Apr 01, 2021
by
Miroslav Kratochvil
🚴
Browse files
fix the nice FBA variants (again)
Closes #39
parent
f2b6185e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/analysis/fba.jl
View file @
cc30e843
...
...
@@ -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...)::Maybe{Vector{Float64}}
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
...
)
::
Maybe
{
Vector
{
Float64
}}
(
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...)::Maybe{Dict{String, Float64}} 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
...
,
)
::
Maybe
{
Dict
{
String
,
Float64
}}
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}}())
...
...
test/analysis/fba.jl
View file @
cc30e843
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment