Unverified Commit 0a68a3b4 authored by St. Elmo's avatar St. Elmo
Browse files

fixed remaining tests

parent 730aaafd
......@@ -165,7 +165,7 @@ function flux_variability_analysis(
λmin <= COBREXA.JuMP.objective_function(opt_model) <= λmax # in case there is a negative bound
)
for i = 1:length(v)
for (i, r_id) in enumerate(reactions(model))
COBREXA.JuMP.@objective(opt_model, Max, v[i])
COBREXA.JuMP.optimize!(opt_model)
status = (
......@@ -173,11 +173,11 @@ function flux_variability_analysis(
COBREXA.JuMP.termination_status(opt_model) == MOI.LOCALLY_SOLVED
)
if status
fva_max[model.reactions[i].id] =
fva_max[r_id] =
Dict(zip(reactions(model), value.(opt_model[:x])))
else
@warn "Error maximizing index: $i with error $(termination_status(opt_model))"
fva_max[model.reactions[i].id] = nothing
fva_max[r_id] = nothing
end
@objective(opt_model, Min, v[i])
......@@ -187,11 +187,11 @@ function flux_variability_analysis(
termination_status(opt_model) == MOI.LOCALLY_SOLVED
)
if status
fva_min[model.reactions[i].id] =
fva_min[r_id] =
Dict(zip(reactions(model), value.(opt_model[:x])))
else
@warn "Error minimizing index: $i with error $(termination_status(opt_model))"
fva_min[model.reactions[i].id] = nothing
fva_min[r_id] = nothing
end
end
......
function _get_boundary_reaction_ids(model::StandardModel)::Array{String,1}
return [i.id for i in model.reactions if length(i.metabolites) == 1]
return [r.id for r in values(model.reactions) if is_boundary(r)]
end
function add_cycle_free(fluxes::Dict{String,Float64})
......@@ -8,7 +8,7 @@ function add_cycle_free(fluxes::Dict{String,Float64})
old_objective = objective_function(opt_model)
boundary_ids = _get_boundary_reaction_ids(model)
min_objectives = zeros(Int64, 1, length(v))
for (i, reaction) in enumerate(model.reactions)
for (i, reaction) in enumerate(values(model.reactions))
id = reaction.id
if v[i] in old_objective.terms.keys
continue
......
......@@ -50,8 +50,8 @@ end
model = read_model(model_path, StandardModel)
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
glucose = findfirst(model.reactions, "EX_glc__D_e")
biomass = model.reactions["BIOMASS_Ecoli_core_w_GAM"]
glucose = model.reactions["EX_glc__D_e"]
sol = flux_balance_analysis_dict(
model,
Tulip.Optimizer;
......@@ -68,7 +68,7 @@ end
atol = TEST_TOLERANCE,
)
pfl = findfirst(model.reactions, "PFL")
pfl = model.reactions["PFL"]
pfl_frac = 0.8
biomass_frac = 0.2
sol_multi = flux_balance_analysis_dict(
......
......@@ -69,9 +69,9 @@ end
model = read_model(model_path, StandardModel)
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
glucose = findfirst(model.reactions, "EX_glc__D_e")
oxygen = findfirst(model.reactions, "EX_o2_e")
biomass = model.reactions["BIOMASS_Ecoli_core_w_GAM"]
glucose = model.reactions["EX_glc__D_e"]
oxygen = model.reactions["EX_o2_e"]
fva_max, fva_min = flux_variability_analysis(
model,
Tulip.Optimizer;
......
......@@ -7,8 +7,8 @@
model = read_model(model_path, StandardModel)
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
glucose = findfirst(model.reactions, "EX_glc__D_e")
biomass = model.reactions["BIOMASS_Ecoli_core_w_GAM"]
glucose = model.reactions["EX_glc__D_e"]
d = parsimonious_flux_balance_analysis_dict(
model,
......
......@@ -45,7 +45,7 @@ end
model = create_loopless_test_model()
optimizer = Tulip.Optimizer
# first test that fba in fact does not give the loopless solution
objective = findfirst(model.reactions, "v5")
objective = model.reactions["v5"]
res_fba = flux_balance_analysis_dict(
model,
optimizer,
......
......@@ -58,10 +58,10 @@ run_test_file("data", "test_models.jl")
# import base files
@testset "COBREXA test suite" begin
# run_test_dir("types", "Data structures")
# run_test_dir("base", "Base functionality")
# run_test_dir("io", "I/O functions")
run_test_dir("types", "Data structures")
run_test_dir("base", "Base functionality")
run_test_dir("io", "I/O functions")
run_test_dir("reconstruction")
# run_test_dir("analysis")
# run_test_dir("sampling")
run_test_dir("analysis")
run_test_dir("sampling")
end
......@@ -8,8 +8,8 @@
model = read_model(model_path, StandardModel)
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
glucose = findfirst(model.reactions, "EX_glc__D_e")
biomass = model.reactions["BIOMASS_Ecoli_core_w_GAM"
glucose = model.reactions["EX_glc__D_e"
opt_model = flux_balance_analysis(
model,
Tulip.Optimizer;
......@@ -19,7 +19,7 @@
change_solver_attribute("IPM_IterationsLimit", 500),
],
)
biomass_index = model[biomass]
biomass_index = index_of(biomass, model)
λ = JuMP.value(opt_model[:x][biomass_index])
change_constraint(biomass, 0.99 * λ, λ)(model, opt_model)
......
@testset "Sampling Tests" begin
# these tests are not very good - sampling needs work
# # these tests are not very good - sampling needs work
model_path = download_data_file(
"http://bigg.ucsd.edu/static/models/e_coli_core.json",
joinpath("data", "e_coli_core.json"),
......@@ -8,8 +8,8 @@
model = read_model(model_path, StandardModel)
biomass = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")
glucose = findfirst(model.reactions, "EX_glc__D_e")
biomass = model.reactions["BIOMASS_Ecoli_core_w_GAM"]
glucose = model.reactions["EX_glc__D_e"]
opt_model = flux_balance_analysis(
model,
Tulip.Optimizer;
......@@ -19,13 +19,13 @@
change_solver_attribute("IPM_IterationsLimit", 500),
],
)
biomass_index = model[biomass]
biomass_index = index_of(biomass, reactions(model))
λ = JuMP.value(opt_model[:x][biomass_index])
change_constraint(biomass, 0.99 * λ, λ)(model, opt_model)
samples = hit_and_run(100_000, opt_model, keepevery = 10, samplesize = 5000)
# The sampling converges very randomly and extremely approximately, so only
# test a rough result
# # The sampling converges very randomly and extremely approximately, so only
# # test a rough result
@test isapprox(mean(samples[64, :]), 8.9, atol = 0.1)
end
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