Unverified Commit 9ee80312 authored by cylon-x's avatar cylon-x 🤖 Committed by St. Elmo
Browse files

automatic formatting changes

parent 02f2cc9f
......@@ -19,17 +19,22 @@ add_objective!(model, ["met1", "met2"]; objective_weights=[0.1, 0.9]) # adds a n
add_objective!(model, ["met1", "met2"]; objective_weights=[0.1, 0.9], objective_column_index=10) # updates column 10
```
"""
function add_objective!(community::CoreModel, objective_mets::Vector{String}; objective_weights=Float64[], objective_column_index=0)
function add_objective!(
community::CoreModel,
objective_mets::Vector{String};
objective_weights = Float64[],
objective_column_index = 0,
)
obj_inds = indexin(objective_mets, metabolites(community))
if isempty(objective_weights)
objective_weights = repeat([1.0], inner=length(objective_mets))
objective_weights = repeat([1.0], inner = length(objective_mets))
end
if objective_column_index == 0 # needs to be created
nr, _ = size(community.S)
objcol = spzeros(nr)
objcol[obj_inds] .= -objective_weights
# extend model by one reaction
community.S = hcat(community.S, objcol)
community.xl = [community.xl; 0.0]
......@@ -48,7 +53,8 @@ function add_objective!(community::CoreModel, objective_mets::Vector{String}; ob
end
end
add_objective!(model::CoreModel, objective_met::String, objective_weight::Float64) = add_objective!(model, [objective_met], [objective_weight])
add_objective!(model::CoreModel, objective_met::String, objective_weight::Float64) =
add_objective!(model, [objective_met], [objective_weight])
"""
add_model(
......@@ -78,13 +84,14 @@ function add_model(
model::M,
exchange_rxn_ids::Vector{String},
exchange_met_ids::Vector{String};
species_name="",
biomass_id=""
) where {M<:MetabolicModel}
species_name = "",
biomass_id = "",
) where {M<:MetabolicModel}
exchange_met_community_inds = indexin(exchange_met_ids, metabolites(community))
exchange_rxn_community_inds = indexin(exchange_rxn_ids, reactions(community))
if any(isnothing.(exchange_met_community_inds)) || any(isnothing.(exchange_rxn_community_inds))
if any(isnothing.(exchange_met_community_inds)) ||
any(isnothing.(exchange_rxn_community_inds))
throw(
DomainError(
"exchange metabolite/reaction not found.",
......@@ -112,11 +119,11 @@ function add_model(
biomass_met = 0.0
if biomass_id != "" # add biomass metabolite
biomass_rxn = first(indexin([biomass_id], reactions(model)))
biomass_rxn = first(indexin([biomass_id], reactions(model)))
push!(Iadd, n_model_rows + n_cmodel_rows + 1)
push!(Jadd, biomass_rxn + n_cmodel_cols)
push!(Vadd, 1.0)
biomass_met = 1
biomass_met = 1
end
n_metabolites_total = n_model_rows + n_cmodel_rows + biomass_met
......@@ -133,12 +140,12 @@ function add_model(
lbs = [lbs; lbsadd]
ubs = [ubs; ubsadd]
rxnsadd = "$(species_name)_".*reactions(model)
rxnsadd = "$(species_name)_" .* reactions(model)
if biomass_id != ""
metsadd =
["$(species_name)_" .* metabolites(model); "$(species_name)_" * biomass_id]
else
metsadd = "$(species_name)_".*metabolites(model)
metsadd = "$(species_name)_" .* metabolites(model)
end
rxns = [reactions(community); rxnsadd]
mets = [metabolites(community); metsadd]
......
......@@ -210,7 +210,7 @@ end
@test size(stoichiometry(m1)) == (70, 94)
@test size(stoichiometry(m2)) == (71, 94)
@test size(stoichiometry(m3)) == (70, 94)
@test size(stoichiometry(m4)) == (71, 94)
@test size(stoichiometry(m4)) == (71, 94)
@test any(["glc__D_e", "for_c"] . Ref(metabolites(m1)))
@test any(["glc__D_e"] . Ref(metabolites(m2)))
@test any(["glc__D_e", "for_c"] . Ref(metabolites(m3)))
......
......@@ -27,8 +27,15 @@
community.xl[env_ex_inds] .= m2.xl[m2_ex_inds]
community.xu[env_ex_inds] .= m2.xu[m2_ex_inds]
biomass_ids = ["species_1_BIOMASS_Ecoli_core_w_GAM", "species_2_BIOMASS_Ecoli_core_w_GAM"]
add_objective!(community, biomass_ids; objective_column_index=first(indexin(["community_biomass"], reactions(community))))
biomass_ids =
["species_1_BIOMASS_Ecoli_core_w_GAM", "species_2_BIOMASS_Ecoli_core_w_GAM"]
add_objective!(
community,
biomass_ids;
objective_column_index = first(
indexin(["community_biomass"], reactions(community)),
),
)
d = flux_balance_analysis_dict(community, Tulip.Optimizer)
@test size(stoichiometry(community)) == (166, 211)
......@@ -127,11 +134,25 @@ end
m2 = load_model(CoreModel, model_path)
community = add_model(community, m2, exchange_rxn_ids, exchange_met_ids; species_name="species_2", biomass_id="BIOMASS_Ecoli_core_w_GAM")
biomass_ids = ["species_1_BIOMASS_Ecoli_core_w_GAM", "species_2_BIOMASS_Ecoli_core_w_GAM"]
add_objective!(community, biomass_ids; objective_column_index=first(indexin(["community_biomass"], reactions(community))))
community = add_model(
community,
m2,
exchange_rxn_ids,
exchange_met_ids;
species_name = "species_2",
biomass_id = "BIOMASS_Ecoli_core_w_GAM",
)
biomass_ids =
["species_1_BIOMASS_Ecoli_core_w_GAM", "species_2_BIOMASS_Ecoli_core_w_GAM"]
add_objective!(
community,
biomass_ids;
objective_column_index = first(
indexin(["community_biomass"], reactions(community)),
),
)
d = flux_balance_analysis_dict(community, Tulip.Optimizer)
@test size(stoichiometry(community)) == (166, 211)
......
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