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
782 stars 212 forks source link

expected collapse branch to outline instead of traingle #666

Open dengzq1234 opened 1 year ago

dengzq1234 commented 1 year ago

I tried to design a layout that collapse target branch(taxonomic rank) to a outline instead of a traingle clade, unfortunately I wasn't able to do so. I wonder if I execute the correct parameters

image

example tree gtdb_annotated.nw.txt

example code

from ete4 import Tree
# from staple_layouts import LayoutBarplot
# from conditional_layouts import LayoutBinary
from ete4.smartview import TreeStyle, NodeStyle, TreeLayout
from ete4.smartview  import RectFace, CircleFace, SeqMotifFace, TextFace, OutlineFace, LegendFace

TREEFILE = './gtdb_annotated.nw.txt'

popup_prop_keys = ['name', 'dist', 'support', 'rank', 'sci_name', 
                    'taxid', 'lineage', 'named_lineage']

t = Tree(TREEFILE, format=1)
level = 2 

def collapse_order():
    def layout_fn(node):
        color="green"
        if not node.is_root() and  node.props.get('rank') == 'order':
            #face_name = TextFace(node.props.get('sci_name'), color=color)
            face_name = OutlineFace(node.props.get('sci_name'), color=color, collapsing_height= float("inf"))
            node.sm_style["draw_descendants"] = False
            node.sm_style["outline_color"] = color
            node.add_face(face_name, column = 8,  position = 'aligned', collapsed_only=True)
    layout_fn.name = "level4_order"
    return layout_fn
    return 

layouts = [
    TreeLayout(name='order', ns=collapse_order())

]

t.explore(tree_name='example',layouts=layouts, \
            popup_prop_keys=popup_prop_keys)