3

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.

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

1 Answers1

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.

Kohl Kinning
  • 1,149
  • 6
  • 26