Skip to content

Can't convert Seurat 5 object to h5ad AnnData #8220

@yangshichen0713

Description

@yangshichen0713

Hello, I created a lot of rds files using Seurat V5 and merged all the rds files together and merged the Count using JoinLayers(). I am now trying to convert the rds to h5ad but I am getting the following error. Thanks !!!

pbmc_filter <- as.SingleCellExperiment(pbmc, assay = c("RNA"))
writeH5AD(pbmc_filter, "pbmc_filter.h5ad", X_name = 'counts')
No module named 'anndata'Traceback:

1. writeH5AD(pbmc_filter, "pbmc_filter.h5ad", X_name = "counts")
2. basiliskRun(env = env, fun = .H5ADwriter, sce = sce, file = file, 
 .     X_name = X_name, skip_assays = skip_assays, compression = compression, 
 .     verbose = verbose, ...)
3. fun(...)
4. SCE2AnnData(sce, X_name = X_name, skip_assays = skip_assays, 
 .     verbose = verbose, ...)
5. import("anndata")
6. py_module_import(module, convert = convert)

Activity

yangshichen0713

yangshichen0713 commented on Dec 25, 2023

@yangshichen0713
Author

Then I used another method and that didn't work either. -_-

SaveH5Seurat(pbmc, filename = "pbmc_filter.h5Seurat")
Convert("pbmc_filter.h5Seurat", dest = "h5ad")
Creating h5Seurat file for version 3.1.5.9900

Validating h5Seurat file

Adding data from RNA as X

Error in assay.group$obj_copy_to(dst_loc = dfile, dst_name = "X", src_name = x.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 291: source object not found
        class: HDF5
        major: Symbol table
        minor: Object not found

    error #005: H5Gloc.c in H5G_loc_find(): line 442: can't find object
        class: HDF5
        major: Symbol table
   
Traceback:

1. Convert("pbmc_filter.h5Seurat", dest = "h5ad")
2. Convert.character("pbmc_filter.h5Seurat", dest = "h5ad")
3. Convert(source = hfile, dest = dest, assay = assay, overwrite = overwrite, 
 .     verbose = verbose, ...)
4. Convert.h5Seurat(source = hfile, dest = dest, assay = assay, 
 .     overwrite = overwrite, verbose = verbose, ...)
5. H5SeuratToH5AD(source = source, dest = dest, assay = assay, overwrite = overwrite, 
 .     verbose = verbose)
6. assay.group$obj_copy_to(dst_loc = dfile, dst_name = "X", src_name = x.data)
haukeh90

haukeh90 commented on Dec 29, 2023

@haukeh90

Hi,

this problem can be circumvented by converting the V5 to a V3 assay in the seurat object before the conversion:

object[["RNA3"]] <- as(object = object[["RNA"]], Class = "Assay")
DefaultAssay(object) <- "RNA3"
object[["RNA"]] <- NULL
object <- RenameAssays(object = object, RNA3 = 'RNA')

please find additional information here: https://satijalab.org/seurat/articles/seurat5_essential_commands
subsequent conversion could be done using sceasy: https://github.com/cellgeni/sceasy

However I could imagine that the conversion outlined by mojaveazure (without using sceasy) should also work after converting the V5 to the V3 assay: https://mojaveazure.github.io/seurat-disk/articles/convert-anndata.html

Best

Hauke

yangshichen0713

yangshichen0713 commented on Jan 2, 2024

@yangshichen0713
Author

Thanks, I will have a try!

samuel-marsh

samuel-marsh commented on Feb 28, 2024

@samuel-marsh
Collaborator

Hi,

Not member of dev team but hopefully can be helpful. As per other issues here Seurat team has updated that SeuratData (convert function) is no longer being actively maintained.

As others have mentioned sceasy will work if it’s Assay (Seurat v3/4) object but not v5 and unfortunately package doesn’t appear to be actively maintained. To simplify the process I have introduced as.anndata function in my package scCustomize which will work will either type of Seurat object and without requiring conversion of assay type.

https://samuel-marsh.github.io/scCustomize/articles/Object_Conversion.html#convert-seurat-or-liger-objects-to-anndata-objects

Best,
Sam

Note: Closing issue as it pertains to SeuratDisk/Convert function.

heteyszabolcs

heteyszabolcs commented on Mar 20, 2024

@heteyszabolcs

object[["RNA3"]] <- as(object = object[["RNA"]], Class = "Assay")
DefaultAssay(object) <- "RNA3"
object[["RNA"]] <- NULL
object <- RenameAssays(object = object, RNA3 = 'RNA')

After I converted back to V3 the mojaveazure way worked. Thanks!

albertfei1998

albertfei1998 commented on Jun 14, 2025

@albertfei1998

obj[["RNA3"]] <- as(obj[["RNA"]], Class = "Assay")
DefaultAssay(obj) <- "RNA3"
obj[["RNA"]] <- NULL
obj <- RenameAssays(object = obj, RNA3 = 'RNA')
after converted back to V3, it works.
but scanpy read the converted .h5sd file and showed only 2000 genes, which might be the high variable gene.
very inconvenient in V5, suggest use scanpy from the very begining.

albertfei1998

albertfei1998 commented on Jun 14, 2025

@albertfei1998

Hi,

Not member of dev team but hopefully can be helpful. As per other issues here Seurat team has updated that SeuratData (convert function) is no longer being actively maintained.

As others have mentioned sceasy will work if it’s Assay (Seurat v3/4) object but not v5 and unfortunately package doesn’t appear to be actively maintained. To simplify the process I have introduced as.anndata function in my package scCustomize which will work will either type of Seurat object and without requiring conversion of assay type.

https://samuel-marsh.github.io/scCustomize/articles/Object_Conversion.html#convert-seurat-or-liger-objects-to-anndata-objects

Best, Sam

Note: Closing issue as it pertains to SeuratDisk/Convert function.

great work!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @samuel-marsh@heteyszabolcs@albertfei1998@haukeh90@yangshichen0713

        Issue actions

          Can't convert Seurat 5 object to h5ad AnnData · Issue #8220 · satijalab/seurat