Question: how to add/update node id to a tree in Bio::Tree::Tree object
0
gravatar for sckinta
4.6 years ago by
sckinta570
United States
sckinta570 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.6k views
ADD COMMENTlink written 4.6 years ago by sckinta570
Please log in to add an answer.

Help
Access

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