[Bioperl-l] tree splice remove nodes

Janet Young jayoung at fhcrc.org
Sat Sep 12 01:11:00 UTC 2009


Hi,

I'm having a problem in a script that I'm hoping someone can help me  
figure out.  I'm using splice(-remove_id) to prune a Bio::Tree::Tree  
object, and it looks like it worked fine.

However, I'm also trying to keep a separate copy of the original  
(unpruned) tree in a different object but that second object seems to  
get pruned as well.

Here's my tree, stored in a file called testtree2.nwk:

(((A,(B,b)),C),D,E);

---------------------------------------
Here's my script:

#!/usr/bin/perl

use warnings;
use strict;
use Bio::TreeIO;

my $treeIO = new Bio::TreeIO(-file => "testtree2.nwk", - 
format=>'newick');
while (my $tree = $treeIO->next_tree() ) {

       print "\nfound a tree\n\n";
       my @originalleaves = $tree -> get_leaf_nodes();
       foreach my $originalleaf (@originalleaves) {print "original  
tree has node with id " . $originalleaf->id() . "\n";}

       my $tree2 = $tree;

       my @remove = ("D","E");
       print "\nremoving nodes @remove\n\n";

       $tree2 -> splice(-remove_id => \@remove);
       my @leaves2 = $tree2 -> get_leaf_nodes();
       foreach my $leaf2 (@leaves2) {print "after removing tree2 has  
node with id " . $leaf2->id() . "\n";}

       print "\n";

       my @originalleavesafter = $tree -> get_leaf_nodes();
       foreach my $leaf3 (@originalleavesafter) {print "after removing  
original tree has node with id " . $leaf3->id() . "\n";}

}

---------------------------------------


And here's my output:

found a tree

original tree has node with id A
original tree has node with id B
original tree has node with id b
original tree has node with id C
original tree has node with id D
original tree has node with id E

removing nodes D E

after removing tree2 has node with id A
after removing tree2 has node with id B
after removing tree2 has node with id b
after removing tree2 has node with id C

after removing original tree has node with id A
after removing original tree has node with id B
after removing original tree has node with id b
after removing original tree has node with id C


-------------------------

I want to splice the specified nodes out of $tree2 and leave $tree  
untouched, but both $tree and $tree2 seem to be affected by the splice  
operation. Am I failing to understand something about references/ 
dereferencing?   I'm not sure if I just haven't figured this out right  
or if it's a bug.  If it looks like a bug let me know and I'll post it  
to bugzilla.

thanks in advance for any advice,

Janet

-------------------------------------------------------------------

Dr. Janet Young (Trask lab)

Fred Hutchinson Cancer Research Center
1100 Fairview Avenue N., C3-168,
P.O. Box 19024, Seattle, WA 98109-1024, USA.

tel: (206) 667 1471 fax: (206) 667 6524
email: jayoung  ...at...  fhcrc.org

http://www.fhcrc.org/labs/trask/

-------------------------------------------------------------------






More information about the Bioperl-l mailing list