[Bioperl-l] tree splice remove nodes

Chris Fields cjfields at illinois.edu
Sat Sep 12 04:12:06 UTC 2009


On Sep 11, 2009, at 9:00 PM, 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.

You can rewind the filehandle if it's seekable:

my $fh = $treeio->_fh;
seek($fh,0,0); # or something like that...

Don't use sysseek (doesn't work with buffered IO).

>  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
>
> use Clone qw(clone);
> ....
> $tree2 = clone($tree);
> ...
>
> hope this helps- cheers MAJ

This normally works with bioperl objects, just not sure about Tree  
(might be worth testing out).

chris



More information about the Bioperl-l mailing list