How to Convert Seurat to AnnData (.rds to .h5ad): R Code vs. Online Converter

Updated

You have a Seurat object in R and need an AnnData .h5ad file for Scanpy, scvi-tools, CellRank, squidpy, or a CELLxGENE submission. There are four R packages that do this, plus a no-code online option. This guide shows working code for each, explains which Seurat slots end up where, and lists the Seurat v5 issues that break most tutorials.

Short answer: use anndataR::write_h5ad(obj, "out.h5ad"). On Seurat v5, call JoinLayers() first. If you don't want to install anything, use the online Seurat → AnnData converter.

Option 1: anndataR (recommended)

anndataR is the scverse-maintained R package for reading and writing AnnData. It converts Seurat objects directly without Python or an intermediate.h5Seurat file.

# install.packages("BiocManager")
BiocManager::install("anndataR")   # or: remotes::install_github("scverse/anndataR")

library(Seurat)
library(anndataR)

obj <- readRDS("my_seurat.rds")

# Seurat v5: merge split layers (e.g. counts.sample1, counts.sample2) first
obj <- JoinLayers(obj)

write_h5ad(obj, "my_data.h5ad")

If you want control over which layers and reductions are exported, convert to an in-memory AnnData first with as_AnnData(), inspect it, then call write_h5ad() on the result.

Option 2: SeuratDisk

SeuratDisk was the standard approach for years and still appears in most tutorials. It goes through an intermediate .h5Seurat file:

remotes::install_github("mojaveazure/seurat-disk")
library(SeuratDisk)

# Seurat v5 workaround: convert Assay5 back to a v3-style Assay
obj[["RNA"]] <- as(obj[["RNA"]], "Assay")

SaveH5Seurat(obj, filename = "my_data.h5Seurat", overwrite = TRUE)
Convert("my_data.h5Seurat", dest = "h5ad", overwrite = TRUE)

SeuratDisk is not on CRAN, gets few updates, and fails often on Seurat v5 objects. See SeuratDisk errors and alternatives if you hit problems.

Option 3: sceasy

sceasy wraps the conversion in one call, but it calls Python's anndata through reticulate, so you need a working Python environment that R can find:

# Python side: pip install anndata
remotes::install_github("cellgeni/sceasy")
library(sceasy)
library(reticulate)
use_condaenv("my-env")   # environment that has anndata installed

sceasy::convertFormat(obj, from = "seurat", to = "anndata",
                      outFile = "my_data.h5ad")

Option 4: zellkonverter (via SingleCellExperiment)

If you already work in Bioconductor, zellkonverter writes h5ad from a SingleCellExperiment. It manages its own Python environment through basilisk, so the first run downloads Python packages.

BiocManager::install("zellkonverter")
library(zellkonverter)

sce <- as.SingleCellExperiment(obj)
writeH5AD(sce, "my_data.h5ad")

Option 5: online converter (no code)

If you don't have R set up, can't install packages on a shared cluster, or are handing data to a Python-only collaborator, SingleCellConvert runs the anndataR conversion for you on a server. Upload the .rds file (up to 20 GB) and download the .h5ad. It handles Seurat v5 layers and Visium spatial data (coordinates, images, scale factors) automatically. Conversions are paid (from $2.50 per file), so the R options above are better if you already have a working environment.

Which option should you use?

MethodNeeds Python?Seurat v5Spatial dataBest for
anndataRNoYes (JoinLayers first)ManualMost R users
SeuratDiskNoWorkaround neededNoLegacy pipelines
sceasyYes (reticulate)PartialNoMixed R/Python setups
zellkonverterManaged automaticallyVia SCENoBioconductor users
SingleCellConvertNo (no install)YesYes (Visium)No local setup / large files

What maps where

SeuratAnnData
obj@meta.dataadata.obs
Assay feature metadataadata.var
Layers counts / data / scale.dataadata.X and adata.layers
Reductions (pca, umap, tsne)adata.obsm["X_pca"], ["X_umap"], …
Graphs (RNA_snn, RNA_nn)adata.obsp
obj@miscadata.uns

Common problems

Seurat v5 split layers

After IntegrateLayers() or split(), a v5 assay stores one counts layer per sample (counts.1, counts.2, …). Converters expect a single matrix, so run obj <- JoinLayers(obj) before exporting.

Gene names or cell names change

Seurat replaces underscores in feature names with dashes. If you join the h5ad against another table in Python, map names explicitly rather than assuming they match.

Factors become categoricals

R factors are written as pandas categoricals, which is usually what you want. Character columns with many unique values stay as strings.

Verify the result in Python

import scanpy as sc
adata = sc.read_h5ad("my_data.h5ad")
print(adata)                 # check n_obs x n_vars, obs/var columns, obsm keys
sc.pl.umap(adata, color="seurat_clusters")

Frequently asked questions

What is the easiest way to convert a Seurat object to h5ad?

In R, install anndataR and run anndataR::write_h5ad(seurat_obj, "out.h5ad"). For Seurat v5 objects with split layers, run JoinLayers() first. If you cannot install packages, an online converter such as SingleCellConvert does the same conversion without any local setup.

Does SeuratDisk work with Seurat v5?

Not reliably. SeuratDisk predates Seurat v5 Assay5 objects. A common workaround is to convert the assay back with obj[["RNA"]] <- as(obj[["RNA"]], "Assay") before SaveH5Seurat, but anndataR is the better-maintained option today.

Which Seurat data ends up in which AnnData slot?

Cell metadata (meta.data) becomes .obs, gene metadata becomes .var, the counts/data layers become .X and .layers, reductions such as PCA and UMAP become .obsm, and neighbor graphs become .obsp.

Can I convert multiple assays (RNA + ADT) to one h5ad?

AnnData holds one feature space per object, so converters export one assay at a time (usually the default assay). For multimodal data, export each assay to its own h5ad or use MuData.

Related guides