biom.table.Table.partition — biom-format.org

# biom-format.org

## biom.table.Table.partition

`Table.` `partition`(f, axis='sample')

  Yields partitions

  Parameters: | f : function f is given the ID and metadata of the vector and must return what partition the vector is part of. axis : {‘sample’, ‘observation’}, optional The axis to iterate over
  Returns: | GeneratorType A generator that yields (partition, Table)

  Examples

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

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

      >>> data = np.asarray([[0, 0, 1], [1, 3, 42]])
      >>> table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'],
      ...               [{'full_genome_available': True},
      ...                {'full_genome_available': False}],
      ...               [{'sample_type': 'a'}, {'sample_type': 'a'},
      ...                {'sample_type': 'b'}])

  Define a function to bin by sample_type

      >>> f = lambda id_, md: md['sample_type']

  Partition the table and view results

      >>> bins, tables = table.partition(f)
      >>> print bins[1]
      # Constructed from biom file
      #OTU ID S1  S2
      O1  0.0 0.0
      O2  1.0 3.0
      >>> print tables[1]
      # Constructed from biom file
      #OTU ID S3
      O1  1.0
      O2  42.0