From 8001a5fcfed44ce65d43984e0bb7b35160d0dfaa Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 30 Jan 2024 13:59:35 +0100 Subject: [PATCH] convert FBA to frontend --- docs/src/examples/02-flux-balance-analysis.jl | 2 +- docs/src/examples/02a-optimizer-parameters.jl | 4 ++-- docs/src/examples/02b-model-modifications.jl | 4 ++-- src/analysis/frontend.jl | 6 +++--- src/frontend/balance.jl | 15 ++++++--------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/src/examples/02-flux-balance-analysis.jl b/docs/src/examples/02-flux-balance-analysis.jl index 7527c869..a30a51fb 100644 --- a/docs/src/examples/02-flux-balance-analysis.jl +++ b/docs/src/examples/02-flux-balance-analysis.jl @@ -43,7 +43,7 @@ model = load_model("e_coli_core.json") # is captured in the default behavior of function # [`flux_balance_analysis`](@ref): -solution = flux_balance_analysis(model, GLPK.Optimizer) +solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer) @test isapprox(solution.objective, 0.8739, atol = TEST_TOLERANCE) #src diff --git a/docs/src/examples/02a-optimizer-parameters.jl b/docs/src/examples/02a-optimizer-parameters.jl index 0bc355c9..f5d27f56 100644 --- a/docs/src/examples/02a-optimizer-parameters.jl +++ b/docs/src/examples/02a-optimizer-parameters.jl @@ -46,7 +46,7 @@ model = load_model("e_coli_core.json") # limit for IPM algorithm may now look as follows: solution = flux_balance_analysis( model, - Tulip.Optimizer; + optimizer = Tulip.Optimizer, settings = [silence, set_optimizer_attribute("IPM_IterationsLimit", 1000)], ) @@ -59,7 +59,7 @@ solution = flux_balance_analysis( solution = flux_balance_analysis( model, - Tulip.Optimizer; + optimizer = Tulip.Optimizer, settings = [set_optimizer_attribute("IPM_IterationsLimit", 2)], ) diff --git a/docs/src/examples/02b-model-modifications.jl b/docs/src/examples/02b-model-modifications.jl index cb281a9b..0ff693cc 100644 --- a/docs/src/examples/02b-model-modifications.jl +++ b/docs/src/examples/02b-model-modifications.jl @@ -78,7 +78,7 @@ model.reactions["CS"].stoichiometry import GLPK -base_solution = flux_balance_analysis(model, GLPK.Optimizer) +base_solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer) base_solution.objective # Now, for example, we can limit the intake of glucose by the model: @@ -91,7 +91,7 @@ model.reactions["EX_glc__D_e"].lower_bound = -5.0 # ...and solve the modified model: # -low_glucose_solution = flux_balance_analysis(model, GLPK.Optimizer) +low_glucose_solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer) low_glucose_solution.objective @test isapprox(low_glucose_solution.objective, 0.41559777, atol = TEST_TOLERANCE) #src diff --git a/src/analysis/frontend.jl b/src/analysis/frontend.jl index 6e051cdc..ff99e41c 100644 --- a/src/analysis/frontend.jl +++ b/src/analysis/frontend.jl @@ -24,9 +24,9 @@ front-end analysis function. function frontend_optimized_values( builder, args...; - objective = identity, + objective, output = identity, - sense, + sense = Maximal, optimizer, settings = [], kwargs..., @@ -39,8 +39,8 @@ function frontend_optimized_values( objective = objective(constraints), output = output(constraints), sense, - settings, optimizer, + settings, ) end diff --git a/src/frontend/balance.jl b/src/frontend/balance.jl index 0f52bff6..1c43ecee 100644 --- a/src/frontend/balance.jl +++ b/src/frontend/balance.jl @@ -24,14 +24,11 @@ Most arguments are forwarded to [`optimized_values`](@ref). Returns a tree with the optimization solution of the same shape as given by [`flux_balance_constraints`](@ref). """ -function flux_balance_analysis(model::A.AbstractFBCModel, optimizer; kwargs...) - constraints = flux_balance_constraints(model) - optimized_values( - constraints; - objective = constraints.objective.value, - optimizer, - kwargs..., - ) -end +flux_balance_analysis(model::A.AbstractFBCModel; kwargs...) = frontend_optimized_values( + flux_balance_constraints, + model; + objective = x -> x.objective.value, + kwargs..., +) export flux_balance_analysis