"Cannot add new cells" in Spatial Alevin Tutorial
Closed this issue · 1 comments
Hi, I have been trying to follow this tutorial but have run into a problem where Seurat appears to think I am trying to add new cells when I believe I am trying to add an assay. Here is the relevant code section and the error I receive:
DefaultAssay(object = image.data) <- "Spatial"
brain[['slice']] <- image.data
Error in `[[<-`:
! Cannot add new cells with [[<-
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `[[<-`:
! Cannot add new cells with [[<-
---
Backtrace:
▆
1. ├─methods (local) `[[<-`(`*tmp*`, "slice", value = `<VisiumV2[,600]>`)
2. └─SeuratObject (local) `[[<-`(`*tmp*`, "slice", value = `<VisiumV2[,600]>`)
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.
I checked that Seurat has not changed the sobj[["ASSAYNAME"]] <- MYASSAYOBJECT
syntax in the same R session by following this tutorial up to the line where the adt
assay is added and confirmed that the resulting object had two assays present.
I think this may be a versioning issue related to what types of objects can be added into layers (aka slots) in a Seurat object. For reference, here are some details of the objects involved:
> class(brain)
[1] "Seurat"
attr(,"package")
[1] "SeuratObject"
> class(image.data)
[1] "VisiumV2"
attr(,"package")
[1] "Seurat"
It is worth noting that I installed Salmon using the docker image found here approximately three months ago. The version number I see is 1.10.3
. Below is my sessionInfo output as well.
My best guess is that I have to adjust the object type for image.data
here to something that can be coerced into a slot in the brain
Seurat object, but I am not sure what object that should be. Let me know if I am making a simple mistake here too, I am quite rusty with the nuances of R. Thank you for your consideration and I hope to hear from the team soon!
> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS
Matrix products: default
BLAS/LAPACK: /home/chris/anaconda3/envs/r_and_python/lib/libopenblasp-r0.3.27.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/New_York
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Seurat_5.1.0 SeuratObject_5.0.2 sp_2.1-4 patchwork_1.2.0
[5] ggplot2_3.5.1 devtools_2.4.5 usethis_2.2.3 tximport_1.30.0
[9] fishpond_2.8.0
loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-3 jsonlite_1.8.8
[3] magrittr_2.0.3 spatstat.utils_3.0-5
[5] fs_1.6.4 zlibbioc_1.48.0
[7] vctrs_0.6.5 ROCR_1.0-11
[9] spatstat.explore_3.2-6 memoise_2.0.1
[11] RCurl_1.98-1.14 htmltools_0.5.8.1
[13] S4Arrays_1.2.0 SparseArray_1.2.2
[15] sctransform_0.4.1 parallelly_1.37.1
[17] KernSmooth_2.23-24 htmlwidgets_1.6.4
[19] ica_1.0-3 plyr_1.8.9
[21] plotly_4.10.4 zoo_1.8-12
[23] cachem_1.1.0 igraph_2.0.3
[25] mime_0.12 lifecycle_1.0.4
[27] pkgconfig_2.0.3 Matrix_1.6-5
[29] R6_2.5.1 fastmap_1.2.0
[31] GenomeInfoDbData_1.2.11 MatrixGenerics_1.14.0
[33] fitdistrplus_1.1-11 future_1.33.2
[35] shiny_1.8.1.1 digest_0.6.36
[37] colorspace_2.1-0 S4Vectors_0.40.2
[39] tensor_1.5 RSpectra_0.16-1
[41] irlba_2.3.5.1 pkgload_1.3.4
[43] GenomicRanges_1.54.1 progressr_0.14.0
[45] spatstat.sparse_3.1-0 fansi_1.0.6
[47] polyclip_1.10-6 httr_1.4.7
[49] abind_1.4-5 compiler_4.3.3
[51] remotes_2.5.0 withr_3.0.0
[53] fastDummies_1.7.3 pkgbuild_1.4.4
[55] MASS_7.3-60 DelayedArray_0.28.0
[57] sessioninfo_1.2.2 gtools_3.9.5
[59] tools_4.3.3 lmtest_0.9-40
[61] httpuv_1.6.15 future.apply_1.11.2
[63] goftest_1.2-3 glue_1.7.0
[65] nlme_3.1-165 promises_1.3.0
[67] grid_4.3.3 Rtsne_0.17
[69] reshape2_1.4.4 cluster_2.1.6
[71] generics_0.1.3 spatstat.data_3.1-2
[73] gtable_0.3.5 tidyr_1.3.1
[75] data.table_1.15.4 utf8_1.2.4
[77] XVector_0.42.0 spatstat.geom_3.2-9
[79] BiocGenerics_0.48.1 RcppAnnoy_0.0.22
[81] ggrepel_0.9.5 RANN_2.6.1
[83] pillar_1.9.0 stringr_1.5.1
[85] spam_2.10-0 RcppHNSW_0.6.0
[87] later_1.3.2 splines_4.3.3
[89] dplyr_1.1.4 lattice_0.22-6
[91] deldir_2.0-4 survival_3.7-0
[93] tidyselect_1.2.1 SingleCellExperiment_1.24.0
[95] miniUI_0.1.1.1 pbapply_1.7-2
[97] gridExtra_2.3 IRanges_2.36.0
[99] SummarizedExperiment_1.32.0 scattermore_1.2
[101] stats4_4.3.3 Biobase_2.62.0
[103] matrixStats_1.3.0 stringi_1.8.4
[105] lazyeval_0.2.2 codetools_0.2-20
[107] tibble_3.2.1 cli_3.6.3
[109] uwot_0.1.16 xtable_1.8-4
[111] reticulate_1.38.0 munsell_0.5.1
[113] Rcpp_1.0.12 GenomeInfoDb_1.38.1
[115] spatstat.random_3.2-3 globals_0.16.3
[117] svMisc_1.2.3 png_0.1-8
[119] parallel_4.3.3 ellipsis_0.3.2
[121] dotCall64_1.1-1 profvis_0.3.8
[123] urlchecker_1.0.1 bitops_1.0-7
[125] listenv_0.9.1 viridisLite_0.4.2
[127] scales_1.3.0 ggridges_0.5.6
[129] leiden_0.4.3.1 purrr_1.0.2
[131] crayon_1.5.3 rlang_1.1.4
[133] cowplot_1.1.3
I managed to figure out what I assume is the up-to-date way of doing things. I will post the code that works for me here in case anyone else comes across this issue:
suppressPackageStartupMessages({
library(fishpond)
library(tximport)
library(devtools)
library(ggplot2)
library(patchwork)
# Just install Seurat like normal. Tutorial's allusion to a "spatial" branch appears to be outdated.
library(Seurat)
})
# navigate to data directory
wkdir <- "path/to/alevin_data/"
setwd(wkdir)
# load in alevin output
files <- file.path("alevin_out/alevin/quants_mat.gz")
file.exists(files)
# set prefix for output files
prefix = "alevin"
# tximport loads the alevin data into R
txi <- tximport(files = files, type = "alevin")
# Creating a Seurat object with spatial assay
assay <- "Spatial"
brain <- CreateSeuratObject(counts = txi$counts, project = "SPATIAL", assay = assay)
brain
# loading the 10x image data
seqdir <- "path/to/10x_imaging_data/"
image.data <- Read10X_Image(paste0(seqdir,"spatial/"))
# Since the names of alevin cb is different from 10x
# we rename the cells and filter the image data
# to have the metadata for only quantified cells
image.data@boundaries$centroids@cells <- gsub("-1", "", image.data@boundaries$centroids@cells)
common.cells <- intersect(Cells(x = brain), image.data@boundaries$centroids@cells)
# Subset the centroids object
centroids <- image.data@boundaries$centroids
# Find indices of common cells
common_indices <- which(centroids@cells %in% common.cells)
# Subset the cells and coords slots
centroids@cells <- centroids@cells[common_indices]
centroids@coords <- centroids@coords[common_indices, ]
# Update the image.data object with the subsetted centroids
image.data@boundaries$centroids <- centroids
# Update the brain object accordingly
brain <- subset(brain, cells = common.cells)
# adding image data to Seurat object
DefaultAssay(object = image.data) <- "Spatial"
brain@images[['slice']] <- image.data
The rest of the tutorial (plotting and clustering) is fairly standard and should work just fine. Of course, if your setup differs substantially from mine, it is certainly possible you will encounter different behavior so stay vigilent!