robustnet.utils =============== .. py:module:: robustnet.utils .. autoapi-nested-parse:: Define utility and helper functions. Attributes ---------- .. autoapisummary:: robustnet.utils.METAB_SEN_PLOT_YLIM robustnet.utils.FLUX_SEN_PLOT_YLIM robustnet.utils.SEN_PLOT_N_BINS Classes ------- .. autoapisummary:: robustnet.utils.FluxFitResults robustnet.utils.NonTCSampleResults robustnet.utils.EnsembleResults robustnet.utils.Prograss Functions --------- .. autoapisummary:: robustnet.utils.read_reaction_file robustnet.utils.read_data_file robustnet.utils.generate_distribution robustnet.utils.plot_sampled_vs_prior_distribution Module Contents --------------- .. py:data:: METAB_SEN_PLOT_YLIM :value: (0.01, 100.0) .. py:data:: FLUX_SEN_PLOT_YLIM :value: (0.5, 1.5) .. py:data:: SEN_PLOT_N_BINS :value: 49 .. py:function:: read_reaction_file(filename) Read reaction information form file. :param filename: 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. :type filename: str .. py:function:: read_data_file(filename, n_dims=2) Read omics data or sampled parameter sets from file. :param filename: 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. :type filename: str .. py:function:: generate_distribution(mean, std, n_samples, varnames, nonneg=True) Generate random values subject to specified normal or truncated normal distribution. :param mean: Mean values with shape ``(n_vars,)``. :type mean: numpy.ndarray :param std: Standard deviations with shape ``(n_vars,)``. :type std: numpy.ndarray :param n_samples: Number of samples to generate. :type n_samples: int :param varnames: Variable names corresponding to the sampled variables. :type varnames: list :param nonneg: If ``True``, constrain sampled values to be nonnegative, i.e., using truncated normal distribution. :type nonneg: bool .. py:function:: plot_sampled_vs_prior_distribution(out_dir, kind, data, xlabel, show_fig, output_data) Plot distribution comparison of sampled versus prior data. :param out_dir: Output directory. :type out_dir: str or None :param kind: Type of variable to plot. :type kind: {'flux', 'metab', 'enz', 'kparam'} :param data: Data used for plotting with columns ``['Prior', 'Sampled']``. :type data: pandas.DataFrame :param xlabel: Label for the x-axis. :type xlabel: str :param show_fig: If ``True``, display the figure. :type show_fig: bool :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool .. py:class:: FluxFitResults(vs, vs_std, opt_obj, dof, v_exp) .. py:attribute:: vs .. py:attribute:: vs_std .. py:attribute:: opt_obj .. py:attribute:: dof .. py:attribute:: v_exp .. py:property:: estimated_fluxes Returns pandas.Series. .. py:property:: estimated_flux_errors Returns pandas.Series or None. .. py:method:: plot_simulated_vs_measured_fluxes(out_dir=None, reactions='all', show_fig=False) Plot simulated versus measured fluxes. :param out_dir: Output directory. :type out_dir: str or None, optional :param reactions: Reactions to plot. If ``all``, all fluxes are plotted. :type reactions: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional .. py:method:: __repr__() .. py:class:: 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) .. py:attribute:: idata .. py:attribute:: posterior .. py:attribute:: v_exp_mu .. py:attribute:: v_exp_sigma .. py:attribute:: k_exp_mu .. py:attribute:: k_exp_sigma .. py:attribute:: x_exp_mu .. py:attribute:: x_exp_sigma .. py:attribute:: e_exp_mu .. py:attribute:: e_exp_sigma .. py:attribute:: rxns .. py:attribute:: kparams .. py:attribute:: metabs .. py:attribute:: enzs .. py:attribute:: sampled_vs .. py:attribute:: sampled_kparams .. py:attribute:: sampled_xs .. py:attribute:: sampled_es .. py:property:: sampled_reference_fluxes returns: Sampled reference fluxe distribution with samples as rows and fluxes as columns. :rtype: pandas.DataFrame .. py:property:: sampled_kinetic_parameters returns: Sampled kinetic parameters with samples as rows and kinetic parameters as columns. :rtype: pandas.DataFrame .. py:property:: sampled_metabolite_concentrations returns: Sampled metabolite concentrations with samples as rows and metabolites as columns. :rtype: pandas.DataFrame .. py:property:: sampled_enzyme_concentrations returns: Sampled enzyme concentrations with samples as rows and enzymes as columns. :rtype: pandas.DataFrame .. py:property:: trace returns: Inference data object containing posterior samples and sampling statistics. :rtype: arviz.InferenceData .. py:method:: plot_sampled_vs_prior_fluxes(out_dir=None, fluxes='all', show_fig=False, output_data=False) Plot sampled versus prior reference flux distribution. :param out_dir: Output directory. :type out_dir: str or None, optional :param fluxes: Fluxes to plot. If ``all``, all fluxes are plotted. :type fluxes: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: plot_sampled_vs_prior_kinetic_parameters(out_dir=None, parameters='all', show_fig=False, output_data=False) Plot sampled versus prior kinetic parameters. :param out_dir: Output directory. :type out_dir: str or None, optional :param parameters: Kinetic parameters to plot. If ``all``, all parameters are plotted. :type parameters: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: plot_sampled_vs_prior_metabolites(out_dir=None, metabolites='all', show_fig=False, output_data=False) Plot sampled versus prior metabolite concentrations. :param out_dir: Output directory. :type out_dir: str or None, optional :param metabolites: Metabolites to plot. If ``all``, all metabolites are plotted. :type metabolites: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: plot_sampled_vs_prior_enzymes(out_dir=None, enzymes='all', show_fig=False, output_data=False) Plot sampled versus prior enzyme concentrations. :param out_dir: Output directory. :type out_dir: str or None, optional :param enzymes: Enzymes to plot. If ``all``, all enzymes are plotted. :type enzymes: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:class:: EnsembleResults(pert_enzs, sim_res, v_sen, stoy_mat, n_steps) .. py:attribute:: pert_enzs .. py:attribute:: sim_res .. py:attribute:: v_sen .. py:attribute:: n_eff_models .. py:attribute:: metabs .. py:attribute:: rxns .. py:attribute:: n_steps .. py:property:: effective_models 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. .. py:method:: _check_simulation_results() Check whether simulation results are empty. .. py:method:: _plot_helper_pert_direction() .. py:method:: _get_robust_model_probability(l_only, r_only) .. py:method:: _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) Helper function to plot sensitivity based on statistics of all results. :param kind: :type kind: {'metab', 'flux'} .. py:method:: _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) Help function to plot sensitivity using sampled results. :param kind: :type kind: {'metab', 'flux'} .. py:method:: _plot_helper_distribution_plot(out_dir, kind, item, r_only, l_only, show_fig, output_data) Help function to plot distribution. :param kind: :type kind: {'metab', 'flux', 'maxeigreal'} .. py:property:: robust_index .. py:method:: robust_model_probability(out_dir=None, show_fig=False, output_data=False) 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. :param out_dir: Output directory. :type out_dir: str or None, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: 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) Plot responses of steady-state metabolite concentrations (relative values, i.e., ``|x| / |x0|``) to enzyme expression perturbations. Equivalent to ``bifurcation_diagram``. :param out_dir: Output directory. :type out_dir: str or None, optional :param kind: Plot type. - ``"stats"``: plot probability distributions of relative concentrations across perturbation levels. - ``"sample"``: plot trajectories from sampled models. :type kind: {"stats", "sample"}, optional :param metabolites: Metabolites to plot. If ``all``, all metabolites are plotted. :type metabolites: list of str, optional :param ylim: Lower and upper y-axis limits. If ``None``, the default range is ``(1e-2, 1e2)`` for relative concentrations. :type ylim: 2-tuple or None, optional :param n_sets: 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"``. :type n_sets: int, optional :param rng_seed: Random seed used for model selection. Valid only when ``kind="sample"``. :type rng_seed: int or None, optional :param n_bins: Number of bins used in statistical summaries of relative concentrations or fluxes. Must be an odd number. Valid only when ``kind="stats"``. :type n_bins: int, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: 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) Plot responses of steady-state metabolite concentrations (relative values, i.e., ``|x| / |x0|``) to enzyme expression perturbations. Equivalent to ``metabolite_sensitivity``. 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. .. py:method:: metabolite_distribution(out_dir=None, metabolites='all', show_fig=False, output_data=False) Plot distributions of metabolite concentrations (absolute values) during enzyme expression perturbations. :param out_dir: Output directory. :type out_dir: str or None, optional :param metabolites: Metabolites to plot. If ``all``, all metabolites are plotted. :type metabolites: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: 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) Plot responses of steady-state fluxes to enzyme expression perturbations. :param out_dir: Output directory. :type out_dir: str or None, optional :param kind: Plot type. - ``"stats"``: plot probability distributions of relative fluxes across perturbation levels. - ``"sample"``: plot trajectories from sampled models. :type kind: {"stats", "sample"}, optional :param reactions: Reactions to plot. If ``all``, all fluxes are plotted. :type reactions: list of str, optional :param ylim: Lower and upper y-axis limits. If ``None``, the default range is ``(0.5, 1.5)`` for relative fluxes. :type ylim: 2-tuple or None, optional :param n_sets: 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"``. :type n_sets: int, optional :param rng_seed: Random seed used for model selection. Valid only when ``kind="sample"``. :type rng_seed: int or None, optional :param n_bins: Number of bins used in statistical summaries of relative concentrations or fluxes. Must be an odd number. Valid only when ``kind="stats"``. :type n_bins: int, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: flux_distribution(out_dir=None, reactions='all', show_fig=False, output_data=False) Plot distributions of reaction fluxes (absolute values) during enzyme expression perturbations. :param out_dir: Output directory. :type out_dir: str or None, optional :param reactions: Reactions to plot. If ``all``, all fluxes are plotted. :type reactions: list of str, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: eigreal_sensitivity(out_dir=None, show_fig=False, output_data=False) Plot the average and median maximum real parts of Jacobian eigenvalues across all models as functions of enzyme perturbation. :param out_dir: Output directory. :type out_dir: str or None, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:method:: eigreal_distribution(out_dir=None, show_fig=False, output_data=False) Plot distributions of the maximum real parts of Jacobian eigenvalues during enzyme perturbations. :param out_dir: Output directory. :type out_dir: str or None, optional :param show_fig: If ``True``, display the figure. :type show_fig: bool, optional :param output_data: If ``True``, export the data used for plotting. Requires ``out_dir`` to be specified. :type output_data: bool, optional .. py:class:: Prograss(mininterval=1, miniters=1, bar_format='{desc}{elapsed}') .. py:attribute:: mininterval :value: 1 .. py:attribute:: miniters :value: 1 .. py:attribute:: bar_format :value: '{desc}{elapsed}' .. py:attribute:: done :value: False .. py:method:: _refresh_pbar(pbar) Refresh pbar every second if not done. .. py:method:: context()