File Coverage

blib/lib/Bio/MUST/Core/Tree/Forest.pm
Criterion Covered Total %
statement 39 39 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 52 52 100.0


line stmt bran cond sub pod time code
1             package Bio::MUST::Core::Tree::Forest;
2             # ABSTRACT: Collection of (bootstrap) trees
3             $Bio::MUST::Core::Tree::Forest::VERSION = '0.212530';
4 17     17   146 use Moose;
  17         42  
  17         164  
5 17     17   122822 use namespace::autoclean;
  17         43  
  17         226  
6              
7 17     17   1962 use autodie;
  17         46  
  17         187  
8 17     17   96292 use feature qw(say);
  17         43  
  17         1815  
9              
10 17     17   155 use Bio::Phylo::IO qw(parse);
  17         62  
  17         1281  
11              
12 17     17   130 use Bio::MUST::Core::Types;
  17         40  
  17         623  
13 17     17   111 use aliased 'Bio::MUST::Core::Tree';
  17         58  
  17         158  
14              
15              
16             # public array
17             has 'trees' => (
18             traits => ['Array'],
19             is => 'ro',
20             isa => 'ArrayRef[Bio::MUST::Core::Tree]',
21             default => sub { [] },
22             handles => {
23             count_trees => 'count',
24             all_trees => 'elements',
25             add_tree => 'push',
26             get_tree => 'get',
27             },
28             );
29              
30              
31              
32             sub restore_ids {
33 1     1 1 12 my $self = shift;
34 1         3 my $mapper = shift;
35              
36 1         48 $_->restore_ids($mapper) for $self->all_trees;
37              
38 1         10 return;
39             }
40              
41              
42             sub load {
43 1     1 1 600 my $class = shift;
44 1         4 my $infile = shift;
45              
46 1         3 my @trees;
47              
48             # build Bio::MUST::Core::Tree object from each Bio::Phylo::Forest::Tree
49 1         8 my $forest = parse(-format => 'newick', -file => $infile);
50 1         2233226 while (my $tree = $forest->next) {
51 10         538 push @trees, Tree->new( tree => $tree );
52             }
53              
54 1         57 return $class->new( trees => \@trees );
55             }
56              
57              
58             sub store {
59 2     2 1 9 my $self = shift;
60 2         4 my $outfile = shift;
61              
62 2         16 open my $out, '>', $outfile;
63              
64 2         98 say {$out} join "\n", map {
65 2         2937 $_->tree->to_newick( -nodelabels => 0 ) # This might be an issue!
  20         618359  
66             } $self->all_trees;
67              
68 2         68198 return;
69             }
70              
71             __PACKAGE__->meta->make_immutable;
72             1;
73              
74             __END__
75              
76             =pod
77              
78             =head1 NAME
79              
80             Bio::MUST::Core::Tree::Forest - Collection of (bootstrap) trees
81              
82             =head1 VERSION
83              
84             version 0.212530
85              
86             =head1 SYNOPSIS
87              
88             # TODO
89              
90             =head1 DESCRIPTION
91              
92             # TODO
93              
94             =head1 METHODS
95              
96             =head2 restore_ids
97              
98             =head2 load
99              
100             =head2 store
101              
102             =head1 AUTHOR
103              
104             Denis BAURAIN <denis.baurain@uliege.be>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
109              
110             This is free software; you can redistribute it and/or modify it under
111             the same terms as the Perl 5 programming language system itself.
112              
113             =cut