-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #800 from LCSB-BioCore/sew-fba-tests-etc
Start getting FBA to work
- Loading branch information
Showing
24 changed files
with
602 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,8 @@ Manifest.toml | |
|
||
# ignore container files | ||
*.sif | ||
|
||
# ignore models | ||
*.xml | ||
*.json | ||
*.mat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
|
||
# # Flux balance analysis | ||
# # Flux balance analysis (FBA) | ||
|
||
# Here we use [`flux_balance`](@ref) and several related functions to | ||
# find an optimal flux in the *E. coli* "core" model. We will need the model, | ||
# which we can download using [`download_model`](@ref): | ||
|
||
using COBREXA | ||
|
||
# TODO: run FBA on a FBC model | ||
download_model( | ||
"http://bigg.ucsd.edu/static/models/e_coli_core.json", | ||
"e_coli_core.json", | ||
"7bedec10576cfe935b19218dc881f3fb14f890a1871448fc19a9b4ee15b448d8", | ||
) | ||
|
||
# Additionally to COBREXA and the model format package, we will need a solver | ||
# -- let's use Tulip here: | ||
|
||
import JSONFBCModels | ||
import Tulip | ||
|
||
model = load_model("e_coli_core.json") | ||
|
||
# ## Running a FBA | ||
# | ||
# There are many possibilities on how to arrange the metabolic model into the | ||
# optimization framework and how to actually solve it. The "usual" assumed one | ||
# is captured in the default behavior of function | ||
# [`flux_balance`](@ref): | ||
|
||
solution = flux_balance(model, Tulip.Optimizer) | ||
|
||
@test isapprox(solution.objective, 0.8739, atol = TEST_TOLERANCE) #src | ||
|
||
# The result contains a tree of all optimized values in the model, including | ||
# fluxes, the objective value, and possibly others (given by what the model | ||
# contains). | ||
# | ||
# You can explore the dot notation to explore the solution, extracting e.g. the | ||
# value of the objective: | ||
|
||
solution.objective | ||
|
||
# ...or the value of the flux through the given reaction (note the solution is | ||
# not unique in FBA): | ||
|
||
solution.fluxes.PFK | ||
|
||
# ...or make a "table" of all fluxes through all reactions: | ||
|
||
collect(solution.fluxes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
# # Changing optimizer parameters | ||
# | ||
# Many optimizers require fine-tuning to produce best results. You can pass in | ||
# additional optimizer settings via the `modifications` parameter of | ||
# [`flux_balance`](@ref). These include e.g. | ||
# | ||
# - [`set_optimizer_attribute`](@ref) (typically allowing you to tune e.g. | ||
# iteration limits, tolerances, or floating-point precision) | ||
# - [`set_objective_sense`](@ref) (allowing you to change and reverse the | ||
# optimization direction, if required) | ||
# - [`silence`](@ref) to disable the debug output of the optimizer | ||
# - and even [`set_optimizer`](@ref), which changes the optimizer | ||
# implementation used (this is not quite useful in this case, but becomes | ||
# beneficial with more complex, multi-stage optimization problems) | ||
# | ||
# To demonstrate this, we'll use the usual toy model: | ||
|
||
using COBREXA | ||
import JSONFBCModels, Tulip | ||
|
||
download_model( | ||
"http://bigg.ucsd.edu/static/models/e_coli_core.json", | ||
"e_coli_core.json", | ||
"7bedec10576cfe935b19218dc881f3fb14f890a1871448fc19a9b4ee15b448d8", | ||
) | ||
|
||
model = load_model("e_coli_core.json") | ||
|
||
# Running a FBA with a silent optimizer that has slightly increased iteration | ||
# limit for IPM algorithm may now look as follows: | ||
solution = flux_balance( | ||
model, | ||
Tulip.Optimizer; | ||
modifications = [silence, set_optimizer_attribute("IPM_IterationsLimit", 1000)], | ||
) | ||
|
||
@test !isnothing(solution) #src | ||
|
||
# To see some of the effects of the configuration changes, you may e.g. | ||
# deliberately cripple the optimizer's possibilities to a few iterations, which | ||
# will cause it to fail and return no solution: | ||
|
||
solution = flux_balance( | ||
model, | ||
Tulip.Optimizer; | ||
modifications = [silence, set_optimizer_attribute("IPM_IterationsLimit", 2)], | ||
) | ||
|
||
println(solution) | ||
|
||
@test isnothing(solution) #src | ||
|
||
# Applicable optimizer attributes are documented in the documentations of the | ||
# respective optimizers. To browse the possibilities, you may want to see the | ||
# [JuMP documentation page that summarizes the references to the available | ||
# optimizers](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
# # Making adjustments to the model | ||
# | ||
# Typically, we do not need to solve the models as they come from the authors | ||
# (someone else already did that!), but we want to perform various | ||
# perturbations in the model structure and conditions, and explore how the | ||
# model behaves in the changed conditions. | ||
# | ||
# With COBREXA, there are 2 different approaches that one can take: | ||
# 1. We can change the model structure and use the changed metabolic model. | ||
# This is better for doing simple and small but systematic modifications, such | ||
# as removing metabolites, adding reactions, etc. | ||
# 2. We can intercept the pipeline that converts the metabolic model to | ||
# constraints and then to the optimizer representation, and make small | ||
# modifications along that way. This is better for various technical model | ||
# adjustments, such as using combined objectives or adding reaction-coupling | ||
# constraints. | ||
# | ||
# Here we demonstrate the first, "modelling" approach. The main advantage of | ||
# that approach is that the modified model is still a FBC model, and you can | ||
# export, save and share it via the AbstractFBCModels interace. The main | ||
# disadvantage is that the "common" FBC model interface does not easily express | ||
# various complicated constructions (communities, reaction coupling, enzyme | ||
# constraints, etc.) -- see the [example about modifying the | ||
# constraints](02c-constraint-modifications.md) for a closer look on how to | ||
# modify even such complex constructions. | ||
# | ||
# TODO here. :) |
Oops, something went wrong.