This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Subset Seurat Object based on metadata

Good afternoon,

I am trying to filter my Seurat object based on metadata with

Pancreas_Object<- subset(x = Pancreas_Object, subset = sample_type=='solid tumor')

However, I get the following error:

RNA assay doesn't leave any cells, so it is removed
Error in subset.Seurat(x = Pancreas_Object, subset = sample_type == "solid tumor") :
    No cells left in the default assay, please change the default assay

I don't understand why it says "RNA assay doesn't leave any cells". I clearly have cells for this sample_type.

There is only one assay ("RNA") no integrated data or similar.

Thank you for any input!

seurat

You can try this-

Idents(Pancreas_Object) <- "sample_type" 
cell_values <- c("solid tumor")
Pancreas_Object_subset <- subset(Pancreas_Object, idents = cell_values, invert = FALSE)

Thank you, but unfortunately I still get the same error:

Idents(C1Q_Object) <- "sample_type" 
cell_values <- c("solid tumor")
Pancreas_Object_subset <- subset(C1Q_Object, idents = cell_values, invert = FALSE)
Error in subset.Seurat(C1Q_Object, idents = cell_values, invert = FALSE) : 
  No cells left in the default assay, please change the default assay

Hi Bine,

Have you figured out how to solve your problem? I am facing the exact same issue.

Best regards,
Anton

P.S: Please do not add answers unless you're answering the top level question. Instead, use Add Comment or Add Reply as appropriate. I've moved your post to the right location this time, please be more careful in the future.

2 answers

That's likely because the rownames in your seurat metadata do not match the colnames of your count matrix

you can compare them with

colnames(GetAssayData(seurat_object, assay = "RNA", slot = "counts"))
rownames(seurat_object@meta.data)

Best,
Aurel

Hi all,

I recently also encountered the same error: "RNA assay doesn't leave any cells, so it is removed.." when I am doing the subset function in Seurat package:

gse262072_basal <- subset(gse262072, subset = GroupID=="Basal")

Here is my solution: check the cell names between the assay data and the metadata

rownames(gse262072@meta.data)[1:5] [1]
"CD_02_s_CARTQ_AAACCCACATGGCCAC-1" "CD_02_s_CARTQ_AAACGAACAGCTATAC-1"
"CD_02_s_CARTQ_AAACGAACAGTTAGAA-1" [4]
"CD_02_s_CARTQ_AAACGAATCGCTTGCT-1" "CD_02_s_CARTQ_AAAGAACAGAGGGTGG-1"

gse262072@assays$RNA@data@Dimnames[[2]][1:5] [1]
"CARTQ_AAACCCACATGGCCAC-1" "CARTQ_AAACGAACAGCTATAC-1"
"CARTQ_AAACGAACAGTTAGAA-1" "CARTQ_AAACGAATCGCTTGCT-1" [5]
"CARTQ_AAAGAACAGAGGGTGG-1"

gse262072@assays$RNA@counts@Dimnames[[2]][1:5] [1]
"CD_02_s_CARTQ_AAACCCACATGGCCAC-1" "CD_02_s_CARTQ_AAACGAACAGCTATAC-1"
"CD_02_s_CARTQ_AAACGAACAGTTAGAA-1" [4]
"CD_02_s_CARTQ_AAACGAATCGCTTGCT-1" "CD_02_s_CARTQ_AAAGAACAGAGGGTGG-1"

Here, you can see the cell name in assay data was inconsistent with meta.data and assay counts. So, just simply run:

gse262072@assays$RNA@data@Dimnames[[2]] <-  gse262072@assays$RNA@counts@Dimnames[[2]]

Then, it works at my side.

Hope this could help you.

Log in to answer this question.