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.212650';
4 17     17   138 use Moose;
  17         42  
  17         151  
5 17     17   123314 use namespace::autoclean;
  17         47  
  17         180  
6              
7 17     17   1789 use autodie;
  17         55  
  17         203  
8 17     17   95709 use feature qw(say);
  17         45  
  17         1774  
9              
10 17     17   162 use Bio::Phylo::IO qw(parse);
  17         46  
  17         1181  
11              
12 17     17   141 use Bio::MUST::Core::Types;
  17         66  
  17         581  
13 17     17   116 use aliased 'Bio::MUST::Core::Tree';
  17         46  
  17         147  
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 11 my $self = shift;
34 1         3 my $mapper = shift;
35              
36 1         51 $_->restore_ids($mapper) for $self->all_trees;
37              
38 1         6 return;
39             }
40              
41              
42             sub load {
43 1     1 1 469 my $class = shift;
44 1         2 my $infile = shift;
45              
46 1         4 my @trees;
47              
48             # build Bio::MUST::Core::Tree object from each Bio::Phylo::Forest::Tree
49 1         9 my $forest = parse(-format => 'newick', -file => $infile);
50 1         2226620 while (my $tree = $forest->next) {
51 10         563 push @trees, Tree->new( tree => $tree );
52             }
53              
54 1         58 return $class->new( trees => \@trees );
55             }
56              
57              
58             sub store {
59 2     2 1 20 my $self = shift;
60 2         6 my $outfile = shift;
61              
62 2         19 open my $out, '>', $outfile;
63              
64 2         85 say {$out} join "\n", map {
65 2         2875 $_->tree->to_newick( -nodelabels => 0 ) # This might be an issue!
  20         614636  
66             } $self->all_trees;
67              
68 2         67832 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.212650
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