seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Error in .subscript.2ary(x, , j, drop = drop) : subscript out of bounds when trying to merge 4 different SCTransform Seurat objects

Open chungsai opened this issue 11 months ago • 16 comments

Hello,

I am trying to merge 4 rds of mine after reading them in. Each of these have 4 samples in them that are QC'd but unintegrated and SCTransformed, and have run pca, clustered and umap ran. Plots were generated.

When I try to load them for merging and integration .This occurs

L_2 = ReadRDS(filepath bla bla) D_2 = ReadRDS(filepath bla bla2) R2 = ReadRDS(filepath bla bla3) T2 =ReadRDS(filepath bla bla4)

data_SCT <- merge(L_2, c(D_2, R2, T2), # add.cell.ids = c('L.S', 'D.S','Rj', 'To'), project = 'AllModelsPODsn2', merge.data = TRUE)

Error in .subscript.2ary(x, , j, drop = drop) : subscript out of bounds

I have alternative versions of these same 4 seur x 4 samples each, but I ran the regular normalization, scale variable features and pca then umap instead.

And using the same code, merging is not an issue and I do not get this error.

I keep encountering a lot of errors with SCT than I do with the original method, but I'd like to use SCT.

Hoping for advice.

Best,

session_info() ─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.3.2 (2023-10-31) os macOS Sonoma 14.3.1 system aarch64, darwin20 ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz America/Toronto date 2024-02-29 rstudio 2023.12.1+402 Ocean Storm (desktop) pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ! package * version date (UTC) lib source abind * 1.4-5 2016-07-21 [1] CRAN (R 4.3.0) annotate * 1.80.0 2023-10-26 [1] Bioconductor AnnotationDbi * 1.64.1 2023-11-02 [1] Bioconductor AUCell * 1.24.0 2023-10-24 [1] Bioconductor beachmat 2.18.1 2024-02-17 [1] Bioconductor 3.18 (R 4.3.2) beeswarm 0.4.0 2021-06-01 [1] CRAN (R 4.3.0) Biobase * 2.62.0 2023-10-26 [1] Bioconductor BiocFileCache 2.10.1 2023-10-26 [1] Bioconductor BiocGenerics * 0.48.1 2023-11-02 [1] Bioconductor BiocIO 1.12.0 2023-10-26 [1] Bioconductor BiocManager * 1.30.22 2023-08-08 [1] CRAN (R 4.3.0) BiocNeighbors 1.20.2 2024-01-13 [1] Bioconductor 3.18 (R 4.3.2) BiocParallel * 1.36.0 2023-10-26 [1] Bioconductor BiocSingular 1.18.0 2023-11-06 [1] Bioconductor biomaRt * 2.58.2 2024-02-03 [1] Bioconductor 3.18 (R 4.3.2) Biostrings 2.70.2 2024-01-30 [1] Bioconductor 3.18 (R 4.3.2) bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) bitops 1.0-7 2021-04-24 [1] CRAN (R 4.3.0) blob 1.2.4 2023-03-17 [1] CRAN (R 4.3.0) bluster 1.12.0 2023-12-19 [1] Bioconductor 3.18 (R 4.3.2) cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) callr 3.7.5 2024-02-19 [1] CRAN (R 4.3.1) cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.1) V cluster 2.1.4 2023-12-01 [1] CRAN (R 4.3.1) (on disk 2.1.6) codetools 0.2-19 2023-02-01 [1] CRAN (R 4.3.2) colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) combinat 0.0-8 2012-10-29 [1] CRAN (R 4.3.0) cowplot 1.1.3 2024-01-22 [1] CRAN (R 4.3.1) crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) curl 5.2.0 2023-12-08 [1] CRAN (R 4.3.1) data.table * 1.15.0 2024-01-30 [1] CRAN (R 4.3.1) DBI 1.2.2 2024-02-16 [1] CRAN (R 4.3.1) dbplyr 2.4.0 2023-10-26 [1] CRAN (R 4.3.1) DDRTree * 0.1.5 2017-04-30 [1] CRAN (R 4.3.0) DelayedArray * 0.28.0 2023-11-06 [1] Bioconductor DelayedMatrixStats * 1.24.0 2023-11-06 [1] Bioconductor deldir 2.0-2 2023-11-23 [1] CRAN (R 4.3.1) desc 1.4.3 2023-12-10 [1] CRAN (R 4.3.1) devtools * 2.4.5 2022-10-11 [1] CRAN (R 4.3.0) digest 0.6.34 2024-01-11 [1] CRAN (R 4.3.1) dotCall64 1.1-1 2023-11-28 [1] CRAN (R 4.3.1) dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.3.1) dqrng 0.3.2 2023-11-29 [1] CRAN (R 4.3.1) edgeR 4.0.16 2024-02-20 [1] Bioconductor 3.18 (R 4.3.2) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.0) evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.1) farver 2.1.1 2022-07-06 [1] CRAN (R 4.3.0) fastDummies 1.7.3 2023-07-06 [1] CRAN (R 4.3.0) fastICA 1.2-4 2023-11-27 [1] CRAN (R 4.3.1) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) fastmatch 1.1-4 2023-08-18 [1] CRAN (R 4.3.0) fgsea * 1.28.0 2023-10-26 [1] Bioconductor filelock 1.0.3 2023-12-11 [1] CRAN (R 4.3.1) fitdistrplus 1.1-11 2023-04-25 [1] CRAN (R 4.3.0) fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) future 1.33.1 2023-12-22 [1] CRAN (R 4.3.1) future.apply 1.11.1 2023-12-21 [1] CRAN (R 4.3.1) generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) GenomeInfoDb * 1.38.6 2024-02-10 [1] Bioconductor 3.18 (R 4.3.2) GenomeInfoDbData 1.2.11 2024-02-29 [1] Bioconductor GenomicAlignments 1.38.2 2024-01-20 [1] Bioconductor 3.18 (R 4.3.2) GenomicRanges * 1.54.1 2023-10-30 [1] Bioconductor ggbeeswarm 0.7.2 2023-04-29 [1] CRAN (R 4.3.0) ggplot2 * 3.5.0 2024-02-23 [1] CRAN (R 4.3.1) ggrepel 0.9.5 2024-01-10 [1] CRAN (R 4.3.1) ggridges 0.5.6 2024-01-23 [1] CRAN (R 4.3.1) glmGamPoi 1.14.3 2024-02-10 [1] Bioconductor 3.18 (R 4.3.2) globals 0.16.2 2022-11-21 [1] CRAN (R 4.3.0) glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.1) goftest 1.2-3 2021-10-07 [1] CRAN (R 4.3.0) gprofiler2 * 0.2.3 2024-02-23 [1] CRAN (R 4.3.1) graph * 1.80.0 2023-10-26 [1] Bioconductor gridExtra 2.3 2017-09-09 [1] CRAN (R 4.3.0) GSEABase * 1.64.0 2023-10-26 [1] Bioconductor GSVA * 1.50.0 2023-11-06 [1] Bioconductor gtable 0.3.4 2023-08-21 [1] CRAN (R 4.3.0) harmony * 1.2.0 2023-11-29 [1] CRAN (R 4.3.1) HDF5Array 1.30.1 2024-02-17 [1] Bioconductor 3.18 (R 4.3.2) hdf5r 1.3.9 2024-01-14 [1] CRAN (R 4.3.1) hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) HSMMSingleCell 1.22.0 2023-10-26 [1] Bioconductor htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.1) htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.3.1) httpuv 1.6.14 2024-01-26 [1] CRAN (R 4.3.1) httr 1.4.7 2023-08-15 [1] CRAN (R 4.3.0) ica 1.0-3 2022-07-08 [1] CRAN (R 4.3.0) igraph 2.0.2 2024-02-17 [1] CRAN (R 4.3.1) IRanges * 2.36.0 2023-10-26 [1] Bioconductor irlba * 2.3.5.1 2022-10-03 [1] CRAN (R 4.3.0) jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.3.1) KEGGREST 1.42.0 2023-10-26 [1] Bioconductor KernSmooth 2.23-22 2023-07-10 [1] CRAN (R 4.3.2) knitr 1.45 2023-10-30 [1] CRAN (R 4.3.1) labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.0) later 1.3.2 2023-12-06 [1] CRAN (R 4.3.1) V lattice 0.21-9 2023-10-24 [1] CRAN (R 4.3.1) (on disk 0.22.5) lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.3.0) leiden 0.4.3.1 2023-11-17 [1] CRAN (R 4.3.1) leidenbase 0.1.27 2023-12-01 [1] CRAN (R 4.3.1) lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1) limma * 3.58.1 2023-11-02 [1] Bioconductor listenv 0.9.1 2024-01-29 [1] CRAN (R 4.3.1) lmtest 0.9-40 2022-03-21 [1] CRAN (R 4.3.0) locfit 1.5-9.8 2023-06-11 [1] CRAN (R 4.3.0) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) V MASS 7.3-60 2024-01-13 [1] CRAN (R 4.3.1) (on disk 7.3.60.0.1) Matrix * 1.6-5 2024-01-11 [1] CRAN (R 4.3.1) MatrixGenerics * 1.14.0 2023-10-26 [1] Bioconductor matrixStats * 1.2.0 2023-12-11 [1] CRAN (R 4.3.1) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) metapod 1.10.1 2023-12-23 [1] Bioconductor 3.18 (R 4.3.2) mime 0.12 2021-09-28 [1] CRAN (R 4.3.0) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.3.0) multtest * 2.58.0 2023-10-26 [1] Bioconductor munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0) V nlme 3.1-163 2023-11-27 [1] CRAN (R 4.3.1) (on disk 3.1.164) org.Hs.eg.db * 3.18.0 2024-03-01 [1] Bioconductor org.Rn.eg.db * 3.18.0 2024-03-01 [1] Bioconductor parallelly 1.37.0 2024-02-14 [1] CRAN (R 4.3.1) patchwork 1.2.0 2024-01-08 [1] CRAN (R 4.3.1) pbapply 1.7-2 2023-06-27 [1] CRAN (R 4.3.0) pheatmap * 1.0.12 2019-01-04 [1] CRAN (R 4.3.0) pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) pkgbuild 1.4.3 2023-12-10 [1] CRAN (R 4.3.1) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) pkgload 1.3.4 2024-01-16 [1] CRAN (R 4.3.1) plotly 4.10.4 2024-01-13 [1] CRAN (R 4.3.1) plyr * 1.8.9 2023-10-02 [1] CRAN (R 4.3.1) png 0.1-8 2022-11-29 [1] CRAN (R 4.3.0) polyclip 1.10-6 2023-09-27 [1] CRAN (R 4.3.1) presto * 1.0.0 2024-02-11 [1] https://satijalab.r-universe.dev (R 4.3.2) prettyunits 1.2.0 2023-09-24 [1] CRAN (R 4.3.1) processx 3.8.3 2023-12-10 [1] CRAN (R 4.3.1) profvis 0.3.8 2023-05-02 [1] CRAN (R 4.3.0) progress 1.2.3 2023-12-06 [1] CRAN (R 4.3.1) progressr 0.14.0 2023-08-10 [1] CRAN (R 4.3.0) promises 1.2.1 2023-08-10 [1] CRAN (R 4.3.0) ps 1.7.6 2024-01-18 [1] CRAN (R 4.3.1) purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0) R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.0) R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.3.1) R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.3.1) R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) ragg 1.2.7 2023-12-11 [1] CRAN (R 4.3.1) RANN 2.6.1 2019-01-08 [1] CRAN (R 4.3.0) rappdirs 0.3.3 2021-01-31 [1] CRAN (R 4.3.0) RColorBrewer * 1.1-3 2022-04-03 [1] CRAN (R 4.3.0) Rcpp * 1.0.12 2024-01-09 [1] CRAN (R 4.3.1) RcppAnnoy 0.0.22 2024-01-23 [1] CRAN (R 4.3.1) RcppHNSW 0.6.0 2024-02-04 [1] CRAN (R 4.3.1) RCurl 1.98-1.14 2024-01-09 [1] CRAN (R 4.3.1) remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.3.0) reshape2 1.4.4 2020-04-09 [1] CRAN (R 4.3.0) restfulr 0.0.15 2022-06-16 [1] CRAN (R 4.3.0) reticulate 1.35.0 2024-01-31 [1] CRAN (R 4.3.1) rhdf5 2.46.1 2023-12-02 [1] Bioconductor 3.18 (R 4.3.2) rhdf5filters 1.14.1 2023-12-16 [1] Bioconductor 3.18 (R 4.3.2) Rhdf5lib 1.24.2 2024-02-10 [1] Bioconductor 3.18 (R 4.3.2) rjson 0.2.21 2022-01-09 [1] CRAN (R 4.3.0) rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.1) rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.3.1) ROCR 1.0-11 2020-05-02 [1] CRAN (R 4.3.0) Rsamtools 2.18.0 2023-10-26 [1] Bioconductor RSpectra 0.16-1 2022-04-24 [1] CRAN (R 4.3.0) RSQLite 2.3.5 2024-01-21 [1] CRAN (R 4.3.1) rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.0) rsvd 1.0.5 2021-04-16 [1] CRAN (R 4.3.0) rtracklayer 1.62.0 2023-10-26 [1] Bioconductor Rtsne 0.17 2023-12-07 [1] CRAN (R 4.3.1) S4Arrays * 1.2.0 2023-10-26 [1] Bioconductor S4Vectors * 0.40.2 2023-11-25 [1] Bioconductor 3.18 (R 4.3.2) ScaledMatrix 1.10.0 2023-11-06 [1] Bioconductor scales * 1.3.0 2023-11-28 [1] CRAN (R 4.3.1) scater 1.30.1 2023-11-16 [1] Bioconductor scattermore 1.2 2023-06-12 [1] CRAN (R 4.3.0) V scDblFinder * 1.16.0 2024-03-01 [1] Github (plger/scDblFinder@8c24aac) (on disk 1.17.1) scran * 1.30.2 2024-01-23 [1] Bioconductor 3.18 (R 4.3.2) sctransform 0.4.1 2023-10-19 [1] CRAN (R 4.3.1) scuttle * 1.12.0 2023-11-06 [1] Bioconductor sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) Seurat * 5.0.1 2023-11-17 [1] CRAN (R 4.3.1) SeuratObject * 5.0.1 2023-11-17 [1] CRAN (R 4.3.1) shiny 1.8.0 2023-11-17 [1] CRAN (R 4.3.1) SingleCellExperiment * 1.24.0 2023-11-06 [1] Bioconductor slam 0.1-50 2022-01-08 [1] CRAN (R 4.3.0) SoupX * 1.6.2 2022-11-01 [1] CRAN (R 4.3.0) sp * 2.1-3 2024-01-30 [1] CRAN (R 4.3.1) spam 2.10-0 2023-10-23 [1] CRAN (R 4.3.1) SparseArray * 1.2.4 2024-02-10 [1] Bioconductor 3.18 (R 4.3.2) sparseMatrixStats 1.14.0 2023-10-26 [1] Bioconductor spatstat.data 3.0-4 2024-01-15 [1] CRAN (R 4.3.1) spatstat.explore 3.2-6 2024-02-01 [1] CRAN (R 4.3.1) spatstat.geom 3.2-8 2024-01-26 [1] CRAN (R 4.3.1) spatstat.random 3.2-2 2023-11-29 [1] CRAN (R 4.3.1) spatstat.sparse 3.0-3 2023-10-24 [1] CRAN (R 4.3.1) spatstat.utils 3.0-4 2023-10-24 [1] CRAN (R 4.3.1) statmod 1.5.0 2023-01-06 [1] CRAN (R 4.3.0) stringi 1.8.3 2023-12-11 [1] CRAN (R 4.3.1) stringr * 1.5.1 2023-11-14 [1] CRAN (R 4.3.1) SummarizedExperiment * 1.32.0 2023-11-06 [1] Bioconductor V survival 3.5-7 2024-02-14 [1] CRAN (R 4.3.1) (on disk 3.5.8) systemfonts 1.0.5 2023-10-09 [1] CRAN (R 4.3.1) tensor 1.5 2012-05-05 [1] CRAN (R 4.3.0) textshaping 0.3.7 2023-10-09 [1] CRAN (R 4.3.1) tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) tidyr 1.3.1 2024-01-24 [1] CRAN (R 4.3.1) tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) UCell * 2.6.2 2023-12-19 [1] Bioconductor 3.18 (R 4.3.2) urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.3.0) usethis * 2.2.3 2024-02-19 [1] CRAN (R 4.3.1) utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1) uwot 0.1.16 2023-06-29 [1] CRAN (R 4.3.0) vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1) VGAM * 1.1-9 2023-09-19 [1] CRAN (R 4.3.1) vipor 0.4.7 2023-12-18 [1] CRAN (R 4.3.1) viridis * 0.6.5 2024-01-29 [1] CRAN (R 4.3.1) viridisLite * 0.4.2 2023-05-02 [1] CRAN (R 4.3.0) withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.1) xfun 0.42 2024-02-08 [1] CRAN (R 4.3.1) xgboost 1.7.7.1 2024-01-25 [1] CRAN (R 4.3.1) XML * 3.99-0.16.1 2024-01-22 [1] CRAN (R 4.3.1) xml2 1.3.6 2023-12-04 [1] CRAN (R 4.3.1) xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) XVector 0.42.0 2023-10-26 [1] Bioconductor yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.1) zlibbioc 1.48.0 2023-10-26 [1] Bioconductor zoo 1.8-12 2023-04-13 [1] CRAN (R 4.3.0)

[1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library

chungsai avatar Mar 01 '24 04:03 chungsai

hi @chungsai, if you can share the objects or a subset of them (for example does this also occur when merging just two of the samples), that would be useful. My email is [email protected]

saketkc avatar Mar 01 '24 17:03 saketkc

Hi yes, this occurred when I just tried 2 of them. I am sharing you a subset of my files.

chungsai avatar Mar 02 '24 00:03 chungsai

Hi!

I also got the same error.

I want to merge 6 seurat objects after performing SCT individually. However, I get the following error: "Error in .subscript.2ary(x, , j, drop = drop) : subscript out of bounds". This happens if I try to merge 2, 3, 4, 5 or the 6 objects.

If I use NormalizeData, FindVariableGenes, and ScaleData I can merge the objects with no problems.

FYI last week I had no problem merging 2 seurat objects after SCT...

Could you share the solution?

Thank you :)

martsaraiva avatar Mar 14 '24 19:03 martsaraiva

Hey, apparently it's a known bug now. And they're working on it.

chungsai avatar Mar 15 '24 00:03 chungsai

I am also getting that error when I try to subset based on features

merged_tcr.noTCRgenes <- subset(merged_tcr, features = TCR.genes) Error in .subscript.2ary(x, i, j, drop = TRUE) : subscript out of bounds

afletch00 avatar Apr 08 '24 18:04 afletch00

I have the same issue, too. Any update on this? Thank you!

shengyongniu avatar Apr 11 '24 14:04 shengyongniu

It happens the same when you run AggregateExpression and I can confirm now also with AverageExpression.

jj <- jj <- AverageExpression(ASTRO_OBJ, return.seurat= T, assays= "RNA", layer = "counts", group.by = c("donor_sex", "donor_genotype", "library_method", "library_label", "region_of_interest_acronym"))

Error in ..subscript.2ary(x, l[[1L]], l[[2L]], drop = drop[1L]) : x[i,j] too dense for [CR]sparseMatrix; would have more than 2^31-1 nonzero entries

The message indicates that the matrix I am working with is too dense for a sparse matrix representation, which would result in more than 2^31-1 nonzero entries. Should I transforme it in a sparse matrix? @mschilli87 this is a clear bug since it does not handle dense matrices

stefanonard85 avatar May 23 '24 12:05 stefanonard85

Have you tried setting return.only.var.genes=FALSE for SCTransform? If you only keep variable genes in the SCT layer, you might have data for different subsets of genes in the different Seurat objects you are trying to merge. That could trigger a subscript out of bounds error when trying to get data for a gene from the SCT assay of one object from the SCT assay of another object.

mschilli87 avatar May 23 '24 15:05 mschilli87

@stefanonard85: I was more referring to the general issue of 'subscript out of bounds when trying to merge [...] SCTransform[ed] Seurat objects'. @mariavam just told me earlier today that they got that error message in the same setup and my suggestion fixed it.

mschilli87 avatar May 23 '24 18:05 mschilli87

Thanks all for your patience -- we are continuing to work on addressing this issue and plan to have a fix soon.

igrabski avatar Jun 24 '24 18:06 igrabski

Thanks all for your patience -- we are continuing to work on addressing this issue and plan to have a fix soon.

Are there any updates for this? Or any alternative methods to merge objects in the meantime? Thanks!

malkasla avatar Jul 31 '24 13:07 malkasla

Running to the same problem when merging objects normalised with SCTransform. Any suggestions how to overcome it for now? Thank you!

juuzia avatar Aug 01 '24 14:08 juuzia

I also have the same issue when merging objects.

gucascau avatar Aug 01 '24 15:08 gucascau

I switched to Scanpy and I suggest you guys to do the same. working with big data in anndata format is far better and faster.

stefanonard85 avatar Aug 01 '24 15:08 stefanonard85