Drawing Cloud Trees¶
Cloud tree drawings provide a useful way to visualize discordance among sets of trees in a MultiTree object.
In [1]:
Copied!
import toytree
import toytree
Example dataset¶
In [8]:
Copied!
# a multi-newick string
NEWICKS = """\
(((a:1,b:1):1,(d:1.5,e:1.5):0.5):1,c:3);
(((a:1,d:1):1,(b:1,e:1):1):1,c:3);
(((a:1.5,b:1.5):1,(d:1,e:1):1.5):1,c:3.5);
(((a:1.25,b:1.25):0.75,(d:1,e:1):1):1,c:3);
(((a:1,b:1):1,(d:1.5,e:1.5):0.5):1,c:3);
(((b:1,a:1):1,(d:1.5,e:1.5):0.5):2,c:4);
(((a:1.5,b:1.5):0.5,(d:1,e:1):1):1,c:3);
(((b:1.5,d:1.5):0.5,(a:1,e:1):1):1,c:3);
"""
# a multi-newick string
NEWICKS = """\
(((a:1,b:1):1,(d:1.5,e:1.5):0.5):1,c:3);
(((a:1,d:1):1,(b:1,e:1):1):1,c:3);
(((a:1.5,b:1.5):1,(d:1,e:1):1.5):1,c:3.5);
(((a:1.25,b:1.25):0.75,(d:1,e:1):1):1,c:3);
(((a:1,b:1):1,(d:1.5,e:1.5):0.5):1,c:3);
(((b:1,a:1):1,(d:1.5,e:1.5):0.5):2,c:4);
(((a:1.5,b:1.5):0.5,(d:1,e:1):1):1,c:3);
(((b:1.5,d:1.5):0.5,(a:1,e:1):1):1,c:3);
"""
In [9]:
Copied!
# create a multitree object
mtree = toytree.mtree(NEWICKS)
# create a multitree object
mtree = toytree.mtree(NEWICKS)
Cloud tree drawings¶
The .draw_cloud_tree
function takes similar styling arguments as the ToyTree.draw
function but accepts a few additional arguments.
In [24]:
Copied!
# draw a cloud tree
mtree.draw_cloud_tree(
scale_bar=True,
edge_style={
"stroke-opacity": 0.1,
"stroke-width": 2.5,
},
);
# draw a cloud tree
mtree.draw_cloud_tree(
scale_bar=True,
edge_style={
"stroke-opacity": 0.1,
"stroke-width": 2.5,
},
);
Styling individual trees¶
I find it useful to set different styles on different trees in a set to better examine their differences. In this example I set a different color to the edges depending on whether the tree topology matches the most common topology in the set or not.
In [21]:
Copied!
# make a copy of the multitree on which we will set styles
mtree2 = mtree.copy()
# get unique trees
utrees = mtree2.get_unique_topologies()
# set color to red if most common topology, else green
for tree in mtree2:
if tree.distance.get_treedist_rf(utrees[0][0]) == 0:
tree.style.edge_colors = 'red'
else:
tree.style.edge_colors = "green"
# draw the cloud tree w/o any overriding args to use individual .style dicts
mtree2.draw_cloud_tree(
scale_bar=True,
interior_algorithm=0,
edge_style={"stroke-opacity": 0.25},
tip_labels_style={"font-size": 15},
);
# make a copy of the multitree on which we will set styles
mtree2 = mtree.copy()
# get unique trees
utrees = mtree2.get_unique_topologies()
# set color to red if most common topology, else green
for tree in mtree2:
if tree.distance.get_treedist_rf(utrees[0][0]) == 0:
tree.style.edge_colors = 'red'
else:
tree.style.edge_colors = "green"
# draw the cloud tree w/o any overriding args to use individual .style dicts
mtree2.draw_cloud_tree(
scale_bar=True,
interior_algorithm=0,
edge_style={"stroke-opacity": 0.25},
tip_labels_style={"font-size": 15},
);