robustnet.utils¶
Define utility and helper functions.
Attributes¶
Classes¶
Functions¶
|
Read reaction information form file. |
|
Read omics data or sampled parameter sets from file. |
|
Generate random values subject to specified normal or truncated normal |
|
Plot distribution comparison of sampled versus prior data. |
Module Contents¶
- 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_idand metabolites/influxes/effluxes/kinetic parameters/enzymes. Apandas.DataFrameis returned.For steady-state omics data, a
pandas.Seriesis 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. Requiresout_dirto be specified.
- class robustnet.utils.FluxFitResults(vs, vs_std, opt_obj, dof, v_exp)[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]¶
-
- property sampled_reference_fluxes[source]¶
- returns: Sampled reference fluxe distribution with samples as rows and fluxes
as columns.
- Return type:
- property sampled_kinetic_parameters[source]¶
- returns: Sampled kinetic parameters with samples as rows and kinetic
parameters as columns.
- Return type:
- property sampled_metabolite_concentrations[source]¶
- returns: Sampled metabolite concentrations with samples as rows and
metabolites as columns.
- Return type:
- property sampled_enzyme_concentrations[source]¶
- returns: Sampled enzyme concentrations with samples as rows and enzymes
as columns.
- Return type:
- 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:
- 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. Requiresout_dirto 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. Requiresout_dirto 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. Requiresout_dirto be specified.
- class robustnet.utils.EnsembleResults(pert_enzs, sim_res, v_sen, stoy_mat, 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_modelsorn_stepsinevaluate_robustness, or generating additional parameter sets.
- _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'})
- 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.
- 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.
- Lower and upper y-axis limits. If
n_sets (int, optional) –
Number of sampled model sets used for plotting.
If
n_setsdoes 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. Requiresout_dirto 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.
- Lower and upper y-axis limits. If
- n_setsint, optional
Number of sampled model sets used for plotting.
If
n_setsdoes 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. Requiresout_dirto 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. Requiresout_dirto 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_setsdoes 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. Requiresout_dirto 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. Requiresout_dirto 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.