Question: Removing branch support values that meet certain requirements in a newick file
0
gravatar for joran.martijn
4.9 years ago by
Sweden
joran.martijn0 wrote:

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.

ADD COMMENTlink modified 4.9 years ago • written 4.9 years ago by joran.martijn0
3
gravatar for jason
4.9 years ago by
jason160
United States
jason160 wrote:

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 COMMENTlink modified 4.9 years ago • written 4.9 years ago by jason160
0
gravatar for joran.martijn
4.9 years ago by
Sweden
joran.martijn0 wrote:

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 COMMENTlink modified 4.9 years ago • written 4.9 years ago by joran.martijn0
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: 760 users visited in the last hour