Export hetamap to tsv

This topic may seem odd, and I haven’t found reference to this in the forum - so here goes:

I would like to export a heatmap to a tsv format. More specifically, the features are clustered and I would like to replicate the order of the clustered features, to use as a supplementary table alongside the actual visual heatmap. Thanks :ocean: :sun_with_face:

Hi!
I don’t remember about heatmaps, but if you will open a corresponding .qzv file as archive and navigate to ‘data’ subfolder, you will find all necessary files, including .tsv or .csv tables.

2 Likes

Awesome! Many thanks @timanix for this neat method.
I did have to lookup how to do it, and found it here, works great, just like exporting, but easier :slightly_smiling_face:
*Unfortunately this did not solve my problem though...

2 Likes

Hi @shira! Glad you found that post, but for the sake of demonstration, I'll point you towards the "official" QIIME 2 solution:

https://docs.qiime2.org/2020.2/tutorials/exporting/

:qiime2:

Thanks @thermokarst, but the tutorial you cite talks about exporting, but actually does not solve my original problem which was the need to obtain the table containing the clustered heatmap data. I could not find any mention of this super useful ‘trick’ of opening a QZV file as a ZIP and finding all these goodies inside. Is there an official write up of that?

1 Like

Yes, but not in a tutorial:

https://dev.qiime2.org/latest/storing-data/

See this section of the tutorial I sent earlier for details on "extracting":

https://docs.qiime2.org/2020.2/tutorials/exporting/#exporting-versus-extracting

As for the contents of the extracted viz, I don't think you'll find any TSVs or CSVs for this particular visualization (although it sounds like maybe you found an alternative path forward, based on your reply above?). You marked a "solution", which implies that your original request has been resolved. If not, please clarify. The reason I shared the export/extract tutorial is that it is written up in more detail, compared to @colinbrislawn's "hack" that you shared.

2 Likes

Thanks @thermokarst - you are right of course! The table I was looking for was not among the files after all :frowning:
I unmarked the “solution” button - but what is the solution?

1 Like

I don't think there is a solution that gets you exactly what you want. @timanix and @thermokarst provided details on the way to export/extract data from any QZA/QZV, but that only works if the data are stored in there. In the case of the heatmap visualization, the raw data are not stored in there, only the image I believe. Let me see if I can get you close to what you want:

You can use export to export your feature table (the one used as input to heatmap) as a biom, then convert the biom to a TSV using biom convert --to-tsv.

Exporting the feature table would not replicate this sorting. You could just export and either manually sort (if the table is small!) or supplement the unsorted table.

1 Like

Thanks @Nicholas_Bokulich. That’s too bad, it would be quite useful, for publication purposes. As far as I understand, in R you can easily get the sorted row names back, perhaps this should be added to the exported data in a QIIME heatmap as well?

Yes, this can also be done using the python module that QIIME 2 uses to make this heatmap. I am not sure if this would be useful or a hindrance to most users, though (this would increase runtime and create another file to clutter up the workspace!). I have opened an issue to track this here but my feeling right now is that this will be a low priority unless if we get more demand for this (this is the first request we've had) — contributions are always welcome!

Thanks @shira !

1 Like

Hi @shira

This is something I've done in Python though it was with mmvec results rather than a feature-table heatmap. My understanding is that qiime feature-table heatmap uses seaborn.clustermap under the hood.

The underlying "clustered" data can be retrieved using the data2d property of the clustermap. So if you have a clustermap plotted like this:

g = sns.clustermap(...)

g.data2d would return a DataFrame "ordered" by the clustermap rows/columns.

This may require you to plot the clustermap manually, as I am not super familiar with Qiime2's visualization data architecture.

3 Likes

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