patch nointernalids for internal nodes Was: [Bioperl-l] Bio::Tree newick and internal nodes

Albert Vilella avilella at ub.edu
Wed Nov 16 06:44:41 EST 2005


I have added a (dummy) /nointernalids/ bootstrap_style 
flag in newick.pm that, if chosen, wont print the ids of internal nodes,
having or not having branch_length defined:

> ((Tkodak:0.890176,Pfurio:0.256021,(Pabyss:0.203701,Phorik:0.327239)6:0.000000)5);
> 
> E.g.:
> 
> (Tkodak:0.890176,Pfurio:0.256021,(Pabyss:0.203701,Phorik:0.327239):0.000000);

----

patch:

--- newick.pm.~1.30.~   2005-10-24 15:01:40.000000000 +0200
+++ newick.pm   2005-11-16 12:38:17.000000000 +0100
@@ -234,10 +234,10 @@
    foreach my $tree( @trees ) {
        my @data = _write_tree_Helper($tree->get_root_node,
                                     $self->bootstrap_style);
-       #if($data[-1] !~ /\)$/ ) {
-       #   $data[0] = "(".$data[0];
-       #   $data[-1] .= ")";
-       #}
+       if($data[-1] !~ /\)$/ ) {
+          $data[0] = "(".$data[0];
+          $data[-1] .= ")";
+       }
        $self->_print(join(',', @data), ";\n");
    }
    $self->flush if $self->_flush_on_write && defined $self->_fh;
@@ -280,7 +280,10 @@
            if( ! defined $bl || ! length($bl) ||
                ($style && $style =~ /nobranchlength/i) ) {

-               if( defined $id || defined $bs ) {
+                if ($style && $style =~ /nointernalids/i) {
+                    # do not print id even if no branchlength is
+                    # defined
+                } elsif( defined $id || defined $bs ) {
                    $data[-1] .= defined $bs ? $bs : $id;
                }
            } elsif( $style =~ /molphy/i ) {
@@ -295,6 +298,15 @@
                if( defined $bs ) {
                    $data[-1] .= "[$bs]";
                }
+           } elsif( $style =~ /nointernalids/i ) {
+               if( $bl =~ /\#/) {
+                   $data[-1] .= $bl;
+               } else {
+                   $data[-1] .= ":$bl";
+               }
+               if( defined $bs ) {
+                   $data[-1] .= "[$bs]";
+               }
            } else {
                # traditional style of
                # ((A:1,B:2)81:3);   where 3 is internal node branch length
@@ -373,8 +385,8 @@
     my $val = shift;
     if( defined $val ) {

-       if( $val !~ /^nobranchlength|molphy|traditional/i ) {
-           $self->warn("requested an unknown bootstrap style $val, expect one of nobranchlength,molphy,traditional, not updating value.  Default is $DefaultBootstrapStyle\n");
+       if( $val !~ /^nobranchlength|molphy|traditional|nointernalids/i ) {
+           $self->warn("requested an unknown bootstrap style $val, expect one of nobranchlength,molphy,traditional,nointernalids, not updating value.  Default is $DefaultBootstrapStyle\n");
        } else {
            $self->{'_bootstrap_style'} = $val;
        }



More information about the Bioperl-l mailing list