This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to add/update node id to a tree in Bio::Tree::Tree object

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

0 answers

No answers yet.

Log in to answer this question.