Commit 6a1743ac authored by St. Elmo's avatar St. Elmo
Browse files

format fix

parent 92648559
using Documenter, COBREXA
makedocs(modules = [COBREXA],
clean = false,
sitename = "COBREXA.jl",
format = Documenter.HTML(
# Use clean URLs, unless built as a "local" build
prettyurls = !("local" in ARGS),
assets = ["assets/favicon.ico"],
highlights = ["yaml"],
),
authors = "The developers of COBREXA.jl",
linkcheck = !("skiplinks" in ARGS),
pages = [
"Home" => "index.md",
"Functions" => "functions.md",
"How to contribute" => "howToContribute.md",
"Model Structure" => "model_structure.md",
"Model IO" => "io.md",
"Model Construction" => "model_construction.md",
"Optimization Based Analysis Tools" => "basic_analysis.md",
"Sampling Tools" => "sampling_tools.md",
],
)
makedocs(
modules = [COBREXA],
clean = false,
sitename = "COBREXA.jl",
format = Documenter.HTML(
# Use clean URLs, unless built as a "local" build
prettyurls = !("local" in ARGS),
assets = ["assets/favicon.ico"],
highlights = ["yaml"],
),
authors = "The developers of COBREXA.jl",
linkcheck = !("skiplinks" in ARGS),
pages = [
"Home" => "index.md",
"Functions" => "functions.md",
"How to contribute" => "howToContribute.md",
"Model Structure" => "model_structure.md",
"Model IO" => "io.md",
"Model Construction" => "model_construction.md",
"Optimization Based Analysis Tools" => "basic_analysis.md",
"Sampling Tools" => "sampling_tools.md",
],
)
......@@ -27,7 +27,9 @@ _printBanner()
# autoloading
const _inc(path...) = include(joinpath(path...))
const _inc_all(dir) = _inc.(joinpath.(dir, filter(fn -> endswith(fn, ".jl"), readdir(dir))))
_inc_all.(joinpath.(@__DIR__, ["types", "base", "io", "reconstruction", "analysis", "sampling"]))
_inc_all.(
joinpath.(@__DIR__, ["types", "base", "io", "reconstruction", "analysis", "sampling"]),
)
# export everything that isn't prefixed with _ (inspired by JuMP.jl, thanks!)
for sym in names(@__MODULE__, all = true)
......
......@@ -39,10 +39,10 @@ function fba(
weights = Float64[],
solver_attributes = Dict{Any,Any}(),
constraints = Dict{String,Tuple{Float64,Float64}}(),
sense = MOI.MAX_SENSE
sense = MOI.MAX_SENSE,
)
# get core optimization problem
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense=sense)
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense = sense)
# modify core optimization problem according to user specifications
if !isempty(solver_attributes) # set other attributes
......@@ -62,7 +62,7 @@ function fba(
# ensure that an array of objective indices are fed in
if typeof(objective_func) == Reaction
objective_indices = [model[objective_func]]
else
else
objective_indices = [model[rxn] for rxn in objective_func]
end
......@@ -79,7 +79,7 @@ function fba(
# model.reactions[i].objective_coefficient = weights[wcounter]
opt_weights[i] = weights[wcounter]
wcounter += 1
# else
# else
# model.reactions[i].objective_coefficient = 0.0
end
end
......
......@@ -138,9 +138,9 @@ function fva(
weights = Float64[],
solver_attributes = Dict{Any,Any}(),
constraints = Dict{String,Tuple{Float64,Float64}}(),
sense = MOI.MAX_SENSE
sense = MOI.MAX_SENSE,
)
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense=sense)
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense = sense)
if !isempty(solver_attributes) # set other attributes
for (k, v) in solver_attributes
......@@ -159,7 +159,7 @@ function fva(
# ensure that an array of objective indices are fed in
if typeof(objective_func) == Reaction
objective_indices = [model[objective_func]]
else
else
objective_indices = [model[rxn] for rxn in objective_func]
end
......@@ -176,7 +176,7 @@ function fva(
# model.reactions[i].objective_coefficient = weights[wcounter]
opt_weights[i] = weights[wcounter]
wcounter += 1
# else
# else
# model.reactions[i].objective_coefficient = 0.0
end
end
......
......@@ -27,20 +27,21 @@ function pfba(
weights = Float64[],
solver_attributes = Dict{Any,Any}(),
constraints = Dict{String,Tuple{Float64,Float64}}(),
sense = MOI.MAX_SENSE
sense = MOI.MAX_SENSE,
)
## FBA ################################################
if typeof(optimizer) <: AbstractArray # choose optimizer
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer[1], sense=sense)
cbm, v, mb, lbcons, ubcons =
makeOptimizationModel(model, optimizer[1], sense = sense)
if !isempty(solver_attributes["opt1"]) # set other attributes
for (k, v) in solver_attributes["opt1"]
set_optimizer_attribute(cbm, k, v)
end
end
else # singe optimizer
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense=sense)
cbm, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense = sense)
if !isempty(solver_attributes) # set other attributes
for (k, v) in solver_attributes
set_optimizer_attribute(cbm, k, v)
......@@ -74,7 +75,7 @@ function pfba(
# model.reactions[i].objective_coefficient = weights[wcounter]
opt_weights[i] = weights[wcounter]
wcounter += 1
# else
# else
# model.reactions[i].objective_coefficient = 0.0
end
end
......@@ -114,12 +115,13 @@ function pfba(
optimize!(cbm)
for lbconval in [0.999999, 0.99999, 0.9999, 0.999, 0.99] # relax bound for stability
if termination_status(cbm) == MOI.OPTIMAL || termination_status(cbm) == MOI.LOCALLY_SOLVED # try to relax bound if failed optimization
if termination_status(cbm) == MOI.OPTIMAL ||
termination_status(cbm) == MOI.LOCALLY_SOLVED # try to relax bound if failed optimization
break
else
JuMP.delete(cbm, pfbacon)
@constraint(cbm, lbconval * λ <= sum(v[i] for i in objective_indices) <= λ)
optimize!(cbm)
optimize!(cbm)
end
end
......
......@@ -19,5 +19,6 @@ function _printBanner()
| | | | | | _ \\| |_) | _| $(g)\\$(n) $(r)/$(n) / _ \\ | and EXascale Analysis in Julia
| |__| |_| | |_) | _ <| |___ $(m)/$(n) $(b)\\$(n) / ___ \\ |
\\____\\___/|____/|_| \\_\\_____$(m)/_/$(n)$(b)\\_\\$(n)/_/ \\_\\ | Version: v$(COBREXA_VERSION)
|")
|",
)
end
......@@ -98,10 +98,10 @@ function hit_and_run(
samplesize = 1000,
solver_attributes = Dict{Any,Any}(),
random_objective = false,
sense = MOI.MAX_SENSE
sense = MOI.MAX_SENSE,
)
# get core optimization problem
cbmodel, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense=sense)
cbmodel, v, mb, lbcons, ubcons = makeOptimizationModel(model, optimizer, sense = sense)
if !isempty(solver_attributes) # set other attributes
for (k, v) in solver_attributes
......
@testset "Flux balance analysis with CobraModel" begin
model = read_model(Downloads.download("http://bigg.ucsd.edu/static/models/e_coli_core.json", joinpath("data", "e_coli_core.json")))
model = read_model(
Downloads.download(
"http://bigg.ucsd.edu/static/models/e_coli_core.json",
joinpath("data", "e_coli_core.json"),
),
)
@test length(model.reactions) == 95 # read in correctly
# 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
sol = fba(model, optimizer; objective_func=biomass, constraints = cons)
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
solmulti = fba(model, optimizer; objective_func = [biomass, pfl], weights = [0.8, 0.2]) # classic flux balance analysis
flux_vec = [sol[rxn.id] for rxn in model.reactions]
sol_mapped = map_fluxes(flux_vec, model)
@test isapprox(
sol_mapped["BIOMASS_Ecoli_core_w_GAM"],
1.0572509997013568,
atol = 1e-6,
)
@test isapprox(sol["BIOMASS_Ecoli_core_w_GAM"], 1.0572509997013568, atol = 1e-6)
@test !isempty(solmulti)
sol = fba(model, optimizer; objective_func=biomass)
@test isapprox(sol_mapped["BIOMASS_Ecoli_core_w_GAM"], 1.0572509997013568, atol = 1e-6)
@test isapprox(sol["BIOMASS_Ecoli_core_w_GAM"], 1.0572509997013568, atol = 1e-6)
@test !isempty(solmulti)
sol = fba(model, optimizer; objective_func = biomass)
# atom tracker
atom_fluxes = atom_exchange(sol, model)
......
@testset "Flux variability analysis with CobraModel" begin
model = read_model(Downloads.download("http://bigg.ucsd.edu/static/models/e_coli_core.json", joinpath("data", "e_coli_core.json")))
model = read_model(
Downloads.download(
"http://bigg.ucsd.edu/static/models/e_coli_core.json",
joinpath("data", "e_coli_core.json"),
),
)
@test length(model.reactions) == 95 # read in correctly
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
......@@ -9,9 +14,15 @@
optimizer = Tulip.Optimizer
atts = Dict("IPM_IterationsLimit" => 500)
cons = Dict("EX_glc__D_e" => (-10.0, -10.0))
fva_max, fva_min = fva(model, optimizer; objective_func=biomass, solver_attributes = atts)
fva_max2, fva_min2 =
fva(model, optimizer; objective_func=[biomass, pfl], weights = [0.5, 0.5], constraints = cons)
fva_max, fva_min =
fva(model, optimizer; objective_func = biomass, solver_attributes = atts)
fva_max2, fva_min2 = fva(
model,
optimizer;
objective_func = [biomass, pfl],
weights = [0.5, 0.5],
constraints = cons,
)
@testset "FVA" begin
@test isapprox(fva_max["PDH"]["PDH"], 9.338922420065819, atol = 1e-6)
@test isapprox(fva_min["PDH"]["PDH"], 9.270274952732315, atol = 1e-6)
......
@testset "Parsimonious flux balance analysis with CobraModel" begin
model = read_model(Downloads.download("http://bigg.ucsd.edu/static/models/e_coli_core.json", joinpath("data", "e_coli_core.json")))
model = read_model(
Downloads.download(
"http://bigg.ucsd.edu/static/models/e_coli_core.json",
joinpath("data", "e_coli_core.json"),
),
)
@test length(model.reactions) == 95 # read in correctly
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
......@@ -13,7 +18,13 @@
"max_iter" => 100_000,
"verbose" => false,
)
solworks = pfba(model, optimizer; objective_func=biomass, solver_attributes = atts, constraints = cons) # just see if it works - OSQP is a terrible LP solver
solworks = pfba(
model,
optimizer;
objective_func = biomass,
solver_attributes = atts,
constraints = cons,
) # just see if it works - OSQP is a terrible LP solver
sol = pfba(
model,
[Tulip.Optimizer, OSQP.Optimizer];
......
@testset "IO" begin
# E. coli models - realistic size models
iJO1366_xml = Downloads.download("http://bigg.ucsd.edu/static/models/iJO1366.xml", joinpath("data", "iJO1366.xml"))
iJO1366_xml = Downloads.download(
"http://bigg.ucsd.edu/static/models/iJO1366.xml",
joinpath("data", "iJO1366.xml"),
)
sbmlmodel_ecoli = read_model(iJO1366_xml)
@test_broken length(sbmlmodel_ecoli.reactions) == 2583
iJO1366_mat = Downloads.download("http://bigg.ucsd.edu/static/models/iJO1366.mat", joinpath("data", "iJO1366.mat"))
iJO1366_mat = Downloads.download(
"http://bigg.ucsd.edu/static/models/iJO1366.mat",
joinpath("data", "iJO1366.mat"),
)
matlabmodel_ecoli = read_model(iJO1366_mat)
@test length(matlabmodel_ecoli.reactions) == 2583
iJO1366_json = Downloads.download("http://bigg.ucsd.edu/static/models/iJO1366.json", joinpath("data", "iJO1366.json"))
iJO1366_json = Downloads.download(
"http://bigg.ucsd.edu/static/models/iJO1366.json",
joinpath("data", "iJO1366.json"),
)
jsonmodel_ecoli = read_model(iJO1366_json)
@test length(jsonmodel_ecoli.reactions) == 2583
......
@testset "Sampling Tests" begin
# these tests are not very good - sampling needs work
model = read_model(Downloads.download("http://bigg.ucsd.edu/static/models/e_coli_core.json", joinpath("data", "e_coli_core.json")))
model = read_model(
Downloads.download(
"http://bigg.ucsd.edu/static/models/e_coli_core.json",
joinpath("data", "e_coli_core.json"),
),
)
@test length(model.reactions) == 95 # read in correctly
......@@ -8,10 +13,10 @@
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
cons = Dict("EX_glc__D_e" => (-12.0, -12.0))
atts = Dict("IPM_IterationsLimit" => 110)
sol = fba(model, optimizer; objective_func=biomass, constraints = cons)
sol = fba(model, optimizer; objective_func = biomass, constraints = cons)
cons["BIOMASS_Ecoli_core_w_GAM"] =
(sol["BIOMASS_Ecoli_core_w_GAM"] * 0.99, sol["BIOMASS_Ecoli_core_w_GAM"])
samples = hit_and_run(
100_000,
model,
......@@ -21,9 +26,9 @@
constraints = cons,
solver_attributes = atts,
)
# @test isapprox(mean(samples[64, :]), 8.9, atol = 0.5) # only tests if the sampler approximately converged
# samples = achr(
# 100_000,
# model,
......
Markdown is supported
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