COBREXA.COBREXAModule
\\\\\  // //     | COBREXA.jl  v1.5.1
 \\ \\// //      |
  \\ \/ //       | COnstraint-Based Reconstruction
   \\  //        | and EXascale Analysis in Julia
   //  \\        |
  // /\ \\       | See documentation and examples at:
 // //\\ \\      | https://lcsb-biocore.github.io/COBREXA.jl
// //  \\\\\     |

To start up quickly, install your favorite optimizer, load a metabolic model in a format such as SBML or JSON, and run a metabolic analysis such as the flux balance analysis:

import Pkg; Pkg.add("GLPK")
using COBREXA, GLPK
model = load_model("e_coli_core.xml")
x = flux_balance_analysis_dict(model, GLPK.Optimizer)
flux_summary(x)

A complete overview of the functionality can be found in the documentation.

COBREXA.MaybeType
Maybe{T} = Union{Nothing, T}

A nice name for "nullable" type.

COBREXA._constantsConstant

A named tuple that contains the magic values that are used globally for whatever purposes.

COBREXA.AnnotationsType
Annotations = Dict{String,Vector{String}}

Dictionary used to store (possible multiple) standardized annotations of something, such as a Metabolite and a Reaction.

Example

Annotations("PubChem" => ["CID12345", "CID54321"])
COBREXA.CoreCouplingType
mutable struct CoreCoupling{M} <: ModelWrapper

A matrix-based wrap that adds reaction coupling matrix to the inner model. A flux x feasible in this model must satisfy:

    cₗ ≤ C x ≤ cᵤ

Fields

  • lm::Any

  • C::SparseArrays.SparseMatrixCSC{Float64, Int64}

  • cl::Vector{Float64}

  • cu::Vector{Float64}

COBREXA.CoreModelType
mutable struct CoreModel <: MetabolicModel

A "bare bones" core linear optimization problem of the form, with reaction and metabolite names.

min c^T x
s.t. S x = b
      xₗ ≤ x ≤ xᵤ

Fields

  • S::SparseArrays.SparseMatrixCSC{Float64, Int64}

  • b::SparseArrays.SparseVector{Float64, Int64}

  • c::SparseArrays.SparseVector{Float64, Int64}

  • xl::Vector{Float64}

  • xu::Vector{Float64}

  • rxns::Vector{String}

  • mets::Vector{String}

  • grrs::Vector{Union{Nothing, Vector{Vector{String}}}}

COBREXA.CoreModelCoupledType
const CoreModelCoupled = CoreCoupling{CoreModel}

A matrix-based linear model with additional coupling constraints in the form:

    cₗ ≤ C x ≤ cᵤ

Internally, the model is implemented using CoreCoupling that contains a single CoreModel.

COBREXA.ExpressionLimitedModelType
struct ExpressionLimitedModel <: ModelWrapper

ExpressionLimitedModel follows the methodology of the E-Flux algorithm to constraint the flux through the reactions in order to simulate the limited expression of genes (and thus the limited availability of the gene products).

Use make_expression_limited_model or with_expression_limits to construct the models.

E-Flux algorithm is closer described by: Colijn, Caroline, Aaron Brandes, Jeremy Zucker, Desmond S. Lun, Brian Weiner, Maha R. Farhat, Tan-Yun Cheng, D. Branch Moody, Megan Murray, and James E. Galagan. "Interpreting expression data with metabolic flux models: predicting Mycobacterium tuberculosis mycolic acid production." PLoS computational biology 5, no. 8 (2009): e1000489.

Fields

  • relative_expression::Dict{String, Float64}: Relative gene expression w.r.t. to some chosen reference; the normalization and scale of the values should match the expectations of the bounding_function.
COBREXA.FluxSummaryType
struct FluxSummary

A struct used to store summary information about the solution of a constraint based analysis result.

Fields

  • biomass_fluxes::OrderedCollections.OrderedDict{String, Float64}

  • import_fluxes::OrderedCollections.OrderedDict{String, Float64}

  • export_fluxes::OrderedCollections.OrderedDict{String, Float64}

  • unbounded_fluxes::OrderedCollections.OrderedDict{String, Float64}

COBREXA.FluxSummaryMethod
FluxSummary() -> FluxSummary

A default empty constructor for FluxSummary.

COBREXA.FluxVariabilitySummaryType
struct FluxVariabilitySummary

Stores summary information about the result of a flux variability analysis.

Fields

  • biomass_fluxes::Dict{String, Vector{Union{Nothing, Float64}}}

  • exchange_fluxes::Dict{String, Vector{Union{Nothing, Float64}}}

COBREXA.GeckoModelType
struct GeckoModel <: ModelWrapper

A model with complex enzyme concentration and capacity bounds, as described in Sánchez, Benjamín J., et al. "Improving the phenotype predictions of a yeast genome-scale metabolic model by incorporating enzymatic constraints." Molecular systems biology 13.8 (2017): 935.

Use make_gecko_model or with_gecko to construct this kind of model.

The model wraps another "internal" model, and adds following modifications:

  • enzymatic reactions with known enzyme information are split into multiple forward and reverse variants for each isozyme,
  • reaction coupling is added to ensure the groups of isozyme reactions obey the global reaction flux bounds from the original model,
  • gene concentrations specified by each reaction and its gene product stoichiometry, can constrained by the user to reflect measurements, such as from mass spectrometry,
  • additional coupling is added to simulate total masses of different proteins grouped by type (e.g., membrane-bound and free-floating proteins), which can be again constrained by the user (this is slightly generalized from original GECKO algorithm, which only considers a single group of indiscernible proteins).

The structure contains fields columns that describe the contents of the stoichiometry matrix columns, coupling_row_reaction, coupling_row_gene_product and coupling_row_mass_group that describe correspondence of the coupling rows to original model and determine the coupling bounds (note: the coupling for gene product is actually added to stoichiometry, not in coupling), and inner, which is the original wrapped model. The objective of the model includes also the extra columns for individual genes, as held by coupling_row_gene_product.

Implementation exposes the split reactions (available as reactions(model)), but retains the original "simple" reactions accessible by fluxes. The related constraints are implemented using coupling and coupling_bounds.

Fields

  • objective::SparseArrays.SparseVector{Float64, Int64}

  • columns::Vector{COBREXA._gecko_reaction_column}

  • coupling_row_reaction::Vector{Int64}

  • coupling_row_gene_product::Vector{Tuple{Int64, Tuple{Float64, Float64}}}

  • coupling_row_mass_group::Vector{COBREXA._gecko_capacity}

  • inner::MetabolicModel

COBREXA.GeneType
Gene() -> Gene
Gene(id; name, notes, annotations) -> Gene

A convenient constructor for a Gene.

COBREXA.GeneType
mutable struct Gene

Fields

  • id::String

  • name::Union{Nothing, String}

  • notes::Dict{String, Vector{String}}

  • annotations::Dict{String, Vector{String}}

COBREXA.GeneAssociationType
GeneAssociation = Vector{Vector{String}}

An association to genes, represented as a logical formula in a positive disjunctive normal form (DNF). (The 2nd-level vectors of strings are connected by "and" to form conjunctions, and the 1st-level vectors of these conjunctions are connected by "or" to form the DNF.)

COBREXA.HDF5ModelType
mutable struct HDF5Model <: MetabolicModel

A model that is stored in HDF5 format. The model data is never really pulled into memory, but instead mmap'ed as directly as possible into the Julia structures. This makes reading the HDF5Models extremely fast, at the same time the (uncached) HDF5Models can be sent around efficiently among distributed nodes just like Serialized models, provided the nodes share a common storage.

All HDF5Models must have the backing disk storage. To create one, use save_h5_model or save_model with .h5 file extension. To create a temporary model that behaves like a model "in memory", save it to a temporary file. For related reasons, you can not use convert models to HDF5Model format, because the conversion would impliy having the model saved somewhere.

Fields

  • h5::Union{Nothing, HDF5.File}

  • filename::String

COBREXA.IsozymeType
mutable struct Isozyme

Information about isozyme composition and activity.

Fields

  • gene_product_count::Dict{String, Int64}

  • kcat_forward::Float64

  • kcat_reverse::Float64

COBREXA.JSONModelType
struct JSONModel <: MetabolicModel

A struct used to store the contents of a JSON model, i.e. a model read from a file ending with .json. These model files typically store all the model data in arrays of JSON objects (represented in Julia as vectors of dictionaries).

Usually, not all of the fields of the input JSON can be easily represented when converting to other models, care should be taken to avoid losing information.

Direct work with the json structure is not very efficient; the model structure therefore caches some of the internal structure in the extra fields. The single-parameter JSONModel constructor creates these caches correctly from the json. The model structure is designed as read-only, and changes in json invalidate the cache.

Example

model = load_json_model("some_model.json")
model.json # see the actual underlying JSON
reactions(model) # see the list of reactions

Fields

  • json::Dict{String, Any}

  • rxn_index::Dict{String, Int64}

  • rxns::Vector{Any}

  • met_index::Dict{String, Int64}

  • mets::Vector{Any}

  • gene_index::Dict{String, Int64}

  • genes::Vector{Any}

COBREXA.MATModelType
struct MATModel <: MetabolicModel

Wrapper around the models loaded in dictionaries from the MATLAB representation.

Fields

  • mat::Dict{String, Any}
COBREXA.MetabolicModelType
abstract type MetabolicModel end

A helper supertype of everything usable as a linear-like model for COBREXA functions.

If you want your model type to work with COBREXA, add the MetabolicModel as its supertype, and implement the accessor functions. Accessors reactions, metabolites, stoichiometry, bounds and objective must be implemented; others are not mandatory and default to safe "empty" values.

COBREXA.MetaboliteType
Metabolite() -> Metabolite
Metabolite(
    id;
    name,
    formula,
    charge,
    compartment,
    notes,
    annotations
) -> Metabolite

A constructor for Metabolites.

COBREXA.MetaboliteType
mutable struct Metabolite

Fields

  • id::String

  • name::Union{Nothing, String}

  • formula::Union{Nothing, String}

  • charge::Union{Nothing, Int64}

  • compartment::Union{Nothing, String}

  • notes::Dict{String, Vector{String}}

  • annotations::Dict{String, Vector{String}}

COBREXA.MetaboliteFormulaType
MetaboliteFormula = Dict{String,Int}

Dictionary of atoms and their abundances in a molecule.

COBREXA.NotesType
Notes = Dict{String,Vector{String}}

Free-form notes about something (e.g. a Gene), categorized by "topic".

COBREXA.ReactionType
Reaction(id::String, metabolites) -> Reaction
Reaction(
    id::String,
    metabolites,
    dir;
    default_bound
) -> Reaction

Convenience constructor for Reaction. The reaction equation is specified using metabolites, which is a dictionary mapping metabolite ids to stoichiometric coefficients. The direcion of the reaction is set through dir which can take :bidirectional, :forward, and :reverse as values. Finally, the default_bound is the value taken to mean infinity in the context of constraint based models, often this is set to a very high flux value like 1000.

COBREXA.ReactionType
Reaction() -> Reaction
Reaction(
    id;
    name,
    metabolites,
    lb,
    ub,
    grr,
    subsystem,
    notes,
    annotations,
    objective_coefficient
) -> Reaction

A constructor for Reaction that only takes a reaction id and assigns default/uninformative values to all the fields that are not explicitely assigned.

COBREXA.ReactionType
mutable struct Reaction

A structure for representing a single reaction in a StandardModel.

Fields

  • id::String

  • name::Union{Nothing, String}

  • metabolites::Dict{String, Float64}

  • lb::Float64

  • ub::Float64

  • grr::Union{Nothing, Vector{Vector{String}}}

  • subsystem::Union{Nothing, String}

  • notes::Dict{String, Vector{String}}

  • annotations::Dict{String, Vector{String}}

  • objective_coefficient::Float64

COBREXA.ReactionStatusType
mutable struct ReactionStatus

Used for concise reporting of modeling results.

Fields

  • already_present::Bool

  • index::Int64

  • info::String

COBREXA.SBMLModelType
struct SBMLModel <: MetabolicModel

Construct the SBML model and add the necessary cached indexes, possibly choosing an active objective.

COBREXA.SBMLModelType
struct SBMLModel <: MetabolicModel

Thin wrapper around the model from SBML.jl library. Allows easy conversion from SBML to any other model format.

Fields

  • sbml::SBML.Model

  • reaction_ids::Vector{String}

  • reaction_idx::Dict{String, Int64}

  • metabolite_ids::Vector{String}

  • metabolite_idx::Dict{String, Int64}

  • gene_ids::Vector{String}

  • active_objective::String

COBREXA.SMomentModelType
struct SMomentModel <: ModelWrapper

An enzyme-capacity-constrained model using sMOMENT algorithm, as described by Bekiaris, Pavlos Stephanos, and Steffen Klamt, "Automatic construction of metabolic models with enzyme constraints" BMC bioinformatics, 2020.

Use make_smoment_model or with_smoment to construct the models.

The model is constructed as follows:

  • stoichiometry of the original model is retained as much as possible, but enzymatic reations are split into forward and reverse parts (marked by a suffix like ...#forward and ...#reverse),
  • coupling is added to simulate a virtual metabolite "enzyme capacity", which is consumed by all enzymatic reactions at a rate given by enzyme mass divided by the corresponding kcat,
  • the total consumption of the enzyme capacity is constrained to a fixed maximum.

The SMomentModel structure contains a worked-out representation of the optimization problem atop a wrapped MetabolicModel, in particular the separation of certain reactions into unidirectional forward and reverse parts, an "enzyme capacity" required for each reaction, and the value of the maximum capacity constraint. Original coupling in the inner model is retained.

In the structure, the field columns describes the correspondence of stoichiometry columns to the stoichiometry and data of the internal wrapped model, and total_enzyme_capacity is the total bound on the enzyme capacity consumption as specified in sMOMENT algorithm.

This implementation allows easy access to fluxes from the split reactions (available in reactions(model)), while the original "simple" reactions from the wrapped model are retained as fluxes. All additional constraints are implemented using coupling and coupling_bounds.

Fields

  • columns::Vector{COBREXA._smoment_column}

  • total_enzyme_capacity::Float64

  • inner::MetabolicModel

COBREXA.SerializedType
mutable struct Serialized{M} <: ModelWrapper

A meta-model that represents a model that is serialized on the disk. The internal model will be loaded on-demand by using any accessor, or by calling precache! directly.

Fields

  • m::Union{Nothing, M} where M

  • filename::String

COBREXA.StandardModelType
mutable struct StandardModel <: MetabolicModel

StandardModel is used to store a constraint based metabolic model with meta-information. Meta-information is defined as annotation details, which include gene-reaction-rules, formulas, etc.

This model type seeks to keep as much meta-information as possible, as opposed to CoreModel and CoreModelCoupled, which keep the bare neccessities only. When merging models and keeping meta-information is important, use this as the model type. If meta-information is not important, use the more efficient core model types. See CoreModel and CoreModelCoupled for comparison.

In this model, reactions, metabolites, and genes are stored in ordered dictionaries indexed by each struct's id field. For example, model.reactions["rxn1_id"] returns a Reaction where the field id equals "rxn1_id". This makes adding and removing reactions efficient.

Note that the stoichiometric matrix (or any other core data, e.g. flux bounds) is not stored directly as in CoreModel. When this model type is used in analysis functions, these core data structures are built from scratch each time an analysis function is called. This can cause performance issues if you run many small analysis functions sequentially. Consider using the core model types if performance is critical.

See also: Reaction, Metabolite, Gene

Example

model = load_model(StandardModel, "my_model.json")
keys(model.reactions)

Fields

  • id::String

  • reactions::OrderedCollections.OrderedDict{String, Reaction}

  • metabolites::OrderedCollections.OrderedDict{String, Metabolite}

  • genes::OrderedCollections.OrderedDict{String, Gene}

COBREXA._StoichiometryType
struct _Stoichiometry

A small helper type for constructing reactions inline

Fields

  • s::Dict{String, Float64}
COBREXA._gecko_capacityType
struct _gecko_capacity

A helper struct that contains the gene product capacity terms organized by the grouping type, e.g. metabolic or membrane groups etc.

Fields

  • group_id::String

  • gene_product_idxs::Vector{Int64}

  • gene_product_molar_masses::Vector{Float64}

  • group_upper_bound::Float64

COBREXA._gecko_reaction_columnType
struct _gecko_reaction_column

A helper type for describing the contents of GeckoModels.

Fields

  • reaction_idx::Int64

  • isozyme_idx::Int64

  • direction::Int64

  • reaction_coupling_row::Int64

  • lb::Float64

  • ub::Float64

  • gene_product_coupling::Vector{Tuple{Int64, Float64}}

COBREXA._smoment_columnType
struct _smoment_column

A helper type that describes the contents of SMomentModels.

Fields

  • reaction_idx::Int64

  • direction::Int64

  • lb::Float64

  • ub::Float64

  • capacity_required::Float64

Base.:+Method
+(
    a::Union{Metabolite, COBREXA._Stoichiometry},
    b::Union{Metabolite, COBREXA._Stoichiometry}
) -> COBREXA._Stoichiometry

Shorthand for metabolite1 + metabolite2. Add 2 groups of Metabolites together to form reactions inline. Use with +, *, and similar operators.

Base.closeMethod
close(model::HDF5Model)

Close (and un-cache) the HDF5Model data. This allows the associated file to be opened for writing again.

Base.convertMethod
convert(
    _::Type{MATModel},
    m::MetabolicModel
) -> MetabolicModel

Convert any metabolic model to MATModel.

Base.convertMethod
convert(
    _::Type{SBMLModel},
    mm::MetabolicModel
) -> MetabolicModel

Convert any metabolic model to SBMLModel.

Base.convertMethod
convert(
    _::Type{StandardModel},
    model::MetabolicModel
) -> MetabolicModel

Convert any MetabolicModel into a StandardModel. Note, some data loss may occur since only the generic interface is used during the conversion process.

Base.convertMethod
convert(
    ::Type{CoreCoupling{M}},
    mm::MetabolicModel;
    clone_coupling
) -> MetabolicModel

Make a CoreCoupling out of any compatible model type.

Base.convertMethod
convert(
    _::Type{CoreModel},
    m::MetabolicModel
) -> MetabolicModel

Make a CoreModel out of any compatible model type.

Base.showMethod
show(
    io::IO,
    _::MIME{Symbol("text/plain")},
    m::MetabolicModel
)

Pretty printing of everything metabolic-modelish.

Base.showMethod
show(
    io::IO,
    _::MIME{Symbol("text/plain")},
    m::Serialized{M}
)

Show the Serialized model without unnecessarily loading it.

COBREXA.:←Method
←(
    substrates::Union{Nothing, Metabolite, COBREXA._Stoichiometry},
    products::Union{Nothing, Metabolite, COBREXA._Stoichiometry}
) -> Reaction

Shorthand for substrates ← products. Make a reverse-only Reaction from substrates and products.

COBREXA.:→Method
→(
    substrates::Union{Nothing, Metabolite, COBREXA._Stoichiometry},
    products::Union{Nothing, Metabolite, COBREXA._Stoichiometry}
) -> Reaction

Shorthand for substrates → products. Make a forward-only Reaction from substrates and products.

COBREXA.:↔Method
↔(
    substrates::Union{Nothing, Metabolite, COBREXA._Stoichiometry},
    products::Union{Nothing, Metabolite, COBREXA._Stoichiometry}
) -> Reaction

Shorthand for substrates ↔ products. Make a bidirectional (reversible) Reaction from substrates and products.

COBREXA._affine_hit_and_run_chainMethod
_affine_hit_and_run_chain(
    warmup,
    lbs,
    ubs,
    C,
    cl,
    cu,
    iters,
    seed
) -> Matrix{Float64}

Internal helper function for computing a single affine hit-and-run chain.

COBREXA._defaultMethod
_default(d, x::Union{Nothing, T} where T) -> Any

Fold the Maybe{T} down to T by defaulting.

COBREXA._do_knockoutMethod
_do_knockout(
    model::MetabolicModel,
    opt_model,
    gene_ids::Vector{String}
)

Internal helper for knockouts on generic MetabolicModels. This can be overloaded so that the knockouts may work differently (more efficiently) with other models.

COBREXA._gecko_gene_product_couplingMethod
_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_couplingMethod
_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_reactionsMethod
_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_couplingMethod
_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_nameMethod
_gecko_reaction_name(
    original_name::String,
    direction::Int64,
    isozyme_idx::Int64
) -> String

Internal helper for systematically naming reactions in GeckoModel.

COBREXA._guesskeyMethod
_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._max_variability_fluxMethod
_max_variability_flux(opt_model, flux, sense, ret) -> Any

Internal helper for maximizing reactions in optimization model.

COBREXA._maximize_warmup_reactionMethod
_maximize_warmup_reaction(opt_model, rid, ret) -> Any

A helper function for finding warmup points from reaction variability.

COBREXA._maybemapMethod
_maybemap(f, x) -> Any

Apply a function to x only if it is not nothing.

COBREXA._mmdf_add_df_boundMethod
_mmdf_add_df_bound(lb, ub) -> COBREXA.var"#545#546"

Helper function to add a new constraint on the driving force.

COBREXA._mmdf_concen_objectiveMethod
_mmdf_concen_objective(midx, sense) -> COBREXA.var"#543#544"

Helper function to change the objective to optimizing some concentration.

COBREXA._mmdf_dgr_objectiveMethod
_mmdf_dgr_objective(ridx, sense) -> COBREXA.var"#541#542"

Helper function to change the objective to optimizing some dG.

COBREXA._parse_formulaMethod
_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._parse_grrMethod
_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_grrMethod
_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 acceptsOR,|,||,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_sbmlMethod
_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._pretty_print_keyvalsMethod
_pretty_print_keyvals(io, def::String, payload::Dict)

Specialization of _pretty_print_keyvals for dictionaries.

COBREXA._pretty_print_keyvalsMethod
_pretty_print_keyvals(io, def::String, payload::String)

Specialization of _pretty_print_keyvals for plain strings.

COBREXA._screen_argsMethod
_screen_args(
    argtuple,
    kwargtuple,
    modsname
) -> Union{Tuple{}, NamedTuple}

Internal helper to check the presence and shape of modification and argument arrays in screen and pals.

COBREXA._screen_implMethod
_screen_impl(
    model::MetabolicModel;
    variants,
    analysis,
    args,
    workers
)

The actual implementation of screen.

COBREXA._smoment_column_reactionsMethod
_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._sortuniqueMethod
_sortunique(x) -> Any

A helper for producing predictable unique sequences. Might be faster if compacting would be done directly in sort().

COBREXA._universal_stoichiometryMethod
_universal_stoichiometry(
    urxns::Vector{Reaction},
    mids::Vector{String}
) -> NamedTuple{(:stoichiometry, :lbs, :ubs, :new_mids), Tuple{SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}, Vector{Float64}, Vector{String}}}

A helper function that constructs the stoichiometric matrix of a set of universal_reactions. The order of the metabolites is determined with mids, so that this stoichiometric matrix can be combined with another one.

COBREXA._unparse_grrMethod
_unparse_grr(
    _::Type{SBML.GeneProductAssociation},
    x::Vector{Vector{String}}
) -> SBML.GPAOr

Convert a GeneAssociation to the corresponding SBML.jl structure.

COBREXA._unparse_grrMethod
_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.add_community_objective!Method
add_community_objective!(
    community::CoreModel,
    objective_mets_weights::Dict{String, Float64};
    objective_id
)

Add an objective column to the community model with optional id objective_id. Supply a dictionary mapping the string names of the objective metabolites to their weights in objective_mets_weights. Note, the weights are negated inside the function so that positive weights are seen as reagents/substrates, NOT products in the reaction equation.

Example

add_community_objective!(model, Dict("met1"=>1.0, "met2"=>2.0))

See also: update_community_objective!

COBREXA.add_community_objective!Method
add_community_objective!(
    community::StandardModel,
    objective_mets_weights::Dict{String, Float64};
    objective_id
)

Variant of [add_community_objective!] that takes a StandardModel community model as input.

COBREXA.add_coupling_constraints!Method
add_coupling_constraints!(
    m::CoreCoupling,
    c::AbstractVector{Float64},
    cl::AbstractFloat,
    cu::AbstractFloat
)

Overload for adding a single coupling constraint.

COBREXA.add_coupling_constraints!Method
add_coupling_constraints!(
    m::CoreCoupling,
    C::AbstractMatrix{Float64},
    cl::AbstractVector{Float64},
    cu::AbstractVector{Float64}
)

In-place add a single coupling constraint in form

    cₗ ≤ C x ≤ cᵤ
COBREXA.add_crowding_constraintsMethod
add_crowding_constraints(
    weights::Dict{Int64, Float64}
) -> COBREXA.var"#577#579"{Dict{Int64, Float64}}

Adds a molecular crowding constraint to the optimization problem: ∑ wᵢ × vᵢ ≤ 1 where wᵢ is a weight and vᵢ is a flux index in the model's reactions specified in weights as vᵢ => wᵢ pairs.

See Beg, Qasim K., et al. "Intracellular crowding defines the mode and sequence of substrate uptake by Escherichia coli and constrains its metabolic activity." Proceedings of the National Academy of Sciences 104.31 (2007) for more details.

COBREXA.add_gene!Method
add_gene!(model::StandardModel, gene::Gene)

Add gene to model based on gene id.

COBREXA.add_genes!Method
add_genes!(model::StandardModel, genes::Vector{Gene})

Add genes to model based on gene id.

COBREXA.add_loopless_constraintsMethod
add_loopless_constraints(
;
    max_flux_bound,
    strict_inequality_tolerance
) -> COBREXA.var"#598#603"{Float64, Int64}

Add quasi-thermodynamic constraints to the model to ensure that no thermodynamically infeasible internal cycles can occur. Adds the following constraints to the problem:

-max_flux_bound × (1 - yᵢ) ≤ xᵢ ≤ max_flux_bound × yᵢ
-max_flux_bound × yᵢ + strict_inequality_tolerance × (1 - yᵢ) ≤ Gᵢ
Gᵢ ≤ -strict_inequality_tolerance × yᵢ + max_flux_bound × (1 - yᵢ)
Nᵢₙₜ' × G = 0
yᵢ ∈ {0, 1}
Gᵢ ∈ ℝ
i ∈ internal reactions
Nᵢₙₜ is the nullspace of the internal stoichiometric matrix

Note, this modification introduces binary variables, so an optimization solver capable of handing mixed integer problems needs to be used. The arguments max_flux_bound and strict_inequality_tolerance implement the "big-M" method of indicator constraints.

For more details about the algorithm, see Schellenberger, Lewis, and, Palsson. "Elimination of thermodynamically infeasible loops in steady-state metabolic models.", Biophysical journal, 2011.

COBREXA.add_metabolite!Method
add_metabolite!(model::StandardModel, met::Metabolite)

Add met to model based on metabolite id.

COBREXA.add_metabolites!Method
add_metabolites!(
    model::StandardModel,
    mets::Vector{Metabolite}
)

Add mets to model based on metabolite id.

COBREXA.add_model_with_exchangesMethod
add_model_with_exchanges(
    community::CoreModel,
    model::MetabolicModel,
    exchange_rxn_mets::Dict{String, String};
    model_name,
    biomass_id
) -> CoreModel

Add model to community, which is a pre-existing community model with exchange reactions and metabolites in the dictionary exchange_rxn_mets. The model_name is appended to each reaction and metabolite, see join_with_exchanges. If biomass_id is specified then a biomass metabolite for model is also added to the resulting model. The column corresponding to the biomass_id reaction then produces this new biomass metabolite with unit coefficient. The exchange reactions and metabolites in exchange_rxn_mets must already exist in community. Always returns a new community model because it is more efficient than resizing all the matrices.

No in-place variant for CoreModels exists yet.

Example

community = add_model_with_exchanges(community,
    model,
    exchange_rxn_mets;
    model_name="species_2",
    biomass_id="BIOMASS_Ecoli_core_w_GAM")
COBREXA.add_model_with_exchangesMethod
add_model_with_exchanges(
    community::StandardModel,
    model::MetabolicModel,
    exchange_rxn_mets::Dict{String, String};
    model_name,
    biomass_id
) -> StandardModel

The StandardModel variant of add_model_with_exchanges. Makes a deepcopy of community and calls the inplace variant of this function on that copy.

COBREXA.add_moment_constraintsMethod
add_moment_constraints(
    kcats::Dict{String, Float64},
    protein_mass_fraction::Float64
) -> COBREXA.var"#608#614"{Dict{String, Float64}, Float64}

A modification that adds enzyme capacity constraints to the problem using a modified version of the MOMENT algorithm. Requires specific activities, ksas [mmol product/g enzyme/h], for each reaction. Proteins are identified by their associated gene IDs. Adds a variable vector y to the problem corresponding to the protein concentration [g enzyme/gDW cell] of each gene product in the order of genes(model). The total protein concentration [g protein/gDW cell] is constrained to be less than or equal to the protein_mass_fraction. Reaction flux constraints are changed to the MOMENT constraints (see below) for all reactions that have a gene reaction rule, otherwise the flux bounds are left unaltered.

See Adadi, Roi, et al. "Prediction of microbial growth rate versus biomass yield by a metabolic network with kinetic parameters." PLoS computational biology (2012) for more details of the original algorithm.

Here, a streamlined version of the algorithm is implemented to ensure that the correct units are used. Specifically, this implementation uses specific activities instead of kcats. Thus, for a reaction that can only proceed forward and is catalyzed by protein a, the flux x[i] is bounded by x[i] <= ksas[i] * y[a]. If isozymes a or b catalyse the reaction, then x[i] <= ksas[i] * (y[a] + y[b]). If a reaction is catalyzed by subunits a and b then x[i] <= ksas[i] * min(y[a], y[b]). These rules are applied recursively in the model like in the original algorithm. The enzyme capacity constraint is then implemented by sum(y) ≤ protein_mass_fraction. The major benefit of using ksas instead of kcats is that active site number and unit issues are prevented.

Example

flux_balance_analysis(
    ...,
    modifications = [ add_moment_constraints(my_kcats, 0.6) ],
)
COBREXA.add_reaction!Method
add_reaction!(model::CoreModel, rxn::Reaction)

Add rxn to model. The model must already contain the metabolites used by rxn in the model.

COBREXA.add_reaction!Method
add_reaction!(model::StandardModel, rxn::Reaction)

Add rxn to model based on reaction id.

COBREXA.add_reactions!Method
add_reactions!(model::CoreModel, rxns::Vector{Reaction})

Add rxns to model efficiently. The model must already contain the metabolites used by rxns in the model.

COBREXA.add_reactions!Method
add_reactions!(model::StandardModel, rxns::Vector{Reaction})

Add rxns to model based on reaction id.

COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModel,
    Sp::AbstractMatrix{Float64},
    b::AbstractVector{Float64},
    c::AbstractVector{Float64},
    xl::AbstractVector{Float64},
    xu::AbstractVector{Float64},
    rxns::AbstractVector{String},
    mets::AbstractVector{String};
    check_consistency
) -> Union{CoreModel, Tuple{CoreModel, Any, Any}}
COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModel,
    Sp::AbstractMatrix{Float64},
    b::AbstractVector{Float64},
    c::AbstractVector{Float64},
    xl::AbstractVector{Float64},
    xu::AbstractVector{Float64};
    check_consistency
) -> Union{CoreModel, Tuple{CoreModel, Any, Any}}
COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModel,
    s::AbstractVector{Float64},
    b::AbstractVector{Float64},
    c::AbstractFloat,
    xl::AbstractFloat,
    xu::AbstractFloat,
    rxn::String,
    mets::AbstractVector{String};
    check_consistency
) -> Union{CoreModel, Tuple{CoreModel, Vector{Int64}, Any}}
COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModel,
    s::AbstractVector{Float64},
    b::AbstractVector{Float64},
    c::AbstractFloat,
    xl::AbstractFloat,
    xu::AbstractFloat;
    check_consistency
) -> Union{CoreModel, Tuple{CoreModel, Vector{Int64}, Any}}

Add reaction(s) to a CoreModel model m.

COBREXA.add_reactionsMethod
add_reactions(
    m1::CoreModel,
    m2::CoreModel;
    check_consistency
) -> Union{CoreModel, Tuple{CoreModel, Vector{Int64}, Vector{Int64}}}

Add all reactions from m2 to m1.

COBREXA.add_reactionsMethod
add_reactions(
    m1::CoreModelCoupled,
    m2::CoreModel;
    check_consistency
) -> CoreModelCoupled

Add all reactions from m2 to m1.

COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModelCoupled,
    s::AbstractVector{Float64},
    b::AbstractVector{Float64},
    c::AbstractFloat,
    xl::AbstractFloat,
    xu::AbstractFloat,
    rxn::String,
    mets::AbstractVector{String};
    check_consistency
) -> CoreModelCoupled
COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModelCoupled,
    Sp::AbstractMatrix{Float64},
    b::AbstractVector{Float64},
    c::AbstractVector{Float64},
    xl::AbstractVector{Float64},
    xu::AbstractVector{Float64},
    rxns::AbstractVector{String},
    mets::AbstractVector{String};
    check_consistency
) -> CoreModelCoupled
COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModelCoupled,
    s::AbstractVector{Float64},
    b::AbstractVector{Float64},
    c::AbstractFloat,
    xl::AbstractFloat,
    xu::AbstractFloat;
    check_consistency
) -> CoreModelCoupled

Add reaction(s) to a CoreModelCoupled model m.

COBREXA.add_reactionsMethod
add_reactions(
    m::CoreModelCoupled,
    Sp::AbstractMatrix{Float64},
    b::AbstractVector{Float64},
    c::AbstractVector{Float64},
    xl::AbstractVector{Float64},
    xu::AbstractVector{Float64};
    check_consistency
) -> CoreModelCoupled
COBREXA.affine_hit_and_runMethod
affine_hit_and_run(
    m::MetabolicModel,
    warmup_points::Matrix{Float64};
    sample_iters,
    workers,
    chains,
    seed
) -> Any

Run a hit-and-run style sampling that starts from warmup_points and uses their affine combinations for generating the run directions to sample the space delimited by lbs and ubs. The reaction rate vectors in warmup_points should be organized in columns, i.e. warmup_points[:,1] is the first set of reaction rates.

There are total chains of hit-and-run runs, each on a batch of size(warmup_points, 2) points. The runs are scheduled on workers, for good load balancing chains should be ideally much greater than length(workers).

Each run continues for maximum(sample_iters) iterations; the numbers in sample_iters represent the iterations at which the whole "current" batch of points is collected for output. For example, sample_iters=[1,4,5] causes the process run for 5 iterations, returning the sample batch that was produced by 1st, 4th and last (5th) iteration.

Returns a matrix of sampled reaction rates (in columns), with all collected samples horizontally concatenated. The total number of samples (columns) will be size(warmup_points,2) * chains * length(sample_iters).

Example

warmup_points = warmup_from_variability(model, GLPK.Optimizer)
samples = affine_hit_and_run(model, warmup_points, sample_iters = 101:105)

# convert the result to flux (for models where the distinction matters):
fluxes = reaction_flux(model)' * samples
COBREXA.ambiguously_identified_itemsMethod
ambiguously_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_indexMethod
annotation_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.atom_fluxesMethod
atom_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.balanceMethod
balance(
    a::CoreModel
) -> SparseArrays.SparseVector{Float64, Int64}

CoreModel target flux balance.

COBREXA.balanceMethod
balance(model::GeckoModel) -> Any

Return the balance of the reactions in the inner model, concatenated with a vector of zeros representing the enzyme balance of a GeckoModel.

COBREXA.balanceMethod
balance(m::MATModel) -> Any

Extracts balance from the MAT model, defaulting to zeroes if not present.

COBREXA.balanceMethod
balance(
    a::MetabolicModel
) -> SparseArrays.SparseVector{Float64, Int64}

Get the sparse balance vector of a model.

COBREXA.balanceMethod
balance(model::ModelWrapper)

Evaluates balance on the model contained in ModelWrapper.

COBREXA.balanceMethod
balance(
    model::SBMLModel
) -> SparseArrays.SparseVector{Float64, Int64}

Balance vector of a SBMLModel. This is always zero.

COBREXA.balanceMethod
balance(
    model::StandardModel
) -> SparseArrays.SparseVector{Float64, Int64}

Return the balance of the linear problem, i.e. b in Sv = 0 where S is the stoichiometric matrix and v is the flux vector.

COBREXA.boundsMethod
bounds(
    a::CoreModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

CoreModel flux bounds.

COBREXA.boundsMethod
bounds(
    model::GeckoModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Return variable bounds for GeckoModel.

COBREXA.boundsMethod
bounds(model::JSONModel) -> Tuple{Vector, Vector}

Get the bounds for reactions, assuming the information is stored in .lower_bound and .upper_bound.

COBREXA.boundsMethod
bounds(m::MATModel) -> Tuple{Any, Any}

Extracts bounds from the MAT file, saved under lb and ub.

COBREXA.boundsMethod
bounds(
    a::MetabolicModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Get the lower and upper solution bounds of a model.

COBREXA.boundsMethod
bounds(model::ModelWrapper)

Evaluates bounds on the model contained in ModelWrapper.

COBREXA.boundsMethod
bounds(
    model::SBMLModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Get the lower and upper flux bounds of model SBMLModel. Throws DomainError in case if the SBML contains mismatching units.

COBREXA.boundsMethod
bounds(
    model::SMomentModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Return the variable bounds for SMomentModel.

COBREXA.boundsMethod
bounds(
    model::StandardModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Return the lower and upper bounds, respectively, for reactions in model. Order matches that of the reaction ids returned in reactions().

COBREXA.change_bound!Method
change_bound!(
    model::CoreCoupling,
    rxn_idx::Int;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model in-place.

Example

new_model = change_bound!(model, 123, lower=-21.15, upper=42.3)
COBREXA.change_bound!Method
change_bound!(
    model::CoreCoupling,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model in-place.

Example

new_model = change_bound!(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_bound!Method
change_bound!(
    model::CoreModel,
    rxn_idx::Int;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model in-place.

Example

new_model = change_bound!(model, 123, lower=-21.15, upper=42.3)
COBREXA.change_bound!Method
change_bound!(
    model::CoreModel,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model in-place.

Example

new_model = change_bound!(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_bound!Method
change_bound!(
    model::StandardModel,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model in-place.

Example

new_model = change_bound!(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_boundMethod
change_bound(
    model::CoreCoupling,
    rxn_idx::Int;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model and return the modified model.

Example

change_bound(model, 123, lower=-21.15, upper=42.3)
COBREXA.change_boundMethod
change_bound(
    model::CoreCoupling,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model and return the modified model.

Example

change_bound(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_boundMethod
change_bound(
    model::CoreModel,
    rxn_idx::Int;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model and return the modified model.

Example

change_bound(model, 123, lower=-21.15, upper=42.3)
COBREXA.change_boundMethod
change_bound(
    model::CoreModel,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model and return the modified model.

Example

change_bound(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_boundMethod
change_bound(model::Serialized, ...)

Calls change_bound of the internal serialized model type. Returns the modified un-serialized model.

COBREXA.change_boundMethod
change_bound(
    model::StandardModel,
    rxn_id::String;
    lower = nothing,
    upper = nothing,
)

Change the specified reaction flux bound in the model and return the modified model.

Example

change_bound(model, "ReactionB", lower=-21.15, upper=42.3)
COBREXA.change_bounds!Method
change_bounds!(
    model::CoreCoupling,
    rxn_idxs::AbstractVector{Int64};
    lower = (nothing for _ = rxn_idxs),
    upper = (nothing for _ = rxn_idxs),
)

Change the specified reaction flux bounds in the model in-place.

Example

new_model = change_bounds!(model, [123, 234], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_bounds!Method
change_bounds!(
    model::CoreCoupling,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model in-place.

Example

new_model = change_bounds!(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_bounds!Method
change_bounds!(
    model::CoreModel,
    rxn_idxs::AbstractVector{Int64};
    lower = (nothing for _ = rxn_idxs),
    upper = (nothing for _ = rxn_idxs),
)

Change the specified reaction flux bounds in the model in-place.

Example

new_model = change_bounds!(model, [123, 234], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_bounds!Method
change_bounds!(
    model::CoreModel,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model in-place.

Example

new_model = change_bounds!(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_bounds!Method
change_bounds!(
    model::StandardModel,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model in-place.

Example

new_model = change_bounds!(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_boundsMethod
change_bounds(
    model::CoreCoupling,
    rxn_idxs::AbstractVector{Int64};
    lower = (nothing for _ = rxn_idxs),
    upper = (nothing for _ = rxn_idxs),
)

Change the specified reaction flux bounds in the model and return the modified model.

Example

change_bounds(model, [123, 234], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_boundsMethod
change_bounds(
    model::CoreCoupling,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model and return the modified model.

Example

change_bounds(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_boundsMethod
change_bounds(
    model::CoreModel,
    rxn_idxs::AbstractVector{Int64};
    lower = (nothing for _ = rxn_idxs),
    upper = (nothing for _ = rxn_idxs),
)

Change the specified reaction flux bounds in the model and return the modified model.

Example

change_bounds(model, [123, 234], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_boundsMethod
change_bounds(
    model::CoreModel,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model and return the modified model.

Example

change_bounds(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_boundsMethod
change_bounds(
    model::StandardModel,
    rxn_ids::AbstractVector{String};
    lower = (nothing for _ = rxn_ids),
    upper = (nothing for _ = rxn_ids),
)

Change the specified reaction flux bounds in the model and return the modified model.

Example

change_bounds(model, ["ReactionA", "ReactionC"], lower=[-2.1, -50.05], upper=[4.2, 100.1])
COBREXA.change_constraintMethod
change_constraint(
    id::String;
    lb,
    ub
) -> COBREXA.var"#586#587"{Nothing, Nothing, String}

Change the lower and upper bounds (lb and ub respectively) of reaction id if supplied.

COBREXA.change_coupling_bounds!Method
change_coupling_bounds!(
    model::CoreCoupling,
    constraints::Vector{Int64};
    cl,
    cu
)

Change the lower and/or upper bounds (cl and cu) for the given list of coupling constraints.

COBREXA.change_objective!Method
change_objective!(model::CoreModel, rxn_idx::Int64)

Change objective function of a CoreModel to a single 1 at reaction index rxn_idx.

COBREXA.change_objective!Method
change_objective!(model::CoreModel, rxn_id::String)

Change objective function of a CoreModel to a single 1 at the given reaction ID.

COBREXA.change_objective!Method
change_objective!(
    model::CoreModel,
    rxn_idxs::Vector{Int64};
    weights
)

Change the objective to reactions at given indexes, optionally specifying their weights in the same order. By default, all set weights are 1.

COBREXA.change_objective!Method
change_objective!(
    model::CoreModel,
    rxn_ids::Vector{String};
    weights
)

Change objective of given reaction IDs, optionally specifying objective weights in the same order as rxn_ids. By default, all set weights are 1.

COBREXA.change_objective!Method
change_objective!(
    model::StandardModel,
    rxn_ids::Vector{String};
    weights
)

Change the objective for model to reaction(s) with rxn_ids, optionally specifying their weights. By default, assume equal weights. If no objective exists in model, sets objective.

COBREXA.change_objectiveMethod
change_objective(
    new_objective::Union{String, Vector{String}};
    weights,
    sense
) -> Union{COBREXA.var"#589#591"{MathOptInterface.OptimizationSense, Vector{String}}, COBREXA.var"#589#591"{MathOptInterface.OptimizationSense, String}}

Modification that changes the objective function used in a constraint based analysis function. new_objective can be a single reaction identifier, or an array of reactions identifiers.

Optionally, the objective can be weighted by a vector of weights, and a optimization sense can be set to either MAX_SENSE or MIN_SENSE.

COBREXA.change_optimizerMethod
change_optimizer(optimizer) -> COBREXA.var"#622#623"

Change the JuMP optimizer used to run the optimization.

This may be used to try different approaches for reaching the optimum, and in problems that may require different optimizers for different parts, such as the parsimonious_flux_balance_analysis.

COBREXA.change_optimizer_attributeMethod
change_optimizer_attribute(
    attribute_key,
    value
) -> COBREXA.var"#624#625"

Change a JuMP optimizer attribute. The attributes are optimizer-specific, refer to the JuMP documentation and the documentation of the specific optimizer for usable keys and values.

COBREXA.change_senseMethod
change_sense(objective_sense) -> COBREXA.var"#620#621"

Change the objective sense of optimization. Possible arguments are MAX_SENSE and MIN_SENSE.

If you want to change the objective and sense at the same time, use change_objective instead to do both at once.

COBREXA.check_duplicate_reactionMethod
check_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 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.

See also: reaction_mass_balanced

COBREXA.couplingMethod
coupling(
    a::CoreCoupling
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Coupling constraint matrix for a CoreCoupling.

COBREXA.couplingMethod
coupling(model::GeckoModel) -> Any

Return the coupling of GeckoModel. That combines the coupling of the wrapped model, coupling for split (arm) reactions, and the coupling for the total enzyme capacity.

COBREXA.couplingMethod
coupling(m::MATModel) -> Any

Extract coupling matrix stored, in C key.

COBREXA.couplingMethod
coupling(
    a::MetabolicModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Get a matrix of coupling constraint definitions of a model. By default, there is no coupling in the models.

COBREXA.couplingMethod
coupling(model::SMomentModel) -> Any

Return the coupling of SMomentModel. That combines the coupling of the wrapped model, coupling for split reactions, and the coupling for the total enzyme capacity.

COBREXA.coupling_boundsMethod
coupling_bounds(
    a::CoreCoupling
) -> Tuple{Vector{Float64}, Vector{Float64}}

Coupling bounds for a CoreCoupling.

COBREXA.coupling_boundsMethod
coupling_bounds(m::MATModel) -> Tuple{Any, Any}

Extracts the coupling constraints. Currently, there are several accepted ways to store these in MATLAB models; this takes the constraints from vectors cl and cu.

COBREXA.coupling_boundsMethod
coupling_bounds(
    a::MetabolicModel
) -> Tuple{Vector{Float64}, Vector{Float64}}

Get the lower and upper bounds for each coupling bound in a model, as specified by coupling. By default, the model does not have any coupling bounds.

COBREXA.envelope_latticeMethod
envelope_lattice(
    model::MetabolicModel,
    ridxs::Vector{Int64};
    samples,
    ranges,
    reaction_samples
) -> Base.Generator{_A, COBREXA.var"#458#459"} where _A

Create a lattice (list of "tick" vectors) for reactions at indexes ridxs in a model. Arguments samples, ranges, and reaction_samples may be optionally specified to customize the lattice creation process.

COBREXA.envelope_latticeMethod
envelope_lattice(
    model::MetabolicModel,
    rids::Vector{String};
    kwargs...
) -> Base.Generator{_A, COBREXA.var"#458#459"} where _A

Version of envelope_lattice that works on string reaction IDs instead of integer indexes.

COBREXA.expression_probabilistic_boundsMethod
expression_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.flux_balance_analysisMethod
flux_balance_analysis(
    model::MetabolicModel,
    optimizer;
    modifications
) -> JuMP.Model

Run flux balance analysis (FBA) on the model optionally specifying modifications to the problem. Basically, FBA solves this optimization problem:

max cᵀx
s.t. S x = b
     xₗ ≤ x ≤ xᵤ

See "Orth, J., Thiele, I. & Palsson, B. What is flux balance analysis?. Nat Biotechnol 28, 245-248 (2010). https://doi.org/10.1038/nbt.1614" for more information.

The optimizer must be set to a JuMP-compatible optimizer, such as GLPK.Optimizer or Tulip.Optimizer

Optionally, you may specify one or more modifications to be applied to the model before the analysis, such as change_optimizer_attribute, change_objective, and change_sense.

Returns an optimized JuMP model.

Example

model = load_model("e_coli_core.json")
solution = flux_balance_analysis(model, GLPK.optimizer)
value.(solution[:x])  # extract flux steady state from the optimizer

biomass_reaction_id = findfirst(model.reactions, "BIOMASS_Ecoli_core_w_GAM")

modified_solution = flux_balance_analysis(model, GLPK.optimizer;
    modifications=[change_objective(biomass_reaction_id)])
COBREXA.flux_balance_analysis_dictMethod
flux_balance_analysis_dict(
    model::MetabolicModel,
    args...;
    kwargs...
) -> Union{Nothing, Dict{String, Float64}}

A variant of FBA that returns a dictionary assigning fluxes to reactions, if the solution is found. Arguments are passed to flux_balance_analysis.

This function is kept for backwards compatibility, use flux_dict instead.

COBREXA.flux_balance_analysis_vecMethod
flux_balance_analysis_vec(
    model::MetabolicModel,
    args...;
    kwargs...
) -> Union{Nothing, Vector{Float64}}

A variant of FBA that returns a vector of fluxes in the same order as reactions of the model, if the solution is found.

Arguments are passed to flux_balance_analysis.

This function is kept for backwards compatibility, use flux_vector instead.

COBREXA.flux_dictMethod
flux_dict(
    model::MetabolicModel,
    opt_model
) -> Union{Nothing, Dict{String, Float64}}

Returns the fluxes of the model as a reaction-keyed dictionary, if solved.

Example

flux_dict(model, flux_balance_analysis(model, ...))
COBREXA.flux_dictMethod
flux_dict(model::MetabolicModel) -> COBREXA.var"#184#185"

A pipeable variant of flux_dict.

Example

flux_balance_analysis(model, ...) |> flux_dict(model)
COBREXA.flux_summaryMethod
flux_summary(
    flux_result::Union{Nothing, Dict{String, Float64}};
    exclude_exchanges,
    exchange_prefixes,
    biomass_strings,
    exclude_biomass,
    small_flux_bound,
    large_flux_bound,
    keep_unbounded
) -> FluxSummary

Summarize a dictionary of fluxes into small, useful representation of the most important information contained. Useful for pretty-printing and quickly exploring the results. Internally this function uses looks_like_biomass_reaction and looks_like_exchange_reaction. The corresponding keyword arguments passed to these functions. Use this if your model has non-standard ids for reactions. Fluxes smaller than small_flux_bound are not stored, while fluxes larger than large_flux_bound are only stored if keep_unbounded is true.

Example

julia> sol = flux_dict(flux_balance_analysis(model, Tulip.Optimizer))
julia> fr = flux_summary(sol)
Biomass:
  BIOMASS_Ecoli_core_w_GAM: 0.8739
Import:
  EX_o2_e:     -21.7995
  EX_glc__D_e: -10.0
  EX_nh4_e:    -4.7653
  EX_pi_e:     -3.2149
Export:
  EX_h_e:      17.5309
  EX_co2_e:    22.8098
  EX_h2o_e:    29.1758
COBREXA.flux_variability_analysisMethod
flux_variability_analysis(
    model::MetabolicModel,
    fluxes::SparseArrays.SparseMatrixCSC{Float64, Int64},
    optimizer;
    modifications,
    workers,
    optimal_objective_value,
    bounds,
    ret
) -> Array

Flux variability analysis solves a pair of optimization problems in model for each flux f described in fluxes:

min,max fᵀxᵢ
s.t. S x = b
    xₗ ≤ x ≤ xᵤ
     cᵀx ≥ bounds(Z₀)[1]
     cᵀx ≤ bounds(Z₀)[2]

where Z₀:= cᵀx₀ is the objective value of an optimal solution of the associated FBA problem (see flux_balance_analysis for a related analysis, also for explanation of the modifications argument).

The bounds is a user-supplied function that specifies the objective bounds for the variability optimizations, by default it restricts the flux objective value to the precise optimum reached in FBA. It can return -Inf and Inf in first and second pair to remove the limit. Use gamma_bounds and objective_bounds for simple bounds.

optimizer must be set to a JuMP-compatible optimizer. The computation of the individual optimization problems is transparently distributed to workers (see Distributed.workers()). The value of Z₀ can be optionally supplied in argument optimal_objective_value, which prevents this function from calling the non-parallelizable FBA. Separating the single-threaded FBA and multithreaded variability computation can be used to improve resource allocation efficiency in many common use-cases.

ret is a function used to extract results from optimized JuMP models of the individual fluxes. By default, it calls and returns the value of JuMP.objective_value. More information can be extracted e.g. by setting it to a function that returns a more elaborate data structure; such as m -> (JuMP.objective_value(m), JuMP.value.(m[:x])).

Returns a matrix of extracted ret values for minima and maxima, of total size (size(fluxes,2),2). The optimizer result status is checked with is_solved; nothing is returned if the optimization failed for any reason.

Example

model = load_model("e_coli_core.json")
flux_variability_analysis(model, GLPK.optimizer)
COBREXA.flux_variability_analysis_dictMethod
flux_variability_analysis_dict(
    model::MetabolicModel,
    optimizer;
    kwargs...
) -> Tuple{Any, Any}

A variant of flux_variability_analysis that returns the individual maximized and minimized fluxes as two dictionaries (of dictionaries). All keyword arguments except ret are passed through.

Example

mins, maxs = flux_variability_analysis_dict(
    model,
    Tulip.Optimizer;
    bounds = objective_bounds(0.99),
    modifications = [
        change_optimizer_attribute("IPM_IterationsLimit", 500),
        change_constraint("EX_glc__D_e"; lb = -10, ub = -10),
        change_constraint("EX_o2_e"; lb = 0, ub = 0),
    ],
)
COBREXA.flux_variability_summaryMethod
flux_variability_summary(
    flux_result::Tuple{Dict{String, Dict{String, Float64}}, Dict{String, Dict{String, Float64}}};
    exclude_exchanges,
    exchange_prefixes,
    biomass_strings,
    exclude_biomass
) -> FluxVariabilitySummary

Summarize a dictionary of flux dictionaries obtained eg. from flux_variability_analysis_dict. The simplified summary representation is useful for pretty-printing and easily showing the most important results.

Internally this function uses looks_like_biomass_reaction and looks_like_exchange_reaction. The corresponding keyword arguments are passed to these functions. Use this if your model has an uncommon naming of reactions.

Example

julia> sol = flux_variability_analysis_dict(model, Gurobi.Optimizer; bounds = objective_bounds(0.99))
julia> flux_res = flux_variability_summary(sol)
Biomass                     Lower bound   Upper bound
  BIOMASS_Ecoli_core_w_GAM: 0.8652        0.8652
Exchange
  EX_h2o_e:                 28.34         28.34
  EX_co2_e:                 22.0377       22.0377
  EX_o2_e:                  -22.1815      -22.1815
  EX_h_e:                   17.3556       17.3556
  EX_glc__D_e:              -10.0         -10.0
  EX_nh4_e:                 -4.8448       -4.8448
  EX_pi_e:                  -3.2149       -3.2149
  EX_for_e:                 0.0           0.0
  ...                       ...           ...
COBREXA.flux_vectorMethod
flux_vector(
    model::MetabolicModel,
    opt_model
) -> Union{Nothing, Vector{Float64}}

Returns a vector of fluxes of the model, if solved.

Example

flux_vector(flux_balance_analysis(model, ...))
COBREXA.fluxesMethod
fluxes(a::MetabolicModel) -> Vector{String}

In some models, the reactions that correspond to the columns of stoichiometry matrix do not fully represent the semantic contents of the model; for example, fluxes may be split into forward and reverse reactions, reactions catalyzed by distinct enzymes, etc. Together with reaction_flux (and n_fluxes) this specifies how the flux is decomposed into individual reactions.

By default (and in most models), fluxes and reactions perfectly correspond.

COBREXA.fluxesMethod
fluxes(model::ModelWrapper)

Evaluates fluxes on the model contained in ModelWrapper.

COBREXA.gamma_boundsMethod
gamma_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.gapfill_minimum_reactionsMethod
gapfill_minimum_reactions(
    model::MetabolicModel,
    universal_reactions::Vector{Reaction},
    optimizer;
    objective_bounds,
    maximum_new_reactions,
    weights,
    modifications
) -> JuMP.Model

Find a minimal set of reactions from universal_reactions that should be added to model so that the model has a feasible solution with bounds on its objective function given in objective_bounds. Weights of the added reactions may be specified in weights to prefer adding reactions with lower weights.

Internally, this builds and solves a mixed integer program, following the method of Reed et al. (Reed, Jennifer L., et al. "Systems approach to refining genome annotation." Proceedings of the National Academy of Sciences (2006)).

The function returns a solved JuMP optimization model, with the boolean reaction inclusion indicators in variable vector y. Use gapfilled_mask or gapfilled_rids to collect the reaction information in Julia datatypes.

To reduce the uncertainty in the MILP solver (and likely reduce the complexity), you may put a limit on the size of the added reaction set in maximum_new_reactions.

Common pitfalls

If gapfill_minimum_reactions is supposed to generate any reasonable output, the input model MUST NOT be feasible, otherwise there is "no work to do" and no reactions are added. Notably, an inactive model (the flux is zero) is considered to be feasible. If this is the case, gapfilled_rids will return an empty vector (as opposed to nothing).

To prevent this, you may need to modify the model to disallow the trivial solutions (for example by putting a lower bound on reactions that you expect to be working in the solved model, in a similar manner like how the ATP maintenance reaction is bounded in E. Coli "core" model). The objective_bounds parameter makes this easier by directly placing a bound on the objective value of the model, which typically forces the model to be active.

The maximum_new_reactions parameter may have critical impact on performance in some solvers, because (in a general worst case) there is 2^maximum_new_reactions model variants to be examined. Putting a hard limit on the reaction count may serve as a heuristic that helps the solver not to waste too much time solving impractically complex subproblems.

COBREXA.gapfilled_maskMethod
gapfilled_mask(opt_model) -> BitVector

Get a BitVector of added reactions from the model solved by gapfill_minimum_reactions. The bit indexes correspond to the indexes of universal_reactions given to the gapfilling function. In case the model is not solved, this returns nothing.

If this function returns a zero vector (instead of nothing), it is very likely that the original model was already feasible and you may need to constraint it more. Refer to "pitfalls" section in the documentation of gapfill_minimum_reactions for more details.

Example

gapfill_minimum_reactions(myModel, myReactions, Tulip.Optimizer) |> gapfilled_mask
COBREXA.gapfilled_ridsMethod
gapfilled_rids(
    opt_model,
    universal_reactions::Vector{Reaction}
) -> Vector{String}

Utility to extract a short vector of IDs of the reactions added by the gapfilling algorithm. Use with opt_model returned from gapfill_minimum_reactions.

If this function returns an empty vector (instead of nothing), it is very likely that the original model was already feasible and you may need to constraint it more. Refer to "pitfalls" section in the documentation of gapfill_minimum_reactions for more details.

COBREXA.gapfilled_ridsMethod
gapfilled_rids(
    universal_reactions::Vector{Reaction}
) -> COBREXA.var"#414#415"{Vector{Reaction}}

Overload of gapfilled_rids that can be piped easily.

Example

gapfill_minimum_reactions(myModel, myReactions, Tulip.Optimizer) |> gapfilled_rids(myReactions)
COBREXA.gene_annotationsMethod
gene_annotations(a::MetabolicModel, gene_id::String) -> Any

Return standardized names that identify the corresponding gene or product. The dictionary assigns vectors of possible identifiers to identifier system names, e.g. "PDB" => ["PROT01"].

COBREXA.gene_annotationsMethod
gene_annotations(
    model::SBMLModel,
    gid::String
) -> Dict{String, Vector{String}}

Return the annotations of gene with ID gid.

COBREXA.gene_annotationsMethod
gene_annotations(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the annotation associated with gene id in model. Return an empty Dict if not present.

COBREXA.gene_nameMethod
gene_name(model::JSONModel, gid::String) -> Any

Return the name of gene with ID gid.

COBREXA.gene_nameMethod
gene_name(model::MetabolicModel, gid::String) -> Any

Return the name of gene with ID gid.

COBREXA.gene_nameMethod
gene_name(
    model::SBMLModel,
    gid::String
) -> Union{Nothing, String}

Return the name of gene with ID gid.

COBREXA.gene_nameMethod
gene_name(
    m::StandardModel,
    gid::String
) -> Union{Nothing, String}

Return the name of gene with ID id.

COBREXA.gene_notesMethod
gene_notes(
    model::JSONModel,
    gid::String
) -> Dict{String, Vector{String}}

Gene notes from the JSONModel.

COBREXA.gene_notesMethod
gene_notes(model::MetabolicModel, gene_id::String) -> Any

Return the notes associated with the gene gene_id in model.

COBREXA.gene_notesMethod
gene_notes(
    model::SBMLModel,
    gid::String
) -> Dict{String, Vector{String}}

Return the notes about gene with ID gid.

COBREXA.gene_notesMethod
gene_notes(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the notes associated with gene id in model. Return an empty Dict if not present.

COBREXA.gene_product_dictMethod
gene_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.genesMethod
genes(a::CoreModel) -> Vector{String}

Collect all genes contained in the CoreModel. The call is expensive for large models, because the vector is not stored and instead gets rebuilt each time this function is called.

COBREXA.genesMethod
genes(model::GeckoModel) -> Any

Return the gene ids of genes that have enzymatic constraints associated with them.

COBREXA.genesMethod
genes(model::JSONModel) -> Vector

Extract gene names from a JSON model.

COBREXA.genesMethod
genes(m::MATModel) -> Any

Extracts the possible gene list from genes key.

COBREXA.genesMethod
genes(a::MetabolicModel) -> Vector{String}

Return identifiers of all genes contained in the model. By default, there are no genes.

In SBML, these are usually called "gene products" but we write genes for simplicity.

COBREXA.genesMethod
genes(model::ModelWrapper)

Evaluates genes on the model contained in ModelWrapper.

COBREXA.genesMethod
genes(model::StandardModel) -> Vector{String}

Return a vector of gene id strings in model.

COBREXA.getsMethod
gets(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.is_atp_maintenance_reactionMethod
is_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 inannotationkeys` to look for entries. Returns false if no hits or if no keys are found.

COBREXA.is_biomass_reactionMethod
is_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_boundaryMethod
is_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.is_exchange_reactionMethod
is_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_reactionMethod
is_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_reactionMethod
is_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_solvedMethod
is_solved(opt_model) -> Bool

Return true if opt_model solved successfully (solution is optimal or locally optimal). Return false if any other termination status is reached. Termination status is defined in the documentation of JuMP.

COBREXA.is_spontaneous_reactionMethod
is_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_reactionMethod
is_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.join_with_exchangesMethod
join_with_exchanges(
    ::Type{CoreModel},
    models::Array{M<:MetabolicModel, 1},
    exchange_rxn_mets::Dict{String, String};
    biomass_ids,
    model_names
) -> CoreModel

Return a CoreModel representing the community model of models joined through their exchange reactions and metabolites in the dictionary exchange_rxn_mets, which maps exchange reactions to their associated metabolite. These exchange reactions and metabolites link model metabolites to environmental metabolites and reactions. Optionally specify model_names to append a specific name to each reaction and metabolite of an organism for easier reference (default is species_i for each model index i in models). Note, the bounds of the environmental variables are all set to zero. Thus, to run a simulation you need to constrain them appropriately. All the other bounds are inherited from the models used to construct the community model.

If biomass_ids is supplied, then a community model is returned that has an extra reaction added to the end of the stoichiometric matrix (last column) that can be assigned as the objective reaction. It also creates biomass "metabolites" that can be used in this objective reaction. In the returned mode, these biomass metabolites are produced by the reaction corresponding to biomass_ids in each model respectively. Note, this reaction is unspecified, further action needs to be taken to specify it, e.g. assign weights to the last column of the stoichiometric matrix in the rows corresponding to the biomass metabolites.

To further clarify how this join works. Suppose you have 2 organisms with stoichiometric matrices S₁ and S₂ and you want to link them with exchange_rxn_mets = Dict(er₁ => em₁, er₂ => em₂, er₃ => em₃, ...). Then a new community stoichiometric matrix is constructed that looks like this:

            _      er₁  er₂  er₃  ...  b_
           |S₁                           |
           |   S₂                        |
        em₁|                             |
S   =   em₂|                             |
        em₃|                             |
        ...|                             |
        bm₁|                             |
        bm₂|_                           _|

The exchange reactions in each model get linked to environmental metabolites, emᵢ, and these get linked to environmental exchanges, erᵢ. These erᵢ behave like normal single organism exchange reactions. When biomass_ids are supplied, each model's biomass reaction produces a pseudo-metabolite (bmᵢ). These can be weighted in column b, called the community_biomass reaction in the community model, if desired. Refer to the tutorial if this is unclear.

Example

m1 = load_model(core_model_path)
m2 = load_model(CoreModel, core_model_path)

# need to list ALL the exchanges that will form part of the entire model
exchange_rxn_mets = Dict(k => first(keys(reaction_stoichiometry(m1, ex_rxn)))
    for filter(looks_like_exchange_reaction, reactions(m1)))

biomass_ids = ["BIOMASS_Ecoli_core_w_GAM", "BIOMASS_Ecoli_core_w_GAM"]

community = join_with_exchanges(
    CoreModel,
    [m1, m2],
    exchange_rxn_mets;
    biomass_ids = biomass_ids,
)
COBREXA.join_with_exchangesMethod
join_with_exchanges(
    ::Type{StandardModel},
    models::Array{M<:MetabolicModel, 1},
    exchange_rxn_mets::Dict{String, String};
    biomass_ids,
    model_names
) -> StandardModel

A variant of join_with_exchanges that returns a StandardModel.

COBREXA.knockoutMethod
knockout(
    gene_id::String
) -> COBREXA.var"#593#594"{Vector{String}}

A helper variant of knockout for a single gene.

COBREXA.knockoutMethod
knockout(
    gene_ids::Vector{String}
) -> COBREXA.var"#593#594"{Vector{String}}

A modification that zeroes the bounds of all reactions that would be knocked out by the combination of specified genes (effectively disabling the reactions).

A slightly counter-intuitive behavior may occur if knocking out multiple genes: Because this only changes the reaction bounds, multiple gene knockouts must be specified in a single call to knockout, because the modifications have no way to remember which genes are already knocked out and which not.

In turn, having a reaction that can be catalyzed either by Gene1 or by Gene2, specifying modifications = [knockout(["Gene1", "Gene2"])] does indeed disable the reaction, but modifications = [knockout("Gene1"), knockout("Gene2")] does not disable the reaction (although reactions that depend either only on Gene1 or only on Gene2 are disabled).

COBREXA.load_h5_modelMethod
load_h5_model(file_name::String) -> HDF5Model

Return a HDF5Model associated with the given file. Does not actually load anything (for efficiency) – use precache! to start pulling data into the memory.

COBREXA.load_json_modelMethod
load_json_model(filename::String) -> JSONModel

Load and return a JSON-formatted model that is stored in file_name.

COBREXA.load_mat_modelMethod
load_mat_model(file_name::String) -> MATModel

Load and return a MATLAB file file_name that contains a COBRA-compatible model.

COBREXA.load_modelMethod
load_model(file_name::String; extension) -> Any

Generic function for loading models that chooses a specific loader function based on the extension argument (e.g., ".xml" chooses loading of the SBML model format), or throws an error. By default the extension from file_name is used.

Currently, these model types are supported:

COBREXA.load_modelMethod
load_model(
    type::Type{T<:MetabolicModel},
    file_name::String;
    extension
) -> MetabolicModel

Helper function that loads the model using load_model and returns it converted to type.

Example:

load_model(CoreModel, "mySBMLModel.xml")
COBREXA.load_sbml_modelMethod
load_sbml_model(file_name::String) -> SBMLModel

Load and return a SBML XML model in file_name.

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

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

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

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

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

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

COBREXA.looks_like_biomass_reactionMethod
looks_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_reactionMethod
looks_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_metaboliteMethod
looks_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.lower_boundsMethod
lower_bounds(model::StandardModel) -> Vector{Float64}

Return the lower bounds for all reactions in model in sparse format.

COBREXA.make_gecko_modelMethod
make_gecko_model(
    model::MetabolicModel;
    reaction_isozymes,
    gene_product_bounds,
    gene_product_molar_mass,
    gene_product_mass_group,
    gene_product_mass_group_bound
)

Wrap a model into a GeckoModel, following the structure given by GECKO algorithm (see GeckoModel documentation for details).

Arguments

  • reaction_isozymes is a function that returns a vector of Isozymes for each reaction, or empty vector if the reaction is not enzymatic.
  • gene_product_bounds is a function that returns lower and upper bound for concentration for a given gene product (specified by the same string gene ID as in reaction_isozymes), as Tuple{Float64,Float64}.
  • gene_product_molar_mass is a function that returns a numeric molar mass of a given gene product specified by string gene ID.
  • gene_product_mass_group is a function that returns a string group identifier for a given gene product, again specified by string gene ID. By default, all gene products belong to group "uncategorized" which is the behavior of original GECKO.
  • gene_product_mass_group_bound is a function that returns the maximum mass for a given mass group.

Alternatively, all function arguments may be also supplied as dictionaries that provide the same data lookup.

COBREXA.make_optimization_modelMethod
make_optimization_model(
    model::MetabolicModel,
    optimizer;
    sense
) -> JuMP.Model

Convert MetabolicModels to a JuMP model, place objectives and the equality constraint.

Here coupling means inequality constraints coupling multiple variables together.

COBREXA.make_smoment_modelMethod
make_smoment_model(
    model::MetabolicModel;
    reaction_isozyme,
    gene_product_molar_mass,
    total_enzyme_capacity
)

Construct a model with a structure given by sMOMENT algorithm; returns a SMomentModel (see the documentation for details).

Arguments

  • reaction_isozyme parameter is a function that returns a single Isozyme for each reaction, or nothing if the reaction is not enzymatic. If the reaction has multiple isozymes, use smoment_isozyme_speed to select the fastest one, as recommended by the sMOMENT paper.
  • gene_product_molar_mass parameter is a function that returns a molar mass of each gene product as specified by sMOMENT.
  • total_enzyme_capacity is the maximum "enzyme capacity" in the model.

Alternatively, all function arguments also accept dictionaries that are used to provide the same data lookup.

COBREXA.max_min_driving_forceMethod
max_min_driving_force(
    model::MetabolicModel,
    reaction_standard_gibbs_free_energies::Dict{String, Float64},
    optimizer;
    flux_solution,
    proton_ids,
    water_ids,
    constant_concentrations,
    concentration_ratios,
    concentration_lb,
    concentration_ub,
    T,
    R,
    small_flux_tol,
    modifications,
    ignore_reaction_ids
) -> Union{Nothing, NamedTuple{(:mmdf, :dg_reactions, :concentrations), _A} where _A<:Tuple{Any, Dict, Dict}}

Perform a max-min driving force analysis on the model, as defined by Noor, et al., "Pathway thermodynamics highlights kinetic obstacles in central metabolism.", PLoS computational biology, 2014.

The function uses the supplied optimizer and reaction_standard_gibbs_free_energies. Optionally, flux_solution can be used to set the directions of each reaction in model (all reactions are assumed to proceed forward and are active by default). The supplied flux_solution should be free of internal cycles i.e. thermodynamically consistent. This optional input is important if a reaction in model normally runs in reverse (negative flux). Note, reactions in flux_solution that are smaller than small_flux_tol are also ignored in the analysis function (for numerical stability).

The max-min driving force algorithm returns the Gibbs free energy of the reactions, the concentrations of metabolites and the actual maximum minimum driving force. The optimization problem solved is:

max min -ΔᵣG
s.t. ΔᵣG = ΔrG⁰ + R T S' ln(C)
     ΔᵣG ≤ 0
     ln(Cₗ) ≤ ln(C) ≤ ln(Cᵤ)

where ΔrG are the Gibbs energies dissipated by the reactions, R is the gas constant, T is the temperature, S is the stoichiometry of the model, and C is the vector of metabolite concentrations (and their respective lower and upper bounds).

In case no feasible solution exists, nothing is returned.

Reactions specified in ignore_reaction_ids are internally ignored when calculating the max-min driving force. This should include water and proton importers.

Since biochemical thermodynamics are assumed, the proton_ids and water_ids need to be specified so that they can be ignored in the calculations. Effectively this assumes an aqueous environment at constant pH is used.

constant_concentrations is used to fix the concentrations of certain metabolites (such as CO₂). concentration_ratios is used to specify additional constraints on metabolite pair concentrations (typically, this is done with various cofactors such as the ATP/ADP ratio. For example, you can fix the concentration of ATP to be always 5× higher than of ADP by specifying Dict(("ATP","ADP") => 5.0)

concentration_lb and concentration_ub set the Cₗ and Cᵤ in the optimization problems.

T and R can be specified in the corresponding units; defaults are K and kJ/K/mol.

COBREXA.max_min_driving_force_variabilityMethod
max_min_driving_force_variability(
    model::MetabolicModel,
    reaction_standard_gibbs_free_energies::Dict{String, Float64},
    optimizer;
    workers,
    optimal_objective_value,
    bounds,
    modifications,
    kwargs...
) -> Array

Perform a variant of flux variability analysis on a max min driving force type problem. Arguments are forwarded to max_min_driving_force. Calls screen internally and possibly distributes computation across workers. If optimal_objective_value = nothing, the function first performs regular max min driving force analysis to find the max min driving force of the model and sets this to optimal_objective_value. Then iteratively maximizes and minimizes the driving force across each reaction, and then the concentrations while staying close to the original max min driving force as specified in bounds.

The bounds is a user-supplied function that specifies the max min driving force bounds for the variability optimizations, by default it restricts the flux objective value to the precise optimum reached in the normal max min driving force analysis. It can return -Inf and Inf in first and second pair to remove the limit. Use gamma_bounds and objective_bounds for simple bounds.

Returns a matrix of solutions to max_min_driving_force additionally constrained as described above, where the rows are in the order of the reactions and then the metabolites of the model. For the reaction rows the first column is the maximum dG of that reaction, and the second column is the minimum dG of that reaction subject to the above constraints. For the metabolite rows, the first column is the maximum concentration, and the second column is the minimum concentration subject to the constraints above.

COBREXA.metabolite_annotationsMethod
metabolite_annotations(
    a::MetabolicModel,
    metabolite_id::String
) -> Any

Return standardized names that may help to reliably identify the metabolite. The dictionary assigns vectors of possible identifiers to identifier system names, e.g. "ChEMBL" => ["123"] or "PubChem" => ["CID123", "CID654645645"].

COBREXA.metabolite_annotationsMethod
metabolite_annotations(
    model::SBMLModel,
    mid::String
) -> Dict{String, Vector{String}}

Return the annotations of metabolite with ID mid.

COBREXA.metabolite_annotationsMethod
metabolite_annotations(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the annotation associated with metabolite id in model. Return an empty Dict if not present.

COBREXA.metabolite_chargeMethod
metabolite_charge(
    m::MATModel,
    mid::String
) -> Union{Nothing, Int64}

Extract metabolite charge from metCharge or metCharges.

COBREXA.metabolite_chargeMethod
metabolite_charge(
    model::MetabolicModel,
    metabolite_id::String
) -> Any

Return the charge associated with metabolite metabolite_id in model. Returns nothing if charge not present.

COBREXA.metabolite_chargeMethod
metabolite_charge(
    model::StandardModel,
    id::String
) -> Union{Nothing, Int64}

Return the charge associated with metabolite id in model. Return nothing if not present.

COBREXA.metabolite_compartmentMethod
metabolite_compartment(m::MATModel, mid::String) -> Any

Extract metabolite compartment from metCompartment or metCompartments.

COBREXA.metabolite_compartmentMethod
metabolite_compartment(
    model::MetabolicModel,
    metabolite_id::String
) -> Any

Return the compartment of metabolite metabolite_id in model if it is assigned. If not, return nothing.

COBREXA.metabolite_compartmentMethod
metabolite_compartment(
    model::StandardModel,
    id::String
) -> Union{Nothing, String}

Return compartment associated with metabolite id in model. Return nothing if not present.

COBREXA.metabolite_fluxesMethod
metabolite_fluxes(
    model::MetabolicModel,
    flux_dict::Dict{String, Float64}
) -> Tuple{Dict{String, Dict{String, Float64}}, Dict{String, 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.

COBREXA.metabolite_formulaMethod
metabolite_formula(
    model::JSONModel,
    mid::String
) -> Union{Nothing, Dict{String, Int64}}

Parse and return the metabolite .formula

COBREXA.metabolite_formulaMethod
metabolite_formula(
    m::MATModel,
    mid::String
) -> Union{Nothing, Dict{String, Int64}}

Extract metabolite formula from key metFormula or metFormulas.

COBREXA.metabolite_formulaMethod
metabolite_formula(
    model::MetabolicModel,
    metabolite_id::String
) -> Any

Return the formula of metabolite metabolite_id in model. Return nothing in case the formula is not known or irrelevant.

COBREXA.metabolite_formulaMethod
metabolite_formula(
    model::StandardModel,
    id::String
) -> Union{Nothing, Dict{String, Int64}}

Return the formula of reaction id in model. Return nothing if not present.

COBREXA.metabolite_nameMethod
metabolite_name(model::JSONModel, mid::String) -> Any

Return the name of metabolite with ID mid.

COBREXA.metabolite_nameMethod
metabolite_name(m::MATModel, mid::String) -> Any

Extract metabolite name from metNames.

COBREXA.metabolite_nameMethod
metabolite_name(model::MetabolicModel, mid::String) -> Any

Return the name of metabolite with ID mid.

COBREXA.metabolite_nameMethod
metabolite_name(
    model::SBMLModel,
    mid::String
) -> Union{Nothing, String}

Return the name of metabolite with ID mid.

COBREXA.metabolite_nameMethod
metabolite_name(
    m::StandardModel,
    mid::String
) -> Union{Nothing, String}

Return the name of metabolite with ID id.

COBREXA.metabolite_notesMethod
metabolite_notes(
    model::MetabolicModel,
    metabolite_id::String
) -> Any

Return the notes associated with metabolite reaction_id in model.

COBREXA.metabolite_notesMethod
metabolite_notes(
    model::SBMLModel,
    mid::String
) -> Dict{String, Vector{String}}

Return the notes about metabolite with ID mid.

COBREXA.metabolite_notesMethod
metabolite_notes(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the notes associated with metabolite id in model. Return an empty Dict if not present.

COBREXA.metabolitesMethod
metabolites(a::CoreModel) -> Vector{String}

Metabolites in a CoreModel.

COBREXA.metabolitesMethod
metabolites(model::JSONModel) -> Vector

Extract metabolite names (stored as .id) from JSON model.

COBREXA.metabolitesMethod
metabolites(m::MATModel) -> Vector{String}

Extracts metabolite names from mets key in the MAT file.

COBREXA.metabolitesMethod
metabolites(a::MetabolicModel) -> Vector{String}

Return a vector of metabolite identifiers in a model. The vector precisely corresponds to the rows in stoichiometry matrix.

As with reactionss, some metabolites in models may be virtual, representing purely technical equality constraints.

COBREXA.metabolitesMethod
metabolites(model::StandardModel) -> Vector{String}

Return a vector of metabolite id strings contained in model. The order of metabolite strings returned here matches the order used to construct the stoichiometric matrix.

COBREXA.minimize_metabolic_adjustment_analysisMethod
minimize_metabolic_adjustment_analysis(
    model::MetabolicModel,
    flux_ref::Union{Dict{String, Float64}, Vector{Float64}},
    optimizer;
    modifications,
    kwargs...
) -> JuMP.Model

Run minimization of metabolic adjustment (MOMA) on model with respect to flux_ref, which is a vector of fluxes in the order of reactions(model). MOMA finds the shortest Euclidian distance between flux_ref and model with modifications:

min Σᵢ (xᵢ - flux_refᵢ)²
s.t. S x = b
     xₗ ≤ x ≤ xᵤ

Because the problem has a quadratic objective, a QP solver is required. See "Daniel, Vitkup & Church, Analysis of Optimality in Natural and Perturbed Metabolic Networks, Proceedings of the National Academy of Sciences, 2002" for more details.

Additional arguments are passed to flux_balance_analysis.

Returns an optimized model that contains the resultant nearest flux.

Example

model = load_model("e_coli_core.json")
flux_ref = flux_balance_analysis_vec(model, Gurobi.Optimizer)
optmodel = minimize_metabolic_adjustment(
    model,
    flux_ref,
    Gurobi.Optimizer;
    modifications = [change_constraint("PFL"; lb=0, ub=0)], # find flux of mutant that is closest to the wild type (reference) model
    )
value.(solution[:x])  # extract the flux from the optimizer
COBREXA.minimize_metabolic_adjustment_analysis_vecMethod
minimize_metabolic_adjustment_analysis_vec(
    model::MetabolicModel,
    args...;
    kwargs...
) -> Union{Nothing, Vector{Float64}}

Perform minimization of metabolic adjustment (MOMA) and return a vector of fluxes in the same order as the reactions in model. Arguments are forwarded to minimize_metabolic_adjustment internally.

This function is kept for backwards compatibility, use flux_vector instead.

COBREXA.n_genesMethod
n_genes(model::GeckoModel) -> Int64

Return the number of genes that have enzymatic constraints associated with them.

COBREXA.n_genesMethod
n_genes(a::MetabolicModel) -> Int64

Return the number of genes in the model (as returned by genes). If you just need the number of the genes, this may be much more efficient than calling genes and measuring the array.

COBREXA.n_genesMethod
n_genes(model::ModelWrapper)

Evaluates n_genes on the model contained in ModelWrapper.

COBREXA.n_genesMethod
n_genes(model::StandardModel) -> Int64

Return the number of genes in model.

COBREXA.n_metabolitesMethod
n_metabolites(a::MetabolicModel) -> Int64

Get the number of metabolites in a model.

COBREXA.n_metabolitesMethod
n_metabolites(model::StandardModel) -> Int64

Return the number of metabolites in model.

COBREXA.n_reactionsMethod
n_reactions(model::GeckoModel) -> Int64

Returns the number of all irreversible reactions in model as well as the number of gene products that take part in enzymatic reactions.

COBREXA.n_reactionsMethod
n_reactions(a::MetabolicModel) -> Int64

Get the number of reactions in a model.

COBREXA.n_reactionsMethod
n_reactions(model::StandardModel) -> Int64

Return the number of reactions contained in model.

COBREXA.objectiveMethod
objective(
    a::CoreModel
) -> SparseArrays.SparseVector{Float64, Int64}

CoreModel objective vector.

COBREXA.objectiveMethod
objective(
    model::GeckoModel
) -> SparseArrays.SparseVector{Float64, Int64}

Return the objective of the GeckoModel. Note, the objective is with respect to the internal variables, i.e. reactions(model), which are the unidirectional reactions and the genes involved in enzymatic reactions that have kinetic data.

COBREXA.objectiveMethod
objective(
    model::JSONModel
) -> SparseArrays.SparseVector{_A, Int64} where _A

Collect .objective_coefficient keys from model reactions.

COBREXA.objectiveMethod
objective(m::MATModel) -> Any

Extracts the objective from the MAT model (defaults to zeroes).

COBREXA.objectiveMethod
objective(
    a::MetabolicModel
) -> SparseArrays.SparseVector{Float64, Int64}

Get the objective vector of the model. Analysis functions, such as flux_balance_analysis, are supposed to maximize dot(objective, x) where x is a feasible solution of the model.

COBREXA.objectiveMethod
objective(
    model::SBMLModel
) -> SparseArrays.SparseVector{Float64, Int64}

Objective of the SBMLModel.

COBREXA.objectiveMethod
objective(
    model::StandardModel
) -> SparseArrays.SparseVector{Float64, Int64}

Return sparse objective vector for model.

COBREXA.objective_envelopeMethod
objective_envelope(
    model::MetabolicModel,
    ridxs::Vector{Int64},
    optimizer;
    modifications,
    lattice_args,
    lattice,
    analysis,
    kwargs...
) -> NamedTuple{(:lattice, :values), _A} where _A<:Tuple{Any, Array}

Compute an array of objective values for the model for rates of reactions specified ridxs fixed to a regular range of values between their respective lower and upper bounds.

This can be used to compute a "production envelope" of a metabolite; but generalizes to any specifiable objective and to multiple dimensions of the examined space. For example, to retrieve a production envelope of any metabolite, set the objective coefficient vector of the model to a vector that contains a single 1 for the exchange reaction that "outputs" this metabolite, and run objective_envelope with the exchange reaction of the "parameter" metabolite specified in ridxs.

Returns a named tuple that contains lattice with reference values of the metabolites, and an N-dimensional array values with the computed objective values, where N is the number of specified reactions. Because of the increasing dimensionality, the computation gets very voluminous with increasing length of ridxs. The lattice for computing the optima can be supplied in the argument; by default it is created by envelope_lattice called on the model and reaction indexes. Additional arguments for the call to envelope_lattice can be optionally specified in lattice_args.

kwargs are internally forwarded to screen_optmodel_modifications. modifications are appended to the list of modifications after the lattice bounds are set. By default, this returns the objective values for all points in the lattice; alternate outputs can be implemented via the analysis argument.

Example

julia> m = load_model("e_coli_core.xml");

julia> envelope = objective_envelope(m, ["R_EX_gln__L_e", "R_EX_fum_e"],
                                     Tulip.Optimizer;
                                     lattice_args=(samples=6,));

julia> envelope.lattice   # the reaction rates for which the optima were computed
2-element Vector{Vector{Float64}}:
 [0.0, 200.0, 400.0, 600.0, 800.0, 1000.0]
 [0.0, 200.0, 400.0, 600.0, 800.0, 1000.0]

julia> envelope.values   # the computed flux objective values for each reaction rate combination
6×6 Matrix{Float64}:
  0.873922   9.25815  17.4538  19.56   20.4121  20.4121
 13.0354    17.508    19.9369  21.894  22.6825  22.6825
 16.6666    18.6097   20.2847  21.894  22.6825  22.6825
 16.6666    18.6097   20.2847  21.894  22.6825  22.6825
 16.6666    18.6097   20.2847  21.894  22.6825  22.6825
 16.6666    18.6097   20.2847  21.894  22.6825  22.6825
COBREXA.objective_envelopeMethod
objective_envelope(
    model::MetabolicModel,
    rids::Vector{String},
    args...;
    kwargs...
) -> NamedTuple{(:lattice, :values), _A} where _A<:Tuple{Any, Array}

Version of objective_envelope that works on string reaction IDs instead of integer indexes.

COBREXA.optimize_objectiveMethod
optimize_objective(opt_model) -> Union{Nothing, Float64}

Shortcut for running JuMP optimize! on a model and returning the objective value, if solved.

COBREXA.parsimonious_flux_balance_analysisMethod
parsimonious_flux_balance_analysis(
    model::MetabolicModel,
    optimizer;
    modifications,
    qp_modifications,
    relax_bounds
) -> JuMP.Model

Run parsimonious flux balance analysis (pFBA) on the model. In short, pFBA runs two consecutive optimization problems. The first is traditional FBA:

max cᵀx = μ
s.t. S x = b
     xₗ ≤ x ≤ xᵤ

And the second is a quadratic optimization problem:

min Σᵢ xᵢ²
s.t. S x = b
     xₗ ≤ x ≤ xᵤ
     μ = μ⁰

Where the optimal solution of the FBA problem, μ⁰, has been added as an additional constraint. See "Lewis, Nathan E, Hixson, Kim K, Conrad, Tom M, Lerman, Joshua A, Charusanti, Pep, Polpitiya, Ashoka D, Adkins, Joshua N, Schramm, Gunnar, Purvine, Samuel O, Lopez-Ferrer, Daniel, Weitz, Karl K, Eils, Roland, König, Rainer, Smith, Richard D, Palsson, Bernhard Ø, (2010) Omic data from evolved E. coli are consistent with computed optimal growth from genome-scale models. Molecular Systems Biology, 6. 390. doi: accession:10.1038/msb.2010.47" for more details.

pFBA gets the model optimum by standard FBA (using flux_balance_analysis with optimizer and modifications), then finds a minimal total flux through the model that still satisfies the (slightly relaxed) optimum. This is done using a quadratic problem optimizer. If the original optimizer does not support quadratic optimization, it can be changed using the callback in qp_modifications, which are applied after the FBA. See the documentation of flux_balance_analysis for usage examples of modifications.

Thhe optimum relaxation sequence can be specified in relax parameter, it defaults to multiplicative range of [1.0, 0.999999, ..., 0.99] of the original bound.

Returns an optimized model that contains the pFBA solution (or an unsolved model if something went wrong).

Example

model = load_model("e_coli_core.json")
optmodel = parsimonious_flux_balance_analysis(model, biomass, Gurobi.Optimizer)
value.(solution[:x])  # extract the flux from the optimizer
COBREXA.parsimonious_flux_balance_analysis_dictMethod
parsimonious_flux_balance_analysis_dict(
    model::MetabolicModel,
    args...;
    kwargs...
) -> Union{Nothing, Dict{String, Float64}}

Perform parsimonious flux balance analysis on model using optimizer. Returns a dictionary mapping the reaction IDs to fluxes. Arguments are forwarded to parsimonious_flux_balance_analysis internally.

This function is kept for backwards compatibility, use flux_dict instead.

COBREXA.parsimonious_flux_balance_analysis_vecMethod
parsimonious_flux_balance_analysis_vec(
    model::MetabolicModel,
    args...;
    kwargs...
) -> Union{Nothing, Vector{Float64}}

Perform parsimonious flux balance analysis on model using optimizer. Returns a vector of fluxes in the same order as the reactions in model. Arguments are forwarded to parsimonious_flux_balance_analysis internally.

This function is kept for backwards compatibility, use flux_vector instead.

COBREXA.precache!Method
precache!(a::MetabolicModel)

Do whatever is feasible to get the model into a state that can be read from as-quickly-as-possible. This may include e.g. generating helper index structures and loading delayed parts of the model from disk. The model should be modified "transparently" in-place. Analysis functions call this right before applying modifications or converting the model to the optimization model using make_optimization_model; usually on the same machine where the optimizers (and, generally, the core analysis algorithms) will run. The calls are done in a good hope that the performance will be improved.

By default, it should be safe to do nothing.

COBREXA.precache!Method
precache!(model::Serialized)

Load the Serialized model from disk in case it's not alreadly loaded.

COBREXA.reaction_annotationsMethod
reaction_annotations(
    a::MetabolicModel,
    reaction_id::String
) -> Any

Return standardized names that may help identifying the reaction. The dictionary assigns vectors of possible identifiers to identifier system names, e.g. "Reactome" => ["reactomeID123"].

COBREXA.reaction_annotationsMethod
reaction_annotations(
    model::SBMLModel,
    rid::String
) -> Dict{String, Vector{String}}

Return the annotations of reaction with ID rid.

COBREXA.reaction_annotationsMethod
reaction_annotations(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the annotation associated with reaction id in model. Return an empty Dict if not present.

COBREXA.reaction_atom_balanceMethod
reaction_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_fluxMethod
reaction_flux(model::GeckoModel) -> Any

Get the mapping of the reaction rates in GeckoModel to the original fluxes in the wrapped model.

COBREXA.reaction_fluxMethod
reaction_flux(a::MetabolicModel) -> Any

Retrieve a sparse matrix that describes the correspondence of a solution of the linear system to the fluxes (see fluxes for rationale). Returns a sparse matrix of size (n_reactions(a), n_fluxes(a)). For most models, this is an identity matrix.

COBREXA.reaction_fluxMethod
reaction_flux(model::SMomentModel) -> Any

Get the mapping of the reaction rates in SMomentModel to the original fluxes in the wrapped model.

COBREXA.reaction_gene_associationMethod
reaction_gene_association(
    model::JSONModel,
    rid::String
) -> Union{Nothing, Vector{Vector{String}}}

Parses the .gene_reaction_rule from reactions.

COBREXA.reaction_gene_associationMethod
reaction_gene_association(
    m::MATModel,
    rid::String
) -> Union{Nothing, Vector{Vector{String}}}

Extracts the associations from grRules key, if present.

COBREXA.reaction_gene_associationMethod
reaction_gene_association(
    a::MetabolicModel,
    reaction_id::String
) -> Any

Returns the sets of genes that need to be present so that the reaction can work (technically, a DNF on gene availability, with positive atoms only).

For simplicity, nothing may be returned, meaning that the reaction always takes place. (in DNF, that would be equivalent to returning [[]].)

COBREXA.reaction_gene_associationMethod
reaction_gene_association(
    model::StandardModel,
    id::String
) -> Union{Nothing, Vector{Vector{String}}}

Return the gene reaction rule in string format for reaction with id in model. Return nothing if not available.

COBREXA.reaction_gene_association_vecMethod
reaction_gene_association_vec(
    model::CoreModel
) -> Vector{Union{Nothing, Vector{Vector{String}}}}

Retrieve a vector of all gene associations in a CoreModel, in the same order as reactions(model).

COBREXA.reaction_nameMethod
reaction_name(model::JSONModel, rid::String) -> Any

Return the name of reaction with ID rid.

COBREXA.reaction_nameMethod
reaction_name(m::MATModel, rid::String) -> Any

Extract reaction name from rxnNames.

COBREXA.reaction_nameMethod
reaction_name(model::MetabolicModel, rid::String) -> Any

Return the name of reaction with ID rid.

COBREXA.reaction_nameMethod
reaction_name(
    model::SBMLModel,
    rid::String
) -> Union{Nothing, String}

Return the name of reaction with ID rid.

COBREXA.reaction_nameMethod
reaction_name(
    m::StandardModel,
    rid::String
) -> Union{Nothing, String}

Return the name of reaction with ID id.

COBREXA.reaction_notesMethod
reaction_notes(
    model::MetabolicModel,
    reaction_id::String
) -> Any

Return the notes associated with reaction reaction_id in model.

COBREXA.reaction_notesMethod
reaction_notes(
    model::SBMLModel,
    rid::String
) -> Dict{String, Vector{String}}

Return the notes about reaction with ID rid.

COBREXA.reaction_notesMethod
reaction_notes(
    model::StandardModel,
    id::String
) -> Dict{String, Vector{String}}

Return the notes associated with reaction id in model. Return an empty Dict if not present.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::CoreModel,
    ridx
) -> Dict{String, Float64}

Return the stoichiometry of reaction at index ridx.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::CoreModel,
    rid::String
) -> Dict{String, Float64}

Return the stoichiometry of reaction with ID rid.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    model::JSONModel,
    rid::String
) -> Dict{String, Float64}

Return the stoichiometry of reaction with ID rid.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::MATModel,
    ridx
) -> Dict{String, Float64}

Return the stoichiometry of reaction at index ridx.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::MATModel,
    rid::String
) -> Dict{String, Float64}

Return the stoichiometry of reaction with ID rid.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::MetabolicModel,
    rid::String
) -> Any

Return the stoichiometry of reaction with ID rid in the model. The dictionary maps the metabolite IDs to their stoichiometric coefficients.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::SBMLModel,
    rid::String
) -> Dict{String, Float64}

Return the stoichiometry of reaction with ID rid.

COBREXA.reaction_stoichiometryMethod
reaction_stoichiometry(
    m::StandardModel,
    rid::String
) -> Dict{String, Float64}

Return the stoichiometry of reaction with ID rid.

COBREXA.reaction_subsystemMethod
reaction_subsystem(model::JSONModel, rid::String) -> Any

Parses the .subsystem out from reactions.

COBREXA.reaction_subsystemMethod
reaction_subsystem(
    model::MetabolicModel,
    reaction_id::String
) -> Any

Return the subsystem of reaction reaction_id in model if it is assigned. If not, return nothing.

COBREXA.reaction_subsystemMethod
reaction_subsystem(
    model::StandardModel,
    id::String
) -> Union{Nothing, String}

Return the subsystem associated with reaction id in model. Return nothing if not present.

COBREXA.reaction_variability_analysisMethod
reaction_variability_analysis(
    model::MetabolicModel,
    reaction_indexes::Vector{Int64},
    optimizer;
    kwargs...
) -> Array

A variant for flux_variability_analysis that examines actual reactions (selected by their indexes in reactions argument) instead of whole fluxes. This may be useful for models where the sets of reactions and fluxes differ.

COBREXA.reactionsMethod
reactions(a::CoreModel) -> Vector{String}

Get the reactions in a CoreModel.

COBREXA.reactionsMethod
reactions(model::GeckoModel) -> Any

Returns the internal reactions in a GeckoModel (these may be split to forward- and reverse-only parts with different isozyme indexes; reactions IDs are mangled accordingly with suffixes).

COBREXA.reactionsMethod
reactions(model::JSONModel) -> Vector

Extract reaction names (stored as .id) from JSON model.

COBREXA.reactionsMethod
reactions(m::MATModel) -> Vector{String}

Extracts reaction names from rxns key in the MAT file.

COBREXA.reactionsMethod
reactions(a::MetabolicModel) -> Vector{String}

Return a vector of reaction identifiers in a model. The vector precisely corresponds to the columns in stoichiometry matrix.

For technical reasons, the "reactions" may sometimes not be true reactions but various virtual and helper pseudo-reactions that are used in the metabolic modeling, such as metabolite exchanges, separate forward and reverse reactions, supplies of enzymatic and genetic material and virtual cell volume, etc. To simplify the view of the model contents use reaction_flux.

COBREXA.reactionsMethod
reactions(model::SMomentModel) -> Vector

Returns the internal reactions in a SMomentModel (these may be split to forward- and reverse-only parts; reactions IDs are mangled accordingly with suffixes).

COBREXA.reactionsMethod
reactions(model::StandardModel) -> Vector{String}

Return a vector of reaction id strings contained in model. The order of reaction ids returned here matches the order used to construct the stoichiometric matrix.

COBREXA.remove_gene!Method
remove_gene!(
    model::StandardModel,
    gid::String;
    knockout_reactions
)

Remove gene with id from model. If knockout_reactions is true, then also constrain reactions that require the genes to function to carry zero flux.

Example

remove_gene!(model, "g1")
COBREXA.remove_genes!Method
remove_genes!(
    model::StandardModel,
    gids::Vector{String};
    knockout_reactions
)

Remove all genes with ids from model. If knockout_reactions is true, then also constrain reactions that require the genes to function to carry zero flux.

Example

remove_genes!(model, ["g1", "g2"])
COBREXA.remove_metabolite!Method
remove_metabolite!(model::CoreCoupling, metabolite_idx::Int)

Remove metabolite from the model of type CoreCoupling in-place.

COBREXA.remove_metabolite!Method
remove_metabolite!(model::CoreCoupling, metabolite_id::String)

Remove metabolite from the model of type CoreCoupling in-place.

COBREXA.remove_metabolite!Method
remove_metabolite!(model::CoreModel, metabolite_idx::Int)

Remove metabolite from the model of type CoreModel in-place.

COBREXA.remove_metabolite!Method
remove_metabolite!(model::CoreModel, metabolite_id::String)

Remove metabolite from the model of type CoreModel in-place.

COBREXA.remove_metabolite!Method
remove_metabolite!(model::StandardModel, metabolite_id::String)

Remove metabolite from the model of type StandardModel in-place.

COBREXA.remove_metaboliteMethod
remove_metabolite(model::CoreCoupling, metabolite_idx::Int)

Remove metabolite from the model of type CoreCoupling and return the modified model.

COBREXA.remove_metaboliteMethod
remove_metabolite(model::CoreCoupling, metabolite_id::String)

Remove metabolite from the model of type CoreCoupling and return the modified model.

COBREXA.remove_metaboliteMethod
remove_metabolite(model::CoreModel, metabolite_idx::Int)

Remove metabolite from the model of type CoreModel and return the modified model.

COBREXA.remove_metaboliteMethod
remove_metabolite(model::CoreModel, metabolite_id::String)

Remove metabolite from the model of type CoreModel and return the modified model.

COBREXA.remove_metaboliteMethod
remove_metabolite(model::StandardModel, metabolite_id::String)

Remove metabolite from the model of type StandardModel and return the modified model.

COBREXA.remove_metabolites!Method
remove_metabolites!(model::CoreCoupling, metabolite_idxs::AbstractVector{Int64})

Remove metabolites from the model of type CoreCoupling in-place.

COBREXA.remove_metabolites!Method
remove_metabolites!(model::CoreCoupling, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type CoreCoupling in-place.

COBREXA.remove_metabolites!Method
remove_metabolites!(model::CoreModel, metabolite_idxs::AbstractVector{Int64})

Remove metabolites from the model of type CoreModel in-place.

COBREXA.remove_metabolites!Method
remove_metabolites!(model::CoreModel, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type CoreModel in-place.

COBREXA.remove_metabolites!Method
remove_metabolites!(model::StandardModel, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type StandardModel in-place.

COBREXA.remove_metabolitesMethod
remove_metabolites(model::CoreCoupling, metabolite_idxs::AbstractVector{Int64})

Remove metabolites from the model of type CoreCoupling and return the modified model.

COBREXA.remove_metabolitesMethod
remove_metabolites(model::CoreCoupling, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type CoreCoupling and return the modified model.

COBREXA.remove_metabolitesMethod
remove_metabolites(model::CoreModel, metabolite_idxs::AbstractVector{Int64})

Remove metabolites from the model of type CoreModel and return the modified model.

COBREXA.remove_metabolitesMethod
remove_metabolites(model::CoreModel, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type CoreModel and return the modified model.

COBREXA.remove_metabolitesMethod
remove_metabolites(model::StandardModel, metabolite_ids::AbstractVector{String})

Remove metabolites from the model of type StandardModel and return the modified model.

COBREXA.remove_reaction!Method
remove_reaction!(model::CoreCoupling, reaction_idx::Int)

Remove reaction from the model of type CoreCoupling in-place.

COBREXA.remove_reaction!Method
remove_reaction!(model::CoreCoupling, reaction_id::String)

Remove reaction from the model of type CoreCoupling in-place.

COBREXA.remove_reaction!Method
remove_reaction!(model::CoreModel, reaction_idx::Int)

Remove reaction from the model of type CoreModel in-place.

COBREXA.remove_reaction!Method
remove_reaction!(model::CoreModel, reaction_id::String)

Remove reaction from the model of type CoreModel in-place.

COBREXA.remove_reaction!Method
remove_reaction!(model::StandardModel, reaction_id::String)

Remove reaction from the model of type StandardModel in-place.

COBREXA.remove_reactionMethod
remove_reaction(model::CoreCoupling, reaction_idx::Int)

Remove reaction from the model of type CoreCoupling and return the modified model.

COBREXA.remove_reactionMethod
remove_reaction(model::CoreCoupling, reaction_id::String)

Remove reaction from the model of type CoreCoupling and return the modified model.

COBREXA.remove_reactionMethod
remove_reaction(model::CoreModel, reaction_idx::Int)

Remove reaction from the model of type CoreModel and return the modified model.

COBREXA.remove_reactionMethod
remove_reaction(model::CoreModel, reaction_id::String)

Remove reaction from the model of type CoreModel and return the modified model.

COBREXA.remove_reactionMethod
remove_reaction(model::StandardModel, reaction_id::String)

Remove reaction from the model of type StandardModel and return the modified model.

COBREXA.remove_reactions!Method
remove_reactions!(model::CoreCoupling, reaction_idxs::AbstractVector{Int64})

Remove reactions from the model of type CoreCoupling in-place.

COBREXA.remove_reactions!Method
remove_reactions!(model::CoreCoupling, reaction_ids::AbstractVector{String})

Remove reactions from the model of type CoreCoupling in-place.

COBREXA.remove_reactions!Method
remove_reactions!(model::CoreModel, reaction_idxs::AbstractVector{Int64})

Remove reactions from the model of type CoreModel in-place.

COBREXA.remove_reactions!Method
remove_reactions!(model::CoreModel, reaction_ids::AbstractVector{String})

Remove reactions from the model of type CoreModel in-place.

COBREXA.remove_reactions!Method
remove_reactions!(model::StandardModel, reaction_ids::AbstractVector{String})

Remove reactions from the model of type StandardModel in-place.

COBREXA.remove_reactionsMethod
remove_reactions(model::CoreCoupling, reaction_idxs::AbstractVector{Int64})

Remove reactions from the model of type CoreCoupling and return the modified model.

COBREXA.remove_reactionsMethod
remove_reactions(model::CoreCoupling, reaction_ids::AbstractVector{String})

Remove reactions from the model of type CoreCoupling and return the modified model.

COBREXA.remove_reactionsMethod
remove_reactions(model::CoreModel, reaction_idxs::AbstractVector{Int64})

Remove reactions from the model of type CoreModel and return the modified model.

COBREXA.remove_reactionsMethod
remove_reactions(model::CoreModel, reaction_ids::AbstractVector{String})

Remove reactions from the model of type CoreModel and return the modified model.

COBREXA.remove_reactionsMethod
remove_reactions(model::StandardModel, reaction_ids::AbstractVector{String})

Remove reactions from the model of type StandardModel and return the modified model.

COBREXA.save_h5_modelMethod
save_h5_model(
    model::MetabolicModel,
    file_name::String
) -> HDF5Model

Converts and writes a metabolic model to disk in the HDF5 format.

Additionally returns an (uncached) HDF5Model that represents the contents of the saved file. Because all HDF5-based models need to be backed by disk storage, writing the data to disk (using this function) is the only way to make new HDF5 models.

COBREXA.save_json_modelMethod
save_json_model(model::MetabolicModel, file_name::String)

Save a JSONModel in model to a JSON file file_name.

In case the model is not JSONModel, it will be converted automatically.

COBREXA.save_mat_modelMethod
save_mat_model(
    model::MetabolicModel,
    file_path::String;
    model_name
)

Save a MATModel in model to a MATLAB file file_name in a format compatible with other MATLAB-based COBRA software.

In case the model is not MATModel, it will be converted automatically.

model_name is the identifier name for the whole model written to the MATLAB file; defaults to just "model".

COBREXA.save_modelMethod
save_model(
    model::MetabolicModel,
    file_name::String;
    extension
) -> Maybe{HDF5Model}

Generic function for saving models that chooses a specific writer function from the extension argument (such as ".xml" for SBML format), or throws an error. By default the extension from file_name is used.

Currently, these model types are supported:

COBREXA.save_sbml_modelMethod
save_sbml_model(model::MetabolicModel, file_name::String)

Write a given SBML model to file_name.

COBREXA.screenMethod
screen(args...; kwargs...)

Take an array of model-modifying function vectors in variants, and execute the function analysis on all variants of the model specified by variants. The computation is distributed over worker IDs in workers. If args are supplied (as an array of the same size as the variants), they are forwarded as arguments to the corresponding analysis function calls.

The array of variants must contain vectors of single-parameter functions, these are applied to model in order. The functions must not modify the model, but rather return a modified copy. The copy should be made as shallow as possible, to increase memory efficiency of the process. Variant generators that modify the argument model in-place will cause unpredictable results. Refer to the definition of screen_variant for details.

The function analysis will receive a single argument (the modified model), together with arguments from args expanded by .... Supply an array of tuples or vectors to pass in multiple arguments to each function. If the argument values should be left intact (not expanded to multiple arguments), they must be wrapped in single-item tuple or vector.

The modification and analysis functions are transferred to workers as-is; all packages required to run them (e.g. the optimization solvers) must be loaded there. Typically, you want to use the macro @everywhere using MyFavoriteSolver from Distributed package for loading the solvers.

Return value

The results of running analysis are collected in to the resulting array, in a way that preserves the shape of the variants, similarly as with pmap.

The results of analysis function must be serializable, preferably made only from pure Julia structures, because they may be transferred over the network between the computation nodes. For that reason, functions that return whole JuMP models that contain pointers to allocated C structures (such as flux_balance_analysis used with GLPK or Gurobi otimizers) will generally not work in this context.

Note: this function is a thin argument-handling wrapper around _screen_impl.

Example

function reverse_reaction(i::Int)
    (model::CoreModel) -> begin
        mod = copy(model)
        mod.S[:,i] .*= -1   # this is unrealistic but sufficient for demonstration
        mod
    end
end

m = load_model(CoreModel, "e_coli_core.xml")

screen(m,
    variants = [
        [reverse_reaction(5)],
        [reverse_reaction(3), reverse_reaction(6)]
    ],
    analysis = mod -> mod.S[:,3])  # observe the changes in S

screen(m,
    variants = [
        [reverse_reaction(5)],
        [reverse_reaction(3), reverse_reaction(6)]
    ],
    analysis = mod -> flux_balance_analysis_vec(mod, GLPK.Optimizer))
COBREXA.screen_optmodel_modificationsMethod
screen_optmodel_modifications(args...; kwargs...)

Screen multiple modifications of the same optimization model.

This function is potentially more efficient than screen because it avoids making variants of the model structure and remaking of the optimization model. On the other hand, modification functions need to keep the optimization model in a recoverable state (one that leaves the model usable for the next modification), which limits the possible spectrum of modifications applied.

Internally, model is distributed to workers and transformed into the optimization model using make_optimization_model. common_modifications are applied to the models at that point. Next, vectors of functions in modifications are consecutively applied, and the result of analysis function called on model are collected to an array of the same extent as modifications. Calls of analysis are optionally supplied with extra arguments from args expanded with ..., just like in screen.

Both the modification functions (in vectors) and the analysis function here have 2 base parameters (as opposed to 1 with screen): first is the model (carried through as-is), second is the prepared JuMP optimization model that may be modified and acted upon. As an example, you can use modification change_constraint and analysis screen_optimize_objective.

Note: This function is a thin argument-handling wrapper around _screen_optmodel_modifications_impl.

COBREXA.screen_variantFunction
screen_variant(
    model::MetabolicModel,
    variant::Vector,
    analysis
) -> Any
screen_variant(
    model::MetabolicModel,
    variant::Vector,
    analysis,
    args
) -> Any

Helper function for screen that applies all single-argument functions in variant to the model (in order from "first" to "last"), and executes analysis on the result.

Can be used to test model variants locally.

COBREXA.screen_variantsMethod
screen_variants(model, variants, analysis; workers) -> Array

A shortcut for screen that only works with model variants.

COBREXA.serialize_modelMethod
serialize_model(
    model::Serialized,
    filename::String
) -> Serialized

Specialization of serialize_model that prevents nested serialization of already-serialized models.

COBREXA.serialize_modelMethod
serialize_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.

COBREXA.set_optmodel_bound!Method
set_optmodel_bound!(vidx, opt_model; lb, ub) -> Bool

Helper function to set the bounds of a variable in the model. Internally calls set_normalized_rhs from JuMP. If the bounds are set to nothing, they will not be changed.

COBREXA.silenceFunction
silence

Modification that disable all output from the JuMP optimizer (shortcut for set_silent from JuMP).

COBREXA.smoment_isozyme_speedMethod
smoment_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_speedMethod
smoment_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.

COBREXA.solved_objective_valueMethod
solved_objective_value(opt_model) -> Union{Nothing, Float64}

Returns the current objective value of a model, if solved.

Example

solved_objective_value(flux_balance_analysis(model, ...))
COBREXA.stoichiometryMethod
stoichiometry(
    a::CoreModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

CoreModel stoichiometry matrix.

COBREXA.stoichiometryMethod
stoichiometry(model::GeckoModel) -> Any

Return a stoichiometry of the GeckoModel. The enzymatic reactions are split into unidirectional forward and reverse ones, each of which may have multiple variants per isozyme.

COBREXA.stoichiometryMethod
stoichiometry(
    model::JSONModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Get the stoichiometry. Assuming the information is stored in reaction object under key .metabolites.

COBREXA.stoichiometryMethod
stoichiometry(m::MATModel) -> Any

Extract the stoichiometry matrix, stored under key S.

COBREXA.stoichiometryMethod
stoichiometry(
    a::MetabolicModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Get the sparse stoichiometry matrix of a model. A feasible solution x of a model m is defined as satisfying the equations:

  • stoichiometry(m) * x .== balance(m)
  • x .>= lbs
  • y .<= ubs
  • `(lbs, ubs) == bounds(m)
COBREXA.stoichiometryMethod
stoichiometry(
    model::SBMLModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Recreate the stoichiometry matrix from the SBMLModel.

COBREXA.stoichiometryMethod
stoichiometry(model::SMomentModel) -> Any

Return a stoichiometry of the SMomentModel. The enzymatic reactions are split into unidirectional forward and reverse ones.

COBREXA.stoichiometryMethod
stoichiometry(
    model::StandardModel
) -> SparseArrays.SparseMatrixCSC{Float64, Int64}

Return the stoichiometric matrix associated with model in sparse format.

COBREXA.stoichiometry_stringMethod
stoichiometry_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.unwrap_modelMethod
unwrap_model(a::ModelWrapper) -> Any

A simple helper to pick the single w

COBREXA.unwrap_modelMethod
unwrap_model(m::Serialized) -> Union{Nothing, M} where M

Unwrap the serialized model (precaching it transparently).

COBREXA.unwrap_serializedMethod
unwrap_serialized(
    model::Serialized
) -> Union{Nothing, M} where M

Returns the model stored in the serialized structure.

COBREXA.update_community_objective!Method
update_community_objective!(
    community::CoreModel,
    objective_id::String,
    objective_mets_weights::Dict{String, Float64}
)

Update the weights for the objective column with id objective_id in community using objective_mets_weights, which maps metabolite ids to weights. The current weights are reset to 0 before being updated to the supplied weights. Note, the weights are negated inside the function so that the objective metabolites are seen as reagents/substrates, NOT products in the reaction equation.

Example

update_community_objective!(model, "community_biomass", Dict("met1"=>1.0, "met2"=>2.0))

See also: add_community_objective!

COBREXA.update_community_objective!Method
update_community_objective!(
    community::StandardModel,
    objective_id::String,
    objective_mets_weights::Dict{String, Float64}
)

Variant of [update_community_objective!] that takes a StandardModel community model as input.

COBREXA.upper_boundsMethod
upper_bounds(model::StandardModel) -> Vector{Float64}

Return the upper bounds for all reactions in model in sparse format. Order matches that of the reaction ids returned in reactions().

COBREXA.verify_consistencyMethod
verify_consistency(
    m::CoreModel,
    Sp::AbstractMatrix{Float64},
    b::AbstractVector{Float64},
    c::AbstractVector{Float64},
    xl::AbstractVector{Float64},
    xu::AbstractVector{Float64},
    names::AbstractVector{String},
    mets::AbstractVector{String},
    new_reactions,
    new_metabolites
) -> Tuple{Any, Any}

Check the consistency of given reactions with existing reactions in m.

TODO: work in progress, doesn't return consistency status.

COBREXA.warmup_from_variabilityFunction
warmup_from_variability(
    model::MetabolicModel,
    optimizer,
    n_points::Int64
) -> Matrix{Float64}
warmup_from_variability(
    model::MetabolicModel,
    optimizer,
    n_points::Int64,
    seed;
    kwargs...
) -> Matrix{Float64}

Generates FVA-like warmup points for samplers, by selecting random points by minimizing and maximizing reactions. Can not return more than 2 times the number of reactions in the model.

COBREXA.warmup_from_variabilityFunction
warmup_from_variability(
    model::MetabolicModel,
    optimizer
) -> Matrix{Float64}
warmup_from_variability(
    model::MetabolicModel,
    optimizer,
    min_reactions::AbstractVector{Int64}
) -> Matrix{Float64}
warmup_from_variability(
    model::MetabolicModel,
    optimizer,
    min_reactions::AbstractVector{Int64},
    max_reactions::AbstractVector{Int64};
    modifications,
    workers
) -> Matrix{Float64}

Generate FVA-like warmup points for samplers, by minimizing and maximizing the specified reactions. The result is returned as a matrix, each point occupies as single column in the result.

!!! warning Limited effect of modifications in warmup_from_variability Modifications of the optimization model applied in modifications parameter that change the semantics of the model have an effect on the warmup points, but do not automatically carry to the subsequent sampling. Users are expected to manually transplant any semantic changes to the actual sampling functions, such as affine_hit_and_run.

COBREXA.with_added_reactionsMethod
with_added_reactions(
    args...;
    kwargs...
) -> COBREXA.var"#448#449"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant with reactions added. Forwards the arguments to add_reactions. Intended to be used with screen.

COBREXA.with_changed_boundMethod
with_changed_bound(
    args...;
    kwargs...
) -> COBREXA.var"#436#437"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant that has a new bound set. Forwards arguments to change_bound. Intended for usage with screen.

COBREXA.with_changed_boundsMethod
with_changed_bounds(
    args...;
    kwargs...
) -> COBREXA.var"#439#440"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant that has new bounds set. Forwards arguments to change_bounds. Intended for usage with screen.

COBREXA.with_geckoMethod
with_gecko(
;
    kwargs...
) -> COBREXA.var"#400#401"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant which adds extra semantics of the Gecko algorithm, giving a GeckoModel. The arguments are forwarded to make_gecko_model. Intended for usage with screen.

COBREXA.with_removed_metaboliteMethod
with_removed_metabolite(
    args...;
    kwargs...
) -> COBREXA.var"#442#443"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant without a certain metabolite. Forwards arguments to remove_metabolite. Intended to be used with screen.

COBREXA.with_removed_reactionMethod
with_removed_reaction(
    args...;
    kwargs...
) -> COBREXA.var"#451#452"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant without a certain reaction. Forwards arguments to remove_reaction. Intended to be used with screen.

COBREXA.with_smomentMethod
with_smoment(
;
    kwargs...
) -> COBREXA.var"#397#398"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}

Specifies a model variant which adds extra semantics of the sMOMENT algorithm, giving a SMomentModel. The arguments are forwarded to make_smoment_model. Intended for usage with screen.

COBREXA.@_is_reaction_fnMacro

@isreactionfn(annoid, identifier)

A helper for creating functions like is_exchange_reaction.

COBREXA.@_make_logging_tagMacro

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".

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).

COBREXA.@add_reactions!Macro

Shortcut to add multiple reactions and their lower and upper bounds

Call variants

@add_reactions! model begin
    reaction_name, reaction
end

@add_reactions! model begin
    reaction_name, reaction, lower_bound
end

@add_reactions! model begin
    reaction_name, reaction, lower_bound, upper_bound
end

Examples

@add_reactions! model begin
    "v1", nothing → A, 0, 500
    "v2", A ↔ B + C, -500
    "v3", B + C → nothing
end