TransWikia.com

Subsetting from seurat object based on orig.ident?

Bioinformatics Asked on August 25, 2021

I am pretty new to Seurat. I want to subset from my original seurat object (BC3) meta.data based on orig.ident. however, when i use subset(), it returns with Error.

ER_HER_P <- subset(BC3, idents = c("BC03"))
Error: No cells found

table(Idents(BC3))
BC01   BC02   BC03 BC03LN   BC04   BC05   BC06   BC07 BC07LN   BC08   BC09   BC10   BC11 
21     50     33     51     42     74     15     48     52     21     55     13     11 

There are 33 cells under the identity. I checked the active.ident to make sure the identity has not shifted to any other column, but still I am getting the error?

head([email protected])
[1] BC01 BC01 BC01 BC01 BC01 BC01
Levels: BC01 BC02 BC03 BC03LN BC04 BC05 BC06 BC07 BC07LN BC08 BC09 BC10 BC11

2 Answers

A bit too long to type as a comment.

To use subset on a Seurat object, (see ?subset.Seurat) , you have to provide:

Subset a Seurat object

Description:

     Subset a Seurat object

Usage:

     ## S3 method for class 'Seurat'
     x[i, j, ...]
     
     ## S3 method for class 'Seurat'
     subset(x, subset, cells = NULL, features = NULL, idents = NULL, ...)
     
Arguments:

       x: Seurat object to be subsetted

i, features: A vector of features to keep

j, cells: A vector of cells to keep

So you either use the matrix to subset:

library(Seurat)
data(pbmc_small)
Idents(pbmc_small) = paste0("BC",Idents(pbmc_small))
table(Idents(pbmc_small))

BC0 BC2 BC1 
 36  19  25

test = pbmc_small[,Idents(pbmc_small)=="BC0"]
table(Idents(test))

BC0 
 36 

Or you provide the cells:

subset(pbmc_small,cells=colnames(pbmc_small)[Idents(pbmc_small)=="BC0"])
An object of class Seurat 
230 features across 36 samples within 1 assay 
Active assay: RNA (230 features, 20 variable features)
 2 dimensional reductions calculated: pca, tsne

What you have should work, but try calling the actual function (in case there are packages that clash):

Seurat:::subset.Seurat(pbmc_small,idents="BC0")

An object of class Seurat 
230 features across 36 samples within 1 assay 
Active assay: RNA (230 features, 20 variable features)
 2 dimensional reductions calculated: pca, tsne

Answered by StupidWolf on August 25, 2021

If you are going to use idents like that, make sure that you have told the software what your default ident category is.

This works for me, with the metadata column being called "group", and "endo" being one possible group there.

Idents(combined.all) <- "group"
endo_subset <- subset(combined.all, idents = c("endo"))

I think this is basically what you did, but I think this looks a little nicer

Answered by swbarnes2 on August 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP