If I create a phylogenetic tree using Biopython Phylo module, it is oriented from left to right, e.g.:
import matplotlib.pyplot as plt
from Bio import Phylo
from io import StringIO
handle = StringIO("(((A,B),(C,D)),(E,F,G));")
tree = Phylo.read(handle, "newick")
fig, ax = plt.subplots(1, 1, figsize=(6, 6))
Phylo.draw(tree, axes=ax, do_show=False)
plt.savefig("./tree_rect.png")
plt.close(fig)
If I now try to convert it to a circular tree using the built-in polar transformation of matplotlib, I obtain:
fig, ax = plt.subplots(subplot_kw=dict(polar=True), figsize=(6, 6))
Phylo.draw(tree, axes=ax, do_show=False)
plt.savefig("./tree_circ.png")
plt.close(fig)
I obtain
that is matplotlib takes y-axis as the radial axis and x-axis as the angle. This is the opposite of what I need for obtaining a correct layout, which I can do, e.g., using ete3:
from ete3 import Tree, TreeStyle
t = Tree("(((A,B),(C,D)),(E,F,G));")
circular_style = TreeStyle()
circular_style.mode = "c"
circular_style.scale = 20
t.render("tree_ete3.png", w=183, units="mm", tree_style=circular_style)
(How) could this be done using Bio.Phylo? I suppose the possibilities are
- Changing the layout in
Phylo.draw
, so that the tree is directed upwards - telling matplotlib polar transformation to use x-axis as the radial vector and y-axis as the angle
but I don't know how to do either (and whether it can be done.)
Related question: Python: How to convert a phylogenetic tree into a circular format?