Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaf names visible despite show_leaf_name=False #734

Open
michaelgruenstaeudl opened this issue Nov 26, 2023 · 2 comments
Open

Leaf names visible despite show_leaf_name=False #734

michaelgruenstaeudl opened this issue Nov 26, 2023 · 2 comments
Assignees

Comments

@michaelgruenstaeudl
Copy link

michaelgruenstaeudl commented Nov 26, 2023

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
Copy link

Yogesh1-11 commented Feb 4, 2024

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)

@Tarasovk49
Copy link

Hi, Michael!
Never got this problem using ete3, but recently I switched to ete4, rewrote the code for the particular tree I used to render with ete3 and got same issue as you.
What solved it for me was changing the default value of TreeStyle.show_leaf_name to False:

self.show_leaf_name = True

Though, if I want the names to be shown, I just add ts.show_leaf_name = True in my code and it works perfect.
I believe you may find similar lines in ete3 code and do the same.
Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants