Skip to contents

Convert another AnnData object to an HDF5AnnData object

Arguments

adata

An AnnData object to be converted to HDF5AnnData

file

The file name (character) of the .h5ad file

compression

The compression algorithm to use when writing the HDF5 file. Can be one of "none", "gzip" or "lzf". Defaults to "none".

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

Value

An HDF5AnnData object with the same data as the input AnnData object.

See also

Examples

ad <- AnnData(
  X = matrix(1:5, 3L, 5L),
  layers = list(
    A = matrix(5:1, 3L, 5L),
    B = matrix(letters[1:5], 3L, 5L)
  ),
  obs = data.frame(row.names = LETTERS[1:3], cell = 1:3),
  var = data.frame(row.names = letters[1:5], gene = 1:5),
)
ad$as_HDF5AnnData("test.h5ad")
#> AnnData object with n_obs × n_vars = 3 × 5
#>     obs: 'cell'
#>     var: 'gene'
#>     layers: 'A', 'B'
# remove file
file.remove("test.h5ad")
#> [1] TRUE