biotapy.io.read_biom#
- biotapy.io.read_biom(path, *, tree=None)#
Read a BIOM table (JSON 1.0 or HDF5 2.1) with samples as rows.
- Parameters:
- Return type:
- Returns:
TreeData The table in
X; observationtaxonomymetadata as rank columns invar; sample metadata inobs, with empty values as NaN; the tree invart['phylo'].- Raises:
biom.exception.TableException – The file repeats a sample or observation id (raised by biom-format).
ValueError –
treeis not a valid Newick tree, or shares no tip with the table.
- Warns:
UserWarning – Tree tips and table features differ; only shared features are kept.
Notes
R equivalent:
phyloseq::import_biomGuide: Reading and writing dataBIOM does not record what
Xholds, souns['biotapy']['x_kind']is inferred from the values: non-negative whole numbers are"counts", rows that each sum to 1 are"relative", anything else is"abundance".Only the
taxonomy(orTaxonomy) observation metadata key is read; other observation keys, such asconfidence, are not.Examples
>>> import tempfile >>> from pathlib import Path >>> import biom >>> from biom.util import biom_open >>> import biotapy as bt >>> toy = bt.datasets.toy() >>> path = Path(tempfile.mkdtemp()) / "toy.biom" >>> table = biom.Table(toy.X.T, list(toy.var_names), list(toy.obs_names)) >>> with biom_open(str(path), "w") as handle: ... table.to_hdf5(handle, "example") >>> bt.io.read_biom(path).shape (6, 8)