Skip to contents

Save a Seurat object to the efficient HDF5-based h5Seurat format. This format is optimized for large, complex single-cell datasets including multi-modal and spatial data. h5Seurat files can be rapidly converted to other formats like h5ad (AnnData) or h5mu (MuData) for interoperability with Python tools.

Usage

SaveH5Seurat(object, filename, overwrite = FALSE, verbose = TRUE, ...)

as.h5Seurat(x, ...)

# Default S3 method
SaveH5Seurat(object, filename, overwrite = FALSE, verbose = TRUE, ...)

# S3 method for class 'Seurat'
SaveH5Seurat(
  object,
  filename = paste0(Project(object = object), ".h5Seurat"),
  overwrite = FALSE,
  verbose = TRUE,
  ...
)

# Default S3 method
as.h5Seurat(x, filename, overwrite = FALSE, verbose = TRUE, ...)

# S3 method for class 'H5File'
as.h5Seurat(x, ...)

# S3 method for class 'Seurat'
as.h5Seurat(
  x,
  filename = paste0(Project(object = x), ".h5seurat"),
  overwrite = FALSE,
  verbose = TRUE,
  ...
)

Arguments

object, x

An object (typically a Seurat object)

filename

Name of file to save the object to. If not provided, defaults to <ProjectName>.h5seurat. The .h5seurat extension is added automatically if not present.

overwrite

Logical; if TRUE, overwrite an existing file with the same name. Default is FALSE.

verbose

Show progress updates during save. Default is TRUE.

...

Arguments passed to other methods

Value

SaveH5Seurat: Invisibly returns the filename of the saved file

as.h5Seurat: An h5Seurat object

Details

The h5Seurat format stores:

  • All assays with their layers (counts, data, scale.data, etc.) for Seurat V5

  • Dimensional reductions (PCA, UMAP, etc.)

  • Nearest-neighbor graphs and similarity graphs

  • Spatial images and coordinates (for spatial experiments)

  • Cell metadata and feature annotations

  • Cell identity classes

  • Command history

  • Miscellaneous and tool-specific data

The h5Seurat format is particularly useful for:

  • Storing large datasets efficiently with HDF5 compression

  • Rapid conversion to Python formats (h5ad, h5mu)

  • Multi-modal and spatial transcriptomics experiments

  • Preserving all Seurat V5 layer information

Seurat V5 Layer Support

When saving Seurat V5 objects with multiple layers (e.g., counts, data, scale.data), all layers are preserved and can be selectively loaded using LoadH5Seurat.

See also

LoadH5Seurat to load a saved h5Seurat file as.h5Seurat for direct conversion without object assignment Convert for converting to other formats (h5ad, h5mu)

Examples

if (FALSE) { # \dontrun{
library(Seurat)
library(SeuratDisk)

# Create a simple example Seurat object
seurat_obj <- CreateSeuratObject(counts = GetAssayData(pbmc_small))

# Save to h5Seurat format
SaveH5Seurat(seurat_obj, filename = "my_data.h5seurat")

# Save with overwrite if file already exists
SaveH5Seurat(seurat_obj, filename = "my_data.h5seurat", overwrite = TRUE)

# Load the saved file back
seurat_obj <- LoadH5Seurat("my_data.h5seurat")

# For multimodal data (e.g., CITE-seq)
# SaveH5Seurat automatically saves all assays
SaveH5Seurat(citeseq_obj, filename = "multimodal_data.h5seurat")

# For spatial data (e.g., Visium)
SaveH5Seurat(visium_obj, filename = "spatial_visium.h5seurat")
} # }