micom.viz.interactions

Visualizations for interactions.

Attributes

Classes

Visualization

A visualization object.

Functions

interactions(→ pandas.DataFrame)

Quantify interactions of a focal/reference taxon with other taxa.

summarize_interactions(→ pandas.DataFrame)

Summarize interactions to key quantities.

MES(→ pandas.DataFrame)

Calculate the Metabolic Exchange Score (MES) for each metabolite.

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.

Module Contents

micom.viz.interactions.interactions(results: micom.workflows.GrowthResults, taxa: None | str | List[str], threads: int = 1, progress: bool = True) pandas.DataFrame[source]

Quantify interactions of a focal/reference taxon with other taxa.

Parameters:
  • results (GrowthResults) – The growth results to use.

  • taxa (str, list of str, or None) – The focal taxa to use. Can be a single taxon, a list of taxa or None in which case all taxa are considered.

Returns:

The mapped interactions between the focal taxon and all other taxa.

Return type:

pandas.DataFrame

micom.viz.interactions.summarize_interactions(ints: pandas.DataFrame) pandas.DataFrame[source]

Summarize interactions to key quantities.

Parameters:

ints (pandas.DataFrame) – The interactions for individual metabolites calculated before.

Returns:

The summarized interactions contaning the total flux, mass flux, carbon flux, nitrogen flux and number of interactions between any pair of taxa in that sample.

Return type:

pandas.DataFrame

micom.viz.interactions.MES(results: micom.workflows.GrowthResults, cutoff: float = None) pandas.DataFrame[source]

Calculate the Metabolic Exchange Score (MES) for each metabolite.

MES is the harmonic mean of producers and consumers for a chosen metabolite in one sample. High values indicate a large prevalence of cross-feeding for the particular metabolite. A value of zero indicates an absence of cross-feeding for the particular metabolite.

Parameters:
  • results (GrowthResults) – The growth results to use.

  • cutoff (float) – The smallest flux to consider in the analysis. Will default to the solver tolerance if set to None.

Returns:

The scores for each metabolite and each sample including metabolite annotations.

Return type:

pandas.DataFrame

References

micom.viz.interactions.logger[source]
micom.viz.interactions.GrowthResults[source]
class micom.viz.interactions.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.interactions.UNITS[source]
micom.viz.interactions.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.interactions.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.