FluxVariabilitySummary.jl 3.03 KB
Newer Older
St. Elmo's avatar
St. Elmo committed
1
2
3
4
5
6
"""
    FluxVariabilitySummary

A struct used to store summary information about the 
solution of a flux variability analysis result.
"""
St. Elmo's avatar
St. Elmo committed
7
struct FluxVariabilitySummary
St. Elmo's avatar
St. Elmo committed
8
9
    biomass_fluxes :: Dict{String, Vector{Union{Float64, Nothing}}}
    exchange_fluxes :: Dict{String, Vector{Union{Float64, Nothing}}} 
St. Elmo's avatar
St. Elmo committed
10
11
end

St. Elmo's avatar
St. Elmo committed
12
"""
St. Elmo's avatar
St. Elmo committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    flux_variability_summary(flux_result::Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}}; 
        exclude_exchanges = false,
        exchange_prefixes = _constants.exchange_prefixes,
        biomass_strings = _constants.biomass_strings,
        exclude_biomass = false,
        )
Return a `FluxVariabilitySummary` struct based on the `flux_result` of a
constraint based analysis simulation. Internally this function uses
[`looks_like_biomass_reaction`](@ref) and
[`looks_like_exchange_reaction`](@ref). The corresponding keyword arguments
passed to these functions. Use this if your model has non-standard ids for
reactions. 

# 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
43
44
"""
function flux_variability_summary(flux_result::Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}}; 
St. Elmo's avatar
St. Elmo committed
45
46
47
48
49
50
    exclude_exchanges = false,
    exchange_prefixes = _constants.exchange_prefixes,
    biomass_strings = _constants.biomass_strings,
    exclude_biomass = false,
    )

St. Elmo's avatar
St. Elmo committed
51
    rxn_ids = keys(flux_result[1])
St. Elmo's avatar
St. Elmo committed
52
53
54
    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
55
56
57
58
    biomass_fluxes = Dict{String, Vector{Union{Float64, Nothing}}}()
    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
59
        biomass_fluxes[rxn_id] = [lb, ub]
St. Elmo's avatar
St. Elmo committed
60
61
    end

St. Elmo's avatar
St. Elmo committed
62
63
64
65
66
67
    ex_rxn_fluxes = Dict{String, Vector{Union{Float64, Nothing}}}() 
    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
68

St. Elmo's avatar
St. Elmo committed
69
    return FluxVariabilitySummary(biomass_fluxes, ex_rxn_fluxes)
St. Elmo's avatar
St. Elmo committed
70
end