RGLab / MAST

Tools and methods for analysis of single cell assay data in R
224 stars 57 forks source link

bug: MAST returns error after Seurat SCTransform, v2 regularization #175

Closed grhogg closed 1 year ago

grhogg commented 1 year ago

Hello,

Thank you for your amazing package!

I have been running into an error when trying to run FindMarkers on a Seurat Object with the MAST algorithm, using their newer v2 regularization pipeline. Any help would be greatly appreciated.

error is generated after calling MAST in findmarkers. Other tests like Wilcox still work fine

Error in .nextMethod(.Object = .Object, ... = ..., design = design) : invalid name for slot of class “BayesGLMlike”: norm.method

R base 4.2.1 Seurat version 4.2 Mast version 1.22 SCTransform version 0.3.5

Example with Seurat Dataset:


library(Seurat)
library(SeuratData)
library(patchwork)
library(dplyr)
library(ggplot2)
library(MAST)

InstallData("ifnb")

# load dataset

LoadData("ifnb")

# split the dataset into a list of two seurat objects (stim and CTRL)

ifnb.list <- SplitObject(ifnb, split.by = "stim")

ctrl <- ifnb.list[["CTRL"]]
stim <- ifnb.list[["STIM"]]

ctrl <- SCTransform(ctrl, vst.flavor = "v2")
stim <- SCTransform(stim, vst.flavor = "v2") 

ifnb.list <- list(ctrl = ctrl, stim = stim)

#integrate datasets

features <- SelectIntegrationFeatures(object.list = ifnb.list, nfeatures = 3000)
ifnb.list <- PrepSCTIntegration(object.list = ifnb.list, anchor.features = features)
immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, normalization.method = "SCT",
                                         anchor.features = features)
immune.combined.sct <- IntegrateData(anchorset = immune.anchors, normalization.method = "SCT")

#assign stim conditions

immune.combined.sct$celltype.stim <- paste(immune.combined.sct$seurat_annotations, immune.combined.sct$stim,
                                           sep = "_")
Idents(immune.combined.sct) <- "celltype.stim"

#correct SCT Counts

immune.combined.sct <- PrepSCTFindMarkers(immune.combined.sct)

#find Markers with MAST algorithm

b.interferon.response <- FindMarkers(immune.combined.sct, assay = "SCT", ident.1 = "B_STIM", ident.2 = "B_CTRL",
                                      test.use = "MAST")

Error in .nextMethod(.Object = .Object, ... = ..., design = design) : invalid name for slot of class “BayesGLMlike”: norm.method

sessionInfo()

_R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages: [1] stats4 stats graphics grDevices utils datasets methods base

other attached packages: [1] ifnb.SeuratData_3.1.0 SeuratData_0.2.2 MAST_1.22.0
[4] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0
[7] GenomicRanges_1.48.0 GenomeInfoDb_1.32.4 IRanges_2.30.1
[10] S4Vectors_0.34.0 BiocGenerics_0.42.0 MatrixGenerics_1.8.1
[13] matrixStats_0.62.0 ggplot2_3.3.6 dplyr_1.0.10
[16] patchwork_1.1.2 sp_1.5-0 SeuratObject_4.1.2
[19] Seurat_4.2.0

loaded via a namespace (and not attached): [1] plyr_1.8.7 igraph_1.3.5 lazyeval_0.2.2 splines_4.2.1
[5] listenv_0.8.0 scattermore_0.8 usethis_2.1.6 digest_0.6.29
[9] htmltools_0.5.3 fansi_1.0.3 magrittr_2.0.3 memoise_2.0.1
[13] tensor_1.5 cluster_2.1.3 ROCR_1.0-11 remotes_2.4.2
[17] globals_0.16.1 spatstat.sparse_2.1-1 prettyunits_1.1.1 colorspace_2.0-3
[21] rappdirs_0.3.3 ggrepel_0.9.1 xfun_0.33 RCurl_1.98-1.8
[25] callr_3.7.2 crayon_1.5.2 jsonlite_1.8.0 progressr_0.11.0
[29] spatstat.data_2.2-0 survival_3.3-1 zoo_1.8-11 glue_1.6.2
[33] polyclip_1.10-0 gtable_0.3.1 zlibbioc_1.42.0 XVector_0.36.0
[37] leiden_0.4.3 DelayedArray_0.22.0 pkgbuild_1.3.1 future.apply_1.9.1
[41] abind_1.4-5 scales_1.2.1 DBI_1.1.3 spatstat.random_2.2-0
[45] miniUI_0.1.1.1 Rcpp_1.0.9 viridisLite_0.4.1 xtable_1.8-4
[49] reticulate_1.26 spatstat.core_2.4-4 profvis_0.3.7 htmlwidgets_1.5.4
[53] httr_1.4.4 RColorBrewer_1.1-3 ellipsis_0.3.2 ica_1.0-3
[57] urlchecker_1.0.1 pkgconfig_2.0.3 uwot_0.1.14 deldir_1.0-6
[61] utf8_1.2.2 tidyselect_1.1.2 rlang_1.0.6 reshape2_1.4.4
[65] later_1.3.0 munsell_0.5.0 tools_4.2.1 cachem_1.0.6
[69] cli_3.4.1 generics_0.1.3 devtools_2.4.4 ggridges_0.5.4
[73] evaluate_0.16 stringr_1.4.1 fastmap_1.1.0 yaml_2.3.5
[77] goftest_1.2-3 processx_3.7.0 knitr_1.40 fs_1.5.2
[81] fitdistrplus_1.1-8 purrr_0.3.4 RANN_2.6.1 sparseMatrixStats_1.8.0
[85] pbapply_1.5-0 future_1.28.0 nlme_3.1-157 mime_0.12
[89] compiler_4.2.1 rstudioapi_0.14 plotly_4.10.0 curl_4.3.2
[93] png_0.1-7 spatstat.utils_2.3-1 tibble_3.1.8 glmGamPoi_1.8.0
[97] stringi_1.7.8 ps_1.7.1 rgeos_0.5-9 lattice_0.20-45
[101] Matrix_1.5-1 vctrs_0.4.2 pillar_1.8.1 lifecycle_1.0.2
[105] spatstat.geom_2.4-0 lmtest_0.9-40 RcppAnnoy_0.0.19 bitops_1.0-7
[109] data.table_1.14.2 cowplot_1.1.1 irlba_2.3.5 httpuv_1.6.6
[113] R6_2.5.1 promises_1.2.0.1 KernSmooth_2.23-20 gridExtra_2.3
[117] parallelly_1.32.1 sessioninfo_1.2.2 codetools_0.2-18 MASS_7.3-57
[121] assertthat_0.2.1 pkgload_1.3.0 rprojroot_2.0.3 withr_2.5.0
[125] sctransform_0.3.5 GenomeInfoDbData_1.2.8 mgcv_1.8-40 parallel_4.2.1
[129] grid_4.2.1 rpart_4.1.16 tidyr_1.2.1 DelayedMatrixStats_1.18.1 [133] rmarkdown_2.16 Rtsne_0.16 shiny1.7.2

amcdavid commented 1 year ago

There's a typo or invalid argument being passed to MAST from FindAllMarkers, a bug in Seurat. Might get a hint about where this is happening by looking at the traceback().

On Fri, Sep 30, 2022 at 10:45 AM grhogg @.***> wrote:

Hello,

Thank you for your amazing package!

I have been running into an error when trying to run FindMarkers on a Seurat Object with the MAST algorithm, using their newer v2 regularization pipeline. Any help would be greatly appreciated.

error is generated after calling MAST in findmarkers. Other tests like Wilcox still work fine

Error in .nextMethod(.Object = .Object, ... = ..., design = design) : invalid name for slot of class “BayesGLMlike”: norm.method

R base 4.2.1 Seurat version 4.2 Mast version 1.22 SCTransform version 0.3.5

Example with Seurat Dataset:

library(Seurat)

library(SeuratData)

library(patchwork)

library(dplyr)

library(ggplot2)

library(MAST)

InstallData("ifnb")

load dataset

LoadData("ifnb")

split the dataset into a list of two seurat objects (stim and CTRL)

ifnb.list <- SplitObject(ifnb, split.by = "stim")

ctrl <- ifnb.list[["CTRL"]]

stim <- ifnb.list[["STIM"]]

ctrl <- SCTransform(ctrl, vst.flavor = "v2")

stim <- SCTransform(stim, vst.flavor = "v2")

ifnb.list <- list(ctrl = ctrl, stim = stim)

integrate datasets

features <- SelectIntegrationFeatures(object.list = ifnb.list, nfeatures = 3000)

ifnb.list <- PrepSCTIntegration(object.list = ifnb.list, anchor.features = features)

immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, normalization.method = "SCT",

                                     anchor.features = features)

immune.combined.sct <- IntegrateData(anchorset = immune.anchors, normalization.method = "SCT")

assign stim conditions

immune.combined.sct$celltype.stim <- paste(immune.combined.sct$seurat_annotations, immune.combined.sct$stim,

                                       sep = "_")

Idents(immune.combined.sct) <- "celltype.stim"

correct SCT Counts

immune.combined.sct <- PrepSCTFindMarkers(immune.combined.sct)

find Markers with MAST algorithm

b.interferon.response <- FindMarkers(immune.combined.sct, assay = "SCT", ident.1 = "B_STIM", ident.2 = "B_CTRL",

                                  test.use = "MAST")

Error in .nextMethod(.Object = .Object, ... = ..., design = design) : invalid name for slot of class “BayesGLMlike”: norm.method

sessionInfo()

_R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C [5] LC_TIME=English_United States.utf8

attached base packages: [1] stats4 stats graphics grDevices utils datasets methods base

other attached packages: [1] ifnb.SeuratData_3.1.0 SeuratData_0.2.2 MAST_1.22.0 [4] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0 [7] GenomicRanges_1.48.0 GenomeInfoDb_1.32.4 IRanges_2.30.1 [10] S4Vectors_0.34.0 BiocGenerics_0.42.0 MatrixGenerics_1.8.1 [13] matrixStats_0.62.0 ggplot2_3.3.6 dplyr_1.0.10 [16] patchwork_1.1.2 sp_1.5-0 SeuratObject_4.1.2 [19] Seurat_4.2.0

loaded via a namespace (and not attached): [1] plyr_1.8.7 igraph_1.3.5 lazyeval_0.2.2 splines_4.2.1 [5] listenv_0.8.0 scattermore_0.8 usethis_2.1.6 digest_0.6.29 [9] htmltools_0.5.3 fansi_1.0.3 magrittr_2.0.3 memoise_2.0.1 [13] tensor_1.5 cluster_2.1.3 ROCR_1.0-11 remotes_2.4.2 [17] globals_0.16.1 spatstat.sparse_2.1-1 prettyunits_1.1.1 colorspace_2.0-3 [21] rappdirs_0.3.3 ggrepel_0.9.1 xfun_0.33 RCurl_1.98-1.8 [25] callr_3.7.2 crayon_1.5.2 jsonlite_1.8.0 progressr_0.11.0 [29] spatstat.data_2.2-0 survival_3.3-1 zoo_1.8-11 glue_1.6.2 [33] polyclip_1.10-0 gtable_0.3.1 zlibbioc_1.42.0 XVector_0.36.0 [37] leiden_0.4.3 DelayedArray_0.22.0 pkgbuild_1.3.1 future.apply_1.9.1 [41] abind_1.4-5 scales_1.2.1 DBI_1.1.3 spatstat.random_2.2-0 [45] miniUI_0.1.1.1 Rcpp_1.0.9 viridisLite_0.4.1 xtable_1.8-4 [49] reticulate_1.26 spatstat.core_2.4-4 profvis_0.3.7 htmlwidgets_1.5.4 [53] httr_1.4.4 RColorBrewer_1.1-3 ellipsis_0.3.2 ica_1.0-3 [57] urlchecker_1.0.1 pkgconfig_2.0.3 uwot_0.1.14 deldir_1.0-6 [61] utf8_1.2.2 tidyselect_1.1.2 rlang_1.0.6 reshape2_1.4.4 [65] later_1.3.0 munsell_0.5.0 tools_4.2.1 cachem_1.0.6 [69] cli_3.4.1 generics_0.1.3 devtools_2.4.4 ggridges_0.5.4 [73] evaluate_0.16 stringr_1.4.1 fastmap_1.1.0 yaml_2.3.5 [77] goftest_1.2-3 processx_3.7.0 knitr_1.40 fs_1.5.2 [81] fitdistrplus_1.1-8 purrr_0.3.4 RANN_2.6.1 sparseMatrixStats_1.8.0 [85] pbapply_1.5-0 future_1.28.0 nlme_3.1-157 mime_0.12 [89] compiler_4.2.1 rstudioapi_0.14 plotly_4.10.0 curl_4.3.2 [93] png_0.1-7 spatstat.utils_2.3-1 tibble_3.1.8 glmGamPoi_1.8.0 [97] stringi_1.7.8 ps_1.7.1 rgeos_0.5-9 lattice_0.20-45 [101] Matrix_1.5-1 vctrs_0.4.2 pillar_1.8.1 lifecycle_1.0.2 [105] spatstat.geom_2.4-0 lmtest_0.9-40 RcppAnnoy_0.0.19 bitops_1.0-7 [109] data.table_1.14.2 cowplot_1.1.1 irlba_2.3.5 httpuv_1.6.6 [113] R6_2.5.1 promises_1.2.0.1 KernSmooth_2.23-20 gridExtra_2.3 [117] parallelly_1.32.1 sessioninfo_1.2.2 codetools_0.2-18 MASS_7.3-57 [121] assertthat_0.2.1 pkgload_1.3.0 rprojroot_2.0.3 withr_2.5.0 [125] sctransform_0.3.5 GenomeInfoDbData_1.2.8 mgcv_1.8-40 parallel_4.2.1 [129] grid_4.2.1 rpart_4.1.16 tidyr_1.2.1 DelayedMatrixStats_1.18.1 [133] rmarkdown_2.16 Rtsne_0.16 shiny1.7.2

— Reply to this email directly, view it on GitHub https://github.com/RGLab/MAST/issues/175, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALLAHUF3PUWUUNKDQ6HP73WA4RMJANCNFSM6AAAAAAQZ7EMLE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

grhogg commented 1 year ago

Thanks for your quick response! I have posted traceback() output below. Would this bug be better reported on the Seurat Github? Thanks again.

traceback()

18: stop(sprintf(ngettext(sum(is.na(which)), "invalid name for slot of class %s: %s", "invalid names for slots of class %s: %s"), dQuote(Class), paste(snames[is.na(which)], collapse = ", ")), domain = NA)

17: .nextMethod(.Object = .Object, ... = ..., design = design)

16: callNextMethod()

15: .local(.Object, ...)

14: .nextMethod(.Object = .Object, ... = ...)

13: callNextMethod()

12: initialize(value, ...)

11: initialize(value, ...)

10: new(method, design = colData(sca), formula = Formula, priorVar = priorVar, priorDOF = priorDOF, ...)

9: MAST::zlm(formula = fmla, sca = sca, ...)

8: MASTDETest(data.use = data.use, cells.1 = cells.1, cells.2 = cells.2, latent.vars = latent.vars, verbose = verbose, ...)

7: PerformDE(object = object, cells.1 = cells.1, cells.2 = cells.2, features = features, test.use = test.use, verbose = verbose, min.cells.feature = min.cells.feature, latent.vars = latent.vars, densify = densify, ...)

6: FindMarkers.default(object = data.use, slot = data.slot, counts = counts, cells.1 = cells.1, cells.2 = cells.2, features = features, logfc.threshold = logfc.threshold, test.use = test.use, min.pct = min.pct, min.diff.pct = min.diff.pct, verbose = verbose, only.pos = only.pos, max.cells.per.ident = max.cells.per.ident, random.seed = random.seed, latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, pseudocount.use = pseudocount.use, fc.results = fc.results, densify = densify, ...)

5: FindMarkers(object = data.use, slot = data.slot, counts = counts, cells.1 = cells.1, cells.2 = cells.2, features = features, logfc.threshold = logfc.threshold, test.use = test.use, min.pct = min.pct, min.diff.pct = min.diff.pct, verbose = verbose, only.pos = only.pos, max.cells.per.ident = max.cells.per.ident, random.seed = random.seed, latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, pseudocount.use = pseudocount.use, fc.results = fc.results, densify = densify, ...)

4: FindMarkers.SCTAssay(object = data.use, slot = slot, cells.1 = cells$cells.1, cells.2 = cells$cells.2, features = features, logfc.threshold = logfc.threshold, test.use = test.use, min.pct = min.pct, min.diff.pct = min.diff.pct, verbose = verbose, only.pos = only.pos, max.cells.per.ident = max.cells.per.ident, random.seed = random.seed, latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, mean.fxn = mean.fxn, base = base, fc.name = fc.name, densify = densify, norm.method = norm.method, ...)

3: FindMarkers(object = data.use, slot = slot, cells.1 = cells$cells.1, cells.2 = cells$cells.2, features = features, logfc.threshold = logfc.threshold, test.use = test.use, min.pct = min.pct, min.diff.pct = min.diff.pct, verbose = verbose, only.pos = only.pos, max.cells.per.ident = max.cells.per.ident, random.seed = random.seed, latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, mean.fxn = mean.fxn, base = base, fc.name = fc.name, densify = densify, norm.method = norm.method, ...)

2: FindMarkers.Seurat(immune.combined.sct, assay = "SCT", ident.1 = "B_STIM", ident.2 = "B_CTRL", test.use = "MAST")

1: FindMarkers(immune.combined.sct, assay = "SCT", ident.1 = "B_STIM", ident.2 = "B_CTRL", test.use = "MAST")

amcdavid commented 1 year ago

Yeah, this is a Seurat bug. It probably just needs to explicitly pass the norm.method argument to the FindMarkers, so it doesn't get slurped up by the ....

I see you opened an issue there, thanks: https://github.com/satijalab/seurat/issues/6489

behrouzsh commented 1 year ago

Dear @amcdavid, even though there is another thread for this question, there is no answer for how to solve the issue, it is only said that there is a bug. Will you please be more specific? I am working on a spatial transcriptomic data and the available assays are "Spatial" and "SCT". MAST works for "Spatial" assay but generates the error for SCT. What should be the argument for norm.method to pass to FindMarkers for SCT assay? What is your suggested solution? Thanks,

lucygarner commented 1 year ago

I am having the same issue. It would be great to get help with this.

MadsE10 commented 1 year ago

I had the same error and installing an older version of Seurat resolved it for me.

I previously had Seurat 4.2, but installed Seurat 4.1.1 then everything began to work normally again.

just to check what version you are actually using

packageVersion('Seurat')

library(remotes)

remotes::install_version("Seurat", version = "4.1.1")

lopes36363 commented 1 year ago

If you delete SCT.model list from the seurat object, it suddenly works. I could remove it by:

sne[["LOL"]] <- CreateAssayObject(counts = GetAssayData(sne, assay="SCT", slot="data")) #Copy "SCT data" to "LOL counts" and "LOL data" sne <- SetAssayData(sne, assay = "LOL", slot = "scale.data", new.data = GetAssayData(sne, assay="SCT", slot="scale.data")); gc() #"Copy "SCT scale.data" to "LOL scale.data" DefaultAssay(sne) <- "LOL" sne <- DietSeurat(sne, assays = "LOL", counts=T, data=T, scale.data=T) sne <- RenameAssays(sne, LOL = 'SCT')

lwhitmore commented 1 year ago

Hello, I have downloaded the latest version of MAST 1.25 but am still getting the following error Seurat is version 4.3: Error in .nextMethod(.Object = .Object, ... = ..., design = design) : invalid name for slot of class “BayesGLMlike”: norm.method Below is my command: DEgenes <- FindMarkers(combined, assay = "SCT", slot="data", ident.1 = ident_1, ident.2 = ident_2, test.use = "MAST", logfc.threshold = 0, min.pct = 0

recorrect_umi = FALSE

    )

Any help with this would be greatly appreciated

amcdavid commented 1 year ago

@lwhitmore Please provide a reproducible example that I can run to see if there's anything I can do about this issue MAST. The bug seems to be in Seurat, so you might open / comment on an issue there.

lwhitmore commented 1 year ago

@amcdavid My apologies I just needed to restart my R session apparently its working great! Again sorry to re-open this issue.