MarcElosua / SPOTlight

Spatial Transcriptomics Capture Location Deconvolution
https://marcelosua.github.io/SPOTlight
GNU General Public License v3.0
159 stars 25 forks source link

Error in `SeuratObject::GetAssayData()`: #91

Closed wang0430 closed 1 year ago

wang0430 commented 1 year ago

hi, I updated seurat to seurat5, and presented following error with SPOTlight function.

res = SPOTlight(x = sce,y = sample, groups = sce$celltype, mgs = mgs_df, hvg = hvg, weight_id = "mean.AUC", group_id = "cluster", gene_id = "gene")

Error in SeuratObject::GetAssayData(): ! assay must be one of "Spatial" or "SCT", not "counts".

wang0430 commented 1 year ago

Run rlang::last_trace(drop = FALSE) to see 4 hidden frames.

?SPOTlight rlang::last_trace(drop = FALSE) <error/rlang_error> Error in SeuratObject::GetAssayData(): ! assay must be one of "Spatial" or "SCT", not "counts".

Backtrace: ▆

  1. ├─SPOTlight::SPOTlight(...)
  2. │ └─SPOTlight::trainNMF(...)
  3. │ └─SPOTlight:::.extract_counts(y, assay_sp, slot_sp)
  4. │ ├─base::as.matrix(SeuratObject::GetAssayData(x, slot, assay))
  5. │ ├─SeuratObject::GetAssayData(x, slot, assay)
  6. │ └─SeuratObject:::GetAssayData.Seurat(assay = slot)
  7. │ └─rlang::arg_match(arg = assay, values = Assays(object = object))
  8. │ └─rlang::arg_match0(arg, values, error_arg, error_call = error_call)
  9. └─rlang:::stop_arg_match(w, values = x, error_arg = y, error_call = z)
  10. └─rlang::abort(msg, call = error_call, arg = error_arg)
HelenaLC commented 1 year ago
MarcElosua commented 1 year ago

Could you also print the output of Seurat::Assays(sce) and Seurat::Assays(sample) as well as sce and sample?

wang0430 commented 1 year ago

I updata the parameter and solved it. Thank you ! Happy

corinnestrawser commented 9 months ago

Hi! I've run SPOTlight in the past, but I've recently updated Seurat and now I'm having a similar issue: "Error in SeuratObject::GetAssayData(): ! assay must be one of "RNA" or "SCT", not "counts"."

Any help would be greatly appreciated!

backtrace: └─SPOTlight::SPOTlight(...) └─SPOTlight::trainNMF(...) └─SPOTlight:::.extract_counts(x, assay_sc, slot_sc) ├─base::as.matrix(SeuratObject::GetAssayData(x, slot, assay)) ├─SeuratObject::GetAssayData(x, slot, assay) └─SeuratObject:::GetAssayData.Seurat(assay = slot) Run rlang::last_trace(drop = FALSE) to see 4 hidden frames.

my code:

merged <- readRDS("./objects/visium_merged_scrna_annotated.rds") rna <- readRDS("./objects/scrna_merged.rds") split <- SplitObject(merged, split.by = "sample") Idents(rna) <- "orig.ident" # use only one sample sub <- subset(rna, idents = c("Het")) # use only one sample hvg <- sub@assays$SCT@var.features Idents(sub) <- "clusterid" mgs <- FindAllMarkers(sub, assay = "SCT", test.use = "roc") mgs_df <- mgs[mgs$myAUC >= 0.8,] Idents(sub) <- "clusterid" sub <- subset(sub, downsample = 20) spotlight <- list() for (sample in names(split)){ spe <- split[[sample]] DefaultAssay(spe) <- "Spatial" DefaultAssay(sub) <- "SCT" res <- SPOTlight( x = sub, y = spe, groups = sub$clusterid, mgs = mgs_df, hvg = hvg, weight_id = "myAUC", group_id = "cluster", gene_id = "gene", assay_sc = "SCT", slot_sc = "counts", assay_sp = "Spatial", slot_sp = "counts") spotlight[[sample]] <- res }`

checked available assays Seurat::Assays(sub) [1] "RNA" "SCT" Seurat::Assays(spe) [1] "Spatial" "SCT"

sessionInfo: R version 4.3.1 (2023-06-16) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Amazon Linux 2 other attached packages: [1] lubridate_1.9.2 forcats_1.0.0
[3] stringr_1.5.0 dplyr_1.1.2
[5] purrr_1.0.2 readr_2.1.4
[7] tidyr_1.3.0 tibble_3.2.1
[9] ggplot2_3.4.3 tidyverse_2.0.0
[11] scran_1.28.2 scuttle_1.10.3
[13] SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.2 [15] GenomicRanges_1.52.0 GenomeInfoDb_1.36.1
[17] IRanges_2.34.1 S4Vectors_0.38.1
[19] MatrixGenerics_1.12.3 matrixStats_1.0.0
[21] SPOTlight_1.4.1 Biobase_2.60.0
[23] BiocGenerics_0.46.0 Seurat_5.0.1
[25] SeuratObject_5.0.1 sp_2.0-0
[27] BiocManager_1.30.22

MarcElosua commented 9 months ago

Hi @corinnestrawser this is due to Seurat V5 updated its data accessor functions. I will update this in the next release, in the meantime you can pass the count matrix instead of the whole Seurat object!