satijalab / seurat

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

Seurat V5 integration error: "Error in UseMethod(generic = "Assays", object = object) " #9454

Open cherrie-g opened 1 week ago

cherrie-g commented 1 week ago

Hi I have three single cell RNA seurat object to integrate. Each one is separated rds file. Actually I didn't find how to deal with this situation cause the tutorial load the processed data. So my analysis steps were like below:

file.list <- c('sample1.rds', 'sample2.rds', 'sample3.rds')
obj.list <- list()

for (i in 1:length(file.list)) {
    obj <- readRDS(file.list[[i]])
    obj.list[[i]] <- obj
}

obj5.merge <- merge(obj.list[[1]], c(obj.list[[2]], obj.list[[3]]), add.cell.ids = c('sample1', 'sample2', 'sample3'))

But at the split process, the first error occured:

> obj5.merge[["RNA"]] <- split(obj5.merge[["RNA"]], f = obj5.merge$orig.ident)
Error in `.local()`:
! The following layers are already split: ‘counts.sample1’,
• ‘counts.sample2’, ‘counts.sample3’ Please join before splitting
Run `rlang::last_trace()` to see where the error occurred.

And I saw that the obj5.merge@assay$RNA@layers had been split to three:

  ..@ assays      :List of 1
  .. ..$ RNA:Formal class 'Assay5' [package "SeuratObject"] with 8 slots
  .. .. .. ..@ layers    :List of 3
  .. .. .. .. ..$ counts.sample1:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. .. ..@ i       : int [1:26328192] 5 7 8 10 24 28 31 32 33 38 ...
  .. .. .. .. .. .. ..@ p       : int [1:6289] 0 3886 7528 11579 15480 21611 26307 32689 36531 39823 ...
  .. .. .. .. .. .. ..@ Dim     : int [1:2] 20574 6288
  .. .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. ..@ x       : num [1:26328192] 2 1 1 1 1 1 1 1 1 1 ...
  .. .. .. .. .. .. ..@ factors : list()
  .. .. .. .. ..$ counts.sample2:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. .. ..@ i       : int [1:26857450] 5 7 8 13 24 31 32 33 46 49 ...
  .. .. .. .. .. .. ..@ p       : int [1:6295] 0 3941 7643 11705 15610 21788 26595 33078 36973 40342 ...
  .. .. .. .. .. .. ..@ Dim     : int [1:2] 20807 6294
  .. .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. ..@ x       : num [1:26857450] 3 1 1 2 2 1 2 1 1 8 ...
  .. .. .. .. .. .. ..@ factors : list()
  .. .. .. .. ..$ counts.sample3:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. .. ..@ i       : int [1:12038142] 6 44 49 121 148 233 262 295 310 340 ...
  .. .. .. .. .. .. ..@ p       : int [1:3712] 0 784 4257 6571 9175 13300 16809 21548 24542 27983 ...
  .. .. .. .. .. .. ..@ Dim     : int [1:2] 18564 3711
  .. .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. ..@ x       : num [1:12038142] 1 1 1 1 2 1 1 4 1 2 ...
  .. .. .. .. .. .. ..@ factors : list()

And then I just go ahead to normalize, reduction and IntegratedLayers, the second error occured:

> obj5.integrated <- IntegrateLayers(object = obj5.merge, 
                              method = CCAIntegration, 
                              orig.reduction = "pca", 
                              new.reduction = "integrated.cca",
                              verbose = FALSE)
  |                                                  | 0 % ~calculating  Error in UseMethod(generic = "Assays", object = object) : 
  no applicable method for 'Assays' applied to an object of class "NULL"

I noticed that the layer name of mine seems to be different to ifnb data:

> obj5.merge
An object of class Seurat 
41602 features across 16293 samples within 2 assays 
Active assay: SCT (19712 features, 3000 variable features)
 3 layers present: counts, data, scale.data
 1 other assay present: RNA
 2 dimensional reductions calculated: pca, umap.unintegrated

Does someone know the reason of the two errors in my scripts? Is there any tutorial suit for my situation?

Thanks

cherrie-g commented 1 week ago

As a complement, I think it may be related with SCT. The layer before SCTransform is "3 layers present: counts.sample1, counts.sample2, counts.sample3", and after is "3 layers present: counts, data, scale.data".