[Bioperl-l] tree splice remove nodes

Sendu Bala bix at sendu.me.uk
Sat Sep 12 08:33:22 UTC 2009


Mark A. Jensen wrote:
> Hi Janet-
> The trouble here is that $tree2 = $tree
> doesn't create an independent copy of the entire
> tree data structure. So, $tree2 and $tree
> essentially point to the same thing. The easiest way to get two 
> independent copies is probably to read the file twice:
> 
> $treeIO = new Bio::TreeIO(-file => "testtree2.nwk", -format=>'newick');
> $tree = $treeIO->next_tree;
> $treeIO = new Bio::TreeIO(-file => "testtree2.nwk", -format=>'newick');
> $tree2 = $treeIO->next tree;
> 
> which will create two copies. This is a little kludgy, but 
> unfortunately, there doesn't seem to be any easy way to rewind the 
> TreeIO object.
> When you want a copy of a complex object, generally you need to "clone" 
> it, and there are variety of modules
> you can use to create clones. [It's probably worth adding a clone() 
> method to TreeFunctionsI--maybe I'll do that.]
> Get the module Clone from CPAN and do

 From my comments in Bio/Tree/TreeFunctionsI.pm:

Clone.pm clone() seg faults and fails to make the clone, whilst Storable 
dclone needs $self->{_root_cleanup_methods} deleted (code ref) and seg 
faults at end of script.

TreeFunctionsI.pm already has the _clone() method. I suppose you could 
add some POD for it, rename it clone() and update the methods that call 
the private method to call the public version instead, Mark.

Janet: just clone your tree object with:
my $tree2 = $tree->_clone();



More information about the Bioperl-l mailing list