readH5AD: Read matrix from H5AD file

View source: R/import.R

readH5ADR Documentation

Read matrix from H5AD file

Description

Read raw count matrix from H5AD file. By default, readH5AD load specified layer into memory (inMemory = TRUE). To use LIGER in delayed mode for handling large datasets, set inMemory = FALSE to load the data as a DelayedArray object. Note that only CSR format is supported for the matrix.

Usage

readH5AD(filename, layer, inMemory = TRUE, obs = FALSE)

readH5ADMem(filename, layer, obs = FALSE)

readH5ADDelay(filename, layer, obs = FALSE)

Arguments

filename

Character string, path to the H5AD file.

layer

Character string specifying the H5 path of raw count data to be loaded. Use 'X' for adata.X, 'raw/X' for adata.raw.X, or 'layers/layer_name' for adata.layers['layer_name'].

inMemory

Logical, whether to load the data into memory. Default TRUE. FALSE loads the data as a DelayedArray object.

obs

Logical, whether to also load the cell metadata from adata.obs. Default FALSE.

Details

Currently, the only supported H5AD AnnData encoding versions are as follows:

  • adata.X, adata.raw.X, or adata.layers['layer'] - csr_matrix 0.1.0

  • adata.obs and adata.var - dataframe 0.2.0

  • Categoricals in a data frame - categorical 0.2.0

If users possess H5AD files encoded with older specification, please either open an issue on GitHub or use R package 'anndata' to manually extract information.

Value

When loaded in memory, a sparse matrix of class dgCMatrix will be returned. When loaded in delayed mode, a TENxMatrix object will be returned. If obs = TRUE, a list containing the matrix and the cell metadata will be returned.

Examples

tempH5AD <- tempfile(fileext = '.h5ad')
writeH5AD(pbmc, tempH5AD, overwrite = TRUE)
mat <- readH5AD(tempH5AD, layer = 'X')
delayMat <- readH5AD(tempH5AD, layer = 'X', inMemory = FALSE)

rliger documentation built on June 8, 2025, 1:56 p.m.