netmap.downstream.gene_clustering.add_clusters_to_adata¶
- netmap.downstream.gene_clustering.add_clusters_to_adata(adata, dist_linkage, cutoff_distance, cluster_var='correlation_cluster', genes=None)[source]¶
Cut the dendrogram and annotate
adata.varwith flat cluster assignments.Applies
scipy.cluster.hierarchy.fclusteratcutoff_distanceto the provided linkage matrix and merges the resulting integer cluster labels intoadata.varundercluster_var. Ifcutoff_distanceisNone, a-1sentinel column is added instead and a warning is printed.- Parameters:
adata (anndata.AnnData) – AnnData object whose
.varwill receive the cluster label column. Must be the same object (or compatible) as the one used to computedist_linkage.dist_linkage – Linkage matrix as returned by
get_hierarchical_clustering()(or anyscipy.cluster.hierarchylinkage function).cutoff_distance (float or None) – Height at which to cut the dendrogram. Pass
Noneto skip clustering and fill with-1.cluster_var (str) – Name of the column added to
adata.var. Defaults to'correlation_cluster'.genes (list or None) – Gene subset used when building
dist_linkage; restricts which rows ofadata.varare matched. Defaults toNone(all genes).
- Returns:
The input
adatawithcluster_varmerged into.var(outer join, so genes absent from the linkage receive NaN).- Return type: