biom.table.Table.metadata

Table.metadata(id=None, axis='sample')

Return the metadata of the identified sample/observation.

Parameters:
idstr

ID of the sample or observation whose index will be returned.

axis{‘sample’, ‘observation’}

Axis to search for id.

Returns:
defaultdict or None

The corresponding metadata defaultdict or None of that axis does not have metadata.

Raises:
UnknownAxisError

If provided an unrecognized axis.

UnknownIDError

If provided an unrecognized sample/observation ID.

Examples

>>> import numpy as np
>>> from biom.table import Table

Create a 2x3 BIOM table, with observation metadata and no sample metadata:

>>> data = np.asarray([[0, 0, 1], [1, 3, 42]])
>>> table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'],
...               [{'foo': 'bar'}, {'x': 'y'}], None)

Get the metadata of the observation with ID “O2”:

>>> # casting to `dict` as the return is `defaultdict`
>>> dict(table.metadata('O2', 'observation'))
{'x': 'y'}

Get the metadata of the sample with ID “S1”:

>>> table.metadata('S1', 'sample') is None
True