Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SummarizedExperiment::assay: on fastMNN object : object of type 'S4' is not subsettable #45

Open
nebetbastet opened this issue Sep 26, 2023 · 4 comments

Comments

@nebetbastet
Copy link

nebetbastet commented Sep 26, 2023

Hello,

I have an issue with the 'fastMNN' function in batchelor.
I can't access the assay of the generated object as I get an error.

out= batchelor::fastMNN(objects.sce)
out

class: SingleCellExperiment
dim: 2000 10000
metadata(2): merge.info pca.info
assays(1): reconstructed
rownames(2000): PTGDS S100B ... BCAS1 AGPAT5
rowData names(1): rotation
colnames(10000): AGAGCGAGTTAGATGA-1 ATTGGTGCAATCTACG-1 ... TTAGGCATCATGGTCA-1
TGGCCAGCAATGGACG-1
colData names(1): batch
reducedDimNames(1): corrected
mainExpName: NULL
altExpNames(0):

assay(out)

Error in (function (cond) : erreur d'évaluation de l'argument 'x' lors de la sélection d'une méthode pour la fonction 'type' : object of type 'S4' is not subsettable

When I manually create an sce object, I don't encounter this problem.
Similarly, when I convert a Seurat object into an sce object, there are no issues accessing the assays.

Here's my SessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

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

time zone: Europe/Paris
tzcode source: internal

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

other attached packages:
[1] SeuratWrappers_0.3.1 genefilter_1.82.1 magick_2.8.0
[4] rgl_1.2.1 destiny_3.14.0 sinaplot_1.1.0
[7] plyr_1.8.8 RColorBrewer_1.1-3 ggplot2_3.4.3
[10] DESeq2_1.40.2 patchwork_1.1.3 UCell_2.4.0
[13] harmony_1.0.1 Rcpp_1.0.11 sscVis_0.1.0
[16] SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.2 Biobase_2.60.0
[19] GenomicRanges_1.52.0 GenomeInfoDb_1.36.3 IRanges_2.34.1
[22] S4Vectors_0.38.2 BiocGenerics_0.46.0 MatrixGenerics_1.12.3
[25] matrixStats_1.0.0 dplyr_1.1.2 SeuratObject_4.1.3
[28] Seurat_4.3.0.1 markdown_1.8 knitr_1.44

loaded via a namespace (and not attached):
[1] spatstat.sparse_3.0-2 bitops_1.0-7 httr_1.4.7
[4] doParallel_1.0.17 dynamicTreeCut_1.63-1 tools_4.3.1
[7] sctransform_0.4.0 backports_1.4.1 ResidualMatrix_1.10.0
[10] utf8_1.2.3 R6_2.5.1 lazyeval_0.2.2
[13] uwot_0.1.16 GetoptLong_1.0.5 withr_2.5.0
[16] sp_2.0-0 gridExtra_2.3 progressr_0.14.0
[19] cli_3.6.1 spatstat.explore_3.2-3 sass_0.4.7
[22] mvtnorm_1.2-3 robustbase_0.99-0 spatstat.data_3.0-1
[25] proxy_0.4-27 ggridges_0.5.4 pbapply_1.7-2
[28] R.utils_2.12.2 parallelly_1.36.0 maps_3.4.1
[31] limma_3.56.2 TTR_0.24.3 RSQLite_2.3.1
[34] rstudioapi_0.15.0 impute_1.74.1 generics_0.1.3
[37] shape_1.4.6 ica_1.0-3 spatstat.random_3.1-6
[40] car_3.1-2 dendextend_1.17.1 Matrix_1.6-1.1
[43] ggbeeswarm_0.7.2 fansi_1.0.4 abind_1.4-5
[46] R.methodsS3_1.8.2 lifecycle_1.0.3 scatterplot3d_0.3-44
[49] yaml_2.3.7 carData_3.0-5 Rtsne_0.16
[52] blob_1.2.4 grid_4.3.1 promises_1.2.1
[55] crayon_1.5.2 miniUI_0.1.1.1 lattice_0.21-8
[58] beachmat_2.16.0 cowplot_1.1.1 annotate_1.78.0
[61] KEGGREST_1.40.0 pillar_1.9.0 ComplexHeatmap_2.16.0
[64] rjson_0.2.21 boot_1.3-28.1 future.apply_1.11.0
[67] codetools_0.2-19 leiden_0.4.3 glue_1.6.2
[70] remotes_2.4.2.1 pcaMethods_1.92.0 data.table_1.14.8
[73] vcd_1.4-11 vctrs_0.6.3 png_0.1-8
[76] spam_2.9-1 gtable_0.3.4 cachem_1.0.8
[79] ks_1.14.1 xfun_0.40 S4Arrays_1.0.6
[82] mime_0.12 RcppEigen_0.3.3.9.3 pracma_2.4.2
[85] survival_3.5-7 iterators_1.0.14 fields_15.2
[88] ellipsis_0.3.2 fitdistrplus_1.1-11 ROCR_1.0-11
[91] nlme_3.1-163 xts_0.13.1 bit64_4.0.5
[94] RcppAnnoy_0.0.21 bslib_0.5.1 irlba_2.3.5.1
[97] vipor_0.4.5 KernSmooth_2.23-22 DBI_1.1.3
[100] colorspace_2.1-0 nnet_7.3-19 smoother_1.1
[103] ggrastr_1.0.2 tidyselect_1.2.0 bit_4.0.5
[106] extrafontdb_1.0 curl_5.0.2 compiler_4.3.1
[109] BiocNeighbors_1.18.0 DelayedArray_0.26.7 plotly_4.10.2
[112] scales_1.2.1 hexbin_1.28.3 DEoptimR_1.1-2
[115] lmtest_0.9-40 stringr_1.5.0 digest_0.6.33
[118] goftest_1.2-3 spatstat.utils_3.0-3 rmarkdown_2.25
[121] XVector_0.40.0 RhpcBLASctl_0.23-42 base64enc_0.1-3
[124] htmltools_0.5.6 pkgconfig_2.0.3 extrafont_0.19
[127] sparseMatrixStats_1.12.2 fastmap_1.1.1 ggthemes_4.2.4
[130] rlang_1.1.1 GlobalOptions_0.1.2 htmlwidgets_1.6.2
[133] shiny_1.7.5 DelayedMatrixStats_1.22.6 jquerylib_0.1.4
[136] zoo_1.8-12 jsonlite_1.8.7 BiocParallel_1.34.2
[139] mclust_6.0.0 R.oo_1.25.0 BiocSingular_1.16.0
[142] RCurl_1.98-1.12 magrittr_2.0.3 scuttle_1.10.2
[145] GenomeInfoDbData_1.2.10 dotCall64_1.0-2 munsell_0.5.0
[148] viridis_0.6.4 reticulate_1.32.0 stringi_1.7.12
[151] zlibbioc_1.46.0 MASS_7.3-60 parallel_4.3.1
[154] listenv_0.9.0 ggrepel_0.9.3 deldir_1.0-9
[157] Biostrings_2.68.1 splines_4.3.1 tensor_1.5
[160] circlize_0.4.15 locfit_1.5-9.8 ranger_0.15.1
[163] igraph_1.5.1 ggpubr_0.6.0 spatstat.geom_3.2-5
[166] ggsignif_0.6.4 RcppHNSW_0.5.0 ScaledMatrix_1.8.1
[169] reshape2_1.4.4 XML_3.99-0.14 evaluate_0.21
[172] BiocManager_1.30.22 laeken_0.5.2 batchelor_1.16.0
[175] foreach_1.5.2 httpuv_1.6.11 Rttf2pt1_1.3.12
[178] VIM_6.2.2 RANN_2.6.1 tidyr_1.3.0
[181] purrr_1.0.2 polyclip_1.10-4 future_1.33.0
[184] clue_0.3-65 scattermore_1.2 gridBase_0.4-7
[187] rsvd_1.0.5 broom_1.0.5 xtable_1.8-4
[190] e1071_1.7-13 RSpectra_0.16-1 rstatix_0.7.2
[193] later_1.3.1 viridisLite_0.4.2 class_7.3-22
[196] tibble_3.2.1 moduleColor_1.8-4 memoise_2.0.1
[199] AnnotationDbi_1.62.2 beeswarm_0.4.0 cluster_2.1.4
[202] ggplot.multistats_1.0.0 globals_0.16.2

Thank you for your help

@LTLA
Copy link
Owner

LTLA commented Oct 12, 2023

Sorry for the late reply. I don't have any issues running the example:

library(batchelor)
example(fastMNN, echo=FALSE)
out
## class: SingleCellExperiment 
## dim: 200 100 
## metadata(2): merge.info pca.info
## assays(1): reconstructed
## rownames: NULL
## rowData names(1): rotation
## colnames: NULL
## colData names(1): batch
## reducedDimNames(1): corrected
## mainExpName: NULL
## altExpNames(0):

assay(out)
## <200 x 100> LowRankMatrix object of type "double":
##                [,1]         [,2]         [,3] ...       [,99]      [,100]
##   [1,] -0.041500974 -0.041187990 -0.065122142   . -0.01857182 -0.08582027
##   [2,]  0.019251114 -0.047421044 -0.020124255   . -0.04065221  0.01079485
##   [3,] -0.001653034  0.017117968 -0.038393065   . -0.07142613 -0.07357877
##   [4,] -0.044129094 -0.061465542 -0.093328064   . -0.02522488 -0.05275507
##   [5,] -0.028562310 -0.022114883 -0.047984941   . -0.12481886 -0.01802864
##    ...            .            .            .   .           .           .
## [196,] -0.034075842 -0.121444735 -0.007966894   . -0.04559586 -0.06874582
## [197,] -0.077225050  0.003219620 -0.070414809   .  0.03878306 -0.07472732
## [198,] -0.068255656 -0.021519339 -0.018424398   . -0.05250330 -0.09911245
## [199,] -0.034577621 -0.086351051 -0.045710427   . -0.08996022 -0.01574235
## [200,] -0.034046424 -0.049210218 -0.092373174   . -0.08422264 -0.13358312

It would be helpful to see str(assay(out, withDimnames=FALSE))

@moosa-r
Copy link

moosa-r commented Jan 3, 2024

Dear @LTLA ,

I also encounter this error even when running the example provided in fastMNN function's Documentation.

> library(batchelor)
> B1 <- matrix(rnorm(10000, -1), ncol=50) # Batch 1 
> B2 <- matrix(rnorm(10000, 1), ncol=50) # Batch 2
> out <- fastMNN(B1, B2)
Warning in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE,  :
  You're computing too large a percentage of total singular values, use a standard svd instead.
> out
class: SingleCellExperiment 
dim: 200 100 
metadata(2): merge.info pca.info
assays(1): reconstructed
rownames: NULL
rowData names(1): rotation
colnames: NULL
colData names(1): batch
reducedDimNames(1): corrected
mainExpName: NULL
altExpNames(0):
> assay(out)
Error in (function (cond)  : 
  error in evaluating the argument 'x' in selecting a method for function 'type': object of type 'S4' is not subsettable
> str(assay(out, withDimnames=FALSE))
Formal class 'LowRankMatrix' [package "BiocSingular"] with 1 slot
  ..@ seed:Formal class 'LowRankMatrixSeed' [package "BiocSingular"] with 2 slots
  .. .. ..@ rotation  : num [1:200, 1:50] -0.0622 -0.0752 -0.0614 -0.0641 -0.0696 ...
  .. .. ..@ components: num [1:100, 1:50] 0.709 0.706 0.71 0.709 0.707 ...

Here is my session info:

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

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    

time zone: Europe/Brussels
tzcode source: internal

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

other attached packages:
 [1] batchelor_1.16.0            SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.2
 [4] Biobase_2.60.0              GenomicRanges_1.52.1        GenomeInfoDb_1.36.4        
 [7] IRanges_2.34.1              S4Vectors_0.38.2            BiocGenerics_0.46.0        
[10] MatrixGenerics_1.12.3       matrixStats_1.2.0          

loaded via a namespace (and not attached):
 [1] Matrix_1.6-4              compiler_4.3.1            crayon_1.5.2             
 [4] Rcpp_1.0.11               rsvd_1.0.5                scuttle_1.10.3           
 [7] bitops_1.0-7              DelayedMatrixStats_1.22.6 parallel_4.3.1           
[10] BiocParallel_1.34.2       lattice_0.22-5            XVector_0.40.0           
[13] S4Arrays_1.0.6            ScaledMatrix_1.8.1        igraph_1.6.0             
[16] DelayedArray_0.26.7       GenomeInfoDbData_1.2.10   rlang_1.1.2              
[19] BiocNeighbors_1.18.0      cli_3.6.2                 magrittr_2.0.3           
[22] BiocSingular_1.16.0       zlibbioc_1.46.0           grid_4.3.1               
[25] rstudioapi_0.15.0         irlba_2.3.5.1             sparseMatrixStats_1.12.2 
[28] lifecycle_1.0.4           codetools_0.2-19          ResidualMatrix_1.10.0    
[31] beachmat_2.16.0           abind_1.4-5               RCurl_1.98-1.13          
[34] pkgconfig_2.0.3           tools_4.3.1              

Thank you in advance for your time and consideration. :)

@LTLA
Copy link
Owner

LTLA commented Jan 6, 2024

I have no such problems with running example(fastMNN):

> example(fastMNN)

fstMNN> B1 <- matrix(rnorm(10000, -1), ncol=50) # Batch 1 

fstMNN> B2 <- matrix(rnorm(10000, 1), ncol=50) # Batch 2

fstMNN> out <- fastMNN(B1, B2)
Warning in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE,  :
  You're computing too large a percentage of total singular values, use a standard svd instead.

fstMNN> # Corrected values for use in clustering, etc.
fstMNN> str(reducedDim(out)) 
 num [1:100, 1:50] -0.715 -0.71 -0.71 -0.71 -0.706 ...

fstMNN> # Extracting corrected expression values for gene 10.
fstMNN> summary(assay(out)[10,])
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-0.163524 -0.070971 -0.037425 -0.040175 -0.008362  0.063427 

I will note that you are one BioC release behind, based on the version numbers in your session information. Perhaps try updating to the latest BioC release. (That said, I didn't change anything in any of the affected packages between releases, so I don't know whether this would really help; but you'd want to update anyway, because if there really is a problem, I'll only be updating the latest release, and not any of the older releases.)

@moosa-r
Copy link

moosa-r commented Jan 6, 2024

Thanks for your time. Strange indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants