[Bioperl-l] Question about Bio::TreeIO

iain wallace iain.wallace at ucd.ie
Sun Dec 21 18:39:18 EST 2003


Hi all, 

I am trying to write a function that can read in a tree, go through 
each of the nodes, and tell me how many leaves are a descendent of that 
node.
e.g the root node would be an ancestor to all the leaves.

My code simply looks at all the nodes, and calls get_all_descendents(), 
and if any of the descendents is a leaf the count is incremented by 
one. However, my code below doesn't seem to work, as it says some nodes 
have no descendents which are leaves.

Is there a flaw in my logic, or is my code simply wrong???

Before I go, there is one other question i would like to ask, how can i 
pass a bioperl object (like a node) in this case to a function? I tried 
passing by reference function(\$node) but that wouldn't work for me...

Any help would be great, Thanks 
Iain 



 foreach my $node ( $rootnode->get_all_Descendents() ) {

        $count=0;
        foreach my $newnode ( $node-> get_all_Descendents()){
                if($newnode->is_Leaf){
                $count++;
                }
        }

        $nodeid=$node->internal_id;
        $node->add_tag_value($count,1);
        if ($count==0){
        print "$nodeid has no leaves....";
        }
    }





More information about the Bioperl-l mailing list