Utilities
Helper functions
COBREXA.ambiguously_identified_items
— Methodambiguously_identified_items(
index::Dict{String,Dict{String,[String]}},
)::Vector{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 = _annotations,
)::Dict{String,Dict{String,[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(rxn::Reaction, rxns::Dict{String, Reaction}; only_metabolites=true)
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})
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::StandardModel, rxn)
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)
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(rxn_dict::Dict{String, Float64}; format_id = x -> x)
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)
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::MM, filename::String)::Serialized{MM} where {MM<:MetabolicModel}
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
— MethodBase.copy(g::Gene)
Shallow copy of a Gene
Base.copy
— MethodBase.copy(m::Metabolite)
Shallow copy of a Metabolite
Base.copy
— MethodBase.copy(r::Reaction)
Shallow copy of a Reaction
Base.copy
— MethodBase.copy(m::StandardModel)
Shallow copy of a StandardModel
COBREXA.gamma_bounds
— Methodgamma_bounds(gamma)
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)
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)::MetaboliteFormula
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::MetaboliteFormula)::String
Format MetaboliteFormula
to String
.
COBREXA.atom_fluxes
— Methodatom_fluxes(model::MetabolicModel, reaction_fluxes::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})
Return two dictionaries of metabolite id
s mapped to reactions that consume or produce them, given the flux distribution supplied in flux_dict
.
COBREXA._parse_grr
— Method_parse_grr(gpa::SBML.GeneProductAssociation)::GeneAssociation
Parse SBML.GeneProductAssociation
structure to the simpler GeneAssociation. The input must be (implicitly) in a positive DNF.
COBREXA._parse_grr
— Method_parse_grr(s::String)::GeneAssociation
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)::Maybe{SBML.GeneProductAssociation}
Internal helper for parsing the string GRRs into SBML data structures. More general than _parse_grr
.
COBREXA._unparse_grr
— Method_unparse_grr(
::Type{SBML.GeneProductAssociation},
x::GeneAssociation,
)::SBML.GeneAssociation
Convert a GeneAssociation to the corresponding SBML.jl
structure.
COBREXA._unparse_grr
— Methodunparse_grr(grr::Vector{Vector{Gene}}
Converts a nested string gene reaction array back into a gene reaction rule string.
Example
julia> _unparse_grr(String, [["YIL010W", "YLR043C"], ["YIL010W", "YGR209C"]])
"(YIL010W and YLR043C) or (YIL010W and YGR209C)"
COBREXA._guesskey
— Method_guesskey(ks, possibilities)
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.find_biomass_reaction_ids
— Methodfind_biomass_reaction_ids(m::MetabolicModel; kwargs...)
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...)
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...)
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...)
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...)
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...)
Shortcut for finding extracellular metabolite indexes in a model; arguments are forwarded to looks_like_extracellular_metabolite
.
COBREXA.looks_like_biomass_reaction
— Methodlooks_like_biomass_reaction(rxn_id::String;
exclude_exchanges = false,
exchange_prefixes = _constants.exchange_prefixes,
biomass_strings = _constants.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.
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 = false,
biomass_strings = _constants.biomass_strings,
exchange_prefixes = _constants.exchange_prefixes,
)
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
.
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(rxn_id::String;
extracellular_suffixes = _constants.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
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.@_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. Internal type is returned (because 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
— Macromacro _make_logging_group(sym::Symbol, doc::String)
This 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"
.