How Can I Label Internal Branches Of A Phylogenetic Tree?
3
4
Entering edit mode
13.7 years ago
John ▴ 790

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 • 18k views
ADD COMMENT
1
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

Which file format do you use?

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
5
Entering edit mode
13.6 years ago
jhc ★ 3.0k

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 COMMENT
2
Entering edit mode
13.7 years ago
Michael 55k

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode
13.7 years ago
Rvosa ▴ 580

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 COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1966 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6