Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 ✨ Atoms in reactions and overall flux #312

Merged
merged 4 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/base/utils/StandardModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,33 @@ function atom_exchange(flux_dict::Dict{String,Float64}, model::StandardModel)
atom_flux = Dict{String,Float64}()
for (rxn_id, flux) in flux_dict
if is_boundary(model.reactions[rxn_id])
for (met, stoich) in model.reactions[rxn_id].metabolites
for (met, stoich_rxn) in model.reactions[rxn_id].metabolites
adict = get_atoms(model.metabolites[met])
for (atom, stoich) in adict
atom_flux[atom] = get(atom_flux, atom, 0.0) + flux * stoich
for (atom, stoich_molecule) in adict
atom_flux[atom] = get(atom_flux, atom, 0.0) + flux * stoich_rxn * stoich_molecule
end
end
end
end
return atom_flux
end

"""
atom_exchange(rxn_id::String, model::StandardModel)

Return a dictionary mapping the flux of atoms through a reaction in `model`.
"""
function atom_exchange(rxn_id::String, model::StandardModel)
atom_flux = Dict{String,Float64}()
for (met, stoich_rxn) in model.reactions[rxn_id].metabolites
adict = get_atoms(model.metabolites[met])
for (atom, stoich_molecule) in adict
atom_flux[atom] = get(atom_flux, atom, 0.0) + stoich_rxn * stoich_molecule
end
end
return atom_flux
end

"""
metabolite_fluxes(flux_dict::Dict{String, Float64}, model::StandardModel)

Expand All @@ -75,7 +91,6 @@ produce them given the flux distribution supplied in `fluxdict`.
"""
function metabolite_fluxes(flux_dict::Dict{String,Float64}, model::StandardModel)
S = stoichiometry(model)
met_flux = Dict{String,Float64}()
rxnids = reactions(model)
metids = metabolites(model)

Expand Down
11 changes: 6 additions & 5 deletions test/base/utils/StandardModel.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

@testset "StandardModel utilities" begin
model = load_model(StandardModel, model_paths["e_coli_core.json"])

Expand All @@ -13,12 +12,14 @@

# atom tracker
atom_fluxes = atom_exchange(sol, model)
@test isapprox(atom_fluxes["C"], -37.1902, atol = 1e-3)

@test isapprox(atom_fluxes["C"], 37.1902, TEST_TOLERANCE)
@test atom_exchange("FBA", model)["C"] == 0.0
@test isapprox(atom_exchange("BIOMASS_Ecoli_core_w_GAM", model)["C"], -42.5555, TEST_TOLERANCE)

# metabolite trackers
consuming, producing = metabolite_fluxes(sol, model)
@test isapprox(consuming["atp_c"]["PFK"], -7.47738, atol = 1e-3)
@test isapprox(producing["atp_c"]["PYK"], 1.75818, atol = 1e-3)
@test isapprox(consuming["atp_c"]["PFK"], -7.47738, TEST_TOLERANCE)
@test isapprox(producing["atp_c"]["PYK"], 1.75818, TEST_TOLERANCE)

# set bounds
cbm = make_optimization_model(model, optimizer)
Expand Down