satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.25k stars 904 forks source link

scVIIntegration and FastMNNIntegration failed after #8631

Open sabrina0701 opened 6 months ago

sabrina0701 commented 6 months ago

In seurat 5, all run quite well with logNormalize, but got an error after I changed to SCT normalization with FastMNNIntegration and scVIIntegration. The codes and errors I got please find below:

combined<-readRDS("LCNEC_filter.rds") combined[["RNA"]] <- split(combined[["RNA"]], f = combined$patient_ID) combined <- SCTransform(combined) combined <- RunPCA(combined)

combined <- IntegrateLayers( object = combined, method = FastMNNIntegration, new.reduction = "integrated.mnn", normalization.method = "SCT", verbose = FALSE )

Error in checkBatchConsistency(batches, cells.in.columns = TRUE) : number of rows is not the same across batches (see batch "normalization.method")

combined <- IntegrateLayers( object = combined, method = scVIIntegration, new.reduction = "integrated.scvi", normalization.method = "SCT", conda_env = "miniconda3/envs/Seurat", verbose = FALSE )

Error in UseMethod(generic = "JoinLayers", object = object) : no applicable method for 'JoinLayers' applied to an object of class "c('SCTAssay', 'Assay', 'KeyMixin')"

CCA, rPCA and harmony work well with SCT normalization, does it mean FastMNN and scVI can't run with SCT normalization?

Thanks!

jdrnevich commented 6 months ago

I came across your issue while searching for answers for my related problems with SCTransform and the new v5 layers. I think the issue is that SCTransform internally calls sctransform::vst which has a parameter min_cells=5 by default. Which means when SCTransform is run separately for each sample, it only uses genes that are expressed in at least 5 cells in that sample. So the set of genes used is going to differ for each sample, which is what I think may be causing the number of rows is not the same across batches (see batch "normalization.method") error that you're seeing. SCTransform somehow returns values for all genes in counts and data slots in the SCT assay, but the scale.data slot only has values for genes that are expressed in at least 5 cells in every single sample! I stumbled upon this after trying to make heatmaps of some top DE genes, only to find they weren't in the scale.data. Which boggles my mind because genes that aren't expressed in any cells in one group but many cells in another group are exactly the genes you want to find!

The second error for scVIIntegration of no applicable method for 'JoinLayers' applied to an object of class "c('SCTAssay', 'Assay', 'KeyMixin') might be due to the fact that the SCT assay is no longer split into layers by sample, but instead it's back to count/data/scale.data layers.

I have no idea of the inner workings of SCTransform, vst, or the FastMNNIntegration/scVIIntegration to even suggest any fixes. Just hope this points the people that do to the correct places!

artsvendsen commented 4 months ago

I'm getting the same error, have you managed to figure out a work around?

NBIX-Brandon-Sos commented 3 months ago

Also getting the same error with SCT normalization, when running:

integObj %>% IntegrateLayers( object = ., normalization.method = "SCT", method = FastMNNIntegration,

orig.reduction = "pca",

    new.reduction = "iFMNN"
)

Error in checkBatchConsistency(batches, cells.in.columns = TRUE) : number of rows is not the same across batches (see batch "normalization.method")

Looks like there is an issue in fastMNN retrieving the S4 objects and its only 1 object is getting retrieved (was using 2 in my test). Might be because layers are different between SCT assay and RNA assay and not getting accounted for correctly? In RNA assay I see 5 layers for 2 samples, in SCT assay I see 3 layers.

When running trace, the batches object only has 1 object in it, and the error is thrown by checkBatchConsistency. In the meantime I'll just be running with RNA assay with log normalization and scaling

trace('fastMNN', edit=T)

batches <- .unpackLists(...) checkBatchConsistency(batches, cells.in.columns = TRUE)

Or could it be SCT normalization can't be run with FastMNN integration? Thank you!

Mincana-Huang commented 2 months ago

I also encountered the same problem, did you solve it?

NBIX-Brandon-Sos commented 2 months ago

Haven't looked into it more, I just run the RNA assay with log normalization and scaling for FastMNN right now

kathbosc commented 1 week ago

I have the same problem using the SCT assay for fastMNN integration..