Removing branch support values that meet certain requirements in a newick file
2
0
Entering edit mode
10.6 years ago

Hi!

I have a tree file in newick format that looks a bit like this:

(((A:0.5,B:0.5)30:0.3),((((C:0.3,D:0.6)80:0.4),F:0.3)100:0.2));

All the numbers between 0 and 1 are branch lengths.

The 30, 80, and 100 are bootstrap support values.

What I like to do is with a command or script or program, delete all bootstrap support values lower then 70. Thus, the resulting newick tree will look like.

(((A:0.5,B:0.5):0.3),((((C:0.3,D:0.6)80:0.4),F:0.3)100:0.2));

I feel like it should be quiet easy, but I simply can't get it.

newick bootstrap posterior probability perl • 4.3k views
ADD COMMENT
3
Entering edit mode
10.6 years ago
jason ▴ 160

use Bio::TreeIO; 
use strict;

my $in = Bio::TreeIO->new(-format => 'newick', -fh => \*DATA); 
# replace above with this to open a file
# my $in = Bio::TreeIO->new(-format => 'newick', -file => "mytree.tre");

# see Bio::TreeIO on how you can write directly to a file, otherwise to STDOUT by default

my $out = Bio::TreeIO->new(-format => 'newick');
while( my $tree = $in->next_tree ) {
# get all the internal nodes (i.e. those which are not leaf nodes)

 for my $node ( grep { ! $_->is_Leaf } $tree->get_nodes ) {
# bootstrap is stored in the id field for newick trees since there is no other defined slot  
  if($node->id < 70 ) {
    $node->id('');  
   }
 }
 $out->write_tree($tree);
}
__DATA__
(((A:0.5,B:0.5)30:0.3),((((C:0.3,D:0.6)80:0.4),F:0.3)100:0.2));
ADD COMMENT
0
Entering edit mode
10.6 years ago

Awesome, it seems to do the trick! But for some reason I still commonly get error / warning messages like

Use of uninitialized value in numeric lt (<) at script.pl line 28, <GEN0> line 1.

Line 28 corresponds to the if($node->id < 70 ) { in my version of the script

ADD COMMENT

Login before adding your answer.

Traffic: 1609 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