Question: how to add/update node id to a tree in Bio::Tree::Tree object
gravatar for sckinta
5.2 years ago by
United States
sckinta600 wrote:

I have a tree file read into a Bio::Tree::Tree object and trying to update/add to node which contains the gene name of interest. How can i do it?

Here is my code

my $treeio = Bio::TreeIO->new(-format => 'newick', -file => "$inputfile");
my $tree = $treeio->next_tree; # Bio::Tree::Tree object

my @nodesOfinterest;

foreach my $node ( grep { ! $_ -> is_Leaf } $tree -> get_nodes ) {
    next if ! $node -> ancestor ; # ignore the root node
    foreach my $child ( $node -> each_Descendent ) {
        if (grep{$child -> id eq $_} @namesOfinterest ) {
            # something should add here to update $node information 
            push @nodesOfinterest, $node;

After this, I will extract the least common ancester fromĀ @nodesOfinterest to build a subtree

my $common_acester = $tree->get_lca( -nodes => \@nodesOfinterest);

my $subtree = Bio::Tree::Tree->new(-root => $common_acester, -nodelete => 1);
perl bio::tree • 1.7k views
ADD COMMENTlink written 5.2 years ago by sckinta600
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 995 users visited in the last hour