opendvp.plotting.correlation_heatmap

opendvp.plotting.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.

Return type:

Figure | None

Parameters:#

adataAnnData

Annotated data matrix.

correlation_method{“pearson”, “kendall”, “spearman”}, optional

Method to calculate the correlation (default = “spearman”).

sample_labelstr, optional

Column name in adata.obs to label samples with. If None, uses adata.obs_names.

color_mapstr, optional

Colormap for the heatmap (default = “magma”).

vminfloat, optional

Minimum value for colormap scaling (default = 0.7).

vmaxfloat, optional

Maximum value for colormap scaling (default = 1.0).

return_figbool, optional

If True, returns the matplotlib Figure object for further customization. If False, shows the plot and returns None.

axmatplotlib.axes.Axes, optional

Axes object to plot on. If None, a new figure and axes are created.

Returns:#

figmatplotlib.figure.Figure or None

The figure object if return_fig is True, otherwise 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.