text: user1475: I'm using the python API for the biom-format package. I read in two files in biom format and merged them, like so:
  In [1]: import biom
  
  In [2]: a = biom.load_table('./table-a.biom')
  
  In [3]: b = biom.load_table('./table-b.biom')
  
  In [4]: a
  Out[4]: 51116 x 46 <class 'biom.table.Table'> with 185077 nonzero entries (7% dense)
  
  In [5]: b
  Out[5]: 37479 x 26 <class 'biom.table.Table'> with 100124 nonzero entries (10% dense)
  
  In [6]: c = a.merge(b)
  
  In [7]: c
  Out[7]: 67022 x 47 <class 'biom.table.Table'> with 254555 nonzero entries (8% dense)
  
  How do I now export this biom object (c) as a biom file? There are a few methods available, eg, .to_tsv(), but I don't see a way to save this object in biom format.
  
  user1691: There is a function in PiCRUST you can use
  from picrust.util import write_biom_table
  
  write_biom_table(c,'table-c.biom')
  
  Note, however, that depending if you want json or hdf5 format and if your metadata are complex, you may need to use additional arguments. These are the arguments of the function:
  def write_biom_table(biom_table, biom_table_fp, compress=True,
                   write_hdf5=HAVE_H5PY, format_fs=None):
  """Writes a BIOM table to the specified filepath
  
  Parameters
  ----------
  biom_table : biom.Table
      The table object to write out
  biom_table_fp : str
      The path to the output file
  compress : bool, optional
      Defaults to ``True``. If True, built-in compression on the output HDF5
      file will be enabled. This option is only relevant if ``write_hdf5`` is
      ``True``.
  write_hdf5 : bool, optional
      Defaults to ``True`` if H5PY is installed and to ``False`` if H5PY is
      not installed. If ``True`` the output biom table will be written as an
      HDF5 binary file, otherwise it will be a JSON string.
  format_fs : dict, optional
      Formatting functions to be passed to `Table.to_hdf5`
  
  Notes
  -----
  This code was adapted from QIIME 1.9
  """
  
  I have some problems to perform a simple operation and write the output of biom data generated with picrust, it might be helpful as an example of how to use the arguments.
  
  user2307: You can use the functions to_hdf5 and to_json from the biom-format package:
  to_hdf5
  with biom.util.biom_open('output.biom', 'w') as f:
      merged_table.to_hdf5(f, "example")
  
  to_json
  with open('output.txt', 'w') as f:
      f.write(merged_table.to_json("example"))
  
  
original_text: 1475: <p>I'm using the python API for the biom-format package. I read in two files in biom format and merged them, like so:</p>
  
  <pre><code>In [1]: import biom
  
  In [2]: a = biom.load_table('./table-a.biom')
  
  In [3]: b = biom.load_table('./table-b.biom')
  
  In [4]: a
  Out[4]: 51116 x 46 &lt;class 'biom.table.Table'&gt; with 185077 nonzero entries (7% dense)
  
  In [5]: b
  Out[5]: 37479 x 26 &lt;class 'biom.table.Table'&gt; with 100124 nonzero entries (10% dense)
  
  In [6]: c = a.merge(b)
  
  In [7]: c
  Out[7]: 67022 x 47 &lt;class 'biom.table.Table'&gt; with 254555 nonzero entries (8% dense)
  </code></pre>
  
  <p>How do I now export this biom object (<code>c</code>) as a biom file? There are a few methods available, eg, <code>.to_tsv()</code>, but I don't see a way to save this object in biom format.</p>
   1691: <p>There is a function in <a href="http://picrust.github.io/" rel="nofollow noreferrer">PiCRUST</a> you can use</p>
  
  <pre><code>from picrust.util import write_biom_table
  
  write_biom_table(c,'table-c.biom')
  </code></pre>
  
  <p>Note, however, that depending if you want json or hdf5 format and if your metadata are complex, you may need to use additional arguments. These are the arguments of the function:</p>
  
  <pre><code>def write_biom_table(biom_table, biom_table_fp, compress=True,
                   write_hdf5=HAVE_H5PY, format_fs=None):
  """Writes a BIOM table to the specified filepath
  
  Parameters
  ----------
  biom_table : biom.Table
      The table object to write out
  biom_table_fp : str
      The path to the output file
  compress : bool, optional
      Defaults to ``True``. If True, built-in compression on the output HDF5
      file will be enabled. This option is only relevant if ``write_hdf5`` is
      ``True``.
  write_hdf5 : bool, optional
      Defaults to ``True`` if H5PY is installed and to ``False`` if H5PY is
      not installed. If ``True`` the output biom table will be written as an
      HDF5 binary file, otherwise it will be a JSON string.
  format_fs : dict, optional
      Formatting functions to be passed to `Table.to_hdf5`
  
  Notes
  -----
  This code was adapted from QIIME 1.9
  """
  </code></pre>
  
  <p>I have some problems to perform a simple operation and write the output of biom data generated with picrust, it might be helpful as an <a href="https://github.com/biocore/qiime/issues/2205" rel="nofollow noreferrer">example</a> of how to use the arguments.</p>
   2307: <p>You can use the functions <code>to_hdf5</code> and <code>to_json</code> from the <a href="http://biom-format.org/documentation/generated/biom.table.Table.html" rel="nofollow noreferrer">biom-format package</a>:</p>
  
  <p><code>to_hdf5</code></p>
  
  <pre><code>with biom.util.biom_open('output.biom', 'w') as f:
      merged_table.to_hdf5(f, "example")
  </code></pre>
  
  <p><code>to_json</code></p>
  
  <pre><code>with open('output.txt', 'w') as f:
      f.write(merged_table.to_json("example"))
  </code></pre>
  