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

Rerooting branch support value problem #689

Open
metehaansever opened this issue Jun 1, 2023 · 1 comment
Open

Rerooting branch support value problem #689

metehaansever opened this issue Jun 1, 2023 · 1 comment

Comments

@metehaansever
Copy link

Hello,
I am trying to reroot the Newick tree but each format has some problems.

import ete3

t = ete3.Tree("((C,D)1,(A,(B,X)3)2,E)R;",format=1)
left_most = t.search_nodes(name='X')[0]
right_most = t.search_nodes(name='X')[0]
new_root = t.get_common_ancestor(left_most, right_most)
t.set_outgroup(new_root)
new_newick = t.write(format=1,format_root_node=True, outfile="newick_tree.txt")

print (t)

When I try with format=1 and reroot from X, I receive the right tree with misplaced branch support values.

(X:0.5,(B:1,(A:1,((C:1,D:1)1:1,E:1):1)2:1)3:0.5)R:0;

When I try with format=0 and reroot from X, I receive the right tree with the right branch support values but format=0 sets 1 to each branch support values.

(X:0.5,(B:1,(A:1,((C:1,D:1)1:1,E:1)2:1)3:1)1:0.5)1:0;

And I just want to know if am i doing something wrong or if is there any other workaround solution for rerooting with format = 1?

@emilhaegglund
Copy link

emilhaegglund commented Jun 5, 2023

Hi,
I think this is the correct behaviour since with format=1 the values are not interpreted as support values but node names and therefore should be moved on rerooting, and this also explains why it sets all support values to 1.
But I still think this is a problem because phylogenies with multiple support values, such as Ultrafast Bootstrap and SH-aLRT from IQ-Tree, can only be read with format=1 and when rerooting them the values are moved.
One workaround I have seen is to first loop over the tree and copy the value of the node name attribute to the node support attribute.

for n in t.traverse():
    n.support = float(n.name)

For multiple types of support values, you can split the string of support values and keep one of the values

for n in t.traverse():
    n.support = float(n.name.split("/")[0])

or you can try this quick-fix script that I hope should work.

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

2 participants