Skip to contents

Rename clusters for the Seurat object

Usage

RenameClusters(
  srt,
  group.by,
  nameslist = list(),
  name = "newclusters",
  keep_levels = FALSE
)

Arguments

srt

A Seurat object.

group.by

The old group used to rename cells.

nameslist

A named list of new cluster value.

name

The name of the new cluster stored in the Seurat object.

keep_levels

If the old group is a factor, keep the order of the levels.

Examples

data(pancreas_sub)

# Rename all clusters
pancreas_sub <- standard_scop(pancreas_sub)
#>  [2026-01-27 07:54:12] Start standard scop workflow...
#>  [2026-01-27 07:54:13] Checking a list of <Seurat>...
#> ! [2026-01-27 07:54:13] Data 1/1 of the `srt_list` is "unknown"
#>  [2026-01-27 07:54:13] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 1/1 of the `srt_list`...
#>  [2026-01-27 07:54:15] Perform `Seurat::FindVariableFeatures()` on the data 1/1 of the `srt_list`...
#>  [2026-01-27 07:54:15] Use the separate HVF from srt_list
#>  [2026-01-27 07:54:15] Number of available HVF: 2000
#>  [2026-01-27 07:54:16] Finished check
#>  [2026-01-27 07:54:16] Perform `Seurat::ScaleData()`
#>  [2026-01-27 07:54:16] Perform pca linear dimension reduction
#>  [2026-01-27 07:54:17] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#>  [2026-01-27 07:54:17] Reorder clusters...
#>  [2026-01-27 07:54:17] Perform umap nonlinear dimension reduction
#>  [2026-01-27 07:54:17] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2026-01-27 07:54:21] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2026-01-27 07:54:24] Run scop standard workflow completed
levels(pancreas_sub@meta.data[["SubCellType"]]) <- unique(
  pancreas_sub@meta.data[["SubCellType"]]
)
pancreas_sub <- RenameClusters(
  pancreas_sub,
  group.by = "SubCellType",
  nameslist = letters[1:8]
)
CellDimPlot(pancreas_sub, "newclusters")
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


# Rename specified clusters
pancreas_sub <- RenameClusters(pancreas_sub,
  group.by = "SubCellType",
  nameslist = list("a" = "Alpha", "b" = "Beta")
)
CellDimPlot(pancreas_sub, "newclusters")
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


# Merge and rename clusters
pancreas_sub <- RenameClusters(
  pancreas_sub,
  group.by = "SubCellType",
  nameslist = list(
    "EndocrineClusters" = c("Alpha", "Beta", "Epsilon", "Delta")
  ),
  name = "Merged",
  keep_levels = TRUE
)
CellDimPlot(pancreas_sub, "Merged")
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.