Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why renaming Idents in Seurat object doesn't work? #8820

Open
yeroslaviz opened this issue Apr 25, 2024 · 2 comments
Open

why renaming Idents in Seurat object doesn't work? #8820

yeroslaviz opened this issue Apr 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@yeroslaviz
Copy link

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?

@yeroslaviz yeroslaviz added the bug Something isn't working label Apr 25, 2024
@yeroslaviz
Copy link
Author

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'

@mhkowalski
Copy link
Contributor

Hi,

Glad you were able to find a workaround. I couldn't reproduce this myself, would you be able to provide a reproducible example to get this issue?

Idents(pbmc_small) <- 'RNA_snn_res.0.8'
levels(pbmc_small)
cluster_ids <- c("DC2_genes",  "mregDC_genes")
names(cluster_ids) <- levels(pbmc_small)
pbmc_small <- RenameIdents(pbmc_small, cluster_ids)
head(Idents(pbmc_small))
ATGCCAGAACGACT CATGGCCTGTGCAT GAACCTGATGAACC TGACTGGATTCTCA AGTCAGACTGCACA TCTGATACACGTGT 
     DC2_genes      DC2_genes   mregDC_genes      DC2_genes      DC2_genes      DC2_genes 
Levels: DC2_genes mregDC_genes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants