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

added initial functions

parent 1e74656a
struct FluxSummary
biomass_fluxes :: Dict{String, Float64}
import_fluxes :: Dict{String, Float64}
export_fluxes :: Dict{String, Float64}
unbounded_fluxes :: Dict{String, Float64}
end
"""
flux_summary(model::MetabolicModel, 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
Return a `FluxSummary` struct based on the `flux_result` of a constraint based
analysis simulation of `model`. Internally this function uses
[`looks_like_biomass_reaction`](@ref) and
[`looks_like_exchange_reaction`](@ref). The corresponding keyword arguments can
be set in `summarize` and are then passed to these functions if your model has
nonstandard ids for reactions. Fluxes smaller than `small_flux_bound` are not
displayed, while fluxes larger than `large_flux_bound` are only displayed if
`display_unbounded` is `true`. `round_digits` is used to round the displayed
value of the flux.
This function is most useful as a way to generate a struct that has nice pretty
printing of flux results. The resultant struct can also be used in downstream
applications if necessary.
# Example
```
```
"""
function flux_summary(model::MetabolicModel, 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,
keep_unbounded = false,
)
ex_rxns = filter(x -> looks_like_exchange_reaction(x, exclude_biomass=exclude_biomass, biomass_strings=biomass_strings, exchange_prefixes=exchange_prefixes), reactions(model))
bmasses = filter(x -> looks_like_biomass_reaction(x; exclude_exchanges=exclude_exchanges, exchange_prefixes=exchange_prefixes, biomass_strings=biomass_strings), reactions(model))
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)),
Dict(k => v for (k, v) in zip(ex_rxns[import_fluxes], ex_fluxes[import_fluxes])),
Dict(k => v for (k, v) in zip(ex_rxns[export_fluxes], ex_fluxes[export_fluxes])),
Dict(k => v for (k, v) in zip([ex_rxns[lower_unbounded]; ex_rxns[upper_unbounded]], [ex_fluxes[lower_unbounded]; ex_fluxes[upper_unbounded]])),
)
else
return FluxSummary(Dict(k => v for (k, v) in zip(bmasses, bmass_fluxes)),
Dict(k => v for (k, v) in zip(ex_rxns[import_fluxes], ex_fluxes[import_fluxes])),
Dict(k => v for (k, v) in zip(ex_rxns[export_fluxes], ex_fluxes[export_fluxes])),
Dict{String, Float64}(),
)
end
end
struct FluxVariabilitySummary
biomass_fluxes :: Dict{String, Float64}
import_fluxes :: Dict{String, Float64}
export_fluxes :: Dict{String, Float64}
unbounded_fluxes :: Dict{String, Float64}
end
function flux_variability_summary(model::MetabolicModel, flux_result::Dict{String, 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,
)
end
function Base.show(io::IO, ::MIME"text/plain", flux_res::FluxSummary)
c = Base.text_colors # of course I added colors :)
# println(c[:bold]*c[:light_black], "Biomass:", c[:normal]) # display all the biomass fluxes
# for (k, v) in zip(bmasses, bmass_fluxes)
# println("\t", c[:light_magenta], k, ": ", c[:normal], round(v, digits=round_digits), c[:normal])
# end
# println(c[:bold]*c[:light_black],"Import:", c[:normal])
# for (k, v) in zip(ex_rxns[import_fluxes], ex_fluxes[import_fluxes])
# println("\t", c[:light_magenta], k, ": ", c[:normal], round(v, digits=round_digits))
# end
# println(c[:bold]*c[:light_black],"Export:", c[:normal])
# for (k, v) in zip(ex_rxns[export_fluxes], ex_fluxes[export_fluxes])
# println("\t", c[:light_magenta], k, ": ", c[:normal], round(v, digits=round_digits))
# end
# println(c[:bold]*c[:light_black],"Unbounded:", c[:normal])
# for (k, v) in zip([ex_rxns[lower_unbounded]; ex_rxns[upper_unbounded]], [ex_fluxes[lower_unbounded]; ex_fluxes[upper_unbounded]])
# println("\t", c[:light_magenta], k, ": ", c[:normal], round(v, digits=round_digits))
# end
end
function Base.show(io::IO, ::MIME"text/html", flux_res::FluxSummary)
end
function Base.show(io::IO, ::MIME"text/plain", flux_res::FluxVariabilitySummary)
# for the repl
end
function Base.show(io::IO, ::MIME"text/html", flux_res::FluxVariabilitySummary)
# for jupyter
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