micom.viz

Init file for MICOM Visualization.

Submodules

Package Contents

Classes

Visualization

A visualization object.

Functions

plot_exchanges_per_sample(.strftime[, direction, cluster])

Plot the per sample exchange fluxes.

plot_exchanges_per_taxon(.strftime[, direction, ...])

Plot the exchange fluxes per taxon.

plot_focal_interactions(.strftime, kind)

Plot metabolic interactions between a focal taxa and all other taxa.

plot_mes(.strftime, groups, prevalence)

Plot metabolic interactions between a focal taxa and all other taxa.

plot_association(results, phenotype[, variable_type, ...])

Test for differential metabolite production.

plot_tradeoff(tradeoff_rates[, filename, tolerance])

Plot diagnostics for varying tradeoff values.

class micom.viz.Visualization(filename, data, template)[source]

Bases: object

A visualization object.

filename

The filename of trhe saved visualization.

Type:

str

data

The data used to create the Visualization.

Type:

dict

template

The jinja template used to render the visualization.

Type:

jinja2.Template

view()[source]

Open the visualization in a browser.

Parameters:

None.

Return type:

nothing

save(**kwargs)[source]

Render and and save the visualization.

micom.viz.plot_exchanges_per_sample(results, filename='sample_exchanges_%s.html' % datetime.now().strftime('%Y%m%d'), direction='import', cluster=True) None[source]

Plot the per sample exchange fluxes.

Parameters:
  • results (micom.workflows.GrowthResults) – The results returned by the grow workflow.

  • filename (str) – The HTML file where the visualization will be saved.

  • direction (str either "import" or "export") – The direction of fluxes to plot.

  • cluster (bool) – Whether to reorder samples so that samples with similar exchange fluxes are close to another.

Returns:

A MICOM visualization. Can be served with viz.serve.

Return type:

Visualization

micom.viz.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[source]

Plot the exchange fluxes per taxon.

Parameters:
  • results (micom.workflows.GrowthResults) – The exchanges returned by the grow workflow.

  • filename (str) – The HTML file where the visualization will be saved.

  • direction (str either "import" or "export") – The direction of fluxes to plot.

  • use_total_fluxes (bool) – Whether to use fluxes normalized to 1gDW of bacteria or the total flux.

  • tsne_args (dict) – Additional arguments passed to TSNE.

Returns:

A MICOM visualization. Can be served with viz.serve.

Return type:

Visualization

micom.viz.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[source]

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.

Parameters:
  • results (micom.workflows.GrowthResults) – The results returned by the grow workflow.

  • taxon (str) – The focal taxon to use as a reference. Must be one of the taxa appearing in results.growth_rates.taxon.

  • filename (str) – The HTML file where the visualization will be saved.

  • kind (str) – 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

Returns:

A MICOM visualization. Can be served with viz.serve.

Return type:

Visualization

micom.viz.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[source]

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 = 2cdot

rac{|p||c|}{|p| + |c|}

$$

resultsmicom.workflows.GrowthResults

The results returned by the grow workflow.

filenamestr

The HTML file where the visualization will be saved.

groupspandas.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.

prevalencefloat 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.

The CSV files will always include all MES scores independent of the prevalence filter which is only used for visualization.

Visualization

A MICOM visualization. Can be served with viz.serve.

micom.viz.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)[source]

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.

Parameters:
  • results (micom.workflows.GrowthResults) – The results returned by the grow workflow.

  • phenotype (pandas.Series) – The data to be fitted. Its index must correspond to sample_id in exchanges.

  • variable_type (str of ["binary", "continuous"]) – The type of the variable.

  • variable_name (str) – A short description of the phenotype for instance “disease status”.

  • filename (str) – The HTML file where the visualization will be saved.

  • flux_type (str of ["import", "production"]) – Whether to fit using import or production fluxes.

  • threads (int) – The number of threads to use.

  • fdr_threshold (float) – The false discovery rate cutoff to use (FDR-corrected p-value cutoff). Defaults to 0.05.

  • atol (float) – Tolerance to consider a flux different from zero. Will default to the solver tolerance.

Returns:

A MICOM visualization. Can be served with viz.view.

Return type:

Visualization

micom.viz.plot_tradeoff(tradeoff_rates, filename='tradeoff_%s.html' % datetime.now().strftime('%Y%m%d'), tolerance=1e-06)[source]

Plot diagnostics for varying tradeoff values.

Parameters:
  • tradeoff_rates (pandas.DataFrame) – The growth rates returned by the tradeoff workflow.

  • filename (str) – The HTML file where the visualization will be saved.

  • tolerance (float) – Smallest growth rate that will be considered. Everything lower will be considered not growing.

Returns:

A MICOM visualization. Can be served with viz.serve.

Return type:

Visualization