Skip to contents

Export multimodal Seurat objects to MuData (.h5mu) format. This function wraps MuDataSeurat::WriteH5MU with additional support for spatial data preservation and Seurat V5 layer handling.

Usage

SaveH5MU(
  object,
  filename,
  assays = NULL,
  modality.names = NULL,
  include.spatial = TRUE,
  overwrite = FALSE,
  verbose = TRUE,
  ...
)

as.h5mu(object, filename, ...)

Arguments

object

A Seurat object

filename

Output filename

assays

Character vector of assay names to export. If NULL (default), exports all assays

modality.names

Named vector mapping assay names to desired modality names in the h5mu file. If NULL, uses reverse of standard mapping (RNA→rna, ADT→prot, ATAC→atac, etc.)

include.spatial

Logical; if TRUE, includes spatial data (coordinates, images, scalefactors) in the h5mu file

overwrite

Overwrite existing file

verbose

Show progress messages

...

Additional arguments passed to SaveH5MU

Value

Invisibly returns the filename

Invisibly returns the filename

Details

The h5mu format is designed for multimodal data and stores each Seurat assay as a separate modality under /mod/{modality_name}. This function:

  • Extracts each specified assay from the Seurat object

  • Converts assays to modality structure

  • Writes counts, data, and scale.data layers for each modality

  • Preserves cell metadata in both global /obs and per-modality obs

  • Includes spatial data if requested

  • Maintains dimensional reductions and graphs

Assay Mapping

By default, Seurat assay names are mapped to standard MuData modality names:

  • RNA → rna

  • ADT → prot

  • ATAC → atac

  • Spatial → spatial

  • Other names are converted to lowercase

Examples

if (FALSE) { # \dontrun{
# Save a multimodal Seurat object (CITE-seq)
SaveH5MU(seurat_obj, "multimodal_data.h5mu")

# Save specific assays only
SaveH5MU(seurat_obj, "rna_and_protein.h5mu", assays = c("RNA", "ADT"))

# Custom modality name mapping
SaveH5MU(
  seurat_obj,
  "data.h5mu",
  modality.names = c(RNA = "rna", Protein = "prot")
)

# Include spatial data
SaveH5MU(visium_obj, "spatial_multimodal.h5mu", include.spatial = TRUE)
} # }