robustnet.utils

Define utility and helper functions.

Attributes

METAB_SEN_PLOT_YLIM

FLUX_SEN_PLOT_YLIM

SEN_PLOT_N_BINS

Classes

FluxFitResults

NonTCSampleResults

EnsembleResults

Prograss

Functions

read_reaction_file(filename)

Read reaction information form file.

read_data_file(filename[, n_dims])

Read omics data or sampled parameter sets from file.

generate_distribution(mean, std, n_samples, varnames)

Generate random values subject to specified normal or truncated normal

plot_sampled_vs_prior_distribution(out_dir, kind, ...)

Plot distribution comparison of sampled versus prior data.

Module Contents

robustnet.utils.METAB_SEN_PLOT_YLIM = (0.01, 100.0)[source]
robustnet.utils.FLUX_SEN_PLOT_YLIM = (0.5, 1.5)[source]
robustnet.utils.SEN_PLOT_N_BINS = 49[source]
robustnet.utils.read_reaction_file(filename)[source]

Read reaction information form file.

Parameters:

filename (str) –

File containing reaction information. Supported file formats are .xlsx, .tsv, and .csv.

Required columns are:

  • Reaction: Reaction identifier.

  • Enzyme: Catalytic enzyme.

  • Substrates: Reaction substrates.

  • Products: Reaction products.

  • Rate expression: Reaction rate expression.

robustnet.utils.read_data_file(filename, n_dims=2)[source]

Read omics data or sampled parameter sets from file.

Parameters:

filename (str) –

File containing omics data, or sampled parameter sets. Supported file formats are .xlsx, .tsv, and .csv. Headers are required.

For sampled parameter sets, required columns include set_id and metabolites/influxes/effluxes/kinetic parameters/enzymes. A pandas.DataFrame is returned.

For steady-state omics data, a pandas.Series is returned.

robustnet.utils.generate_distribution(mean, std, n_samples, varnames, nonneg=True)[source]

Generate random values subject to specified normal or truncated normal distribution.

Parameters:
  • mean (numpy.ndarray) – Mean values with shape (n_vars,).

  • std (numpy.ndarray) – Standard deviations with shape (n_vars,).

  • n_samples (int) – Number of samples to generate.

  • varnames (list) – Variable names corresponding to the sampled variables.

  • nonneg (bool) – If True, constrain sampled values to be nonnegative, i.e., using truncated normal distribution.

robustnet.utils.plot_sampled_vs_prior_distribution(out_dir, kind, data, xlabel, show_fig, output_data)[source]

Plot distribution comparison of sampled versus prior data.

Parameters:
  • out_dir (str or None) – Output directory.

  • kind ({'flux', 'metab', 'enz', 'kparam'}) – Type of variable to plot.

  • data (pandas.DataFrame) – Data used for plotting with columns ['Prior', 'Sampled'].

  • xlabel (str) – Label for the x-axis.

  • show_fig (bool) – If True, display the figure.

  • output_data (bool) – If True, export the data used for plotting. Requires out_dir to be specified.

class robustnet.utils.FluxFitResults(vs, vs_std, opt_obj, dof, v_exp)[source]
vs[source]
vs_std[source]
opt_obj[source]
dof[source]
v_exp[source]
property estimated_fluxes[source]

Returns pandas.Series.

property estimated_flux_errors[source]

Returns pandas.Series or None.

plot_simulated_vs_measured_fluxes(out_dir=None, reactions='all', show_fig=False)[source]

Plot simulated versus measured fluxes.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • reactions (list of str, optional) – Reactions to plot. If all, all fluxes are plotted.

  • show_fig (bool, optional) – If True, display the figure.

__repr__()[source]
class robustnet.utils.NonTCSampleResults(idata, v_exp_mu, v_exp_sigma, k_exp_mu, k_exp_sigma, x_exp_mu, x_exp_sigma, e_exp_mu, e_exp_sigma)[source]
idata[source]
posterior[source]
v_exp_mu[source]
v_exp_sigma[source]
k_exp_mu[source]
k_exp_sigma[source]
x_exp_mu[source]
x_exp_sigma[source]
e_exp_mu[source]
e_exp_sigma[source]
rxns[source]
kparams[source]
metabs[source]
enzs[source]
sampled_vs[source]
sampled_kparams[source]
sampled_xs[source]
sampled_es[source]
property sampled_reference_fluxes[source]
returns: Sampled reference fluxe distribution with samples as rows and fluxes

as columns.

Return type:

pandas.DataFrame

property sampled_kinetic_parameters[source]
returns: Sampled kinetic parameters with samples as rows and kinetic

parameters as columns.

Return type:

pandas.DataFrame

property sampled_metabolite_concentrations[source]
returns: Sampled metabolite concentrations with samples as rows and

metabolites as columns.

Return type:

pandas.DataFrame

property sampled_enzyme_concentrations[source]
returns: Sampled enzyme concentrations with samples as rows and enzymes

as columns.

Return type:

pandas.DataFrame

property trace[source]
returns: Inference data object containing posterior samples and sampling

statistics.

Return type:

arviz.InferenceData

plot_sampled_vs_prior_fluxes(out_dir=None, fluxes='all', show_fig=False, output_data=False)[source]

Plot sampled versus prior reference flux distribution.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • fluxes (list of str, optional) – Fluxes to plot. If all, all fluxes are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

plot_sampled_vs_prior_kinetic_parameters(out_dir=None, parameters='all', show_fig=False, output_data=False)[source]

Plot sampled versus prior kinetic parameters.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • parameters (list of str, optional) – Kinetic parameters to plot. If all, all parameters are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

plot_sampled_vs_prior_metabolites(out_dir=None, metabolites='all', show_fig=False, output_data=False)[source]

Plot sampled versus prior metabolite concentrations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • metabolites (list of str, optional) – Metabolites to plot. If all, all metabolites are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

plot_sampled_vs_prior_enzymes(out_dir=None, enzymes='all', show_fig=False, output_data=False)[source]

Plot sampled versus prior enzyme concentrations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • enzymes (list of str, optional) – Enzymes to plot. If all, all enzymes are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

class robustnet.utils.EnsembleResults(pert_enzs, sim_res, v_sen, stoy_mat, n_steps)[source]
pert_enzs[source]
sim_res[source]
v_sen[source]
n_eff_models[source]
metabs[source]
rxns[source]
n_steps[source]
property effective_models[source]

Return indices of models that remain valid before perturbation and at the first perturbation step.

These indices also correspond to the loaded parameter sets, including metabolite concentrations, enzyme concentrations, kinetic parameters, and influxes or effluxes if available.

A small number of valid models may lead to biased simulation results. In such cases, consider increasing n_models or n_steps in evaluate_robustness, or generating additional parameter sets.

_check_simulation_results()[source]

Check whether simulation results are empty.

_plot_helper_pert_direction()[source]
_get_robust_model_probability(l_only, r_only)[source]
_plot_helper_sensitivity_stats_plot(out_dir, kind, item, l_only, r_only, xticks, xticklabels, xlabel, suffix, indices, ylim, n_bins, show_fig, output_data)[source]

Helper function to plot sensitivity based on statistics of all results.

Parameters:

kind ({'metab', 'flux'})

_plot_helper_sensitivity_sample_plot(out_dir, kind, item, l_only, r_only, xticks, xticklabels, xlabel, suffix, indices, ylim, n_bins, show_fig, output_data)[source]

Help function to plot sensitivity using sampled results.

Parameters:

kind ({'metab', 'flux'})

_plot_helper_distribution_plot(out_dir, kind, item, r_only, l_only, show_fig, output_data)[source]

Help function to plot distribution.

Parameters:

kind ({'metab', 'flux', 'maxeigreal'})

property robust_index[source]
robust_model_probability(out_dir=None, show_fig=False, output_data=False)[source]

Plot the probability of robust models as a function of enzyme perturbation.

The normalized area under the curve (norm AUC), ranging from 0 to 1, is used as a robustness metric. Higher norm AUC values indicate greater robustness against the specified perturbation strategy.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

metabolite_sensitivity(out_dir=None, kind='stats', metabolites='all', ylim=None, n_sets=100, rng_seed=None, n_bins=49, show_fig=False, output_data=False)[source]

Plot responses of steady-state metabolite concentrations (relative values, i.e., |x| / |x0|) to enzyme expression perturbations.

Equivalent to bifurcation_diagram.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • kind ({"stats", "sample"}, optional) – Plot type. - "stats": plot probability distributions of relative concentrations across perturbation levels. - "sample": plot trajectories from sampled models.

  • metabolites (list of str, optional) – Metabolites to plot. If all, all metabolites are plotted.

  • ylim (2-tuple or None, optional) –

    Lower and upper y-axis limits. If None, the default range is

    (1e-2, 1e2) for relative concentrations.

  • n_sets (int, optional) –

    Number of sampled model sets used for plotting.

    If n_sets does not exceed the total number of sets, models are randomly selected. Otherwise, all sets are used.

    Valid only when kind="sample".

  • rng_seed (int or None, optional) –

    Random seed used for model selection.

    Valid only when kind="sample".

  • n_bins (int, optional) –

    Number of bins used in statistical summaries of relative concentrations or fluxes.

    Must be an odd number.

    Valid only when kind="stats".

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

bifurcation_diagram(out_dir=None, kind='stats', metabolites='all', ylim=None, n_sets=100, rng_seed=None, n_bins=49, show_fig=False, output_data=False)[source]
Plot responses of steady-state metabolite concentrations

(relative values, i.e., |x| / |x0|) to enzyme expression perturbations.

Equivalent to metabolite_sensitivity.

out_dirstr or None, optional

Output directory.

kind: {“stats”, “sample”}, optional

Plot type. - "stats": plot probability distributions of relative concentrations across perturbation levels. - "sample": plot trajectories from sampled models.

metaboliteslist of str, optional

Metabolites to plot. If all, all metabolites are plotted.

ylim2-tuple or None, optional
Lower and upper y-axis limits. If None, the default range is

(1e-2, 1e2) for relative concentrations.

n_setsint, optional

Number of sampled model sets used for plotting.

If n_sets does not exceed the total number of sets, models are randomly selected. Otherwise, all sets are used.

Valid only when kind="sample".

rng_seedint or None, optional

Random seed used for model selection.

Valid only when kind="sample".

n_binsint, optional

Number of bins used in statistical summaries of relative concentrations or fluxes.

Must be an odd number.

Valid only when kind="stats".

show_figbool, optional

If True, display the figure.

output_databool, optional

If True, export the data used for plotting. Requires out_dir to be specified.

metabolite_distribution(out_dir=None, metabolites='all', show_fig=False, output_data=False)[source]

Plot distributions of metabolite concentrations (absolute values) during enzyme expression perturbations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • metabolites (list of str, optional) – Metabolites to plot. If all, all metabolites are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

flux_sensitivity(out_dir=None, kind='stats', reactions='all', ylim=None, n_sets=100, rng_seed=None, n_bins=49, show_fig=False, output_data=False)[source]

Plot responses of steady-state fluxes to enzyme expression perturbations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • kind ({"stats", "sample"}, optional) – Plot type. - "stats": plot probability distributions of relative fluxes across perturbation levels. - "sample": plot trajectories from sampled models.

  • reactions (list of str, optional) – Reactions to plot. If all, all fluxes are plotted.

  • ylim (2-tuple or None, optional) – Lower and upper y-axis limits. If None, the default range is (0.5, 1.5) for relative fluxes.

  • n_sets (int, optional) –

    Number of sampled model sets used for plotting.

    If n_sets does not exceed the total number of sets, models are randomly selected. Otherwise, all sets are used.

    Valid only when kind="sample".

  • rng_seed (int or None, optional) –

    Random seed used for model selection.

    Valid only when kind="sample".

  • n_bins (int, optional) –

    Number of bins used in statistical summaries of relative concentrations or fluxes.

    Must be an odd number.

    Valid only when kind="stats".

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

flux_distribution(out_dir=None, reactions='all', show_fig=False, output_data=False)[source]

Plot distributions of reaction fluxes (absolute values) during enzyme expression perturbations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • reactions (list of str, optional) – Reactions to plot. If all, all fluxes are plotted.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

eigreal_sensitivity(out_dir=None, show_fig=False, output_data=False)[source]

Plot the average and median maximum real parts of Jacobian eigenvalues across all models as functions of enzyme perturbation.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

eigreal_distribution(out_dir=None, show_fig=False, output_data=False)[source]

Plot distributions of the maximum real parts of Jacobian eigenvalues during enzyme perturbations.

Parameters:
  • out_dir (str or None, optional) – Output directory.

  • show_fig (bool, optional) – If True, display the figure.

  • output_data (bool, optional) – If True, export the data used for plotting. Requires out_dir to be specified.

class robustnet.utils.Prograss(mininterval=1, miniters=1, bar_format='{desc}{elapsed}')[source]
mininterval = 1[source]
miniters = 1[source]
bar_format = '{desc}{elapsed}'[source]
done = False[source]
_refresh_pbar(pbar)[source]

Refresh pbar every second if not done.

context()[source]