biom.table.Table.update_ids

Table.update_ids(id_map, axis='sample', strict=True, inplace=True)

Update the ids along the given axis.

Parameters:
id_mapdict

Mapping of old to new ids. All keys and values in this dict should be strings.

axis{‘sample’, ‘observation’}, optional

Axis to search for id. Defaults to ‘sample’

strictbool, optional

If True, raise an error if an id is present in the given axis but is not a key in id_map. If False, retain old identifier for ids that are present in the given axis but are not keys in id_map.

inplacebool, optional

If True the ids are updated in self; if False the ids are updated in a new table is returned.

Returns:
Table

Table object where ids have been updated.

Raises:
UnknownAxisError

If provided an unrecognized axis.

TableException

If an id from self is not in id_map and strict is True.

Examples

Create a 2x3 BIOM table:

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

Define a mapping of old to new sample ids:

>>> id_map = {'S1':'s1.1', 'S2':'s2.2', 'S3':'s3.3'}

Get the ids along the sample axis in the table:

>>> print(table.ids(axis='sample'))
['S1' 'S2' 'S3']

Update the sample ids and get the ids along the sample axis in the updated table:

>>> updated_table = table.update_ids(id_map, axis='sample')
>>> print(updated_table.ids(axis='sample'))
['s1.1' 's2.2' 's3.3']