seurat-disk icon indicating copy to clipboard operation
seurat-disk copied to clipboard

Error in converting h5ad to Seurat - Warning: Unknown file type: h5ad

Open fly4all opened this issue 3 years ago • 7 comments

Hi,

Thank you for making all these scRNAseq analysis resources.

I have been trying to follow the given example here to convert an h5ad file into a Seurat object, but have been getting an error upon running the Convert function. Here is the code I ran: url <- "https://seurat.nygenome.org/pbmc3k_final.h5ad" curl::curl_download(url, basename(url)) Convert("pbmc3k_final.h5ad", dest = "h5seurat", overwrite = TRUE)

This is the error I got: Convert("pbmc3k_final.h5ad", dest = "h5seurat", overwrite = TRUE) Warning: Unknown file type: h5ad Warning: 'assay' not set, setting to 'RNA' Creating h5Seurat file for version 3.1.5.9900 Adding X as scale.data Adding raw/X as data Adding raw/X as counts Adding meta.features from raw/var Adding dispersions from scaled feature-level metadata Adding dispersions_norm from scaled feature-level metadata Merging gene_ids from scaled feature-level metadata Adding highly_variable from scaled feature-level metadata Adding means from scaled feature-level metadata Merging n_cells from scaled feature-level metadata Error in dfile$obj_copy_from(src_loc = source, src_name = "obs", dst_name = "meta.data") : HDF5-API Errors: error #000: H5Ocopy.c in H5Ocopy(): line 251: unable to copy object class: HDF5 major: Object header minor: Unable to copy object

error #001: H5VLcallback.c in H5VL_object_copy(): line 5530: object copy failed
    class: HDF5
    major: Virtual Object Layer
    minor: Unable to copy object

error #002: H5VLcallback.c in H5VL__object_copy(): line 5491: object copy failed
    class: HDF5
    major: Virtual Object Layer
    minor: Unable to copy object

error #003: H5VLnative_object.c in H5VL__native_object_copy(): line 126: unable to copy object
    class: HDF5
    major: Symbol table
    minor: Unable to copy object

error #004: H5Ocopy.c in H5O_copy(): line 313: unable to copy object
    class: HDF5
    major: Object header
    minor: Unable to copy object

error #005: H5Ocopy.c in H5O__copy_obj(): line 1217: unable to copy object
    class: HDF5
    major

Error in private$closeFun(id) : HDF5-API Errors: error #000: H5F.c in H5Fclose(): line 886: decrementing file ID failed class: HDF5 major: Object atom minor: Unable to close file

error #001: H5I.c in H5I_dec_app_ref(): line 1422: can't decrement ID ref count
    class: HDF5
    major: Object atom
    minor: Unable to decrement reference count

error #002: H5F.c in H5F__close_cb(): line 243: unable to close file
    class: HDF5
    major: File accessibility
    minor: Unable to close file

error #003: H5VLcallback.c in H5VL_file_close(): line 3977: file close failed
    class: HDF5
    major: Virtual Object Layer
    minor: Unable to close file

error #004: H5VLcallback.c in H5VL__file_close(): line 3945: file close failed
    class: HDF5
    major: Virtual Object Layer
    minor: Unable to close file

error #005: H5VLnative_file.c in H5VL__native_file_close(): line 884: can't close file
    class: HDF5

-- this is my R session info:

R version 4.0.5 (2021-03-31) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Mojave 10.14.6

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.0/Resources/lib/libRlapack.dylib

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

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

other attached packages: [1] pbmc3k.SeuratData_3.1.4 SeuratData_0.2.1 SeuratDisk_0.0.0.9019 withr_2.4.2 Rhdf5lib_1.10.1
[6] hdf5r_1.3.3 HDF5Array_1.16.1 rhdf5_2.32.4 DelayedArray_0.14.1 IRanges_2.22.2
[11] S4Vectors_0.26.1 BiocGenerics_0.34.0 matrixStats_0.59.0 ggpubr_0.4.0 ggplot2_3.3.5
[16] Matrix_1.3-4 dplyr_1.0.7 SeuratObject_4.0.2 Seurat_4.0.3

loaded via a namespace (and not attached): [1] Rtsne_0.15 colorspace_2.0-2 ggsignif_0.6.2 deldir_0.2-10 ellipsis_0.3.2
[6] rio_0.5.26 ggridges_0.5.3 rstudioapi_0.13 spatstat.data_2.1-0 leiden_0.3.8
[11] listenv_0.8.0 bit64_4.0.5 ggrepel_0.9.1 fansi_0.5.0 codetools_0.2-18
[16] splines_4.0.5 polyclip_1.10-0 jsonlite_1.7.2 broom_0.7.8 ica_1.0-2
[21] cluster_2.1.2 png_0.1-7 uwot_0.1.10 shiny_1.6.0 sctransform_0.3.2
[26] spatstat.sparse_2.0-0 compiler_4.0.5 httr_1.4.2 backports_1.2.1 fastmap_1.1.0
[31] lazyeval_0.2.2 cli_2.5.0 later_1.2.0 htmltools_0.5.1.1 tools_4.0.5
[36] igraph_1.2.6 gtable_0.3.0 glue_1.4.2 RANN_2.6.1 reshape2_1.4.4
[41] rappdirs_0.3.3 tinytex_0.32 Rcpp_1.0.6 carData_3.0-4 scattermore_0.7
[46] cellranger_1.1.0 vctrs_0.3.8 nlme_3.1-152 lmtest_0.9-38 xfun_0.24
[51] stringr_1.4.0 globals_0.14.0 openxlsx_4.2.3 mime_0.11 miniUI_0.1.1.1
[56] lifecycle_1.0.0 irlba_2.3.3 rstatix_0.7.0 goftest_1.2-2 future_1.21.0
[61] MASS_7.3-54 zoo_1.8-9 scales_1.1.1 spatstat.core_2.2-0 hms_1.0.0
[66] promises_1.2.0.1 spatstat.utils_2.2-0 RColorBrewer_1.1-2 curl_4.3.2 reticulate_1.20
[71] pbapply_1.4-3 gridExtra_2.3 rpart_4.1-15 stringi_1.6.2 zip_2.1.1
[76] rlang_0.4.11 pkgconfig_2.0.3 lattice_0.20-44 ROCR_1.0-11 purrr_0.3.4
[81] tensor_1.5 patchwork_1.1.1 htmlwidgets_1.5.3 bit_4.0.4 cowplot_1.1.1
[86] tidyselect_1.1.1 parallelly_1.26.0 RcppAnnoy_0.0.18 plyr_1.8.6 magrittr_2.0.1
[91] R6_2.5.0 generics_0.1.0 DBI_1.1.1 pillar_1.6.1 haven_2.3.1
[96] foreign_0.8-81 mgcv_1.8-36 fitdistrplus_1.1-5 survival_3.2-11 abind_1.4-5
[101] tibble_3.1.2 future.apply_1.7.0 crayon_1.4.1 car_3.0-10 KernSmooth_2.23-20
[106] utf8_1.2.1 spatstat.geom_2.2-0 plotly_4.9.4.1 readxl_1.3.1 grid_4.0.5
[111] data.table_1.14.0 forcats_0.5.1 digest_0.6.27 xtable_1.8-4 tidyr_1.1.3
[116] httpuv_1.6.1 munsell_0.5.0 viridisLite_0.4.0

The actual dataset I wanted to convert are the h5ad files in this GEO dataset here: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE161228

Please let me know any advice on how to resolve this. Thank you!

fly4all avatar Jun 25 '21 17:06 fly4all

I'm having a similar problem with a dataset generated from my processing pipeline. The input is an h5ad file with a dense X matrix and some per-obs and per-var annotations. I get the same “Unknown file type: h5ad” error message., however there was an output .h5seurat file generated, but trying to load it fails with Error in if (!x[[i]]$dims) {: argument is of length zero (last verbose message was Adding miscellaneous information, stack trace pointed to as.list(x=x[["misc"]]), if that helps.

Other than the mysterious "Unknown file type: h5ad" message which seems harmless (though scary to my users), the real problem seems to be that I had an adata.uns['__name__'] = 'clean' (my code uses __name__ to carry the name of the data set around for logging and the like). Removing this from the AnnData before writing it into the file solved the problem. [Edit: This fixed the failure error, not the "Unknown file type" error.]

orenbenkiki avatar Jul 05 '21 15:07 orenbenkiki

@fly4all Have you found a solution for this problem or the cause of this problem, I face the same issue when converting anndata to seurat

ahmedibatta avatar Jul 05 '21 19:07 ahmedibatta

I also had an error in LoadH5Seurat after converting from a h5ad similar to that described by orenbenkiki, my search found his comment, so I'll put my solution to that problem here. But the original error reported by fly4all is different.

Adding miscellaneous information

Error in if (!x[[i]]$dims) {: argument is of length zero
Traceback:

1. LoadH5Seurat("temp.h5seurat", verbose = T)
2. LoadH5Seurat.character("temp.h5seurat", 
 .     verbose = T)
3. LoadH5Seurat(file = hfile, assays = assays, reductions = reductions, 
 .     graphs = graphs, neighbors = neighbors, images = images, 
 .     meta.data = meta.data, commands = commands, misc = misc, 
 .     tools = tools, verbose = verbose, ...)
4. LoadH5Seurat.h5Seurat(file = hfile, assays = assays, reductions = reductions, 
 .     graphs = graphs, neighbors = neighbors, images = images, 
 .     meta.data = meta.data, commands = commands, misc = misc, 
 .     tools = tools, verbose = verbose, ...)
5. as.Seurat(x = file, assays = assays, reductions = reductions, 
 .     graphs = graphs, neighbors = neighbors, images = images, 
 .     meta.data = meta.data, commands = commands, misc = misc, 
 .     tools = tools, verbose = verbose, ...)
6. as.Seurat.h5Seurat(x = file, assays = assays, reductions = reductions, 
 .     graphs = graphs, neighbors = neighbors, images = images, 
 .     meta.data = meta.data, commands = commands, misc = misc, 
 .     tools = tools, verbose = verbose, ...)
7. as.list(x = x[["misc"]])
8. as.list(x = x[["misc"]])
9. .local(x, ...)
10. as.list(x = x[[i]], ...)
11. as.list(x = x[[i]], ...)
12. .local(x, ...)
13. as.list(x = x[[i]], ...)
14. as.list(x = x[[i]], ...)
15. .local(x, ...)
16. as.list(x = x[[i]], ...)
17. as.list(x = x[[i]], ...)
18. .local(x, ...)

Adding misc=F to LoadH5Seurat seemed to fix this.

Jon-bioinfo avatar Aug 23 '21 04:08 Jon-bioinfo

Adding misc=F to LoadH5Seurat seemed to fix this. my error Error in if (!x[[i]]$dims) { : argument is of length zero This fixed my problems too.

FanZhang9 avatar Jun 08 '22 08:06 FanZhang9

Adding misc=F to LoadH5Seurat seemed to fix this.

This worked for me! thanks :D

earmingol avatar Nov 03 '22 22:11 earmingol

My error: Error in if (!x[[i]]$dims) { : the condition has length > 1 I have added misc=F but it still not worked. I still faced that error when converting .h5ad file into a Seurat object. Can anyone support me to fix this? Thanks a lot

nghiaplt1611 avatar Jan 29 '24 15:01 nghiaplt1611