[Bioperl-l] tree splice remove nodes

Mark A. Jensen maj at fortinbras.us
Sat Sep 12 11:37:37 UTC 2009


Done-- thanks Sendu. I made _clone alias clone, to keep 
from rocking anyone's boat. 
Janet- definitely do  $tree2 = $tree->_clone.

----- Original Message ----- 
From: "Sendu Bala" <bix at sendu.me.uk>
To: "Mark A. Jensen" <maj at fortinbras.us>
Cc: "Janet Young" <jayoung at fhcrc.org>; <bioperl-l at lists.open-bio.org>
Sent: Saturday, September 12, 2009 4:33 AM
Subject: Re: [Bioperl-l] tree splice remove nodes


> 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