Subject: | Bug in Bio::NEXUS::Node.pm |
Date: | Wed, 08 Jul 2009 17:28:50 +0100 |
To: | bug-Bio-NEXUS [...] rt.cpan.org |
From: | Jon Hill <jon.hill [...] imperial.ac.uk> |
Hi,
Spotted this bug whilst trying to remove taxa that had odd symbols in
their name, e.g. Eurostopodidae+Steatornithidae
Essentially, the reg exp in prune() (line 867) fails in such cases and
the taxa are removed even if they shouldn't be.
Attached is an example test case.
To fix:
$name = quotemeta $name
before the reg exp.
A diff is:
867,868d866
< # escape +
< $name = quotemeta $name;
I'm currently writing a Perl module which uses Bio::NEXUS very heavily.
I plan to distribute my modified Bio::NEXUS (with the above fix) along
with my module, which is also GPL. Once a fix has been issued, this will
no longer be necessary. Hope that's OK.
J.
--
Jon Hill
AMCG, Earth Science and Engineering,
Imperial College London, SW7 2AZ.
Phone: 020 75941351
Mob: 07748254812
#!/usr/bin/perl -w
# test case to demosntrate bug in Bio::NEXUS
use Bio::NEXUS;
use Test::More tests =>1;
# apologies for the slightly convlouted example - it's using code snippets
# from my own module which have to handle more complex things :)
#
#
# We're going to try and remove taxa_4, but 'taxa_n+taxa_2' will
# dissappear too.
my @quote_taxa_tree;
$quote_taxa_tree = "(taxa_1, 'taxa_n+taxa_2', 'taxa_3=taxa5', taxa_4)";
# set up nexus object
my $nexus_obj = new Bio::NEXUS();
my $trees_block = new Bio::NEXUS::TreesBlock('trees');
$trees_block->add_tree_from_newick( $quote_taxa_tree , "tree_1" );
$nexus_obj->add_block($trees_block);
$nexus_obj->set_taxablock();
# remove taxa
$nexus_obj = $nexus_obj->exclude_otus( ["taxa_4"] );
# get out trees
my @trees;
# generate new newick string
# loop over all trees found in file and return
foreach my $block ( @{ $nexus_obj->get_blocks() } ) {
my $type = $block->{'type'};
if ( $type eq "trees" ) {
foreach my $tree ( @{ $block->get_trees() } ) {
# add to array after stripping off ;
push( @trees,substr( $tree->as_string_inodes_nameless(), 0, -1 ) );
}
}
}
$answer = "(taxa_1,'taxa_n+taxa_2','taxa_3=taxa5')";
is ($trees[0], $answer, "Removed correct taxa");