# Subsetting from seurat object based on orig.ident?

I am pretty new to Seurat. I want to subset from my original seurat object (BC3) meta.data based on orig.ident. however, when i use subset(), it returns with Error.

ER_HER_P <- subset(BC3, idents = c("BC03"))
Error: No cells found

table(Idents(BC3))
BC01   BC02   BC03 BC03LN   BC04   BC05   BC06   BC07 BC07LN   BC08   BC09   BC10   BC11
21     50     33     51     42     74     15     48     52     21     55     13     11


There are 33 cells under the identity. I checked the active.ident to make sure the identity has not shifted to any other column, but still I am getting the error?

head(BC3@active.ident)
[1] BC01 BC01 BC01 BC01 BC01 BC01
Levels: BC01 BC02 BC03 BC03LN BC04 BC05 BC06 BC07 BC07LN BC08 BC09 BC10 BC11

• A stupid suggestion, but did you try to give it as a string ? just "BC03" ? Other option is to get the cell names of that ident and then pass a vector of cell names. cells = as.vector(rownames(object@meta.data[object@meta.data\$idents=="BC03",])) Jul 22, 2020 at 13:46
• Thank you for the suggestion. But it didnt work.. Jul 22, 2020 at 15:19
• It worked with M <- subset(x = BC3, subset = orig.ident == "BC03") Jul 22, 2020 at 15:35

If you are going to use idents like that, make sure that you have told the software what your default ident category is.

This works for me, with the metadata column being called "group", and "endo" being one possible group there.

Idents(combined.all) <- "group"
endo_subset <- subset(combined.all, idents = c("endo"))


I think this is basically what you did, but I think this looks a little nicer

• I would just add you can run Idents(combined.all) to see which groups are in your identity before subsetting by one of them. Dec 21, 2020 at 14:55

A bit too long to type as a comment.

To use subset on a Seurat object, (see ?subset.Seurat) , you have to provide:

Subset a Seurat object

Description:

Subset a Seurat object

Usage:

## S3 method for class 'Seurat'
x[i, j, ...]

## S3 method for class 'Seurat'
subset(x, subset, cells = NULL, features = NULL, idents = NULL, ...)

Arguments:

x: Seurat object to be subsetted

i, features: A vector of features to keep

j, cells: A vector of cells to keep


So you either use the matrix to subset:

library(Seurat)
data(pbmc_small)
Idents(pbmc_small) = paste0("BC",Idents(pbmc_small))
table(Idents(pbmc_small))

BC0 BC2 BC1
36  19  25

test = pbmc_small[,Idents(pbmc_small)=="BC0"]
table(Idents(test))

BC0
36


Or you provide the cells:

subset(pbmc_small,cells=colnames(pbmc_small)[Idents(pbmc_small)=="BC0"])
An object of class Seurat
230 features across 36 samples within 1 assay
Active assay: RNA (230 features, 20 variable features)
2 dimensional reductions calculated: pca, tsne


What you have should work, but try calling the actual function (in case there are packages that clash):

Seurat:::subset.Seurat(pbmc_small,idents="BC0")

An object of class Seurat
230 features across 36 samples within 1 assay
Active assay: RNA (230 features, 20 variable features)
2 dimensional reductions calculated: pca, tsne