FluxVariabilitySummary.jl 3.58 KB
Newer Older
St. Elmo's avatar
St. Elmo committed
1
2
3
"""
    FluxVariabilitySummary

4
Stores summary information about the result of a flux variability analysis.
St. Elmo's avatar
St. Elmo committed
5
"""
St. Elmo's avatar
St. Elmo committed
6
struct FluxVariabilitySummary
7
8
    biomass_fluxes::Dict{String,Vector{Maybe{Float64}}}
    exchange_fluxes::Dict{String,Vector{Maybe{Float64}}}
St. Elmo's avatar
St. Elmo committed
9
10
end

11
12
13
"""
    FluxVariabilitySummary()

14
A default empty constructor for [`FluxVariabilitySummary`](@ref).
15
16
17
"""
function FluxVariabilitySummary()
    FluxVariabilitySummary(
18
19
        Dict{String,Vector{Maybe{Float64}}}(),
        Dict{String,Vector{Maybe{Float64}}}(),
20
21
22
    )
end

St. Elmo's avatar
St. Elmo committed
23
"""
24
    flux_variability_summary(flux_result::Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}};
St. Elmo's avatar
St. Elmo committed
25
26
27
28
        exclude_exchanges = false,
        exchange_prefixes = _constants.exchange_prefixes,
        biomass_strings = _constants.biomass_strings,
        exclude_biomass = false,
St. Elmo's avatar
St. Elmo committed
29
30
31
        )::FluxVariabilitySummary

Summarize a dictionary of flux dictionaries obtained eg. from
32
33
34
35
36
37
[`flux_variability_analysis_dict`](@ref). The simplified summary representation
is useful for pretty-printing and easily showing the most important results.

Internally this function uses [`looks_like_biomass_reaction`](@ref) and
[`looks_like_exchange_reaction`](@ref). The corresponding keyword arguments are
passed to these functions. Use this if your model has an uncommon naming of
38
reactions.
St. Elmo's avatar
St. Elmo committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

# Example
```
julia> sol = flux_variability_analysis_dict(model, Gurobi.Optimizer; bounds = objective_bounds(0.99))
julia> flux_res = flux_variability_summary(sol)
Biomass                     Lower bound   Upper bound
  BIOMASS_Ecoli_core_w_GAM: 0.8652        0.8652
Exchange
  EX_h2o_e:                 28.34         28.34
  EX_co2_e:                 22.0377       22.0377
  EX_o2_e:                  -22.1815      -22.1815
  EX_h_e:                   17.3556       17.3556
  EX_glc__D_e:              -10.0         -10.0
  EX_nh4_e:                 -4.8448       -4.8448
  EX_pi_e:                  -3.2149       -3.2149
  EX_for_e:                 0.0           0.0
  ...                       ...           ...
```
St. Elmo's avatar
St. Elmo committed
57
"""
St. Elmo's avatar
St. Elmo committed
58
59
function flux_variability_summary(
    flux_result::Tuple{Dict{String,Dict{String,Float64}},Dict{String,Dict{String,Float64}}};
St. Elmo's avatar
St. Elmo committed
60
61
62
63
    exclude_exchanges = false,
    exchange_prefixes = _constants.exchange_prefixes,
    biomass_strings = _constants.biomass_strings,
    exclude_biomass = false,
St. Elmo's avatar
St. Elmo committed
64
)
65
    isnothing(flux_result) && return FluxVariabilitySummary()
St. Elmo's avatar
St. Elmo committed
66

St. Elmo's avatar
St. Elmo committed
67
    rxn_ids = keys(flux_result[1])
St. Elmo's avatar
St. Elmo committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    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,
    )
St. Elmo's avatar
St. Elmo committed
86

87
    biomass_fluxes = Dict{String,Vector{Maybe{Float64}}}()
St. Elmo's avatar
St. Elmo committed
88
89
90
    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]
St. Elmo's avatar
St. Elmo committed
91
        biomass_fluxes[rxn_id] = [lb, ub]
St. Elmo's avatar
St. Elmo committed
92
93
    end

94
    ex_rxn_fluxes = Dict{String,Vector{Maybe{Float64}}}()
St. Elmo's avatar
St. Elmo committed
95
96
97
98
99
    for rxn_id in ex_rxns
        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]
        ex_rxn_fluxes[rxn_id] = [lb, ub]
    end
St. Elmo's avatar
St. Elmo committed
100

St. Elmo's avatar
St. Elmo committed
101
    return FluxVariabilitySummary(biomass_fluxes, ex_rxn_fluxes)
St. Elmo's avatar
St. Elmo committed
102
end