def prettifyTree(ete_tree, leaf_font_size=32, branch_support_size=20, show_bootstraps=True, title=None, ts=None): ''' Perform standardized functions to make the ETE trees easier to read: - Make the branch support bigger - Make the leaf fonts bigger - Turn off elongating branches for visualization purposes (i.e. make sure the real branch lengths are represented) - Change both to standard font (Times) - Standardize the tree's width (calculate based on the maximum length from the root to a tip) - (optional) add title to tree ''' for node in ete_tree.traverse(): if node.is_leaf(): # Make text faces with name = the existing node name but with big font. # A side effect of this is that we also get the annotations lined up F = faces.TextFace(node.name, ftype="Times", fsize=leaf_font_size) node.add_face(F, 0, position="aligned") else: if show_bootstraps: # Make branch support bigger F = faces.TextFace(node._support, ftype="Times", fsize=branch_support_size) node.add_face(F, 0, position="branch-top") #correct the long root node bug (fixed in next release) ete_tree.dist = 0 # Optionally create a new TreeStyle if we are not passing in an old one. if ts is None: ts = TreeStyle() # This "fixes" the dashed line issue but makes the tree look terrible. # There may be no way around this (and it's likely other tree viewers do the same thing # but just don't tell you). #ts.optimal_scale_level = "full" # We made these bigger so lets turn off the default ones too. ts.show_branch_support = False ts.show_leaf_name = False if title is not None: ts.title.clear() title = TextFace(title) title.hz_align = True title.fsize = 52 ts.title.add_face(title, 0) return ete_tree, ts
def prettifyTree(ete_tree, leaf_font_size = 32, branch_support_size = 20, show_bootstraps = True, title=None, ts = None): ''' Perform standardized functions to make the ETE trees easier to read: - Make the branch support bigger - Make the leaf fonts bigger - Turn off elongating branches for visualization purposes (i.e. make sure the real branch lengths are represented) - Change both to standard font (Times) - Standardize the tree's width (calculate based on the maximum length from the root to a tip) - (optional) add title to tree ''' for node in ete_tree.traverse(): if node.is_leaf(): # Make text faces with name = the existing node name but with big font. # A side effect of this is that we also get the annotations lined up F = faces.TextFace(node.name, ftype="Times", fsize=leaf_font_size) node.add_face(F, 0, position="aligned") else: if show_bootstraps: # Make branch support bigger F = faces.TextFace(node._support, ftype="Times", fsize=branch_support_size) node.add_face(F, 0, position="branch-top") #correct the long root node bug (fixed in next release) ete_tree.dist=0 # Optionally create a new TreeStyle if we are not passing in an old one. if ts is None: ts = TreeStyle() # This "fixes" the dashed line issue but makes the tree look terrible. # There may be no way around this (and it's likely other tree viewers do the same thing # but just don't tell you). #ts.optimal_scale_level = "full" # We made these bigger so lets turn off the default ones too. ts.show_branch_support = False ts.show_leaf_name = False if title is not None: ts.title.clear() title = TextFace(title) title.hz_align = True title.fsize = 52 ts.title.add_face(title, 0) return ete_tree, ts