netmap.downstream.clustering.spectral_clustering

netmap.downstream.clustering.spectral_clustering(adata, n_clu=2, key_added='spectral')[source]

Run scikit-learn spectral clustering on the neighbour graph of an AnnData object.

Recomputes the neighbour graph with default parameters via sc.pp.neighbors, then fits a sklearn.cluster.SpectralClustering model using the precomputed nearest-neighbour distances stored in adata.obsp['distances']. The resulting integer cluster labels are stored as a categorical column in adata.obs. If key_added already exists in adata.obs a numeric suffix (_1, _2, …) is appended to avoid overwriting existing annotations.

Parameters:
  • adata (anndata.AnnData) – AnnData object on which to run spectral clustering. Modified in-place.

  • n_clu (int) – Number of clusters to compute. Defaults to 2.

  • key_added (str) – Base name of the column added to adata.obs. Defaults to 'spectral'.

Returns:

The input adata object with an additional categorical column in .obs named key_added (or key_added_<n> if the name was already taken) containing the spectral cluster labels.

Return type:

anndata.AnnData