[ensembl-dev] protein tree id and tagvalue

Matthieu Muffato muffato at ebi.ac.uk
Wed Jul 4 14:00:33 BST 2012

On 04/07/12 13:52, Moretti Sébastien wrote:
>>> So now I use GeneTree adaptor, this way, with tree_type = tree (not
>>> clusters), and member_type = protein (not ncrna):
>>> my $tree_adaptor = $reg->get_adaptor('Multi', 'compara', 'GeneTree');
>>> my @children = @{$tree_adaptor->fetch_all(-tree_type => 'tree',
>>> -member_type => 'protein')};
>>> for my $tree (@children){
>>>     my $node_id   = $tree->root->node_id;
>>>     my $tax_level = $tree->root->get_tagvalue('taxon_name');
>>> }
>>> Now my script crashes later on.
>>> I check the tree root taxon_name to see if this is the taxonomic level
>>> I expect. If this is Bilateria instead of Euteleostomi I want to
>>> navigate in the tree until I reach a Euteleostomi node.
>>> I used a recursive function that use my $tree object with the children
>>> method
>>> $tree->children();
>>> But children is not a method of Bio::EnsEMBL::Compara::GeneTree
>>> and $tree->root->children() does not look to do the right thing.
>>> How could I do that ?
>> children() is indeed not defined in GeneTree but in GeneTreeNode. It
>> returns an arrayref of GeneTreeNode. You can call node_id(),
>> get_tagvalue(...) on each of them
> I cannot make it work.
> $tree is a phylogenetic tree object with a Bilateria root (e.g.
> ENSGT00390000000002) defined with a GeneTree adaptor.
> If I want to iterate on children nodes of that tree, starting from root,
> I use
> my @children = @{$tree->root->sorted_children()}; # or children()
> But then it iterates (recursively) endlessly, with a "Deep recursion on
> subroutine" message at some point. I guess the root method is not the
> right one in the following for loop because I get the taxon_name of the
> root of the tree, not the taxon_name of child nodes.
> for my $subtree ( @children ){
>      $subtree->root->get_tagvalue('taxon_name');
> }
> How could I manage that ?

"->root", called on any node of a tree, will return the root node of 
that tree. That's why you keep getting the taxon_name of the root in 
your example. Simply remove "->root" and directly use 

If the sub-tree is not in the expected clade, you can recursively call 


> Regards
> Sébastien
>>> An additional question:
>>> Now the right way to use release_tree()
>>> is $tree->root->release_tree; ?
>> Yes, you can still use GeneTreeNode::release_tree(). I have not found
>> yet a nice (transparent) way of cleaning up the memory
>> Regards,
>> Matthieu

Matthieu Muffato, Ph.D.
Ensembl Developer - Comparative Genomics
European Bioinformatics Institute (EMBL-EBI)
Wellcome Trust Genome Campus, Hinxton
Cambridge, CB10 1SD, United Kingdom

More information about the Dev mailing list