Remove cells from Seurat based on a list
2
4
Entering edit mode
4.5 years ago
elb ▴ 260

Hi guys, is there a way to remove from Seurat3 object (all slots) a set of cells listed in a vector?

I tried:

my_object_without_cells = subset(object = my_dataset, cells = cells_to_be_removed)

but the cells are still there. I checked the n of cells and the n of genes and it is unchanged.

Thank you in advance

scRNA-seq Seurat • 21k views
ADD COMMENT
0
Entering edit mode

So, basically subsetting on colnames(obj) removes the cells from all slots of the SeuratObject? Meaning @data,@sct @meta.data etc?

Thank you very much

ADD REPLY
7
Entering edit mode
4.5 years ago
ATpoint 85k
## Example data:
pbmc_raw <- read.table(
  file = system.file('extdata', 'pbmc_raw.txt', package = 'Seurat'),
  as.is = TRUE
)
pbmc_small <- CreateSeuratObject(counts = pbmc_raw)

length(colnames(pbmc_small)) ## 80

## list the cells (=colnames) that you want to remove:
toRemove <- c("ATGCCAGAACGACT", "CATGGCCTGTGCAT")

## filter them out:
pbmc_filtered <- pbmc_small[,!colnames(pbmc_small) %in% toRemove]

length(colnames(pbmc_filtered)) ## 78
ADD COMMENT
0
Entering edit mode

Thank you very much! It works!

ADD REPLY
0
Entering edit mode

Thank you!!

ADD REPLY
0
Entering edit mode
4.5 years ago
dtm2451 ▴ 30

Looks to me like you should be providing the function with the reverse -- the cells you want to keep.

cells = colnames(my_dataset)[!(colnames(my_dataset) %in% cells_to_be_removed)]

should do the trick.

ADD COMMENT

Login before adding your answer.

Traffic: 1744 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