<p>I was able to achieve this in the following way:</p>

<pre class="lang-r prettyprint-override"><code>require(data.table)
cell_names &lt;- vector(mode="character")
for (i in 1:length(neuron_ids)) {
  seurat_subset &lt;- SubsetData(seurat_object, subset.name = neuron_ids[i], accept.low = 0.1)
  genes &lt;- colnames(seurat_subset@data)
  cell_names &lt;- c(cell_names, genes[! genes %chin% cell_names])
}
seurat_subset &lt;- SubsetData(seurat_object, cells.use = cell_names)
</code></pre>

<p>Would be interesting to know if <code>Seurat</code> provides such functionality out of the box.</p>

CC BY-SA 4.0
2019-11-15T19:36:39.167Z
In Seurat V3 you should use `seurat_subset <- SubsetData(seurat_object, cells = cell_names)` as `cells.use` is no longer supported.
zdebruine
CC BY-SA 4.0
2018-05-04T01:17:43.603Z
2018-05-04T07:59:00.323Z
2018-05-04T07:59:00.323Z
Nikita Vlasenko
<p>I know that I can do subsetting on just one gene in <code>Seurat</code>:</p>

<pre><code>seurat_subset &lt;- SubsetData(seurat_object, subset.name = neuron_ids[1], accept.low = 0.1)
</code></pre>

<p>However, I want to subset on multiple genes. Is there a way to do that? I just do not want to do manual subsetting on 10 genes, then manually getting <code>@data</code> matrix from each subset, and recreating seurat object afterwards.</p>

<r><rna-seq><single-cell><seurat>
Subset on multiple genes in Seurat
# Subset on multiple genes in Seurat

(Asked by: username_0 on 2018-05-04)

I know that I can do subsetting on just one gene in Seurat:
seurat_subset <- SubsetData(seurat_object, subset.name = neuron_ids[1], accept.low = 0.1)

However, I want to subset on multiple genes. Is there a way to do that? I just do not want to do manual subsetting on 10 genes, then manually getting @data matrix from each subset, and recreating seurat object afterwards.

**Tags:** r, rna-seq, single-cell, seurat

---

## 1 answers

### Answer by username_0 on 2018-05-04. Score: 6 | Accepted answer

I was able to achieve this in the following way:
require(data.table)
cell_names <- vector(mode="character")
for (i in 1:length(neuron_ids)) {
  seurat_subset <- SubsetData(seurat_object, subset.name = neuron_ids[i], accept.low = 0.1)
  genes <- colnames(seurat_subset@data)
  cell_names <- c(cell_names, genes[! genes %chin% cell_names])
}
seurat_subset <- SubsetData(seurat_object, cells.use = cell_names)

Would be interesting to know if Seurat provides such functionality out of the box.

> **Comments:**
> **username_1**: In Seurat V3 you should use `seurat_subset <- SubsetData(seurat_object, cells = cell_names)` as `cells.use` is no longer supported.  

---

