seurat
seurat copied to clipboard
FindIntegrationAnchors() returns "no applicable method for 'Assays' applied to an object of class "NULL""
Hello, I have a list of seurat objects that I read into a list. Then I merge them, split them by experimental condition, perform standard steps but when running the function FindIntegrationAnchors(), I get:
Error in UseMethod(generic = "Assays", object = object) : no applicable method for 'Assays' applied to an object of class "NULL"
However, I see that the class of the merged object is "RNA", so I don't get why I get class NULL afterwards.
Please help, I have been stacked in this issue for several days.
Below you can see the script
Thank you very much !
library(Seurat) library(dplyr) library(ggplot2) library(SeuratObject) library(future.apply)
workDir <- "/project/lbarreiro/USERS/lucas/czi/data/scrna/seurat/human_iav_tcruzi" setwd(workDir)
# Read first 4 files:
file_paths <- list.files(workDir, pattern = "^seuratObj4_[1-4]\.rds$", full.names = TRUE)
# Initialize an empty list to store Seurat objects
seurat_list <- future_lapply(file_paths, readRDS)
# Merge the Seurat objects concurrently
merged_obj <- Reduce(merge, seurat_list) # Takes ~20 min
# class(merged_obj) # Seurat
slotNames(merged_obj)
#[1] "assays" "meta.data" "active.assay" "active.ident" "graphs"
#[6] "neighbors" "reductions" "images" "project.name" "misc"
#[11] "version" "commands" "tools"
# > Assays(merged_obj)
# [1] "RNA"
# split the dataset into a list of four seurat objects (C1, C2, C3, C4)
ifnb.list <- SplitObject(merged_obj, split.by = "expCond1") # very fast
# class(ifnb.list) # list
# normalize and identify variable features for each dataset independently
ifnb.list <- lapply(X = ifnb.list, FUN = function(x) { x <- NormalizeData(x) x <- FindVariableFeatures(x, selection.method = "vst", nfeatures = 2000) })
# class(ifnb.list) # list
# select features that are repeatedly variable across datasets for integration run PCA on each
# dataset using these features
features <- SelectIntegrationFeatures(object.list = ifnb.list) # class(features) # "character"
ifnb.list <- lapply(X = ifnb.list, FUN = function(x) { x <- ScaleData(x, features = features, verbose = FALSE) x <- RunPCA(x, features = features, verbose = FALSE) }) # class(ifnb.list) # list
# Active assays:
assayNames(ifnb.list)
immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, anchor.features = features, reduction = "rpca", assay = "RNA", normalization.method = "LogNormalize")
Error in UseMethod(generic = "Assays", object = object) : no applicable method for 'Assays' applied to an object of class "NULL"
Having a similar issue with the following:
> obj <- IntegrateLayers(
+ object = obj,
+ method = RPCAIntegration,
+ normalization.method = "SCT",
+ verbose = F
+ )
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s
| | 0 % ~calculating Error in UseMethod(generic = "Assays", object = object) :
no applicable method for 'Assays' applied to an object of class "NULL"
Based on tutorial https://satijalab.org/seurat/articles/seurat5_integration#perform-streamlined-one-line-integrative-analysis
I don't want to hijack this issue. I'm not expecting a reply to my own issue here. I mainly post here to be notified of replies to the issue reported above, but I thought that maybe the maintainers might be interested in knowing that the issue might affect more than one use case.
Version of Seurat packages
P Seurat * 5.0.3 2024-03-18 [?] CRAN (R 4.3.1)
P SeuratData * 0.2.2.9001 2024-04-19 [?] Github (satijalab/seurat-data@4dc08e0)
SeuratObject * 5.0.1 2023-11-17 [1] CRAN (R 4.3.1)
P SeuratWrappers * 0.3.5 2024-04-19 [?] Github (satijalab/seurat-wrappers@8d46d6c)
Hi - to the original issue, do you run into the same issue when running the vignette with the ifnb dataset, and/or would you be able to create a reproducible example? Could you check the class() of the individual assays before running FindIntegrationAnchors by running class(ifnb.list[1]
etc.?
Shall I open another issue for my related issue? only asking as the original poster seems unresponsive here, so there isn't much for me to track. On the other hand, that would result in duplicated issues reporting the same error message, which I also don't like doing.
I am also having the same problem as kevinrue.
Hi guys @kevinrue @SMP7UC , this problems might because only one layer existed in the seurat project.
I suggest use split()
to splite the data to different layers and re-run the NormalizeData() ... it will solve.
such as:
combined@assays$RNA <-split(combined@assays$RNA,f=combined$samples)
I'm about to try that but in that case I'll point out that the tutorial https://satijalab.org/seurat/articles/seurat5_integration#perform-streamlined-one-line-integrative-analysis is a bit confusing (to me) then.
It runs
obj <- JoinLayers(obj)
obj
Right before the integration using SCT data
options(future.globals.maxSize = 3e+09)
obj <- SCTransform(obj)
obj <- RunPCA(obj, npcs = 30, verbose = F)
obj <- IntegrateLayers(
object = obj,
method = RPCAIntegration,
normalization.method = "SCT",
verbose = F
)
obj <- FindNeighbors(obj, dims = 1:30, reduction = "integrated.dr")
obj <- FindClusters(obj, resolution = 2)
which seems to contradict your suggestion of splitting the layers (although I agree with you more than the vignette here)
I can confirm that I got integration usign SCT to work just now. It's too long (a month) since my original attempt and I haven't kept the whole notebook, so I can only assume that I was following the tutorial to the letter and joining layers before running that last bit of integration. I'm not sure how the tutorial gets away with it, but today skipping the joining step worked just fine. Thanks!