<p>I think your issue is simply not assigning the newly-subset object in to a new object.</p>

<p>Assuming <code>rownames(subset_DR1)</code> is indeed a list of cell names</p>

<pre><code>seuratObj_subset_dr1 &lt;- SubsetData(seuratObj, cells=rownames(subset_DR1))
</code></pre>

<p>will work.</p>

CC BY-SA 4.0
2019-08-01T21:28:54.137Z
2019-08-02T18:50:11.307Z
2019-08-02T18:50:11.307Z
Kohl Kinning
<p>I have a Seurat object existing of an aggregate of two samples namely; RD1 and RD2. I am trying to make a subset of each sample. But it's not really working. I manage to make a subset of the cells but I don't manage to make a subset of the whole object. Isn't there a way to do this, based on the subset from cell names a subset to make from the whole object. </p>

<pre><code>seuratObj<span class="math-container">$orignal_1 &lt;- seuratObj@meta.data$</span>orig.ident
seuratObj<span class="math-container">$orignal_2 &lt;- seuratObj@meta.data$</span>orig.ident
seuratObj<span class="math-container">$orignal_1 &lt;- gsub("RD1", "TRUE",seuratObj$</span>orignal_1 )
seuratObj<span class="math-container">$orignal_1  &lt;- gsub("RD2", "False",seuratObj$</span>orignal_1  )
seuratObj<span class="math-container">$orignal_2  &lt;- gsub("RD1k", "TRUE",seuratObj$</span>orignal_2  )
seuratObj<span class="math-container">$orignal_2  &lt;- gsub("RD2", "False",seuratObj$</span>orignal_2  )

subset_DR1 &lt;- data.frame(orignal_1 = seuratObj$orignal_1)
subset_DR1 &lt;- subset(subset_DR1, orignal_1 == TRUE,select = c("orignal_1"))

subset_DR2 &lt;- data.frame(orignal_2 = seuratObj$orignal_2)
subset_DR2 &lt;- subset(subset_DR2 , orignal_2 == TRUE,select = c("orignal_2"))

SubsetData(seuratObj, cells = rownames(subset_DR1), subset.name = seuratObj$orignal_1)
</code></pre>

<p>I just started to work with seurat packages. I think I am missing something. </p>

CC BY-SA 4.0
2019-07-19T07:27:58.007Z
Welcome to the site ageans. Did you try to create two seurat objects one for each sample? (Instead of dividing this single seurat object?)
llrs
CC BY-SA 4.0
2019-07-19T07:36:40.893Z
Yes, I have 1 suerat object and now I am trying to divide them into two Seurat object, 1 for each sample.
ageans
CC BY-SA 4.0
2019-07-19T07:43:42.097Z
Ok, but can't you create from the start two seurat objects?
llrs
CC BY-SA 4.0
2019-07-19T07:57:59.127Z
Sadly enough now because it's an old object. And I only got the object. And for the rest of the analysis, it should be 1 object. But for 1 part I need to separate it.
ageans
CC BY-SA 4.0
2019-07-26T01:41:07.223Z
Can you post some information on the meta data? Do you have a column in the metadata that annotates the subset?Also assign the subset to new object, subset_obj <- SubsetData() if you use seurat2, subset_obj <-  subset(x = seuratObj, subset = orig.ident == "Replicate1") if you use seurat3.
Mack123456
<r><seurat><subset>
Subsetting of object existing of two samples
# Subsetting of object existing of two samples

(Asked by: username_0 on 2019-07-18)

I have a Seurat object existing of an aggregate of two samples namely; RD1 and RD2. I am trying to make a subset of each sample. But it's not really working. I manage to make a subset of the cells but I don't manage to make a subset of the whole object. Isn't there a way to do this, based on the subset from cell names a subset to make from the whole object. 
seuratObj$orignal_1 <- seuratObj@meta.data$orig.ident
seuratObj$orignal_2 <- seuratObj@meta.data$orig.ident
seuratObj$orignal_1 <- gsub("RD1", "TRUE",seuratObj$orignal_1 )
seuratObj$orignal_1  <- gsub("RD2", "False",seuratObj$orignal_1  )
seuratObj$orignal_2  <- gsub("RD1k", "TRUE",seuratObj$orignal_2  )
seuratObj$orignal_2  <- gsub("RD2", "False",seuratObj$orignal_2  )

subset_DR1 <- data.frame(orignal_1 = seuratObj$orignal_1)
subset_DR1 <- subset(subset_DR1, orignal_1 == TRUE,select = c("orignal_1"))

subset_DR2 <- data.frame(orignal_2 = seuratObj$orignal_2)
subset_DR2 <- subset(subset_DR2 , orignal_2 == TRUE,select = c("orignal_2"))

SubsetData(seuratObj, cells = rownames(subset_DR1), subset.name = seuratObj$orignal_1)

I just started to work with seurat packages. I think I am missing something.

**Tags:** r, seurat, subset
> **Comments:**
> **username_1**: Welcome to the site ageans. Did you try to create two seurat objects one for each sample? (Instead of dividing this single seurat object?)  
> **username_0**: Yes, I have 1 suerat object and now I am trying to divide them into two Seurat object, 1 for each sample.  
> **username_1**: Ok, but can't you create from the start two seurat objects?  
> **username_0**: Sadly enough now because it's an old object. And I only got the object. And for the rest of the analysis, it should be 1 object. But for 1 part I need to separate it.  
> **username_2**: Can you post some information on the meta data? Do you have a column in the metadata that annotates the subset?Also assign the subset to new object, subset_obj <- SubsetData() if you use seurat2, subset_obj <-  subset(x = seuratObj, subset = orig.ident == "Replicate1") if you use seurat3.  

---

## 1 answers

### Answer by username_3 on 2019-08-01. Score: 2

I think your issue is simply not assigning the newly-subset object in to a new object.
Assuming rownames(subset_DR1) is indeed a list of cell names
seuratObj_subset_dr1 <- SubsetData(seuratObj, cells=rownames(subset_DR1))

will work.


---

