SingleR-inc / SingleR

Clone of the Bioconductor repository for the SingleR package.
https://bioconductor.org/packages/devel/bioc/html/SingleR.html
GNU General Public License v3.0
173 stars 19 forks source link

Bioconductor develop / "object of type 'S4' is not subsettable"? #176

Closed bbimber closed 3 years ago

bbimber commented 3 years ago

Hello,

I write an R package these uses singleR. Our tests recently started to fail on the bioconductor/devel branch. They're working on release. We use singleR in what I think is a pretty basic manner (below), where we have a seurat object, convert to SingleCellExperiment, and run SingleR() using the HPCA ref.

We are getting the error "object of type 'S4' is not subsettable". Is this a known issue?

ref <- celldex::HumanPrimaryCellAtlasData()
sce <- Seurat::as.SingleCellExperiment(seuratObjSubset, assay = assay)
sce <- scater::logNormCounts(sce)

refAssay <- 'logcounts'
if (!('logcounts' %in% names(SummarizedExperiment::assays(ref)))) {
  refAssay <- 'normcounts'
}

pred.results <- suppressWarnings(SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, assay.type.ref = refAssay, fine.tune = TRUE, prune = TRUE))
LTLA commented 3 years ago

I'll assume you're using the latest version of all packages and Bioconductor 3.13.

We are getting the error "object of type 'S4' is not subsettable". Is this a known issue?

Not to me. Should have worked pretty smoothly. If we were to run the example:

sce <- scRNAseq::LaMannoBrainData('human-es')
ref <- celldex::HumanPrimaryCellAtlasData()
pred.results <- suppressWarnings(SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, 
    assay.type.test=1, assay.type.ref = "logcounts", fine.tune = TRUE, prune = TRUE))

Spews out Neuroepithelial_cell calls, which may or may not be biologically sensible, but it does at least run.

A longer traceback() would be informative, along with some information about the class of logcounts(sce).

bbimber commented 3 years ago

That's a good point. It's possible something in the seurat to sce portion changed, not single r itself. This all happening headlessly on github actions, but everything in this build should be pulling latest versions of everything.

I'll try to debug this locally.

bbimber commented 3 years ago

One question: is "assay.type.test=1" needed? the default appears to be "logcounts"?

bbimber commented 3 years ago

I make a local environment to test this, and I repro that subset error with your example above. This might be due to R-devel as well? Below is the repro and more info:

sce <- scRNAseq::LaMannoBrainData('human-es')
ref <- celldex::HumanPrimaryCellAtlasData()
pred.results <- suppressWarnings(SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, assay.type.test=1, assay.type.ref = "logcounts", fine.tune = TRUE, prune = TRUE))
traceback()

the trackback is:

Error in FUN(X[[i]], ...) : object of type 'S4' is not subsettable
> traceback()
9: lapply(varlist[[i]], `[`, recycle, drop = FALSE)
8: lapply(varlist[[i]], `[`, recycle, drop = FALSE)
7: DataFrame(scores = I(scores), first.labels = labels, tuning.scores = I(DataFrame(first = tuned[[2]], 
       second = tuned[[3]])), labels = new.labels)
6: FUN(X[[i]], ...)
5: lapply(trained, FUN = .classify_internals, test = test, quantile = quantile, 
       fine.tune = fine.tune, tune.thresh = tune.thresh, sd.thresh = sd.thresh, 
       prune = prune, BPPARAM = BPPARAM)
4: classifySingleR(test, trained, quantile = quantile, fine.tune = fine.tune, 
       tune.thresh = tune.thresh, prune = prune, check.missing = FALSE, 
       BPPARAM = BPPARAM)
3: SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, 
       assay.type.test = 1, assay.type.ref = "logcounts", fine.tune = TRUE, 
       prune = TRUE)
2: withCallingHandlers(expr, warning = function(w) if (inherits(w, 
       classes)) tryInvokeRestart("muffleWarning"))
1: suppressWarnings(SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, 
       assay.type.test = 1, assay.type.ref = "logcounts", fine.tune = TRUE, 
       prune = TRUE))

SessionInfo is:

R Under development (unstable) (2021-01-23 r79873)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

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

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

other attached packages:
 [1] celldex_1.0.0               scRNAseq_2.5.2              SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0 Biobase_2.51.0              GenomicRanges_1.43.3       
 [7] GenomeInfoDb_1.27.4         IRanges_2.25.6              S4Vectors_0.29.6            BiocGenerics_0.37.0         MatrixGenerics_1.3.0        matrixStats_0.57.0         
[13] CellMembrane_1.0.0         

loaded via a namespace (and not attached):
  [1] reticulate_1.18               R.utils_2.10.1                tidyselect_1.1.0              RSQLite_2.2.3                 AnnotationDbi_1.53.0         
  [6] htmlwidgets_1.5.3             grid_4.1.0                    BiocParallel_1.25.2           Rtsne_0.15                    DropletUtils_1.10.2          
 [11] munsell_0.5.0                 ScaledMatrix_0.99.2           codetools_0.2-18              ica_1.0-2                     future_1.21.0                
 [16] miniUI_0.1.1.1                withr_2.4.0                   colorspace_2.0-0              filelock_1.0.2                rstudioapi_0.13              
 [21] Seurat_3.2.3                  ROCR_1.0-11                   tensor_1.5                    listenv_0.8.0                 GenomeInfoDbData_1.2.4       
 [26] polyclip_1.10-0               bit64_4.0.5                   pheatmap_1.0.12               rhdf5_2.35.0                  parallelly_1.23.0            
 [31] vctrs_0.3.6                   generics_0.1.0                BiocFileCache_1.15.1          R6_2.5.0                      rsvd_1.0.3                   
 [36] locfit_1.5-9.4                AnnotationFilter_1.15.0       bitops_1.0-6                  rhdf5filters_1.3.3            spatstat.utils_2.0-0         
 [41] DelayedArray_0.17.7           assertthat_0.2.1              BiocIO_1.1.2                  promises_1.1.1                scales_1.1.1                 
 [46] gtable_0.3.0                  beachmat_2.7.6                globals_0.14.0                goftest_1.2-2                 ensembldb_2.15.1             
 [51] rlang_0.4.10                  genefilter_1.73.1             splines_4.1.0                 rtracklayer_1.51.4            lazyeval_0.2.2               
 [56] BiocManager_1.30.10           yaml_2.2.1                    reshape2_1.4.4                abind_1.4-5                   GenomicFeatures_1.43.3       
 [61] httpuv_1.5.5                  tools_4.1.0                   ggplot2_3.3.3                 ellipsis_0.3.1                RColorBrewer_1.1-2           
 [66] ggridges_0.5.3                Rcpp_1.0.6                    plyr_1.8.6                    sparseMatrixStats_1.3.2       progress_1.2.2               
 [71] zlibbioc_1.37.0               purrr_0.3.4                   RCurl_1.98-1.2                prettyunits_1.1.1             rpart_4.1-15                 
 [76] openssl_1.4.3                 deldir_0.2-9                  pbapply_1.4-3                 cowplot_1.1.1                 zoo_1.8-8                    
 [81] ggrepel_0.9.1                 cluster_2.1.0                 magrittr_2.0.1                data.table_1.13.6             scattermore_0.7              
 [86] lmtest_0.9-38                 RANN_2.6.1                    ProtGenerics_1.23.6           fitdistrplus_1.1-3            hms_1.0.0                    
 [91] patchwork_1.1.1               mime_0.9                      xtable_1.8-4                  XML_3.99-0.5                  gridExtra_2.3                
 [96] compiler_4.1.0                biomaRt_2.47.1                tibble_3.0.5                  KernSmooth_2.23-18            crayon_1.3.4                 
[101] R.oo_1.24.0                   htmltools_0.5.1.1             mgcv_1.8-33                   later_1.1.0.1                 tidyr_1.1.2                  
[106] geneplotter_1.69.0            DBI_1.1.1                     ExperimentHub_1.17.0          dbplyr_2.0.0                  MASS_7.3-53                  
[111] rappdirs_0.3.1                MAST_1.16.0                   Matrix_1.3-2                  R.methodsS3_1.8.1             igraph_1.2.6                 
[116] pkgconfig_2.0.3               GenomicAlignments_1.27.2      plotly_4.9.3                  scuttle_1.0.4                 xml2_1.3.2                   
[121] annotate_1.69.0               dqrng_0.2.1                   XVector_0.31.1                stringr_1.4.0                 digest_0.6.27                
[126] sctransform_0.3.2             RcppAnnoy_0.0.18              SingleR_1.4.0                 spatstat.data_1.7-0           Biostrings_2.59.2            
[131] leiden_0.3.6                  uwot_0.1.10                   edgeR_3.33.1                  DelayedMatrixStats_1.13.4     restfulr_0.0.13              
[136] curl_4.3                      Rsamtools_2.7.0               shiny_1.5.0                   rjson_0.2.20                  lifecycle_0.2.0              
[141] nlme_3.1-151                  jsonlite_1.7.2                Rhdf5lib_1.13.0               BiocNeighbors_1.9.4           askpass_1.1                  
[146] viridisLite_0.3.0             limma_3.47.3                  pillar_1.4.7                  lattice_0.20-41               fastmap_1.0.1                
[151] httr_1.4.2                    survival_3.2-7                interactiveDisplayBase_1.29.0 glue_1.4.2                    spatstat_1.64-1              
[156] png_0.1-7                     BiocVersion_3.13.1            bit_4.0.4                     stringi_1.5.3                 HDF5Array_1.19.0             
[161] blob_1.2.1                    DESeq2_1.30.0                 BiocSingular_1.7.1            AnnotationHub_2.23.0          memoise_1.1.0                
[166] dplyr_1.0.3                   irlba_2.3.3                   future.apply_1.7.0  
LTLA commented 3 years ago

Hm. I still can't reproduce it on the latest R-devel (r79876).

The nature of the error suggests that some other package is overriding I(). I don't understand why this would cause problems because we explicitly import I() from S4Vectors. Can you reproduce the error with just my code chunk and no other packages?

bbimber commented 3 years ago

I'm afraid no change. I restarted r-devel (r79873) and then ran exactly this:

sce <- scRNAseq::LaMannoBrainData('human-es')
ref <- celldex::HumanPrimaryCellAtlasData()
pred.results <- suppressWarnings(SingleR::SingleR(test = sce, ref = ref, labels = ref$label.main, assay.type.test=1, assay.type.ref = "logcounts", fine.tune = TRUE, prune = TRUE))
traceback()
sessionInfo()

Identical error/stack as above.

R Under development (unstable) (2021-01-23 r79873)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

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

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

other attached packages:
 [1] celldex_1.0.0               scRNAseq_2.5.2              SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0 Biobase_2.51.0              GenomicRanges_1.43.3       
 [7] GenomeInfoDb_1.27.4         IRanges_2.25.6              S4Vectors_0.29.6            BiocGenerics_0.37.0         MatrixGenerics_1.3.0        matrixStats_0.57.0         

loaded via a namespace (and not attached):
 [1] ProtGenerics_1.23.6           bitops_1.0-6                  bit64_4.0.5                   filelock_1.0.2                progress_1.2.2                httr_1.4.2                   
 [7] tools_4.1.0                   irlba_2.3.3                   R6_2.5.0                      DBI_1.1.1                     lazyeval_0.2.2                withr_2.4.0                  
[13] tidyselect_1.1.0              prettyunits_1.1.1             bit_4.0.4                     curl_4.3                      compiler_4.1.0                BiocNeighbors_1.9.4          
[19] xml2_1.3.2                    DelayedArray_0.17.7           rtracklayer_1.51.4            askpass_1.1                   rappdirs_0.3.1                stringr_1.4.0                
[25] digest_0.6.27                 Rsamtools_2.7.0               rmarkdown_2.6                 XVector_0.31.1                pkgconfig_2.0.3               htmltools_0.5.1.1            
[31] SingleR_1.4.0                 sparseMatrixStats_1.3.2       dbplyr_2.0.0                  fastmap_1.0.1                 ensembldb_2.15.1              rlang_0.4.10                 
[37] rstudioapi_0.13               RSQLite_2.2.3                 shiny_1.5.0                   DelayedMatrixStats_1.13.4     BiocIO_1.1.2                  generics_0.1.0               
[43] BiocParallel_1.25.2           dplyr_1.0.3                   BiocSingular_1.7.1            RCurl_1.98-1.2                magrittr_2.0.1                GenomeInfoDbData_1.2.4       
[49] Matrix_1.3-2                  Rcpp_1.0.6                    lifecycle_0.2.0               stringi_1.5.3                 yaml_2.2.1                    zlibbioc_1.37.0              
[55] BiocFileCache_1.15.1          AnnotationHub_2.23.0          grid_4.1.0                    blob_1.2.1                    promises_1.1.1                ExperimentHub_1.17.0         
[61] crayon_1.3.4                  lattice_0.20-41               beachmat_2.7.6                Biostrings_2.59.2             GenomicFeatures_1.43.3        hms_1.0.0                    
[67] knitr_1.30                    pillar_1.4.7                  rjson_0.2.20                  ScaledMatrix_0.99.2           biomaRt_2.47.1                XML_3.99-0.5                 
[73] glue_1.4.2                    BiocVersion_3.13.1            evaluate_0.14                 BiocManager_1.30.10           vctrs_0.3.6                   httpuv_1.5.5                 
[79] openssl_1.4.3                 purrr_0.3.4                   assertthat_0.2.1              xfun_0.20                     rsvd_1.0.3                    mime_0.9                     
[85] xtable_1.8-4                  restfulr_0.0.13               AnnotationFilter_1.15.0       later_1.1.0.1                 tibble_3.0.5                  GenomicAlignments_1.27.2     
[91] AnnotationDbi_1.53.0          memoise_1.1.0                 ellipsis_0.3.1                interactiveDisplayBase_1.29.0
LTLA commented 3 years ago

Is there a reason why you have SingleR 1.4.0 (BioC release) mixed in with a whole bunch of BioC-devel packages?

bbimber commented 3 years ago

Good catch - I wonder if remotes does that. I'm not sure if there's a better practice to handle this. My DESCRIPTION has the remotes config (i.e. Remotes: bioc::release/SingleR,).

options('repos') should only include the devel repos but perhaps something in remotes/devtools is doing that. Alternately there might be some caching happening on github actions, but it's supposed to force updates. I will try to look into that more.

bbimber commented 3 years ago

OK, thanks for your help. I figured out how this version problem can happen.

Both locally and though the gitub-actions build, it was installing my R package using remotes::install(). My DESCRIPTION specified Remotes: bio::SingleR (even without specifying a specific version). Apparently even if you are running Bioc-devel, remotes will default to pulling packages from release, unless you explicitly specify otherwise. I was able to set the environment variable R_BIOC_VERSION to 3.13, which should change that. This now works locally and get the right version. I need to figure out the headless/gitub-actions case (which still has the old version), but the problem is definitely versions, not SingleR itself.

Thanks again.