This tutorial serves as a reference to get started with distributedFBA.jl
. Download the live notebook from here.
If you are not familiar with COBRA.jl
, or how COBRA.jl
should be installed, please refer to the tutorial on COBRA.jl
.
In [ ]:
using COBRA
The connection functions are given in connect.jl
, which, if a parallel version is desired, must be included separately:
In [ ]:
using Distributed #leejm516: This is needed even though COBRA imports that package
include(joinpath(dirname(pathof(COBRA)), "connect.jl"))
You may add local workers as follows:
In [ ]:
# specify the total number of parallel workers
nWorkers = 4
# create a parallel pool
workersPool, nWorkers = createPool(nWorkers)
The IDs of the respective workers are given in workersPool
, and the number of local workers is stored in nWorkers
.
In order to be able to use the COBRA
module on all connected workers, you must invoke:
In [ ]:
@everywhere using COBRA;
In [ ]:
# specify the solver name
solverName = :GLPKMathProgInterface
# include the solver configuration file
include(joinpath(dirname(pathof(COBRA)), "../config/solverCfg.jl"))
The name of the solver can be changed as follows:
In [ ]:
# change the COBRA solver
solver = changeCobraSolver(solverName, solParams)
where solParams
is an array with the definition of the solver parameters.
In [ ]:
# download the test model
using HTTP
include(joinpath(dirname(pathof(COBRA)), "../test/getTestmodel.jl"))
getTestModel()
Load the stoichiometric matrix S from a MATLAB structure
named model in the specified .mat file
In [ ]:
model = loadModel("ecoli_core_model.mat", "S", "model");
where S
is the name of the field of the stoichiometric matrix and model
is the name of the model. Note the semicolon that suppresses the ouput of model
.
In [ ]:
# set the reaction list (only one reaction)
rxnsList = 13
# select the reaction optimization mode
# 0: only minimization
# 1: only maximization
# 2: maximization and minimization
rxnsOptMode = 1
# launch the distributedFBA process with only 1 reaction on 1 worker
minFlux, maxFlux = distributedFBA(model, solver, nWorkers=1, rxnsList=rxnsList, rxnsOptMode=rxnsOptMode);
where the reaction number 13
is solved. Note that the no extra conditions are added to the model (last function argument is false
). The minimum flux and maximum flux can hence be listed as:
In [ ]:
maxFlux[rxnsList]
In [ ]:
# launch the distributedFBA process with all reactions
minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax = distributedFBA(model, solver, nWorkers=4, optPercentage=90.0, preFBA=true);
The optimal solution of the original FBA problem can be retrieved with:
In [ ]:
optSol
The corresponding solution vector maxFlux
of the original FBA that is solved with:
In [ ]:
fbaSol
The minimum and maximum fluxes of each reaction are in:
In [ ]:
maxFlux
The flux vectors of all the reactions are stored in fvamin
and fvamax
.
In [ ]:
fvamin
In [ ]:
fvamax
In [ ]:
rxnsList = [1; 18; 10; 20:30; 90; 93; 95]
rxnsOptMode = [0; 1; 2; 2 .+ zeros(Int, length(20:30)); 2; 1; 0]
# run only a few reactions with rxnsOptMode and rxnsList
# distributedFBA(model, solver, nWorkers, optPercentage, objective, rxnsList, strategy, preFBA, rxnsOptMode)
minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver);
Note that the reactions can be input as an unordered list.
You can save the output of distributedFBA
by using:
In [ ]:
saveDistributedFBA("results.mat")
Note that the results are saved in a .mat
file that can be opened in MATLAB for further processing.
In [ ]:
rm("ecoli_core_model.mat")
rm("results.mat")