xela07 has asked for the wisdom of the Perl Monks concerning the following question:

My question should be simple. I am looking to remove nodes from a phylogenetic tree. The splice function in bioperl should presumably take both the node ids or the node pointers. I have tried to include or and not include the root, yet I cannot get this function work. At first I created an array of nodes that I wanted to keep, but I have since reverted to trying to keep all the nodes and just trying to get the splice function to work.

Any help would be greatly appreciated.
Thank you!

#!/usr/bin/env perl + use strict; use warnings; use Bio::TreeIO; use Bio::Tree::TreeFunctionsI; use Bio::Tree::Tree; use Data::Dumper; use Bio::Seq; use Bio::SeqIO; use Bio::Tree::Node; my $usage = "usage: $0 treeFile \n"; my $treeFile = $ARGV[0] or die $usage; my @stored; my $treeio = new Bio::TreeIO('-format' => 'newick', '-file' => $treeFile); my $tree = $treeio->next_tree(); my $root_node = $tree->get_root_node; my @nodes = $tree->get_nodes(); #push (@nodes, $root_node); $tree->splice(-keep_node => \@nodes); exit(0);

I get the following error:
--------------------- WARNING ---------------------
MSG: Requested to remove everything except certain nodes, but those nodes were not found; doing nothing instead
---------------------------------------------------

When I just print the node ids, it works fine and I can get the node ids or the pointers:

my $tree = $treeio->next_tree(); my $root_node = $tree->get_root_node; my @nodes = $tree->get_nodes(); foreach my $my_node (@nodes){ print $my_node->id(); print "\n"; }

Replies are listed 'Best First'.
Re: Splice Function for Bioperl Tree editing
by Khen1950fx (Canon) on Apr 11, 2013 at 08:06 UTC
    You were close. Try this very simplified example to get rid of the warnings:
    #!/usr/bin/perl -l use strict; use warnings; use Data::Dumper::Concise; use Bio::TreeIO; use Bio::Tree::TreeFunctionsI; my $usage = "usage: $0 treeFile \n"; my $treeFile = $ARGV[0] or die $usage; my $in = Bio::TreeIO->new( -format => 'newick', -file => $treeFile, ); my $tree = $in->next_tree; my @nodes = $tree->find_node(-id => 'node1'); $tree->splice(-remove_id => [0], -keep_id => [1]); print Dumper( $in ); exit(0);
Re: Splice Function for Bioperl Tree editing
by Don Coyote (Hermit) on Apr 11, 2013 at 08:15 UTC

    Did you try using the id removal syntax first?

    $tree->splice(-remove_id => \@nodeidlist);
Re: Splice Function for Bioperl Tree editing
by Anonymous Monk on Apr 11, 2013 at 03:22 UTC

    I get the following error:

    Its a warning, and a pretty good one -- you aren't removing anything from the tree, you're keeping everything -- are you sure you want to do that (do nothing)?