# Subsetting of object existing of two samples

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.

• 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
Jul 19, 2019 at 7:27
• Yes, I have 1 suerat object and now I am trying to divide them into two Seurat object, 1 for each sample. Jul 19, 2019 at 7:36
• Ok, but can't you create from the start two seurat objects?
– llrs
Jul 19, 2019 at 7:43
• 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. Jul 19, 2019 at 7:57
• 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. Jul 26, 2019 at 1:41

Assuming rownames(subset_DR1) is indeed a list of cell names
seuratObj_subset_dr1 <- SubsetData(seuratObj, cells=rownames(subset_DR1))