This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert a Seurat object to .h5ad file

Hi,

I'm trying to build a single-cell browser using cellxgene from the Chan-Zuckerberg Intiative. However, I need to have a .h5ad file from the annpdata ackage in Python. I've done all my analysis in R, mainly using Seurat.

I was wondering if there's a way to convert a Seurat object to .h5ad within R. Seurat team seems to be working on this but as of Aug 2019 it's non-functional.

Thanks.

single-cell rna-seq seurat r scanpy

4 answers

Looks like the way to do it is to write to loom format via loomR, then read that into anndata to be written as an .h5ad file.

Single cell folks need to a pick a file format/structure and stick with it.

EDIT (02/05/2021): The recent zellkonverter package from Bioc provides an easier way to do this.

Could not have said it better. Thanks!

In R, you can convert Seurat object to h5ad and vice versa using sceasy.

The best way now is to manually create your h5ad from seurat objects, such as put all normalized value as adata.X , raw counts to adata.raw, all gene annotations to adata.var and all cell annotations to adata.obs, etc

Or use scanpy from the very beginning.

But then how do you actually make the conversion?

You can also try to use the srt_to_adata function of SCP package (https://github.com/zhanghao-njmu/SCP)

library(SCP)
data("pancreas1k")
adata <- srt_to_adata(pancreas1k)
adata$write_h5ad("pancreas1k.h5ad")

Log in to answer this question.