:py:mod:`micom.viz` =================== .. py:module:: micom.viz .. autoapi-nested-parse:: Init file for MICOM Visualization. Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 association/index.rst core/index.rst exchanges/index.rst growth/index.rst interactions/index.rst tradeoff/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: micom.viz.Visualization Functions ~~~~~~~~~ .. autoapisummary:: micom.viz.plot_exchanges_per_sample micom.viz.plot_exchanges_per_taxon micom.viz.plot_focal_interactions micom.viz.plot_mes micom.viz.plot_association micom.viz.plot_tradeoff .. py:class:: Visualization(filename, data, template) Bases: :py:obj:`object` A visualization object. .. attribute:: filename The filename of trhe saved visualization. :type: str .. attribute:: data The data used to create the Visualization. :type: dict .. attribute:: template The jinja template used to render the visualization. :type: jinja2.Template .. py:method:: view() Open the visualization in a browser. :param None.: :rtype: nothing .. py:method:: save(**kwargs) Render and and save the visualization. .. py:function:: plot_exchanges_per_sample(results, filename='sample_exchanges_%s.html' % datetime.now().strftime('%Y%m%d'), direction='import', cluster=True) -> None Plot the per sample exchange fluxes. :param results: The results returned by the `grow` workflow. :type results: micom.workflows.GrowthResults :param filename: The HTML file where the visualization will be saved. :type filename: str :param direction: The direction of fluxes to plot. :type direction: str either "import" or "export" :param cluster: Whether to reorder samples so that samples with similar exchange fluxes are close to another. :type cluster: bool :returns: A MICOM visualization. Can be served with `viz.serve`. :rtype: Visualization .. py:function:: plot_exchanges_per_taxon(results, filename='taxon_exchanges_%s.html' % datetime.now().strftime('%Y%m%d'), direction='import', use_total_flux=False, **tsne_args) -> None Plot the exchange fluxes per taxon. :param results: The exchanges returned by the `grow` workflow. :type results: micom.workflows.GrowthResults :param filename: The HTML file where the visualization will be saved. :type filename: str :param direction: The direction of fluxes to plot. :type direction: str either "import" or "export" :param use_total_fluxes: Whether to use fluxes normalized to 1gDW of bacteria or the total flux. :type use_total_fluxes: bool :param tsne_args: Additional arguments passed to TSNE. :type tsne_args: dict :returns: A MICOM visualization. Can be served with `viz.serve`. :rtype: Visualization .. py:function:: plot_focal_interactions(results: micom.workflows.GrowthResults, taxon: str, filename: str = 'focal_interactions_%s.html' % datetime.now().strftime('%Y%m%d'), kind: str = 'mass') -> None Plot metabolic interactions between a focal taxa and all other taxa. This will visualize metabolic interaction between a taxon of interest (focal taxon) and all other taxa across all samples. :param results: The results returned by the `grow` workflow. :type results: micom.workflows.GrowthResults :param taxon: The focal taxon to use as a reference. Must be one of the taxa appearing in `results.growth_rates.taxon`. :type taxon: str :param filename: The HTML file where the visualization will be saved. :type filename: str :param kind: Which kind of flux to use. Either - "flux": molar flux of a metabolite - "mass" (default): the mass flux (flux normalized by molecular weight) - "C": carbon flux - "N": nitrogen flux :type kind: str :returns: A MICOM visualization. Can be served with `viz.serve`. :rtype: Visualization .. py:function:: plot_mes(results: micom.workflows.GrowthResults, filename: str = 'mes_%s.html' % datetime.now().strftime('%Y%m%d'), groups: pandas.Series = None, prevalence: float = 0.5) -> None Plot metabolic interactions between a focal taxa and all other taxa. This will plot the metabolic exchange score across samples and metabolites. The metabolic exchange score (MES) is defined as the geometric mean of the number of producers and consumers for a given metabolite in a sample. $$ MES = 2\cdot rac{|p||c|}{|p| + |c|} $$ Parameters ---------- results : micom.workflows.GrowthResults The results returned by the `grow` workflow. filename : str The HTML file where the visualization will be saved. groups : pandas.Series Additional metadata to stratify MES score. The index must correspond to the `sample_id` in the results and values must be categorical. The `.name` attribute will be used to name the groups. prevalence : float in [0, 1] In what proportion of samples the metabolite has to have a non-zero MES to be shown on the plots. Can be used to show only very commonly exchanged metabolites. Notes ----- The CSV files will always include all MES scores independent of the prevalence filter which is only used for visualization. Returns ------- Visualization A MICOM visualization. Can be served with `viz.serve`. .. py:function:: plot_association(results, phenotype, variable_type='binary', variable_name='phenotype', filename='association_%s.html' % datetime.now().strftime('%Y%m%d'), flux_type='production', fdr_threshold=0.05, threads=1, atol=1e-06) Test for differential metabolite production. This will check for associations of the `phenotype` with metabolite fluxes. Individual tests are performed using non-parametric tests of the overall consumption or production fluxes for each samples versus the phenotype. To assess the the global association, this will fit L1-regularized linear models with log-fluxes as features. Will use LASSO regression for a continuous response and L1-regularized Logistic regression for a binary response. :param results: The results returned by the `grow` workflow. :type results: micom.workflows.GrowthResults :param phenotype: The data to be fitted. Its index must correspond to `sample_id` in `exchanges`. :type phenotype: pandas.Series :param variable_type: The type of the variable. :type variable_type: str of ["binary", "continuous"] :param variable_name: A short description of the phenotype for instance "disease status". :type variable_name: str :param filename: The HTML file where the visualization will be saved. :type filename: str :param flux_type: Whether to fit using import or production fluxes. :type flux_type: str of ["import", "production"] :param threads: The number of threads to use. :type threads: int :param fdr_threshold: The false discovery rate cutoff to use (FDR-corrected p-value cutoff). Defaults to 0.05. :type fdr_threshold: float :param atol: Tolerance to consider a flux different from zero. Will default to the solver tolerance. :type atol: float :returns: A MICOM visualization. Can be served with `viz.view`. :rtype: Visualization .. py:function:: plot_tradeoff(tradeoff_rates, filename='tradeoff_%s.html' % datetime.now().strftime('%Y%m%d'), tolerance=1e-06) Plot diagnostics for varying tradeoff values. :param tradeoff_rates: The growth rates returned by the `tradeoff` workflow. :type tradeoff_rates: pandas.DataFrame :param filename: The HTML file where the visualization will be saved. :type filename: str :param tolerance: Smallest growth rate that will be considered. Everything lower will be considered not growing. :type tolerance: float :returns: A MICOM visualization. Can be served with `viz.serve`. :rtype: Visualization