Skip to content

hdf5_adata$as_Seurat fails when features contain _ #476

Description

@doliv071

Description

I'm trying to convert an anndata h5ad to Seurat object via read_h5ad. The object contains feature names with _ in them e.g. gene_1, gene_2, etc. This apparently is not allowed in the seurat object: Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-') ... however, Seurat does allow underscore in the assay rownames?!?! The result is that as_Seurat fails because the sanity check indicates some insanity Error: No feature overlap between existing object and new layer data

The underlying object is okay, because the conversion to SingleCellExperiment works just fine.

> system.file("ext/", "demo_data.h5ad", package = "rcna") |> 
+     read_h5ad(as = "Seurat")
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Data is of class matrix. Coercing to dgCMatrix.
Error: No feature overlap between existing object and new layer data
In addition: Warning message:
No "counts" or "data" layer found in `names(layers_mapping)`, this may lead to unexpected
results when using the resulting <Seurat> object. 
> traceback()
9: stop("No feature overlap between existing object and new layer data", 
       call. = FALSE)
8: `LayerData<-.Assay5`(object = `*tmp*`, layer = layer, ..., value = value)
7: `LayerData<-`(object = `*tmp*`, layer = layer, ..., value = value)
6: `LayerData<-.Seurat`(`*tmp*`, layer = dummy_counts, value = counts)
5: SeuratObject::`LayerData<-`(`*tmp*`, layer = dummy_counts, value = counts)
4: .as_Seurat_create_object_with_layers(adata, layers_mapping, object_metadata, 
       assay_name)
3: as_Seurat(self, assay_name = assay_name, x_mapping = x_mapping, 
       layers_mapping = layers_mapping, object_metadata_mapping = object_metadata_mapping, 
       assay_metadata_mapping = assay_metadata_mapping, reduction_mapping = reduction_mapping, 
       graph_mapping = graph_mapping, misc_mapping = misc_mapping)
2: hdf5_adata$as_Seurat(...)
1: read_h5ad(system.file("ext/", "demo_data.h5ad", package = "rcna"), 
       as = "Seurat")

Minimal Reproducible Example

Session Information

Session info ``` > sessionInfo() R version 4.5.0 (2025-04-11) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 24.04.4 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C 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] ggbeeswarm_0.7.3 anndataR_1.0.2 Seurat_5.5.1 SeuratObject_5.4.0
[5] sp_2.2-1 ggplot2_4.0.2 dplyr_1.2.1 rcna_0.1.0

loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-3 rstudioapi_0.18.0 jsonlite_2.0.0
[4] magrittr_2.0.5 spatstat.utils_3.2-2 farver_2.1.2
[7] fs_2.0.1 vctrs_0.7.3 ROCR_1.0-12
[10] memoise_2.0.1 spatstat.explore_3.8-0 S4Arrays_1.10.1
[13] htmltools_0.5.9 usethis_3.2.1 Rhdf5lib_1.32.0
[16] SparseArray_1.10.10 rhdf5_2.54.1 sctransform_0.4.3
[19] parallelly_1.46.1 KernSmooth_2.23-26 htmlwidgets_1.6.4
[22] desc_1.4.3 ica_1.0-3 plyr_1.8.9
[25] plotly_4.12.0 zoo_1.8-15 cachem_1.1.0
[28] igraph_2.2.3 mime_0.13 lifecycle_1.0.5
[31] pkgconfig_2.0.3 Matrix_1.7-5 R6_2.6.1
[34] fastmap_1.2.0 MatrixGenerics_1.22.0 fitdistrplus_1.2-6
[37] future_1.70.0 shiny_1.13.0 digest_0.6.39
[40] S4Vectors_0.48.1 patchwork_1.3.2 rprojroot_2.1.1
[43] tensor_1.5.1 RSpectra_0.16-2 irlba_2.3.7
[46] pkgload_1.5.1 GenomicRanges_1.62.1 beachmat_2.26.0
[49] progressr_0.19.0 spatstat.sparse_3.1-0 httr_1.4.8
[52] polyclip_1.10-7 abind_1.4-8 compiler_4.5.0
[55] withr_3.0.2 S7_0.2.1 BiocParallel_1.44.0
[58] fastDummies_1.7.5 pkgbuild_1.4.8 MASS_7.3-65
[61] DelayedArray_0.36.1 sessioninfo_1.2.3 tools_4.5.0
[64] vipor_0.4.7 lmtest_0.9-40 otel_0.2.0
[67] beeswarm_0.4.0 httpuv_1.6.17 future.apply_1.20.2
[70] goftest_1.2-3 glue_1.8.0 rhdf5filters_1.22.0
[73] nlme_3.1-169 promises_1.5.0 grid_4.5.0
[76] Rtsne_0.17 cluster_2.1.8.2 reshape2_1.4.5
[79] generics_0.1.4 gtable_0.3.6 spatstat.data_3.1-9
[82] tidyr_1.3.2 data.table_1.18.2.1 XVector_0.50.0
[85] xml2_1.5.2 BiocGenerics_0.56.0 spatstat.geom_3.7-3
[88] RcppAnnoy_0.0.23 ggrepel_0.9.8 RANN_2.6.2
[91] pillar_1.11.1 stringr_1.6.0 spam_2.11-3
[94] RcppHNSW_0.6.0 later_1.4.8 splines_4.5.0
[97] lattice_0.22-9 survival_3.8-6 deldir_2.0-4
[100] tidyselect_1.2.1 SingleCellExperiment_1.32.0 scuttle_1.20.0
[103] miniUI_0.1.2 pbapply_1.7-4 knitr_1.51
[106] gridExtra_2.3 Seqinfo_1.0.0 IRanges_2.44.0
[109] SummarizedExperiment_1.40.0 scattermore_1.2 stats4_4.5.0
[112] xfun_0.57 Biobase_2.70.0 devtools_2.5.0
[115] matrixStats_1.5.0 stringi_1.8.7 lazyeval_0.2.3
[118] evaluate_1.0.5 codetools_0.2-20 tibble_3.3.1
[121] cli_3.6.6 uwot_0.2.4 xtable_1.8-8
[124] reticulate_1.46.0 roxygen2_7.3.3 dichromat_2.0-0.1
[127] Rcpp_1.1.1 globals_0.19.1 spatstat.random_3.4-5
[130] png_0.1-9 spatstat.univar_3.1-7 parallel_4.5.0
[133] ellipsis_0.3.3 dotCall64_1.2 listenv_0.10.1
[136] viridisLite_0.4.3 scales_1.4.0 ggridges_0.5.7
[139] purrr_1.2.2 rlang_1.2.0 cowplot_1.2.0

</details>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues yet to be checked by maintainers

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions