Bio-MUST-Core
view release on metacpan or search on metacpan
lib/Bio/MUST/Core/Tree/Forest.pm view on Meta::CPAN
package Bio::MUST::Core::Tree::Forest;
# ABSTRACT: Collection of (bootstrap) trees
$Bio::MUST::Core::Tree::Forest::VERSION = '0.252040';
use Moose;
use namespace::autoclean;
use autodie;
use feature qw(say);
use Bio::Phylo::IO qw(parse);
use Bio::MUST::Core::Types;
use aliased 'Bio::MUST::Core::Tree';
# public array
has 'trees' => (
traits => ['Array'],
is => 'ro',
isa => 'ArrayRef[Bio::MUST::Core::Tree]',
default => sub { [] },
handles => {
count_trees => 'count',
all_trees => 'elements',
add_tree => 'push',
get_tree => 'get',
},
);
sub restore_ids {
my $self = shift;
my $mapper = shift;
$_->restore_ids($mapper) for $self->all_trees;
return;
}
sub load {
my $class = shift;
my $infile = shift;
my @trees;
# build Bio::MUST::Core::Tree object from each Bio::Phylo::Forest::Tree
my $forest = parse(-format => 'newick', -file => $infile);
while (my $tree = $forest->next) {
push @trees, Tree->new( tree => $tree );
}
return $class->new( trees => \@trees );
}
sub store {
my $self = shift;
my $outfile = shift;
open my $out, '>', $outfile;
say {$out} join "\n", map {
$_->tree->to_newick( -nodelabels => 0 ) # This might be an issue!
( run in 1.316 second using v1.01-cache-2.11-cpan-d8267643d1d )