satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.29k stars 915 forks source link

Reorder seurat_obj@active.ident #7003

Closed JackieMium closed 1 year ago

JackieMium commented 1 year ago

If seurat_obj@active.ident is already assigned to a ordered label say A B C and D and in this order, to reorder it, if I use something like:

seurat_obj@active.ident <- factor(as.character(seurat_obj@active.ident), levels = c("A", "D", "C", "B"))

or

levels(seurat_obj@active.ident) <- c("A", "D", "C", "B")

table(seurat_obj@active.ident) and levels(seurat_obj@active.ident) all reports the reordered result. But if I try to plot using the NEW seurat_obj, it hangs a long time and finally reports an error with no plot result:

DotPlot(seurat_obj, features = c("g1", "g2"))
Warning: Found the following features in more than one assay, excluding the default. 
We will not include these in the final data frame: g1, g2
None of the requested variables were found  g1, g2

However, if use

seurat_obj$ct <- factor(as.character(seurat_obj@active.ident), levels = c("A", "D", "C", "B"))
Idents(seurat_obj) <- seurat_obj$ct

then DotPlot() works fine and seurat_obj@active.ident is reordered in the plot.

Do I HAVE TO use another column in seurat_obj@meta.data as a temporary variable every time I reorder cell idents?

longmanz commented 1 year ago

Hi, It seems that I cannot reproduce your issue. Which version of Seurat are you using? In addition, does your original "active.ident" present in your seurat_obj@meta.data? If not, then that will lead to an error if you try to modify the active.ident.

JackieMium commented 1 year ago

Hi, It seems that I cannot reproduce your issue. Which version of Seurat are you using?

I am using v4.2.1 from CRAN on a Linux machine.

In addition, does your original "active.ident" present in your seurat_obj@meta.data? If not, then that will lead to an error if you try to modify the active.ident.

Yes active.ident is already a factor vector with the same cell idents, I was just trying to change the factor levels as I reported. And as you can see I was able to assign it to seurat_obj$ct and then relevel ct column in seurat@meta.data.

JackieMium commented 1 year ago

Hi, It seems that I cannot reproduce your issue. Which version of Seurat are you using? In addition, does your original "active.ident" present in your seurat_obj@meta.data? If not, then that will lead to an error if you try to modify the active.ident.

I tried another dataset and the problem is gone. Maybe its due to the seurat_obj is rather large and computer resource is tight the the I was releveling. Consider the issue fixed. Thanks for for reply. You can close this issue now.

longmanz commented 1 year ago

Hi, Thanks for double checking. If this happens again to other datasets, please let us know and we will look into this.