pegasus.calc_dendrogram
- pegasus.calc_dendrogram(data, groupby='obs', rep='pca', genes=None, on_average=True, linkage_method='ward', res_key='dendrogram')[source]
Cluster data using hierarchical clustering algorithm.
The metric in use is a Connection Specific Index (CSI) matrix ([Suo18], [Bass13]) built from the correlations between
groupbyattribute levels regarding therepembedding.- Parameters
data (
MultimodalData,UnimodalData, orAnnDataobject) – Single cell expression data.groupby (
str, optional, default:None) – Set cluster labels in use. If"obs", use cell names (i.e.data.obs_names); if"var", use feature names (i.e.data.var_names). Otherwise, specify a categorical cell or feature attribute to use, which must exist indata.obsordata.var.rep (
str, optional, default:pca) – Cell embedding to use. If specified, it only works whengenesisNone, and its key"X_"+repmust exist indata.obsm. By default, use PCA embedding. IfNone, use the current count matrixdata.X.genes (
List[str], optional, default:None) – List of genes to use. Gene names must exist indata.var. If set, use the counts indata.Xfor plotting; ifNone, use the embedding specified inrep.on_average (
bool, optional, default:True) – IfTrue, clusteringgroupbylevels based on their mean values. Only works whengroupbyis notNone.linkage_method (
str, optional, default:ward) – Which linkage criterion to use, used by hierarchical clustering. Available options:ward(default),single,complete,average,weighted,centroid,median. See scipy linkage documentation for details.res_key (
str, optional, default:dendrogram) – Key name indata.unsfield to store the calculated dendrogram information, which will be used byplot_dendrogramfunction for plotting.
- Return type
None- Returns
NoneUpdate
data.uns–data.uns[res_key]: A tuple of the calculated linkage matrix and its corresponding labels.
Examples
>>> pg.calc_dendrogram(data, groupby='leiden_labels') >>> pg.calc_dendrogram(data, genes=['CD4', 'CD8A', 'CD8B'], on_average=False) >>> pg.calc_dendrogram(data, groupby="var", rep=None, on_average=False)