Dear Rutger Vos,
I am exploring the package Bio::Phylo for the manipulation of my
phylogenetic trees. To understand how to prune a tree based on a
specific regular expression and write the output to newick format, I
used some examples you provided.
use Bio::Phylo::IO 'parse';
use strict;
my
$string="((A:0.33139,B:0.29208):0.04409,(C:0.28550,D:0.28440):0.03647,(E:0.35068,F:0.38974):0.03419);";
my $tree = parse(
-format => 'newick',
-string => $string
)->first;
my $tips = $tree->get_by_regular_expression(
-value => 'get_name',
-match => qr/^(?:A|B)$/,
);
$tree->keep_tips($tips);
print $tree->to_newick;
When I try to run the above script I get the message "Can't call
method "get_parent" on an undefined value at
/usr/local/perl/5.8.8/lib/site_perl/5.8.8/Bio/Phylo/Forest/Tree.pm"
As you mentioned, $tips is an array reference holding node 'A' and
node 'B' and keep_tips accepts an array ref of taxon names. I try to
find out what might be going on, without success, but maybe I am not
getting something about the output of get_by_regular_expression.
@tips=('A,'B');
$tree->keep_tips(\@tips);
print $tree->to_newick;
If instead of using get_by_regular_expression, I simply write as above
it works fine.
Best regards
Sandra Botelho