[Bioperl-l] Bio::Tree::IO "Collapse" function

Jason Stajich jason.stajich at duke.edu
Sat Jun 3 15:10:51 UTC 2006


The bootstrap is stored as the node ID because that is a limitation  
of the newick format, there isn't a formal way to distinguish  
internal IDs from bootstraps.  There are several differents ways that  
programs encode the internal ID and a bootstrap value in that one  
slot - we try and parse it out if the the bootstrap is stored in  
brackets like INTERNALID[BOOTSTRAP].

Formats like nhx explicitly solve this problem, but most programs  
only use the simple newick.  if you know your data it is a simple  
procedure to move the internal ID data into the bootstrap slot.

in terms of ignoreoverwrite you just need to send in a second  
parameter which is true
$node->add_Descendent($childnode, 1);

-jason


On May 31, 2006, at 10:06 AM, Lucia Peixoto wrote:

> Hi
> Thanks
> a couple more questions
> why is the bootstrap value stored as the node id? Is that right?
>
> also, in the add_descendant method, how do you set the  
> $ignoreoverwrite
> parameter to true?
>
> Lucia
>
> Quoting Jason Stajich <jason.stajich at duke.edu>:
>
>> 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
>>
>>
>
>
> Lucia Peixoto
> Department of Biology,SAS
> University of Pennsylvania

--
Jason Stajich
Duke University
http://www.duke.edu/~jes12





More information about the Bioperl-l mailing list