Question: How Can I Label Internal Branches Of A Phylogenetic Tree?
4
gravatar for John
8.7 years ago by
John770
John770 wrote:

I just want to be able to input a tree to a program and have it output the same tree but with numbers written on the internal branches, so that I can identify them easily. e.g. branch 1, 2 etc.

Thanks, John

phylogenetics tree • 12k views
ADD COMMENTlink written 8.7 years ago by John770
1

the idea of labeling edges is not exactly a phylogenetic need, but a descriptive aid for displaying trees with lots of information in it. it would be really useful for me if I could write comments on certain edges of a tree we use to give as reference, since there's no automatic way of doing so (right now we are forced to export the tree as an image and then manually edit such image to write notes on it).

ADD REPLYlink written 8.7 years ago by Jorge Amigo11k
1

Newick allows node labels. If you want edge labels, i.e. separate from node labels, you can use NeXML. Here is an example file with both node labels and edge labels.

ADD REPLYlink modified 10 weeks ago by RamRS24k • written 8.6 years ago by Rvosa570

Which file format do you use?

ADD REPLYlink written 8.7 years ago by Lars Juhl Jensen11k

I haven't found any format that allows this, Lars. in fact I've discussed this on a similar post, stating that the only thing I found related to branch labelling was storing confidence values in phyloxml format, although this is not perfect (confidence values are limited to double values, but strings are not allowed). any light on this matter will definitely be of great help to me too.

ADD REPLYlink written 8.7 years ago by Jorge Amigo11k

branches is confusing, should use 'nodes' and 'edges' instead, so you want to put a label on the edges? Why not just label the nodes, that would result in the same outcome because in a tree, the edges are often only modeled implicitly.

ADD REPLYlink written 8.7 years ago by Michael Dondrup46k
5
gravatar for jhc
8.6 years ago by
jhc2.8k
Spain
jhc2.8k wrote:

The ETE package (Python language) allows for tree node annotation using the extended newick format.

from ete2 import Tree
tree = Tree('(((A,B),C),D);')

edge = 0
for node in tree.traverse():
   if not node.is_leaf():
      node.name = "NODE_%d" %edge
      edge += 1

print tree.write(format=8)
#
# (((A,B)NODE_2,C)NODE_1,D);
#

Or, if you want to add more information to the nodes:

from ete2 import Tree
tree = Tree('(((A,B),C),D);')

edge = 0
for node in tree.traverse():
   if not node.is_leaf():
      node.add_feature("label", "NODE_%d" %edge )
      node.add_feature("confidence", 1.0 )
      edge += 1

print tree.write(format=9, features=["label", "confidence"])
#
# (((A,B)[&&NHX:label=node_2:confidence=1.0],C)[&&NHX:label=node_1:confidence=1.0],D)[&&NHX:label=node_0:confidence=1.0];
#
ADD COMMENTlink modified 10 weeks ago by RamRS24k • written 8.6 years ago by jhc2.8k
2
gravatar for Michael Dondrup
8.7 years ago by
Bergen, Norway
Michael Dondrup46k wrote:

Newick 'format' allows this: http://en.wikipedia.org/wiki/Newick_format See also: http://evolution.genetics.washington.edu/phylip/newicktree.html

For example:

((raccoon:19.19959,bear:6.80041)InnerNode1:0.84600,((sea_lion:11.99700, seal:12.00300)InnerNode2:7.52973,((monkey:100.85930,cat:47.14069):20.59201, weasel:18.87953):2.09460):3.87382,dog:25.46154);

There was a similar question about a tree-viewer here and I tested with the above tree with Epos and it worked.

ADD COMMENTlink modified 10 weeks ago by RamRS24k • written 8.7 years ago by Michael Dondrup46k

sorry Michael, but I don't see the internal branches labelling on your example. end branches are appropriately labeled, but not internal ones. or is it a problem of the viewer? which one are you using to see internal branches (not nodes) labels?

ADD REPLYlink written 8.7 years ago by Jorge Amigo11k

Er, yeah that's true! I didn't see the difference between 'branches' (edges would be the correct term and should be used instead of branches), inner nodes, and leaves. That was a bit confusing. However, it doesn't really matter, I think we should better label the inner nodes instead of the edges, because the edges are only implicitly modeled by most formats. I used Epos

ADD REPLYlink modified 10 weeks ago by RamRS24k • written 8.7 years ago by Michael Dondrup46k
1
gravatar for Rvosa
8.6 years ago by
Rvosa570
Leiden, the Netherlands
Rvosa570 wrote:

This can be done easily using Bio::Phylo:

 #!/usr/bin/perl
 use strict;
 use Bio::Phylo::IO 'parse';

 my $newick = '(((A,B),C),D);';
 my $tree = parse( '-format' => 'newick', '-string' => $newick )->first;
 my $counter = 1;

 $tree->visit( 
    sub {
        my $node = shift;
        $node->set_name( $counter++ ) if $node->is_internal;
    } 
 );

 print $tree->to_newick( '-nodelabels' => 1 );
ADD COMMENTlink modified 10 weeks ago by RamRS24k • written 8.6 years ago by Rvosa570

This produces (((A,B)3,C)2,D)1; by the way.

ADD REPLYlink written 8.6 years ago by Rvosa570
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1423 users visited in the last hour