[Bioperl-l] copying Bio::Tree::Tree objects
Jason Stajich
jason.stajich at duke.edu
Tue Dec 14 08:38:08 EST 2004
There is no deep copy (yet... feel free to write one).
Node identifiers (internal_id) are intended to be unique for all nodes
in memory.
Presumably you want to be able to refer to the same internal node in
two different trees?
Why not give them all labels and then you can use the $node->id method.
Just give all non-tip nodes a label and then write out the tree.
my $id = 1;
for my $node ( grep { ! $_->is_Leaf } $tree->get_nodes ) {
$node->id("internal_$id");
$id++;
}
my $out = Bio::TreeIO->new(-format => 'newick', -file =>
">treecopy.tre");
$out->write_tree($tree);
$out->write_tree($tree); #write it twice so you'll have two copies
undef $out;
my $in = Bio::TreeIO->new(-format => 'newick', -file => 'treecopy.tre');
my $tree1 = $in->next_tree;
my $tree2 = $in->next_tree;
Now you should have two copies of the tree.
-jason
On Dec 14, 2004, at 6:55 AM, Jon manning wrote:
> Hi to all,
>
> Is there a simple way of copying tree objects, i.e. not pass by
> reference like:
>
> $tree2 = $tree;
>
> keeping node identifiers etc the same? I want to change one copy while
> keeping the other to refer back to. I tried using TreeIO to write and
> then read in the tree, but this seems to preclude the use of the same
> node identifiers, making the comparison tricky.
>
> Thanks,
>
> Jon
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
>
--
Jason Stajich
jason.stajich at duke.edu
http://www.duke.edu/~jes12/
More information about the Bioperl-l
mailing list