Open michaelgruenstaeudl opened 7 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)
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
However, the above code displays both the original leaf names as well as the new (i.e., aligned) ones.
I wish to display only the new (i.e., aligned) leaf names. What part of the above code is incorrect?