Seurat to Scanpy Conversion
Export a Seurat object to .h5ad with SeuratDisk
What it does
This workflow converts an R Seurat object into a Scanpy-compatible .h5ad file. It uses SeuratDisk to save an intermediate .h5Seurat file and then convert that object into AnnData format, preserving the chosen assay and Seurat metadata in the exported object.
When to use it
Use this workflow when the upstream analysis was performed in Seurat but the next step needs to happen in Python or Scanpy. It is a compact format-conversion utility rather than a full analysis notebook, and it is most helpful when you need a clear reminder of which Seurat assay becomes the primary AnnData matrix.
Prerequisites
- Source folder:
scRNAseq_Seurat_to_Scanpy - Main files:
- Required packages include
qs,Seurat, andSeuratDisk - Input: a Seurat object, commonly stored as
combined.qsave - Version caveat from the committed README: the tested path assumes Seurat versions below v5 because
SeuratDisksupport was limited at the time of testing
Steps
Load the Seurat object and update it before export
The script reads a .qsave object, updates it if needed, and sets the assay that should become the main expression layer in the exported .h5ad.
sample_name <- "combined.qsave"
combined <- qs::qread(sample_name)
combined <- UpdateSeuratObject(combined)
DefaultAssay(combined) <- "RNA"
# or DefaultAssay(combined) <- "SCT"Choose the assay intentionally before conversion
The README makes the assay choice the main decision point in this workflow:
- if
RNAis the default assay, the export writes RNA normalized data toXand RNA counts toraw - if
SCTis the default assay, the export changes which matrix becomes the primary layer
That choice determines what Scanpy will treat as the main expression matrix after import, so it should match the downstream Python analysis you actually plan to run.
Export to .h5Seurat and convert to .h5ad
The conversion itself is a two-step handoff through SeuratDisk.
SaveH5Seurat(combined, filename = "combined.h5Seurat", overwrite = TRUE)
Convert("combined.h5Seurat", dest = "h5ad", overwrite = TRUE)Check metadata and export separate variants if needed
The committed script and README both suggest a small amount of cleanup may be needed before import on the Python side. In particular, the script comments note that metadata columns containing all NA values can cause problems and may need to be removed before writing the .h5Seurat file. The README also explicitly notes that you can export different assays separately if you want multiple H5AD variants.
Gotchas / notes
- The README explicitly warns that the tested path uses Seurat below v5 because
SeuratDisksupport was limited at the time of testing. - The committed script includes comments about clearing metadata columns with all-
NAvalues if Scanpy import errors occur. - The committed script uses
combinedfor the loaded object but also showsDefaultAssay(seu) <- "SCT"in one line, so readers should treat that as a source inconsistency and apply the assay choice to the object they actually loaded. - This workflow is intentionally thin: it contains a script and README, but no committed local figures or rendered screenshots.