Sorts cell metadata variable by similarity using hierarchical clustering
Source:R/utilities.R
SortIdents.RdCompute distance matrix from a feature/variable matrix and perform hierarchical clustering to order variables (for example, cell types) according to their similarity.
Usage
SortIdents(
object,
layer = "data",
assay = NULL,
label = NULL,
dendrogram = FALSE,
method = "euclidean",
verbose = TRUE
)Arguments
- object
A Seurat object containing single-cell data.
- layer
The layer of the data to use (default is "data").
- assay
Name of assay to use. If NULL, use the default assay
- label
Metadata attribute to sort. If NULL, uses the active identities.
- dendrogram
Logical, whether to plot the dendrogram (default is FALSE).
- method
The distance method to use for hierarchical clustering (default is 'euclidean', other options from
stats::dist()are 'maximum', 'manhattan', 'canberra', 'binary' and 'minkowski').- verbose
Display messages
Value
The Seurat object with metadata variable reordered by similarity.
If the metadata variable was a character vector, it will be converted to a
factor and the factor levels set according to the similarity ordering. If
active identities were used (label=NULL), the levels will be updated
according to similarity ordering.
Examples
atac_small$test <- sample(1:10, ncol(atac_small), replace = TRUE)
atac_small <- SortIdents(object = atac_small, label = "test")
#> Creating pseudobulk profiles for 1 cell groups
#> Computing euclidean distance between pseudobulk profiles
#> Clustering distance matrix
print(levels(atac_small$test))
#> [1] "10" "2" "3" "4" "9" "8" "6" "5" "7" "1"