opendvp.pl.correlation_heatmap#
- correlation_heatmap(adata, correlation_method='spearman', sample_label=None, color_map='magma', vmin=0.7, vmax=1.0, return_fig=False, ax=None)#
Plot a clustered correlation heatmap of protein abundance for all samples in an AnnData object.
This function computes the pairwise correlation matrix between features (columns) in the AnnData object, then clusters and reorders the matrix using hierarchical clustering (scipy), so that similar samples/features are grouped together. The heatmap is plotted with annotated values in the top-right triangle and colors only in the bottom-left triangle for clarity.
- Parameters:
adata (anndata.AnnData) – Annotated data matrix.
correlation_method ({"pearson", "kendall", "spearman"}, optional) – Method to calculate the correlation (default = “spearman”).
sample_label (str, optional) – Column name in adata.obs to label samples with. If None, uses adata.obs_names.
color_map (str, optional) – Colormap for the heatmap (default = “magma”).
vmin (float, optional) – Minimum value for colormap scaling (default = 0.7).
vmax (float, optional) – Maximum value for colormap scaling (default = 1.0).
return_fig (bool, optional) – If True, returns the matplotlib Figure object for further customization. If False, shows the plot and returns None.
ax (matplotlib.axes.Axes, optional) – Axes object to plot on. If None, a new figure and axes are created.
- Returns:
fig – The figure object if return_fig is True, otherwise None.
- Return type:
matplotlib.figure.Figure or None
Notes
The correlation matrix is clustered and reordered using hierarchical clustering (average linkage) on 1 - correlation distance.
Both rows and columns are reordered to group similar features/samples together.