How to collapse metadata in qiime feature-table heatmap

I need to know how to display a specific metadata in a heatmap without redundancy

I am using this code to generate a heatmap of collapsed feature table to the phyla level in samples that are categorized by plant genus . I mean, I have only 5 plant genera as a source of 63 samples. but, the heatmap displayed by sampleID+the plant genus which look redundant (repetitive plant genera). Is there a way to collapse the metadata.

qiime feature-table heatmap
–i-table table-no-mito-no-chlor-l2.qza
–m-sample-metadata-file metadata.tsv
–m-sample-metadata-column SampleGenus
–o-visualization heatmapphyla.qzv

Also, is there an option to flip the figure (taxa displayed on y- axis and metadata on x-axis).


1 Like

Hello Eman,

Yes. The idea is to use feature-table group to combine samples so you just have 5 samples (one for each of your five plants :rose::hibiscus::sunflower::blossom::tulip:), then make a heatmap of this grouped table.

Not within this plugin… yet! That would be a cool feature to add to the plugin.


1 Like

Hello @colinbrislawn

I grouped the metadata column
qiime feature-table group
–i-table table-no-mito-no-chlor-l2.qza
–p-axis sample
–m-metadata-file metadata.tsv
–m-metadata-column “PlantGenus”
–p-mode sum
–o-grouped-table tableheatmap.qza


qiime feature-table heatmap
–i-table tableheatmap.qza
–m-sample-metadata-file metadata.tsv
–m-sample-metadata-column PlantGenus
–o-visualization heatmapphyla1.qzv

I got this error

Plugin error from feature-table:

The following IDs are not present in the metadata: then listing the 5 plant genera names

Traceback (most recent call last):
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2cli/”, line 328, in call
results = action(**arguments)
File “</home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/>”, line 2, in heatmap
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/sdk/”, line 240, in bound_callable
output_types, provenance)
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/sdk/”, line 445, in callable_executor
ret_val = self._callable(output_dir=temp_dir, **view_args)
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2_feature_table/_heatmap/”, line 121, in heatmap
table = _munge_sample_metadata(sample_metadata, table, cluster)
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2_feature_table/_heatmap/”, line 79, in _munge_sample_metadata
metadata = metadata.filter_ids(table.index)
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/metadata/”, line 1105, in filter_ids
File “/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/metadata/”, line 198, in _filter_ids_helper
% (’, '.join(repr(e) for e in sorted(missing_ids))))
ValueError: The following IDs are not present in the metadata: ‘Genus1’, ‘Genus2’, ‘Genus3’, ‘Genus4’, ‘Genus5’

I think by grouping we lost the primary key of data tables; sample_Id.

I don’t know what to do??


Hi! Could you try instead of

…this code?

qiime feature-table heatmap
  --i-table tableheatmap.qza
  --o-visualization heatmapphyla1.qzv

It works! I am super happy. Thank you so much! Indeed, I intended to generate heatmaps for this project in qiime since the phyloseq object is missing almost half of the samples, I do not know why? I am using the same script that I have used for other projects! Feature taxonomy table.biom has 63 samples and qiime qza files show 63 samples, but the object in R shows only 37 samples. I know almost 1/3 of my samples have very low read counts but they should exist.
One more question, is there a way to select the top50/20 taxa? So far, I think I can keep them by using --p-min-frequency

qiime feature-table filter-features \
--i-table table.qza \
 --p-min-frequency xxx \
--o-filtered-table table-top50.qza

where I can assign xxx manually by checking the feature table. Is that true?

Thanks again

1 Like

That’s right! You have made great progress on this heatmap! :1st_place_medal:


Sounds great!

1 Like

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