etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
781 stars 212 forks source link

ultrametric malfunctions in code #721

Closed dengzq1234 closed 11 months ago

dengzq1234 commented 11 months ago

If modify ultrametric option in the tree style function, ultrametric malfunction and lost its capacity even in interactive interface

image

demo code

from ete4 import Tree
from ete4.smartview import TreeStyle, TreeLayout

t = Tree('(((((Phy004Z0OU_MELUD:0.0946697,Phy004V34S_CORBR:0.0843078)1:0.0296133,(Phy004U0LB_BUCRH:0.0424414,Phy004Z7RR_MERNU:0.115361)1:0.00300256)1:0.0131996,(Phy00527O5_PICPB:0.0684659,Phy004TLNA_APAVI:0.04435)1:0.0093323)1:0.0128687,Phy004STVX_187382:0.0385263)1:0.00468636,(((Phy00535AU_PYGAD:0.0330352,Phy004O1E0_APTFO:0.00383064)1:0.0122131,(Phy004UIZ8_CALAN:0.0575799,Phy004SNJQ_CHAVO:0.0713472)1:0.0103022)1:0.000902551,(Phy004OLZN_COLLI:5e-09,Phy004OLZM_COLLI:0.0203921)1:0.0549954)1:0.0019839)1:0.00477848;')
# ultrametric_style = TreeStyle()
# ultrametric_style.ultrametric = True

def modify_tree_style(tree_style):
    #tree_style.aligned_grid = True
    tree_style.collapse_size = 70
    # Add more modifications as needed
    tree_style.ultrametric = True

# Create a TreeLayout object, passing in the function
tree_layout = TreeLayout(name="MyTreeLayout", ts=modify_tree_style)

#layout = TreeLayout(name="example")
#tree_layout.set_tree_style(tree=t, style=tree_layout)
layouts = [tree_layout]
t.explore(keep_server=True, layouts=layouts)
jordibc commented 11 months ago

Thanks @dengzq1234 . As we have discussed, there is no easy "fix" for this problem, and in fact it is modifying a tree (like making it ultrametric) as a "style" what makes it very tricky. We have removed ultrametric from TreeStyle, and done the appropriate changes for the gui to work as before in 01107051.