SCA-IRCM / SingleCellSignalR

R package for Bioconductor submission
29 stars 12 forks source link

clusterID changed after Retreiving the results of the preprocessed Seurat object #5

Closed gt7901b closed 3 years ago

gt7901b commented 3 years ago

Hi:

I run

Retreiving the results of the preprocessing from the Seurat object

cluster = as.numeric(Idents(seurat.obj)) data = data.frame(seurat.obj[["RNA"]]@data) to convert extract data and clusterID from seurat object.

But I noticed that the clusterID number changed in cluster variable

if I do table(cluster) cluster 1 2 3 4 5 6 7 8 9 10 11 12 13 12654 4581 1195 577 746 1714 4957 2094 1188 3968 1474 1154 691 14 15 16 17 18 19 1090 1849 639 579 618 66

but my original seurat object has different clusterID table(Idents(seurat.obj))

0               1    10    11         12    13    14         15    16    17         18     2     3 

12654 4957 1154 1090 746 691 639 618 579 577 66 4581 3968 4 5 6 7 8 9 2094 1849 1714 1474 1195 1188

I can see the clusterID all increased by 1. but judging by cell number, I can see cluster7 was 1, cluster11 was 10...

is there a way not to change clusterID?

thanks

SimCab-CHU commented 3 years ago

Hi, The problem comes from the fact that you have more than 10 clusters. Idents(seurat.obj)is a factor, then it starts at 0 and is ranked by the first digit (ex: 0 < 1 < 10 < 11 < 12 < 2 < 3 ...). To fix your problem you can try : cluster <- as.numeric(levels(Idents(seurat.obj)))[Idents(seurat.obj)] or cluster <- as.numeric(as.character(Idents(seurat.obj))).

Another solution is to take advantage of the c.names argument of the SingleCellSignalR functions by naming the clusters by their "original" name. Hope this helps.

Thanks for using SingleCellSignalR!

SCA

gt7901b commented 3 years ago

got it. Thanks!