Skip to content

ScaleData() fails with “all cells in assays must be present in the Seurat object” error #9860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BenjaminDEMAILLE opened this issue Apr 29, 2025 · 5 comments

Comments

@BenjaminDEMAILLE
Copy link

Title: ScaleData() fails with “all cells in assays must be present in the Seurat object” error

Description:
Calling ScaleData() on a subsetted Seurat object leads to an error about assay cell mismatch, even though the object was previously subsetted and appears valid.

Code to reproduce:

NeuroProx_sub <- ScaleData(NeuroProx_sub, assay = "RNA", features = markers_f$gene)

Output:

Centering and scaling data matrix
  |==========================================================================================| 100%
Error in validObject(object = x) : 
  invalid classSeuratobject: all cells in assays must be present in the Seurat object
Expected behavior:
ScaleData() should complete without error on a valid, subsetted Seurat object if the features and assay are correctly specified.

Troubleshooting attempted:

Verified that markers_f$gene contains genes present in the RNA assay.
Checked that NeuroProx_sub is a valid Seurat object using ValidObject().
Assay "RNA" exists and is the default assay in NeuroProx_sub.
Environment:

Seurat version: 5.3
SeuratObject version: 5.1
R version: 4.5.0

Suggestion:
The error message suggests a mismatch between the cells in the RNA assay and the Seurat object. This might be due to residual cells in the assay slot after subsetting. If so, ScaleData() should better handle such cases or validate the object earlier with a more informative message.

@samuel-marsh
Copy link
Collaborator

samuel-marsh commented Apr 29, 2025

Hi @BenjaminDEMAILLE,

Can you provide reproducible example (ideally using public object (eg from SeuratData package)? I cannot replicate issues currently in my testing suggesting it may be issue with the Seurat object you are using.

Best,
Sam

@BenjaminDEMAILLE
Copy link
Author

BenjaminDEMAILLE commented Apr 29, 2025 via email

@BenjaminDEMAILLE
Copy link
Author

Hi @BenjaminDEMAILLE,

Can you provide reproducible example (ideally using public object (eg from SeuratData package)? I cannot replicate issues currently in my testing suggesting it may be issue with the Seurat object you are using.

Best, Sam

The full code is

NeuroProx_sub <- subset(NeuroProx, downsample = 1000)
markers_f
NeuroProx_sub <- ScaleData(NeuroProx_sub, assay = "RNA", features = markers_f$gene)
Centering and scaling data matrix
  |===========================================================================================================| 100%
Error in validObject(object = x) : 
  invalid classSeuratobject: all cells in assays must be present in the Seurat object

@BenjaminDEMAILLE
Copy link
Author

The problem is due to the subset :

> NeuroProx <- NeuroProx[, NeuroProx$Phase == "S"]
> validObject(NeuroProx)
Error in validObject(NeuroProx) : 
  invalid classSeuratobject: all cells in assays must be present in the Seurat object
> NeuroProx <- qread("20250401_NeuroProx_velo.qs", nthreads = detectCores())
> validObject(NeuroProx)
[1] TRUE

@samuel-marsh
Copy link
Collaborator

Ok thanks. I’ll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants