Utilities
Helper functions
COBREXA.ambiguously_identified_items
— Methodambiguously_identified_items(index::Dict{String, Dict{String, Set{String}}}) -> Set{String}
Find items (genes, metabolites, ...) from the annotation index that are identified non-uniquely by at least one of their annotations.
This often indicates that the items are duplicate or miscategorized.
COBREXA.annotation_index
— Methodannotation_index(xs::AbstractDict{String}; annotations) -> Dict{String, Dict{String, Set{String}}}
Extract annotations from a dictionary of items xs
and build an index that maps annotation "kinds" (e.g. "PubChem"
) to the mapping from the annotations (e.g. "COMPOUND_12345"
) to item IDs that carry the annotations.
Function annotations
is used to access the Annotations
object in the dictionary values.
This is extremely useful for finding items by annotation data.
COBREXA.check_duplicate_reaction
— Methodcheck_duplicate_reaction(crxn::Reaction, rxns::OrderedCollections.OrderedDict{String, Reaction}; only_metabolites) -> Union{Nothing, String}
Check if rxn
already exists in rxns
but has another id
. If only_metabolites
is true
then only the metabolite id
s are checked. Otherwise, compares metabolite id
s and the absolute value of their stoichiometric coefficients to those of rxn
. If rxn
has the same reaction equation as another reaction in rxns
, the return the id
. Otherwise return nothing
.
See also: reaction_mass_balanced
COBREXA.is_boundary
— Methodis_boundary(rxn_dict::Dict{String, Float64}) -> Bool
Return true if the reaction denoted by rxn_dict
is a boundary reaction, otherwise return false. Checks if on boundary by inspecting the number of metabolites in rxn_dict
. Boundary reactions have only one metabolite, e.g. an exchange reaction, or a sink/demand reaction.
COBREXA.reaction_atom_balance
— Methodreaction_atom_balance(model::MetabolicModel, reaction_dict::Dict{String, Float64}) -> Dict{String, Float64}
Returns a dictionary mapping the stoichiometry of atoms through a single reaction. Uses the metabolite information in model
to determine the mass balance. Accepts a reaction dictionary, a reaction string id or a Reaction
as an argument for rxn
.
See also: reaction_mass_balanced
COBREXA.reaction_mass_balanced
— Methodreaction_mass_balanced(model::StandardModel, rxn_id::String) -> Bool
Checks if rxn
is atom balanced. Returns a boolean for whether the reaction is balanced, and the associated balance of atoms for convenience (useful if not balanced). Calls reaction_atom_balance
internally.
See also: check_duplicate_reaction
, reaction_atom_balance
COBREXA.stoichiometry_string
— Methodstoichiometry_string(req; format_id) -> String
Return the reaction equation as a string. The metabolite strings can be manipulated by setting format_id
.
Example
julia> req = Dict("coa_c" => -1, "for_c" => 1, "accoa_c" => 1, "pyr_c" => -1)
julia> stoichiometry_string(req)
"coa_c + pyr_c = for_c + accoa_c"
julia> stoichiometry_string(req; format_id = x -> x[1:end-2])
"coa + pyr = for + accoa"
COBREXA.stoichiometry_string
— Methodstoichiometry_string(rxn::Reaction; kwargs...) -> String
Alternative of stoichiometry_string
take takes a Reaction
as an argument.
COBREXA.serialize_model
— Methodserialize_model(model::Serialized, filename::String) -> Serialized
Specialization of serialize_model
that prevents nested serialization of already-serialized models.
COBREXA.serialize_model
— Methodserialize_model(model::MetabolicModel, filename::String) -> Serialized
Serialize the model
to file filename
, returning a Serialized
model that can be loaded back transparently by precache!
. The result does not contain the actual model data that are deferred to the disk; it may thus be used to save memory, or send the model efficiently to remote workers within distributed shared-storage environments.
The benefit of using this over "raw" Serialization.serialize
is that the resulting Serialized
model will reload itself automatically with precache!
at first usage, which needs to be done manually when using the Serialization
package directly.
Base.copy
— Methodcopy(g::Gene) -> Gene
Shallow copy of a Gene
Base.copy
— Methodcopy(m::Metabolite) -> Metabolite
Shallow copy of a Metabolite
Base.copy
— Methodcopy(r::Reaction) -> Reaction
Shallow copy of a Reaction
Base.copy
— Methodcopy(m::StandardModel) -> StandardModel
Shallow copy of a StandardModel
COBREXA.gamma_bounds
— Methodgamma_bounds(gamma) -> COBREXA.var"#659#660"
A bounds-generating function for flux_variability_analysis
that limits the objective value to be at least gamma*Z₀
, as usual in COBRA packages. Use as the bounds
argument:
flux_variability_analysis(model, some_optimizer; bounds = gamma_bounds(0.9))
COBREXA.objective_bounds
— Methodobjective_bounds(tolerance) -> COBREXA.var"#661#662"
A bounds-generating function for flux_variability_analysis
that limits the objective value to a small multiple of Z₀. Use as bounds
argument, similarly to gamma_bounds
.
COBREXA._parse_formula
— Method_parse_formula(f::String) -> Dict{String, Int64}
Parse a formula in format C2H6O
into a MetaboliteFormula
, which is basically a dictionary of atom counts in the molecule.
COBREXA._unparse_formula
— Method_unparse_formula(f::Dict{String, Int64}) -> String
Format MetaboliteFormula
to String
.
COBREXA.expression_probabilistic_bounds
— Methodexpression_probabilistic_bounds(relative_expression::Dict{String, Float64}, grr::Union{Nothing, Vector{Vector{String}}}) -> Float64
Create E-Flux-like bounds for a reaction that requires gene products given by grr
, with expression "choke" data given by relative probabilities (between 0 and 1) in relative_expression
.
COBREXA.gene_product_dict
— Methodgene_product_dict(model::GeckoModel, opt_model) -> Any
Return a dictionary mapping protein molar concentrations to their ids. The argument opt_model
is a solved optimization problem, typically returned by flux_balance_analysis
. See flux_dict
for the corresponding function that returns a dictionary of solved fluxes.
COBREXA.gene_product_dict
— Methodgene_product_dict(model::GeckoModel) -> COBREXA.var"#668#669"{GeckoModel}
A pipe-able variant of gene_product_dict
.
COBREXA.gene_product_mass
— Methodgene_product_mass(model::SMomentModel, opt_model) -> Any
Extract the total mass utilization in a solved SMomentModel
.
COBREXA.gene_product_mass
— Methodgene_product_mass(model::SMomentModel) -> COBREXA.var"#676#677"{SMomentModel}
A pipe-able variant of gene_product_mass
.
COBREXA.gene_product_mass_group_dict
— Methodgene_product_mass_group_dict(model::GeckoModel, opt_model) -> Union{Nothing, Dict}
Extract the mass utilization in mass groups from a solved GeckoModel
.
COBREXA.gene_product_mass_group_dict
— Methodgene_product_mass_group_dict(model::GeckoModel) -> COBREXA.var"#672#673"{GeckoModel}
A pipe-able variant of gene_product_mass_group_dict
.
COBREXA.atom_fluxes
— Methodatom_fluxes(model::MetabolicModel, reaction_fluxes::Dict{String, Float64}) -> Dict{String, Float64}
Return a dictionary mapping the flux of atoms across a flux solution given by reaction_fluxes
using the reactions in model
to determine the appropriate stoichiometry.
Note, this function ignores metabolites with no formula assigned to them, no error message will be displayed.
Note, if a model is mass balanced there should be not net flux of any atom. By removing reactions from the flux_solution you can investigate how that impacts the mass balances.
Example
# Find flux of Carbon through all metabolic reactions except the biomass reaction
delete!(fluxes, "BIOMASS_Ecoli_core_w_GAM")
atom_fluxes(model, fluxes)["C"]
COBREXA.metabolite_fluxes
— Methodmetabolite_fluxes(model::MetabolicModel, flux_dict::Dict{String, Float64}) -> Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}}
Return two dictionaries of metabolite id
s mapped to reactions that consume or produce them, given the flux distribution supplied in flux_dict
.
COBREXA._gecko_gene_product_coupling
— Method_gecko_gene_product_coupling(model::GeckoModel) -> SparseArrays.SparseMatrixCSC{Float64, Int64}
Compute the part of the coupling for GeckoModel that limits the amount of each kind of protein available.
COBREXA._gecko_mass_group_coupling
— Method_gecko_mass_group_coupling(model::GeckoModel) -> SparseArrays.SparseMatrixCSC{Float64, Int64}
Compute the part of the coupling for GeckoModel
that limits the total mass of each group of gene products.
COBREXA._gecko_reaction_column_reactions
— Method_gecko_reaction_column_reactions(columns, inner) -> SparseArrays.SparseMatrixCSC
Helper method that doesn't require the whole GeckoModel
.
COBREXA._gecko_reaction_column_reactions
— Method_gecko_reaction_column_reactions(model::GeckoModel) -> SparseArrays.SparseMatrixCSC{Int64, Int64}
Retrieve a utility mapping between reactions and split reactions; rows correspond to "original" reactions, columns correspond to "split" reactions.
COBREXA._gecko_reaction_coupling
— Method_gecko_reaction_coupling(model::GeckoModel) -> SparseArrays.SparseMatrixCSC{Int64, Int64}
Compute the part of the coupling for GeckoModel
that limits the "arm" reactions (which group the individual split unidirectional reactions).
COBREXA._gecko_reaction_name
— Method_gecko_reaction_name(original_name::String, direction::Int64, isozyme_idx::Int64) -> String
Internal helper for systematically naming reactions in GeckoModel
.
COBREXA._grr_grammar
— ConstantPikaParser grammar for stringy GRR expressions.
COBREXA._parse_grr
— Method_parse_grr(gpa::SBML.GeneProductAssociation) -> Vector{Vector{String}}
Parse SBML.GeneProductAssociation
structure and convert it to a strictly positive DNF GeneAssociation
. Negation (SBML.GPANot
) is not supported.
COBREXA._parse_grr
— Method_parse_grr(s::String) -> Union{Nothing, Vector{Vector{String}}}
Parse a DNF gene association rule in format (YIL010W and YLR043C) or (YIL010W and YGR209C)
to GeneAssociation. Also accepts
OR,
|,
||,
AND,
&, and
&&`.
Example
julia> _parse_grr("(YIL010W and YLR043C) or (YIL010W and YGR209C)")
2-element Array{Array{String,1},1}:
["YIL010W", "YLR043C"]
["YIL010W", "YGR209C"]
COBREXA._parse_grr_to_sbml
— Method_parse_grr_to_sbml(str::String) -> Union{Nothing, SBML.GeneProductAssociation}
Internal helper for parsing the string GRRs into SBML data structures. More general than _parse_grr
.
COBREXA._sortunique
— Method_sortunique(x) -> Any
A helper for producing predictable unique sequences. Might be faster if compacting would be done directly in sort().
COBREXA._unparse_grr
— Method_unparse_grr(_::Type{SBML.GeneProductAssociation}, x::Vector{Vector{String}}) -> SBML.GPAOr
Convert a GeneAssociation to the corresponding SBML.jl
structure.
COBREXA._unparse_grr
— Method_unparse_grr(::Type{String}, grr::Vector{Vector{String}}; and, or) -> String
Converts a nested string gene reaction array back into a gene reaction rule string.
Example
julia> _unparse_grr(String, [["YIL010W", "YLR043C"], ["YIL010W", "YGR209C"]])
"(YIL010W && YLR043C) || (YIL010W && YGR209C)"
COBREXA._guesskey
— Method_guesskey(avail, possibilities) -> Any
Unfortunately, many model types that contain dictionares do not have standardized field names, so we need to try a few possibilities and guess the best one. The keys used to look for valid field names should be ideally specified as constants in src/base/constants.jl
.
COBREXA.gets
— Methodgets(collection, fail, keys) -> Any
Return fail
if key in keys
is not in collection
, otherwise return collection[key]
. Useful if may different keys need to be tried due to non-standardized model formats.
COBREXA.find_biomass_reaction_ids
— Methodfind_biomass_reaction_ids(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding biomass reaction identifiers in a model; arguments are forwarded to looks_like_biomass_reaction
.
COBREXA.find_biomass_reactions
— Methodfind_biomass_reactions(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding biomass reaction indexes in a model; arguments are forwarded to looks_like_biomass_reaction
.
COBREXA.find_exchange_reaction_ids
— Methodfind_exchange_reaction_ids(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding exchange reaction identifiers in a model; arguments are forwarded to looks_like_exchange_reaction
.
COBREXA.find_exchange_reactions
— Methodfind_exchange_reactions(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding exchange reaction indexes in a model; arguments are forwarded to looks_like_exchange_reaction
.
COBREXA.find_extracellular_metabolite_ids
— Methodfind_extracellular_metabolite_ids(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding extracellular metabolite identifiers in a model; arguments are forwarded to looks_like_extracellular_metabolite
.
COBREXA.find_extracellular_metabolites
— Methodfind_extracellular_metabolites(m::MetabolicModel; kwargs...) -> Any
Shortcut for finding extracellular metabolite indexes in a model; arguments are forwarded to looks_like_extracellular_metabolite
.
COBREXA.is_atp_maintenance_reaction
— Methodis_atp_maintenance_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as an atpmaintenance reaction. Uses `Identifiers.ATPMAINTENANCEREACTIONSinternally, which includes SBO identifiers. In the reaction annotations, use the keys in
annotationkeys` to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_biomass_reaction
— Methodis_biomass_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as a biomass reaction. Uses Identifiers.BIOMASS_REACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_exchange_reaction
— Methodis_exchange_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as an exchange reaction. Uses Identifiers.EXCHANGE_REACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_metabolic_reaction
— Methodis_metabolic_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as a metabolic reaction. Uses Identifiers.METABOLIC_REACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_pseudo_reaction
— Methodis_pseudo_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as a pseudo reaction. Uses Identifiers.PSEUDOREACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_spontaneous_reaction
— Methodis_spontaneous_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as a spontaneous reaction. Uses Identifiers.SPONTANEOUS_REACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.is_transport_reaction
— Methodis_transport_reaction(
model::MetabolicModel,
reaction_id::String;
annotation_keys = ["sbo", "SBO"],
)
Check if a reaction is annotated as a transport reaction. Uses Identifiers.TRANSPORT_REACTIONS
internally, which includes SBO identifiers. In the reaction annotations, use the keys in annotation_keys
to look for entries. Returns false if no hits or if no keys are found.
COBREXA.looks_like_biomass_reaction
— Methodlooks_like_biomass_reaction(rxn_id::String; exclude_exchanges, exchange_prefixes, biomass_strings) -> Bool
A predicate that matches reaction identifiers that look like biomass reactions. Biomass reactions are identified by looking for occurences of biomass_strings
in the reaction id. If exclude_exchanges
is set, the strings that look like exchanges (from looks_like_exchange_reaction
) will not match.
Note
While looks_like_biomass_reaction
is useful for heuristically finding a reaction, it is preferable to use standardized terms for finding reactions (e.g. SBO terms). See is_biomass_reaction
for a more systematic alternative.
Example
filter(looks_like_biomass_reaction, reactions(model)) # returns strings
findall(looks_like_biomass_reaction, reactions(model)) # returns indices
COBREXA.looks_like_exchange_reaction
— Methodlooks_like_exchange_reaction(rxn_id::String; exclude_biomass, biomass_strings, exchange_prefixes) -> Bool
A predicate that matches reaction identifiers that look like exchange or biomass reactions, given the usual naming schemes in common model repositories. Exchange reactions are identified based on matching prefixes in the set exchange_prefixes
and biomass reactions are identified by looking for occurences of biomass_strings
in the reaction id.
Also see find_exchange_reactions
.
Note
While looks_like_exchange_reaction
is useful for heuristically finding a reaction, it is preferable to use standardized terms for finding reactions (e.g. SBO terms). See is_exchange_reaction
for a more systematic alternative.
Example
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
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
COBREXA.looks_like_extracellular_metabolite
— Methodlooks_like_extracellular_metabolite(met_id::String; extracellular_suffixes) -> Bool
A predicate that matches metabolite identifiers that look like they are extracellular metabolites. Extracellular metabolites are identified by extracellular_suffixes
at the end of the metabolite id.
Example
filter(looks_like_extracellular_metabolite, metabolites(model)) # returns strings
findall(looks_like_extracellular_metabolite, metabolites(model)) # returns indices
COBREXA._smoment_column_reactions
— Method_smoment_column_reactions(model::SMomentModel) -> SparseArrays.SparseMatrixCSC{Int64, Int64}
Retrieve a utility mapping between reactions and split reactions; rows correspond to "original" reactions, columns correspond to "split" reactions.
COBREXA._smoment_reaction_name
— Method_smoment_reaction_name(original_name::String, direction::Int64) -> String
Internal helper for systematically naming reactions in SMomentModel
.
COBREXA.smoment_isozyme_speed
— Methodsmoment_isozyme_speed(gene_product_molar_mass::Function) -> COBREXA.var"#775#776"
A piping- and argmax-friendly overload of smoment_isozyme_speed
.
Example
gene_mass_function = gid -> 1.234
best_isozyme_for_smoment = argmax(
smoment_isozyme_speed(gene_mass_function),
my_isozyme_vector,
)
COBREXA.smoment_isozyme_speed
— Methodsmoment_isozyme_speed(isozyme::Isozyme, gene_product_molar_mass) -> Any
Compute a "score" for picking the most viable isozyme for make_smoment_model
, based on maximum kcat divided by relative mass of the isozyme. This is used because sMOMENT algorithm can not handle multiple isozymes for one reaction.
Macro-generated functions and internal helpers
COBREXA.@_change_bounds_fn
— Macro@_change_bounds_fn ModelType IdxType [plural] [inplace] begin ... end
A helper for creating simple bounds-changing function similar to change_bounds
.
COBREXA.@_is_reaction_fn
— Macro@isreactionfn(annoid, identifier)
A helper for creating functions like is_exchange_reaction
.
COBREXA._inherit_model_methods_impl
— Method_inherit_model_methods_impl(source, mtype::Symbol, arglist, access, fwdlist, fns...) -> Expr
A helper backend for @_inherit_model_methods
and @_inherit_model_methods_fn
.
COBREXA.@_inherit_model_methods
— MacroGenerates trivial accessor functions listed in fns
for a model that is wrapped in type mtype
as field member
.
COBREXA.@_inherit_model_methods_fn
— MacroA more generic version of @_inherit_model_methods
that accesses the "inner" model using an accessor function name.
COBREXA.@_remove_fn
— Macro@ _remove_fn objname ModelType IndexType [plural] [inplace] begin ... end
A helper for creating functions that follow the remove_objname
template, such as remove_metabolites
and remove_reaction
.
COBREXA.@_serialized_change_unwrap
— Macro@_serialized_change_unwrap function
Creates a simple wrapper structure that calls the function
transparently on the internal precached model. The internal type is returned (otherwise this would break the consistency of serialization).
Logging and debugging helpers
COBREXA.log_io
— Functionlog_io(enable::Bool=true)
Enable (default) or disable (by passing false
) output of messages and warnings from model input/output.
COBREXA.log_models
— Functionlog_models(enable::Bool=true)
Enable (default) or disable (by passing false
) output of model-related messages.
COBREXA.log_perf
— Functionlog_perf(enable::Bool=true)
Enable (default) or disable (by passing false
) output of performance-related tracing information.
COBREXA.@_make_logging_tag
— MacroThis creates a group of functions that allow masking out topic-related logging actions. A call that goes as follows:
@_make_logging_tag XYZ
creates the following tools:
- global variable
_XYZ_log_enabled
defaulted to false - function
log_XYZ
that can be called to turn the logging on/off - a masking macro
@_XYZ_log
that can be prepended to commands that should only happen if the logging of tag XYZ is enabled.
The masking macro is then used as follows:
@_XYZ_log @info "This is the extra verbose information you wanted!" a b c
The user can direct logging with these:
log_XYZ()
log_XYZ(false)
doc
should be a name of the stuff that is being printed if the corresponding log_XYZ() is enabled – it is used to create a friendly documentation for the logging switch. In this case it could say "X, Y and Z-related messages"
.