Hi, Does anyone have any experience generating phylogenetic trees using Plotly with python? I already have the newick files for the trees and can process and plot them (e.g. with ete3 or Bio.Phylo), but I would love to get the x-y coordinates of those tree nodes and edges to generate interactive plots in Plotly. Or maybe there are other more elegant ways to generate trees from newick files in Plotly. Thanks in advance for any help!
Jon
2 answers
There is no y coordinate for the tree nodes but you can get the x (branch length) like this:
from Bio import Phylo
tree = Phylo.read("example.nwk", "newick")
#all nodes:
print(tree.depths())
# only terminals nodes:
print(tree.get_terminals())
Thanks Simon. I don't think I asked my question in the quite right way. Although a newick tree is a just a mathematical object with no representation in 2D space, some drawing algorithm must have been used to render that object onto two (x,y) dimensions on a graph. So I am wondering 1) what algorithm(s) can render a newick tree object into a 2D graph like in the image below, and 2) how can I grab the coordinates of the nodes and edges?
Thanks!
Log in to answer this question.