Phylo/ListableRole.pm

filter: Statementstmt 68.2% 127 / 186 Branchbran 63.7% 51 / 80 Conditioncond 78.5% 33 / 42 MC/DCmcdc 67.8% 19 / 28 Subroutinesub 84.2% 16 / 19 Podpod 100% 12 / 12 totaltotal 70.3% 258 / 367 CC 70 SCAR 28.3
CC
70
Cov
69%
sets_to_xml
56.0
cross_reference
29.4
get_by_value
17.0
CRAP 17.0
« Phylo/Taxa.pm ↑ Summary Phylo/Parsers/Fasta.pm »
1 package Bio::Phylo::ListableRole;
2 51 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 51 ▶use Bio::Phylo::Util::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 51 ▶use base 'Bio::Phylo::NeXML::Writable';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 51 ▶use Scalar::Util qw'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 51 ▶use Bio::Phylo::Util::Exceptions 'throw';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 51 ▶use Bio::Phylo::Util::CONSTANT qw':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 {
11 51 my $logger = __PACKAGE__->get_logger;
12 51 my ( $DATUM, $NODE, $MATRIX, $TREE ) =
13 ( _DATUM_, _NODE_, _MATRIX_, _TREE_ );
14  
15 =head1 NAME
16  
17 Bio::Phylo::ListableRole - Extra functionality for things that are lists
18  
19 =head1 SYNOPSIS
20  
21 No direct usage, parent class. Methods documented here
22 are available for all objects that inherit from it.
23  
24 =head1 DESCRIPTION
25  
26 A listable object is an object that contains multiple smaller objects of the
27 same type. For example: a tree contains nodes, so it's a listable object.
28  
29 This class contains methods that are useful for all listable objects: Matrices
30 (i.e. sets of matrix objects), individual Matrix objects, Datum objects (i.e.
31 character state sequences), Taxa, Forest, Tree and Node objects.
32  
33 =head1 METHODS
34  
35 =head2 ARRAY METHODS
36  
37 =over
38  
39 =item prune_entities()
40  
41 Prunes the container's contents specified by an array reference of indices.
42  
43 Type : Mutator
44 Title : prune_entities
45 Usage : $list->prune_entities([9,7,7,6]);
46 Function: Prunes a subset of contents
47 Returns : A Bio::Phylo::Listable object.
48 Args : An array reference of indices
49  
50 =cut
51  
52 0 ▶ sub prune_entities {
Subroutine prune_entities: not called CC=3 SCAR=24.8
Pod documented
53 0 my ( $self, @indices ) = @_;
54 0 my %indices = map { $_ => 1 } @indices;
55 0 my $last_index = $self->last_index;
56 0 my @keep;
57 0 for my $i ( 0 .. $last_index ) {
58 0 ▶ push @keep, $i if not exists $indices{$i};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $indices{$i} 0 0 0
59 }
60 0 return $self->keep_entities( \@keep );
61 }
62  
63 =item get_index_of()
64  
65 Returns the index of the argument in the list,
66 or undef if the list doesn't contain the argument
67  
68 Type : Accessor
69 Title : get_index_of
70 Usage : my $i = $listable->get_index_of($obj)
71 Function: Returns the index of the argument in the list,
72 or undef if the list doesn't contain the argument
73 Returns : An index or undef
74 Args : A contained object
75  
76 =cut
77  
78 68 ▶ sub get_index_of {
Subroutine get_index_of: called CC=3 SCAR=11.0
Pod documented
79 68 my ( $self, $obj ) = @_;
80 68 my $id = $obj->get_id;
81 68 my $i = 0;
82 68 for my $ent ( @{ $self->get_entities } ) {
83 148 ▶ return $i if $ent->get_id == $id;
Branch: 1 branch
BranchTrueFalseTotal
if $ent->get_id == $id 68 80 148
84 80 $i++;
85 }
86 0 return;
87 }
88  
89 =item get_by_index()
90  
91 Gets element at index from container.
92  
93 Type : Accessor
94 Title : get_by_index
95 Usage : my $contained_obj = $obj->get_by_index($i);
96 Function: Retrieves the i'th entity
97 from a listable object.
98 Returns : An entity stored by a listable
99 object (or array ref for slices).
100 Args : An index or range. This works
101 the way you dereference any perl
102 array including through slices,
103 i.e. $obj->get_by_index(0 .. 10)>
104 $obj->get_by_index(0, -1)
105 and so on.
106 Comments: Throws if out-of-bounds
107  
108 =cut
109  
110 123 ▶ sub get_by_index {
Subroutine get_by_index: called CC=4 SCAR=18.4
Pod documented
111 123 my $self = shift;
112 123 my $entities = $self->get_entities;
113 123 my @range = @_;
114 123 ▶ if ( scalar @range > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @range > 1) { } 0 123 123
115 0 my @returnvalue;
116 0 eval { @returnvalue = @{$entities}[@range] };
117 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
118 0 throw 'OutOfBounds' => 'index out of bounds';
119 }
120 0 return \@returnvalue;
121 }
122 else {
123 123 my $returnvalue;
124 123 eval { $returnvalue = $entities->[ $range[0] ] };
125 123 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 123 123
126 0 throw 'OutOfBounds' => 'index out of bounds';
127 }
128 123 return $returnvalue;
129 }
130 }
131  
132 =item get_by_regular_expression()
133  
134 Gets elements that match regular expression from container.
135  
136 Type : Accessor
137 Title : get_by_regular_expression
138 Usage : my @objects = @{
139 $obj->get_by_regular_expression(
140 -value => $method,
141 -match => $re
142 ) };
143 Function: Retrieves the data in the
144 current Bio::Phylo::Listable
145 object whose $method output
146 matches $re
147 Returns : A list of Bio::Phylo::* objects.
148 Args : -value => any of the string
149 datum props (e.g. 'get_type')
150 -match => a compiled regular
151 expression (e.g. qr/^[D|R]NA$/)
152  
153 =cut
154  
155 17 ▶ sub get_by_regular_expression {
Subroutine get_by_regular_expression: called CC=6 SCAR=17.9
Pod documented
156 17 my $self = shift;
157 17 my %o = looks_like_hash @_;
158 17 my @matches;
159 17 for my $e ( @{ $self->get_entities } ) {
160 175 ▶ if ( $o{-match} && looks_like_instance( $o{-match}, 'Regexp' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{'-match'} and &looks_like_instance($o{'-match'}, 'Regexp')) { } 174 1 175
Condition66%2/3
$o{"-match"} and &looks_like_instance($o{"-match"}, "Regexp")
!ll&&!rl&&r
10174
MC/DC50%1/2
$o{"-match"} and &looks_like_instance($o{"-match"}, "Regexp")
$o{"-match"} &looks_like_instance($o{"-match"}, "Regexp")
Truth table66%2/3
A and B
A= $o{"-match"}B= &looks_like_instance($o{"-match"}, "Regexp")
ABresult
0X0
100
111
161 174 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) =~ /$o{"-match"}/) 13 160 173
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) =~ /$o{"-match"}/
!ll&&!rl&&r
3312713
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) =~ /$o{"-match"}/
$e->get($o{"-value"}) $e->get($o{"-value"}) =~ /$o{"-match"}/
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) =~ /$o{"-match"}/
ABresult
0X0
100
111
162 && $e->get( $o{-value} ) =~ $o{-match} )
163 {
164 13 push @matches, $e;
165 }
166 }
167 else {
168 1 throw 'BadArgs' => 'need a regular expression to evaluate';
169 }
170 }
171 15 return \@matches;
172 }
173  
174 =item get_by_value()
175  
176 Gets elements that meet numerical rule from container.
177  
178 Type : Accessor
179 Title : get_by_value
180 Usage : my @objects = @{ $obj->get_by_value(
181 -value => $method,
182 -ge => $number
183 ) };
184 Function: Iterates through all objects
185 contained by $obj and returns
186 those for which the output of
187 $method (e.g. get_tree_length)
188 is less than (-lt), less than
189 or equal to (-le), equal to
190 (-eq), greater than or equal to
191 (-ge), or greater than (-gt) $number.
192 Returns : A reference to an array of objects
193 Args : -value => any of the numerical
194 obj data (e.g. tree length)
195 -lt => less than
196 -le => less than or equals
197 -eq => equals
198 -ge => greater than or equals
199 -gt => greater than
200  
201 =cut
202  
203 28 ▶ sub get_by_value {
Subroutine get_by_value: called CC=17 SCAR=28.3
Pod documented
204 28 my $self = shift;
205 28 my %o = looks_like_hash @_;
206 28 my @results;
207 28 for my $e ( @{ $self->get_entities } ) {
208 116 ▶ if ( $o{-eq} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-eq"}) 22 94 116
209 22 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) == $o{"-eq"}) 3 18 21
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) == $o{"-eq"}
!ll&&!rl&&r
1173
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) == $o{"-eq"}
$e->get($o{"-value"}) $e->get($o{"-value"}) == $o{"-eq"}
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) == $o{"-eq"}
ABresult
0X0
100
111
210 && $e->get( $o{-value} ) == $o{-eq} )
211 {
212 3 push @results, $e;
213 }
214 }
215 115 ▶ if ( $o{-le} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-le"}) 22 93 115
216 22 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) <= $o{"-le"}) 5 16 21
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) <= $o{"-le"}
!ll&&!rl&&r
1155
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) <= $o{"-le"}
$e->get($o{"-value"}) $e->get($o{"-value"}) <= $o{"-le"}
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) <= $o{"-le"}
ABresult
0X0
100
111
217 && $e->get( $o{-value} ) <= $o{-le} )
218 {
219 5 push @results, $e;
220 }
221 }
222 114 ▶ if ( $o{-lt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-lt"}) 24 90 114
223 24 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) < $o{"-lt"}) 6 17 23
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) < $o{"-lt"}
!ll&&!rl&&r
1166
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) < $o{"-lt"}
$e->get($o{"-value"}) $e->get($o{"-value"}) < $o{"-lt"}
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) < $o{"-lt"}
ABresult
0X0
100
111
224 && $e->get( $o{-value} ) < $o{-lt} )
225 {
226 6 push @results, $e;
227 }
228 }
229 113 ▶ if ( $o{-ge} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-ge"}) 24 89 113
230 24 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) >= $o{"-ge"}) 18 5 23
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) >= $o{"-ge"}
!ll&&!rl&&r
1418
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) >= $o{"-ge"}
$e->get($o{"-value"}) $e->get($o{"-value"}) >= $o{"-ge"}
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) >= $o{"-ge"}
ABresult
0X0
100
111
231 && $e->get( $o{-value} ) >= $o{-ge} )
232 {
233 18 push @results, $e;
234 }
235 }
236 112 ▶ if ( $o{-gt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-gt"}) 24 88 112
237 24 ▶ if ( $e->get( $o{-value} )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->get($o{"-value"}) and $e->get($o{"-value"}) > $o{"-gt"}) 17 6 23
Condition100%3/3
$e->get($o{"-value"}) and $e->get($o{"-value"}) > $o{"-gt"}
!ll&&!rl&&r
1517
MC/DC100%2/2
$e->get($o{"-value"}) and $e->get($o{"-value"}) > $o{"-gt"}
$e->get($o{"-value"}) $e->get($o{"-value"}) > $o{"-gt"}
Truth table100%3/3
A and B
A= $e->get($o{"-value"})B= $e->get($o{"-value"}) > $o{"-gt"}
ABresult
0X0
100
111
238 && $e->get( $o{-value} ) > $o{-gt} )
239 {
240 17 push @results, $e;
241 }
242 }
243 }
244 23 return \@results;
245 }
246  
247 =item get_by_name()
248  
249 Gets first element that has argument name
250  
251 Type : Accessor
252 Title : get_by_name
253 Usage : my $found = $obj->get_by_name('foo');
254 Function: Retrieves the first contained object
255 in the current Bio::Phylo::Listable
256 object whose name is 'foo'
257 Returns : A Bio::Phylo::* object.
258 Args : A name (string)
259  
260 =cut
261  
262 173 ▶ sub get_by_name {
Subroutine get_by_name: called CC=6 SCAR=19.0
Pod documented
263 173 my ( $self, $name ) = @_;
264 173 ▶ if ( not defined $name or ref $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or ref $name) 0 173 173
Condition33%1/3
not defined $name or ref $name
l!l&&r!l&&!r
00173
MC/DC0%0/2
not defined $name or ref $name
not defined $name ref $name
Truth table33%1/3
not(A) or B
A= not defined $nameB= ref $name
ABresult
1X1
011
000
265 0 throw 'BadString' => "Can't search on name '$name'";
266 }
267 173 for my $obj ( @{ $self->get_entities } ) {
268 608 my $obj_name = $obj->get_name;
269 608 ▶ if ( $obj_name and $name eq $obj_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj_name and $name eq $obj_name) 173 435 608
Condition100%3/3
$obj_name and $name eq $obj_name
!ll&&!rl&&r
63372173
MC/DC100%2/2
$obj_name and $name eq $obj_name
$obj_name $name eq $obj_name
Truth table100%3/3
A and B
A= $obj_nameB= $name eq $obj_name
ABresult
0X0
100
111
270 173 return $obj;
271 }
272 }
273 0 return;
274 }
275  
276 =back
277  
278 =head2 VISITOR METHODS
279  
280 =over
281  
282 =item visit()
283  
284 Iterates over objects contained by container, executes argument
285 code reference on each.
286  
287 Type : Visitor predicate
288 Title : visit
289 Usage : $obj->visit(
290 sub{ print $_[0]->get_name, "\n" }
291 );
292 Function: Implements visitor pattern
293 using code reference.
294 Returns : The container, possibly modified.
295 Args : a CODE reference.
296  
297 =cut
298  
299 193 ▶ sub visit {
Subroutine visit: called CC=3 SCAR=11.3
Pod documented
300 193 my ( $self, $code ) = @_;
301 193 ▶ if ( looks_like_instance( $code, 'CODE' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_instance($code, 'CODE')) { } 193 0 193
302 193 for ( @{ $self->get_entities } ) {
303 1109 $code->($_);
304 }
305 }
306 else {
307 0 throw 'BadArgs' => "\"$code\" is not a CODE reference!";
308 }
309 193 return $self;
310 }
311  
312 =back
313  
314 =head2 TESTS
315  
316 =over
317  
318 =item contains()
319  
320 Tests whether the container object contains the argument object.
321  
322 Type : Test
323 Title : contains
324 Usage : if ( $obj->contains( $other_obj ) ) {
325 # do something
326 }
327 Function: Tests whether the container object
328 contains the argument object
329 Returns : BOOLEAN
330 Args : A Bio::Phylo::* object
331  
332 =cut
333  
334 19201 ▶ sub contains {
Subroutine contains: called CC=8 SCAR=26.4
Pod documented
335 19201 my ( $self, $obj ) = @_;
336 19201 ▶ if ( blessed $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($obj)) { } 19201 0 19201
337 19201 my $id = $obj->get_id;
338 19201 for my $ent ( @{ $self->get_entities } ) {
339 989437 ▶ next if not $ent;
Branch: 1 branch
BranchTrueFalseTotal
unless $ent 0 989437 989437
340 989437 ▶ return 1 if $ent->get_id == $id;
Branch: 1 branch
BranchTrueFalseTotal
if $ent->get_id == $id 19189 970248 989437
341 }
342 12 return 0;
343 }
344 else {
345 0 for my $ent ( @{ $self->get_entities } ) {
346 0 ▶ next if not $ent;
Branch: 1 branch
BranchTrueFalseTotal
unless $ent 0 0 0
347 0 ▶ return 1 if $ent eq $obj;
Branch: 1 branch
BranchTrueFalseTotal
if $ent eq $obj 0 0 0
348 }
349 }
350 }
351  
352 =item can_contain()
353  
354 Tests if argument can be inserted in container.
355  
356 Type : Test
357 Title : can_contain
358 Usage : &do_something if $listable->can_contain( $obj );
359 Function: Tests if $obj can be inserted in $listable
360 Returns : BOOL
361 Args : An $obj to test
362  
363 =cut
364  
365 19730 ▶ sub can_contain {
Subroutine can_contain: called CC=5 SCAR=16.1
Pod documented
366 19730 my ( $self, @obj ) = @_;
367 19730 for my $obj (@obj) {
368 20036 my ( $self_type, $obj_container );
369 20036 eval {
370 20036 $self_type = $self->_type;
371 20036 $obj_container = $obj->_container;
372 };
373 20036 ▶ if ( $@ or $self_type != $obj_container ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or $self_type != $obj_container) 5 20031 20036
Condition100%3/3
$@ or $self_type != $obj_container
l!l&&r!l&&!r
4120031
MC/DC100%2/2
$@ or $self_type != $obj_container
$@ $self_type != $obj_container
Truth table100%3/3
A or B
A= $@B= $self_type != $obj_container
ABresult
1X1
011
000
374 5 ▶ if ( not $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@) { } 1 4 5
375 1 $logger->info(" $self $self_type != $obj $obj_container");
376 }
377 else {
378 4 $logger->info($@);
379 }
380 5 return 0;
381 }
382 }
383 19725 return 1;
384 }
385  
386 =back
387  
388 =head2 UTILITY METHODS
389  
390 =over
391  
392 =item cross_reference()
393  
394 The cross_reference method links node and datum objects to the taxa they apply
395 to. After crossreferencing a matrix with a taxa object, every datum object has
396 a reference to a taxon object stored in its C<$datum-E<gt>get_taxon> field, and
397 every taxon object has a list of references to datum objects stored in its
398 C<$taxon-E<gt>get_data> field.
399  
400 Type : Generic method
401 Title : cross_reference
402 Usage : $obj->cross_reference($taxa);
403 Function: Crossreferences the entities
404 in the container with names
405 in $taxa
406 Returns : string
407 Args : A Bio::Phylo::Taxa object
408 Comments:
409  
410 =cut
411  
412 5 ▶ sub cross_reference {
Subroutine cross_reference: called CC=17 SCAR=33.8
Pod documented
413 5 my ( $self, $taxa ) = @_;
414 5 my ( $selfref, $taxref ) = ( ref $self, ref $taxa );
415 5 ▶ if ( looks_like_implementor( $taxa, 'get_entities' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_implementor($taxa, 'get_entities')) { } 4 1 5
416 4 my $ents = $self->get_entities;
417 4 ▶ if ( $ents && @{$ents} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ents and @{$ents;}) 3 1 4
Condition66%2/3
$ents and @{$ents;}
!ll&&!rl&&r
013
MC/DC50%1/2
$ents and @{$ents;}
$ents @{$ents;}
Truth table66%2/3
A and B
A= $entsB= @{$ents;}
ABresult
0X0
100
111
418 3 foreach ( @{$ents} ) {
419 4 ▶ if ( looks_like_implementor( $_, 'get_name' )
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_implementor($_, 'get_name') and &looks_like_implementor($_, 'set_taxon')) { } 2 2 4
Condition66%2/3
&looks_like_implementor($_, "get_name") and &looks_like_implementor($_, "set_taxon")
!ll&&!rl&&r
022
MC/DC50%1/2
&looks_like_implementor($_, "get_name") and &looks_like_implementor($_, "set_taxon")
&looks_like_implementor($_, "get_name") &looks_like_implementor($_, "set_taxon")
Truth table66%2/3
A and B
A= &looks_like_implementor($_, "get_name")B= &looks_like_implementor($_, "set_taxon")
ABresult
0X0
100
111
420 && looks_like_implementor( $_, 'set_taxon' ) )
421 {
422 2 my $tax = $taxa->get_entities;
423 2 ▶ if ( $tax && @{$tax} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tax and @{$tax;}) 2 0 2
Condition33%1/3
$tax and @{$tax;}
!ll&&!rl&&r
002
MC/DC0%0/2
$tax and @{$tax;}
$tax @{$tax;}
Truth table33%1/3
A and B
A= $taxB= @{$tax;}
ABresult
0X0
100
111
424 2 foreach my $taxon ( @{$tax} ) {
425 4 ▶ if ( not $taxon->get_name or not $_->get_name )
Branch: 1 branch
BranchTrueFalseTotal
unless ($taxon->get_name and $_->get_name) 4 0 4
Condition33%1/3
$taxon->get_name and $_->get_name
!ll&&!rl&&r
040
MC/DC0%0/2
$taxon->get_name and $_->get_name
$taxon->get_name $_->get_name
Truth table33%1/3
A and B
A= $taxon->get_nameB= $_->get_name
ABresult
0X0
100
111
426 {
427 4 next;
428 }
429 0 ▶ if ( $taxon->get_name eq $_->get_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taxon->get_name eq $_->get_name) 0 0 0
430 0 $_->set_taxon($taxon);
431 0 ▶ if ( $_->_type == $DATUM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->_type == $DATUM) 0 0 0
432 0 $taxon->set_data($_);
433 }
434 0 ▶ if ( $_->_type == $NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->_type == $NODE) 0 0 0
435 0 $taxon->set_nodes($_);
436 }
437 }
438 }
439 }
440 }
441 else {
442 2 throw 'ObjectMismatch' =>
443 "$selfref can't link to $taxref";
444 }
445 }
446 }
447 2 ▶ if ( $self->_type == $TREE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_type == $TREE) { } 1 1 2
elsif ($self->_type == $MATRIX) { } 1 0 1
448 1 $self->_get_container->set_taxa($taxa);
449 }
450 elsif ( $self->_type == $MATRIX ) {
451 1 $self->set_taxa($taxa);
452 }
453 2 return $self;
454 }
455 else {
456 1 throw 'ObjectMismatch' => "$taxref does not contain taxa";
457 }
458 }
459  
460 =item alphabetize()
461  
462 Sorts the contents alphabetically by their name.
463  
464 Type : Generic method
465 Title : alphabetize
466 Usage : $obj->alphabetize;
467 Function: Sorts the contents alphabetically by their name.
468 Returns : $self
469 Args : None
470 Comments:
471  
472 =cut
473
474 0 ▶ sub alphabetize {
Subroutine alphabetize: not called CC=2 SCAR=17.9
Pod documented
475 0 my $self = shift;
476 0 my @sorted = map { $_->[0] }
477 0 sort { $_->[1] cmp $_->[1] }
478 0 map { [ $_, $_->get_internal_name ] }
479 0 @{ $self->get_entities };
480 0 $self->clear;
481 0 $self->insert($_) for @sorted;
482 0 return $self;
483 }
484
485 =back
486  
487 =head2 SETS MANAGEMENT
488  
489 Many Bio::Phylo objects are segmented, i.e. they contain one or more subparts
490 of the same type. For example, a matrix contains multiple rows; each row
491 contains multiple cells; a tree contains nodes, and so on. (Segmented objects
492 all inherit from Bio::Phylo::Listable, i.e. the class whose documentation you're
493 reading here.) In many cases it is useful to be able to define subsets of the
494 contents of segmented objects, for example sets of taxon objects inside a taxa
495 block. The Bio::Phylo::Listable object allows this through a number of methods
496 (add_set, remove_set, add_to_set, remove_from_set etc.). Those methods delegate
497 the actual management of the set contents to the L<Bio::Phylo::Set> object.
498 Consult the documentation for L<Bio::Phylo::Set> for a code sample.
499  
500 =over
501  
502 =item sets_to_xml()
503  
504 Returns string representation of sets
505  
506 Type : Accessor
507 Title : sets_to_xml
508 Usage : my $str = $obj->sets_to_xml;
509 Function: Gets xml string
510 Returns : Scalar
511 Args : None
512  
513 =cut
514  
515 0 ▶ sub sets_to_xml {
Subroutine sets_to_xml: not called CC=7 SCAR=40.3
Pod documented
516 0 my $self = shift;
517 0 my $xml = '';
518 0 ▶ if ( $self->can('get_sets') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("get_sets")) 0 0 0
519 0 for my $set ( @{ $self->get_sets } ) {
520 0 my %contents;
521 0 for my $ent ( @{ $self->get_entities } ) {
522 0 ▶ if ( $self->is_in_set($ent,$set) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_in_set($ent, $set)) 0 0 0
523 0 my $tag = $ent->get_tag;
524 0 ▶ $contents{$tag} = [] if not $contents{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $contents{$tag} 0 0 0
525 0 push @{ $contents{$tag} }, $ent->get_xml_id;
526 }
527 }
528 0 for my $key ( keys %contents ) {
529 0 my @ids = @{ $contents{$key} };
530 0 $contents{$key} = join ' ', @ids;
531 }
532 0 $set->set_attributes(%contents);
533 0 $xml .= "\n" . $set->to_xml;
534 }
535 }
536 0 return $xml;
537 }
538  
539 =back
540  
541 =cut
542  
543 # podinherit_insert_token
544  
545 =head1 SEE ALSO
546  
547 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
548 for any user or developer questions and discussions.
549  
550 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
551  
552 =head2 Objects inheriting from Bio::Phylo::Listable
553  
554 =over
555  
556 =item L<Bio::Phylo::Forest>
557  
558 Iterate over a set of trees.
559  
560 =item L<Bio::Phylo::Forest::Tree>
561  
562 Iterate over nodes in a tree.
563  
564 =item L<Bio::Phylo::Forest::Node>
565  
566 Iterate of children of a node.
567  
568 =item L<Bio::Phylo::Matrices>
569  
570 Iterate over a set of matrices.
571  
572 =item L<Bio::Phylo::Matrices::Matrix>
573  
574 Iterate over the datum objects in a matrix.
575  
576 =item L<Bio::Phylo::Matrices::Datum>
577  
578 Iterate over the characters in a datum.
579  
580 =item L<Bio::Phylo::Taxa>
581  
582 Iterate over a set of taxa.
583  
584 =back
585  
586 =head2 Superclasses
587  
588 =over
589  
590 =item L<Bio::Phylo::NeXML::Writable>
591  
592 This object inherits from L<Bio::Phylo::NeXML::Writable>, so methods
593 defined there are also applicable here.
594  
595 =back
596  
597 =head1 CITATION
598  
599 If you use Bio::Phylo in published research, please cite it:
600  
601 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
602 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
603 I<BMC Bioinformatics> B<12>:63.
604 L<http://dx.doi.org/10.1186/1471-2105-12-63>
605  
606 =cut
607  
608 }
609 51 1;
« Phylo/Taxa.pm ↑ Summary Phylo/Parsers/Fasta.pm »