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

Added fusing + some small modifications to functions

parent 7ca418a3
Pipeline #45150 passed with stages
in 12 minutes and 38 seconds
......@@ -25,19 +25,19 @@ change_constraint(id::String, lb, ub) =
end
"""
change_objective(new_objective::Union{String,Vector{String}}; weights=[], sense=MOI.MAX_SENSE)
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.
Optionally, the objective can be weighted by a vector of `weights`, and a
optimization `sense` can be set.
optimization `sense` can be set to either `MAX_SENSE` or `MIN_SENSE`.
"""
change_objective(
new_objective::Union{String,Vector{String}};
weights = [],
sense = MOI.MAX_SENSE,
sense = MAX_SENSE,
) =
(model, opt_model) -> begin
......
......@@ -11,6 +11,20 @@ struct FluxSummary
unbounded_fluxes::OrderedDict{String,Float64}
end
"""
FluxSummary()
A default empty constructor for `FluxSummary`.
"""
function FluxSummary()
FluxSummary(
OrderedDict{String,Float64}(),
OrderedDict{String,Float64}(),
OrderedDict{String,Float64}(),
OrderedDict{String,Float64}(),
)
end
"""
flux_summary(flux_result::Dict{String, Float64};
exclude_exchanges = false,
......@@ -49,7 +63,7 @@ Export:
```
"""
function flux_summary(
flux_result::Dict{String,Float64};
flux_result::Maybe{Dict{String,Float64}};
exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.biomass_strings,
......@@ -58,6 +72,8 @@ function flux_summary(
large_flux_bound = _constants.default_reaction_bound,
keep_unbounded = false,
)
isnothing(flux_result) && return FluxSummary()
rxn_ids = collect(keys(flux_result))
ex_rxns = filter(
x -> looks_like_exchange_reaction(
......
......@@ -9,6 +9,18 @@ struct FluxVariabilitySummary
exchange_fluxes::Dict{String,Vector{Union{Float64,Nothing}}}
end
"""
FluxVariabilitySummary()
A default empty constructor for `FluxVariabilitySummary`
"""
function FluxVariabilitySummary()
FluxVariabilitySummary(
Dict{String,Vector{Union{Float64,Nothing}}}(),
Dict{String,Vector{Union{Float64,Nothing}}}(),
)
end
"""
flux_variability_summary(flux_result::Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}};
exclude_exchanges = false,
......@@ -50,6 +62,7 @@ function flux_variability_summary(
biomass_strings = _constants.biomass_strings,
exclude_biomass = false,
)
isnothing(flux_result) && return FluxVariabilitySummary()
rxn_ids = keys(flux_result[1])
ex_rxns = filter(
......
......@@ -14,14 +14,13 @@ function metabolite_fluxes(model::MetabolicModel, flux_dict::Dict{String,Float64
for (row, mid) in enumerate(mids)
for (col, rid) in enumerate(rids)
mf = flux_dict[rid] * S[row, col]
# ignore zero flux
if mf < -_constants.tolerance # consuming rxn
if mf < 0 # consuming rxn
if haskey(consuming, mid)
consuming[mid][rid] = mf
else
consuming[mid] = Dict(rid => mf)
end
elseif mf > _constants.tolerance
elseif mf >= 0 # producing rxn
if haskey(producing, mid)
producing[mid][rid] = mf
else
......
......@@ -5,9 +5,10 @@ end
_pad_spaces(str::String, maxlen::Int) = _pad_spaces(length(str), maxlen)
function Base.show(io::IO, ::MIME"text/plain", flux_res::FluxSummary)
longest_biomass_len = maximum([length(k) for k in keys(flux_res.biomass_fluxes)])
longest_import_len = maximum([length(k) for k in keys(flux_res.import_fluxes)])
longest_export_len = maximum([length(k) for k in keys(flux_res.export_fluxes)])
longest_biomass_len =
maximum(length(k) for k in keys(flux_res.biomass_fluxes); init = 0)
longest_import_len = maximum(length(k) for k in keys(flux_res.import_fluxes); init = 0)
longest_export_len = maximum(length(k) for k in keys(flux_res.export_fluxes); init = 0)
if !isempty(flux_res.unbounded_fluxes)
longest_unbounded_len =
......
function Base.show(io::IO, ::MIME"text/plain", flux_res::FluxVariabilitySummary)
longest_biomass_len = maximum([length(k) for k in keys(flux_res.biomass_fluxes)])
longest_exchange_len = maximum([length(k) for k in keys(flux_res.exchange_fluxes)])
longest_biomass_len =
maximum(length(k) for k in keys(flux_res.biomass_fluxes); init = 0)
longest_exchange_len =
maximum(length(k) for k in keys(flux_res.exchange_fluxes); init = 0)
word_pad_len = max(longest_biomass_len, longest_exchange_len)
longest_biomass_flux_len = maximum([
length(string(round(v[1], digits = 4))) for v in values(flux_res.biomass_fluxes)
])
longest_biomass_flux_len = maximum(
length(string(round(v[1], digits = 4))) for v in values(flux_res.biomass_fluxes);
init = 0,
)
longest_exchange_flux_len = max(
maximum([
maximum(
length(string(round(v[1], digits = 4))) for
v in values(flux_res.exchange_fluxes)
]),
v in values(flux_res.exchange_fluxes);
init = 0,
),
length("Lower bound "),
)
number_pad_len = max(longest_biomass_flux_len, longest_exchange_flux_len)
......
......@@ -53,7 +53,7 @@ end
exchange_rxn_mets = Dict(
ex_rxn => first(keys(reaction_stoichiometry(m2, ex_rxn))) for
ex_rxn in filter(looks_like_exchange_reaction, reactions(m2))
ex_rxn in reactions(m2) if looks_like_exchange_reaction(ex_rxn)
)
biomass_ids = ["BIOMASS_Ecoli_core_w_GAM", "BIOMASS_Ecoli_core_w_GAM"]
......@@ -91,7 +91,7 @@ end
exchange_rxn_mets = Dict(
ex_rxn => first(keys(reaction_stoichiometry(m2, ex_rxn))) for
ex_rxn in filter(looks_like_exchange_reaction, reactions(m2))
ex_rxn in reactions(m2) if looks_like_exchange_reaction(ex_rxn)
)
biomass_ids = ["BIOMASS_Ecoli_core_w_GAM", "BIOMASS_Ec_iJO1366_core_53p95M"]
......@@ -143,7 +143,7 @@ end
exchange_rxn_mets = Dict(
ex_rxn => first(keys(reaction_stoichiometry(m1, ex_rxn))) for
ex_rxn in filter(looks_like_exchange_reaction, reactions(m1))
ex_rxn in reactions(m1) if looks_like_exchange_reaction(ex_rxn)
)
biomass_ids = ["BIOMASS_Ecoli_core_w_GAM"]
......
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