Unverified Commit a1987d7d authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #316 from LCSB-BioCore/mk-cleanup-exchange-stuff

clean up exchanges a bit
parents d4509bae f8b6830c
Pipeline #42915 passed with stages
in 19 minutes and 57 seconds
...@@ -18,17 +18,20 @@ Also see [`find_exchange_reactions`](@ref). ...@@ -18,17 +18,20 @@ Also see [`find_exchange_reactions`](@ref).
findall(looks_like_exchange_reaction, reactions(model)) # returns indices findall(looks_like_exchange_reaction, reactions(model)) # returns indices
filter(looks_like_exchange_reaction, reactions(model)) # returns Strings 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 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 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, exclude_biomass = false,
biomass_strings = _constants.biomass_strings, biomass_strings = _constants.biomass_strings,
exchange_prefixes = _constants.exchange_prefixes, exchange_prefixes = _constants.exchange_prefixes,
)::Bool )::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 end
""" """
...@@ -43,7 +46,7 @@ find_exchange_reactions(m::MetabolicModel; kwargs...) = ...@@ -43,7 +46,7 @@ find_exchange_reactions(m::MetabolicModel; kwargs...) =
""" """
find_exchange_reaction_ids(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). forwarded to [`looks_like_exchange_reaction`](@ref).
""" """
find_exchange_reaction_ids(m::MetabolicModel; kwargs...) = find_exchange_reaction_ids(m::MetabolicModel; kwargs...) =
...@@ -67,12 +70,14 @@ filter(looks_like_biomass_reaction, reactions(model)) # returns strings ...@@ -67,12 +70,14 @@ filter(looks_like_biomass_reaction, reactions(model)) # returns strings
findall(looks_like_biomass_reaction, reactions(model)) # returns indices 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, exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes, exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.biomass_strings, biomass_strings = _constants.biomass_strings,
)::Bool )::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 end
""" """
find_biomass_reactions(m::MetabolicModel; kwargs...) find_biomass_reactions(m::MetabolicModel; kwargs...)
...@@ -86,8 +91,8 @@ find_biomass_reactions(m::MetabolicModel; kwargs...) = ...@@ -86,8 +91,8 @@ find_biomass_reactions(m::MetabolicModel; kwargs...) =
""" """
find_biomass_reaction_ids(m::MetabolicModel; kwargs...) find_biomass_reaction_ids(m::MetabolicModel; kwargs...)
Shortcut for finding biomass reaction names in a model; arguments are forwarded Shortcut for finding biomass reaction identifiers in a model; arguments are
to [`looks_like_biomass_reaction`](@ref). forwarded to [`looks_like_biomass_reaction`](@ref).
""" """
find_biomass_reaction_ids(m::MetabolicModel; kwargs...) = find_biomass_reaction_ids(m::MetabolicModel; kwargs...) =
filter(id -> looks_like_biomass_reaction(id, kwargs...), reactions(m)) filter(id -> looks_like_biomass_reaction(id, kwargs...), reactions(m))
...@@ -108,8 +113,26 @@ filter(looks_like_exchange_metabolite, metabolites(model)) # returns strings ...@@ -108,8 +113,26 @@ filter(looks_like_exchange_metabolite, metabolites(model)) # returns strings
findall(looks_like_exchange_metabolite, metabolites(model)) # returns indices 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, exchange_suffixes = _constants.exchange_suffixes,
)::Bool )::Bool
any(endswith(met_id, x) for x in exchange_suffixes) any(endswith(met_id, x) for x in exchange_suffixes)
end 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!( ...@@ -381,61 +381,6 @@ function change_coupling_bounds!(
end end
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!( change_bounds!(
model::CoreModelCoupled, 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