jeetsukumaran / DendroPy

A Python library for phylogenetic scripting, simulation, data processing and manipulation.

Home Page:https://pypi.org/project/DendroPy/.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected unifurcation suppression in reroot_at_node()

psathyrella opened this issue · comments

Unless I'm missing something, it appears that when reroot_at_node() is called on an unrooted tree, that suppress_unifurcations=False doesn't always have the desired effect. I think this isn't the expected behavior?

This should reproduce it:

#!/usr/bin/env python
import dendropy

print 'version: ', dendropy.__version__
unrooted_treestr = '(((l1,l2)n2)n1)root;'
rooted_treestr = '[&R] ' + unrooted_treestr

for tlabel, tstr in [('unrooted', unrooted_treestr), ('rooted', rooted_treestr)]:
    print '%s:' % tlabel
    dtree = dendropy.Tree.get_from_string(tstr, 'newick')

    print 'before reroot:'
    print dtree.as_ascii_plot(show_internal_node_labels=True, width=70)

    new_root_node = dtree.seed_node.child_nodes()[0]
    dtree.reroot_at_node(new_root_node, suppress_unifurcations=False)

    print 'after reroot:'
    print dtree.as_ascii_plot(show_internal_node_labels=True, width=70)
    print ''

and the output I get is:

version:  4.4.0
unrooted:
before reroot:
                                            /---------------------- l1
root------------------n1--------------------n2                        
                                            \---------------------- l2
                                                                      
                                                                      
after reroot:
/---------------------------------------------------------------- l1  
|                                                                     
n1--------------------------------------------------------------- l2  
|                                                                     
\---------------------------------------------------------------- root
                                                                      
                                                                      

rooted:
before reroot:
                                            /---------------------- l1
root------------------n1--------------------n2                        
                                            \---------------------- l2
                                                                      
                                                                      
after reroot:
                                /-------------------------------- l1  
/-------------------------------n2                                    
n1                              \-------------------------------- l2  
|                                                                     
\---------------------------------------------------------------- root


where n2 disappears on reroot in the first (unrooted) case, but not in the second (rooted) case.

ok, great, thanks.

Also, I may have missed it, but I couldn't find the choices for the rooting keyword arg for Tree.get() by clicking around from here or here, although eventually found it in dataio/newickreader.py by grepping the source.