how to add/update node id to a tree in Bio::Tree::Tree object
0
0
Entering edit mode
8.4 years ago
sckinta ▴ 730

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 ancestor 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 • 2.3k views
ADD COMMENT

Login before adding your answer.

Traffic: 2457 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6