Change the cell names in all the different parts of an object. Can be useful before combining multiple objects.

RenameCells(object, ...)

# S3 method for Assay
RenameCells(object, new.names = NULL, ...)

# S3 method for Assay5
RenameCells(object, new.names = NULL, ...)

# S3 method for DimReduc
RenameCells(object, new.names = NULL, ...)

# S3 method for Neighbor
RenameCells(object, old.names = NULL, new.names = NULL, ...)

# S3 method for Seurat
RenameCells(
  object,
  add.cell.id = missing_arg(),
  new.names = missing_arg(),
  for.merge = deprecated(),
  ...
)

Arguments

object

An object

...

Arguments passed to other methods

new.names

vector of new cell names

old.names

vector of old cell names

add.cell.id

prefix to add cell names

for.merge

Deprecated

Value

An object with new cell names

Details

If add.cell.id is set a prefix is added to existing cell names. If new.names is set these will be used to replace existing names.

Examples

# Rename cells in an Assay
head(x = colnames(x = pbmc_small[["RNA"]]))
#> [1] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA"
#> [5] "AGTCAGACTGCACA" "TCTGATACACGTGT"
renamed.assay <- RenameCells(
    pbmc_small[["RNA"]],
    new.names = paste0("A_", colnames(x = pbmc_small[["RNA"]]))
)
head(x = colnames(x = renamed.assay))
#> [1] "A_ATGCCAGAACGACT" "A_CATGGCCTGTGCAT" "A_GAACCTGATGAACC" "A_TGACTGGATTCTCA"
#> [5] "A_AGTCAGACTGCACA" "A_TCTGATACACGTGT"

# Rename cells in a DimReduc
head(x = Cells(x = pbmc_small[["pca"]]))
#> [1] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA"
#> [5] "AGTCAGACTGCACA" "TCTGATACACGTGT"
renamed.dimreduc <- RenameCells(
    object = pbmc_small[["pca"]],
    new.names = paste0("A_", Cells(x = pbmc_small[["pca"]]))
)
head(x = Cells(x = renamed.dimreduc))
#> [1] "A_ATGCCAGAACGACT" "A_CATGGCCTGTGCAT" "A_GAACCTGATGAACC" "A_TGACTGGATTCTCA"
#> [5] "A_AGTCAGACTGCACA" "A_TCTGATACACGTGT"

# Rename cells in a Seurat object
head(x = colnames(x = pbmc_small))
#> [1] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA"
#> [5] "AGTCAGACTGCACA" "TCTGATACACGTGT"
pbmc_small <- RenameCells(object = pbmc_small, add.cell.id = "A")
head(x = colnames(x = pbmc_small))
#> [1] "A_ATGCCAGAACGACT" "A_CATGGCCTGTGCAT" "A_GAACCTGATGAACC" "A_TGACTGGATTCTCA"
#> [5] "A_AGTCAGACTGCACA" "A_TCTGATACACGTGT"