tacco.plots.heatmap

heatmap(adata, value_key, group_key, basis_adata=None, basis_value_key=None, basis_group_key=None, fillna=None, restrict_groups=None, restrict_values=None, basis_restrict_groups=None, basis_restrict_values=None, reduction='sum', normalization=None, assume_counts=None, reads=False, colors=None, alpha=None, axsize=None, axes_labels=None, annotation=None, value_cluster=False, group_cluster=False, value_dendrogram=False, group_dendrogram=False, value_order=None, group_order=None, group_labels_rotation=None, ax=None, cmap=None, cmap_center=0, cmap_vmin_vmax=None, complement_colors=True, colorbar=True, colorbar_label=None)[source]

Plot heatmap of contribution to groups.

Parameters:
  • adata – An AnnData with annotation in .obs. Can also be a DataFrame with the data to show in the heatmap. In the latter case all adata processing arguments are ignored.

  • value_key – The .obs or .obsm key with the values to determine the enrichment for.

  • group_key – The .obs key with categorical group information.

  • basis_adata – Another AnnData with annotation in .obs to compare. If None, only the adata composition is shown.

  • basis_value_key – The .obs or .obsm key for basis_adata with the values to determine the enrichment for. If None, value_key is used.

  • basis_group_key – The .obs key with categorical group information for basis_adata. If None, value_key is used.

  • fillna – If None, observation containing NA in the values are filtered. Else, NA values are replaced with this value.

  • restrict_groups – A list-like containing the groups within which the enrichment analysis is to be done. If None, all groups are included.

  • restrict_values – A list-like containing the values within which the enrichment analysis is to be done. If None, all values are included. Works only for categorical values.

  • basis_restrict_groups – Like restrict_groups but for basis_adata.

  • basis_restrict_values – Like restrict_values but for basis_adata.

  • reduction

    The reduction to apply on each (group,sample) subset of the data. Possible values are:

    • ’sum’: sum of the values over observations

    • ’mean’: mean of the values over observations

    • ’median’: median of the values over observations

    • a callable mapping a DataFrame to its reduced counterpart

  • normalization

    The normalization to apply on each reduced (group,sample) subset of the data. Possible values are:

    • ’sum’: normalize values by their sum (yields fractions)

    • ’percent’: like ‘sum’ scaled by 100 (yields percentages)

    • ’gmean’: normalize values by their geometric mean (yields contributions which make more sense for enrichments than fractions, due to zero-sum issue; see enrichments())

    • ’clr’: “Center logratio transform”; like ‘gmean’ with additional log transform; makes the distribution more normal and better suited for t tests

    • None: no normalization

    • a value name from value_key: all values are normalized to this contribution

    • a callable mapping a DataFrame to its normalized counterpart

  • assume_counts – Ony relevant for normalization==’gmean’ and normalization==’clr’; whether to regularize zeros by adding a pseudo count of 1 or by replacing them by 1e-3 of the minimum value. If None, check whether the data are consistent with count data and assume counts accordingly, except if reads==True, then also assume_counts==True.

  • reads – Whether to weight the values by the total count per observation

  • colors – The mapping of value names to colors. If None, a set of standard colors is used.

  • alpha – A value-group-dataframe specifying a separate alpha value for all cells in the histogram. If None, no transparency is used.

  • axsize – Tuple of width and size of a single axis. If None, use automatic values.

  • axes_labels – Labels to write on the axes as an list-like of the two labels.

  • annotation – A DataFrame containing annotation for each heatmap cell. If “value”, annotate by the values. If None, don’t annotate. If a tuple of “value” and a DataFrame, append the annotation from the dataframe to the values.

  • value_cluster – Whether to cluster and reorder the values.

  • group_cluster – Whether to cluster and reorder the groups.

  • value_dendrogram – Whether to draw a dendrogram for the values. If True, this implies value_cluster=True.

  • group_dendrogram – Whether to draw a dendrogram for the groups. If True, this implies group_cluster=True.

  • value_order – Set the order of the values explicitly with a list or to be close to diagonal by specifying “diag”; this option is incompatible with value_cluster and value_dendrogram.

  • group_order – Set the order of the groups explicitly with a list or to be close to diagonal by specifying “diag”; this option is incompatible with group_cluster and group_dendrogram.

  • group_labels_rotation – Adjusts the rotation of the group labels in degree.

  • ax – The Axes to plot on. If None, creates a fresh figure for plotting. Incompatible with dendrogram plotting.

  • cmap – A string/colormap to override the colors with.

  • cmap_center – A value to use as center of the colormap. E.g. choosing 0 sets the central color to 0 for every colormap in the plot (i.e. 0 will get white, positive and negative colors the color and complement color given by colors for cmap is None, and whatever the central color of the supplied colormap is if cmap is not None). If None, the colormap spans the entire value range.

  • cmap_vmin_vmax – A tuple giving the range of values for the colormap. This can be modfied by cmap_center.

  • complement_colors – Whether to use complement colors for values below cmap_center if cmap==None.

  • colorbar – Whether to draw a colorbar; only available if cmap is not None.

  • colorbar_label – The label to use for the colorbar; only available if colorbar is True.

Returns:

A Figure if ax is None, else None.