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
768 stars 216 forks source link

Leaf names visible despite show_leaf_name=False #734

Open michaelgruenstaeudl opened 7 months ago

michaelgruenstaeudl commented 7 months ago

The following code is supposed to visualize a minimalistic tree next to a sequence alignment, with the tree leaves displayed as aligned. Especially note the setting ts.show_leaf_name=False

from ete3 import PhyloTree, TreeStyle, TextFace
tre = "(A:3,(B:1,C:6));"
aln = """
>A
ATGC
>B
GCAT
>C
AGCT
"""
t = PhyloTree(tre, alignment=aln, alg_format="fasta")
for l in t.iter_leaves():
    l.add_face(TextFace(l.name), 0, position='aligned')
ts = TreeStyle()
ts.show_leaf_name=False
ts.draw_guiding_lines=True
t.show(tree_style=ts)

However, the above code displays both the original leaf names as well as the new (i.e., aligned) ones. test I wish to display only the new (i.e., aligned) leaf names. What part of the above code is incorrect?

Yogesh1-11 commented 5 months ago

why cant i use "def layout(node):" node and leaves have some different definition? leaf and node both are not working. please see the code attached from ete3 import PhyloTree, faces, AttrFace, TreeStyle, NodeStyle tre = "(A:3,(B:1,C:6));" aln = """

A ATGC B GCAT C AGCT """ t = PhyloTree(tre, alignment=aln, alg_format="fasta") t = PhyloTree(tre, alignment=aln, alg_format="fasta") positions_to_color = [2,3] def layout(leaf): sequence = leaf.name # Access the sequence directly from the leaf name print("Processing leaf:", leaf.name) # Print the leaf name being processed

# Color specified positions
for position in positions_to_color:
    aa = sequence[position - 1]  # Access the character at the position
    print(f"  - Coloring position {position} with amino acid: {aa}")  # Print position and amino acid
    color = faces._aabgcolors.get(aa, "#FFFFFF")

ts = TreeStyle() ts.show_leaf_name = False ts.draw_guiding_lines = True t.set_style({"layout_fn": layout}) t.show(tree_style=ts)