biotapy.io.write_biom

Contents

biotapy.io.write_biom#

biotapy.io.write_biom(adata, path, *, fmt='hdf5')#

Write X with taxonomy and sample metadata as a BIOM table.

Parameters:
  • adata (AnnData) – Samples x features; rank columns in var become observation taxonomy metadata, obs columns become sample metadata.

  • path (str | Path) – Output file.

  • fmt (Literal['hdf5', 'json'] (default: 'hdf5')) – "hdf5" (BIOM 2.1) or "json" (BIOM 1.0).

Raises:

ValueError – fmt is neither "hdf5" nor "json".

Return type:

None

Notes

R equivalent: biomformat::write_biom Guide: Reading and writing data

BIOM has no slot for a tree, layers or embeddings: a TreeData’s tree and everything outside X, rank columns and obs are not written. Sample metadata is written as text; missing values are written as empty strings and read back as NaN. Missing ranks are written as bare prefixes (g__) so every rank keeps its place.

Examples

>>> import tempfile
>>> from pathlib import Path
>>> import biotapy as bt
>>> path = Path(tempfile.mkdtemp()) / "toy.biom"
>>> bt.io.write_biom(bt.datasets.toy(), path)
>>> bt.io.read_biom(path).shape
(6, 8)