Unverified Commit 15efb26a authored by Laurent Heirendt's avatar Laurent Heirendt Committed by GitHub
Browse files

Merge pull request #50 from LCSB-BioCore/lh-pkg-changes

Minor package changes
parents 38ce4d66 9ed20573
#ignore data files
*.json
*.mat
*.xml
.DS_Store
test/data/*.xml
test/data/*.mat
test/data/*.json
# ignore VScode clutter
/.vscode
......
name = "COBREXA"
uuid = "babc4406-5200-4a30-9033-bf5ae714c842"
authors = ["Some people"]
authors = ["The developers of COBREXA.jl"]
version = "0.1.0"
[deps]
......@@ -22,7 +22,6 @@ MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
OSQP = "ab2f91bb-94b4-55e3-9ba0-7f65df51de79"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
......
......@@ -30,16 +30,18 @@ This is package aims to provide constraint based reconstruction and analysis too
To install this package: `] add ???`. See the documentation for more information.
## Quick Example
Let's use `COBREXA.jl` to perform classic flux balance analysis on an *E. coli* community.
```julia
using COBREXA
using JuMP
using Tulip # pick any solver supported by JuMP
# download the model
model_file = COBREXA.Downloads.download("http://bigg.ucsd.edu/static/models/iJO1366.json", "iJO1366.json")
# Import E. coli models (models have pretty printing)
model_1 = read_model("iJO1366.json")
model_2 = read_model("iJO1366.json")
model_3 = read_model("iJO1366.json")
model_1 = read_model(model_file)
model_2 = read_model(model_file)
model_3 = read_model(model_file)
# Build an exascale model
exascale_model = join(model_1, model_2, model_3,...)
......
......@@ -23,7 +23,7 @@ using Tulip
model = read_model("e_coli_core.json")
optimizer = Tulip.Optimizer
optimizer = COBREXA.Tulip.Optimizer
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
cons = Dict("EX_glc__D_e" => (-12.0, -12.0))
sol = fba(model, biomass, optimizer, constraints=cons) # classic flux balance analysis
......
......@@ -8,12 +8,12 @@ using JuMP
using MAT
using Distributed
using DistributedData
using Downloads
using Requires
using JSON
using Measurements
using Statistics
using Random
using PyCall
using Tulip # for LPs
using OSQP # for QPs, but it kinda sucks
......
......@@ -38,7 +38,7 @@ function flux_variability_analysis(
end
(optimization_model, x0) = flux_balance_analysis(model, optimizer)
Z0 = JuMP.objective_value(optimization_model)
Z0 = COBREXA.JuMP.objective_value(optimization_model)
optimization_model = nothing # we won't need this one anymore, so free the memory
# store a JuMP optimization model at all workers
......@@ -91,7 +91,7 @@ Internal helper function for adding constraints to a model. Exists mainly
because for avoiding namespace problems on remote workers.
"""
function _FVA_add_constraint(model, c, x, Z0, gamma)
JuMP.@constraint(model, c' * x gamma * Z0)
COBREXA.JuMP.@constraint(model, c' * x gamma * Z0)
end
"""
......@@ -102,11 +102,11 @@ namespace problems.
"""
function _FVA_optimize_reaction(model, rid)
sense = rid > 0 ? MOI.MAX_SENSE : MOI.MIN_SENSE
var = JuMP.all_variables(model)[abs(rid)]
var = COBREXA.JuMP.all_variables(model)[abs(rid)]
JuMP.@objective(model, sense, var)
JuMP.optimize!(model)
return JuMP.objective_value(model)
COBREXA.JuMP.@objective(model, sense, var)
COBREXA.JuMP.optimize!(model)
return COBREXA.JuMP.objective_value(model)
end
"""
......
......@@ -120,7 +120,7 @@ function pfba(
termination_status(cbm) == MOI.LOCALLY_SOLVED # try to relax bound if failed optimization
break
else
JuMP.delete(cbm, pfbacon)
COBREXA.JuMP.delete(cbm, pfbacon)
@constraint(cbm, lbconval * λ <= sum(v[i] for i in objective_indices) <= λ)
optimize!(cbm)
end
......
......@@ -10,7 +10,7 @@ function make_optimization_model(
m, n = size(stoichiometry(model))
xl, xu = bounds(model)
optimization_model = JuMP.Model(optimizer)
optimization_model = COBREXA.JuMP.Model(optimizer)
@variable(optimization_model, x[i = 1:n])
@objective(optimization_model, sense, objective(model)' * x)
mb = @constraint(optimization_model, mb, stoichiometry(model) * x .== balance(model)) # mass balance
......@@ -30,6 +30,6 @@ function optimize_model(
) where {LM<:MetabolicModel}
optimization_model, x, _, _, _ =
make_optimization_model(model, optimizer; sense = sense)
JuMP.optimize!(optimization_model)
COBREXA.JuMP.optimize!(optimization_model)
return (optimization_model, x)
end
......@@ -2,19 +2,19 @@
cp = test_simpleLP()
(lp, x) = flux_balance_analysis(cp, GLPK.Optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test sol [1.0, 2.0]
(lp, x) = flux_balance_analysis(cp, Clp.Optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test sol [1.0, 2.0]
# test the maximization of the objective
cp = test_simpleLP2()
(lp, x) = flux_balance_analysis(cp, GLPK.Optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test sol [-1.0, 2.0]
# test with a more biologically meaningfull model
......@@ -29,7 +29,7 @@
(lp, x) = flux_balance_analysis(cp, GLPK.Optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test objective_value(lp) expected_optimum
@test cp.c' * sol expected_optimum
......@@ -54,7 +54,7 @@ end
# FBA
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
cons = Dict("EX_glc__D_e" => (-12.0, -12.0))
optimizer = Tulip.Optimizer # quiet by default
optimizer = COBREXA.Tulip.Optimizer # quiet by default
sol = fba(model, optimizer; objective_func = biomass, constraints = cons)
pfl = findfirst(model.reactions, "PFL")
solmulti = fba(model, optimizer; objective_func = [biomass, pfl], weights = [0.8, 0.2]) # classic flux balance analysis
......
......@@ -74,7 +74,7 @@ end
pfl = findfirst(model.reactions, "PFL")
# FVA
optimizer = Tulip.Optimizer
optimizer = COBREXA.Tulip.Optimizer
atts = Dict("IPM_IterationsLimit" => 500)
cons = Dict("EX_glc__D_e" => (-10.0, -10.0))
fva_max, fva_min =
......
......@@ -27,7 +27,7 @@
) # just see if it works - OSQP is a terrible LP solver
sol = pfba(
model,
[Tulip.Optimizer, OSQP.Optimizer];
[COBREXA.Tulip.Optimizer, COBREXA.OSQP.Optimizer];
objective_func = biomass,
solver_attributes = Dict("opt1" => Dict{Any,Any}(), "opt2" => atts),
) # try two optimizers
......
......@@ -4,12 +4,12 @@
optimizer = GLPK.Optimizer
(lp, x) = optimize_model(cp, optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test sol [1.0, 2.0]
optimizer = Clp.Optimizer
(lp, x) = optimize_model(cp, optimizer)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
sol = COBREXA.JuMP.value.(x)
@test sol [1.0, 2.0]
end
......@@ -14,7 +14,6 @@ using OSQP
using Statistics
using JSON
using Measurements
using Downloads
function run_test_file(path...)
fn = joinpath(path...)
......@@ -42,7 +41,7 @@ function download_data_file(url, path, hash)
return path
end
Downloads.download(url, path)
COBREXA.Downloads.download(url, path)
check_data_file_hash(path, hash)
return path
end
......
......@@ -8,7 +8,7 @@
),
)
optimizer = Tulip.Optimizer
optimizer = COBREXA.Tulip.Optimizer
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
cons = Dict("EX_glc__D_e" => (-12.0, -12.0))
atts = Dict("IPM_IterationsLimit" => 110)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment