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 asklearn.cluster.SpectralClusteringmodel using the precomputed nearest-neighbour distances stored inadata.obsp['distances']. The resulting integer cluster labels are stored as a categorical column inadata.obs. Ifkey_addedalready exists inadata.obsa 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
adataobject with an additional categorical column in.obsnamedkey_added(orkey_added_<n>if the name was already taken) containing the spectral cluster labels.- Return type: