Plot a tree with a heatmap

58 views
Skip to first unread message

Margaux Jullien

unread,
Aug 23, 2023, 10:44:39 AM8/23/23
to eteto...@googlegroups.com
Hello,

I would like to build a tree representation next to a heatmap of the sequence identity matrix similar to this representation (I'm not trying to represent the tree at the top of the figure):
image.png
I am trying to use ClusterTree to do it but I'm not sure I'm doing it correctly as what I am trying to do is not a clustering analysis.

If I use the following tree as an example: 
tree = "(WP_014954389.1:1.3050884292,((((((WP_168783374.1:0.3936806252,WP_043870346.1:0.4684134224)99:0.6985594655,WP_025300848.1:2.0629097729)99:0.6362359355,QCI79366.1:0.8276758532)70:0.3093978568,(((((WP_015238209.1:1.4792774342,WP_178947744.1:1.2226067330)19:0.0672701621,WP_100114824.1:1.2636068690)54:0.1519818345,(WP_157633830.1:0.8652147787,WP_055732702.1:0.8155919632)84:0.4093092999)38:0.1766921552,WP_102950495.1:1.4054850087)34:0.0671828188,((WP_050805257.1:0.7917584769,WP_159714401.1:0.5316354406)100:1.6883433530,WP_083786548.1:2.9441887324)51:0.3430428563)52:0.1985660642)53:0.0938917904,WP_021798970.1:1.2391047710)79:0.2391187740,WP_106873917.1:1.1520717820)90:0.2432860058,WP_145596621.1:2.0375801694);"

and the corresponding matrix :
matrix = """
#Names\tWP_014954389.1\tWP_145596621.1\tWP_106873917.1\tWP_021798970.1\tQCI79366.1\tWP_025300848.1\tWP_102950495.1\tWP_083786548.1\tWP_168783374.1\tWP_043870346.1\tWP_050805257.1\tWP_159714401.1\tWP_100114824.1\tWP_157633830.1\tWP_055732702.1\tWP_015238209.1\tWP_178947744.1
WP_014954389.1\t1.\t0.5\t0.3\t0.2\t0.25\t0.35\t0.3\t0.35\t0.2\t0.25\t0.3\t0.15\t0.25\t0.2\t0.25\t0.05\t0.15
WP_145596621.1\t0.5\t1.\t0.25\t0.15\t0.25\t0.3\t0.4\t0.35\t0.15\t0.2\t0.4\t0.25\t0.3\t0.2\t0.3\t0.05\t0.05
WP_106873917.1\t0.3\t0.25\t1.\t0.4\t0.2\t0.25\t0.25\t0.45\t0.4\t0.15\t0.25\t0.25\t0.2\t0.1\t0.15\t0.05\t0.15
WP_021798970.1\t0.2\t0.15\t0.4\t1.\t0.3\t0.2\t0.25\t0.25\t0.75\t0.1\t0.25\t0.15\t0.25\t0.05\t0.2\t0.15\t0.25
QCI79366.1\t0.25\t0.25\t0.2\t0.3\t1.\t0.25\t0.3\t0.25\t0.35\t0.1\t0.15\t0.15\t0.1\t0.1\t0.15\t0.15\t0.1
WP_025300848.1\t0.35\t0.3\t0.25\t0.2\t0.25\t1.\t0.35\t0.35\t0.2\t0.2\t0.2\t0.2\t0.15\t0.15\t0.3\t0.1\t0.25
WP_102950495.1\t0.3\t0.4\t0.25\t0.25\t0.3\t0.35\t1.\t0.3\t0.25\t0.25\t0.3\t0.2\t0.25\t0.05\t0.25\t0.4\t0.1
WP_083786548.1\t0.35\t0.35\t0.45\t0.25\t0.25\t0.35\t0.3\t1.\t0.3\t0.2\t0.15\t0.3\t0.2\t0.05\t0.4\t0.3\t0.4
WP_168783374.1\t0.2\t0.15\t0.4\t0.75\t0.35\t0.2\t0.25\t0.3\t1.\t0.1\t0.2\t0.1\t0.15\t0.05\t0.25\t0.2\t0.25
WP_043870346.1\t0.25\t0.2\t0.15\t0.1\t0.1\t0.2\t0.25\t0.2\t0.1\t1.\t0.4\t0.5\t0.45\t0.2\t0.15\t0.1\t0.1
WP_050805257.1\t0.3\t0.4\t0.25\t0.25\t0.15\t0.2\t0.3\t0.15\t0.2\t0.4\t1.\t0.45\t0.55\t0.2\t0.2\t0.1\t0.05
WP_159714401.1\t0.15\t0.25\t0.25\t0.15\t0.15\t0.2\t0.2\t0.3\t0.1\t0.5\t0.45\t1.\t0.55\t0.2\t0.1\t0.15\t0.05
WP_100114824.1\t0.25\t0.3\t0.2\t0.25\t0.1\t0.15\t0.25\t0.2\t0.15\t0.45\t0.55\t0.55\t1.\t0.15\t0.15\t0.1\t0.1
WP_157633830.1\t0.2\t0.2\t0.1\t0.05\t0.1\t0.15\t0.05\t0.05\t0.05\t0.2\t0.2\t0.2\t0.15\t1.\t0.25\t0.\t0.
WP_055732702.1\t0.25\t0.3\t0.15\t0.2\t0.15\t0.3\t0.25\t0.4\t0.25\t0.15\t0.2\t0.1\t0.15\t0.25\t1.\t0.1\t0.2
WP_015238209.1\t0.05\t0.05\t0.05\t0.15\t0.15\t0.1\t0.4\t0.3\t0.2\t0.1\t0.1\t0.15\t0.1\t0.\t0.1\t1.\t0.45
WP_178947744.1\t0.15\t0.05\t0.15\t0.25\t0.1\t0.25\t0.1\t0.4\t0.25\t0.1\t0.05\t0.05\t0.1\t0.\t0.2\t0.45\t1.
"""

Here the matrix's rows and columns are ordered just like the tree so I have a diagonal filled with 1 and I expect this diagonal to be visible in the visualization
t = ClusterTree(tree, text_array = matrix)
t.render("%%inline", "heatmap")
image.png
It looks like the rows or the columns of the matrix have been shuffled so the representation is difficult to interpret as I am not sure which one corresponds to which sequence anymore.
So I guess I'm not using ClusterTree as it is supposed to be used. Is what I'm trying to do feasible with this method or should I use something else?

Thanks for any insights!

Margaux

Reply all
Reply to author
Forward
0 new messages