.hclustv_silhouette

proteopy.pl.hclustv_silhouette(adata, linkage_key='auto', values_key='auto', k=15, figsize=(6.0, 4.0), show=True, ax=False, save=None, verbose=True)[source]

Plot silhouette scores for hierarchical clustering.

Evaluates clustering quality by computing the average silhouette score for cluster counts ranging from 2 to k. Higher silhouette scores indicate better-defined clusters.

Parameters:
  • adata (AnnData) – AnnData with clustering results from proteopy.tl.hclustv_tree() stored in .uns.

  • linkage_key (str) – Key in adata.uns for the linkage matrix. When 'auto', auto-detects keys matching hclustv_linkage;*.

  • values_key (str) – Key in adata.uns for the profile values DataFrame. When 'auto', auto-detects keys matching hclustv_values;*.

  • k (int) – Maximum number of clusters to evaluate. Silhouette scores are computed for cluster counts from 2 to k (inclusive).

  • figsize (tuple[float, float]) – Matplotlib figure size in inches.

  • show (bool) – Display the figure.

  • ax (bool) – Return the Matplotlib Axes object instead of displaying.

  • save (str | Path | None) – File path for saving the figure.

  • verbose (bool) – Print status messages including auto-detected keys.

Returns:

Axes object when ax is True; otherwise None.

Return type:

Axes | None

Raises:
  • ValueError – If no clustering results are found in adata.uns, if multiple candidates exist and keys are not specified, or if k < 2.

  • KeyError – If the specified linkage_key or values_key is not found.

Examples

>>> import proteopy as pp
>>> adata = pp.datasets.example_peptide_data()
>>> pr.tl.hclustv_tree(adata, group_by="condition")
>>> pr.pl.hclustv_silhouette(adata, k=5)