I'm trying to subset my Seurat object (hs_mt
) based on mitochondrial percentage (mt_perc). This Seurat object was split to only include human cells using CollapseSpeciesExpressionMatrix
previously.
min(hs_mt$nCount_RNA)
[1] 501
As an example, the minimum value in nCount_RNA as above is 501.
I've tried all the different code options, but it doesn't seem to work. For whatever reason, once I subset, the values in my nFeature_RNA and nCount_RNA change - this only seems to be happening when the original Seurat object with all cell types is split into two different objects according to the species (human cells and mouse cells)
filtered_hs_mt <- subset(hs_mt, mt_ratio < 20)
filtered_hs_mt2 <- subset(x = hs_mt, subset = mt_perc < 20)
Idents(hs_mt) <- "mt_perc"
filtered_hs_mt3 <- subset(hs_mt, idents < 20)
filtered_hs_mt4 <- subset(hs_mt, subset = "mt_perc" < 20)
filtered_hs_mt5 = hs_mt[, hs_mt$mt_perc < 20]
filtered_hs_mt6 <- hs_mt[ , rownames(hs_mt@meta.data)[hs_mt@meta.data$mt_perc <= 0.20]]
# trying to subset based on the names of the cells
length(colnames(hs_mt))
mDat_hs <- hs_mt@meta.data
mDat_hs <- mDat_hs %>%
rownames_to_column("cells")
cells_to_remove_hs <- mDat_hs %>%
filter(mt_perc > 20)
# list the cells (= colnames) that you want to remove
# (from https://www.biostars.org/p/440623/#9569334)
toRemove_hs <- cells_to_remove_hs$cells
# filter them out:
filtered_mt_hs <- hs_mt[,!colnames(hs_mt) %in% toRemove_hs]
All the above give the same exact output:
min(filtered_mt_hs$nCount_RNA)
[1] 0
As an example, the values for cell H3_AAAGAACGTCCCACGA-1:
original:
filtered:
I'm at my wit's end on what I can do to filter based on this column, without having the values in other columns change (which I don't even understand why is happeneing)