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

done with src

parent 667eaac7
Pipeline #43070 failed with stages
in 6 minutes and 55 seconds
"""
struct FluxSummary
FluxSummary
A struct used to store information.
A struct used to store summary information about the solution
of a constraint based analysis result.
"""
struct FluxSummary
biomass_fluxes :: OrderedDict{String, Float64}
......@@ -12,15 +13,15 @@ end
"""
flux_summary(flux_result::Dict{String, Float64};
exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.biomass_strings,
exclude_biomass = false,
small_flux_bound = 1.0/_constants.default_reaction_bound^2,
large_flux_bound = _constants.default_reaction_bound,
round_digits = 3,
keep_unbounded = false,
)::FluxSummary
exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.biomass_strings,
exclude_biomass = false,
small_flux_bound = 1.0/_constants.default_reaction_bound^2,
large_flux_bound = _constants.default_reaction_bound,
round_digits = 3,
keep_unbounded = false,
)::FluxSummary
Return a `FluxSummary` struct based on the `flux_result` of a constraint based
analysis simulation. Internally this function uses
......@@ -60,21 +61,21 @@ function flux_summary(flux_result::Dict{String, Float64};
large_flux_bound = _constants.default_reaction_bound,
keep_unbounded = false,
)
ex_rxns = filter(x -> looks_like_exchange_reaction(x, exclude_biomass=exclude_biomass, biomass_strings=biomass_strings, exchange_prefixes=exchange_prefixes), keys(flux_result))
bmasses = filter(x -> looks_like_biomass_reaction(x; exclude_exchanges=exclude_exchanges, exchange_prefixes=exchange_prefixes, biomass_strings=biomass_strings), keys(flux_result))
rxn_ids = collect(keys(flux_result))
ex_rxns = filter(x -> looks_like_exchange_reaction(x, exclude_biomass=exclude_biomass, biomass_strings=biomass_strings, exchange_prefixes=exchange_prefixes), rxn_ids)
bmasses = filter(x -> looks_like_biomass_reaction(x; exclude_exchanges=exclude_exchanges, exchange_prefixes=exchange_prefixes, biomass_strings=biomass_strings), rxn_ids)
ex_fluxes = [flux_result[k] for k in ex_rxns]
bmass_fluxes = [flux_result[k] for k in bmasses]
idx_srt_fluxes = sortperm(ex_fluxes)
lower_unbounded = [idx for idx in idx_srt_fluxes if ex_fluxes[idx] <= -large_flux_bound]
upper_unbounded = [idx for idx in idx_srt_fluxes if ex_fluxes[idx] >= large_flux_bound]
import_fluxes = [idx for idx in idx_srt_fluxes if -large_flux_bound < ex_fluxes[idx] <= -small_flux_bound]
export_fluxes = [idx for idx in idx_srt_fluxes if small_flux_bound < ex_fluxes[idx] <= large_flux_bound]
if keep_unbounded
return FluxSummary(Dict(k => v for (k, v) in zip(bmasses, bmass_fluxes)),
lower_unbounded = [idx for idx in idx_srt_fluxes if ex_fluxes[idx] <= -large_flux_bound]
upper_unbounded = [idx for idx in idx_srt_fluxes if ex_fluxes[idx] >= large_flux_bound]
return FluxSummary(Dict(k => v for (k, v) in zip(bmasses, bmass_fluxes)),
OrderedDict(k => v for (k, v) in zip(ex_rxns[import_fluxes], ex_fluxes[import_fluxes])),
OrderedDict(k => v for (k, v) in zip(ex_rxns[export_fluxes], ex_fluxes[export_fluxes])),
OrderedDict(k => v for (k, v) in zip([ex_rxns[lower_unbounded]; ex_rxns[upper_unbounded]], [ex_fluxes[lower_unbounded]; ex_fluxes[upper_unbounded]])),
......
......@@ -33,7 +33,7 @@ function flux_variability_summary(flux_result::Tuple{Dict{String, Dict{String, F
for rxn_id in bmasses
lb = isnothing(flux_result[1][rxn_id]) ? nothing : flux_result[1][rxn_id][rxn_id]
ub = isnothing(flux_result[2][rxn_id]) ? nothing : flux_result[2][rxn_id][rxn_id]
res[rxn_id] = [lb, ub]
biomass_fluxes[rxn_id] = [lb, ub]
end
ex_rxn_fluxes = Dict{String, Vector{Union{Float64, Nothing}}}()
......
function _pad_spaces(str, maxlen)
join(repeat([" "], inner=maxlen - length(str) + 1))
function _pad_spaces(str::String, maxlen::Int)
join(repeat([" "], inner=max(0,maxlen - length(str) + 1)))
end
function _pad_spaces(slen::Int, maxlen::Int)
join(repeat([" "], inner=max(0,maxlen - slen + 1)))
end
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)])
println(io, "Biomass:")
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)])
if !isempty(flux_res.unbounded_fluxes)
longest_unbounded_len = maximum([length(k) for k in keys(flux_res.unbounded_fluxes)])
word_pad = max(longest_biomass_len, longest_export_len, longest_import_len, longest_unbounded_len)
else
word_pad = max(longest_biomass_len, longest_export_len, longest_import_len)
end
println(io, "Biomass")
for (k, v) in flux_res.biomass_fluxes
println(io, " ", k, ":", _pad_spaces(k, longest_biomass_len), round(v, digits=4))
println(io, " ", k, ":", _pad_spaces(k, word_pad), round(v, digits=4))
end
longest_import_len = maximum([length(k) for k in keys(flux_res.import_fluxes)])
println(io, "Import:")
println(io, "Import")
for (k, v) in flux_res.import_fluxes
println(io, " ", k, ":", _pad_spaces(k, longest_import_len), round(v, digits=4))
println(io, " ", k, ":", _pad_spaces(k, word_pad), round(v, digits=4))
end
longest_export_len = maximum([length(k) for k in keys(flux_res.import_fluxes)])
println(io, "Export:")
println(io, "Export")
for (k, v) in flux_res.export_fluxes
println(io, " ", k, ":", _pad_spaces(k, longest_export_len), round(v, digits=4))
println(io, " ", k, ":", _pad_spaces(k, word_pad), round(v, digits=4))
end
if !isempty(flux_res.unbounded_fluxes)
longest_unbounded_len = maximum([length(k) for k in keys(flux_res.unbounded_fluxes)])
println(io, "Unbounded:")
println(io, "Unbounded")
for (k, v) in flux_res.unbounded_fluxes
println(io, " ", k, ":", _pad_spaces(k, longest_unbounded_len), round(v, digits=4))
println(io, " ", k, ":", _pad_spaces(k, word_pad), round(v, digits=4))
end
end
return nothing
......
......@@ -4,21 +4,25 @@ function Base.show(io::IO, ::MIME"text/plain", flux_res::FluxVariabilitySummary)
longest_exchange_len = maximum([length(k) for k in keys(flux_res.exchange_fluxes)])
word_pad_len = max(longest_biomass_len, longest_exchange_len)
longest_biomass_flux_len = maximum([length(string(round(v[1], digits)) for v in values(flux_res.biomass_fluxes)])
longest_exchange_flux_len = maximum([length(string(v[1])) for v in values(flux_res.exchange_fluxes)])
longest_biomass_flux_len = maximum([length(string(round(v[1], digits=4))) for v in values(flux_res.biomass_fluxes)])
longest_exchange_flux_len = max(maximum([length(string(round(v[1], digits=4))) for v in values(flux_res.exchange_fluxes)]), length("Lower bound "))
number_pad_len = max(longest_biomass_flux_len, longest_exchange_flux_len)
println(io, "Biomass:", _pad_spaces(length("Biomass: "), word_pad_len),"Lower bound", _pad_spaces("Lower bound", number_pad_len), "Upper bound")
println(io, "Biomass", _pad_spaces(length("Biomass"), word_pad_len+3),"Lower bound ", _pad_spaces("Lower bound ", number_pad_len), "Upper bound")
for (k, v) in flux_res.biomass_fluxes
lb = isnothing(v[1]) ? " " : string(round(v[1], digits=4))
ub = isnothing(v[2]) ? " " : string(round(v[1], digits=4))
println(io, " ", k, ":", _pad_spaces(k, longest_biomass_len), lb, _pad_spaces(lb, longest_biomass_flux_len), ub)
println(io, " ", k, ":", _pad_spaces(k, word_pad_len), lb, _pad_spaces(lb, number_pad_len), ub)
end
# println(io, "Exchange",join(repeat([" "], inner=longest_exchange_len+2-6)),"Lower bound", _pad_spaces("Lower bound", longest_exchange_flux_len), "Upper bound")
# for (k, v) in flux_res.exchange_fluxes
# lb = isnothing(v[1]) ? " " : string(round(v[1], digits=4))
# ub = isnothing(v[2]) ? " " : string(round(v[1], digits=4))
# println(io, " ", k, ":", _pad_spaces(k, longest_exchange_len), lb, _pad_spaces(lb, longest_exchange_flux_len), ub)
# end
println(io, "Exchange")
ex_ids = collect(keys(flux_res.exchange_fluxes))
vs = [abs(flux_res.exchange_fluxes[k][1]) + abs(flux_res.exchange_fluxes[k][2]) for k in ex_ids]
idxs = sortperm(vs, rev=true)
for k in ex_ids[idxs]
v = flux_res.exchange_fluxes[k]
lb = isnothing(v[1]) ? " " : string(round(v[1], digits=4))
ub = isnothing(v[2]) ? " " : string(round(v[1], digits=4))
println(io, " ", k, ":", _pad_spaces(k, word_pad_len), lb, _pad_spaces(lb, number_pad_len), ub)
end
end
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