Skip to content

Commit

Permalink
support yeast-GEM-style indexed compartment names
Browse files Browse the repository at this point in the history
Closes #691
  • Loading branch information
exaexa committed Nov 3, 2022
1 parent c083ad3 commit f42613c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const _constants = (
metformulas = ["metFormula", "metFormulas"],
metcharges = ["metCharge", "metCharges"],
metcompartments = ["metCompartment", "metCompartments", "metComp", "metComps"],
metcomptables = ["comps", "compNames"],
rxnnames = ["rxnNames"],
metnames = ["metNames"],
),
Expand Down
17 changes: 13 additions & 4 deletions src/base/types/MATModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,19 @@ $(TYPEDSIGNATURES)
Extract metabolite compartment from `metCompartment` or `metCompartments`.
"""
metabolite_compartment(m::MATModel, mid::String) = _maybemap(
x -> x[findfirst(==(mid), metabolites(m))],
gets(m.mat, nothing, _constants.keynames.metcompartments),
)
function metabolite_compartment(m::MATModel, mid::String)
res = _maybemap(
x -> x[findfirst(==(mid), metabolites(m))],
gets(m.mat, nothing, _constants.keynames.metcompartments),
)
# if the metabolite is an integer or a (very integerish) float, it is an
# index to a table of metabolite names (such as in the yeast GEM)
typeof(res) <: Real || return res
return _maybemap(
table -> table[Int(res)],
gets(m.mat, nothing, _constants.keynames.metcomptables),
)
end

"""
$(TYPEDSIGNATURES)
Expand Down

0 comments on commit f42613c

Please sign in to comment.