robustnet.model¶
Define Model class.
Classes¶
Module Contents¶
- class robustnet.model.Model(name=None)[source]¶
-
- _parse_expression(rxn, expr_str, enzymes, metabolites)[source]¶
Parse a reaction rate expression.
- Parameters:
- Returns:
ratelaw – Parsed reaction rate information with the following fields:
enz(str or None): Enzyme variable.metabs(list of str): Sorted metabolite variables.kparams(list of str): Sorted kinetic parameter variables.expr: Symbolic expression of the reaction rate.
- Return type:
namedtuple
- _update_model()[source]¶
Update reaction information in the model. Variables appearing in the rate expression that are not identified as enzymes, substrates, or products are treated as kinetic parameters.
- read_from_file(filename)[source]¶
Read reaction information from a file. Previously imported reactions with the same reaction ID will be overwritten.
- Parameters:
filename (str) –
Path to the input file containing reaction information. Supported file formats are
.xlsx,.tsv, and.csv.The input file must contain the following columns:
Reaction: Reaction ID.Enzyme: Catalytic enzyme associated with the reaction. Leave empty if the reaction is non-enzymatic.Substrates: Reaction substrates separated by+. Spaces between metabolite names are allowed. Metabolite names cannot start with a number, but may contain-and_. Metabolite names must not overlap with enzyme names.Products: Reaction products separated by+. Spaces between metabolite names are allowed. Metabolite names cannot start with a number, but may contain-and_. Metabolite names must not overlap with enzyme names.Rate expression: Mathematical expression defining the reaction rate. Enzyme and metabolite names must be consistent with those provided in theEnzyme,Substrates, andProductscolumns. Any additional variables appearing in the expression are treated as kinetic parameters. Both reversible and irreversible reactions are supported. Spaces in the expression are allowed.
- add_reaction(name=None, enzyme=None, substrates=None, products=None, rate_expression=None)[source]¶
Add reaction information into the model. Previously imported reactions with the same reaction ID will be overwritten.
- Parameters:
name (str, optional) – reaction ID.
enzyme (str or None, optional) – Catalytic enzyme associated with the reaction. Use
Nonefor non-enzymatic reactions.substrates (dict or None, optional) – Dictionary mapping substrate metabolite IDs to stoichiometric coefficients. Metabolite names cannot start with a number, but may contain
-and_. Metabolite names must not overlap with enzyme names. UseNoneif the reaction has no substrates.products (dict or None, optional) – Dictionary mapping product metabolite IDs to stoichiometric coefficients. Metabolite names cannot start with a number, but may contain
-and_. Metabolite names must not overlap with enzyme names. UseNoneif the reaction has no products.rate_expression (str or None, optional) – Mathematical expression defining the reaction rate. Enzyme and metabolite names must be consistent with those used in the
enzyme,substrates, andproductsarguments. Any additional variables in the expression are treated as kinetic parameters. Spaces in the expression are allowed.
- static _make_stoichiometric_matrix(reaction_info, metabolites, reactions, exclude=None)[source]¶
Build the stoichiometric matrix from reaction information.
- Parameters:
reaction_info (dict) – Dictionary of reactions in the format
{reaction_id: Reaction_namedtuple}.metabolites (tuple or list) – Metabolite IDs defining the matrix rows.
reactions (tuple or list) – Reaction IDs defining the matrix columns.
exclude (tuple, list or None, optional) – Metabolites to exclude from the stoichiometric matrix.
- stoichiometric_matrix(exclude=None)[source]¶
Compute the stoichiometric matrix, where rows correspond to metabolites and columns correspond to reactions.
- Parameters:
exclude (list, optional) – Metabolites to exclude from the stoichiometric matrix.
- initial_substrates(exclude=None)[source]¶
Get the initial substrates of the model. Initial substrates are metabolites that participate in only one consuming reaction and are not produced by any reaction.
- Parameters:
exclude (list, optional) – Metabolites to exclude from the stoichiometric matrix and, consequently, from the returned initial substrate list.
- final_products(exclude=None)[source]¶
Get the final products of the model. Final products are metabolites that participate in only one producing reaction and are not consumed by any reaction.
- Parameters:
exclude (list, optional) – Metabolites to exclude from the stoichiometric matrix and, consequently, from the returned final product list.
- load_priors(kind, data, std=None)[source]¶
Metabolomics and proteomics data are expected in units of mM, while fluxomics data are expected in units of mmol/L/s. For kinetic parameters, catalytic constants have units of 1/s, Michaelis, activation, and inhibition constants have units of mM, and equilibrium constants are dimensionless. All concentration and flux units are assumed to be cell-volume based. Missing values are allowed and may be indicated by
"nan","na", or blank entries in the input file.- Parameters:
kind ({"metabolomics", "proteomics", "fluxomics", "reference_fluxes",) – “kparameters”} Type of prior measurement data.
data (file or pandas.Series) – Prior measurements. File names must end with
.xlsx,.tsv, or.csv. The input file with headers must contain species name and its measurement in each row. Alternatively, apandas.Seriescan be provided.std (file or pandas.Series, optional) – Standard deviations of prior measurements. File names must end with
.xlsx,.tsv, or.csv. The input file with headers must contain species name and its measurement in each row. Alternatively, apandas.Seriescan be provided. The shape ofstdmust match that ofdata. UseNoneif uncertainty information is unavailable.
- estimate_reference_fluxes(bounds, exclude_metabolites=None, optimizer='scipy', method='COBYQA', tol=0.0001)[source]¶
Estimate the reference flux distribution by fitting measured fluxes (e.g., from 13C fluxomics) using least-squares regression.
Fluxes are expected in units of mmol/L/s with cell-based volumes.
Note that it is recommended to run the optimization multiple times to improve the chance of obtaining a solution with minimal SSR.
- Parameters:
bounds (2-tuple or dict of 2-tuples) –
Lower and upper bounds used during fitting. If a tuple is provided, the same bounds are applied to all fluxes. If a dict is provided, bounds can be specified for individual fluxes, which is useful for defining flux reversibility. For example, Setting
lower_bound >= 0orupper_bound <= 0enforces irreversibility in the forward or reverse direction, respectively.Fluxes without explicit bounds use the minimum lower bound and maximum upper bound from the provided bounds.
exclude_metabolites (list of str or None, optional) –
Metabolites excluded from steady-state mass balance constraints, such as initial substrates and final products. If
None, these metabolites are inferred automatically from the stoichiometric matrix.Because inferred initial substrates and final products depend on reaction direction definitions, explicitly specifying this argument is recommended.
optimizer ({"scipy", "nlopt"}, optional) – Optimizer used to solve the fitting problem. The NLopt package must be installed if
optimizer="nlopt"is selected.method ({"COBYQA", "SLSQP"}, optional) –
optimization method.
COBYQAis gradient-free and generally more robust for non-smooth problems, but may be slower.SLSQPis gradient-based and typically faster, but may struggle with highly nonlinear problems.Currently,
COBYQAis only available whenoptimizer="scipy".tol (float, optional) – Tolerance criterion for optimization convergence.
- Returns:
res – Object containing the estimated reference flux distribution.
Important attributes and methods include:
estimated_fluxes: Estimated reference flux distribution.estimated_flux_errors: Estimated errors in the reference flux distribution.plot_simulated_vs_measured_fluxes: Visualize simulated versus measured fluxes.
- Return type:
- generate_parameter_sets(ref_flux_mu=None, kparam_prior_mu=None, mconc_prior_mu=None, econc_prior_mu=None, ref_flux_sigma=None, kparam_prior_sigma=None, mconc_prior_sigma=None, econc_prior_sigma=None, ref_flux_initvalues=None, kparam_initvalues=None, mconc_initvalues=None, econc_initvalues=None, exclude_metabolites=None, alpha=None, n_tunes=5000, n_samples=2000, n_chains=10, n_jobs=1)[source]¶
Sample model parameters based on prior knowledge of reference fluxes, metabolite concentrations, enzyme concentrations and enzyme kinetic parameters, which can be collected from omics data and enzyme database. Missing values are allowed.
Prior measurements can be provided directly through the corresponding arguments or loaded beforehand using
load_priors. Directly supplied arguments take precedence over loaded priors.- Parameters:
ref_flux_mu (dict, pandas.Series or None) – Reference-state flux distribution in units of mmol/L/s (cell-based). Typically obtained from
estimate_reference_fluxes. IfNone, reference fluxes loaded byload_priorsare used.kparam_prior_mu (dict, pandas.Series or None) – Mean values of the prior distributions for kinetic parameters. Catalytic constants have units of 1/s, Michaelis, activation, and inhibition constants have units of mM, and equilibrium constants are dimensionless. Missing kinetic parameters are allowed. If
None, kinetic parameters loaded byload_priorsare used.mconc_prior_mu (dict, pandas.Series, or None) – Mean values of prior metabolite concentrations in mM (cell-based). Missing metabolites are allowed. If
None, metabolomics data loaded byload_priorsare used.econc_prior_mu (dict, pandas.Series, or None) – Mean values of prior enzyme concentrations in mM (cell-based). Missing enzymes are allowed. If
None, proteomics data loaded byload_priorsare used.ref_flux_sigma (scalar, dict, pandas.Series, or None, optional) – Standard deviations of reference-state fluxes. If a scalar is provided, the same value is used for all fluxes. Missing flux values are allowed when using a dict or
pandas.Series. Typically obtained fromestimate_reference_fluxes. IfNone, standard deviations from reference fluxes loaded byload_priorsare used. Defaults to0.01.kparam_prior_sigma (scalar, dict, pandas.Series, or None, optional) – Standard deviations of kinetic parameters. If a scalar is provided, the same value is used for all parameters. Missing parameter values are allowed. If
None, standard deviations from kinetic parameters loaded byload_priorsare used. Default to0.1.mconc_prior_sigma (scalar, dict, pandas.Series, or None, optional) – Standard deviations of metabolite concentrations. If a scalar is provided, the same value is used for all metabolites. Missing metabolite values are allowed. If
None, standard deviations from metabolomics data loaded byload_priorsare used. Default to0.1.econc_prior_sigma (scalar, dict, pandas.Series, or None, optional) – Standard deviations of enzyme concentrations. If a scalar is provided, the same value is used for all enzymes. Missing enzyme values are allowed. If
None, standard deviations from proteomics data loaded byload_priorsare used. Default to0.001.ref_flux_initvalues (dict, pandas.Series, or None, optional) – Initial values for reference flux sampling. Missing fluxes are allowed. If
None,ref_flux_muis used.kparam_initvalues (dict, pandas.Series, or None, optional) – Initial values for kinetic parameter sampling. Missing parameter values are allowed. If
None,kparam_prior_muis used.mconc_initvalues (dict, pandas.Series, or None, optional) – Initial values for metabolite concentration sampling. Missing metabolite values are allowed. If
None,mconc_prior_muis used.econc_initvalues (dict, pandas.Series, or None, optional) – Initial values for enzyme concentration sampling. Missing enzyme values are allowed. If
None,econc_prior_muis used.exclude_metabolites (list of str or None, optional) – Reserved argument. Currently unused.
alpha (float or None, optional) –
Gaussian penalty strength used in parameter balancing. Larger values impose stronger penalties in log-posterior space.
A reasonable choice is often on the same order of magnitude as
1 / ref_flux_sigma**2. IfNone,geomean(1 / ref_flux_sigma**2)is used.Excessively large values of
alphamay produce sparse or discontinuous samples and significantly reduce the number of effective models in robustness analysis.n_tunes (int, optional) – Number of tuning iterations performed before sampling in each chain.
n_samples (int, optional) – Number of samples drawn in each chain.
n_chains (int, optional) – Number of sampling chains.
n_jobs (int, optional) – Number of parallel jobs to run in parallel. For Windows platforms,
n_jobsis forced to1for compatibility reasons.
- Returns:
res – Object containing the sampled parameter sets.
Important attributes and methods include:
sampled_reference_fluxes: Sampled reference flux distributions.sampled_kinetic_parameters: Sampled kinetic parameters.sampled_metabolite_concentrations: Sampled metabolite concentrations.sampled_enzyme_concentrations: Sampled enzyme concentrations.trace:arviz.InferenceDataobject containing the sampling trace.plot_sampled_vs_prior_fluxes: Visualize sampled versus prior reference fluxes.plot_sampled_vs_prior_kinetic_parameters: Visualize sampledversus prior kinetic parameters.
plot_sampled_vs_prior_metabolites: Visualize sampled versus prior metabolite concentrations.plot_sampled_vs_prior_enzymes: Visualize sampled versus prior enzyme concentrations.
- Return type:
- load_parameter_sets(mconc_set, econc_set, kparam_set)[source]¶
Load sampled parameter sets for robustness analysis.
Sampled parameter sets must be mutually compatible by index. For example, the
i-th sampled metabolite concentration set must correspond to thei-th sampled kinetic parameter set and enzyme concentration set.- Parameters:
mconc_set (file or pandas.DataFrame) – Sampled metabolite concentration sets. File names must end with
.xlsx,.tsv, or.csv. Columns correspond to metabolites. Alternatively, apandas.DataFramecan be provided.econc_set (file or pandas.DataFrame) – Sampled enzyme concentration sets. File names must end with
.xlsx,.tsv, or.csv. Columns correspond to enzymes. Alternatively, apandas.DataFramecan be provided.kparam_set (file or pandas.DataFrame) –
Sampled kinetic parameter sets. File names must end with
.xlsx,.tsv, or.csv. Columns correspond to kinetic parameters. Alternatively, apandas.DataFramecan be provided.Note that some metabolites may be treated as kinetic parameters if they only appear in reaction rate expressions. These metabolites must therefore also be included in the kinetic parameter sets.
- evaluate_robustness(perturb_enzymes='all', fold_change=(0.2, 5), exclude_metabolites=None, n_steps=200, log_spacing=False, n_models=1000, n_jobs=1, flux_sensitivity=True, check_jacobian=True, check_metabolite=True)[source]¶
Simulate perturbation responses and evaluate the robustness of the metabolic system with respect to enzyme expression perturbations.
- Parameters:
perturb_enzymes (list of str or "all", optional) – Enzymes to perturb simultaneously over their specified expression ranges. If
"all", all enzymes in the model are perturbed.fold_change (2-tuple or dict, optional) –
Relative perturbation bounds for enzyme concentrations, defined as fold changes with respect to the reference state.
The fold-change interval must always include
1(the reference state). Perturbations are simulated from the reference state toward both left and right bounds. For example,(0.1, 10)and(10, 0.1)both indicate simulations from1 → 0.1and1 → 10.If one bound equals
1, perturbation is only performed in one direction. For example,(1, 50)and(50, 1)both indicate perturbation from1 → 50.If a dict is provided, fold-change ranges can be assigned individually to enzymes. This allows coordinated or opposed regulation patterns. For example,
{"A": (0.1, 10), "B": (50, 0.5)}indicates that in the left direction enzyme A is perturbed from1 -> 0.1while enzyme B is perturbed simultaneously from1 -> 50, whereas in the right direction enzyme A is perturbed from1 -> 10while enzyme B is perturbed simultaneously from1 -> 0.5.{"A": (1, 10), "B": (1, 50)}represents co-overexpression of enzyme A and B, whereas{"A": (1, 10), "B": (0.5, 1)}represents simultaneous overexperssion of enzyme A and downregulation of enzyme B.Enzymes without explicitly assigned ranges use the default fold-change range
(0.2, 5).Enzymes specified in
fold_changebut not explicitly listed inperturb_enzymesare still perturbed if their names are valid.This argument can also be used when
perturb_enzymes="all". In this case, specified fold-change ranges override the default values.exclude_metabolites (list of str or None, optional) – Metabolites excluded from the analysis. Excluded metabolites are not included in the ODE system.
n_steps (int, optional) –
Number of perturbation steps in each direction. If perturbation is performed in both directions,
2 * n_stepstotal steps are applied.Large fold changes may cause model failure at early perturbation steps, resulting in no effective models. Increasing
n_stepsmay improve stability in such cases.log_spacing (bool, optional) – If
True, perturbation points are logarithmically spaced. Otherwise, they are evenly spaced.n_models (int, optional) –
Number of sampled models used in the simulation. Increasing this value may improve consensus robustness estimates.
The maximum number of models is limited by the number of loaded parameter sets.
n_jobs (int, optional) – Number of parallel jobs.
flux_sensitivity (bool, optional) – If
True, derivatives of steady-state fluxes with respect to enzyme concentrations are also computed.check_jacobian (bool, optional) – If
True, verify that all eigenvalues of the Jacobian matrix have negative real parts.check_metabolite (bool, optional) – If
True, enforce positive metabolite concentrations during analysis.
- Returns:
res – Object containing robustness analysis results.
Important attributes and methods include:
robust_index: Robustness index under the specified perturbation condition.robust_model_probability: Plot the probability of models remaining robust across perturbations.metabolite_sensitivity: Plot metabolite concentration responses across perturbations.bifurcation_diagram: Alias formetabolite_sensitivity.metabolite_distribution: Plot distributions of metabolite concentrations during perturbations.flux_sensitivity: Plot steady-state flux responses across perturbations. Available only whenflux_sensitivity=True.flux_distribution: Plot distributions of steady-state fluxes during perturbations. Available only whenflux_sensitivity=True.eigreal_sensitivity: Plot responses of the maximum real part of Jacobian eigenvalues across perturbations.eigreal_distribution: Plot distributions of the maximum real part of Jacobian eigenvalues during perturbations.
- Return type: