rvosa / bio-phylo

Bio::Phylo - Phyloinformatic analysis using Perl
http://search.cpan.org/dist/Bio-Phylo
GNU General Public License v3.0
16 stars 6 forks source link

Bug in $node->get_sisters method #9

Closed fangly closed 11 years ago

fangly commented 11 years ago

Hi Rutger,

This code,

use strict;
use warnings;
use Bio::Phylo::IO;
my $newick = '(F:0.1)A;';
my $tree = Bio::Phylo::IO->parse( -string => $newick, -format => 'newick' )->first;
my $node = $tree->get_by_name('A');
my @sisters = @{$node->get_sisters};

generates the following error:

Can't call method "get_children" on an undefined value at /usr/local/share/perl/5.14.2/Bio/Phylo/Forest/NodeRole.pm line 758, <DATA> line 1.

I found that to fix this issue, the get_sisters() method of Bio::Phylo::Forest::Node,

    sub get_sisters {
        my $self    = shift;
        my $sisters = $self->get_parent->get_children;
        return $sisters;
    }

should be replaced by something like:

    sub get_sisters {
        my $self = shift;
        my $sisters;
        my $parent = $self->get_parent;
        if ($parent) {
            $sisters = $parent->get_children;
        }
        return $sisters;
    }

Best,

Florent

rvosa commented 11 years ago

Fixed, thanks! See: https://github.com/rvosa/bio-phylo/commit/0029d2c06957341f4aa7df77fde199442ef2977c