AttributeError: 'NoneType' object has no attribute 'encode' when using biom add-metadata


I am trying to add taxonomy data generated in QIIME2 to a BIOM table.

The command:

biom add-metadata -i MATRIX-COUNT-transposed.biom -o MATRIX-COUNT-transposed-wtax.biom --observation-metadata-fp taxonomy.tsv --sc-separated taxonomy

The error:

 File "/opt/software/QIIME2/2017.8/lib/python3.5/site-packages/biom_format-2.1.6-py3.5-linux-x86_64.egg/biom/", line 4123, in to_hdf5
    self.group_metadata(axis='observation'), 'csr', compression)
  File "/opt/software/QIIME2/2017.8/lib/python3.5/site-packages/biom_format-2.1.6-py3.5-linux-x86_64.egg/biom/", line 4095, in axis_dump
    formatter[category](grp, category, md, compression)
  File "/opt/software/QIIME2/2017.8/lib/python3.5/site-packages/biom_format-2.1.6-py3.5-linux-x86_64.egg/biom/", line 274, in general_formatter
    data=[m[header].encode('utf8') for m in md],
  File "/opt/software/QIIME2/2017.8/lib/python3.5/site-packages/biom_format-2.1.6-py3.5-linux-x86_64.egg/biom/", line 274, in <listcomp>
    data=[m[header].encode('utf8') for m in md],
AttributeError: 'NoneType' object has no attribute 'encode'

The two main suggestions (based on googling) I saw and incorporated were to make sure my taxonomy.tsv file had the headers “OTUID taxonomy confidence” with tab separations rather than spaces and to add the --sc-separated taxonomy flag. I’ve also validated my BIOM table with biom validate-table.

Any help would be greatly appreciated! I’d like to be able to continue my analysis using QIIME2 but it seems I need to get past this hurdle first.

Hey @lzocean!

Would you be able to post a sample of taxonomy.tsv? Also I noticed your table has transposed in the filename. Does that mean anything as far as the biom table itself is concerned?


Hi @ebolyen! Thanks for your reply! Here are the first several lines of my taxonomy.tsv:

#OTUID  taxonomy        confidence
LH_1543 Eukaryota;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Raphid-pennate;Pseudo-nitzschia    1
LH_35   Eukaryota;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Radial-centric-basal-Coscinodiscophyceae   1
LH_173  Eukaryota;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Raphid-pennate;Raphid-pennate_X;Raphid-pennate_X_sp.;      1
LH_154  Eukaryota;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Raphid-pennate;Pseudo-nitzschia    0.9
LH_487  Eukaryota;Alveolata;Dinophyta;Dinophyceae;Dinophyceae_X;Dinophyceae_XX;Dinophyceae_XXX;Dinophyceae_XXX_sp.;     1
LH_1343 Eukaryota;Stramenopiles;Ochrophyta;Pelagophyceae;Pelagophyceae_X;Pelagophyceae_XX;Pelagophyceae_XXX;Pelagophyceae_XXX_sp.;      0.8
LH_134  Eukaryota;Stramenopiles;Ochrophyta;Pelagophyceae;Pelagophyceae_X;Pelagophyceae_XX;Pelagophyceae_XXX;Pelagophyceae_XXX_sp.;      0.8
LH_1513 Eukaryota;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Polar-centric-Mediophyceae;Thalassiosira   0.545454545
LH_26   Eukaryota;Stramenopiles;Ochrophyta      1

In regard to the table, I use Minimum Entropy Decomposition to analyze my data and generate my OTUs. The output from MED is a matrix counts table with the samples I inputted as rows and the OTU IDs as columns. I believe the standard BIOM format is the opposite, so I transposed the matrix in Excel. I did reopen it in TextWrangler to make sure it was in Unix format with Unicode (UTF-8) selected. Hope that helps.

Thanks @lzocean!

Your example seems to use spaces instead of tabs, but that might just be our forum software trying to be clever. If you were to load that taxonomy.tsv in Excel, is it able to pick out the columns correctly?

Also, do the IDs in your example match your biom table? You can check with:

biom table-ids --observations -i MATRIX-COUNT-transposed.biom

Let me know what you find!


Yes, Excel is able to separate out the columns correctly.

I ran the command you suggested and the IDs match. However, there seem to be more IDs in my BIOM table (106 it looks like) than my taxonomy table (which only had 100 IDs). Also they are not in the same order. Would either of those cause problems?

Hey @lzocean

Sorry for the delayed response.

This is probably the issue, try filtering your BIOM table down to only the IDs in your taxonomy table and see if that works better.

Yes, this seemed to be the issue! The add-metadata command went through without an error and I used summarize-table to verify that the metadata was added. Thanks so much for your help!


This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.