This is a test version of Biostars. For the public version, visit https://www.biostars.org.
subsetting seurat object to have equal cell numbers in different samples

Hi, I am trying to subset a merged Seurat object (containing 5 different samples). Some samples have over 20,000 cells while some only have around 10,000 so I want to subset the merged object so that all samples have a similar cell distribution. I'm struggling to do this with the subset function and hope someone will be able to help me with this.

I can subset the whole object using this script but is there a way I can modify it to specify to subset each sample so that there are only 10,000 cells in each sample within the merged object?

subcells <- sample(Cells(filter_AS), size=10000, replace=F)
filter2_AS <- subset(x = filter_AS, cells = subcells)

Thanks so much!

single-cell scrnaseq seurat

Try

Idents(filter_AS) <- "orig.ident"
filter2_AS <- subset(filter_AS, downsample=1e4)

Replace 'orig.ident' with whatever metadata column is holding your sample identity.

0 answers

No answers yet.

Log in to answer this question.