<p>If you are going to use idents like that, make sure that you have told the software what your default ident category is.</p>
<p>This works for me, with the metadata column being called &quot;group&quot;, and &quot;endo&quot; being one possible group there.</p>
<pre><code>Idents(combined.all) &lt;- &quot;group&quot;
endo_subset &lt;- subset(combined.all, idents = c(&quot;endo&quot;))
</code></pre>
<p>I think this is basically what you did, but I think this looks a little nicer</p>

CC BY-SA 4.0
2020-12-21T14:55:10.060Z
I would just add you can run `Idents(combined.all)` to see which groups are in your identity before subsetting by one of them.
burger
CC BY-SA 4.0
2020-07-22T17:51:44.300Z
2020-07-22T17:51:44.300Z
swbarnes2
<p>A bit too long to type as a comment.</p>
<p>To use subset on a Seurat object, (see <code>?subset.Seurat</code>) , you have to provide:</p>
<pre><code>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
</code></pre>
<p>So you either use the matrix to subset:</p>
<pre><code>library(Seurat)
data(pbmc_small)
Idents(pbmc_small) = paste0(&quot;BC&quot;,Idents(pbmc_small))
table(Idents(pbmc_small))

BC0 BC2 BC1 
 36  19  25

test = pbmc_small[,Idents(pbmc_small)==&quot;BC0&quot;]
table(Idents(test))

BC0 
 36 
</code></pre>
<p>Or you provide the cells:</p>
<pre><code>subset(pbmc_small,cells=colnames(pbmc_small)[Idents(pbmc_small)==&quot;BC0&quot;])
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
</code></pre>
<p>What you have should work, but try calling the actual function (in case there are packages that clash):</p>
<pre><code>Seurat:::subset.Seurat(pbmc_small,idents=&quot;BC0&quot;)

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
</code></pre>

CC BY-SA 4.0
2020-07-22T15:36:10.277Z
2020-07-22T15:36:10.277Z
StupidWolf
<p>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.</p>
<pre><code>ER_HER_P &lt;- subset(BC3, idents = c(&quot;BC03&quot;))
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 
</code></pre>
<p>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?</p>
<pre><code>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
</code></pre>

CC BY-SA 4.0
2020-07-22T13:46:44.153Z
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",]))`
geek_y
CC BY-SA 4.0
2020-07-22T15:19:11.610Z
Thank you for the suggestion. But it didnt work..
Najeha Mohamed
CC BY-SA 4.0
2020-07-22T15:35:39.067Z
It worked with `M <- subset(x = BC3, subset = orig.ident == "BC03")`
Najeha Mohamed
<r><scrnaseq><seurat><subset>
Subsetting from seurat object based on orig.ident?
# Subsetting from seurat object based on orig.ident?

(Asked by: username_0 on 2020-07-22)

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

**Tags:** r, scrnaseq, seurat, subset
> **Comments:**
> **username_1**: 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",]))`  
> **username_0**: Thank you for the suggestion. But it didnt work..  
> **username_0**: It worked with `M <- subset(x = BC3, subset = orig.ident == "BC03")`  

---

## 2 answers

### Answer by username_2 on 2020-07-22. Score: 1

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

> **Comments:**
> **username_3**: I would just add you can run `Idents(combined.all)` to see which groups are in your identity before subsetting by one of them.  

---

### Answer by username_4 on 2020-07-22. Score: 0

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


---

