extract metadata from biom file

Skip to first unread message


Dec 10, 2015, 4:57:53 PM12/10/15
to Qiime 1 Forum
I would like to load an OTU table and the associated metadata in R, but I'm having some trouble understanding the biom file format.

Ideally, I would just convert the biom file to three separate text files: (1) the OTU table, (2) the sample metadata and (3) the observation metadata. However, for reasons that I have trouble understanding, it seems that this is impossible. I can convert from biom to an OTU table, but I can only keep one column of metadata(?)... Is this correct?

Another approach is to use R's biom package. Unfortunately, this package requires json-formatted biom files, rather than the hdf5 files that are available on the QIITA website. The only way I can find to convert between these is using the "biom convert" utility, but again, I would lose all of the metadata.

I can't imagine that it's impossible to extract the metadata once it's converted to biom, so I must be missing something. Unfortunately I can't find anything in the documentation. If someone could help, I'd really appreciate it. Thanks!


Dec 11, 2015, 9:56:20 AM12/11/15
to Qiime 1 Forum

I think you can do this directly in python...

import biom

# read biom file
a = biom.load_table(infile)

# get sample ids
sample_ids = a.ids()

# get observation ids
obs_ids = a.ids(axis='observation')

# get sample metadata
sample_meta = a.metadata()

# get observation metadata
obs_meta = a.metadata(axis='observation')

Then just write these to a separate file, as needed.

Reply all
Reply to author
0 new messages