index.html 63.4 KB
 Documenter.jl committed Nov 02, 2021 1   Documenter.jl committed Nov 05, 2021 2 Utilities · COBREXA.jl

Utilities

Helper functions

COBREXA.ambiguously_identified_itemsMethod
ambiguously_identified_items( 
Documenter.jl committed Nov 02, 2021  3                                                                       index::Dict{String,Dict{String,[String]}}, 
Documenter.jl committed May 16, 2022  4                                                                   )::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.

source
COBREXA.annotation_indexMethod
annotation_index( 
Documenter.jl committed Nov 02, 2021  5      6                                                                xs::AbstractDict{String};     annotations = _annotations, 
Documenter.jl committed May 16, 2022  7                                                                   )::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.

source
COBREXA.check_duplicate_reactionMethod
check_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 ids are checked. Otherwise, compares metabolite ids 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.

source
COBREXA.is_boundaryMethod
is_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.

source
COBREXA.reaction_atom_balanceMethod
reaction_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.

source
COBREXA.stoichiometry_stringMethod
stoichiometry_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) 
Documenter.jl committed Nov 02, 2021  8      9      10      11                                            julia> stoichiometry_string(req) "coa_c + pyr_c = for_c + accoa_c"  julia> stoichiometry_string(req; format_id = x -> x[1:end-2]) 
Documenter.jl committed May 16, 2022  12                                                                  "coa + pyr = for + accoa"
source
COBREXA.serialize_modelMethod
serialize_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.

source
COBREXA.gamma_boundsMethod
gamma_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))
source
COBREXA.gene_product_dictMethod
gene_product_dict(model::GeckoModel, opt_model)

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.

source
COBREXA.atom_fluxesMethod
atom_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 
Documenter.jl committed Nov 02, 2021  13                                                                  delete!(fluxes, "BIOMASS_Ecoli_core_w_GAM") 
Documenter.jl committed May 16, 2022  14                                                                  atom_fluxes(model, fluxes)["C"]
source
COBREXA.metabolite_fluxesMethod
metabolite_fluxes(model::MetabolicModel, flux_dict::Dict{String, Float64})

Return two dictionaries of metabolite ids mapped to reactions that consume or produce them, given the flux distribution supplied in flux_dict.

source
COBREXA._gecko_reaction_column_reactionsMethod
_gecko_reaction_column_reactions(model::GeckoModel)

Retrieve a utility mapping between reactions and split reactions; rows correspond to "original" reactions, columns correspond to "split" reactions.

source
COBREXA._parse_grrMethod
_parse_grr(gpa::SBML.GeneProductAssociation)::GeneAssociation

Parse SBML.GeneProductAssociation structure to the simpler GeneAssociation. The input must be (implicitly) in a positive DNF.

source
COBREXA._parse_grrMethod
_parse_grr(s::String)::GeneAssociation

Parse a DNF gene association rule in format (YIL010W and YLR043C) or (YIL010W and YGR209C) to GeneAssociation. Also acceptsOR,|,||,AND,&, and&&.

Example

julia> _parse_grr("(YIL010W and YLR043C) or (YIL010W and YGR209C)") 
Documenter.jl committed Nov 02, 2021  15      16                                                          2-element Array{Array{String,1},1}:  ["YIL010W", "YLR043C"] 
Documenter.jl committed May 16, 2022  17                                                                   ["YIL010W", "YGR209C"]
source
COBREXA._parse_grr_to_sbmlMethod
_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.

source
COBREXA._unparse_grrMethod
_unparse_grr( 
Documenter.jl committed Nov 02, 2021  18      19                                                              ::Type{SBML.GeneProductAssociation},     x::GeneAssociation, 
Documenter.jl committed May 16, 2022  20      21                                                          )::SBML.GeneAssociation

Convert a GeneAssociation to the corresponding SBML.jl structure.

source
COBREXA._unparse_grrMethod
unparse_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)"
source
COBREXA._guesskeyMethod
_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.

source
COBREXA.getsMethod
gets(collection, fail, keys)

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.

source
COBREXA.looks_like_biomass_reactionMethod
looks_like_biomass_reaction(rxn_id::String; 
Documenter.jl committed Nov 02, 2021  22      23      24      25                                              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 
Documenter.jl committed May 16, 2022  26                                                                  findall(looks_like_biomass_reaction, reactions(model)) # returns indices
source
COBREXA.looks_like_exchange_reactionMethod
looks_like_exchange_reaction(rxn_id::String; 
Documenter.jl committed Nov 02, 2021  27      28      29      30      31      32      33      34      35      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 
Documenter.jl committed May 16, 2022  36                                                                  filter(x -> looks_like_exchange_reaction(x; exclude_biomass=true), reactions(model)) # returns Strings
source
COBREXA.looks_like_extracellular_metaboliteMethod
looks_like_extracellular_metabolite(rxn_id::String; 
Documenter.jl committed Nov 03, 2021  37                                                                      extracellular_suffixes = _constants.extracellular_suffixes, 
Documenter.jl committed Mar 23, 2022  38                                                                  )::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 
Documenter.jl committed May 16, 2022  39                                                                  findall(looks_like_extracellular_metabolite, metabolites(model)) # returns indices
source
COBREXA._smoment_column_reactionsMethod
_smoment_column_reactions(model::SMomentModel)

Retrieve a utility mapping between reactions and split reactions; rows correspond to "original" reactions, columns correspond to "split" reactions.

source
COBREXA.smoment_isozyme_speedMethod
smoment_isozyme_speed(gene_product_molar_mass::Function)

A piping- and argmax-friendly overload of smoment_isozyme_speed.

Example

gene_mass_function = gid -> 1.234 
Documenter.jl committed Apr 20, 2022  40      41      42      43                                           best_isozyme_for_smoment = argmax(     smoment_isozyme_speed(gene_mass_function),     my_isozyme_vector, 
Documenter.jl committed May 16, 2022  44      45                                                          )
source
COBREXA.smoment_isozyme_speedMethod
smoment_isozyme_speed(isozyme::Isozyme, gene_product_molar_mass)

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.

source

Macro-generated functions and internal helpers

COBREXA.@_serialized_change_unwrapMacro
@_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).

source

Logging and debugging helpers

COBREXA.log_ioFunction
log_io(enable::Bool=true)

Enable (default) or disable (by passing false) output of messages and warnings from model input/output.

source
COBREXA.log_modelsFunction
log_models(enable::Bool=true)

Enable (default) or disable (by passing false) output of model-related messages.

source
COBREXA.log_perfFunction
log_perf(enable::Bool=true)

Enable (default) or disable (by passing false) output of performance-related tracing information.

source
COBREXA.@_make_logging_tagMacro
macro _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".

source
`