Unverified Commit f8b6830c authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

clean up exchanges a bit

parent 1011dcb5
Pipeline #42914 passed with stages
in 8 minutes and 13 seconds
......@@ -18,17 +18,20 @@ Also see [`find_exchange_reactions`](@ref).
findall(looks_like_exchange_reaction, reactions(model)) # returns indices
filter(looks_like_exchange_reaction, reactions(model)) # returns Strings
# to use the optional arguments you need to expand the function's arguments using an anonymous function
# to use the optional arguments you need to expand the function's arguments
# using an anonymous function
findall(x -> looks_like_exchange_reaction(x; exclude_biomass=true), reactions(model)) # returns indices
filter(x -> looks_like_exchange_reaction(x; exclude_biomass=true), reactions(model)) # returns Strings
```
"""
function looks_like_exchange_reaction(rxn_id::String;
function looks_like_exchange_reaction(
rxn_id::String;
exclude_biomass = false,
biomass_strings = _constants.biomass_strings,
exchange_prefixes = _constants.exchange_prefixes,
)::Bool
any(startswith(rxn_id, x) for x in exchange_prefixes) && !(exclude_biomass && any(occursin(x, rxn_id) for x in biomass_strings))
any(startswith(rxn_id, x) for x in exchange_prefixes) &&
!(exclude_biomass && any(occursin(x, rxn_id) for x in biomass_strings))
end
"""
......@@ -43,7 +46,7 @@ find_exchange_reactions(m::MetabolicModel; kwargs...) =
"""
find_exchange_reaction_ids(m::MetabolicModel; kwargs...)
Shortcut for finding exchange reaction names in a model; arguments are
Shortcut for finding exchange reaction identifiers in a model; arguments are
forwarded to [`looks_like_exchange_reaction`](@ref).
"""
find_exchange_reaction_ids(m::MetabolicModel; kwargs...) =
......@@ -67,12 +70,14 @@ filter(looks_like_biomass_reaction, reactions(model)) # returns strings
findall(looks_like_biomass_reaction, reactions(model)) # returns indices
```
"""
function looks_like_biomass_reaction(rxn_id::String;
function looks_like_biomass_reaction(
rxn_id::String;
exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.biomass_strings,
)::Bool
any(occursin(x, rxn_id) for x in biomass_strings) && !(exclude_exchanges && any(startswith(rxn_id, x) for x in exchange_prefixes))
any(occursin(x, rxn_id) for x in biomass_strings) &&
!(exclude_exchanges && any(startswith(rxn_id, x) for x in exchange_prefixes))
end
"""
find_biomass_reactions(m::MetabolicModel; kwargs...)
......@@ -86,8 +91,8 @@ find_biomass_reactions(m::MetabolicModel; kwargs...) =
"""
find_biomass_reaction_ids(m::MetabolicModel; kwargs...)
Shortcut for finding biomass reaction names in a model; arguments are forwarded
to [`looks_like_biomass_reaction`](@ref).
Shortcut for finding biomass reaction identifiers in a model; arguments are
forwarded to [`looks_like_biomass_reaction`](@ref).
"""
find_biomass_reaction_ids(m::MetabolicModel; kwargs...) =
filter(id -> looks_like_biomass_reaction(id, kwargs...), reactions(m))
......@@ -108,8 +113,26 @@ filter(looks_like_exchange_metabolite, metabolites(model)) # returns strings
findall(looks_like_exchange_metabolite, metabolites(model)) # returns indices
```
"""
function looks_like_exchange_metabolite(met_id::String;
function looks_like_exchange_metabolite(
met_id::String;
exchange_suffixes = _constants.exchange_suffixes,
)::Bool
any(endswith(met_id, x) for x in exchange_suffixes)
end
"""
find_exchange_metabolites(m::MetabolicModel; kwargs...)
Shortcut for finding exchange metabolite indexes in a model; arguments are
forwarded to [`looks_like_exchange_metabolite`](@ref).
"""
find_exchange_metabolites(m::MetabolicModel; kwargs...) =
findall(id -> looks_like_exchange_metabolite(id; kwargs...), metabolites(m))
"""
find_exchange_metabolite_ids(m::MetabolicModel; kwargs...)
Shortcut for finding exchange metabolite identifiers in a model; arguments are
forwarded to [`looks_like_exchange_metabolite`](@ref).
"""
find_exchange_metabolite_ids(m::MetabolicModel; kwargs...) =
findall(id -> looks_like_exchange_metabolite(id; kwargs...), metabolites(m))
......@@ -381,61 +381,6 @@ function change_coupling_bounds!(
end
end
"""
find_exchange_reactions(
model::CoreModelCoupled;
exclude_biomass = false,
biomass_str::String = "biomass",
exc_prefs = ["EX_"; "Exch_"; "Ex_"],
)
Get indices of exchange reactions.
Exchange reactions are identified based on most commonly used prefixes.
"""
function find_exchange_reactions(
model::CoreModelCoupled;
exclude_biomass = false,
biomass_str::String = "biomass",
exc_prefs = ["EX_"; "Exch_"; "Ex_"],
)
return find_exchange_reactions(
model.lm;
exclude_biomass = exclude_biomass,
biomass_str = biomass_str,
exc_prefs = exc_prefs,
)
end
"""
find_exchange_metabolites(
model::CoreModelCoupled;
exclude_biomass = false,
biomass_str::String = "biomass",
exc_prefs = ["EX_"; "Exch_"; "Ex_"],
)
Get indices of exchanged metabolites.
In practice returns the metabolites consumed by the reactions given by `find_exchange_reactions`
and if called with the same arguments, the two outputs correspond.
"""
function find_exchange_metabolites(
model::CoreModelCoupled;
exclude_biomass = false,
biomass_str::String = "biomass",
exc_prefs = ["EX_"; "Exch_"; "Ex_"],
)
return find_exchange_metabolites(
model.lm;
exclude_biomass = exclude_biomass,
biomass_str = biomass_str,
exc_prefs = exc_prefs,
)
end
"""
change_bounds!(
model::CoreModelCoupled,
......
Markdown is supported
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