Extracting cells only from one condition (Seurat)
1
2
Entering edit mode
4.8 years ago
V ▴ 410

Hello,

I've combined 3 seurat files in order to do an integrated analysis and everything is working fine, but I would like to extract some cells for subsequent analysis. As the dimplot is now, the clusters consist of cells from all of my conditions so I can not seem to do the usual approach which would be something like :

Cluster.1.8.12.only <- subset(x = seuratA, idents = c('1','8', '12'))

if for example I wanted clusters 1,8 and 12.

Does anyone know how I would modify the above to for example, get clusters 1, 8 and 12 but of only the condition I'm interested in? for simplicity sake lets assume the conditions are labelled A, B and C and are in an integrated seurat called ABC.combined.

Thank you for your help :)

single cell rnaseq seurat RNA-Seq R • 47k views
ADD COMMENT
8
Entering edit mode
4.8 years ago

I'd probably just subset again. Same approach, just using the metadata column using your condition.

Cluster.1.8.12.cond <- subset(x = Cluster.1.8.12.only, subset = your_condition_column == "condition_of_interest")
ADD COMMENT
0
Entering edit mode

Hello,

I've tried to do this but it does not seem to be working for me. I'm probably missing something dumb.

My seurat object is called 'epithelial', which consists of cells obtained from 3 conditions. I'm trying to take out all cells that are under the 'Healthy' condition.

I've done the below to check what column the metadata is stored at :

head(epithelial@meta.data)

Which returns :

              orig.ident nCount_RNA nFeature_RNA    stim integrated_snn_res.0.5 seurat_clusters
AACAAGACAGGACATG.1_1 SeuratProject      27811         5305 Healthy                      0               0
AACCATGTCATGCCAA.1_1 SeuratProject      17552         4351 Healthy                      0               0
AACCCAAAGGCCTGCT.1_1 SeuratProject      23151         4945 Healthy                      0               0
AAGACAAAGAAGTATC.1_1 SeuratProject      13419         3819 Healthy                      5               5
AATGACCCAAGAGGCT.1_1 SeuratProject      17281         4333 Healthy                      0               0
ACATCGAAGACATGCG.1_1 SeuratProject      38385         5917 Healthy                      4               4

Which means my condition is stored in the 4th column. I then run to try to replicate the above you've mentioned :

test.seurat <- subset(epithelial, subset = 4 == "Healthy")

and receive this error :

Error in FetchData(object = object, vars = expr.char[vars.use], cells = cells,  : 
  None of the requested variables were found:

Also for the fun of it tried to be inventive to run :

test.seurat <- subset(epithelial@meta.data$stim, subset = 'Healthy')

which returned

Error in subset.default(epithelial@meta.data$stim, subset = "Healthy") : 
  'subset' must be logical

If you could provide any help that would be most appreciated :( thank you.

ADD REPLY
3
Entering edit mode

Try: test.subset <- subset(x = epithelial, subset = stim == "Healthy")

ADD REPLY
0
Entering edit mode

Worked like a charm, I took out all the cells from the 'Healthy' condition but can now subset again with more specifics.

Thank you so much! V

ADD REPLY
0
Entering edit mode

Hi, Is it possible to select two conditions? I tried test.subset <- subset(x = epithelial, subset = stim == c("Healthy",'another_condition')). But I got much less cells by this. I also tried subset those two conditions and merge them. But I lose all the @graph info. Otherwise, is there a way to only analyse two certain conditions in an integrated seurat object which has multiple conditions? Thanks in advance!

ADD REPLY
5
Entering edit mode

This way worked for me:

test.subset <- subset(x = epithelial, subset = (stim == "Healthy" | stim == "another_condition"))

ADD REPLY
4
Entering edit mode

Try: seurat.subset <- subset(x = epithelial, subset = (stim == "Healthy" & stim == "Others") & (another_condition == "Ambigious"))

Save filtered subset

seurat.subset <- seurat.subset@meta.data

Check the result

table(seurat.subset$stim)

ADD REPLY

Login before adding your answer.

Traffic: 1872 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6