# Converting Between h5ad and Seurat
Working with single-cell data often requires switching between different file formats and analysis environments. In R, **Seurat objects** are the standard for single-cell analysis, while in Python, **AnnData (h5ad)** is the go-to format used by **Scanpy**. Switching between Seurat and Scanpy often requires converting data back and forth, especially when combining tools from both ecosystems.
In this short guide, I’ll show how to:
1. Convert **Seurat object** → **h5ad** (including how to fix the RNA layer issue).
2. Convert **h5ad** → **Seurat object** (using reticulate and sceasy).
## Converting from Seurat object to h5ad
```{r}
library(SeuratDisk)
library(Seurat)
# fixing the RNA3 layer problem
convert_rna_seurat = function(seu){
seu[["RNA"]]$data <- seu[["RNA"]]$counts
seu[["RNA3"]] <- as(object = seu[["RNA"]], Class = "Assay")
DefaultAssay(seu) <- "RNA3"
seu[["RNA"]] <- NULL
seu <- RenameAssays(object = seu, RNA3 = 'RNA')
return = seu
}
seu_obj = convert_rna_seurat(seu_obj)
SaveH5Seurat(seu_obj, filename = seu.h5Seurat")
Convert("seu.h5Seurat", dest = "h5ad")
```
## Converting from h5ad to Seurat object
I tested three packages, **sceasy**, **SeuratDisk**, and **zellkonverter** and found that **sceasy** is the easiest to use. Note that when converting from Python, the **reticulate** package is required.
```{r}
library(sceasy)
library(reticulate)
sceasy::convertFormat("adata.h5ad", from="anndata", to="seurat", outFile='seu_obj.rds')
```
## Closing Note
These conversion steps make it easier to move data across ecosystems, whether you prefer R’s Seurat workflows or Python’s Scanpy. The most common issues usually arise from mismatched assay or layer names, so double-check those when troubleshooting.