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

format

parent e861fcd1
Pipeline #56513 passed with stages
in 12 minutes and 52 seconds
......@@ -20,8 +20,7 @@ Change the lower and upper bounds (`lb` and `ub` respectively) of variable `id`
change_constraint(id::String; lb = nothing, ub = nothing) =
(model, opt_model) -> begin
ind = first(indexin([id], reactions(model)))
isnothing(ind) &&
throw(DomainError(id, "No matching reaction or gene was found."))
isnothing(ind) && throw(DomainError(id, "No matching variable was found."))
set_optmodel_bound!(ind, opt_model, lb = lb, ub = ub)
end
......@@ -29,8 +28,8 @@ change_constraint(id::String; lb = nothing, ub = nothing) =
change_objective(new_objective::Union{String,Vector{String}}; weights=[], sense=MAX_SENSE)
Modification that changes the objective function used in a constraint based
analysis function. `new_objective` can be a single reaction identifier, or an
array of reactions identifiers.
analysis function. `new_objective` can be a single variable identifier, or an
array of variable identifiers (usually variables are reaction ids).
Optionally, the objective can be weighted by a vector of `weights`, and a
optimization `sense` can be set to either `MAX_SENSE` or `MIN_SENSE`.
......@@ -46,14 +45,12 @@ change_objective(
if typeof(new_objective) == String
objective_indices = indexin([new_objective], reactions(model))
else
objective_indices = [
first(indexin([id], reactions(model))) for
id in new_objective
]
objective_indices =
[first(indexin([id], reactions(model))) for id in new_objective]
end
any(isnothing.(objective_indices)) && throw(
DomainError(new_objective, "No matching reaction found for one or more ids."),
DomainError(new_objective, "No matching variable found for one or more ids."),
)
# Initialize weights
......
......@@ -116,12 +116,12 @@ IDs are mangled accordingly with suffixes).
function reactions(model::GeckoModel)
inner_reactions = reactions(model.inner)
mangeled_reactions = [
_gecko_reaction_name(
inner_reactions[col.reaction_idx],
col.direction,
col.isozyme_idx,
) for col in model.columns
]
_gecko_reaction_name(
inner_reactions[col.reaction_idx],
col.direction,
col.isozyme_idx,
) for col in model.columns
]
[mangeled_reactions; genes(model)]
end
......
......@@ -26,7 +26,9 @@ gene_product_mass_group_dict(model::GeckoModel, opt_model) =
is_solved(opt_model) ?
Dict(
grp.group_id => dot(
value.(opt_model[:x])[(n_reactions(model)-n_genes(model)).+grp.gene_product_idxs],
value.(opt_model[:x])[(n_reactions(
model,
)-n_genes(model)).+grp.gene_product_idxs],
grp.gene_product_molar_masses,
) for grp in model.coupling_row_mass_group
) : nothing
......
......@@ -52,19 +52,15 @@
@test isapprox(prot_mass, mass_groups["uncategorized"], atol = TEST_TOLERANCE)
# test enzyme objective
growth_lb = rxn_fluxes["BIOMASS_Ecoli_core_w_GAM"]*0.9
growth_lb = rxn_fluxes["BIOMASS_Ecoli_core_w_GAM"] * 0.9
opt_model = flux_balance_analysis(
gm,
Tulip.Optimizer;
modifications = [
change_objective(
genes(gm);
weights = [],
sense = COBREXA.MIN_SENSE,
),
change_objective(genes(gm); weights = [], sense = COBREXA.MIN_SENSE),
change_constraint("BIOMASS_Ecoli_core_w_GAM", lb = growth_lb),
change_optimizer_attribute("IPM_IterationsLimit", 1000)
]
change_optimizer_attribute("IPM_IterationsLimit", 1000),
],
)
mass_groups_min = gene_product_mass_group_dict(gm, opt_model)
@test mass_groups_min["uncategorized"] < mass_groups["uncategorized"]
......@@ -93,8 +89,8 @@ end
gs = [Gene("g$i") for i = 1:5]
m.reactions["r2"].grr = [["g5"],]
m.reactions["r3"].grr = [["g1"],]
m.reactions["r2"].grr = [["g5"]]
m.reactions["r3"].grr = [["g1"]]
m.reactions["r4"].grr = [["g1"], ["g2"]]
m.reactions["r5"].grr = [["g3", "g4"]]
m.reactions["r6"].objective_coefficient = 1.0
......
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