biom.table.Table.index

Table.index(id, axis)

Return the index 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:
int

Index of the sample/observation identified by id.

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:

>>> data = np.asarray([[0, 0, 1], [1, 3, 42]])
>>> table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'])

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

>>> table.index('O2', 'observation')
1

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

>>> table.index('S1', 'sample')
0