Branch length missing after rerooting

25 views
Skip to first unread message

Marcos Barbeitos

unread,
Jul 13, 2020, 6:34:43 PM7/13/20
to dendrop...@googlegroups.com
Hello, have a posterior distribution of 1000 trees that I have to reroot on the edge leading to Coracias caudatus. My code is:

--
#! /usr/bin/env python
import dendropy, getopt, sys

def reroot( tree ):
    mrca = tree.mrca( taxon_labels = [ "Coracias caudatus" ] ) # Hardcoded
    tree.reroot_at_edge( mrca.edge, update_bipartitions = True )
    return tree

try:
    len(sys.argv)==3

except getopt.GetoptError:
    print( 'Fewer or more than two argument; try something like reroot_trees.py ./input_trees.nex ./output_trees.tre' )
    sys.exit(2)

input_file = [ open( sys.argv[1], "r" ) ]
tree_yielder = dendropy.Tree.yield_from_files( files = input_file, schema = 'nexus', extract_comment_metadata = True, rooting = 'force-unrooted' )

tree_count = 1
rerooted_trees = 0
output_trees = dendropy.TreeList()

for input_tree in tree_yielder:
    output_tree = reroot( input_tree )
    output_trees.append( output_tree )

    tree_count = tree_count + 1
    if tree_count > 9:
        rerooted_trees = rerooted_trees + tree_count
        print ( " ".join( [ "Rerooted", str( rerooted_trees ), "trees" ] ) )
        tree_count = 1

output_trees.write_to_path( dest = sys.argv[2], schema = "nexus" )
--

The beginning of the first rerooted tree looks like:

TREE tree_2428 = [&R] (Coracias_caudatus,((((Ailuroedus_melanotis:34.866504931,(Prionodura_newtoniana:19.09327959...

Am I doing something wrong?

Cheers!

--
Marcos S. Barbeitos

Departamento de Zoologia - Sala 360
Setor de Ciências Biológicas
Universidade Federal do Paraná
Caixa Postal 19020
Curitiba, PR 81531-990
Brazil

Phone: (55 41) 3361-1634

Jeet Sukumaran

unread,
Jul 14, 2020, 3:03:09 AM7/14/20
to dendrop...@googlegroups.com, Marcos Barbeitos
I'll have to check closely to be sure, but I'm guessing that the branch
with no length was the external branch that is now an internal branch?

Is this correct?
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dendropy-users/CA%2BgEHsWSzHeD0ovtCbe8q6QVzw%3DBjJcQELjZEVibNv_T52jUtQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/dendropy-users/CA%2BgEHsWSzHeD0ovtCbe8q6QVzw%3DBjJcQELjZEVibNv_T52jUtQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--

----------------------------------------------------
Jeet Sukumaran
----------------------------------------------------
Assistant Professor
Biology Department
San Diego State University
----------------------------------------------------
Lab:
https://sukumaranlab.org/
Blog:
https://jeetblogs.org/
Repositories:
https://github.com/jeetsukumaran
Photography:
https://www.flickr.com/photos/jeetsukumaran/
Instagram:
https://www.instagram.com/jeetsukumaran/
Calendar:
https://goo.gl/dG5Axs
----------------------------------------------------
Email:
jsuku...@sdsu.edu (work)
jeetsu...@gmail.com (personal)
----------------------------------------------------
Mailing Address:
Biology Department, LS 262
San Diego State University
5500 Campanile Drive
San Diego, CA 92182-4614
----------------------------------------------------

Marcos Barbeitos

unread,
Jul 14, 2020, 3:23:26 PM7/14/20
to Jeet Sukumaran, dendrop...@googlegroups.com
Hi Jeet! Yep, that seems to be the case! Cheers!

Jeet Sukumaran

unread,
Jul 14, 2020, 3:24:43 PM7/14/20
to Marcos Barbeitos, dendrop...@googlegroups.com
Did the root branch originally have a length?
> <mailto:dendropy-users%2Bunsu...@googlegroups.com>
> > <mailto:dendropy-user...@googlegroups.com
> <mailto:dendropy-users%2Bunsu...@googlegroups.com>>.
> jsuku...@sdsu.edu <mailto:jsuku...@sdsu.edu> (work)
> jeetsu...@gmail.com <mailto:jeetsu...@gmail.com> (personal)

Marcos Barbeitos

unread,
Jul 14, 2020, 3:30:42 PM7/14/20
to Jeet Sukumaran, dendrop...@googlegroups.com
Yes, it did. This would be the "end" of the first tree, where the outgroup shows up. It seems to be the case in every tree I checked. I do not mind sharing  the file if you'd like to run some tests. Cheers!

... Menura_novaehollandiae:63.178197420000004):27.039825191000002,Coracias_caudatus:90.21802261456);

Jeet Sukumaran

unread,
Jul 14, 2020, 3:34:18 PM7/14/20
to Marcos Barbeitos, dendrop...@googlegroups.com
In what you have below, the root node has no length.

If it did, it would look like:

" ... 000002,Coracias_caudatus:90.21802261456):##.#####;

where "##.#####" is the length.


On 7/14/20 12:30 PM, Marcos Barbeitos wrote:
> Yes, it did. This would be the "end" of the first tree, where the
> outgroup shows up. It seems to be the case in every tree I checked. I do
> not mind sharing  the file if you'd like to run some tests. Cheers!
>
> ...
> Menura_novaehollandiae:63.178197420000004):27.039825191000002,Coracias_caudatus:90.21802261456);
>
> On Tue, Jul 14, 2020 at 4:24 PM Jeet Sukumaran <jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>> wrote:
>
> Did the root branch originally have a length?
>
> On 7/14/20 12:23 PM, Marcos Barbeitos wrote:
> > Hi Jeet! Yep, that seems to be the case! Cheers!
> >
> > On Tue, Jul 14, 2020 at 4:03 AM Jeet Sukumaran
> <jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>
> > <mailto:jeetsu...@gmail.com
> >     <mailto:dendropy-users%2Bunsu...@googlegroups.com
> <mailto:dendropy-users%252Buns...@googlegroups.com>>
> >      > <mailto:dendropy-user...@googlegroups.com
> <mailto:dendropy-users%2Bunsu...@googlegroups.com>
> >     <mailto:dendropy-users%2Bunsu...@googlegroups.com
> <mailto:dendropy-users%252Buns...@googlegroups.com>>>.
> <mailto:jsuku...@sdsu.edu <mailto:jsuku...@sdsu.edu>> (work)
> > jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>
> <mailto:jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>>

Marcos Barbeitos

unread,
Jul 14, 2020, 4:06:07 PM7/14/20
to Jeet Sukumaran, dendrop...@googlegroups.com
Yes, I misunderstood what you meant, the branch leading to the chosen outgroup has a length, but the original trees are unrooted. The trees came out of the BirdTree website, Coracias caudatus was chosen as the outgroup so we could root the trees before running ancestral state reconstruction in BayesTraits.

Jeet Sukumaran

unread,
Jul 14, 2020, 4:11:30 PM7/14/20
to Marcos Barbeitos, dendrop...@googlegroups.com
Contrary to popular practice, rooting (or re-rooting) a tree is not a
visual/cosmetic operation, but a model change.

The original edge length to be distributed between the new root edge and
the new internal branch. How do you decide this?

On 7/14/20 1:05 PM, Marcos Barbeitos wrote:
> Yes, I misunderstood what you meant, the branch leading to the chosen
> outgroup has a length, but the original trees are unrooted. The trees
> came out of the BirdTree website, Coracias caudatus was chosen as the
> outgroup so we could root the trees before running ancestral state
> reconstruction in BayesTraits.
>
> On Tue, Jul 14, 2020 at 4:34 PM Jeet Sukumaran <jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>> wrote:
>
> In what you have below, the root node has no length.
>
> If it did, it would look like:
>
> " ... 000002,Coracias_caudatus:90.21802261456):##.#####;
>
> where "##.#####" is the length.
>
>
> On 7/14/20 12:30 PM, Marcos Barbeitos wrote:
> > Yes, it did. This would be the "end" of the first tree, where the
> > outgroup shows up. It seems to be the case in every tree I
> checked. I do
> > not mind sharing  the file if you'd like to run some tests. Cheers!
> >
> > ...
> >
> Menura_novaehollandiae:63.178197420000004):27.039825191000002,Coracias_caudatus:90.21802261456);
> >
> > On Tue, Jul 14, 2020 at 4:24 PM Jeet Sukumaran
> <jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>
> >      >     <mailto:dendropy-users%2Bunsu...@googlegroups.com
> <mailto:dendropy-users%252Buns...@googlegroups.com>
> >     <mailto:dendropy-users%252Buns...@googlegroups.com
> <mailto:dendropy-users%25252Bun...@googlegroups.com>>>
> >     <mailto:dendropy-users%252Buns...@googlegroups.com
> <mailto:dendropy-users%25252Bun...@googlegroups.com>>>>.
> >     <mailto:jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com> <mailto:jeetsu...@gmail.com

Marcos Barbeitos

unread,
Jul 14, 2020, 4:20:52 PM7/14/20
to Jeet Sukumaran, dendrop...@googlegroups.com
That is a very good point! These trees are ultrametric, so I was (visually) expecting that the branch leading from the root to the outgroup should have the same length as the tree height?

If you were to open the first tree in a tree viewer such as FigTree, that is how it is represented, in its unrooted form. 

Rerooting the tree using this outgroup does change the original branch length.

The issue here is beyond "cosmetics", BayesTraits requires trees to be rooted using a single outgroup.

Jeet Sukumaran

unread,
Jul 14, 2020, 4:39:07 PM7/14/20
to Marcos Barbeitos, dendrop...@googlegroups.com
> The issue here is beyond "cosmetics", BayesTraits requires trees to be
> rooted using a single outgroup.

Yes, I know rerooting is not cosmetic. Most people treat it as if it is.
When you move the root node (or add a root node) you are making a new
statement about the tree. When you root an unrooted tree, in particular,
you are adding some new information to the tree that was not there
before. One item of information is the placement of the root node. This
you explicitly provide. But you also need to provide the edge length of
the new internal node. Most tree viewers/visualizers not only do not ask
this from you, but often give you no way to specify it. The length is
determined arbitrarily or visually. This is why, going back decades,
people routinely treat rooting/re-rooting as a simple "reconfiguration"
of the tree as opposed to a fundamental change of model (with
introduction of new information). That was what I meant by "Contrary to
popular practice, rooting (or re-rooting) a tree is not visual/cosmetic
operation". Unfortunately, this fallacy is baked into our mindset,
otherwise nobody would even attempt a rooting on any tree with
edgelengths without first asking themselves "what is the length of the
new internal branch going to be"?

The fact that you are going to be using the tree in a subsequent
analysis that takes the branch lengths as truth makes it all the more
critical that you tree rooting the tree as a statistical operation
rather than visual. This means not just rerooting tree or adding a root
node.
> > <mailto:jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>>> wrote:
> >
> >     In what you have below, the root node has no length.
> >
> >     If it did, it would look like:
> >
> >     " ... 000002,Coracias_caudatus:90.21802261456):##.#####;
> >
> >     where "##.#####" is the length.
> >
> >
> >     On 7/14/20 12:30 PM, Marcos Barbeitos wrote:
> >      > Yes, it did. This would be the "end" of the first tree,
> where the
> >      > outgroup shows up. It seems to be the case in every tree I
> >     checked. I do
> >      > not mind sharing  the file if you'd like to run some
> tests. Cheers!
> >      >
> >      > ...
> >      >
> >
>  Menura_novaehollandiae:63.178197420000004):27.039825191000002,Coracias_caudatus:90.21802261456);
> >      >
> >      > On Tue, Jul 14, 2020 at 4:24 PM Jeet Sukumaran
> >     <jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>
> <mailto:jeetsu...@gmail.com <mailto:jeetsu...@gmail.com>>
>  <mailto:dendropy-users%252Buns...@googlegroups.com
> <mailto:dendropy-users%25252Bun...@googlegroups.com>
> >     <mailto:dendropy-users%25252Bun...@googlegroups.com
> <mailto:dendropy-users%2525252Bu...@googlegroups.com>>>>
>  <mailto:dendropy-users%252Buns...@googlegroups.com
> <mailto:dendropy-users%25252Bun...@googlegroups.com>
> >     <mailto:dendropy-users%25252Bun...@googlegroups.com
> <mailto:dendropy-users%2525252Bu...@googlegroups.com>>>>>.
> >      >     <mailto:jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>
> >     <mailto:jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>> <mailto:jeetsu...@gmail.com
> <mailto:jeetsu...@gmail.com>
> >     <mailto:jeetsu...@gmail.com

Marcos Barbeitos

unread,
Jul 14, 2020, 5:11:41 PM7/14/20
to Jeet Sukumaran, dendrop...@googlegroups.com
Hmmm, I see, thanks for the email. It has become obvious that this is not a problem with Dendropy, but with my understanding of rooting. Looks like I have some reading to do! :-) Thanks again, Jeet!
Reply all
Reply to author
Forward
0 new messages