mojaveazure / seurat-disk

Interfaces for HDF5-based Single Cell File Formats
https://mojaveazure.github.io/seurat-disk
GNU General Public License v3.0
146 stars 48 forks source link

Error when convert H5ad to seurat object #100

Open GouQiao opened 2 years ago

GouQiao commented 2 years ago

HI,

I want to convert h5ad to seurat object by seuratdisk. But even using tutorial data , i met errors:

Error in dfile$obj_copy_from(src_loc = source, src_name = "obs", dst_name = "meta.data") :

HDF5-API Errors: error #000: ../../src/hdf5-1.12.0/src/H5Ocopy.c in H5Ocopy(): line 251: unable to copy object class: HDF5 major: Object header minor: Unable to copy object

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

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

error #003: ../../src/hdf5-1.12.0/src/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: ../../src/hdf5-1.12.0/src/H5Ocopy.c in H5O_copy(): line 313: unable to copy object
    class: HDF5
    major: Object header
    minor: Unable

And if I use my own h5ad data, I met this error:

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 Merging features from scaled feature-level metadata Error in self$write_low_level(value, file_space = self_space_id, mem_space = mem_space_id, : Number of objects in robj is not the same and not a multiple of number of elements selected in file: expected are 0 but provided are 3000

Is there anyone know how to solve this problem?

vkartha commented 2 years ago

Same issue here, testing on tutorial data. Any fix yet?

sohrabsa commented 2 years ago

I'm getting a similar error while converting a scanpy compatible anndata object to a seurat object:

Warning: Unknown file type: h5ad
Warning: 'assay' not set, setting to 'RNA'
Creating h5Seurat file for version 3.1.5.9900
Adding X as data
Adding X as counts
Adding meta.features from var
Adding meta.features from var
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 240: unable to copy object
        class: HDF5
        major: Object header
        minor: Unable to copy object

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

    error #002: H5VLcallback.c in H5VL__object_copy(): line 5456: 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 125: unable to copy object
        class: HDF5
        major: Object header
        minor: Unable to copy object

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

    error #005: H5Ocopy.c in H5O__copy_obj(): line 1196: unable to copy object
        class: HDF5
        majo
Error in private$closeFun(id) : HDF5-API Errors:
    error #000: H5F.c in H5Fclose(): line 711: decrementing file ID failed
        class: HDF5
        major: File accessibility
        minor: Unable to close file

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

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

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

    error #004: H5VLcallback.c in H5VL__file_close(): line 3952: 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 838: can't close file
        class
YY-SONG0718 commented 2 years ago

I am having the same issue recently pop up:

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 ensembl_gene from scaled feature-level metadata Error in self$write_low_level(value, file_space = self_space_id, mem_space = mem_space_id, : Number of objects in robj is not the same and not a multiple of number of elements selected in file: expected are 0 but provided are 18844

ogandril commented 2 years ago

Same here.

  1. Even using tutorial data , there are errors.
  2. Using my own data, I have yet another error:

    NB <- LoadH5Seurat("nb_GOSH_cellxgene.h5seurat") Validating h5Seurat file Initializing RNA with data Error in sparseMatrix(i = x[["indices"]][] + 1, p = x[["indptr"]][], x = x[["data"]][], : all(dims >= dims.min) is not TRUE

erosix commented 1 year ago

I got this error too. I edited the column names of the AnnData metadata (.obs), as follows:

import anndata
filename="myAD.h5ad"
anndata1=anndata.read_h5ad(filename)

anndata1.obs.columns = [sub.replace('(', '') for sub in anndata1.obs.columns]
anndata1.obs.columns = [sub.replace(')', '') for sub in anndata1.obs.columns]
anndata1.obs.columns = [sub.replace('/', '') for sub in anndata1.obs.columns]
anndata1.obs.columns = [sub.replace('=', '.') for sub in anndata1.obs.columns]
anndata1.obs.columns = [sub.replace(' ', '_') for sub in anndata1.obs.columns]
anndata1.obs.columns = [sub.replace('-', '_') for sub in anndata1.obs.columns]

filename_out="myAD_edited.h5ad"
anndata1.write(filename_out)

after this i was able to convert to h5seurat without error. However when trying to load the seurat object I got the same error of @ogandril . I read in another issue that this may be due to the matrices being transposed, so I am currently trying this solution:

obj_HDF5 <- SeuratDisk::Connect(seurath5, mode = "r+")

Transpose(obj_HDF5[["assays/RNA/counts"]], overwrite = TRUE)
Transpose(obj_HDF5[["assays/RNA/data"]], overwrite = TRUE)
obj_HDF5$link_delete("assays/RNA/counts")
obj_HDF5$link_delete("assays/RNA/data")

obj_HDF5$link_move_from(obj_HDF5, "assays/RNA/t_counts", "assays/RNA/counts")
obj_HDF5$link_move_from(obj_HDF5, "assays/RNA/t_data", "assays/RNA/data")
old_dims <- hdf5r::h5attr(obj_HDF5[["assays/RNA/data"]], "dims")
new_dims <- rev(old_dims)
hdf5r::h5attr(obj_HDF5[["assays/RNA/counts"]], "dims") <- new_dims
hdf5r::h5attr(obj_HDF5[["assays/RNA/data"]], "dims") <- new_dims
obj_HDF5$close()
lucafusarbassini commented 1 year ago

same issue here with tutorial data

apal6 commented 4 weeks ago

Hi, can someone help? Having the same issue. Thank you