[Bioperl-l] Bio::Tree::IO "Collapse" function
Jason Stajich
jason.stajich at duke.edu
Tue May 30 20:30:56 UTC 2006
you need to special case the root - it won't have an ancestor. just
protect the my $parent = $node->ancestor with an if statement as I
did below
On May 30, 2006, at 4:11 PM, Lucia Peixoto wrote:
> Hi
> OK that was silly, but what I have in my code is what you just wrote
> But the problem is that if I write
>
> $parent->add_Descendent($child)
>
> it tells me that I am calling the method "ass_Descendent" on an
> undefined value
> (but I did define $parent before??)
>
> So here it goes the code so far:
>
> use Bio::TreeIO;
> my $in = new Bio::TreeIO(-file => 'Test2.tre',
> -format => 'newick');
> my $out = new Bio::TreeIO(-file => '>mytree.out',
> -format => 'newick');
> while( my $tree = $in->next_tree ) {
> foreach my $node ( grep { ! $_->is_Leaf() } $tree->get_nodes() ) {
> my $bootstrap=$node->_creation_id;
>
> if ($bootstrap < 70 ){
> >>> if( my $parent = $node->ancestor ) {
> my @children=$node->get_all_Descendents;
> foreach my $child (@children){
> $parent->add_Descendent($child);
> }
}
>
> ........
>
> eventually I'll add (once I assigned the children to the parent
> succesfully):
> $tree->remove_Node($node);
>
> }
> }
> $out->write_tree($tree);
> }
>
> Quoting aaron.j.mackey at gsk.com:
>
>>> foreach $child (@children){
>>> $parent=add_Descendent->$child;
>>> }
>>
>> I think what you want is $parent->add_Descendent($child)
>>
>> -Aaron
>>
>
>
> Lucia Peixoto
> Department of Biology,SAS
> University of Pennsylvania
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
--
Jason Stajich
Duke University
http://www.duke.edu/~jes12
More information about the Bioperl-l
mailing list