making sample-ids appear in a specific order in the heatmap

Hello :smiley:

I successfully constructed a heatmap using the feature-table (I was also able to remove redundancy by grouping the metadata tables)-thank you to all the relevant discussions on the forum!
I have 2 questions:

  1. The sample ids (top-to-bottom-placed on the right of the heatmap) do not appear in the order I specify them in the metadata file. Is there a way I can rearrange the sample ids?

  2. I realize the heatmap requires a feature-table as input (which is derived from taxonomy files, derived in turn from ASVs/OTUs). I was wondering if I could do the same thing, instead use a diversity metric (e.g. Jaccard) as an input. In that case, do I need to first merge the diversity column to the feature-metadata file, and then proceed to the rest of the steps I used to create the previous heatmap?

Thanks!
Anirban

Hi @anirban.mcgill!

Check out the --p-cluster option:

  --p-cluster TEXT Choices('samples', 'features', 'both', 'none')
                         Specify which axes to cluster.      [default: 'both']

You can disable sample-axis clustering, which will keep the samples in the same order they are provided in the table.

You should be able to use this method to convert to a feature table:

https://docs.qiime2.org/2020.6/plugins/available/sample-classifier/metatable/

Using data from the Moving Pictures tutorial:

qiime sample-classifier metatable \
  --i-table table.qza \
  --m-metadata-file core-metrics-results/evenness_vector.qza \
  --m-metadata-file core-metrics-results/faith_pd_vector.qza \
  --m-metadata-file core-metrics-results/observed_features_vector.qza \
  --m-metadata-file core-metrics-results/shannon_vector.qza \
  --o-converted-table merged-table.qza

qiime feature-table transpose \
  --i-table merged-table.qza \
  --o-transposed-feature-table transposed-table.qza

qiime feature-table filter-features \
  --i-table merged-table.qza \
  --m-metadata-file transposed-table.qza \
  --p-where "[id] IN ('pielou_evenness', 'faith_pd', 'observed_features', 'shannon_entropy')"\
  --o-filtered-table filtered-table.qza

qiime feature-table heatmap \
  --i-table filtered-table.qza \
  --p-cluster none \
  --o-visualization heatmap.qzv

Hope that helps! :qiime2:

5 Likes

Hi @thermokarst

I did what you suggested: disabled the --p-cluster option, however, my sample ids are not in the order they are in the sample metadata file.

Please let me mention my exact flow of operations:

  • Created a tabulated feature metadata .qzv file using qiime metadata tabulate

  • From visualization of the .qzv file, I prepared the feature-table tab separated file. Columns were id, feature (the sequence), taxonomy, confidence values

  • I edited this sheet manually to separate the taxonomy into phyla, class etc. columns. All these columns are categorical

  • I next use qiime feature-table group to group at phyla level by summing the values. Here is the command:

qiime feature-table group
–i-table my-table.qza
–p-axis ‘feature’
–m-metadata-file feature-metadata-edit.tsv
–m-metadata-column Phyla
–p-mode ‘sum’
–o-grouped-table grouped-phyla-feature-metadata-edit
–verbose

  • Finally, I ran the heatmap script:

qiime feature-table heatmap
–i-table grouped-phyla-feature-metadata-edit.qza
–p-color-scheme ‘ocean_r’
–o-visualization HEAT-MAPS/feature-metadata-edit.qzv

PS: I tried all variations of the --p-cluster command (including not mentioning it), yet the order of sample ids in the heatmap is the same.

So, I tried visualizing the grouped table using:

qiime metadata tabulate
–m-input-file grouped-phyla-feature-metadata-edit.qza
–o-visualization HEAT-MAPS/example-feature-metadata.qzv

Guess what: the sample ids in the grouped feature table are the same as they are in the heatmap, which makes sense. So I was wondering if there is no way to change this order

Attempt 2: I ran this command:

qiime feature-table heatmap
–i-table grouped-phyla-feature-metadata-edit.qza
–m-sample-metadata-file sample-metadata.tsv
–m-sample-metadata-column Day
–p-cluster ‘features’
–p-color-scheme ‘ocean_r’
–o-visualization HEAT-MAPS/example-feature-metadata-2.qzv

Here as well I tried changing --p-cluster to ‘none’, but it does not work. I also referred to earlier posts in the forum.

So here are my inferences:

  • either I am not understanding the --p-cluster command usage, OR
  • I fail to understand why changing the order in the sample metadata file is not seen in the heatmap.
  • I also tried to match feature-ids (in the feature metadata) to sample-ids (in the sample metadata) to see if I could change the order in the feature-table itself, yet couldn’t do that too!
  • Tried to change the grouped-table artifact-not happening (sigh!)

I am sorry this is very long post. Believe me I tried to troubleshoot this-I went back to provenance of each of the commands to see file-paths etc. yet there is somewhere I am missing out. If you could help (some hint), that would be greatly appreciated :slight_smile:

Merci!
Anirban

Hi,
Sorry to post this again-this is from a previous thread, I tried to order my samples in the heatmap, I seem to be stuck somewhere I cannot understand.

I did what @thermokarst suggested in this post: disabled the --p-cluster option, however, my sample ids are not in the order they are in the sample metadata file.

Please let me mention my exact flow of operations:

  • Created a tabulated feature metadata .qzv file using qiime metadata tabulate
  • From visualization of the .qzv file, I prepared the feature-table tab separated file . Columns were id, feature (the sequence), taxonomy, confidence values
  • I edited this sheet manually to separate the taxonomy into phyla, class etc. columns. All these columns are categorical
  • I next use qiime feature-table group to group at phyla level by summing the values. Here is the command:

qiime feature-table group
–i-table my-table.qza
–p-axis ‘feature’
–m-metadata-file feature-metadata-edit.tsv
–m-metadata-column Phyla
–p-mode ‘sum’
–o-grouped-table grouped-phyla-feature-metadata-edit
–verbose

  • Finally, I ran the heatmap script:

qiime feature-table heatmap
–i-table grouped-phyla-feature-metadata-edit.qza
–p-color-scheme ‘ocean_r’
–o-visualization HEAT-MAPS/feature-metadata-edit.qzv

PS: I tried all variations of the --p-cluster command (including not mentioning it), yet the order of sample ids in the heatmap is the same.

So, I tried visualizing the grouped table using:

qiime metadata tabulate
–m-input-file grouped-phyla-feature-metadata-edit.qza
–o-visualization HEAT-MAPS/example-feature-metadata.qzv

Guess what: the sample ids in the grouped feature table are the same as they are in the heatmap, which makes sense. So I was wondering if there is no way to change this order

Attempt 2: I ran this command:

qiime feature-table heatmap
–i-table grouped-phyla-feature-metadata-edit.qza
–m-sample-metadata-file sample-metadata.tsv
–m-sample-metadata-column Day
–p-cluster ‘features’
–p-color-scheme ‘ocean_r’
–o-visualization HEAT-MAPS/example-feature-metadata-2.qzv

Here as well I tried changing --p-cluster to ‘none’, but it does not work. I also referred to earlier posts in the forum.

So here are my inferences:

  • either I am not understanding the --p-cluster command usage, OR
  • I fail to understand why changing the order in the sample metadata file is not seen in the heatmap.
  • I also tried to match feature-ids (in the feature metadata) to sample-ids (in the sample metadata) to see if I could change the order in the feature-table itself, yet couldn’t do that too!
  • Tried to change the grouped-table artifact-not happening (sigh!)

I am sorry this is very long post. Believe me I tried to troubleshoot this-I went back to provenance of each of the commands to see file-paths etc. yet there is somewhere I am missing out. If you could help (some hint), that would be greatly appreciated :slight_smile:

Merci!
Anirban

Sorry, I should’ve made that more clear - the samples won’t be reordered based on your Sample Metadata, but they will retain the same order that they are in your FeatureTable[Frequency] file. This is useful when generating several heatmaps of the same table. There is no way currently to manually specify the order of the table within QIIME 2, but you can always import the table into your favorite tool and make your own heatmap with the customizations you need.

1 Like

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