diff --git a/.artenolis.yml b/.artenolis.yml index 744e32e..86b84ec 100644 --- a/.artenolis.yml +++ b/.artenolis.yml @@ -10,38 +10,45 @@ script: # add MATLAB to the path - if [ "$ARCH" == "Linux" ]; then - export PATH="/mnt/prince-data/MATLAB/$MATLAB_VER/bin:$PATH"; + export PATH="$PATH:$ARTENOLIS_SOFT_PATH/MATLAB/$MATLAB_VER/bin"; fi - # clone the COBRA Toolbox - - rm -rf /tmp/cobratoolbox-cobrajl - - git clone https://github.com/opencobra/cobratoolbox.git /tmp/cobratoolbox-cobrajl --depth=1 - - cd /tmp/cobratoolbox-cobrajl - - git submodule update --init --remote --no-fetch --depth=1 - # change to the current directory - cd $CURRENT_DIR # rename the cloned folder - cd .. && cp -r $NODE_LABELS COBRA && cd COBRA + # change the test dependencies on Linux and macOS (ARTENOLIS) + - if [ "$ARCH" == "Linux" ] || [ "$ARCH" == "macOS" ]; then + CURRENT_DIR=`pwd`; + cd ~/tmp/cobratoolbox-cobrajl; + git pull origin master; + cd $CURRENT_DIR; + perl -i -pe's/test = \["GLPKMathProgInterface", "GLPK", "Test"\]/test = \["GLPKMathProgInterface", "GLPK", "Test", "MAT", "MATLAB", "Gurobi", "CPLEX"\]/g' Project.toml; + fi + # launch the tests - bash .artenolis/runtests.sh - # clean up the build directory - - cd .. && rm -rf COBRA - after_success: - - if [ "$ARCH" == "Linux" ]; then /mnt/prince-data/JULIA/$JULIA_VER/bin/julia --color=yes -e 'cd(Pkg.dir("COBRA")); using Coverage; tmp=process_folder(); Codecov.submit(tmp, verbose=false); Coveralls.submit(tmp);'; fi + + # submit coverage report + - if [[ "$ARCH" == "Linux" && "$JULIA_VER" == "v1.2.0" ]]; then + $ARTENOLIS_SOFT_PATH/julia/$JULIA_VER/bin/julia --color=yes -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; + fi # set environment variables for documentation deployment - - if [ "$ARCH" == "Linux" ]; then + - if [[ "$ARCH" == "Linux" && "$JENKINS_PULL_REQUEST" != "True" ]]; then export TRAVIS_BRANCH=$GIT_BRANCH; export TRAVIS_PULL_REQUEST=false; var=$GIT_URL; export TRAVIS_REPO_SLUG=${var:7:${#var}}; export TRAVIS_OS_NAME=$label; export TRAVIS_JULIA_VERSION=$JULIA_VER; + $ARTENOLIS_SOFT_PATH/julia/$JULIA_VER/bin/julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'; + $ARTENOLIS_SOFT_PATH/julia/$JULIA_VER/bin/julia --project=docs/ docs/make.jl; fi - # deploy documentation - - if [ "$ARCH" == "Linux" ]; then /mnt/prince-data/JULIA/$JULIA_VER/bin/julia --color=yes -e 'cd(Pkg.dir("COBRA")); include(joinpath("docs", "makeDoc.jl"))'; fi +after_script: + # clean up the build directory + - cd .. && rm -rf COBRA diff --git a/.artenolis/runtests.sh b/.artenolis/runtests.sh index 921a1f1..7a894c5 100644 --- a/.artenolis/runtests.sh +++ b/.artenolis/runtests.sh @@ -5,39 +5,21 @@ echo "MATLAB_VER = $MATLAB_VER" # launch the test script if [ "$ARCH" == "Linux" ]; then - if [ "$JULIA_VER" == "v0.6.4" ]; then - # remove th julia directory to clean the installation directory - rm -rf ~/.julia/v0.6/COBRA - - # add the COBRA module - /mnt/prince-data/JULIA/$JULIA_VER/bin/julia --color=yes -e 'Pkg.clone(pwd()); cd(Pkg.dir("COBRA")); Pkg.test(pwd(), coverage=true);' - - elif [ "$JULIA_VER" == "v0.7.0" ]; then - # add the COBRA module - /mnt/prince-data/JULIA/$JULIA_VER/bin/julia --color=yes -e 'using Pkg; Pkg.clone(pwd())' - fi + $ARTENOLIS_SOFT_PATH/julia/$JULIA_VER/bin/julia --color=yes -e 'import Pkg; Pkg.clone(pwd()); Pkg.test("COBRA", coverage=true); Pkg.rm("COBRA");' elif [ "$ARCH" == "macOS" ]; then - # remove th julia directory to clean the installation directory - rm -rf ~/.julia/v0.6/COBRA - caffeinate -u & - /Applications/Julia-$JULIA_VER.app/Contents/Resources/julia/bin/julia --color=yes -e 'Pkg.clone(pwd()); cd(Pkg.dir("COBRA")); Pkg.test(pwd());' + /Applications/Julia-$JULIA_VER.app/Contents/Resources/julia/bin/julia --color=yes -e 'import Pkg; Pkg.clone(pwd()); Pkg.test("COBRA"); Pkg.rm("COBRA");' elif [ "$ARCH" == "windows" ]; then - if [ "$JULIA_VER" == "v0.6.4" ]; then - # remove th julia directory to clean the installation directory - rm -rf ~/.julia/v0.6/COBRA - - unset Path - nohup "D:\\JULIA\\$JULIA_VER\\\bin\\julia.exe" --color=yes -e 'import Base; ENV["MATLAB_HOME"]="D:\\MATLAB\\$(ENV["MATLAB_VER"])"; Pkg.clone(pwd()); cd(Pkg.dir("COBRA")); Pkg.test(pwd());' > output.log & PID=$! + unset Path + nohup "$ARTENOLIS_SOFT_PATH\\julia\\$JULIA_VER\\\bin\\julia.exe" --color=yes -e 'import Pkg; Pkg.clone(pwd()); Pkg.test("COBRA"); Pkg.rm("COBRA");' > output.log & PID=$! - # follow the log file - tail -n0 -F --pid=$! output.log 2>/dev/null + # follow the log file + tail -n0 -F --pid=$! output.log 2>/dev/null - # wait until the background process is done - wait $PID - fi + # wait until the background process is done + wait $PID fi CODE=$? diff --git a/.gitignore b/.gitignore index 95d41b6..732e04e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,5 @@ docs/build/ docs/tutorial/results.mat results/* test/testModels - -docs/src/tutorials.md \ No newline at end of file +Manifest.toml +docs/src/tutorials.md diff --git a/.travis.yml b/.travis.yml index eae055c..8604576 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,11 @@ os: - linux julia: - - 0.6 - - 0.7 + - 1.0 - nightly matrix: allow_failures: - - julia: 0.7 - julia: nightly notifications: @@ -25,18 +23,3 @@ addons: - libgmp-dev - libglpk-dev -git: - depth: 99999 - -before_install: - - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - -script: - # update all packages - - julia --color=yes -e 'Pkg.update();' - - # temporary addition for julia 0.6 until new version of MAT tagged - - julia --color=yes -e 'Pkg.add("MAT"); Pkg.checkout("MAT")' - - # add and test the COBRA module - - julia --color=yes -e 'Pkg.clone(pwd()); Pkg.test("COBRA")' \ No newline at end of file diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..98c043e --- /dev/null +++ b/Project.toml @@ -0,0 +1,32 @@ +name = "COBRA" +uuid = "58298e0b-d05c-52ec-a210-0694647ebfc7" +version = "0.3.0" + +[deps] +CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0" +Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" +GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" +GLPKMathProgInterface = "3c7084bd-78ad-589a-b5bb-dbd673274bea" +HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MAT = "23992714-dd62-5051-b70f-ba57cb901cac" +MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[compat] +HTTP = ">= 0.8.0" +MAT = ">= 0.5.0" +julia = "1" + +[extras] +CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0" +GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" +GLPKMathProgInterface = "3c7084bd-78ad-589a-b5bb-dbd673274bea" +Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b" +MAT = "23992714-dd62-5051-b70f-ba57cb901cac" +MATLAB = "10e44e05-a98a-55b3-a45b-ba969058deb6" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["GLPKMathProgInterface", "GLPK", "Test"] \ No newline at end of file diff --git a/README.md b/README.md index dcfcb16..0aa76ff 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,9 @@ Shall no solvers be detected on your system, error messages may be thrown when t The code has been benchmarked against the `fastFVA` implementation [[3](#References-1)]. A test model `ecoli_core_model.mat` [[4](#References-1)] can be used to pre-compile the code and can be downloaded using ```Julia -julia> using Requests -julia> include("$(Pkg.dir("COBRA"))/test/getTestModel.jl") +julia> using HTTP, COBRA +julia> pkgDir = joinpath(dirname(pathof(COBRA)), "..") +julia> include(pkgDir*"/test/getTestModel.jl") julia> getTestModel() ``` diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index bed306d..0000000 --- a/REQUIRE +++ /dev/null @@ -1,4 +0,0 @@ -julia 0.6 0.7 -MathProgBase 0.6.1 -MAT 0.3.1 -Requests 0.4.1 diff --git a/config/sshCfg.jl b/config/sshCfg.jl index ef1942e..10a3829 100644 --- a/config/sshCfg.jl +++ b/config/sshCfg.jl @@ -7,21 +7,21 @@ #------------------------------------------------------------------------------------------- -sshWorkers = Array{Dict{Any, Any}}(3) +sshWorkers = Array{Dict{Any, Any}}(undef, 3) -sshWorkers[1,:] = Dict( "usernode" => "first.last@server1.com", +sshWorkers[1] = Dict( "usernode" => "first.last@server1.com", "procs" => 8, "dir" => `"~"/COBRA.jl/`, "flags" => `-6 -p8022`, "exename"=> "/usr/bin/julia/bin/./julia") -sshWorkers[2,:] = Dict( "usernode" => "first.last@server2.com", +sshWorkers[2] = Dict( "usernode" => "first.last@server2.com", "procs" => 16, "dir" => `"~"/COBRA.jl/`, "flags" => "-p22", "exename"=> "/usr/bin/julia/bin/./julia") -sshWorkers[3,:] = Dict( "usernode" => "first.last@server3.com", +sshWorkers[3] = Dict( "usernode" => "first.last@server3.com", "procs" => 32, "dir" => `"~"/COBRA.jl/`, "flags" => "-4 -p9997", diff --git a/docs/makeDoc.jl b/docs/make.jl similarity index 69% rename from docs/makeDoc.jl rename to docs/make.jl index 37c9914..94e07a9 100644 --- a/docs/makeDoc.jl +++ b/docs/make.jl @@ -7,24 +7,9 @@ #------------------------------------------------------------------------------------------- +import Pkg using Documenter - -if !isdefined(:includeCOBRA) includeCOBRA = true end - -if includeCOBRA - include("../src/COBRA.jl") - include("../src/load.jl") - include("../src/solve.jl") - include("../src/distributedFBA.jl") - include("../src/connect.jl") - include("../src/checkSetup.jl") - include("../src/tools.jl") - - # only include PALM.jl if MATLAB is present - if sizeof(Pkg.installed("MATLAB")) > 0 - include("../src/PALM.jl") - end -end +using COBRA # special concatenation of tutorials until issue 701 is fixed: # https://github.com/JuliaDocs/Documenter.jl/issues/701 @@ -34,7 +19,8 @@ end currentDir = pwd() # concatenate tutorial files -cd("$(Pkg.dir("COBRA"))/tutorials") +pkgDir = joinpath(dirname(pathof(COBRA))) +cd(pkgDir*"/../tutorials") # define list of tutorials to be concatenated tutorials = ["tutorial-COBRA.jl.md", "tutorial-distributedFBA.jl.md", "tutorial-PALM.jl.md"] @@ -42,12 +28,13 @@ tutorials = ["tutorial-COBRA.jl.md", "tutorial-distributedFBA.jl.md", "tutorial- # concatenate the tutorials properly speaking cat = "" for tut in tutorials + global cat tmp = read(tut, String) cat = cat * tmp end # set all headers one level lower -cat = replace(cat, "\n#", "\n##") +cat = replace(cat, "\n#" => "\n##") # write out the tutorial to new file open("tutorials.md", "w") do f @@ -56,12 +43,12 @@ open("tutorials.md", "w") do f end # move the tutorials.md file to the docs folder -mv("tutorials.md", "$(Pkg.dir("COBRA"))/docs/src/tutorials.md", remove_destination=true) +mv("tutorials.md", pkgDir*"/../docs/src/tutorials.md", force=true) # change back to the old directory cd(currentDir) -makedocs(format = :html, +makedocs(format = Documenter.HTML(), sitename = "COBRA.jl", pages = Any[ # Compat: `Any` for 0.4 compat "index.md", @@ -76,9 +63,8 @@ makedocs(format = :html, ) deploydocs(repo = "github.com/opencobra/COBRA.jl.git", - julia = get(ENV, "JULIA_VER", ""), target = "build", - make = nothing, - deps = nothing, - latest = get(ENV, "GIT_BRANCH", "") + branch = "gh-pages", + devbranch = "origin/develop", + versions = ["stable" => "v^", "v#.#"] ) diff --git a/docs/src/beginnerGuide.md b/docs/src/beginnerGuide.md index 349ec4d..bb4a6ff 100644 --- a/docs/src/beginnerGuide.md +++ b/docs/src/beginnerGuide.md @@ -3,7 +3,8 @@ What is Julia? -------------- -"*Julia is a high-level, high-performance dynamic programming language […]*". You may read more about Julia [here](http://julialang.org). +"*Julia is a high-level, high-performance dynamic programming language […]*". +You may read more about Julia [here](http://julialang.org). How do I get Julia? ------------------- @@ -36,7 +37,7 @@ If you need help, you can always type a `?`at the Julia REPL. For instance, if y ? abs ``` -You may also find the [FAQ section](faq.html) of this documentation interesting, especially if you are running into issues. +You may also find the [FAQ](@ref) of this documentation interesting, especially if you are running into issues. How do I install a solver? -------------------------- @@ -72,11 +73,6 @@ Pkg.add("GLPKMathProgInterface") Other supported solvers, such as `CPLEX`, `Clp`, `Gurobi`, or `Mosek`, may be installed in a similar way. Their respective interfaces are described [here](https://github.com/JuliaOpt). If you want to use `CPLEX`, you must follow the installation instructions [here](https://github.com/JuliaOpt/CPLEX.jl). Most importantly, make sure that you set the `LD_LIBRARY_PATH` environment variable. -Now I have a solver, and I have Julia. What is next? ------------------------------------------------------- - -You are now all set to install `COBRA.jl`. Follow the installation instructions [here](index.html). You may then also follow this [tutorial](cobratutorial.html) to get you started. - There is a tutorial, but I cannot open it. What should I do? ------------------------------------------------------------ diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 045069e..386361a 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -4,7 +4,8 @@ In order to load currently defined solver parameters, the following file may be included in the script, which defines the `solParams` array: ```julia -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +pkgDir = joinpath(dirname(pathof(COBRA)), "..") +include(pkgDir*"/config/solverCfg.jl") ``` Then, the `COBRA` solver can be set with: ```julia @@ -49,7 +50,8 @@ solParams = [ A parallel pool with workers on SSH nodes can be created using: ```julia -include("$(Pkg.dir("COBRA"))/src/connect.jl") +pkgDir = joinpath(dirname(pathof(COBRA)), "..") +include(pkgDir*"/src/connect.jl") workersPool, nWorkers = createPool(12, true, "mySSHCfg.jl") ``` which will connect 12 local workers, and all workers defined in `mySSHCfg.jl`. An example connection file is provided in the `config/` folder of the `COBRA` package installation folder. diff --git a/docs/src/faq.md b/docs/src/faq.md index b6fb39a..bce810d 100644 --- a/docs/src/faq.md +++ b/docs/src/faq.md @@ -1,4 +1,4 @@ -# Frequently Asked Questions (FAQ) +# [Frequently Asked Questions (FAQ)](@id FAQ) Why can't I build packages in Julia? ------------------------------------ @@ -64,4 +64,4 @@ How can I get the latest version of `COBRA.jl` If you want to enjoy the latest untagged (but eventually unstable) features of `COBRA.jl`, do the following from within `Julia`: ```Julia julia> Pkg.checkout("COBRA", "develop") -``` \ No newline at end of file +``` diff --git a/docs/src/functions.md b/docs/src/functions.md index e0a22f0..603d617 100644 --- a/docs/src/functions.md +++ b/docs/src/functions.md @@ -2,50 +2,44 @@ ## connect.jl -```@docs -createPool +```@autodocs +Modules = [COBRA] +Pages = ["connect.jl"] ``` ## checkSetup.jl -```@docs -checkPackage -checkSysConfig +```@autodocs +Modules = [COBRA] +Pages = ["checkSetup.jl"] ``` ## distributedFBA.jl -```@docs -preFBA! -splitRange -loopFBA -distributedFBA -printSolSummary -saveDistributedFBA +```@autodocs +Modules = [COBRA] +Pages = ["distributedFBA.jl"] ``` ## load.jl -```@docs -LPproblem -loadModel +```@autodocs +Modules = [COBRA] +Pages = ["load.jl"] ``` ## PALM.jl -```@docs -shareLoad -loopModels -PALM +```@autodocs +Modules = [COBRA] +Pages = ["PALM.jl"] ``` ## solve.jl -```@docs -SolverConfig -buildCobraLP -changeCobraSolver -solveCobraLP +```@autodocs +Modules = [COBRA] +Pages = ["solve.jl"] ``` ## tools.jl -```@docs -findRxnIDS -convertUnitRange +```@autodocs +Modules = [COBRA] +Pages = ["tools.jl"] ``` diff --git a/docs/src/tutorials.md b/docs/src/tutorials.md index 508802f..5689b86 100644 --- a/docs/src/tutorials.md +++ b/docs/src/tutorials.md @@ -1,7 +1,6 @@ # Tutorials - -## Tutorial - COBRA.jl +# Tutorial - COBRA.jl This tutorial serves as a quick start guide as well as an interactive reference for more advanced users. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). @@ -59,7 +58,6 @@ The code has been benchmarked against the `fastFVA` implementation [[3](#Referen 2. [Heirendt, L & Arreckx, S. et al. Creation and analysis of biochemical constraint-based models: the COBRA Toolbox v3.0 (submitted), 2017.](https://github.com/opencobra/cobratoolbox) 3. [Steinn, G. et al. Computationally efficient flux variability analysis. BMC Bioinformatics, 11(1):1–3, 2010.](https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-489) 4. [Orth, J. et al. Reconstruction and use of microbial metabolic networks: the core escherichia coli metabolic model as an educational guide. EcoSal Plus, 2010.](http://gcrg.ucsd.edu/Downloads/EcoliCore) - ## Tutorial - distributedFBA.jl This tutorial serves as a reference to get started with `distributedFBA.jl`. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). @@ -77,7 +75,8 @@ The connection functions are given in `connect.jl`, which, if a parallel version ```julia -include("$(Pkg.dir("COBRA"))/src/connect.jl") +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: @@ -97,7 +96,7 @@ In order to be able to use the `COBRA` module on all connected workers, you must ```julia -@everywhere using COBRA +@everywhere using COBRA; ``` ### Define and change the COBRA solver @@ -106,17 +105,15 @@ Before the COBRA solver can be defined, the solver parameters and configuration - `:GLPKMathProgInterface` - `:CPLEX` -- `:Clp` - `:Gurobi` -- `:Mosek` ```julia ## specify the solver name -solverName = :Gurobi #:GLPKMathProgInterface +solverName = :GLPKMathProgInterface ## include the solver configuration file -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(joinpath(dirname(pathof(COBRA)), "../config/solverCfg.jl")) ``` The name of the solver can be changed as follows: @@ -136,8 +133,8 @@ As a test and as an example, the *E.coli* core model may be loaded as: ```julia ## download the test model -using Requests -include("$(Pkg.dir("COBRA"))/test/getTestModel.jl") +using HTTP +include(joinpath(dirname(pathof(COBRA)), "../test/getTestmodel.jl")) getTestModel() ``` @@ -227,7 +224,7 @@ You may now input several reactions with various `rxnsOptMode` values to run spe ```julia rxnsList = [1; 18; 10; 20:30; 90; 93; 95] -rxnsOptMode = [0; 1; 2; 2+zeros(Int, length(20:30)); 2; 1; 0] +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) @@ -264,7 +261,6 @@ rm("results.mat") 3. [Steinn, G. et al. Computationally efficient flux variability analysis. BMC Bioinformatics, 11(1):1–3, 2010.](https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-489) 4. [Orth, J. et al. Reconstruction and use of microbial metabolic networks: the core escherichia coli metabolic model as an educational guide. EcoSal Plus, 2010.](http://gcrg.ucsd.edu/Downloads/EcoliCore) - ## Tutorial - PALM.jl This tutorial serves as a reference to get started with `PALM.jl`. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). @@ -277,10 +273,11 @@ Please make sure to have the following packages installed: `COBRA.jl`, `MATLAB`, ```julia -##= -Pkg.add("COBRA") + +import Pkg; +##Pkg.add("COBRA") Pkg.add("MATLAB") -=# + ``` ### Writing a MATLAB script @@ -293,7 +290,8 @@ The MATLAB script can be saved as `scriptFile.m` in any folder. For illustration ```julia -run(`cat $(Pkg.dir("COBRA"))/test/scriptFile.m`) +using COBRA +run(`cat $(joinpath(dirname(pathof(COBRA)), "../test/scriptFile.m"))`) ``` Note that the variables marked with `PALM_` are the ones defined within Julia. @@ -306,11 +304,11 @@ If you already have a working installation of the COBRA Toolbox, you may skip th **Advanced users** may also want to install the COBRA Toolbox directly installed from Julia. You must have `git` (or `gitBash` on Windows) installed - see [requirements](https://opencobra.github.io/cobratoolbox/stable/installation.html#system-requirements). -For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `/tmp` directory. This may take a while, depending on the speed of your internet connection. +For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `~/tmp` directory. This may take a while, depending on the speed of your internet connection. ```julia -installDir = "/tmp/cobratoolbox" +installDir = homedir()*"/tmp/cobratoolbox" ``` @@ -323,7 +321,12 @@ run(`rm -rf $installDir`) ```julia run(`git clone --depth=1 --recurse-submodules https://github.com/opencobra/cobratoolbox.git $installDir`); -info("The COBRA Toolbox has been cloned successfully to the $installDir directory.") +@info "The COBRA Toolbox has been cloned successfully to the $installDir directory." +``` + + +```julia +run(`mkdir "~/tmp/cobratoolbox"`) ``` **Tip:** When using `PALM.jl`, it is advised to add the `--recurse-submodules` flag. This will speed up the simultaneous initialisations on several workers. @@ -334,7 +337,8 @@ Similarly to `distributedFBA.jl`, the workers may be added using `createPool`, g ```julia -include("$(Pkg.dir("COBRA"))/src/connect.jl") +using Distributed +include(joinpath(dirname(pathof(COBRA)), "connect.jl")) ``` @@ -350,8 +354,8 @@ After initializing the workers, the packages must be loaded on each worker: ```julia -@everywhere using COBRA -@everywhere using MATLAB +@everywhere using COBRA; +@everywhere using MATLAB; ``` ### Sharing the load @@ -406,7 +410,7 @@ Now, all variables are defined, and `PALM.jl` is ready to be launched: ```julia -PALM(modelDir, "$(Pkg.dir("COBRA"))/test/scriptFile.m", nWorkers, "modelCharacteristics.mat", varsCharact, installDir) +PALM(modelDir, "$(joinpath(dirname(pathof(COBRA)), "../test/scriptFile.m"))"; nMatlab=nWorkers, outputFile="modelCharacteristics.mat", varsCharact=varsCharact, cobraToolboxDir=installDir) ``` The output file that contains the values of the variables defined in `varsCharact` for each model is `modelCharacteristics.mat`. This file can be read back into Julia by using: diff --git a/src/COBRA.jl b/src/COBRA.jl index 8b77e52..bdfac87 100644 --- a/src/COBRA.jl +++ b/src/COBRA.jl @@ -17,9 +17,10 @@ The documentation is here: http://opencobra.github.io/COBRA.jl module COBRA # include the load file to load a model of .mat format - using MAT - using MathProgBase - if sizeof(Pkg.installed("MATLAB")) > 0 + import Pkg + using SparseArrays, Distributed, LinearAlgebra + using MAT, MathProgBase + if "MATLAB" in keys(Pkg.installed()) using MATLAB end @@ -30,7 +31,7 @@ module COBRA include("solve.jl") include("distributedFBA.jl") include("tools.jl") - if sizeof(Pkg.installed("MATLAB")) > 0 + if "MATLAB" in keys(Pkg.installed()) include("PALM.jl") end diff --git a/src/PALM.jl b/src/PALM.jl index 8178e52..5f5e08d 100644 --- a/src/PALM.jl +++ b/src/PALM.jl @@ -46,13 +46,13 @@ See also: `createPool()` and `PALM` function shareLoad(nModels::Int, nMatlab::Int = 2, printLevel::Int=1, dryRun::Bool=false) if printLevel > 0 && dryRun - info("Load sharing is determined without actively changing the number of connected workers (dryRun = true).") + @info "Load sharing is determined without actively changing the number of connected workers (dryRun = true)." end # Make sure that not more processes are launched than there are models (load ratio >= 1) if nMatlab > nModels if printLevel > 0 - warn("Number of workers ($nMatlab) exceeds the number of models ($nModels).") + @warn "Number of workers ($nMatlab) exceeds the number of models ($nModels)." end nMatlab = nModels @@ -65,7 +65,7 @@ function shareLoad(nModels::Int, nMatlab::Int = 2, printLevel::Int=1, dryRun::Bo end if printLevel > 0 - warn("Number of workers reduced to number of models for ideal load distribution.\n") + @warn "Number of workers reduced to number of models for ideal load distribution.\n" end end @@ -94,17 +94,17 @@ function shareLoad(nModels::Int, nMatlab::Int = 2, printLevel::Int=1, dryRun::Bo if quotientModels < remainderModels - 1 || remainderModels < 1 if printLevel > 0 - print_with_color(:red, "\n >> Load sharing is not fair. Consider adjusting the maximum poolsize.\n") + printstyled("\n >> Load sharing is not fair. Consider adjusting the maximum poolsize.\n", color=:red) end else if printLevel > 0 - print_with_color(:yellow, "\n >> Load sharing is almost ideal.\n") + printstyled("\n >> Load sharing is almost ideal.\n", color=:yellow) end end else if printLevel > 0 println(" >> Every worker will run ", quotientModels, " model(s).") - print_with_color(:green, " >> Load sharing is ideal.\n") + printstyled(" >> Load sharing is ideal.\n", color=:green) end end @@ -167,7 +167,7 @@ function loopModels(dir, p, scriptName, dirContent, startIndex, endIndex, varsCh #local nModels if endIndex >= startIndex # declaration of local data array - data = Array{Union{Int,Float64,AbstractString}}(localnModels, nCharacteristics + 1) + data = Array{Union{Int,Float64,AbstractString}}(undef, localnModels, nCharacteristics + 1) for k = 1:localnModels PALM_iModel = k #+ (p - 1) * nModels @@ -182,7 +182,7 @@ function loopModels(dir, p, scriptName, dirContent, startIndex, endIndex, varsCh MATLAB.@mput PALM_modelFile MATLAB.@mput PALM_dir MATLAB.@mput PALM_printLevel - eval(parse("MATLAB.mat\"run('$scriptName')\"")) + MATLAB.eval_string("run('" * scriptName * "')") for i = 1:nCharacteristics data[k, i + 1] = MATLAB.get_variable(Symbol(varsCharact[i])) @@ -215,7 +215,7 @@ Results are saved in the `outputFile`. - `nMatlab`: Number of desired MATLAB sessions (default: 2) - `outputFile`: Name of `.mat` file to save the result table named "summaryData" (default name: "PALM_data.mat") -- `cobraToolboxDir`: Directory of the COBRA Toolbox (default: "~/cobratoolbox") +- `cobraToolboxDir`: Directory of the COBRA Toolbox (default: homedir()*"/cobratoolbox") - `printLevel`: Verbose level (default: 1). Mute all output with `printLevel = 0`. # OUTPUTS @@ -226,25 +226,25 @@ File with the name specified in `outputFile`. - Minimum working example ```julia -julia> PALM("~/models", "characteristics") +julia> PALM(homedir()*"/models", "characteristics") ``` - Running `PALM` on 12 MATLAB sessions ```julia -julia> PALM("~/models", "characteristics", 12, "characteristicsResults.mat") +julia> PALM(homedir()*"/models", "characteristics", 12, "characteristicsResults.mat") ``` See also: `loopModels()` and `shareLoad()` """ -function PALM(dir, scriptName, nMatlab::Int=2, outputFile::AbstractString="PALM_data.mat", varsCharact=[], cobraToolboxDir=ENV["HOME"]*Base.Filesystem.path_separator*"cobratoolbox", printLevel::Int=1) +function PALM(dir, scriptName; nMatlab::Int=2, outputFile::AbstractString="PALM_data.mat", varsCharact=[], cobraToolboxDir=homedir()*Base.Filesystem.path_separator*"cobratoolbox", printLevel::Int=1, useCOBRA::Bool=true) # read the content of the directory dirContent = readdir(dir) if printLevel > 0 - info("Directory with $(length(dirContent)) models read successfully.") + @info "Directory with $(length(dirContent)) models read successfully." end nWorkers, quotientModels, remainderModels = shareLoad(length(dirContent), nMatlab) @@ -261,19 +261,32 @@ function PALM(dir, scriptName, nMatlab::Int=2, outputFile::AbstractString="PALM_ nCharacteristics = length(varsCharact) # prepare array for storing remote references - R = Array{Future}(nWorkers) + R = Array{Future}(undef, nWorkers, 2) # declare an array to store the indices for each worker - indicesWorkers = Array{Int}(nWorkers, 3) + indicesWorkers = Array{Int}(undef, nWorkers, 3) # declare an empty array for storing a summary of all data - summaryData = Array{Union{Int,Float64,AbstractString}}(nModels + 1, nCharacteristics + 1) + summaryData = Array{Union{Int,Float64,AbstractString}}(undef, nModels + 1, nCharacteristics + 1) + + # clone the COBRA Toolbox if it is not yet available + # Note: there is no need for the submodules to be cloned + if !isdir(cobraToolboxDir) + cmd = "git clone git@github.com:opencobra/cobratoolbox.git $cobraToolboxDir" + @info cmd + run(`sh -c $cmd`) + end - for (p, pid) in enumerate(workers()) - @spawnat (p + 1) begin - # clone a copy to a tmp folder as the cobtratoolbox is updated at runtime - if !isdir("/tmp/test-ct-$p") - run(`git clone $cobraToolboxDir /tmp/test-ct-$p`) + # clone a copy to a tmp folder as the cobtratoolbox is updated at runtime + if useCOBRA + for (p, pid) in enumerate(workers()) + @sync @spawnat (p + 1) begin + @info homedir()*Base.Filesystem.path_separator*"tmp"*Base.Filesystem.path_separator*"test-ct-$p" + if !isdir(homedir()*Base.Filesystem.path_separator*"tmp"*Base.Filesystem.path_separator*"test-ct-$p") + cmd = "git clone $cobraToolboxDir "*homedir()*Base.Filesystem.path_separator*"tmp"*Base.Filesystem.path_separator*"test-ct-$p" + @info cmd + run(`sh -c $cmd`) + end end end end @@ -282,21 +295,26 @@ function PALM(dir, scriptName, nMatlab::Int=2, outputFile::AbstractString="PALM_ @sync for (p, pid) in enumerate(workers()) if printLevel > 0 - info("Launching MATLAB session on worker $(p+1).") + @info "Launching MATLAB session on worker $(p+1)." end - # adding the model directory and eventual subdirectories to the MATLAB path - # Note: the fileseparator `/` also works on Windows systems if git Bash has been installed - @async R[p] = @spawnat (p+1) begin - eval(parse("mat\"addpath(genpath('/tmp/test-ct-$p'))\"")) - eval(parse("mat\"run('/tmp/test-ct-$p/initCobraToolbox.m');\"")) + if useCOBRA + slash = Base.Filesystem.path_separator + # adding the model directory and eventual subdirectories to the MATLAB path + @async R[p] = @spawnat (p+1) begin + addPath = "addpath(genpath('"*homedir()*slash*"tmp"*slash*"test-ct-"*string(p)*"'))" + runInit = "run('"*homedir()*slash*"tmp"*slash*"test-ct-$p"*slash*"initCobraToolbox.m')" + @info addPath + @info runInit + MATLAB.eval_string(addPath) + MATLAB.eval_string(runInit) + end end - end # print an informative message if printLevel > 0 - info("> MATLAB sessions initializing") + @info "> MATLAB sessions initializing" end @sync for (p, pid) in enumerate(workers()) @@ -316,7 +334,7 @@ function PALM(dir, scriptName, nMatlab::Int=2, outputFile::AbstractString="PALM_ localnModels = quotientModels if printLevel > 0 - info("(case1): Worker $(p+1) runs $localnModels models: from $startIndex to $endIndex") + @info "(case1): Worker $(p+1) runs $localnModels models: from $startIndex to $endIndex" end else endIndex = Int((p+1) * quotientModels + remainderModels) @@ -331,7 +349,7 @@ function PALM(dir, scriptName, nMatlab::Int=2, outputFile::AbstractString="PALM_ localnModels = endIndex - startIndex + 1 if printLevel > 0 - info("(case 2): Worker $(p+1) runs $localnModels models: from $startIndex to $endIndex") + @info "(case 2): Worker $(p+1) runs $localnModels models: from $startIndex to $endIndex" end end diff --git a/src/checkSetup.jl b/src/checkSetup.jl index bbba6ea..622cba7 100644 --- a/src/checkSetup.jl +++ b/src/checkSetup.jl @@ -30,12 +30,12 @@ See also: `using`, `isdir()` function checkPackage(pkgName, printLevel::Int=1) try - eval(Expr(:using, pkgName)) + eval(:(using $pkgName)) return true catch if printLevel > 0 - print_with_color(:yellow, "Package ",string(pkgName), " is not installed. ", - "In order to use $pkgName, you must first run `Pkg.add(\"$pkgName\")`\n") + printstyled("Package ",string(pkgName), " is not installed. ", + "In order to use $pkgName, you must first run `Pkg.add(\"$pkgName\")`\n"; color=:yellow) end return false end @@ -64,14 +64,14 @@ See also: `MathProgBase`, `checkPackage()` function checkSysConfig(printLevel::Int=1) if printLevel > 0 - print_with_color(:yellow, "\n >> Checking the system's configuration ...\n\n") + printstyled("\n >> Checking the system's configuration ...\n\n"; color=:yellow) end #initialize a vector for storing the packages packages = [] # initialize a vector with supported LP solvers - LPsolvers = [:Clp, :GLPKMathProgInterface, :Gurobi, :CPLEX, :Mosek] + LPsolvers = [ :GLPKMathProgInterface, :Gurobi, :CPLEX] #:Clp, :Mosek if checkPackage(:MathProgBase, printLevel) @@ -81,7 +81,7 @@ function checkSysConfig(printLevel::Int=1) if checkPackage(pkgName, printLevel) if printLevel > 0 - print_with_color(:green, string(pkgName), " is installed.\n") + printstyled(string(pkgName), " is installed.\n"; color=:green) end push!(packages, pkgName) end @@ -90,6 +90,9 @@ function checkSysConfig(printLevel::Int=1) if string(pkgName) == "GLPKMathProgInterface" checkPackage(:GLPK, printLevel) end + if string(pkgName) == "Mosek" + checkPackage(:MosekTools, printLevel) + end end end @@ -101,7 +104,7 @@ function checkSysConfig(printLevel::Int=1) # print a success message if the solver is installed catch if printLevel > 0 - print_with_color(:green, "\n >> Done. $(length(packages)) solvers are installed and ready to use.\n") + printstyled("\n >> Done. $(length(packages)) solvers are installed and ready to use.\n"; color=:green) end return packages diff --git a/src/connect.jl b/src/connect.jl index 191fb8d..409683d 100644 --- a/src/connect.jl +++ b/src/connect.jl @@ -8,8 +8,8 @@ #------------------------------------------------------------------------------------------- if "JENKINS" in keys(ENV) - info("JENKINS CI server detected. Workers will be added with test environment configuration.") - include("$JULIA_HOME/../share/julia/test/testenv.jl") + @info "JENKINS CI server detected. Workers will be added with test environment configuration." + include(Sys.BINDIR*"/../share/julia/test/testenv.jl") addprocsCOBRA = addprocs_with_testenv else addprocsCOBRA = addprocs @@ -54,7 +54,7 @@ See also: `workers()`, `nprocs()`, `addprocs()`, `gethostname()` """ -function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::String="$(Pkg.dir("COBRA"))/config/sshCfg.jl", printLevel::Int=1) +function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::String=joinpath(dirname(pathof(COBRA)))*"/../config/sshCfg.jl", printLevel::Int=1) # load cores on remote nodes if connectSSH @@ -68,7 +68,7 @@ function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::S include(connectionFile) if printLevel > 0 - print_with_color(:green, "Done.\n") + printstyled("Done.\n"; color=:green) end else error("Connection file (filename: `$connectionFile`) is unreadable or not accessible.") @@ -91,32 +91,32 @@ function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::S # connect all required workers if nWorkers <= 1 if printLevel > 0 - info("Sequential version - Depending on the model size, expect long execution times.") + @info "Sequential version - Depending on the model size, expect long execution times." end else if printLevel > 0 - info("Parallel version - Connecting the $nWorkers workers ...") + @info "Parallel version - Connecting the $nWorkers workers ..." end # print a warning for already connected threads if nprocs() > nWorkers if printLevel > 0 - print_with_color(:blue, "$nWorkers workers already connected. No further workers to connect.\n") + printstyled("$nWorkers workers already connected. No further workers to connect.\n"; color=:blue) end end # add local threads if localWorkers > 0 && nworkers() < nWorkers - addprocsCOBRA(localWorkers, topology = :master_slave) + addprocsCOBRA(localWorkers, topology = :master_worker) if printLevel > 0 - print_with_color(:blue, "$(nworkers()) local workers are connected. (+1) on host: $(gethostname())\n") + printstyled("$(nworkers()) local workers are connected. (+1) on host: $(gethostname())\n"; color=:blue) end end # add remote threads if connectSSH && nworkers() < nWorkers && isfile(connectionFile) if printLevel > 0 - info("Connecting SSH nodes ...") + @info "Connecting SSH nodes ..." end # loop through the workers to be connected @@ -132,13 +132,13 @@ function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::S # add threads when the SSH login is successful if successConnect - addprocsCOBRA([(sshWorkers[i]["usernode"], sshWorkers[i]["procs"])], topology = :master_slave, + addprocsCOBRA([(sshWorkers[i]["usernode"], sshWorkers[i]["procs"])], topology = :master_worker, tunnel = true, dir = sshWorkers[i]["dir"], sshflags = sshWorkers[i]["flags"], exeflags=`--depwarn=no`, exename = sshWorkers[i]["exename"]) # return a status update if printLevel > 0 - info("Connected ", sshWorkers[i]["procs"], " workers on ", sshWorkers[i]["usernode"]) + @info "Connected ", sshWorkers[i]["procs"], " workers on ", sshWorkers[i]["usernode"] end # increase the counter of remote workers diff --git a/src/distributedFBA.jl b/src/distributedFBA.jl index 1be2f7c..bd4839d 100644 --- a/src/distributedFBA.jl +++ b/src/distributedFBA.jl @@ -65,12 +65,12 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m # provide a warning when the optPercentage is higher than 90% if optPercentage > OPT_PERCENTAGE if printLevel > 0 - print_with_color(:cyan, "The value of optPercentage is higher than 90%. The solution process might take longer than expected.\n\n") + printstyled("The value of optPercentage is higher than 90%. The solution process might take longer than expected.\n\n"; color=:cyan) end end # determine constraints for the correct space (0-100% of the full space) - if countnz(model.c) > 0 + if count(!iszero, model.c) > 0 hasObjective = true # solve the original LP problem @@ -99,7 +99,7 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m # add a condition if the LP has an extra condition based on the FBA solution if hasObjective if printLevel > 0 - print_with_color(:blue, "preFBA! [osenseStr = $osenseStr]: FBAobj = $FBAobj, optPercentage = $optPercentage, objValue = optPercentage * FBAobj = $objValue, norm(fbaSol) = $(norm(fbaSol)).\n\n") + printstyled("preFBA! [osenseStr = $osenseStr]: FBAobj = $FBAobj, optPercentage = $optPercentage, objValue = optPercentage * FBAobj = $objValue, norm(fbaSol) = $(norm(fbaSol)).\n\n"; color=:blue) end # add a row in the stoichiometric matrix @@ -118,7 +118,7 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m return FBAobj, fbaSol else if printLevel > 0 - print_with_color(:blue, "No objective set (`c` is zero). objValue and fbaSol not defined. optPercentage = $optPercentage.\n\n") + printstyled("No objective set (`c` is zero). objValue and fbaSol not defined. optPercentage = $optPercentage.\n\n"; color=:blue) end return nothing end @@ -177,8 +177,8 @@ function splitRange(model, rxnsList, nWorkers::Int=1, strategy::Int=0, printLeve # output the average load per worker and the splitting strategy if printLevel > 0 - print_with_color(:blue, "Average load per worker: $pRxnsWorker reactions ($nWorkers workers).\n") - print_with_color(:blue, "Splitting strategy is $strategy.\n\n") + printstyled("Average load per worker: $pRxnsWorker reactions ($nWorkers workers).\n"; color=:blue) + printstyled("Splitting strategy is $strategy.\n\n"; color=:blue) end # define indices for each worker p @@ -342,8 +342,8 @@ See also: `distributeFBA()`, `MathProgBase.HighLevelInterface` """ -function loopFBA(m, rxnsList, nRxns::Int, rxnsOptMode=2 + zeros(Int, length(rxnsList)), iRound::Int=0, pid::Int=1, - resultsDir::String="$(Pkg.dir("COBRA"))/results", logFiles::Bool=false, onlyFluxes::Bool=false, printLevel::Int=1) +function loopFBA(m, rxnsList, nRxns::Int, rxnsOptMode=2 .+ zeros(Int, length(rxnsList)), iRound::Int=0, pid::Int=1, + resultsDir::String=joinpath(dirname(pathof(COBRA)), "..")*"/results", logFiles::Bool=false, onlyFluxes::Bool=false, printLevel::Int=1) # initialize vectors and counters retObj = zeros(nRxns) @@ -523,8 +523,8 @@ See also: `preFBA!()`, `splitRange()`, `buildCobraLP()`, `loopFBA()`, or `fetch( """ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Float64, Int64}=0.0, objective::String="max", - rxnsList=1:length(model.rxns), strategy::Int=0, rxnsOptMode=2 + zeros(Int, length(model.rxns)), - preFBA::Bool=false, saveChunks::Bool=false, resultsDir::String="$(Pkg.dir("COBRA"))/results", + rxnsList=1:length(model.rxns), strategy::Int=0, rxnsOptMode=2 .+ zeros(Int, length(model.rxns)), + preFBA::Bool=false, saveChunks::Bool=false, resultsDir::String=joinpath(dirname(pathof(COBRA)), "..")*"/results", logFiles::Bool=false, onlyFluxes::Bool=false, printLevel::Int=1) # convert type of optPercentage @@ -539,19 +539,19 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo optSol, fbaSol = preFBA!(model, solver, optPercentage, objective) solTime = time() - startTime if printLevel > 0 - print_with_color(:green, "Original FBA solved. Solution time: $solTime s.\n\n") + printstyled("Original FBA solved. Solution time: $solTime s.\n\n"; color=:green) end else # throw a warning message if preFBA = false and optPercentage > 0% if optPercentage > 0.0 - warn("The value of optPercentage is > 0%, but preFBA = false. Set preFBA = true in order to take optPercentage into account.\n\n") + @warn "The value of optPercentage is > 0%, but preFBA = false. Set preFBA = true in order to take optPercentage into account.\n\n" end # define the optSol and fbaSol variables optSol = NaN fbaSol = NaN * zeros(length(model.rxns)) if printLevel > 0 - print_with_color(:blue, "Original FBA. No additional constraints have been added.\n") + printstyled("Original FBA. No additional constraints have been added.\n"; color=:blue) end end @@ -570,14 +570,14 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo if nRxns > 60000 && !saveChunks && !onlyFluxes saveChunks = true if printLevel > 0 - info("Trying to solve a model of $nRxns reactions. `saveChunks` has been set to `true`.") + @info "Trying to solve a model of $nRxns reactions. `saveChunks` has been set to `true`." end end # set saveChunks to false when only the maxFlux and minFlux arguments are requested if saveChunks && onlyFluxes saveChunks = false - warn("`saveChunks` has been set to `false`.\n") + @warn "`saveChunks` has been set to `false`.\n" end if saveChunks || logFiles @@ -585,11 +585,11 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo if !isdir("$resultsDir") mkdir("$resultsDir") if printLevel > 0 - print_with_color(:green, "Directory `$resultsDir` created.\n") + printstyled("Directory `$resultsDir` created.\n"; color=:green) end else if printLevel > 0 - print_with_color(:cyan, "Directory `$resultsDir` already exists.\n") + printstyled("Directory `$resultsDir` already exists.\n"; color=:cyan) end end end @@ -598,7 +598,7 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo if logFiles && !isdir("$resultsDir/logs") mkdir("$resultsDir/logs") if printLevel > 0 - print_with_color(:green, "Directory `$resultsDir/logs` created.\n") + printstyled("Directory `$resultsDir/logs` created.\n"; color=:green) end end @@ -622,7 +622,7 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo fvamin = NaN * zeros(1, 1) fvamax = NaN * zeros(1, 1) if printLevel > 0 - info("Only the `minFlux` and `maxFlux` vectors will be calculated (solver solution status available in `statussolmin` and `statussolmax`).\n") + @info "Only the `minFlux` and `maxFlux` vectors will be calculated (solver solution status available in `statussolmin` and `statussolmax`).\n" end end @@ -634,33 +634,33 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo if nRxnsList > nRxns rxnsList = 1:nRxns if printLevel > 0 - warn("The `rxnsList` has more reactions than in the model. `rxnsList` shorted to the maximum number of reactions.") + @warn "The `rxnsList` has more reactions than in the model. `rxnsList` shorted to the maximum number of reactions." end end if nRxns != nRxnsList if printLevel > 0 - println(" >> Only $nRxnsList ", (nRxnsList == 1) ? "reaction" : "reactions", " of $nRxns will be solved (~ $(nRxnsList * 100 / nRxns) \%).\n") + println(" >> Only $nRxnsList ", (nRxnsList == 1) ? "reaction" : "reactions", " of $nRxns will be solved (~ $(nRxnsList * 100 / nRxns) %).\n") end else if printLevel > 0 - println(" >> All $nRxns reactions of the model will be solved (100 \%).\n") + println(" >> All $nRxns reactions of the model will be solved (100 %).\n") end end # sanity checks for large models if nRxnsList > 20000 && nWorkers <= 4 if printLevel > 0 - warn("\nTrying to solve more than 20000 optimization problems on fewer than 4 workers. Memory might be limited.") - info(" >> Try running this analysis on a cluster, or use a larger parallel pool.\n") + @warn "\nTrying to solve more than 20000 optimization problems on fewer than 4 workers. Memory might be limited." + @info " >> Try running this analysis on a cluster, or use a larger parallel pool.\n" end end # sanity check for few reactions on a large pool if nRxnsList < nWorkers if printLevel > 0 - warn("\nThe parallel pool of workers is larger than the number of reactions being solved.") - info(" >> Consider reducing the size of the parallel pool to free system resources.\n") + @warn "\nThe parallel pool of workers is larger than the number of reactions being solved." + @info " >> Consider reducing the size of the parallel pool to free system resources.\n" end end @@ -670,7 +670,7 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo rxnsKey = splitRange(model, rxnsList, nWorkers, strategy, printLevel) # prepare array for storing remote references - R = Array{Future}(nWorkers, 2) + R = Array{Future}(undef, nWorkers, 2) # distribution across workers @sync for (p, pid) in enumerate(workers()) @@ -723,7 +723,7 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo # close the 2 file streams close(filemin) close(filemax) - print_with_color(:green, "Done.\n") + printstyled("Done.\n"; color=:green) else fvamin[:, rxnsList[rxnsKey[p]]] = fetch(R[p, 1])[2][:, :] fvamax[:, rxnsList[rxnsKey[p]]] = fetch(R[p, 2])[2][:, :] @@ -784,7 +784,7 @@ function printSolSummary(testFile::String, optSol, maxFlux, minFlux, solTime, nW # print a solution summary if printLevel > 0 println("\n-- Solution summary --\n") - print_with_color(:blue, "$testFile\n") + printstyled("$testFile\n"; color=:blue) if !isnan(optSol) println(" Original FBA obj.val ", optSol) end @@ -844,12 +844,12 @@ julia> saveDistributedFBA("myDirectory/myResults.mat") - Home location ```julia -julia> saveDistributedFBA(ENV["HOME"]*"/myResults.mat") +julia> saveDistributedFBA(homedir()*"/myResults.mat") ``` - Save minFlux and maxFlux variables ```julia -julia> saveDistributedFBA(ENV["HOME"]*"/myResults.mat", ["minFlux", "maxFlux"]) +julia> saveDistributedFBA(homedir()*"/myResults.mat", ["minFlux", "maxFlux"]) ``` """ @@ -866,17 +866,17 @@ function saveDistributedFBA(fileName::String, vars::Array{String,1} = ["minFlux" for i = 1:length(vars) if isdefined(Main, Symbol(vars[i])) if printLevel > 0 - print("Saving $(vars[i]) (T:> $(typeof(eval(Main, Symbol(vars[i]))))) ...") + print("Saving $(vars[i]) (T:> $(typeof(Main.eval(Symbol(vars[i]))))) ...") end # write the variable to the file - write(file, "$(vars[i])", convertUnitRange( eval(Main, Symbol(vars[i])) )) + write(file, "$(vars[i])", convertUnitRange(Main.eval(Symbol(vars[i])) )) # increment the counter countSavedVars = countSavedVars + 1 if printLevel > 0 - print_with_color(:green, "Done.\n") + printstyled("Done.\n"; color=:green) end end end @@ -887,10 +887,10 @@ function saveDistributedFBA(fileName::String, vars::Array{String,1} = ["minFlux" # print a status message if countSavedVars > 0 if printLevel > 0 - print_with_color(:green, "All available variables saved to $fileName.\n") + printstyled("All available variables saved to $fileName.\n"; color=:green) end else - warn("No variables saved.") + @warn "No variables saved." end end diff --git a/src/load.jl b/src/load.jl index 70dcb46..46664d0 100644 --- a/src/load.jl +++ b/src/load.jl @@ -36,7 +36,7 @@ end #------------------------------------------------------------------------------------------- """ - loadModel(fileName, matrixAS, modelName, modelFields, printLevel) + loadModel(fileName, modelName::String="model", printLevel) Function used to load a COBRA model from an existing .mat file @@ -46,9 +46,7 @@ Function used to load a COBRA model from an existing .mat file # OPTIONAL INPUTS -- `matrixAS`: String to distinguish the name of stoichiometric matrix ("S" or "A", default: "S") - `modelName`: String with the name of the model structure (default: "model") -- `modelFields`: Array with strings of fields of the model structure (default: ["ub", "lb", "osense", "c", "b", "csense", "rxns", "mets"]) - `printLevel`: Verbose level (default: 1). Mute all output with `printLevel = 0`. # OUTPUTS @@ -64,18 +62,12 @@ julia> loadModel("myModel.mat") - Full input/output example ```julia -julia> model = loadModel("myModel.mat", "A", "myModelName", ["ub","lb","osense","c","b","csense","rxns","mets"]); +julia> model = loadModel("myModel.mat", "myModelName", 2); ``` -# Notes - -- `osense` is set to "max" (osense = -1) by default -- All entries of `A`, `b`, `c`, `lb`, `ub` are of type float - See also: `MAT.jl`, `matopen()`, `matread()` """ - -function loadModel(fileName::String, matrixAS::String="S", modelName::String="model", modelFields::Array{String,1}=["ub", "lb", "osense", "c", "b", "csense", "rxns", "mets"], printLevel::Int=1) +function loadModel(fileName::String, modelName::String="model", printLevel::Int=1) file = matopen(fileName) vars = matread(fileName) @@ -84,29 +76,63 @@ function loadModel(fileName::String, matrixAS::String="S", modelName::String="mo model = vars[modelName] modelKeys = keys(model) + cdPresent = false + + # set the model fields + modelFields = ["ub", "lb", "osense", "c", "b", "csense", "rxns", "mets"] + + # determine if the model file contains a coupled model or not, i.e. if a C matrix is present + if "C" in modelKeys && "d" in modelKeys + if size(model["C"]) > (0, 0) && size(model["d"]) > (0, 0) + # model is a coupled model + if printLevel > 0 + @info "The model named $modelName loaded from $fileName is a coupled model." + end + cdPresent = true + S = [model["S"]; model["C"]] + else + error("The fields C and d are present in the loaded model structure $modelName in the $fileName, but are not of the right size.") + end + + # set the model fields + push!(modelFields, "d", "dsense", "ctrs") - # load the stoichiometric matrix A or S - if matrixAS == "A" || matrixAS == "S" - if matrixAS in modelKeys - S = model[matrixAS] + # load the vector d + if modelFields[9] in modelKeys + d = vec(model[modelFields[9]]) else - S = model[(matrixAS == "S") ? "A" : "S"] - error("Matrix `$matrixAS` does not exist in `$modelName`, but matrix `S` exists. Set `matrixAS = S` if you want to use `S`.") + error("The vector `$(modelFields[9])` does not exist in `$modelName`.") end else - error("Matrix `$matrixAS` does not exist in `$modelName`.") + if "A" in modelKeys + # legacy structure if a matrix A is present + S = model["A"] + if printLevel > 0 + @warn "The named $modelName loaded from $fileName is a coupled model, but has a legacy structure." + end + else + # model is an uncoupled model + S = model["S"] + if printLevel > 0 + @info "The model named $modelName loaded from $fileName is a uncoupled model." + end + end end + # determine the size of S + nMets = size(S,1) + nRxns = size(S,2) + # load the upper bound vector ub if modelFields[1] in modelKeys - ub = squeeze(model[modelFields[1]], 2) + ub = vec(model[modelFields[1]]) else error("The vector `$(modelFields[1])` does not exist in `$modelName`.") end - # load the upper bound vector lb + # load the lower bound vector lb if modelFields[2] in modelKeys - lb = squeeze(model[modelFields[2]], 2) + lb = vec(model[modelFields[2]]) else error("The vector `$(modelFields[2])` does not exist in `$modelName`.") end @@ -117,54 +143,77 @@ function loadModel(fileName::String, matrixAS::String="S", modelName::String="mo else osense = -1 if printLevel > 0 - info("The model objective is set to be maximized.\n") + @info "The model objective is set to be maximized.\n" end end - # load the upper bound vector c + # load the objective vector c if modelFields[4] in modelKeys && osense != 0 - c = squeeze(model[modelFields[4]], 2) + c = vec(model[modelFields[4]]) else error("The vector `$(modelFields[4])` does not exist in `$modelName`.") end - # load the upper bound vector c + # load the right hand side vector b if modelFields[5] in modelKeys - b = squeeze(model[modelFields[5]], 2) + b = vec(model[modelFields[5]]) else b = zeros(length(c)) error("The vector `$(modelFields[5])` does not exist in `$modelName`.") end # load the constraint senses - csense = fill('E',length(b)) #assume all equality constraints + csense = fill('E',length(b)) # assume all equality constraints + + # initialize the dsense vector for the case of a coupled model + if cdPresent + dsense = fill('E',length(d)) + end + if modelFields[6] in modelKeys for i = 1:length(csense) - csense[i] = model[modelFields[6]][i][1] #convert to chars + csense[i] = model[modelFields[6]][i][1] # convert to chars + end + + # retrieve the dsense vector for a coupled model + if cdPresent + for i = 1:length(dsense) + dsense[i] = model[modelFields[10]][i][1] # convert to chars + end end else if printLevel > 0 - info("All constraints assumed equality constaints.\n") + @info "All constraints assumed equality constaints.\n" end end # load the reaction names vector if modelFields[7] in modelKeys - rxns = squeeze(model[modelFields[7]], 2) + rxns = vec(model[modelFields[7]]) else error("The vector `$(modelFields[7])` does not exist in `$modelName`.") end - # load the reaction names vector + # load the metabolites vector if modelFields[8] in modelKeys - mets = squeeze(model[modelFields[8]], 2) + mets = vec(model[modelFields[8]]) else error("The vector `$(modelFields[8])` does not exist in `$modelName`.") end - # determine the size of S - nMets = size(S,1) - nRxns = size(S,2) + if cdPresent + # load the contraints vector + if modelFields[8] in modelKeys + ctrs = vec(model[modelFields[11]]) + else + error("The vector `$(modelFields[11])` does not exist in `$modelName`.") + end + + # append the d, dsense, and mets vectors for a coupled model + b = [b; d] + csense = [csense; dsense] + mets = [mets; ctrs] + end return LPproblem(S, b[1:nMets], c[1:nRxns], lb[1:nRxns], ub[1:nRxns], osense, csense[1:nMets], rxns, mets) else @@ -173,5 +222,8 @@ function loadModel(fileName::String, matrixAS::String="S", modelName::String="mo end +# keep legacy signature +loadModel(fileName, matrixAS::String="S", modelName::String="model", modelFields::Array{String,1}=["ub", "lb", "osense", "c", "b", "csense", "rxns", "mets"], printLevel::Int=1) = loadModel(fileName, modelName, printLevel) + export loadModel #------------------------------------------------------------------------------------------- diff --git a/src/solve.jl b/src/solve.jl index 0eb7b5f..14383d5 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -142,7 +142,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1) catch error("The solver `Gurobi` cannot be set using `changeCobraSolver()`.") end - + #= elseif name == "Clp" try solver.handle = ClpSolver() @@ -159,7 +159,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1) catch error("The solver `Mosek` cannot be set using `changeCobraSolver()`.") end - + =# else solver.handle = -1 error("The solver is not supported. Please set the solver name to one the supported solvers.") diff --git a/src/tools.jl b/src/tools.jl index bd96cb1..92efd0d 100644 --- a/src/tools.jl +++ b/src/tools.jl @@ -85,7 +85,7 @@ function findRxnIDS(model, rxnsList=model.rxns) # throw an error when no reaction matched any in the model if length(rxnIDsNE) != 0 - warn("Some reaction names are not in the model; their indices in the `rxnsList` are reported in `rxnIDsNE`.\n") + @warn "Some reaction names are not in the model; their indices in the `rxnsList` are reported in `rxnIDsNE`.\n" end return rxnIDs, rxnIDsNE diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index 4927350..0000000 --- a/test/REQUIRE +++ /dev/null @@ -1,8 +0,0 @@ -julia 0.6 -MathProgBase 0.6.1 -MAT 0.3.1 -GLPKMathProgInterface 0.2.3 -GLPK 0.3.0 -Clp 0.2.2 -Requests 0.4.1 -Suppressor 0.1.1 diff --git a/test/getTestModel.jl b/test/getTestModel.jl index bfa71da..ed0c8d9 100644 --- a/test/getTestModel.jl +++ b/test/getTestModel.jl @@ -2,11 +2,11 @@ function getTestModel() if !isfile("ecoli_core_model.mat") print("Downloading the ecoli_core model ...") - ecoliModel = get("http://gcrg.ucsd.edu/sites/default/files/Attachments/Images/downloads/Ecoli_core/ecoli_core_model.mat") - save(ecoliModel, "ecoli_core_model.mat") - print_with_color(:green, "Done.\n") + ecoliModel = HTTP.get("https://github.com/LCSB-BioCore/COBRA.models/raw/master/mat/ecoli_core_model.mat") + write("ecoli_core_model.mat", ecoliModel.body) + printstyled("Done.\n"; color=:green) else - info("The ecoli_core model already exists.\n") + @info "The ecoli_core model already exists.\n" end end diff --git a/test/modelCoupled.mat b/test/modelCoupled.mat new file mode 100644 index 0000000..3c1526a Binary files /dev/null and b/test/modelCoupled.mat differ diff --git a/test/p_all.jl b/test/p_all.jl index 5931bdb..0a74b40 100644 --- a/test/p_all.jl +++ b/test/p_all.jl @@ -7,12 +7,13 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true end +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # output information testFile = @__FILE__ @@ -21,9 +22,10 @@ nWorkers = 4 # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA + # define the name of the default solver solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) @@ -31,7 +33,7 @@ if includeCOBRA end using COBRA - using Requests + using HTTP include("getTestModel.jl") end @@ -40,13 +42,13 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/../config/solverCfg.jl") # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/../test/ecoli_core_model.mat", "S", "model") # test that no output is produced with printLevel = 0 -info(" > Testing silent $solverName ...") +@info " > Testing silent $solverName ..." solver = changeCobraSolver(solverName, printLevel=0) output = @capture_out minFlux, maxFlux = distributedFBA(model, solver, nWorkers=nWorkers, printLevel=0, rxnsList=1:4) if string(solverName) == "Gurobi" @@ -54,7 +56,7 @@ if string(solverName) == "Gurobi" else @test length(output) == 0 end -info(" > Done testing silent $solverName.") +@info " > Done testing silent $solverName." # change the COBRA solver solver = changeCobraSolver(solverName, solParams) @@ -325,7 +327,7 @@ strategy = 0 rxnsList = 1:length(model.rxns) # select the reaction optimization mode -rxnsOptMode = 2 + zeros(Int64, length(rxnsList)) +rxnsOptMode = 2 .+ zeros(Int64, length(rxnsList)) minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver, nWorkers=nWorkers, optPercentage=optPercentage, strategy=strategy, preFBA=true, saveChunks=saveChunks) @@ -333,24 +335,28 @@ minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = d printSolSummary(testFile, optSol, maxFlux, minFlux, solTime, nWorkers, solverName, strategy, saveChunks) # remove the results folder to clean up -run(`rm -rf $(Pkg.dir("COBRA"))/results`) +try + rm(pkgDir*"/results", recursive=true, force=true) +catch + @info "The directory $(Pkg.dir("COBRA"))/results cannot be removed. Please check permissions.\n" +end # create folders if they are not present -if !isdir("$(Pkg.dir("COBRA"))/results") - mkdir("$(Pkg.dir("COBRA"))/results") - print_with_color(:green, "Directory `results` created.\n\n") +if !isdir(pkgDir*"/results") + mkdir(pkgDir*"/results") + printstyled("Directory `results` created.\n\n"; color=:green) # create a folder for storing the chunks of the fluxes of each minimization - if !isdir("$(Pkg.dir("COBRA"))/results/fvamin") - mkdir("$(Pkg.dir("COBRA"))/results/fvamin") + if !isdir(pkgDir*"/results/fvamin") + mkdir(pkgDir*"/results/fvamin") end # create a folder for storing the chunks of the fluxes of each maximization - if !isdir("$(Pkg.dir("COBRA"))/results/fvamax") - mkdir("$(Pkg.dir("COBRA"))/results/fvamax") + if !isdir(pkgDir*"/results/fvamax") + mkdir(pkgDir*"/results/fvamax") end else - print_with_color(:cyan, "Directory `results` already exists.\n\n") + printstyled("Directory `results` already exists.\n\n", color=:green) end minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver, preFBA=true, saveChunks=true) @@ -384,14 +390,22 @@ saveDistributedFBA("testFile.mat", [""]) run(`rm testFile.mat`) # remove the results folder to clean up -run(`rm -rf $(Pkg.dir("COBRA"))/results`) +try + rm(pkgDir*"/results", recursive=true, force=true) +catch + @info "The directory $(Pkg.dir("COBRA"))/results cannot be removed. Please check permissions.\n" +end -# create the logs folder -resultsDir = "$(Pkg.dir("COBRA"))/results" +# create the pkgDir*"/ +resultsDir = pkgDir*"/results" if isdir("$resultsDir/logs") - rm("$resultsDir/logs") - print_with_color(:green, "$resultsDir/logs folder created") + try + rm("$resultsDir/logs", recursive=true, force=true) + catch + @info "The directory $resultsDir/logs cannot be removed. Please check permissions.\n" + end + printstyled("$resultsDir/logs folder created", color=:green) end # call to create a log files directory @@ -401,7 +415,11 @@ minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = d @test isdir("$resultsDir/logs") # remove the results folder to clean up -run(`rm -rf $(Pkg.dir("COBRA"))/results`) +try + rm(pkgDir*"/results", recursive=true, force=true) +catch + @info "The directory $(Pkg.dir("COBRA"))/results cannot be removed. Please check permissions.\n" +end # call to create a log files directory (throws a warning message) minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver, nWorkers=nWorkers, saveChunks=true, onlyFluxes=true, rxnsList=1:10) @@ -412,9 +430,12 @@ minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = d # call to write logFiles with onlyFluxes minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver, nWorkers=nWorkers, onlyFluxes=true, rxnsList=1:10, logFiles=true) -# test if the /logs folder has been created -@test isdir("$(Pkg.dir("COBRA"))/results/logs") +# test if thpkgDir*"/en created +@test isdir(pkgDir*"/results/logs") # remove the results folder to clean up -run(`rm -rf $(Pkg.dir("COBRA"))/results`) - +trypkgDir*"/ + rm(pkgDir*"/results", recursive=true, force=true) +catch + @info "The directory $(Pkg.dir("COBRA"))/results cannot be removed. Please check permissions.\n" +end diff --git a/test/p_distinct.jl b/test/p_distinct.jl index 8acc492..b8dafea 100644 --- a/test/p_distinct.jl +++ b/test/p_distinct.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,19 +18,19 @@ testFile = @__FILE__ # number of workers nWorkers = 4 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,13 +39,13 @@ end getTestModel() # include the solver configuration file -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # define an optPercentage value optPercentage = 90.0 diff --git a/test/p_range.jl b/test/p_range.jl index 6cff052..c3b5015 100644 --- a/test/p_range.jl +++ b/test/p_range.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,19 +18,19 @@ testFile = @__FILE__ # number of workers nWorkers = 4 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,19 +39,19 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # select the number of reactions rxnsList = 1:30 # select the reaction optimization mode -rxnsOptMode = 2 + zeros(Int64, length(rxnsList)) +rxnsOptMode = 2 .+ zeros(Int64, length(rxnsList)) # define an optPercentage value optPercentage = 90.0 diff --git a/test/runtests.jl b/test/runtests.jl index 913e7c3..535f81d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,16 +7,20 @@ #------------------------------------------------------------------------------------------- +using Pkg, Distributed, LinearAlgebra, COBRA + +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # retrieve all packages that are installed on the system -include("$(Pkg.dir("COBRA"))/src/checkSetup.jl") +include(pkgDir*"/src/checkSetup.jl") packages = checkSysConfig() # configure for runnint the tests in batch -solverName = :GLPKMathProgInterface #:CPLEX +solverName = :GLPKMathProgInterface nWorkers = 4 connectSSHWorkers = false -include("$(Pkg.dir("COBRA"))/src/connect.jl") -TESTDIR = "$(Pkg.dir("COBRA"))/test" +include(pkgDir*"/src/connect.jl") +TESTDIR = pkgDir*"/test" # create a parallel pool and determine its size if (@isdefined nWorkers) && (@isdefined connectSSHWorkers) @@ -24,21 +28,17 @@ if (@isdefined nWorkers) && (@isdefined connectSSHWorkers) end # use the module COBRA and Base.Test modules on all workers -using COBRA -using Base.Test -using Requests -using Suppressor +@everywhere using COBRA, Test, HTTP # download the ecoli_core_model include("getTestModel.jl") getTestModel() # check if MATLAB package is present -if sizeof(Pkg.installed("MATLAB")) > 0 - info("The MATLAB package is present. The tests for PALM.jl will be run.") +if "MATLAB" in keys(Pkg.installed()) + @info "The MATLAB package is present. The tests for PALM.jl will be run." - using MAT - using MATLAB + using MAT, MATLAB # load sharing that is not fair nWorkers, quotientModels, remainderModels = COBRA.shareLoad(2) @@ -89,47 +89,47 @@ if sizeof(Pkg.installed("MATLAB")) > 0 "nNz"] # launch PALM with the scriptFile on the 2 models - PALM(joinpath(TESTDIR, "testModels"), "scriptFile", 2, "modelCharacteristics.mat", varsCharact, "/tmp/cobratoolbox-cobrajl") + PALM(joinpath(TESTDIR, "testModels"), "scriptFile", nMatlab=2, outputFile="modelCharacteristics.mat", varsCharact=varsCharact, cobraToolboxDir=homedir()*"/tmp/cobratoolbox-cobrajl") # remove the directory with the test models rm(joinpath(TESTDIR, "testModels"), force=true, recursive=true) else - warn("The MATLAB package is not present. The tests for PALM.jl will not be run.") + @warn "The MATLAB package is not present. The tests for PALM.jl will not be run." end # list all currently supported solvers -supportedSolvers = [:Clp, :GLPKMathProgInterface, :CPLEX, :Gurobi, :Mosek] +supportedSolvers = [:GLPKMathProgInterface, :CPLEX, :Gurobi] #:Clp, :Mosek # test if an error is thrown for non-installed solvers for i = 1:length(supportedSolvers) print(" > Testing $(supportedSolvers[i]) ... ") if !(supportedSolvers[i] in packages) @test_throws ErrorException changeCobraSolver(string(supportedSolvers[i])) - print_with_color(:red, "Not supported.\n") + printstyled("Not supported.\n"; color=:red) else @test typeof(changeCobraSolver(supportedSolvers[i])) == COBRA.SolverConfig - print_with_color(:green, "Done.\n") + printstyled("Done.\n"; color=:green) end end includeCOBRA = false -for s = 1:length(packages) +for s in packages # define a solvername - solverName = string(packages[s]) + global solverName = string(s) # read out the directory with the test files testDir = readdir(TESTDIR) # print the solver name - print_with_color(:green, "\n\n -- Running $(length(testDir) - 2) tests using the $solverName solver. -- \n\n") + printstyled("\n\n -- Running $(length(testDir) - 2) tests using the $solverName solver. -- \n\n"; color=:green) # evaluate the test file for t = 1:length(testDir) # run only parallel and serial test files - if testDir[t][1:2] == "p_" || testDir[t][1:2] == "s_" || testDir[t][1:2] == "z_" - print_with_color(:green, "\nRunning $(testDir[t]) ...\n\n") + if testDir[t][1:2] in ["s_", "z_"] #"p_", + printstyled("\nRunning $(testDir[t]) ...\n\n"; color=:green) include(testDir[t]) end end @@ -138,10 +138,14 @@ end # remove the results folder to clean up tmpDir = joinpath(dirname(@__FILE__), "..", "results") if isdir(tmpDir) - rm(tmpDir, recursive=true) + try + rm("$tmpDir", recursive=true, force=true) + catch + info("The directory $tmpDir cannot be removed. Please check permissions.\n") + end end # print a status line -print_with_color(:green, "\n -- All tests passed. -- \n\n") +printstyled("\n -- All tests passed. -- \n\n"; color=:green) #------------------------------------------------------------------------------------------- diff --git a/test/s_all.jl b/test/s_all.jl index 46fbabc..494823a 100644 --- a/test/s_all.jl +++ b/test/s_all.jl @@ -7,12 +7,13 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true end +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # output information testFile = @__FILE__ @@ -21,17 +22,15 @@ nWorkers = 1 # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src//connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,13 +39,13 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # select the number of reactions rxnsList = 1:length(model.rxns) diff --git a/test/s_core.jl b/test/s_core.jl index 26f3899..dd4c556 100644 --- a/test/s_core.jl +++ b/test/s_core.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,19 +18,19 @@ testFile = @__FILE__ # number of workers nWorkers = 1 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,13 +39,13 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # select the number of reactions rxnsList = 1:length(model.rxns) @@ -90,5 +89,19 @@ saveDistributedFBA("testFile.mat") # remove the file to clean up run(`rm testFile.mat`) +# load a coupled model (printLevel = 0) +modelCoupled = loadModel("modelCoupled.mat", "modelCoupled") + +# test the size of the combined S matrix +@test size(modelCoupled.S, 1) == length(modelCoupled.mets) +@test size(modelCoupled.S, 2) == length(modelCoupled.rxns) + +# load a coupled model (printLevel = 1) +modelCoupled = loadModel("modelCoupled.mat", "modelCoupled", 1) + +# test the size of the combined S matrix +@test size(modelCoupled.S, 1) == length(modelCoupled.mets) +@test size(modelCoupled.S, 2) == length(modelCoupled.rxns) + # print a solution summary printSolSummary(testFile, optSol, maxFlux, minFlux, solTime, nWorkers, solverName) diff --git a/test/s_distinct.jl b/test/s_distinct.jl index aaab519..114bde3 100644 --- a/test/s_distinct.jl +++ b/test/s_distinct.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,19 +18,19 @@ testFile = @__FILE__ # number of workers nWorkers = 1 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,13 +39,13 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # define an optPercentage value optPercentage = 90.0 @@ -55,7 +54,7 @@ optPercentage = 90.0 minFlux1, maxFlux1, optSol1, fbaSol1, fvamin1, fvamax1, statussolmin1, statussolmax1 = distributedFBA(model, solver, nWorkers=nWorkers, optPercentage=optPercentage, preFBA=true) rxnsList = [1; 18; 10; 20:30; 90; 93; 95] -rxnsOptMode = [0; 1; 2; 2 + zeros(Int, length(20:30)); 2; 1; 0] +rxnsOptMode = [0; 1; 2; 2 .+ zeros(Int, length(20:30)); 2; 1; 0] # run only a few reactions with rxnsOptMode and rxnsList minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax = distributedFBA(model, solver, nWorkers=nWorkers, optPercentage=optPercentage, rxnsList=rxnsList, rxnsOptMode=rxnsOptMode, preFBA=true) diff --git a/test/s_fba.jl b/test/s_fba.jl index 3f6450a..7722f3c 100644 --- a/test/s_fba.jl +++ b/test/s_fba.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,19 +18,19 @@ testFile = @__FILE__ # number of workers nWorkers = 1 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) workersPool, nWorkers = createPool(nWorkers, connectSSHWorkers) end - using COBRA - using Requests + using COBRA, HTTP include("getTestModel.jl") end @@ -40,13 +39,13 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") modelOrig = model diff --git a/test/s_tools.jl b/test/s_tools.jl index 2feb2dd..b059857 100644 --- a/test/s_tools.jl +++ b/test/s_tools.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,11 +18,12 @@ testFile = @__FILE__ # number of workers nWorkers = 1 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) @@ -34,13 +34,13 @@ if includeCOBRA end # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) # load an external mat file -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "model") # find the reaction ID of one reaction rxnIDs, rxnIDsNE = findRxnIDS(model, ["PPC"]) diff --git a/test/z_all.jl b/test/z_all.jl index 0af570a..f3537fc 100644 --- a/test/z_all.jl +++ b/test/z_all.jl @@ -7,7 +7,6 @@ #------------------------------------------------------------------------------------------- -using Base.Test if !@isdefined includeCOBRA includeCOBRA = true @@ -19,11 +18,12 @@ testFile = @__FILE__ # number of workers nWorkers = 1 +pkgDir = joinpath(dirname(pathof(COBRA)), "..") + # create a pool and use the COBRA module if the testfile is run in a loop if includeCOBRA - solverName = :GLPKMathProgInterface connectSSHWorkers = false - include("$(Pkg.dir("COBRA"))/src/connect.jl") + include(pkgDir*"/src/connect.jl") # create a parallel pool and determine its size if isdefined(:nWorkers) && isdefined(:connectSSHWorkers) @@ -31,7 +31,7 @@ if includeCOBRA end using COBRA - using Requests + using HTTP include("getTestModel.jl") end @@ -40,7 +40,7 @@ end getTestModel() # include a common deck for running tests -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(pkgDir*"/config/solverCfg.jl") # change the COBRA solver solver = changeCobraSolver(solverName, solParams) @@ -49,27 +49,19 @@ solver = changeCobraSolver(solverName, solParams) @test_throws ErrorException changeCobraSolver("mySolver") # test some functions that are known to throw errors -print_with_color(:yellow, "\n>> The following tests throw warning messages for testing purposes. <<\n\n") +printstyled("\n>> The following tests throw warning messages for testing purposes. <<\n\n"; color=:yellow) # test if an error is thrown when myModel.mat does not exist @test_throws ErrorException loadModel("myModel.mat") # test if an error is thrown when the matrix A does not exist -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "A") +@test_throws ErrorException loadModel(pkgDir*"/test/ecoli_core_model.mat", "A") # test if an error is thrown when the matrix A does not exist -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "R") +@test_throws ErrorException loadModel(pkgDir*"/test/ecoli_core_model.mat", "R") # test if an error is thrown when the struct myModel does not exist -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "myModel") - -# call other fields of the model -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ubTest", "lb", "osense", "c", "b", "csense", "rxns", "mets"]) -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ub", "lbTest", "osense", "c", "b", "csense", "rxns", "mets"]) -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ub", "lb", "osense", "cTest", "b", "csense", "rxns", "mets"]) -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ub", "lb", "osense", "c", "bTest", "csense", "rxns", "mets"]) -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ub", "lb", "osense", "c", "b", "csense", "rxnsTest", "mets"]) -@test_throws ErrorException loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat", "S", "model", ["ub", "lb", "osense", "c", "b", "csense", "rxns", "metsTest"]) +@test_throws ErrorException loadModel(pkgDir*"/test/ecoli_core_model.mat", "S", "myModel") # connect SSH workers that are not reachable @test createPool(1, false) == (workers(), 1) @@ -82,7 +74,7 @@ print_with_color(:yellow, "\n>> The following tests throw warning messages for t @test createPool(2) == (workers(), 2) # load a new version of the model -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat") # run a model with more reactions on the reaction list than in the model rxnsList = 1:length(model.rxns) + 1 @@ -96,7 +88,7 @@ model.c = 0.0 * model.c @test_throws MethodError optSol, fbaSol = preFBA!(model, solver, 90.0, "min") # set a wrong solver handle -model = loadModel("$(Pkg.dir("COBRA"))/test/ecoli_core_model.mat") +model = loadModel(pkgDir*"/test/ecoli_core_model.mat") solver = changeCobraSolver(solverName, solParams) solver.handle = -1 @test_throws ErrorException solveCobraLP(model, solver) @@ -113,7 +105,7 @@ else end # load the test model -modelTest = loadModel("$(Pkg.dir("COBRA"))/test/testData.mat", "S", "modelTest") +modelTest = loadModel(pkgDir*"/test/testData.mat", "S", "modelTest") @test modelTest.osense == -1 @test modelTest.csense == fill('E', length(modelTest.b)) @@ -135,4 +127,4 @@ elseif solver.name == "CPLEX" @test isequal(retStat, [4, NaN]) # unbounded and not solved end -print_with_color(:yellow, "\n >> Note: Warnings above are thrown for testing purposes and can be safely ignored.\n") +printstyled("\n >> Note: Warnings above are thrown for testing purposes and can be safely ignored.\n"; color=:yellow) diff --git a/tutorials/tutorial-COBRA.jl.ipynb b/tutorials/tutorial-COBRA.jl.ipynb index 3d8c9f1..070f1eb 100644 --- a/tutorials/tutorial-COBRA.jl.ipynb +++ b/tutorials/tutorial-COBRA.jl.ipynb @@ -151,15 +151,15 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Julia 0.6.4", + "display_name": "Julia 1.2.0", "language": "julia", - "name": "julia-0.6" + "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.6.4" + "version": "1.2.0" } }, "nbformat": 4, diff --git a/tutorials/tutorial-COBRA.jl.md b/tutorials/tutorial-COBRA.jl.md index 3da5e8a..07239f1 100644 --- a/tutorials/tutorial-COBRA.jl.md +++ b/tutorials/tutorial-COBRA.jl.md @@ -1,4 +1,3 @@ - # Tutorial - COBRA.jl This tutorial serves as a quick start guide as well as an interactive reference for more advanced users. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). diff --git a/tutorials/tutorial-PALM.jl.ipynb b/tutorials/tutorial-PALM.jl.ipynb index 3edbaf9..e20fc45 100644 --- a/tutorials/tutorial-PALM.jl.ipynb +++ b/tutorials/tutorial-PALM.jl.ipynb @@ -26,10 +26,10 @@ "metadata": {}, "outputs": [], "source": [ - "#=\n", - "Pkg.add(\"COBRA\")\n", - "Pkg.add(\"MATLAB\")\n", - "=#" + "\n", + "import Pkg;\n", + "#Pkg.add(\"COBRA\")\n", + "Pkg.add(\"MATLAB\")\n" ] }, { @@ -56,7 +56,8 @@ "metadata": {}, "outputs": [], "source": [ - "run(`cat $(Pkg.dir(\"COBRA\"))/test/scriptFile.m`)" + "using COBRA\n", + "run(`cat $(joinpath(dirname(pathof(COBRA)), \"../test/scriptFile.m\"))`)" ] }, { @@ -83,7 +84,7 @@ "\n", "**Advanced users** may also want to install the COBRA Toolbox directly installed from Julia. You must have `git` (or `gitBash` on Windows) installed - see [requirements](https://opencobra.github.io/cobratoolbox/stable/installation.html#system-requirements).\n", "\n", - "For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `/tmp` directory. This may take a while, depending on the speed of your internet connection." + "For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `~/tmp` directory. This may take a while, depending on the speed of your internet connection." ] }, { @@ -92,13 +93,15 @@ "metadata": {}, "outputs": [], "source": [ - "installDir = \"/tmp/cobratoolbox\"" + "installDir = homedir()*\"/tmp/cobratoolbox\"" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "# if you already ran this tutorial once, you may also remove the previous installation directory with the following command:\n", @@ -109,11 +112,22 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "run(`git clone --depth=1 --recurse-submodules https://github.com/opencobra/cobratoolbox.git $installDir`);\n", - "info(\"The COBRA Toolbox has been cloned successfully to the $installDir directory.\")" + "@info \"The COBRA Toolbox has been cloned successfully to the $installDir directory.\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "run(`mkdir \"~/tmp/cobratoolbox\"`)" ] }, { @@ -143,7 +157,8 @@ "metadata": {}, "outputs": [], "source": [ - "include(\"$(Pkg.dir(\"COBRA\"))/src/connect.jl\")" + "using Distributed\n", + "include(joinpath(dirname(pathof(COBRA)), \"connect.jl\"))" ] }, { @@ -172,8 +187,8 @@ "metadata": {}, "outputs": [], "source": [ - "@everywhere using COBRA\n", - "@everywhere using MATLAB" + "@everywhere using COBRA;\n", + "@everywhere using MATLAB;" ] }, { @@ -283,7 +298,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "? PALM" @@ -299,10 +316,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ - "PALM(modelDir, \"$(Pkg.dir(\"COBRA\"))/test/scriptFile.m\", nWorkers, \"modelCharacteristics.mat\", varsCharact, installDir)" + "PALM(modelDir, \"$(joinpath(dirname(pathof(COBRA)), \"../test/scriptFile.m\"))\"; nMatlab=nWorkers, outputFile=\"modelCharacteristics.mat\", varsCharact=varsCharact, cobraToolboxDir=installDir)" ] }, { @@ -340,17 +359,21 @@ } ], "metadata": { + "@webio": { + "lastCommId": null, + "lastKernelId": null + }, "anaconda-cloud": {}, "kernelspec": { - "display_name": "Julia 0.6.4", + "display_name": "Julia 1.2.0", "language": "julia", - "name": "julia-0.6" + "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.6.4" + "version": "1.2.0" } }, "nbformat": 4, diff --git a/tutorials/tutorial-PALM.jl.md b/tutorials/tutorial-PALM.jl.md index b35a295..ccc7856 100644 --- a/tutorials/tutorial-PALM.jl.md +++ b/tutorials/tutorial-PALM.jl.md @@ -1,4 +1,3 @@ - # Tutorial - PALM.jl This tutorial serves as a reference to get started with `PALM.jl`. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). @@ -11,10 +10,11 @@ Please make sure to have the following packages installed: `COBRA.jl`, `MATLAB`, ```julia -#= -Pkg.add("COBRA") + +import Pkg; +#Pkg.add("COBRA") Pkg.add("MATLAB") -=# + ``` ## Writing a MATLAB script @@ -27,7 +27,8 @@ The MATLAB script can be saved as `scriptFile.m` in any folder. For illustration ```julia -run(`cat $(Pkg.dir("COBRA"))/test/scriptFile.m`) +using COBRA +run(`cat $(joinpath(dirname(pathof(COBRA)), "../test/scriptFile.m"))`) ``` Note that the variables marked with `PALM_` are the ones defined within Julia. @@ -40,11 +41,11 @@ If you already have a working installation of the COBRA Toolbox, you may skip th **Advanced users** may also want to install the COBRA Toolbox directly installed from Julia. You must have `git` (or `gitBash` on Windows) installed - see [requirements](https://opencobra.github.io/cobratoolbox/stable/installation.html#system-requirements). -For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `/tmp` directory. This may take a while, depending on the speed of your internet connection. +For illustration purposes of this tutorial, the COBRA Toolbox will be installed in the `~/tmp` directory. This may take a while, depending on the speed of your internet connection. ```julia -installDir = "/tmp/cobratoolbox" +installDir = homedir()*"/tmp/cobratoolbox" ``` @@ -57,7 +58,12 @@ run(`rm -rf $installDir`) ```julia run(`git clone --depth=1 --recurse-submodules https://github.com/opencobra/cobratoolbox.git $installDir`); -info("The COBRA Toolbox has been cloned successfully to the $installDir directory.") +@info "The COBRA Toolbox has been cloned successfully to the $installDir directory." +``` + + +```julia +run(`mkdir "~/tmp/cobratoolbox"`) ``` **Tip:** When using `PALM.jl`, it is advised to add the `--recurse-submodules` flag. This will speed up the simultaneous initialisations on several workers. @@ -68,7 +74,8 @@ Similarly to `distributedFBA.jl`, the workers may be added using `createPool`, g ```julia -include("$(Pkg.dir("COBRA"))/src/connect.jl") +using Distributed +include(joinpath(dirname(pathof(COBRA)), "connect.jl")) ``` @@ -84,8 +91,8 @@ After initializing the workers, the packages must be loaded on each worker: ```julia -@everywhere using COBRA -@everywhere using MATLAB +@everywhere using COBRA; +@everywhere using MATLAB; ``` ## Sharing the load @@ -140,7 +147,7 @@ Now, all variables are defined, and `PALM.jl` is ready to be launched: ```julia -PALM(modelDir, "$(Pkg.dir("COBRA"))/test/scriptFile.m", nWorkers, "modelCharacteristics.mat", varsCharact, installDir) +PALM(modelDir, "$(joinpath(dirname(pathof(COBRA)), "../test/scriptFile.m"))"; nMatlab=nWorkers, outputFile="modelCharacteristics.mat", varsCharact=varsCharact, cobraToolboxDir=installDir) ``` The output file that contains the values of the variables defined in `varsCharact` for each model is `modelCharacteristics.mat`. This file can be read back into Julia by using: diff --git a/tutorials/tutorial-distributedFBA.jl.ipynb b/tutorials/tutorial-distributedFBA.jl.ipynb index 6a76b95..14c5c55 100644 --- a/tutorials/tutorial-distributedFBA.jl.ipynb +++ b/tutorials/tutorial-distributedFBA.jl.ipynb @@ -45,7 +45,8 @@ "metadata": {}, "outputs": [], "source": [ - "include(\"$(Pkg.dir(\"COBRA\"))/src/connect.jl\")" + "using Distributed #leejm516: This is needed even though COBRA imports that package \n", + "include(joinpath(dirname(pathof(COBRA)), \"connect.jl\"))" ] }, { @@ -88,7 +89,7 @@ "metadata": {}, "outputs": [], "source": [ - "@everywhere using COBRA" + "@everywhere using COBRA;" ] }, { @@ -101,9 +102,7 @@ "\n", "- `:GLPKMathProgInterface`\n", "- `:CPLEX`\n", - "- `:Clp`\n", - "- `:Gurobi`\n", - "- `:Mosek`" + "- `:Gurobi`" ] }, { @@ -113,10 +112,10 @@ "outputs": [], "source": [ "# specify the solver name\n", - "solverName = :Gurobi #:GLPKMathProgInterface\n", + "solverName = :GLPKMathProgInterface\n", "\n", "# include the solver configuration file\n", - "include(\"$(Pkg.dir(\"COBRA\"))/config/solverCfg.jl\")" + "include(joinpath(dirname(pathof(COBRA)), \"../config/solverCfg.jl\"))" ] }, { @@ -159,8 +158,8 @@ "outputs": [], "source": [ "# download the test model\n", - "using Requests\n", - "include(\"$(Pkg.dir(\"COBRA\"))/test/getTestModel.jl\")\n", + "using HTTP\n", + "include(joinpath(dirname(pathof(COBRA)), \"../test/getTestmodel.jl\"))\n", "getTestModel()" ] }, @@ -344,7 +343,7 @@ "outputs": [], "source": [ "rxnsList = [1; 18; 10; 20:30; 90; 93; 95]\n", - "rxnsOptMode = [0; 1; 2; 2+zeros(Int, length(20:30)); 2; 1; 0]\n", + "rxnsOptMode = [0; 1; 2; 2 .+ zeros(Int, length(20:30)); 2; 1; 0]\n", "\n", "# run only a few reactions with rxnsOptMode and rxnsList\n", "# distributedFBA(model, solver, nWorkers, optPercentage, objective, rxnsList, strategy, preFBA, rxnsOptMode)\n", @@ -428,15 +427,15 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Julia 0.6.4", + "display_name": "Julia 1.2.0", "language": "julia", - "name": "julia-0.6" + "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.6.4" + "version": "1.2.0" } }, "nbformat": 4, diff --git a/tutorials/tutorial-distributedFBA.jl.md b/tutorials/tutorial-distributedFBA.jl.md index 93ab66a..62e36e9 100644 --- a/tutorials/tutorial-distributedFBA.jl.md +++ b/tutorials/tutorial-distributedFBA.jl.md @@ -1,4 +1,3 @@ - # Tutorial - distributedFBA.jl This tutorial serves as a reference to get started with `distributedFBA.jl`. Download the live notebook from [here](https://github.com/opencobra/COBRA.jl/tree/master/tutorials). @@ -16,7 +15,8 @@ The connection functions are given in `connect.jl`, which, if a parallel version ```julia -include("$(Pkg.dir("COBRA"))/src/connect.jl") +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: @@ -36,7 +36,7 @@ In order to be able to use the `COBRA` module on all connected workers, you must ```julia -@everywhere using COBRA +@everywhere using COBRA; ``` ## Define and change the COBRA solver @@ -45,17 +45,15 @@ Before the COBRA solver can be defined, the solver parameters and configuration - `:GLPKMathProgInterface` - `:CPLEX` -- `:Clp` - `:Gurobi` -- `:Mosek` ```julia # specify the solver name -solverName = :Gurobi #:GLPKMathProgInterface +solverName = :GLPKMathProgInterface # include the solver configuration file -include("$(Pkg.dir("COBRA"))/config/solverCfg.jl") +include(joinpath(dirname(pathof(COBRA)), "../config/solverCfg.jl")) ``` The name of the solver can be changed as follows: @@ -75,8 +73,8 @@ As a test and as an example, the *E.coli* core model may be loaded as: ```julia # download the test model -using Requests -include("$(Pkg.dir("COBRA"))/test/getTestModel.jl") +using HTTP +include(joinpath(dirname(pathof(COBRA)), "../test/getTestmodel.jl")) getTestModel() ``` @@ -166,7 +164,7 @@ You may now input several reactions with various `rxnsOptMode` values to run spe ```julia rxnsList = [1; 18; 10; 20:30; 90; 93; 95] -rxnsOptMode = [0; 1; 2; 2+zeros(Int, length(20:30)); 2; 1; 0] +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)