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

Error using LoadXenium() #7491

Open
Margokap opened this issue Jun 23, 2023 · 20 comments
Open

Error using LoadXenium() #7491

Margokap opened this issue Jun 23, 2023 · 20 comments
Labels
bug Something isn't working

Comments

@Margokap
Copy link

Hi there, I've encountered difficulties reading in Xenium data from 10x genomics, using the LoadXenium() function with Seurat V5. I have used the function to successfully read in mouse Xenium datasets, so am not sure what is causing the problem - as the file structure is the same for both.

I get the following:

xenium.obj <- LoadXenium("xenium-human", fov = "fov")
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
Error in CreateAssayObject(counts = data$matrix[["Blank Codeword"]]) :
No cell names (colnames) names present in the input matrix

Thanks for all your help!

&session info:

sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C LC_TIME=English_United States.utf8

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

other attached packages:
[1] SeuratDisk_0.0.0.9020 plotly_4.10.2 Matrix_1.5-3 dplyr_1.1.2 spacexr_2.2.1 Seurat_4.3.0
[7] ggplot2_3.4.2 future_1.32.0 SeuratObject_4.1.3 sp_1.6-0

loaded via a namespace (and not attached):
[1] Rtsne_0.16 colorspace_2.1-0 deldir_1.0-9 ellipsis_0.3.2 ggridges_0.5.4 rprojroot_2.0.3
[7] rstudioapi_0.14 spatstat.data_3.0-1 leiden_0.4.3 listenv_0.9.0 farver_2.1.1 remotes_2.4.2
[13] bit64_4.0.5 ggrepel_0.9.3 fansi_1.0.4 R.methodsS3_1.8.2 codetools_0.2-18 splines_4.2.1
[19] doParallel_1.0.17 polyclip_1.10-4 jsonlite_1.8.5 ica_1.0-3 cluster_2.1.4 rgeos_0.6-3
[25] R.oo_1.25.0 png_0.1-8 uwot_0.1.14 shiny_1.7.4 sctransform_0.3.5 spatstat.sparse_3.0-1
[31] BiocManager_1.30.19 readr_2.1.4 compiler_4.2.1 httr_1.4.6 fastmap_1.1.1 lazyeval_0.2.2
[37] limma_3.54.2 cli_3.6.1 later_1.3.1 prettyunits_1.1.1 htmltools_0.5.5 tools_4.2.1
[43] igraph_1.4.3 gtable_0.3.3 glue_1.6.2 RANN_2.6.1 reshape2_1.4.4 Rcpp_1.0.10
[49] scattermore_1.2 vctrs_0.6.2 spatstat.explore_3.2-1 nlme_3.1-162 progressr_0.13.0 crosstalk_1.2.0
[55] iterators_1.0.14 lmtest_0.9-40 spatstat.random_3.1-5 stringr_1.5.0 ps_1.7.5 globals_0.16.2
[61] mime_0.12 miniUI_0.1.1.1 lifecycle_1.0.3 irlba_2.3.5.1 goftest_1.2-3 MASS_7.3-60
[67] zoo_1.8-12 scales_1.2.1 hms_1.1.3 promises_1.2.0.1 spatstat.utils_3.0-3 parallel_4.2.1
[73] RColorBrewer_1.1-3 curl_5.0.1 yaml_2.3.7 reticulate_1.30 pbapply_1.7-0 gridExtra_2.3
[79] stringi_1.7.12 desc_1.4.2 foreach_1.5.2 pkgbuild_1.4.1 rlang_1.1.1 pkgconfig_2.0.3
[85] matrixStats_1.0.0 lattice_0.20-45 ROCR_1.0-11 purrr_1.0.1 tensor_1.5 patchwork_1.1.2
[91] htmlwidgets_1.6.2 labeling_0.4.2 processx_3.8.1 bit_4.0.5 cowplot_1.1.1 tidyselect_1.2.0
[97] parallelly_1.36.0 RcppAnnoy_0.0.20 plyr_1.8.8 magrittr_2.0.3 R6_2.5.1 generics_0.1.3
[103] pillar_1.9.0 withr_2.5.0 fitdistrplus_1.1-11 survival_3.5-5 abind_1.4-5 tibble_3.2.1
[109] future.apply_1.11.0 hdf5r_1.3.8 crayon_1.5.2 KernSmooth_2.23-20 utf8_1.2.3 spatstat.geom_3.2-1
[115] tzdb_0.4.0 grid_4.2.1 data.table_1.14.8 callr_3.7.3 digest_0.6.31 xtable_1.8-4
[121] tidyr_1.3.0 httpuv_1.6.11 R.utils_2.12.2 munsell_0.5.0 viridisLite_0.4.2 quadprog_1.5-8
Warning messages:
1: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
2: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
3: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"

@Margokap Margokap added the bug Something isn't working label Jun 23, 2023
@alikhuseynov
Copy link

I think it depends on what you have in the folder passed to data.dir
The easiest way is to ReadXenium() first, like:

data <- ReadXenium(
    data.dir = data.dir,
    type = c("centroids", "segmentations"),
  )

then check if you have data$matrix[["Blank Codeword"]] inside the data list

@Margokap
Copy link
Author

Thanks for the help! Using the method you suggested, this is what I get

data <- ReadXenium(data.dir = data.dir, type =c('centroids', 'segmentation'))
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
data$matrix[["Blank Codeword"]]
NULL

I manually examined the files in the Xenium data, and the features.tsv file uses the the naming convention "Unassigned Codeword", whereas the mouse data used "Blank Codeword". Do you have any suggestions?

I attempted to troubleshoot: If I replace "Unassigned Codeword" to "Blank Codeword" from the features.tsv, and try to read in the data again, I get a different error:

reprex:
(here I rename unassigned codeword to blank codeword, and update the features.tsv file)

features <- read_tsv('features.tsv')
View(features)
features[features == "Unassigned Codeword"] <- "Blank Codeword"
write_tsv(x = features,
file = "features-blank.tsv")

(here I read in the data with the updated features.tsv file)

xeni-human <- LoadXenium(data.dir = data.dir)
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Error in [[<-:
! Cannot add new cells with [[<-
Run rlang::last_trace() to see where the error occurred.

Thanks again!

sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C LC_TIME=English_United States.utf8

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

other attached packages:
[1] SeuratDisk_0.0.0.9020 plotly_4.10.2 Matrix_1.5-3 dplyr_1.1.2 spacexr_2.2.1 Seurat_4.3.0
[7] ggplot2_3.4.2 future_1.32.0 SeuratObject_4.1.3 sp_1.6-0

loaded via a namespace (and not attached):
[1] Rtsne_0.16 colorspace_2.1-0 deldir_1.0-9 ellipsis_0.3.2 ggridges_0.5.4 rprojroot_2.0.3
[7] rstudioapi_0.14 spatstat.data_3.0-1 leiden_0.4.3 listenv_0.9.0 farver_2.1.1 remotes_2.4.2
[13] bit64_4.0.5 ggrepel_0.9.3 fansi_1.0.4 R.methodsS3_1.8.2 codetools_0.2-18 splines_4.2.1
[19] doParallel_1.0.17 polyclip_1.10-4 jsonlite_1.8.5 ica_1.0-3 cluster_2.1.4 rgeos_0.6-3
[25] R.oo_1.25.0 png_0.1-8 uwot_0.1.14 shiny_1.7.4 sctransform_0.3.5 spatstat.sparse_3.0-1
[31] BiocManager_1.30.19 readr_2.1.4 compiler_4.2.1 httr_1.4.6 fastmap_1.1.1 lazyeval_0.2.2
[37] limma_3.54.2 cli_3.6.1 later_1.3.1 prettyunits_1.1.1 htmltools_0.5.5 tools_4.2.1
[43] igraph_1.4.3 gtable_0.3.3 glue_1.6.2 RANN_2.6.1 reshape2_1.4.4 Rcpp_1.0.10
[49] scattermore_1.2 vctrs_0.6.2 spatstat.explore_3.2-1 nlme_3.1-162 progressr_0.13.0 crosstalk_1.2.0
[55] iterators_1.0.14 lmtest_0.9-40 spatstat.random_3.1-5 stringr_1.5.0 ps_1.7.5 globals_0.16.2
[61] mime_0.12 miniUI_0.1.1.1 lifecycle_1.0.3 irlba_2.3.5.1 goftest_1.2-3 MASS_7.3-60
[67] zoo_1.8-12 scales_1.2.1 hms_1.1.3 promises_1.2.0.1 spatstat.utils_3.0-3 parallel_4.2.1
[73] RColorBrewer_1.1-3 curl_5.0.1 yaml_2.3.7 reticulate_1.30 pbapply_1.7-0 gridExtra_2.3
[79] stringi_1.7.12 desc_1.4.2 foreach_1.5.2 pkgbuild_1.4.1 rlang_1.1.1 pkgconfig_2.0.3
[85] matrixStats_1.0.0 lattice_0.20-45 ROCR_1.0-11 purrr_1.0.1 tensor_1.5 patchwork_1.1.2
[91] htmlwidgets_1.6.2 labeling_0.4.2 processx_3.8.1 bit_4.0.5 cowplot_1.1.1 tidyselect_1.2.0
[97] parallelly_1.36.0 RcppAnnoy_0.0.20 plyr_1.8.8 magrittr_2.0.3 R6_2.5.1 generics_0.1.3
[103] pillar_1.9.0 withr_2.5.0 fitdistrplus_1.1-11 survival_3.5-5 abind_1.4-5 tibble_3.2.1
[109] future.apply_1.11.0 hdf5r_1.3.8 crayon_1.5.2 KernSmooth_2.23-20 utf8_1.2.3 spatstat.geom_3.2-1
[115] tzdb_0.4.0 grid_4.2.1 data.table_1.14.8 callr_3.7.3 digest_0.6.31 xtable_1.8-4
[121] tidyr_1.3.0 httpuv_1.6.11 R.utils_2.12.2 munsell_0.5.0 viridisLite_0.4.2 quadprog_1.5-8
Warning messages:
1: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
2: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
3: In UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"

@alikhuseynov
Copy link

I see, it is related to the new Xenium output.

What else is in your data list output?
Do you get data$matrix[["Unassigned Codeword"]] ?

Take a look at this PR #7346, the easiest way would be to install that updated branch from the contributor and see if it works
remotes::install_github(repo = 'Ceallaig33/seurat', ref = 'patch-1') If this does not work, please add a comment on that PR, ie your issue.
Else you would need to ReadXenium() first, then using data list outputs create spatial Seurat object manually, adding FOVs as in LoadXenium() function.
Hope this helps.

@Margokap
Copy link
Author

Great thank you so much for your suggestions. The data list output includes 'Gene Expression', 'Negative Control Codeword', 'Negative Control Probe', and 'Unassigned Codeword'.
Screen Shot 2023-06-28 at 2 00 11 PM

As you anticipated, I get output for data$matrix[["Unassigned Codeword"]]

ie:

data$matrix[["Unassigned Codeword"]]
161 x 24406 sparse Matrix of class "dgCMatrix"
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0014 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0016 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0019 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0020 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0021 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0022 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0026 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

..............................
........suppressing 24367 columns and 136 rows in show(); maybe adjust 'options(max.print= *, width = *)'
..............................
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0460 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0466 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0471 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0472 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0473 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0475 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0483 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0484 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0487 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0489 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0490 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0494 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

data$matrix[["Unassigned Codeword"]]
161 x 24406 sparse Matrix of class "dgCMatrix"
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0014 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0016 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0019 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0020 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0021 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0022 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0026 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

..............................
........suppressing 24367 columns and 136 rows in show(); maybe adjust 'options(max.print= *, width = *)'
..............................
[[ suppressing 39 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0460 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0466 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0471 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0472 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0473 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0475 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0483 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0484 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0487 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0489 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0490 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0494 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Secondly, using the updated branch from the contributor did not resolve the issue.

reprex:

xeni-human <- LoadXenium(data.dir = data.dir)
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
Error in [[<-:
! Cannot add new cells with [[<-
Run rlang::last_trace() to see where the error occurred.

Thank you so much for all your help, I will follow up with the PR, and use ReadXenium() function if not resolved.

@alikhuseynov
Copy link

alikhuseynov commented Jun 28, 2023

ok, if you want, try out this:

  • keep the original 'features.tsv', not the one you have changed
  • data <- ReadXenium(data.dir = data.dir, type =c('centroids', 'segmentation')) as before
  • then test the following code to see where the error appears:
assay <- "Xenium"
segmentations.data <- list(
    "centroids" = CreateCentroids(data$centroids),
    "segmentation" = CreateSegmentation(data$segmentations)
  )
  coords <- CreateFOV(
    coords = segmentations.data,
    type = c("segmentation", "centroids"),
    molecules = data$microns,
    assay = assay
  )

  xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
  xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
  xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
  xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])

  fov <- "test"
  xenium.obj[[fov]] <- coords

@Margokap
Copy link
Author

thank you for your suggestion! Here is my output, it seems that I have a similar error - I am not sure what is causing it.

reprex:

data <- ReadXenium(data.dir = data.dir, type =c('centroids', 'segmentation'))
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
data$matrix[["Unassigned Codeword"]]
161 x 24406 sparse Matrix of class "dgCMatrix"
[[ suppressing 64 column names ‘barcodes’, ‘1’, ‘2’ ... ]]
[[ suppressing 64 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0014 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0016 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

..............................
........suppressing 24342 columns and 146 rows in show(); maybe adjust 'options(max.print= *, width = *)'
..............................
[[ suppressing 64 column names ‘barcodes’, ‘1’, ‘2’ ... ]]

BLANK_0475 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0483 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0484 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0487 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0489 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0490 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......
BLANK_0494 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......

assay <- "Xenium"
segmentations.data <- list(
"centroids" = CreateCentroids(data$centroids),
"segmentation" = CreateSegmentation(data$segmentations)
)
coords <- CreateFOV(
coords = segmentations.data,
type = c("segmentation", "centroids"),
molecules = data$microns,
assay = assay
)

xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')
xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])
Warning: Feature names cannot have underscores (''), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('
'), replacing with dashes ('-')

fov <- "test"
xenium.obj[[fov]] <- coords
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*, fov, value = <FOV[,0]>)
  2. └─SeuratObject (local) [[<-(*tmp*, fov, value = <FOV[,0]>)
    Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.

rlang::last_trace(drop = FALSE)
<error/rlang_error>
Error in [[<-:
! Cannot add new cells with [[<-


Backtrace:

  1. ├─methods (local) [[<-(*tmp*, fov, value = <FOV[,0]>)
  2. └─SeuratObject (local) [[<-(*tmp*, fov, value = <FOV[,0]>)
  3. └─rlang::abort(message = "Cannot add new cells with [[<-")

Thanks again for all your help with this issue.

&sesioninfo:

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

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

other attached packages:
[1] ggplot2_3.4.2 future_1.32.0 Seurat_4.9.9.9045 SeuratObject_4.9.9.9086 sp_2.0-0

loaded via a namespace (and not attached):
[1] Rtsne_0.16 colorspace_2.1-0 deldir_1.0-9 ellipsis_0.3.2 ggridges_0.5.4 RcppHNSW_0.4.1
[7] rstudioapi_0.14 spatstat.data_3.0-1 leiden_0.4.3 listenv_0.9.0 bit64_4.0.5 ggrepel_0.9.3
[13] RSpectra_0.16-1 fansi_1.0.4 codetools_0.2-18 splines_4.2.1 R.methodsS3_1.8.2 polyclip_1.10-4
[19] spam_2.9-1 jsonlite_1.8.5 ica_1.0-3 cluster_2.1.4 R.oo_1.25.0 png_0.1-8
[25] uwot_0.1.15 shiny_1.7.4 sctransform_0.3.5 spatstat.sparse_3.0-2 compiler_4.2.1 httr_1.4.6
[31] Matrix_1.5-1 fastmap_1.1.1 lazyeval_0.2.2 cli_3.6.1 later_1.3.1 htmltools_0.5.5
[37] tools_4.2.1 igraph_1.5.0 dotCall64_1.0-2 gtable_0.3.3 glue_1.6.2 RANN_2.6.1
[43] reshape2_1.4.4 dplyr_1.1.2 Rcpp_1.0.10 scattermore_1.2 vctrs_0.6.3 spatstat.explore_3.2-1
[49] nlme_3.1-160 progressr_0.13.0 lmtest_0.9-40 spatstat.random_3.1-5 stringr_1.5.0 globals_0.16.2
[55] mime_0.12 miniUI_0.1.1.1 lifecycle_1.0.3 irlba_2.3.5.1 goftest_1.2-3 MASS_7.3-58.1
[61] zoo_1.8-12 scales_1.2.1 promises_1.2.0.1 spatstat.utils_3.0-3 parallel_4.2.1 RColorBrewer_1.1-3
[67] reticulate_1.30 pbapply_1.7-2 gridExtra_2.3 stringi_1.7.12 fastDummies_1.6.3 rlang_1.1.1
[73] pkgconfig_2.0.3 matrixStats_1.0.0 lattice_0.20-45 ROCR_1.0-11 purrr_1.0.1 tensor_1.5
[79] patchwork_1.1.2 htmlwidgets_1.6.2 bit_4.0.5 cowplot_1.1.1 tidyselect_1.2.0 parallelly_1.36.0
[85] RcppAnnoy_0.0.20 plyr_1.8.8 magrittr_2.0.3 R6_2.5.1 generics_0.1.3 pillar_1.9.0
[91] withr_2.5.0 fitdistrplus_1.1-11 survival_3.4-0 abind_1.4-5 tibble_3.2.1 future.apply_1.11.0
[97] KernSmooth_2.23-20 utf8_1.2.3 spatstat.geom_3.2-1 plotly_4.10.2 grid_4.2.1 data.table_1.14.8
[103] digest_0.6.32 xtable_1.8-4 tidyr_1.3.0 httpuv_1.6.11 R.utils_2.12.2 munsell_0.5.0
[109] viridisLite_0.4.2

@alikhuseynov
Copy link

ok, it happens when you are adding FOVs.
run the same code as before, but subset coords to have the same cells as the object.

coords %>% 
    # only consider the cells we have counts and a segmentation.
    subset(x = .,
           cells = intersect(x = Cells(x = .[["segmentation"]]),
                               y = Cells(x = xenium.obj)))
fov <- "test"
xenium.obj[[fov]] <- coords

@Margokap
Copy link
Author

thank you for all your help - here was my output. I'm not sure what's causing this error, I really appreciate your suggestions.

> assay <- "Xenium"
> segmentations.data <- list(
   "centroids" = CreateCentroids(data$centroids),
   "segmentation" = CreateSegmentation(data$segmentations)
 )
> coords <- CreateFOV(
   coords = segmentations.data,
   type = c("segmentation", "centroids"),
   molecules = data$microns,
   assay = assay
 )
> 
> xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
> xenium.obj[["Blank Codeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["Control Codeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["Control Probe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> 
> coords %>%
# only consider the cells we have counts and a segmentation.
   subset(x = .,
          cells = intersect(x = Cells(x = .[["segmentation"]]),
                            y = Cells(x = xenium.obj)))
Error in subset.Centroids(x = x[[i]], cells = cells) : 
  None of the requested cells found

@alikhuseynov
Copy link

alikhuseynov commented Jun 29, 2023

ok, no worries. I think we are almost there ;)
if you do Cells(coords[["segmentation"]]) %>% str
do you get the cell IDs?

Error in subset.Centroids(x = x[[i]], cells = cells) : None of the requested cells found is a current bug in SeuratObject.
related issue 6409
#7462

You can try to use the optimized subset version I did some time ago
older one and the current one

Basically for that code chunk it would be:

# source the subset function
source("./subset_obj_seurat.R") # or subset_obj_seurat_v2.R

# run all the code as before..

coords %>% 
    # only consider the cells we have counts and a segmentation.
    subset_opt(x = .,
           cells = intersect(x = Cells(x = .[["segmentation"]]),
                               y = Cells(x = xenium.obj)))
fov <- "test"
xenium.obj[[fov]] <- coords

Let me know

@Margokap
Copy link
Author

thanks so much for the help;

output for cell ID's - this seems correct

> Cells(coords[["segmentation"]]) %>% str 
 chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" "aaaonnnp-1" "aabfjnfi-1" ...

here is trying the optimized subset function (I tried both versions), and they both produce the following error.

> coords %>% 
+   # only consider the cells we have counts and a segmentation.
+   subset_opt(x = .,
+              cells = intersect(x = Cells(x = .[["segmentation"]]),
+                                y = Cells(x = xenium.obj)))
Updating object slots..
Cloing object..
Matching cells in FOVs..
 Error in slot(object = object, name = "images") : 
cannot get a slot ("images") from an object of type "NULL"
9.
slot(object = object, name = "images")
8.
Images(obj_subset)
7.
seq(.)
6.
Images(obj_subset) %>% seq
5.
lapply(Images(obj_subset) %>% seq, function(i) {
any(obj_subset[[Images(obj_subset)[i]]][["centroids"]] %>% 
Cells %in% cells)
})
4.
unlist(.)
3.
lapply(Images(obj_subset) %>% seq, function(i) {
any(obj_subset[[Images(obj_subset)[i]]][["centroids"]] %>% 
Cells %in% cells)
}) %>% unlist
2.
subset_opt(x = ., cells = intersect(x = Cells(x = .[["segmentation"]]), 
y = Cells(x = xenium.obj)))
1.
coords %>% subset_opt(x = ., cells = intersect(x = Cells(x = .[["segmentation"]]), 
y = Cells(x = xenium.obj)))
Screen Shot 2023-06-29 at 12 37 36 PM

Thanks again for your time & help!

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

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

other attached packages:
[1] magrittr_2.0.3          dplyr_1.1.2             enrichR_3.2             ggplot2_3.4.2          
[5] future_1.32.0           Seurat_4.9.9.9045       SeuratObject_4.9.9.9086 sp_2.0-0               

loaded via a namespace (and not attached):
  [1] Rtsne_0.16             colorspace_2.1-0       rjson_0.2.21           deldir_1.0-9          
  [5] ellipsis_0.3.2         ggridges_0.5.4         RcppHNSW_0.4.1         rstudioapi_0.14       
  [9] spatstat.data_3.0-1    farver_2.1.1           leiden_0.4.3           listenv_0.9.0         
 [13] bit64_4.0.5            ggrepel_0.9.3          RSpectra_0.16-1        fansi_1.0.4           
 [17] codetools_0.2-18       splines_4.2.1          R.methodsS3_1.8.2      polyclip_1.10-4       
 [21] spam_2.9-1             jsonlite_1.8.5         ica_1.0-3              cluster_2.1.4         
 [25] R.oo_1.25.0            png_0.1-8              uwot_0.1.15            shiny_1.7.4           
 [29] sctransform_0.3.5      spatstat.sparse_3.0-2  compiler_4.2.1         httr_1.4.6            
 [33] Matrix_1.5-1           fastmap_1.1.1          lazyeval_0.2.2         cli_3.6.1             
 [37] later_1.3.1            htmltools_0.5.5        tools_4.2.1            igraph_1.5.0          
 [41] dotCall64_1.0-2        gtable_0.3.3           glue_1.6.2             RANN_2.6.1            
 [45] reshape2_1.4.4         Rcpp_1.0.10            scattermore_1.2        vctrs_0.6.3           
 [49] spatstat.explore_3.2-1 nlme_3.1-160           progressr_0.13.0       lmtest_0.9-40         
 [53] spatstat.random_3.1-5  stringr_1.5.0          globals_0.16.2         mime_0.12             
 [57] miniUI_0.1.1.1         lifecycle_1.0.3        irlba_2.3.5.1          WriteXLS_6.4.0        
 [61] goftest_1.2-3          MASS_7.3-58.1          zoo_1.8-12             scales_1.2.1          
 [65] promises_1.2.0.1       spatstat.utils_3.0-3   parallel_4.2.1         RColorBrewer_1.1-3    
 [69] curl_5.0.1             reticulate_1.30        pbapply_1.7-2          gridExtra_2.3         
 [73] stringi_1.7.12         fastDummies_1.6.3      rlang_1.1.1            pkgconfig_2.0.3       
 [77] matrixStats_1.0.0      lattice_0.20-45        ROCR_1.0-11            purrr_1.0.1           
 [81] tensor_1.5             labeling_0.4.2         patchwork_1.1.2        htmlwidgets_1.6.2     
 [85] bit_4.0.5              cowplot_1.1.1          tidyselect_1.2.0       parallelly_1.36.0     
 [89] RcppAnnoy_0.0.20       plyr_1.8.8             R6_2.5.1               generics_0.1.3        
 [93] pillar_1.9.0           withr_2.5.0            fitdistrplus_1.1-11    survival_3.4-0        
 [97] abind_1.4-5            tibble_3.2.1           future.apply_1.11.0    KernSmooth_2.23-20    
[101] utf8_1.2.3             spatstat.geom_3.2-1    plotly_4.10.2          grid_4.2.1            
[105] data.table_1.14.8      digest_0.6.32          xtable_1.8-4           tidyr_1.3.0           
[109] httpuv_1.6.11          R.utils_2.12.2         munsell_0.5.0          viridisLite_0.4.2

@alikhuseynov
Copy link

thanks.
Sorry about that, seems that I would need to add support for subset if FOV is not from an object

Alternative way would be:

  • check Cells(xenium.obj) %>% str and Cells(coords) %>% str as well, to see if they match.
  • coords %>% print # should show how many cells you have
  • then, check if you can add FOV to obj before CreateAssayObject
assay <- "Xenium"
segmentations.data <- list(
    "centroids" = CreateCentroids(data$centroids),
    "segmentation" = CreateSegmentation(data$segmentations)
  )

xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)

  coords <- CreateFOV(
    coords = segmentations.data,
    type = c("segmentation", "centroids"),
    molecules = data$microns,
    assay = assay
  )
  fov <- "test"
  xenium.obj[[fov]] <- coords

  xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
  xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
  xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])

@Margokap
Copy link
Author

Thanks again; here is output. I realized this may be part of the issue.

> Cells(xenium.obj) %>% str 
 chr [1:24406] "barcodes" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" ...
 > Cells(coords) %>% str
 chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" "aaaonnnp-1" "aabfjnfi-1" "aabjifjp-1" "aacdphll-1" "aacgchbe-1" "aacifinp-1" ...

The output from Cells(xenium.obj) is the cell ID except for the word "barcodes", while the output for Cells(coords) is actually the barcode. I have a mouse dataset which I can use LoadXenium with no problem, here is example output:

>Cells(example)
  [1] "1555"  "2196"  "2202"  "2269"  "11977" "12541" "12544" "12565" "12644" "12645" "12665" "12668" "12672" "12680" "17497" "17498" "17505" "17507"
 [19] "17514" "17527" "17528" "17530" "17534" "17540" "17545" "17549" "17553" "17557" "17560" "17564" "17570" "17579" "17580" "17583" "17906" "17907"
 [37] "17909" "17919" "17928" "17931" "17935" "17937" "17940" "17948" "17949" "17958" "19104" "19301" "19318" "19319" "19322" "31533" "31537" "31544"
 [55] "31546" "31575" "31585" "31592" "31594" "31596" "31597" "31598" "31845" "31859" "31860" "31893" "31898" "31917" "31922" "31926" "31932" "31940"
 [73] "31943" "31944" "32128" "32130" "32132" "32133" "32134" "32137" "32139" "32140" "32141" "32143" "32168" "32170" "32171" "32173" "32177" "32178"
 [91] "32613" "32614" "32615" "32616" "32698" "32703" "32704" "32706" "32714" "32773"

I tried your suggestion anyway, reprex if useful. Thanks for all the suggestions

> assay <- "Xenium"
> segmentations.data <- list(
+   "centroids" = CreateCentroids(data$centroids),
+   "segmentation" = CreateSegmentation(data$segmentations)
+ )
> 
> xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
> 
> coords <- CreateFOV(
+   coords = segmentations.data,
+   type = c("segmentation", "centroids"),
+   molecules = data$microns,
+   assay = assay
+ )
> 
> fov <- "test"
> xenium.obj[['fov']] <- coords
Error in `[[<-`:
! Cannot add new cells with [[<-
Run `rlang::last_trace()` to see where the error occurred.

> rlang::last_trace(drop = FALSE)
<error/rlang_error>
Error in `[[<-`:
! Cannot add new cells with [[<-
---
Backtrace:
    ▆
 1. ├─methods (local) `[[<-`(`*tmp*`, "fov", value = `<FOV[,0]>`)
 2. └─SeuratObject (local) `[[<-`(`*tmp*`, "fov", value = `<FOV[,0]>`)
 3.   └─rlang::abort(message = "Cannot add new cells with [[<-")

sessioninfo as above in thread

@alikhuseynov
Copy link

alikhuseynov commented Jun 30, 2023

yeah, the cell IDs are the problem.

I downloaded the data from the link you posted
https://www.10xgenomics.com/resources/datasets/xenium-human-brain-preview-data-1-standard
It works on my side, but re-install Seurat and SeuratObject from CRAN or develop branch

# my packages versions:
Biobase::package.version("SeuratObject")
[1] "4.1.3"
> Biobase::package.version("Seurat")
[1] "4.3.0.9003"

data.dir <- "./xenium_data/xenium_V1_FFPE_Human_Brain_Healthy_With_Addon_outs/"
data <- ReadXenium(data.dir = data.dir, 
                   type = c("centroids", "segmentations"))
data %>% names()
data %>% str()

assay <- "Xenium"
segmentations.data <- list(
  "centroids" = CreateCentroids(data$centroids),
  "segmentation" = CreateSegmentation(data$segmentations)
)
coords <- CreateFOV(
  coords = segmentations.data,
  type = c("segmentation", "centroids"),
  molecules = data$microns,
  assay = assay
)

xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])

fov <- "test"
xenium.obj[[fov]] <- coords
xenium.obj
An object of class Seurat 
541 features across 24406 samples within 4 assays 
Active assay: Xenium (319 features, 0 variable features)
 3 other assays present: BlankCodeword, ControlCodeword, ControlProbe
 1 spatial field of view present: test

Cells(coords) %>% str  
chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" "aaaonnnp-1" "aabfjnfi-1" "aabjifjp-1" "aacdphll-1" "aacgchbe-1" "aacifinp-1" "aaciipgf-1" ...  
Cells(xenium.obj) %>% str  
chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" "aaaonnnp-1" "aabfjnfi-1" "aabjifjp-1" "aacdphll-1" "aacgchbe-1" "aacifinp-1" "aaciipgf-1" ...

# test plot
ImageDimPlot(xenium.obj, fov = "test", molecules = c("PECAM1", "DCN"), nmols = 20000)

LoadXenium works too

xenium.obj.test <- LoadXenium(data.dir = data.dir, fov = "test")
10X data contains more than one type and is being returned as a list containing matrices of each type.
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
xenium.obj.test
An object of class Seurat 
541 features across 24406 samples within 4 assays 
Active assay: Xenium (319 features, 0 variable features)
 3 other assays present: BlankCodeword, ControlCodeword, ControlProbe
 1 spatial field of view present: test

test1

@alikhuseynov
Copy link

@Margokap I imagine it works now?

@shakesber89
Copy link

xenium.obj <- LoadXenium("xenium-human", fov = "fov")
10X data contains more than one type and is being returned as a list containing matrices of each type.

I had the same error. In windows ver. Just updated to Seurat Ver5 and error is fixed.

@Margokap
Copy link
Author

Margokap commented Jul 8, 2023

Thanks so much for all your help @alikhuseynov ! I appreciate the time and responses, I believe the trouble should be resolved if working for others, however I am still getting an error. The cell IDs are seeming to be the problem for sure. I will try to make sure that packages are up to date, and will try running this script again, hopefully it will begin working.

Biobase::package.version("SeuratObject")
[1] "4.9.9.9086"
> 
> Biobase::package.version("Seurat")
[1] "4.9.9.9045"
> data <- ReadXenium(data.dir = data.dir, 
+                    type = c("centroids", "segmentations"))
10X data contains more than one type and is being returned as a list containing matrices of each type.
|--------------------------------------------------|
|==================================================|
> data %>% names()
[1] "matrix"        "microns"       "centroids"     "segmentations"
> data %>% str()
List of 4
 $ matrix       :List of 4
  ..$ Gene Expression          :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:1659010] 5 15 16 17 19 24 25 26 27 29 ...
  .. .. ..@ p       : int [1:24407] 0 86 161 263 325 399 492 597 688 771 ...
  .. .. ..@ Dim     : int [1:2] 319 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:319] "ABCC9" "ADAM17" "ADAMTS12" "ADAMTS16" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:1659010] 1 1 1 2 8 2 2 3 2 1 ...
  .. .. ..@ factors : list()
  ..$ Negative Control Codeword:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:128] 11 14 0 22 11 18 2 14 3 40 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 41 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:41] "NegControlCodeword_0500" "NegControlCodeword_0501" "NegControlCodeword_0502" "NegControlCodeword_0503" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:128] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..$ Negative Control Probe   :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:183] 13 0 15 11 5 0 8 13 19 0 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 20 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:20] "NegControlProbe_00042" "NegControlProbe_00041" "NegControlProbe_00039" "NegControlProbe_00035" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:183] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..$ Unassigned Codeword      :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:512] 109 109 103 134 109 109 139 109 109 109 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 161 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:161] "BLANK_0001" "BLANK_0005" "BLANK_0007" "BLANK_0008" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:512] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
 $ microns      :'data.frame':	6012862 obs. of  3 variables:
  ..$ x   : num [1:6012862] 2463 2499 2521 2602 2613 ...
  ..$ y   : num [1:6012862] 346.2 307.1 586.9 13.4 438.5 ...
  ..$ gene: chr [1:6012862] "CABP1" "SNTB2" "SLC6A1" "CABP1" ...
 $ centroids    :'data.frame':	24406 obs. of  3 variables:
  ..$ x   : num [1:24406] 839 1658 1672 851 831 ...
  ..$ y   : num [1:24406] 4619 4684 4732 4745 4746 ...
  ..$ cell: chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" ...
 $ segmentations:'data.frame':	317275 obs. of  3 variables:
  ..$ cell: chr [1:317275] "aaaaieod-1" "aaaaieod-1" "aaaaieod-1" "aaaaieod-1" ...
  ..$ x   : num [1:317275] 836 822 820 826 838 ...
  ..$ y   : num [1:317275] 4602 4614 4621 4632 4636 ...
> 
> assay <- "Xenium"
> segmentations.data <- list(
+   "centroids" = CreateCentroids(data$centroids),
+   "segmentation" = CreateSegmentation(data$segmentations))
> coords <- CreateFOV(
+   coords = segmentations.data,
+   type = c("segmentation", "centroids"),
+   molecules = data$microns,
+   assay = assay
+ )
> 
> xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
> xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> 
> fov <- "test"
> xenium.obj[[fov]] <- coords
Error in `[[<-`:
! Cannot add new cells with [[<-
Run `rlang::last_trace()` to see where the error occurred.
> 

> xenium.obj
An object of class Seurat 
541 features across 24406 samples within 4 assays 
Active assay: Xenium (319 features, 0 variable features)
 2 layers present: counts, data
 3 other assays present: BlankCodeword, ControlCodeword, ControlProbe
> Cells(coords) %>% str  
 chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" "aaaonnnp-1" ...
> Cells(xenium.obj) %>% str  
 chr [1:24406] "barcodes" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" ...

@alikhuseynov
Copy link

no worries, your package version are 4.9.9, I'm working with these versions:

Biobase::package.version("SeuratObject")
[1] "4.1.3"
> Biobase::package.version("Seurat")
[1] "4.3.0.9003"

I would say re-install your packages to the version < 4.9.9

@Margokap
Copy link
Author

Margokap commented Jul 8, 2023

Thanks again for the help! I will try to find a way to install the same version that you have, and will do some digging for the specific package version.

> Biobase::package.version("Seurat")
[1] "4.3.0"
> Biobase::package.version("SeuratObject")
[1] "4.1.3"
> data <- ReadXenium(data.dir = data.dir, 
+                    type = c("centroids", "segmentations"))
10X data contains more than one type and is being returned as a list containing matrices of each type.
> data %>% names()
[1] "matrix"        "microns"       "centroids"     "segmentations"
> data %>% str()
List of 4
 $ matrix       :List of 4
  ..$ Gene Expression          :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:1659010] 5 15 16 17 19 24 25 26 27 29 ...
  .. .. ..@ p       : int [1:24407] 0 86 161 263 325 399 492 597 688 771 ...
  .. .. ..@ Dim     : int [1:2] 319 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:319] "ABCC9" "ADAM17" "ADAMTS12" "ADAMTS16" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:1659010] 1 1 1 2 8 2 2 3 2 1 ...
  .. .. ..@ factors : list()
  ..$ Negative Control Codeword:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:128] 11 14 0 22 11 18 2 14 3 40 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 41 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:41] "NegControlCodeword_0500" "NegControlCodeword_0501" "NegControlCodeword_0502" "NegControlCodeword_0503" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:128] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..$ Negative Control Probe   :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:183] 13 0 15 11 5 0 8 13 19 0 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 20 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:20] "NegControlProbe_00042" "NegControlProbe_00041" "NegControlProbe_00039" "NegControlProbe_00035" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:183] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..$ Unassigned Codeword      :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:512] 109 109 103 134 109 109 139 109 109 109 ...
  .. .. ..@ p       : int [1:24407] 0 0 0 0 0 0 0 0 0 0 ...
  .. .. ..@ Dim     : int [1:2] 161 24406
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:161] "BLANK_0001" "BLANK_0005" "BLANK_0007" "BLANK_0008" ...
  .. .. .. ..$ : chr [1:24406] "barcodes" "1" "2" "3" ...
  .. .. ..@ x       : num [1:512] 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
 $ microns      :'data.frame':	6012862 obs. of  3 variables:
  ..$ x   : num [1:6012862] 2463 2499 2521 2602 2613 ...
  ..$ y   : num [1:6012862] 346.2 307.1 586.9 13.4 438.5 ...
  ..$ gene: chr [1:6012862] "CABP1" "SNTB2" "SLC6A1" "CABP1" ...
 $ centroids    :'data.frame':	24406 obs. of  3 variables:
  ..$ x   : num [1:24406] 839 1658 1672 851 831 ...
  ..$ y   : num [1:24406] 4619 4684 4732 4745 4746 ...
  ..$ cell: chr [1:24406] "aaaaieod-1" "aaadabdh-1" "aaaepfof-1" "aaanldfc-1" ...
 $ segmentations:'data.frame':	317275 obs. of  3 variables:
  ..$ cell: chr [1:317275] "aaaaieod-1" "aaaaieod-1" "aaaaieod-1" "aaaaieod-1" ...
  ..$ x   : num [1:317275] 836 822 820 826 838 ...
  ..$ y   : num [1:317275] 4602 4614 4621 4632 4636 ...
> 
> assay <- "Xenium"
> segmentations.data <- list(
+   "centroids" = CreateCentroids(data$centroids),
+   "segmentation" = CreateSegmentation(data$segmentations)
+ )
> coords <- CreateFOV(
+   coords = segmentations.data,
+   type = c("segmentation", "centroids"),
+   molecules = data$microns,
+   assay = assay
+ )
> 
> xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
> xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
> 
> fov <- "test"
> xenium.obj[[fov]] <- coords
Error: All cells in the image must be present in assay.

trying LoadXenium with current package versions (produces error as before)

x <- LoadXenium(data.dir = data.dir)
10X data contains more than one type and is being returned as a list containing matrices of each type.
Error in CreateAssayObject(counts = data$matrix[["Blank Codeword"]]) : 
  No cell names (colnames) names present in the input matrix

trying to install the specific seurat package version:

devtools::install_version(package = 'Seurat', version = package_version('4.3.0.9003'))
>Error in download_version_url(package, version, repos, type) : 
  version '4.3.0.9003' is invalid for package 'Seurat'
> remotes::install_version(package = 'Seurat', version = package_version('4.3.0.9003'))
Error in download_version_url(package, version, repos, type) : 
  version '4.3.0.9003' is invalid for package 'Seurat'
remotes::install_version("Seurat", version = "4.3.0.9003")
>Error in download_version_url(package, version, repos, type) : 
  version '4.3.0.9003' is invalid for package 'Seurat'

source code via https://github.com/satijalab/seurat/releases is only available for v4.3.0 - will think about how to workaround this.

@alikhuseynov
Copy link

try develop version for Seurat remotes::install_github(repo = 'satijalab/seurat', ref = 'develop')

@ChiaraCaprioli
Copy link

Hi,

I am experiencing a similar issue with Seurat v5 using the function LoadXenium(). I can smoothly load in the dataset from the vignette, but I can't with my own data.

My sessionInfo():

R version 4.3.3 (2024-02-29)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Rocky Linux 8.9 (Green Obsidian)

Matrix products: default
BLAS/LAPACK: /lustre1/project/stg_00154/LPCM/ccapri/software/miniconda3/envs/seurat/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: Europe/Amsterdam
tzcode source: system (glibc)

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

other attached packages:
 [1] lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      dplyr_1.1.4       
 [5] purrr_1.0.2        readr_2.1.5        tidyr_1.3.1        tibble_3.2.1      
 [9] tidyverse_2.0.0    ggplot2_3.5.1      future_1.33.2      Seurat_5.0.3.9924 
[13] SeuratObject_5.0.2 sp_2.1-4          

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3     jsonlite_1.8.8         magrittr_2.0.3        
  [4] ggbeeswarm_0.7.2       spatstat.utils_3.0-4   farver_2.1.2          
  [7] vctrs_0.6.5            ROCR_1.0-11            Cairo_1.6-2           
 [10] spatstat.explore_3.2-6 base64enc_0.1-3        htmltools_0.5.8.1     
 [13] sctransform_0.4.1      parallelly_1.37.1      KernSmooth_2.23-22    
 [16] htmlwidgets_1.6.4      ica_1.0-3              plyr_1.8.9            
 [19] plotly_4.10.4          zoo_1.8-12             uuid_1.2-0            
 [22] igraph_2.0.3           mime_0.12              lifecycle_1.0.4       
 [25] pkgconfig_2.0.3        Matrix_1.6-5           R6_2.5.1              
 [28] fastmap_1.1.1          fitdistrplus_1.1-11    shiny_1.8.1.1         
 [31] digest_0.6.35          colorspace_2.1-0       patchwork_1.2.0       
 [34] tensor_1.5             RSpectra_0.16-1        irlba_2.3.5.1         
 [37] labeling_0.4.3         progressr_0.14.0       fansi_1.0.6           
 [40] spatstat.sparse_3.0-3  timechange_0.3.0       httr_1.4.7            
 [43] polyclip_1.10-6        abind_1.4-5            compiler_4.3.3        
 [46] bit64_4.0.5            withr_3.0.0            fastDummies_1.7.3     
 [49] R.utils_2.12.3         MASS_7.3-60            tools_4.3.3           
 [52] vipor_0.4.7            lmtest_0.9-40          beeswarm_0.4.0        
 [55] httpuv_1.6.15          future.apply_1.11.2    goftest_1.2-3         
 [58] R.oo_1.26.0            glue_1.7.0             nlme_3.1-164          
 [61] promises_1.3.0         grid_4.3.3             pbdZMQ_0.3-11         
 [64] Rtsne_0.17             cluster_2.1.6          reshape2_1.4.4        
 [67] generics_0.1.3         gtable_0.3.5           spatstat.data_3.0-4   
 [70] tzdb_0.4.0             R.methodsS3_1.8.2      data.table_1.15.2     
 [73] hms_1.1.3              utf8_1.2.4             spatstat.geom_3.2-9   
 [76] RcppAnnoy_0.0.22       ggrepel_0.9.5          RANN_2.6.1            
 [79] pillar_1.9.0           spam_2.10-0            IRdisplay_1.1         
 [82] RcppHNSW_0.6.0         vroom_1.6.5            later_1.3.2           
 [85] splines_4.3.3          lattice_0.22-6         survival_3.6-4        
 [88] bit_4.0.5              deldir_2.0-4           tidyselect_1.2.1      
 [91] miniUI_0.1.1.1         pbapply_1.7-2          gridExtra_2.3         
 [94] scattermore_1.2        matrixStats_1.3.0      stringi_1.8.4         
 [97] lazyeval_0.2.2         evaluate_0.23          codetools_0.2-20      
[100] cli_3.6.2              uwot_0.1.16            IRkernel_1.3.2        
[103] xtable_1.8-4           reticulate_1.36.1      repr_1.1.7            
[106] munsell_0.5.1          Rcpp_1.0.12            globals_0.16.3        
[109] spatstat.random_3.2-3  png_0.1-8              ggrastr_1.0.2         
[112] parallel_4.3.3         dotCall64_1.1-1        listenv_0.9.1         
[115] viridisLite_0.4.2      scales_1.3.0           ggridges_0.5.6        
[118] leiden_0.4.3.1         crayon_1.5.2           rlang_1.1.3           
[121] cowplot_1.1.3         

I figured out the problem might be related to the fact the matrix I want to load lack any "Unassigned Codeword" count, so for now my quick&dirty solution is manually creating a Xenium object, assigning a mock "BlankCodeword" assay with zero counts:

data <- ReadXenium(
    data.dir = path,
    type = c("centroids", "segmentations"),
  )
assay <- "Xenium"
segmentations.data <- list(
    "centroids" = CreateCentroids(data$centroids),
    "segmentation" = CreateSegmentation(data$segmentations)
  )

coords <- CreateFOV(
    coords = segmentations.data,
    type = c("segmentation", "centroids"),
    molecules = data$microns,
    assay = assay
)
xenium.obj <- CreateSeuratObject(counts = data$matrix[["Gene Expression"]], assay = assay)
xenium.obj[["ControlCodeword"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Codeword"]])
xenium.obj[["ControlProbe"]] <- CreateAssayObject(counts = data$matrix[["Negative Control Probe"]])

data$matrix[["Unassigned Codeword"]] <- data$matrix[["Negative Control Codeword"]]
data$matrix[["Unassigned Codeword"]][data$matrix[["Unassigned Codeword"]] != 0] <- 0
xenium.obj[["BlankCodeword"]] <- CreateAssayObject(counts = data$matrix[["Unassigned Codeword"]])

fov <- "test"
xenium.obj[[fov]] <- coords

which returns the following xenium.obj:

An object of class Seurat 
582 features across 819063 samples within 4 assays 
Active assay: Xenium (480 features, 0 variable features)
 1 layer present: counts
 3 other assays present: ControlCodeword, ControlProbe, BlankCodeword
 1 spatial field of view present: test

Is this approach ok? Are there smarter solutions implemented?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants