seurat
seurat copied to clipboard
Subset or DietSeurat do not update assay RNA meta.data in Seurat V5
I'm trying to subset a Seurat V5 object using functions subset
or DietSeurat
and keeping only the variable features.
The problem is that the meta.data of the assay do not have the same genes as the object itself.
I'm showing an example using the pbmcsca
data
pbmcsca <- SeuratData::LoadData("pbmcsca")
pbmcsca <- Seurat::NormalizeData(pbmcsca)
pbmcsca <- Seurat::FindVariableFeatures(pbmcsca)
pbmcsca <- Seurat::ScaleData(pbmcsca)
var1 <- VariableFeatures(pbmcsca)
head(var1)
length(var1)
[1] "IGHM" "THBS1" "PPBP" "TREML1" "SPARC" "PSAP"
[1] 2000
Now I filter:
pbmcsca <- Seurat::DietSeurat(pbmcsca, features = var1)
All the variable features are in the new seurat object
length(intersect(var1, rownames(pbmcsca)))
setdiff(var1, rownames(pbmcsca))
[1] 2000
character(0)
All seems good but when I check the meta.data of the assay, the genes present there are not the same as the variable features.
length(intersect(var1, pbmcsca[["RNA"]]@meta.data$var.features))
table(pbmcsca[["RNA"]]@meta.data$vf_vst_counts_variable)
[1] 174
FALSE TRUE
1826 174
Only 174 Variable Features are present.
For example, in the top 12 Variable Features only the 12 is present in the assay meta.data.
head(var1, n = 12) %in% pbmcsca[["RNA"]]@meta.data$var.features
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
How is that possible ?
Am I missing something ?
Same thing happens with subset
Thank you for your good work.
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.3.2 (2023-10-31)
os Ubuntu 22.04.4 LTS
system x86_64, linux-gnu
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Paris
date 2024-02-29
rstudio 2023.12.1+402 Ocean Storm (desktop)
pandoc NA
─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
ifnb.SeuratData * 3.1.0 2023-12-15 [1] local
pbmcref.SeuratData * 1.0.0 2023-12-05 [1] local
pbmcsca.SeuratData * 3.0.0 2023-12-05 [1] local
Seurat * 5.0.1 2023-11-17 [1] CRAN (R 4.3.2)
SeuratData * 0.2.2.9001 2024-01-08 [1] Github (satijalab/seurat-data@0cce240)
SeuratObject * 5.0.1 2023-11-17 [1] CRAN (R 4.3.2)
sp * 2.1-3 2024-01-30 [1] CRAN (R 4.3.2)
Hi @hermespara,
Not member of dev team but hopefully can be helpful. So I tested two and appears as you describe that the assay meta.data isn't being subsetted correctly.
However, I would note that shouldn't necessarily be an issue. Because anytime you are subsetting object in any way you should be finding variable features again, because the features that are variable may be different once you have removed features or cells etc. When you re-run finding variable features it remakes that assay meta.data slot correctly.
Best, Sam
Hi @samuel-marsh, Thank you for your answer. I agree with you but it can be confusing that the meta.data of the assay do not describe the genes of the assay. Cheers, Hermes
Thank you for this bug report! We have investigated and agree this is an issue; we will address it in a future update.
Hi! I'm encountering a similar issue in Seurat 5.0.2 (not present in v4.3): after using subset to remove a set of features/genes, the object meta.data is not updated (i.e the nFeatures_RNA and nCounts_RNA are no longer correct). Is there a way to update meta.data after a subset command?
Hi @andreiprodan,
the issue above was describing issue with assay meta data and not object meta data (where nCount nFeature are stored. Can you provide a reproducible example of your issue?
Best, Sam