netmap.downstream.gene_clustering.get_hierarchical_clustering

netmap.downstream.gene_clustering.get_hierarchical_clustering(adata, genes=None)[source]

Perform hierarchical clustering of genes by pairwise correlation.

Computes the Pearson correlation matrix across the gene axis of adata.X, converts it to a distance matrix, and fits an average-linkage dendrogram. Returns the raw correlation/cophenet pairs for downstream cutoff selection and the linkage object for tree-cutting.

Parameters:
  • adata (anndata.AnnData) – AnnData object containing gene expression (or attribution) data in layer X. Rows are cells, columns are genes.

  • genes (list or None) – Subset of gene names (matching adata.var.index) to use for clustering. Defaults to None, which uses all genes.

Returns:

A two-element tuple (df, dist_linkage) where:

  • df (pd.DataFrame): DataFrame with columns 'cophenet' (cophenetic distances from the linkage) and 'corr' (upper triangular Pearson correlations, diagonal excluded).

  • dist_linkage: Linkage matrix from scipy.cluster.hierarchy.average on the correlation-distance matrix.

Return type:

tuple