Fork me on GitHub

biom-format.org

biom.table.Table.sort_order

«  biom.table.Table.sort   ::   Contents   ::   biom.table.Table.subsample  »

biom.table.Table.sort_order

Table.sort_order(order, axis='sample')

Return a new table with axis in order

Parameters:

order : iterable

The desired order for axis

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

The axis to operate on

Returns:

Table

A table where the observations or samples are sorted according to order

Examples

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

Create a 2x3 BIOM table:

>>> data = np.asarray([[1, 0, 4], [1, 3, 0]])
>>> table = Table(data, ['O2', 'O1'], ['S2', 'S1', 'S3'])
>>> print table 
# Constructed from biom file
#OTU ID S2  S1  S3
O2  1.0 0.0 4.0
O1  1.0 3.0 0.0

Sort the table using a list of samples:

>>> sorted_table = table.sort_order(['S2', 'S3', 'S1'])
>>> print sorted_table 
# Constructed from biom file
#OTU ID S2      S3      S1
O2      1.0     4.0     0.0
O1      1.0     0.0     3.0

Additionally you could sort the table’s observations:

>>> sorted_table = table.sort_order(['O1', 'O2'], axis="observation")
>>> print sorted_table 
# Constructed from biom file
#OTU ID S2      S1      S3
O1      1.0     3.0     0.0
O2      1.0     0.0     4.0

«  biom.table.Table.sort   ::   Contents   ::   biom.table.Table.subsample  »