Unverified Commit 07ef694a authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

[skip ci] merge tut2 comments

parent ca9f74ba
......@@ -37,10 +37,11 @@ using OSQP
# ## Flux balance analysis (FBA)
#
# Most analysis functions come in several variants that produce different types
# of output. All of them usually require a model and the `JuMP.jl`-compatible
# of output. All of them usually require a model and `JuMP.jl`-compatible
# optimizer to work in the model.
#
# In the case of FBA, you may choose from these:
# In the case of FBA, you may choose from these variants (here using the
# `Tulip` optimizer):
vec_soln = flux_balance_analysis_vec(model, Tulip.Optimizer)
#
......@@ -63,16 +64,16 @@ dict_soln = flux_balance_analysis_dict(
## this changes the objective to maximize the biomass production
change_objective("R_BIOMASS_Ecoli_core_w_GAM"),
## this fixes an exchange reaction to a negative rate
## this fixes a specific rate of the glucose exchange
change_constraint("R_EX_glc__D_e", -12, -12),
## this knocks out two genes, i.e. constraints their associated reactions to zero.
## this knocks out two genes, i.e. constrains their associated reactions to zero.
knockout(["b0978", "b0734"]), ## the gene IDs are cytochrome oxidase (CYTBD)
## actually change the original optimizer to Tulip
## ignore the optimizer specified above and change it to Tulip
change_optimizer(Tulip.Optimizer),
## specify an custom attribute of the Tulip optimizer (see Tulip docs for more)
## set a custom attribute of the Tulip optimizer (see Tulip docs for more possibilities)
change_optimizer_attribute("IPM_IterationsLimit", 110),
## explicitly tell the optimizer to maximize the new objective
......@@ -104,11 +105,13 @@ fva_maxs["R_EX_ac_e"]["R_EX_ac_e"] # get the maximal acetate exchange flux
# ## Parsimonious flux balance analysis (pFBA)
# Parsimonious flux balance analysis (here in
# [`parsimonious_flux_balance_analysis_dict`](@ref) and
# [`parsimonious_flux_balance_analysis_vec`](@ref)) finds a unique flux
# solution that minimizes the squared sum of fluxes of the system subject,
# while maintaining the same objective value as the flux balance analysis
# solution. For that reason, we need a quadratic optimizer.
# [`parsimonious_flux_balance_analysis`](@ref) finds a unique flux solution
# that minimizes the squared sum of fluxes of the system subject, while
# maintaining the same objective value as the flux balance analysis solution.
# Since we are optimizing a quadratic objective, we also need to switch to a
# quadratic optimizer. In this case, OSQP will work. We demonstrate it on the
# dictionary-returning variant of pFBA,
# [`parsimonious_flux_balance_analysis_dict`](@ref):
dict_soln = parsimonious_flux_balance_analysis_dict(
model,
......@@ -119,10 +122,11 @@ dict_soln = parsimonious_flux_balance_analysis_dict(
],
)
# The function has the expectable second variant that returns a vector of
# solutions. We use it to show how to use a different optimizer for finding the
# optimum and for solving the quadratic problem (which may be preferable if the
# optimizer qualities differ for the differing tasks). pFBA allows you to
# The function also has the expectable second variant that returns a vector of
# solutions, in [`parsimonious_flux_balance_analysis_vec`](@ref). Here, we
# utilize it to show how to use different optimizers for finding the optimum
# and for solving the quadratic problem. That may be preferable if the
# optimizer qualities differ for the differing tasks. pFBA allows you to
# specify `qp_modifications` that are applied after the original optimum is
# found, and before the quadratic part of the problem solving begins.
vec_soln = parsimonious_flux_balance_analysis_vec(
......
......@@ -15,27 +15,25 @@ Other analysis methods are either in development and testing, or may be
specified or customized by the user. Implementing new analyses is generally
feasible; you may want to watch [the `COBREXA.jl`
repository](https://github.com/LCSB-BioCore/COBREXA.jl) for newly incoming
code, or send a feature request.
analysis methods.
`COBREXA.jl` exports several helper functions that may help you in running
custom analysis methods:
`COBREXA.jl` additionally exports several helper functions that may help you in
running custom analysis methods:
- there is functionality to convert all types of [`MetabolicModel`](@ref)s to
`JuMP.jl` models, mainly the function [`make_optimization_model`](@ref),
which you may explore and analyze independently of `COBREXA.jl` using the
tools provided by `JuMP.jl`
- there is a system of analysis modifications that allows you to easily specify
various adjustment to the existing analysis methods
- you can convert all types of [`MetabolicModel`](@ref)s to `JuMP.jl` models
using [`make_optimization_model`](@ref), then you may explore and analyze the
models independently of `COBREXA.jl` using the tools provided by `JuMP.jl`
- there is a system of analysis *modifications* that allows you to easily
specify various adjustments to the existing analysis methods
!!! tip "Notebook available!"
Examples of running the balance functions are [available
Examples of running the analysis functions are [available
here](../notebooks/2_finding_balance.md).
## Optimization problem solvers
For most solving most analysis tasks, you need an optimization problem solver
that is compatible with `JuMP.jl`. You may refer to the [official list of
supported
For solving most analysis tasks, you need an optimization problem solver that
is compatible with `JuMP.jl`. You may refer to the [official list of supported
solvers](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers), but
we generally recommend to use either of these:
......@@ -47,12 +45,12 @@ we generally recommend to use either of these:
All solvers can be installed using the Julia package manger.
## Running a single Flux balance analysis
## Flux balance analysis
The above methods generally accept 2 arguments: the model, and the optimizer.
In particular, having installed e.g. GLPK from the above solvers, you can run
the FBA on [your favorite *E. Coli* core
In particular, having installed e.g. GLPK from the above optimizers, you can
run FBA on [your favorite *E. Coli* core
model](http://bigg.ucsd.edu/models/e_coli_core) as follows:
```
......@@ -64,8 +62,8 @@ opt_model = flux_balance_analysis(m, GLPK.Optimizer)
```
After a short while (the solver machinery usually needs to get precompiled
before the first use), you should get the `opt_model`, which is now the
optimized `JuMP.jl` model. It may print an information like this one:
before the first use), you should get `opt_model`, which is now an optimized
`JuMP.jl` model. It may print out information like this:
```
A JuMP Model
......@@ -98,7 +96,7 @@ getting them out of the optimized models:
## Flux variability analysis
FVA is implemented in [`flux_variability_analysis`](@ref), which returns the
usual matrix of minimal and maximal feasible flux for each reaction in the
usual matrix of minimal and maximal feasible fluxes for each reaction in the
model.
The result of calling `flux_variability_analysis(m, GLPK.Optimizer)` may look
......@@ -118,8 +116,8 @@ objective bound, getting a wider range of reaction fluxes, e.g. using
[`gamma_bounds`](@ref) (for COBRA-like γ-bound) and [`objective_bounds`](@ref)
(for a multiplicative bound around the original optimal objective).
As a result, `flux_variability_analysis(m, GLPK.Optimizer; bounds=gamma_bounds(0.8))`
will return much less constrained system:
As a result, `flux_variability_analysis(m, GLPK.Optimizer;
bounds=gamma_bounds(0.8))` will return a much less constrained system:
```
95×2 Array{Float64,2}:
......@@ -130,20 +128,21 @@ will return much less constrained system:
2.57192 3.2149
```
You may additionally restrict the analysis to the list of reactions (passing
them as the second argument), and request a dictionary of the resulting fluxes,
with [`flux_variability_analysis_dict`](@ref).
You may additionally restrict the analysis to a list of reactions (passing the
list as the second argument, see documentation of
[`flux_variability_analysis`](@ref)), or retrieve a dictionary of the resulting
fluxes with [`flux_variability_analysis_dict`](@ref).
## Parsimonious flux balance analysis
pFBA requires a solver that can handle quadratic problems. You may use `OSQP`
or `Gurobi`.
Parsimonious flux balance analysis (pFBA) requires a solver that can handle
quadratic problems. You may use e.g. `OSQP` or `Gurobi`.
Otherwise, the function behaves as `flux_balance_analysis`:
Otherwise, the function behaves just like [`flux_balance_analysis`](@ref):
- `parsimonious_flux_balance_analysis(m, OSQP.Optimizer)` will get you a
`JuMP.jl` model optimized to a slightly more realistic (parsimonious) optimum
than plain FBA,
- [`parsimonious_flux_balance_analysis`](@ref)`(m, OSQP.Optimizer)` will return
a `JuMP.jl` model optimized to a slightly more realistic (parsimonious)
optimum than plain FBA,
- [`parsimonious_flux_balance_analysis_vec`](@ref) will return the fluxes in a
vector,
- [`parsimonious_flux_balance_analysis_dict`](@ref) will return a
......@@ -157,7 +156,7 @@ or created by [`make_optimization_model`](@ref). You may need to carefully
choose the number of iterations and sample sizes to match your model; see the
documentation of [`hit_and_run`](@ref) for details.
Other than that, you can run the sampling for 100 thousand iterations as such:
As an example, you can run the sampling for 100 thousand iterations with:
```
hit_and_run(100_000, make_optimization_model(m, GLPK.Optimizer))
```
......
Supports Markdown
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