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);