seurat
seurat copied to clipboard
Error whilst subsetting a Seurat 5 object: Error in check_valid_matrix(x) : no slot of name "i" for this object of class "Graph"
I'm trying to subset a Seurat 5, BP cells object but I get the following error:
cells_keep <- [email protected] |>
filter(str_detect(cellIDs, cells_retain)) |>
pull(cellIDs) |>
unique() |>
as.character()
seurat_obj <- subset(seurat_obj, subset = cellIDs %in% cells_keep)
# subset(seurat_obj, idents = cells_keep)
# subset(seurat_obj, cells = WhichCells(seurat_obj, idents = cells_keep))
#> Error in check_valid_matrix(x) :
#> no slot of name "i" for this object of class "Graph"
I followed the procedure in the Sketch vignette and projected the clusters onto the full dataset that, as far as I can tell, worked well (note that RNA is the active assay here):
seurat_obj
#> An object of class Seurat
#> 60276 features across 331133 samples within 2 assays
#> Active assay: RNA (30138 features, 2000 variable features)
#> 2 layers present: data, counts
#> 1 other assay present: sketch
#> 6 dimensional reductions calculated: pca, umap, harmony, umap.harmony, harmony.full, umap.full
I've checked the graph
slot of the Seurat object (which I'm assuming the error above is referring to), but I only see sketch based graphs, could this be the issue? Should the data projection process be creating a graph object that the subset function is looking for?
seurat_obj@graphs
#> $sketch_nn
#> A Graph object containing 60866 cells
#> $sketch_snn
#> A Graph object containing 60866 cells
That said, I actually tried to subset on the sketch object too, but got the same error. The same error also occurs when trying to subset after converting the on disk count and data matrices back to in memory matrices with the following:
seurat_obj[["RNA"]]$counts <- as(object = seurat_obj[["RNA"]]$counts, Class = "dgCMatrix")
seurat_obj[["RNA"]]$data <- as(object = seurat_obj[["RNA"]]$data, Class = "dgCMatrix")
Any advice you could offer to help get around this issue would be greatly appreciated.
Session info
R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.7.10
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] MatrixExtra_0.1.15 Matrix_1.6-5 egg_0.4.5
[4] gridExtra_2.3 rmarkdown_2.27 GeneOverlap_1.38.0
[7] enrichR_3.2 kableExtra_1.4.0 hdWGCNA_0.3.03
[10] igraph_2.0.3 ggrepel_0.9.5 harmony_1.2.0
[13] Rcpp_1.0.12 WGCNA_1.72-5 fastcluster_1.2.6
[16] dynamicTreeCut_1.63-1 patchwork_1.2.0 lubridate_1.9.3
[19] forcats_1.0.0 stringr_1.5.1 purrr_1.0.2
[22] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[25] tidyverse_2.0.0 scater_1.30.1 ggplot2_3.5.1
[28] scuttle_1.12.0 SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0
[31] Biobase_2.62.0 GenomicRanges_1.54.1 GenomeInfoDb_1.38.8
[34] IRanges_2.36.0 S4Vectors_0.40.2 BiocGenerics_0.48.1
[37] MatrixGenerics_1.14.0 matrixStats_1.3.0 cowplot_1.1.3
[40] readxl_1.4.3 scCustomize_2.1.2 dplyr_1.1.4
[43] Azimuth_0.5.0 SeuratWrappers_0.3.2 SeuratDisk_0.0.0.9021
[46] Seurat_5.1.0 SeuratObject_5.0.2 sp_2.1-4
[49] BPCells_0.1.0 yaml_2.3.8 shinyBS_0.61.1
loaded via a namespace (and not attached):
[1] R.methodsS3_1.8.2 progress_1.2.3 nnet_7.3-19
[4] poweRlaw_0.80.0 goftest_1.2-3 DT_0.33
[7] Biostrings_2.70.3 vctrs_0.6.5 spatstat.random_3.2-3
[10] proxy_0.4-27 digest_0.6.35 png_0.1-8
[13] shape_1.4.6.1 deldir_2.0-4 parallelly_1.37.1
[16] MASS_7.3-60.0.1 Signac_1.13.0 reshape2_1.4.4
[19] rematch_2.0.0 foreach_1.5.2 httpuv_1.6.15
[22] withr_3.0.0 ggrastr_1.0.2 xfun_0.45
[25] survival_3.7-0 EnsDb.Hsapiens.v86_2.99.0 memoise_2.0.1
[28] ggbeeswarm_0.7.2 janitor_2.2.0 systemfonts_1.1.0
[31] ragg_1.3.2 zoo_1.8-12 GlobalOptions_0.1.2
[34] gtools_3.9.5 pbapply_1.7-2 R.oo_1.26.0
[37] Formula_1.2-5 prettyunits_1.2.0 rematch2_2.1.2
[40] KEGGREST_1.42.0 promises_1.3.0 httr_1.4.7
[43] restfulr_0.0.15 globals_0.16.3 fitdistrplus_1.1-11
[46] rhdf5filters_1.14.1 rhdf5_2.46.1 rstudioapi_0.16.0
[49] miniUI_0.1.1.1 generics_0.1.3 base64enc_0.1-3
[52] curl_5.2.1 zlibbioc_1.48.2 ScaledMatrix_1.10.0
[55] polyclip_1.10-6 GenomeInfoDbData_1.2.11 SparseArray_1.2.4
[58] doParallel_1.0.17 xtable_1.8-4 pracma_2.4.4
[61] evaluate_0.24.0 S4Arrays_1.2.1 preprocessCore_1.64.0
[64] BiocFileCache_2.10.2 hms_1.1.3 irlba_2.3.5.1
[67] colorspace_2.1-0 filelock_1.0.3 hdf5r_1.3.10
[70] ROCR_1.0-11 float_0.3-2 reticulate_1.37.0
[73] spatstat.data_3.0-4 magrittr_2.0.3 lmtest_0.9-40
[76] snakecase_0.11.1 later_1.3.2 viridis_0.6.5
[79] lattice_0.22-6 spatstat.geom_3.2-9 future.apply_1.11.2
[82] scattermore_1.2 XML_3.99-0.16.1 RcppAnnoy_0.0.22
[85] Hmisc_5.1-3 pillar_1.9.0 nlme_3.1-165
[88] iterators_1.0.14 caTools_1.18.2 compiler_4.3.2
[91] beachmat_2.18.1 RSpectra_0.16-1 stringi_1.8.4
[94] tensor_1.5 GenomicAlignments_1.38.2 plyr_1.8.9
[97] crayon_1.5.2 abind_1.4-5 BiocIO_1.12.0
[100] googledrive_2.1.1 bit_4.0.5 fastmatch_1.1-4
[103] textshaping_0.4.0 codetools_0.2-20 BiocSingular_1.18.0
[106] SeuratData_0.2.2.9001 paletteer_1.6.0 plotly_4.10.4
[109] mime_0.12 splines_4.3.2 circlize_0.4.16
[112] fastDummies_1.7.3 dbplyr_2.5.0 sparseMatrixStats_1.14.0
[115] cellranger_1.1.0 knitr_1.47 blob_1.2.4
[118] utf8_1.2.4 seqLogo_1.68.0 AnnotationFilter_1.26.0
[121] WriteXLS_6.7.0 fs_1.6.4 checkmate_2.3.1
[124] listenv_0.9.1 DelayedMatrixStats_1.24.0 svglite_2.1.3
[127] tzdb_0.4.0 pkgconfig_2.0.3 tools_4.3.2
[130] cachem_1.1.0 RhpcBLASctl_0.23-42 RSQLite_2.3.7
[133] viridisLite_0.4.2 DBI_1.2.3 impute_1.76.0
[136] fastmap_1.2.0 scales_1.3.0 grid_4.3.2
[139] ica_1.0-3 shinydashboard_0.7.2 Rsamtools_2.18.0
[142] BiocManager_1.30.23 ggprism_1.0.5 dotCall64_1.1-1
[145] rpart_4.1.23 RANN_2.6.1 farver_2.1.2
[148] foreign_0.8-86 rtracklayer_1.62.0 cli_3.6.2
[151] tester_0.2.0 leiden_0.4.3.1 lifecycle_1.0.4
[154] uwot_0.2.2 backports_1.5.0 presto_1.0.0
[157] BSgenome.Hsapiens.UCSC.hg38_1.4.5 BiocParallel_1.36.0 annotate_1.80.0
[160] timechange_0.3.0 gtable_0.3.5 rjson_0.2.21
[163] ggridges_0.5.6 progressr_0.14.0 parallel_4.3.2
[166] jsonlite_1.8.8 RcppHNSW_0.6.0 TFBSTools_1.40.0
[169] bitops_1.0-7 bit64_4.0.5 Rtsne_0.17
[172] spatstat.utils_3.0-5 BiocNeighbors_1.20.2 CNEr_1.38.0
[175] shinyjs_2.1.0 R.utils_2.12.3 lazyeval_0.2.2
[178] shiny_1.9.1 htmltools_0.5.8.1 GO.db_3.18.0
[181] sctransform_0.4.1 rappdirs_0.3.3 ensembldb_2.26.0
[184] glue_1.7.0 TFMPvalue_0.0.9 spam_2.10-0
[187] googlesheets4_1.1.1 XVector_0.42.0 RCurl_1.98-1.14
[190] BSgenome_1.70.2 JASPAR2020_0.99.10 R6_2.5.1
[193] gplots_3.1.3.1 RcppRoll_0.3.0 GenomicFeatures_1.54.4
[196] cluster_2.1.6 Rhdf5lib_1.24.2 gargle_1.5.2
[199] DirichletMultinomial_1.44.0 DelayedArray_0.28.0 tidyselect_1.2.1
[202] vipor_0.4.7 ProtGenerics_1.34.0 htmlTable_2.4.2
[205] xml2_1.3.6 AnnotationDbi_1.64.1 future_1.33.2
[208] rsvd_1.0.5 munsell_0.5.1 KernSmooth_2.23-24
[211] data.table_1.15.4 htmlwidgets_1.6.4 RColorBrewer_1.1-3
[214] biomaRt_2.58.2 rlang_1.1.4 spatstat.sparse_3.0-3
[217] spatstat.explore_3.2-7 remotes_2.5.0 fansi_1.0.6
[220] beeswarm_0.4.0