Skip to contents

Read data from a H5AD file

Usage

read_h5ad(
  path,
  to = c("InMemoryAnnData", "HDF5AnnData", "SingleCellExperiment", "Seurat"),
  mode = c("r", "r+", "a", "w", "w-", "x"),
  ...
)

Arguments

path

Path to the H5AD file to read

to

The type of object to return. Must be one of: "InMemoryAnnData", "HDF5AnnData", "SingleCellExperiment", "Seurat"

mode

The mode to open the HDF5 file.

  • a creates a new file or opens an existing one for read/write.

  • r opens an existing file for reading.

  • r+ opens an existing file for read/write.

  • w creates a file, truncating any existing ones.

  • w-/x are synonyms, creating a file and failing if it already exists.

...

Extra arguments provided to adata$to_SingleCellExperiment() or adata$to_Seurat(). See AnnData() for more information on the arguments of these functions. Note: update this documentation when r-lib/roxygen2#955 is resolved.

Value

The object specified by to

Examples

h5ad_file <- system.file("extdata", "example.h5ad", package = "anndataR")

# Read the H5AD as a SingleCellExperiment object
if (requireNamespace("SingleCellExperiment", quietly = TRUE)) {
  sce <- read_h5ad(h5ad_file, to = "SingleCellExperiment")
}

# Read the H5AD as a Seurat object
if (requireNamespace("SeuratObject", quietly = TRUE)) {
  seurat <- read_h5ad(h5ad_file, to = "Seurat")
}
#> Warning: Data is of class dgRMatrix. Coercing to dgCMatrix.
#> Warning: No columnames present in cell embeddings, setting to 'PC_1:38'
#> Warning: No columnames present in cell embeddings, setting to 'umap_1:2'