File Coverage

blib/lib/Bio/Phylo/Taxa/TaxaLinker.pm
Criterion Covered Total %
statement 33 42 78.5
branch 2 4 50.0
condition 2 3 66.6
subroutine 10 13 76.9
pod 5 5 100.0
total 52 67 77.6


line stmt bran cond sub pod time code
1             package Bio::Phylo::Taxa::TaxaLinker;
2 40     40   298 use Bio::Phylo;
  40         88  
  40         256  
3 40     40   200 use Bio::Phylo::Mediators::TaxaMediator;
  40         74  
  40         1031  
4 40     40   182 use Bio::Phylo::Util::Exceptions 'throw';
  40         75  
  40         1875  
5 40     40   213 use Bio::Phylo::Util::CONSTANT qw'_TAXA_ looks_like_object';
  40         79  
  40         1803  
6 40     40   210 use strict;
  40         79  
  40         800  
7 40     40   194 use warnings;
  40         80  
  40         5718  
8             my $logger = Bio::Phylo->get_logger;
9             my $mediator = 'Bio::Phylo::Mediators::TaxaMediator';
10             my $TYPE_CONSTANT = _TAXA_;
11              
12             =head1 NAME
13              
14             Bio::Phylo::Taxa::TaxaLinker - Superclass for objects that link to taxa objects
15              
16             =head1 SYNOPSIS
17              
18             use Bio::Phylo::Factory;
19             my $fac = Bio::Phylo::Factory->new;
20              
21             my $matrix = $fac->create_matrix;
22             my $taxa = $fac->create_taxa;
23              
24             if ( $matrix->isa('Bio::Phylo::Taxa::TaxaLinker') ) {
25             $matrix->set_taxa( $taxa );
26             }
27              
28             =head1 DESCRIPTION
29              
30             This module is a superclass for objects that link to L<Bio::Phylo::Taxa> objects.
31              
32             =head1 METHODS
33              
34             =head2 MUTATORS
35              
36             =over
37              
38             =item set_taxa()
39              
40             Associates invocant with Bio::Phylo::Taxa argument.
41              
42             Type : Mutator
43             Title : set_taxa
44             Usage : $obj->set_taxa( $taxa );
45             Function: Links the invocant object
46             to a taxa object.
47             Returns : Modified $obj
48             Args : A Bio::Phylo::Taxa object.
49              
50             =cut
51              
52             sub set_taxa : Clonable DeepClonable {
53 56     56 1 131 my ( $self, $taxa ) = @_;
54 56 100 66     210 if ( $taxa and looks_like_object $taxa, $TYPE_CONSTANT ) {
55 52         249 $logger->info("setting taxa '$taxa'");
56 52         164 $mediator->set_link(
57             '-one' => $taxa,
58             '-many' => $self,
59             );
60             }
61             else {
62 4         13 $logger->info("re-setting taxa link");
63 4         15 $mediator->remove_link( '-many' => $self );
64             }
65 56         198 $self->check_taxa;
66 56         110 return $self;
67 40     40   261 }
  40         84  
  40         219  
68              
69             =item unset_taxa()
70              
71             Removes association between invocant and Bio::Phylo::Taxa object.
72              
73             Type : Mutator
74             Title : unset_taxa
75             Usage : $obj->unset_taxa();
76             Function: Removes the link between invocant object and taxa
77             Returns : Modified $obj
78             Args : NONE
79              
80             =cut
81              
82             sub unset_taxa {
83 0     0 1 0 my $self = shift;
84 0         0 $logger->info("unsetting taxa");
85 0         0 $self->set_taxa();
86 0         0 return $self;
87             }
88              
89             =back
90              
91             =head2 ACCESSORS
92              
93             =over
94              
95             =item get_taxa()
96              
97             Retrieves association between invocant and Bio::Phylo::Taxa object.
98              
99             Type : Accessor
100             Title : get_taxa
101             Usage : my $taxa = $obj->get_taxa;
102             Function: Retrieves the Bio::Phylo::Taxa
103             object linked to the invocant.
104             Returns : Bio::Phylo::Taxa
105             Args : NONE
106             Comments: This method returns the Bio::Phylo::Taxa
107             object to which the invocant is linked.
108             The returned object can therefore contain
109             *more* taxa than are actually in the matrix.
110              
111             =cut
112              
113             sub get_taxa {
114 155     155 1 259 my $self = shift;
115 155         414 $logger->debug("getting taxa");
116 155         456 return $mediator->get_link( '-source' => $self );
117             }
118              
119             =item check_taxa()
120              
121             Performs sanity check on taxon relationships.
122              
123             Type : Interface method
124             Title : check_taxa
125             Usage : $obj->check_taxa
126             Function: Performs sanity check on taxon relationships
127             Returns : $obj
128             Args : NONE
129              
130             =cut
131              
132             sub check_taxa {
133 0     0 1 0 throw 'NotImplemented' => 'Not implemented!';
134             }
135              
136             =item make_taxa()
137              
138             Creates a taxa block from the objects contents if none exists yet.
139              
140             Type : Decorated interface method
141             Title : make_taxa
142             Usage : my $taxa = $obj->make_taxa
143             Function: Creates a taxa block from the objects contents if none exists yet.
144             Returns : $taxa
145             Args : NONE
146              
147             =cut
148              
149             sub make_taxa {
150 0     0 1 0 my $self = shift;
151 0 0       0 if ( my $taxa = $self->get_taxa ) {
152 0         0 return $taxa;
153             }
154             else {
155 0         0 throw 'NotImplemented' => 'Not implemented!';
156             }
157             }
158              
159             sub _cleanup {
160 148     148   420 my $self = shift;
161             }
162              
163             =back
164              
165             =head1 SEE ALSO
166              
167             There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
168             for any user or developer questions and discussions.
169              
170             =over
171              
172             =item L<Bio::Phylo::Matrices::Matrix>
173              
174             The matrix object subclasses L<Bio::Phylo::Taxa::TaxaLinker>.
175              
176             =item L<Bio::Phylo::Forest>
177              
178             The forest object subclasses L<Bio::Phylo::Taxa::TaxaLinker>.
179              
180             =item L<Bio::Phylo::Manual>
181              
182             Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
183              
184             =back
185              
186             =head1 CITATION
187              
188             If you use Bio::Phylo in published research, please cite it:
189              
190             B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
191             and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
192             I<BMC Bioinformatics> B<12>:63.
193             L<http://dx.doi.org/10.1186/1471-2105-12-63>
194              
195             =cut
196              
197             1;