This is a test version of Biostars. For the public version, visit https://www.biostars.org.
why renaming Idents in Seurat object doesn't work?

I'm trying to rename my clusters in a Seurat object.

my old cluster IDs are numers

Idents(seuObj) <- 'RNA_snn_res.0.1'
levels(seuObj)
 [1] "0"  "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"

I would like to assign the clusters names from a named vector

Following the vignette from the web site I tried to assign the vector to the numbers -

cluster_ids <- c("DC2_genes",  "mregDC_genes", "mregDC_genes", "Bcell_genes",...)
names(cluster_ids) <- levels(seuObj)
seuObj <- RenameIdents(seuObj, cluster_ids)

But this just assigns numbers to the new Idents

head(Idents(seuObj))
C7_AAACCCAAGGGTGGGA-1 C7_AAACCCAAGTAGCATA-1 C7_AAACCCACAAGAGGTC-1 C7_AAACCCACAGTCTCTC-1 C7_AAACCCACATGAATCC-1 
    0.346464052287582     0.177389184397163     0.132815134099617     0.300105882352941     0.497196167423096 
C7_AAACCCAGTAGAGGAA-1 
    0.335241176470588

What am I doing wrong here?

seurat renameidents r

2 answers

I manage to find a workwround, but I don't understand what I did wrong here.

my solution was to extract the cluster column as vector and assign the new names to it. Then I created a new column in my seurat obj.

vec <- seuObj$RNA_snn_res.0.1
levels(vec) <- cluster_ids
seuObj[["UCell_clusters"]] <- vec
Idents(seuObj) <- 'UCell_clusters'

But is this the correct way to go?

I think when you give indent to seuObj :

Idents(seuObj) <- 'RNA_snn_res.0.1'

You may wrongly assign other value to it such as "pANN_..." because the output Idents(seuObj) is really similar to the value of seuObj$pANN_...

Don't understand this comment. I don't have any columns with this name.

Log in to answer this question.