HOW TO 'collapse' all branches in a tree that have a support below a given value

718 views
Skip to first unread message

romain....@gmail.com

unread,
Oct 23, 2015, 5:36:26 AM10/23/15
to The ETE toolkit

Dear all,

Using a fully resolved phylogenetic tree with branch support values, I would like to collapse (or 'remove' ... not sure what would be the most appropriate term here) all branches of this tree that have, lets say, a support below 70% of boot.
At the end, I would like to obtain a tree in which all of these weakly supported branches are replaced by polytomies. 

Does anyone know a function in the ETE package that would allow me to do such thing ?

Thanks in advance for your help !
Romain

Alexandros Pittis

unread,
Oct 23, 2015, 7:31:37 AM10/23/15
to eteto...@googlegroups.com
Hey Romain,

so, if I understand well, what you want is deleting lowly supported branches and making a polytomy instead. By deleting the corresponding node, the nodes below are by default transferred to the parental one, one "up". For instance :

from ete2 import Tree
t = Tree('(((a:1,b:1)1:1,c:1)1:1,((e:1,f:1)0.5:1,g:1)1:1);')

print t.get_ascii(attributes=['support', 'name'])

               /-1.0, a
          /1.0,
     /1.0,     \-1.0, b
    |    |
    |     \-1.0, c
-1.0,
    |          /-1.0, e
    |     /0.5,
     \1.0,     \-1.0, f
         |
          \-1.0, g

# Loop through the nodes below the basal one and delete based on their support attribute or any other condition.

for node in t.get_descendants():
    if not node.is_leaf() and node.support <= 0.7:
        node.delete()

print t.get_ascii(attributes=['support', 'name'])

               /-1.0, a
          /1.0,
     /1.0,     \-1.0, b
    |    |
    |     \-1.0, c
-1.0,
    |     /-1.0, g
    |    |
     \1.0, -1.0, e
         |
          \-1.0, f

Check the delete function and here for more examples on various operations.

Cheers,
Alexandros



--
You received this message because you are subscribed to the Google Groups "The ETE toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+...@googlegroups.com.
To post to this group, send email to eteto...@googlegroups.com.
Visit this group at http://groups.google.com/group/etetoolkit.
For more options, visit https://groups.google.com/d/optout.



--
Alexandros Pittis, PhD candidate
Comparative Genomics Group

Centre for Genomic Regulation (CRG)
Barcelona Biomedical Research Park (PRBB)
Doctor Aiguader, 88
08003 Barcelona, Spain
alexandr...@crg.eu
http://gabaldonlab.crg.es

romain....@gmail.com

unread,
Oct 23, 2015, 7:46:54 AM10/23/15
to The ETE toolkit
Hy Alex,

thanks a lot, that works perfectly !!

cheers,
Romain

bioBalls

unread,
Dec 16, 2016, 1:43:27 AM12/16/16
to The ETE toolkit
Thank you very much!!!

Works perfect!

Greetings,
Armin

Philip Ashton

unread,
Aug 23, 2017, 11:31:20 PM8/23/17
to The ETE toolkit
This was really useful, thanks!
Reply all
Reply to author
Forward
0 new messages