Closed alexvpickering closed 5 months ago
Thanks for reaching out @alexvpickering
It's surprising that we'd be doing this in a vignette, AFAIK this is not a supported operation. What vignette did you get this from?
Thanks for reaching out @alexvpickering
It's surprising that we'd be doing this in a vignette, AFAIK this is not a supported operation. What vignette did you get this from?
https://satijalab.org/seurat/articles/seurat5_essential_commands
Following the vignette, I keep getting error
Error in .subset2(x, i, exact = exact) : subscript out of bounds
:library(Seurat) library(SeuratData) options(Seurat.object.assay.version = "v5") pbmc3k <- LoadData("pbmc3k") class(pbmc3k[["RNA"]]) # [1] "Assay5" # attr(,"package") # [1] "SeuratObject" as(object = pbmc3k[["RNA"]], Class = "Assay") Warning: No layers found matching search pattern provided Warning: No layers found matching search pattern provided Error in .subset2(x, i, exact = exact) : subscript out of bounds In addition: Warning message: Layer ‘scale.data’ is empty
Have tried with a few different datasets and getting the same error.
sessionInfo() R version 4.4.0 (2024-04-24) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 22.04.1 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0 locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 [6] LC_MESSAGES=en_CA.UTF-8 LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C time zone: America/Vancouver tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] pbmc3k.SeuratData_3.1.4 SeuratData_0.2.2.9001 Seurat_5.1.0 SeuratObject_5.0.2 sp_2.1-4 loaded via a namespace (and not attached): [1] deldir_2.0-4 pbapply_1.7-2 gridExtra_2.3 remotes_2.5.0 rlang_1.1.3 magrittr_2.0.3 [7] RcppAnnoy_0.0.22 matrixStats_1.3.0 ggridges_0.5.6 compiler_4.4.0 spatstat.geom_3.2-9 png_0.1-8 [13] vctrs_0.6.5 reshape2_1.4.4 stringr_1.5.1 crayon_1.5.2 pkgconfig_2.0.3 fastmap_1.2.0 [19] utf8_1.2.4 promises_1.3.0 purrr_1.0.2 jsonlite_1.8.8 goftest_1.2-3 later_1.3.2 [25] spatstat.utils_3.0-4 irlba_2.3.5.1 parallel_4.4.0 cluster_2.1.6 R6_2.5.1 ica_1.0-3 [31] stringi_1.8.4 RColorBrewer_1.1-3 spatstat.data_3.0-4 reticulate_1.36.1 parallelly_1.37.1 lmtest_0.9-40 [37] scattermore_1.2 Rcpp_1.0.12 tensor_1.5 future.apply_1.11.2 zoo_1.8-12 sctransform_0.4.1 [43] httpuv_1.6.15 Matrix_1.6-5 splines_4.4.0 igraph_2.0.3 tidyselect_1.2.1 abind_1.4-5 [49] spatstat.random_3.2-3 codetools_0.2-19 miniUI_0.1.1.1 spatstat.explore_3.2-7 curl_5.2.1 listenv_0.9.1 [55] lattice_0.22-5 tibble_3.2.1 plyr_1.8.9 shiny_1.8.1.1 ROCR_1.0-11 Rtsne_0.17 [61] future_1.33.2 fastDummies_1.7.3 survival_3.5-8 polyclip_1.10-6 fitdistrplus_1.1-11 pillar_1.9.0 [67] KernSmooth_2.23-22 plotly_4.10.4 generics_0.1.3 RcppHNSW_0.6.0 ggplot2_3.5.1 munsell_0.5.1 [73] scales_1.3.0 globals_0.16.3 xtable_1.8-4 glue_1.7.0 lazyeval_0.2.2 tools_4.4.0 [79] data.table_1.15.4 RSpectra_0.16-1 RANN_2.6.1 leiden_0.4.3.1 dotCall64_1.1-1 cowplot_1.1.3 [85] grid_4.4.0 tidyr_1.3.1 colorspace_2.1-0 nlme_3.1-163 patchwork_1.2.0 cli_3.6.2 [91] rappdirs_0.3.3 spatstat.sparse_3.0-3 spam_2.10-0 fansi_1.0.6 viridisLite_0.4.2 dplyr_1.1.4 [97] uwot_0.2.2 gtable_0.3.5 digest_0.6.35 progressr_0.14.0 ggrepel_0.9.5 htmlwidgets_1.6.4 [103] htmltools_0.5.8.1 lifecycle_1.0.4 httr_1.4.7 mime_0.12 MASS_7.3-60 >
Hi, @alexvpickering. I have the same problem now, have you solved it?
Apologies for the delay, and thank you for the information 😄
I'd strongly recommend that you use CreateAssayObject
to instantiate a new v3 assay instead of converting with as
:
assay_v3 <- CreateAssayObject(
counts = pbmc3k[["RNA"]]$counts,
# optional
data = pbmc3k[["RNA"]]$data
)
pbmc3k[["RNA"]] <- assay_v3
The issue you've both encountered can be resolved by calling ScaleData
on pbmc3k
, but this also highlights why you should avoid using as
for this conversion. The Assay
and Assay5
classes are only isomorphic if the latter has layers corresponding to the three slots defined in the former (counts
, data
, scale.data
). This alignment is ensured when using Seurat’s standard preprocessing workflows, but it might not hold if your assay has non-standard layer names or is missing expected layers.
Using CreateAssayObject
ensures that your assay object is correctly instantiated with the expected v3 structure. We should have an update for our vignettes soon that will provide better guidance 👍
Thank you @dcollins15 - I ended up taking the more involved but ultimately more durable approach and switched over our app to be compatible with v3 and v5 Assays. I noticed a couple oddities that I'll post as separate issues in case they are unintentional.
Hi @dcollins15
Just to chime in on something that would be helpful if possible in implementing a new way of doing this (or updating the instructions at least) is that if one does the conversion/replacement using CreateAssayObject
then the assay meta data (variable features etc) are lost. If there is way to add feature to CreateAssayObject
/CreateAssay5Object
to transfer assay meta data that would be great!
Best, Sam
Great call @samuel-marsh - I'll add this to our roadmap 👍
Great!👍
v5 assays were designed to be behaviorly similar to and forwards-compatible with v3 assays, but are fundamentally different and violate many of the conditions of a v3 Assay. These conditions include
counts
, data
, and scale.data
for v3)matrix
and dgCMatrix
for counts
/data
and matrix
for scale.data
)scale.data
being ragged across the features)While direct conversions from a v5 assay to a v3 assay may be possible under "typical" circumstances, it's not trivial to check and verify that a v5 assays is able to be seamlessly converted to a v3 assay. SeuratObject has an internal converter used in very specific and controlled cases, and that converter should not have been exposed (our bad)
@dcollins15 during the v5 development cycle, I made a number of improvements to handling meta data additions at the Seurat
level; we should work on bringing these down to the assay level so that users can easily transfer feature-level meta data between assays that have some overlap in features. However, given the differences between v3 and v5 assays and explicit lack of backwards compatibility from v5 to v3, a direct v5 to v3 converter is out-of-scope and should not be pursued
@mojaveazure that all totally makes sense, thanks for the details!!
Hi team! I mistakenly updated seurat to V5. after that i was having a lot of problems in analyzing my data. So I switched back to V4. Now i am not able to process my object that has assay5. when i tried to plot voilin plot or other downstrem analysis i got " Error: 'RNA' is not an assay" . although it is present in object. as "S4 object of class assay5". I tried different ways mentioned above to convert Assay5 to Assay but not successful(may be due to current seurat V ‘4.4.0’.) how to solve this problem. Is any way to convert "Assay5" to "Assay" using seurat V ‘4.4.0’? thanks in advance
Following the vignette, I keep getting error
Error in .subset2(x, i, exact = exact) : subscript out of bounds
:Have tried with a few different datasets and getting the same error.