Fork me on GitHub


«  biom.table.Table.max   ::   Contents   ::   biom.table.Table.metadata  »


Table.merge(other, sample='union', observation='union', sample_metadata_f=<function prefer_self at 0x10d1f6410>, observation_metadata_f=<function prefer_self at 0x10d1f6410>)

Merge two tables together

The axes, samples and observations, can be controlled independently. Both can work on either “union” or “intersection”.

sample_metadata_f and observation_metadata_f define how to merge metadata between tables. The default is to just keep the metadata associated to self if self has metadata otherwise take metadata from other. These functions are given both metadata dicts and must return a single metadata dict


other : biom.Table

The other table to merge with this one

sample : {‘union’, ‘intersection’}, optional

observation : {‘union’, ‘intersection’}, optional

sample_metadata_f : function, optional

Defaults to biom.util.prefer_self. Defines how to handle sample metadata during merge.

obesrvation_metadata_f : function, optional

Defaults to biom.util.prefer_self. Defines how to handle observation metdata during merge.



The merged table


  • There is an implicit type conversion to float.
  • The return type is always that of self


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

Create a 2x2 table and a 3x2 table:

>>> d_a = np.asarray([[2, 0], [6, 1]])
>>> t_a = Table(d_a, ['O1', 'O2'], ['S1', 'S2'])
>>> d_b = np.asarray([[4, 5], [0, 3], [10, 10]])
>>> t_b = Table(d_b, ['O1', 'O2', 'O3'], ['S1', 'S2'])

Merging the table results in the overlapping samples/observations (see O1 and S2) to be summed and the non-overlapping ones to be added to the resulting table (see S3).

>>> merged_table = t_a.merge(t_b)
>>> print merged_table  
# Constructed from biom file
#OTU ID S1      S2
O1      6.0     5.0
O2      6.0     4.0
O3      10.0    10.0

«  biom.table.Table.max   ::   Contents   ::   biom.table.Table.metadata  »