| 1 | package Bio::Phylo::Listable; | ||||||||||||||||||||||||||||
| 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::ListableRole; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 51 | ▶ | use base 'Bio::Phylo::ListableRole'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 51 | ▶ | use Bio::Phylo::Util::Exceptions 'throw'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 51 | ▶ | use Bio::Phylo::Util::CONSTANT qw':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||
| 10 | 51 | my $logger = __PACKAGE__->get_logger; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # $fields array necessary for object destruction | ||||||||||||||||||||||||||||
| 13 | 51 | my @fields = \( | |||||||||||||||||||||||||||
| 14 | my ( | ||||||||||||||||||||||||||||
| 15 | %entities, # XXX strong reference | ||||||||||||||||||||||||||||
| 16 | %index, | ||||||||||||||||||||||||||||
| 17 | %listeners, | ||||||||||||||||||||||||||||
| 18 | %sets, | ||||||||||||||||||||||||||||
| 19 | ) | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Bio::Phylo::Listable - List of things, super class for many objects | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | No direct usage, parent class. Methods documented here | ||||||||||||||||||||||||||||
| 30 | are available for all objects that inherit from it. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | A listable object is an object that contains multiple smaller objects of the | ||||||||||||||||||||||||||||
| 35 | same type. For example: a tree contains nodes, so it's a listable object. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | This class contains methods that are useful for all listable objects: Matrices | ||||||||||||||||||||||||||||
| 38 | (i.e. sets of matrix objects), individual Matrix objects, Datum objects (i.e. | ||||||||||||||||||||||||||||
| 39 | character state sequences), Taxa, Forest, Tree and Node objects. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head2 ARRAY METHODS | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =over | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item insert() | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Pushes an object into its container. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Type : Mutator | ||||||||||||||||||||||||||||
| 52 | Title : insert | ||||||||||||||||||||||||||||
| 53 | Usage : $obj->insert($other_obj); | ||||||||||||||||||||||||||||
| 54 | Function: Pushes an object into its container. | ||||||||||||||||||||||||||||
| 55 | Returns : A Bio::Phylo::Listable object. | ||||||||||||||||||||||||||||
| 56 | Args : A Bio::Phylo::* object. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 10069 | ▶ | sub insert { | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 10069 | my ( $self, @obj ) = @_; | |||||||||||||||||||||||||||
| 62 | 10069 | ▶ | if ( @obj and $self->can_contain(@obj) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@obj and $self->can_contain(@obj)
MC/DC100%2/2
@obj and $self->can_contain(@obj)
@obj
$self->can_contain(@obj)
Truth table100%3/3
A and B
A= @objB= $self->can_contain(@obj)
| |||||||||||||||||||||||||||||
| 63 | 10056 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 64 | 10056 | push @{ $entities{$id} }, @obj; | |||||||||||||||||||||||||||
| 65 | 10056 | for (@obj) { | |||||||||||||||||||||||||||
| 66 | 92661 | ▶ | ref $_ && UNIVERSAL::can($_,'_set_container') && $_->_set_container($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ and UNIVERSAL::can($_, "_set_container")
MC/DC50%1/2
ref $_ and UNIVERSAL::can($_, "_set_container")
ref $_
UNIVERSAL::can($_, "_set_container")
Truth table66%2/3
A and B
A= ref $_B= UNIVERSAL::can($_, "_set_container")
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | $self->notify_listeners( 'insert', @obj ) | ||||||||||||||||||||||||||||
| 69 | 10056 | ▶ | if $listeners{$id} and @{ $listeners{$id} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$listeners{$id} and @{$listeners{$id};}
MC/DC50%1/2
$listeners{$id} and @{$listeners{$id};}
$listeners{$id}
@{$listeners{$id};}
Truth table66%2/3
A and B
A= $listeners{$id}B= @{$listeners{$id};}
| |||||||||||||||||||||||||||||
| 70 | 10056 | return $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 13 | throw 'ObjectMismatch' => "Failed insertion: [@obj] in [$self]"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item insert_at_index() | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Inserts argument object in container at argument index. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Type : Mutator | ||||||||||||||||||||||||||||
| 82 | Title : insert_at_index | ||||||||||||||||||||||||||||
| 83 | Usage : $obj->insert_at_index($other_obj, $i); | ||||||||||||||||||||||||||||
| 84 | Function: Inserts $other_obj at index $i in container $obj | ||||||||||||||||||||||||||||
| 85 | Returns : A Bio::Phylo::Listable object. | ||||||||||||||||||||||||||||
| 86 | Args : A Bio::Phylo::* object. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 9422 | ▶ | sub insert_at_index { | ||||||||||||||||||||||||||
|
Subroutine
insert_at_index: called CC=6 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 9422 | my ( $self, $obj, $index ) = @_; | |||||||||||||||||||||||||||
| 92 | 9422 | $logger->debug("inserting '$obj' in '$self' at index $index"); | |||||||||||||||||||||||||||
| 93 | 9422 | ▶ | if ( defined $obj and $self->can_contain($obj) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj and $self->can_contain($obj)
MC/DC0%0/2
defined $obj and $self->can_contain($obj)
defined $obj
$self->can_contain($obj)
Truth table33%1/3
A and B
A= defined $objB= $self->can_contain($obj)
| |||||||||||||||||||||||||||||
| 94 | 9422 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 95 | 9422 | $entities{$id}->[$index] = $obj; | |||||||||||||||||||||||||||
| 96 | 9422 | ▶ | if ( looks_like_implementor( $obj, '_set_container' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 9408 | $obj->_set_container($self); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | $self->notify_listeners( 'insert_at_index', $obj ) | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if $listeners{$id} and @{ $listeners{$id} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$listeners{$id} and @{$listeners{$id};}
MC/DC0%0/2
$listeners{$id} and @{$listeners{$id};}
$listeners{$id}
@{$listeners{$id};}
Truth table33%1/3
A and B
A= $listeners{$id}B= @{$listeners{$id};}
| |||||||||||||||||||||||||||||
| 101 | 9422 | return $self; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||
| 104 | 0 | throw 'ObjectMismatch' => 'Failed insertion!'; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item delete() | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Deletes argument from container. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Type : Mutator | ||||||||||||||||||||||||||||
| 113 | Title : delete | ||||||||||||||||||||||||||||
| 114 | Usage : $obj->delete($other_obj); | ||||||||||||||||||||||||||||
| 115 | Function: Deletes an object from its container. | ||||||||||||||||||||||||||||
| 116 | Returns : A Bio::Phylo::Listable object. | ||||||||||||||||||||||||||||
| 117 | Args : A Bio::Phylo::* object. | ||||||||||||||||||||||||||||
| 118 | Note : Be careful with this method: deleting | ||||||||||||||||||||||||||||
| 119 | a node from a tree like this will | ||||||||||||||||||||||||||||
| 120 | result in undefined references in its | ||||||||||||||||||||||||||||
| 121 | neighbouring nodes. Its children will | ||||||||||||||||||||||||||||
| 122 | have their parent reference become | ||||||||||||||||||||||||||||
| 123 | undef (instead of pointing to their | ||||||||||||||||||||||||||||
| 124 | grandparent, as collapsing a node would | ||||||||||||||||||||||||||||
| 125 | do). The same is true for taxon objects | ||||||||||||||||||||||||||||
| 126 | that reference datum objects: if the | ||||||||||||||||||||||||||||
| 127 | datum object is deleted from a matrix | ||||||||||||||||||||||||||||
| 128 | (say), the taxon will now hold undefined | ||||||||||||||||||||||||||||
| 129 | references. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 729 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=7 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 729 | my ( $self, $obj ) = @_; | |||||||||||||||||||||||||||
| 135 | 729 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 136 | 729 | ▶ | if ( $self->can_contain($obj) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 729 | my $object_id = $obj->get_id; | |||||||||||||||||||||||||||
| 138 | 729 | my $occurence_counter = 0; | |||||||||||||||||||||||||||
| 139 | 729 | ▶ | if ( my $i = $index{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | for my $j ( 0 .. $i ) { | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( $entities{$id}->[$j]->get_id == $object_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | $occurence_counter++; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | my @modified = | ||||||||||||||||||||||||||||
| 147 | 729 | grep { $_->get_id != $object_id } @{ $entities{$id} }; | |||||||||||||||||||||||||||
| 148 | 729 | $entities{$id} = \@modified; | |||||||||||||||||||||||||||
| 149 | 729 | $index{$id} -= $occurence_counter; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||
| 152 | 0 | throw 'ObjectMismatch' => | |||||||||||||||||||||||||||
| 153 | "Invocant object cannot contain argument object"; | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | $self->notify_listeners( 'delete', $obj ) | ||||||||||||||||||||||||||||
| 156 | 729 | ▶ | if $listeners{$id} and @{ $listeners{$id} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$listeners{$id} and @{$listeners{$id};}
MC/DC50%1/2
$listeners{$id} and @{$listeners{$id};}
$listeners{$id}
@{$listeners{$id};}
Truth table66%2/3
A and B
A= $listeners{$id}B= @{$listeners{$id};}
| |||||||||||||||||||||||||||||
| 157 | 729 | return $self; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =item clear() | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Empties container object. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Type : Mutator | ||||||||||||||||||||||||||||
| 165 | Title : clear | ||||||||||||||||||||||||||||
| 166 | Usage : $obj->clear(); | ||||||||||||||||||||||||||||
| 167 | Function: Clears the container. | ||||||||||||||||||||||||||||
| 168 | Returns : A Bio::Phylo::Listable object. | ||||||||||||||||||||||||||||
| 169 | Args : Note. | ||||||||||||||||||||||||||||
| 170 | Note : | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 745 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 745 | my $self = shift; | |||||||||||||||||||||||||||
| 176 | 745 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 177 | 745 | $entities{$id} = []; | |||||||||||||||||||||||||||
| 178 | $self->notify_listeners('clear') | ||||||||||||||||||||||||||||
| 179 | 745 | ▶ | if $listeners{$id} and @{ $listeners{$id} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$listeners{$id} and @{$listeners{$id};}
MC/DC50%1/2
$listeners{$id} and @{$listeners{$id};}
$listeners{$id}
@{$listeners{$id};}
Truth table66%2/3
A and B
A= $listeners{$id}B= @{$listeners{$id};}
| |||||||||||||||||||||||||||||
| 180 | 745 | return $self; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item keep_entities() | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Keeps the container's contents specified by an array reference of indices. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | Type : Mutator | ||||||||||||||||||||||||||||
| 188 | Title : keep_entities | ||||||||||||||||||||||||||||
| 189 | Usage : $list->keep_entities([9,7,7,6]); | ||||||||||||||||||||||||||||
| 190 | Function: Keeps a subset of contents | ||||||||||||||||||||||||||||
| 191 | Returns : A Bio::Phylo::Listable object. | ||||||||||||||||||||||||||||
| 192 | Args : An array reference of indices | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 20 | ▶ | sub keep_entities { | ||||||||||||||||||||||||||
|
Subroutine
keep_entities: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 20 | my ( $self, $indices_array_ref ) = @_; | |||||||||||||||||||||||||||
| 198 | 20 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 199 | 20 | ▶ | my $ent = $entities{$id} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$entities{$id} || []
MC/DC0%0/1
$entities{$id} || []
$entities{$id}
Truth table50%1/2
A
A= $entities{$id}
| |||||||||||||||||||||||||||||
| 200 | 20 | my @contents = @{$ent}; | |||||||||||||||||||||||||||
| 201 | 20 | my @pruned = @contents[ @{$indices_array_ref} ]; | |||||||||||||||||||||||||||
| 202 | 20 | $entities{$id} = \@pruned; | |||||||||||||||||||||||||||
| 203 | 20 | return $self; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =item get_entities() | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Returns a reference to an array of objects contained by the listable object. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Type : Accessor | ||||||||||||||||||||||||||||
| 211 | Title : get_entities | ||||||||||||||||||||||||||||
| 212 | Usage : my @entities = @{ $obj->get_entities }; | ||||||||||||||||||||||||||||
| 213 | Function: Retrieves all entities in the container. | ||||||||||||||||||||||||||||
| 214 | Returns : A reference to a list of Bio::Phylo::* | ||||||||||||||||||||||||||||
| 215 | objects. | ||||||||||||||||||||||||||||
| 216 | Args : none. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =cut | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 148585 | ▶ | sub get_entities { | ||||||||||||||||||||||||||
|
Subroutine
get_entities: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 148585 | ▶ | return $entities{ $_[0]->get_id } || []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$entities{$_[0]->get_id} || []
MC/DC100%1/1
$entities{$_[0]->get_id} || []
$entities{$_[0]->get_id}
Truth table100%2/2
A
A= $entities{$_[0]->get_id}
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 56 | ▶ | sub _get_things { $entities{shift->get_id} } | ||||||||||||||||||||||||||
|
Subroutine
_get_things: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 225 | 56 | ▶ | sub _set_things : Clonable DeepClonable { | ||||||||||||||||||||||||||
|
Subroutine
_set_things: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 226 | 56 | my ( $self, $things ) = @_; | |||||||||||||||||||||||||||
| 227 | 56 | $entities{$self->get_id} = $things; | |||||||||||||||||||||||||||
| 228 | 56 | $self->notify_listeners( '_set_things', $things ); | |||||||||||||||||||||||||||
| 229 | 56 | return $self; | |||||||||||||||||||||||||||
| 230 | 51 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =back | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =head2 ITERATOR METHODS | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =over | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =item first() | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | Jumps to the first element contained by the listable object. | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | Type : Iterator | ||||||||||||||||||||||||||||
| 243 | Title : first | ||||||||||||||||||||||||||||
| 244 | Usage : my $first_obj = $obj->first; | ||||||||||||||||||||||||||||
| 245 | Function: Retrieves the first | ||||||||||||||||||||||||||||
| 246 | entity in the container. | ||||||||||||||||||||||||||||
| 247 | Returns : A Bio::Phylo::* object | ||||||||||||||||||||||||||||
| 248 | Args : none. | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =cut | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 73 | ▶ | sub first { | ||||||||||||||||||||||||||
|
Subroutine
first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | 73 | my $self = shift; | |||||||||||||||||||||||||||
| 254 | 73 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 255 | 73 | $index{$id} = 0; | |||||||||||||||||||||||||||
| 256 | 73 | return $entities{$id}->[0]; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =item last() | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | Jumps to the last element contained by the listable object. | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Type : Iterator | ||||||||||||||||||||||||||||
| 264 | Title : last | ||||||||||||||||||||||||||||
| 265 | Usage : my $last_obj = $obj->last; | ||||||||||||||||||||||||||||
| 266 | Function: Retrieves the last | ||||||||||||||||||||||||||||
| 267 | entity in the container. | ||||||||||||||||||||||||||||
| 268 | Returns : A Bio::Phylo::* object | ||||||||||||||||||||||||||||
| 269 | Args : none. | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | =cut | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 1 | ▶ | sub last { | ||||||||||||||||||||||||||
|
Subroutine
last: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 274 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 275 | 1 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 276 | 1 | $index{$id} = $#{ $entities{$id} }; | |||||||||||||||||||||||||||
| 277 | 1 | return $entities{$id}->[-1]; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =item current() | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | Returns the current focal element of the listable object. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | Type : Iterator | ||||||||||||||||||||||||||||
| 285 | Title : current | ||||||||||||||||||||||||||||
| 286 | Usage : my $current_obj = $obj->current; | ||||||||||||||||||||||||||||
| 287 | Function: Retrieves the current focal | ||||||||||||||||||||||||||||
| 288 | entity in the container. | ||||||||||||||||||||||||||||
| 289 | Returns : A Bio::Phylo::* object | ||||||||||||||||||||||||||||
| 290 | Args : none. | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | =cut | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub current { | ||||||||||||||||||||||||||
|
Subroutine
current: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 296 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( !defined $index{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | $index{$id} = 0; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | 0 | return $entities{$id}->[ $index{$id} ]; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =item next() | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Returns the next focal element of the listable object. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | Type : Iterator | ||||||||||||||||||||||||||||
| 308 | Title : next | ||||||||||||||||||||||||||||
| 309 | Usage : my $next_obj = $obj->next; | ||||||||||||||||||||||||||||
| 310 | Function: Retrieves the next focal | ||||||||||||||||||||||||||||
| 311 | entity in the container. | ||||||||||||||||||||||||||||
| 312 | Returns : A Bio::Phylo::* object | ||||||||||||||||||||||||||||
| 313 | Args : none. | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =cut | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 318 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 319 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ( !defined $index{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 321 | 0 | $index{$id} = 0; | |||||||||||||||||||||||||||
| 322 | 0 | return $entities{$id}->[ $index{$id} ]; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 0 | elsif ( ( $index{$id} + 1 ) <= $#{ $entities{$id} } ) { | |||||||||||||||||||||||||||
| 325 | 0 | $index{$id}++; | |||||||||||||||||||||||||||
| 326 | 0 | return $entities{$id}->[ $index{$id} ]; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||
| 329 | 0 | return; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =item previous() | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | Returns the previous element of the listable object. | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | Type : Iterator | ||||||||||||||||||||||||||||
| 338 | Title : previous | ||||||||||||||||||||||||||||
| 339 | Usage : my $previous_obj = $obj->previous; | ||||||||||||||||||||||||||||
| 340 | Function: Retrieves the previous | ||||||||||||||||||||||||||||
| 341 | focal entity in the container. | ||||||||||||||||||||||||||||
| 342 | Returns : A Bio::Phylo::* object | ||||||||||||||||||||||||||||
| 343 | Args : none. | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | =cut | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub previous { | ||||||||||||||||||||||||||
|
Subroutine
previous: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 348 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 349 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | # either undef or 0 | ||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if ( !$index{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 353 | 0 | return; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | elsif ( 1 <= $index{$id} ) { | ||||||||||||||||||||||||||||
| 356 | 0 | $index{$id}--; | |||||||||||||||||||||||||||
| 357 | 0 | return $entities{$id}->[ $index{$id} ]; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | else { | ||||||||||||||||||||||||||||
| 360 | 0 | return; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =item current_index() | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | Returns the current internal index of the container. | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | Type : Accessor | ||||||||||||||||||||||||||||
| 369 | Title : current_index | ||||||||||||||||||||||||||||
| 370 | Usage : my $last_index = $obj->current_index; | ||||||||||||||||||||||||||||
| 371 | Function: Returns the current internal | ||||||||||||||||||||||||||||
| 372 | index of the container or 0 | ||||||||||||||||||||||||||||
| 373 | Returns : An integer | ||||||||||||||||||||||||||||
| 374 | Args : none. | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | =cut | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub current_index { $index{ ${ $_[0] } } || 0 } | ||||||||||||||||||||||||||
|
Subroutine
current_index: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 56 | ▶ | sub _get_index { $index{shift->get_id} } | ||||||||||||||||||||||||||
|
Subroutine
_get_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 56 | ▶ | sub _set_index : Clonable { | ||||||||||||||||||||||||||
|
Subroutine
_set_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 383 | 56 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||
| 384 | 56 | $index{ $self->get_id } = $idx; | |||||||||||||||||||||||||||
| 385 | 56 | return $self; | |||||||||||||||||||||||||||
| 386 | 51 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | =item last_index() | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | Returns the highest valid index of the container. | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | Type : Generic query | ||||||||||||||||||||||||||||
| 393 | Title : last_index | ||||||||||||||||||||||||||||
| 394 | Usage : my $last_index = $obj->last_index; | ||||||||||||||||||||||||||||
| 395 | Function: Returns the highest valid | ||||||||||||||||||||||||||||
| 396 | index of the container. | ||||||||||||||||||||||||||||
| 397 | Returns : An integer | ||||||||||||||||||||||||||||
| 398 | Args : none. | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub last_index { $#{ $entities{ ${ $_[0] } } } } | ||||||||||||||||||||||||||
|
Subroutine
last_index: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | =back | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =head2 UTILITY METHODS | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =over | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =item set_listener() | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | Attaches a listener (code ref) which is executed when contents change. | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | Type : Utility method | ||||||||||||||||||||||||||||
| 415 | Title : set_listener | ||||||||||||||||||||||||||||
| 416 | Usage : $object->set_listener( sub { my $object = shift; } ); | ||||||||||||||||||||||||||||
| 417 | Function: Attaches a listener (code ref) which is executed when contents change. | ||||||||||||||||||||||||||||
| 418 | Returns : Invocant. | ||||||||||||||||||||||||||||
| 419 | Args : A code reference. | ||||||||||||||||||||||||||||
| 420 | Comments: When executed, the code reference will receive $object | ||||||||||||||||||||||||||||
| 421 | (the container) as its first argument. | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | =cut | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 957 | ▶ | sub set_listener { | ||||||||||||||||||||||||||
|
Subroutine
set_listener: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 426 | 957 | my ( $self, $listener ) = @_; | |||||||||||||||||||||||||||
| 427 | 957 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 428 | 957 | ▶ | if ( not $listeners{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 957 | $listeners{$id} = []; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 957 | ▶ | if ( looks_like_instance( $listener, 'CODE' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 957 | push @{ $listeners{$id} }, $listener; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | else { | ||||||||||||||||||||||||||||
| 435 | 0 | throw 'BadArgs' => "$listener not a CODE reference"; | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 56 | ▶ | sub _set_listeners : Clonable { | ||||||||||||||||||||||||||
|
Subroutine
_set_listeners: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 439 | 56 | my ( $self, $l ) = @_; | |||||||||||||||||||||||||||
| 440 | 56 | $listeners{$self->get_id} = $l; | |||||||||||||||||||||||||||
| 441 | 56 | return $self; | |||||||||||||||||||||||||||
| 442 | 51 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 443 | 56 | ▶ | sub _get_listeners { $listeners{shift->get_id} } | ||||||||||||||||||||||||||
|
Subroutine
_get_listeners: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | =item notify_listeners() | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | Notifies listeners of changed contents. | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | Type : Utility method | ||||||||||||||||||||||||||||
| 450 | Title : notify_listeners | ||||||||||||||||||||||||||||
| 451 | Usage : $object->notify_listeners; | ||||||||||||||||||||||||||||
| 452 | Function: Notifies listeners of changed contents. | ||||||||||||||||||||||||||||
| 453 | Returns : Invocant. | ||||||||||||||||||||||||||||
| 454 | Args : NONE. | ||||||||||||||||||||||||||||
| 455 | Comments: | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 9504 | ▶ | sub notify_listeners { | ||||||||||||||||||||||||||
|
Subroutine
notify_listeners: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 460 | 9504 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||
| 461 | 9504 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 462 | 9504 | ▶ | if ( $listeners{$id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | 9474 | for my $l ( @{ $listeners{$id} } ) { | |||||||||||||||||||||||||||
| 464 | 9474 | $l->( $self, @args ); | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | 9504 | return $self; | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | =back | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | =head2 SETS MANAGEMENT | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | Many Bio::Phylo objects are segmented, i.e. they contain one or more subparts | ||||||||||||||||||||||||||||
| 475 | of the same type. For example, a matrix contains multiple rows; each row | ||||||||||||||||||||||||||||
| 476 | contains multiple cells; a tree contains nodes, and so on. (Segmented objects | ||||||||||||||||||||||||||||
| 477 | all inherit from Bio::Phylo::Listable, i.e. the class whose documentation you're | ||||||||||||||||||||||||||||
| 478 | reading here.) In many cases it is useful to be able to define subsets of the | ||||||||||||||||||||||||||||
| 479 | contents of segmented objects, for example sets of taxon objects inside a taxa | ||||||||||||||||||||||||||||
| 480 | block. The Bio::Phylo::Listable object allows this through a number of methods | ||||||||||||||||||||||||||||
| 481 | (add_set, remove_set, add_to_set, remove_from_set etc.). Those methods delegate | ||||||||||||||||||||||||||||
| 482 | the actual management of the set contents to the L<Bio::Phylo::Set> object. | ||||||||||||||||||||||||||||
| 483 | Consult the documentation for L<Bio::Phylo::Set> for a code sample. | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =over | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | =item add_set() | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | Type : Mutator | ||||||||||||||||||||||||||||
| 490 | Title : add_set | ||||||||||||||||||||||||||||
| 491 | Usage : $obj->add_set($set) | ||||||||||||||||||||||||||||
| 492 | Function: Associates a Bio::Phylo::Set object with the container | ||||||||||||||||||||||||||||
| 493 | Returns : Invocant | ||||||||||||||||||||||||||||
| 494 | Args : A Bio::Phylo::Set object | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | # here we create a listener that updates the set | ||||||||||||||||||||||||||||
| 499 | # object when the associated container changes | ||||||||||||||||||||||||||||
| 500 | 4 | ▶ | my $create_set_listeners = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.3
| |||||||||||||||||||||||||||||
| 501 | 4 | my ( $self, $set ) = @_; | |||||||||||||||||||||||||||
| 502 | 0 | ▶ | my $listener = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 503 | 0 | my ( $listable, $method, $obj ) = @_; | |||||||||||||||||||||||||||
| 504 | 0 | ▶ | if ( $method eq 'delete' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 505 | 0 | $listable->remove_from_set( $obj, $set ); | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | elsif ( $method eq 'clear' ) { | ||||||||||||||||||||||||||||
| 508 | 0 | $set->clear; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | 4 | }; | |||||||||||||||||||||||||||
| 511 | 4 | return $listener; | |||||||||||||||||||||||||||
| 512 | 51 | }; | |||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 4 | ▶ | sub add_set { | ||||||||||||||||||||||||||
|
Subroutine
add_set: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 515 | 4 | my ( $self, $set ) = @_; | |||||||||||||||||||||||||||
| 516 | 4 | my $listener = $create_set_listeners->( $self, $set ); | |||||||||||||||||||||||||||
| 517 | 4 | $self->set_listener($listener); | |||||||||||||||||||||||||||
| 518 | 4 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 519 | 4 | ▶ | $sets{$id} = {} if not $sets{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 4 | my $setid = $set->get_id; | |||||||||||||||||||||||||||
| 521 | 4 | $sets{$id}->{$setid} = $set; | |||||||||||||||||||||||||||
| 522 | 4 | return $self; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | =item set_sets() | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | Type : Mutator | ||||||||||||||||||||||||||||
| 528 | Title : set_sets | ||||||||||||||||||||||||||||
| 529 | Usage : $obj->set_sets([ $s1, $s2, $s3 ]) | ||||||||||||||||||||||||||||
| 530 | Function: Assigns all Bio::Phylo::Set objects to the container | ||||||||||||||||||||||||||||
| 531 | Returns : Invocant | ||||||||||||||||||||||||||||
| 532 | Args : An array ref of Bio::Phylo::Set objects | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | =cut | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 56 | ▶ | sub set_sets : Clonable { | ||||||||||||||||||||||||||
|
Subroutine
set_sets: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 537 | 56 | my ( $self, $sets ) = @_; | |||||||||||||||||||||||||||
| 538 | 56 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 539 | 56 | $sets{$id} = {}; | |||||||||||||||||||||||||||
| 540 | 56 | ▶ | if ( $sets ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 541 | 56 | for my $set ( @{ $sets } ) { | |||||||||||||||||||||||||||
| 542 | 0 | $sets{$id}->{$set->get_id} = $set; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | 56 | return $self; | |||||||||||||||||||||||||||
| 546 | 51 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | =item remove_set() | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | Type : Mutator | ||||||||||||||||||||||||||||
| 551 | Title : remove_set | ||||||||||||||||||||||||||||
| 552 | Usage : $obj->remove_set($set) | ||||||||||||||||||||||||||||
| 553 | Function: Removes association between a Bio::Phylo::Set object and the container | ||||||||||||||||||||||||||||
| 554 | Returns : Invocant | ||||||||||||||||||||||||||||
| 555 | Args : A Bio::Phylo::Set object | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | =cut | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | ▶ | sub remove_set { | ||||||||||||||||||||||||||
|
Subroutine
remove_set: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 560 | 0 | my ( $self, $set ) = @_; | |||||||||||||||||||||||||||
| 561 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 562 | 0 | ▶ | $sets{$id} = {} if not $sets{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 563 | 0 | my $setid = $set->get_id; | |||||||||||||||||||||||||||
| 564 | 0 | delete $sets{$id}->{$setid}; | |||||||||||||||||||||||||||
| 565 | 0 | return $self; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =item get_sets() | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | Type : Accessor | ||||||||||||||||||||||||||||
| 571 | Title : get_sets | ||||||||||||||||||||||||||||
| 572 | Usage : my @sets = @{ $obj->get_sets() }; | ||||||||||||||||||||||||||||
| 573 | Function: Retrieves all associated Bio::Phylo::Set objects | ||||||||||||||||||||||||||||
| 574 | Returns : Invocant | ||||||||||||||||||||||||||||
| 575 | Args : None | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | =cut | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 60 | ▶ | sub get_sets { | ||||||||||||||||||||||||||
|
Subroutine
get_sets: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 580 | 60 | my $self = shift; | |||||||||||||||||||||||||||
| 581 | 60 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 582 | 60 | ▶ | $sets{$id} = {} if not $sets{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | 60 | return [ values %{ $sets{$id} } ]; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | =item is_in_set() | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | Type : Test | ||||||||||||||||||||||||||||
| 589 | Title : is_in_set | ||||||||||||||||||||||||||||
| 590 | Usage : @do_something if $listable->is_in_set($obj,$set); | ||||||||||||||||||||||||||||
| 591 | Function: Returns whether or not the first argument is listed in the second argument | ||||||||||||||||||||||||||||
| 592 | Returns : Boolean | ||||||||||||||||||||||||||||
| 593 | Args : $obj - an object that may, or may not be in $set | ||||||||||||||||||||||||||||
| 594 | $set - the Bio::Phylo::Set object to query | ||||||||||||||||||||||||||||
| 595 | Notes : This method makes two assumptions: | ||||||||||||||||||||||||||||
| 596 | i) the $set object is associated with the container, | ||||||||||||||||||||||||||||
| 597 | i.e. add_set($set) has been called previously | ||||||||||||||||||||||||||||
| 598 | ii) the $obj object is part of the container | ||||||||||||||||||||||||||||
| 599 | If either assumption is violated a warning message | ||||||||||||||||||||||||||||
| 600 | is printed. | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | =cut | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 22 | ▶ | sub is_in_set { | ||||||||||||||||||||||||||
|
Subroutine
is_in_set: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||
| 605 | 22 | my ( $self, $obj, $set ) = @_; | |||||||||||||||||||||||||||
| 606 | 22 | ▶ | if ( looks_like_object($set,_SET_) and $sets{ $self->get_id }->{ $set->get_id } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_object($set, 26) and $sets{$self->get_id}{$set->get_id}
MC/DC0%0/2
&looks_like_object($set, 26) and $sets{$self->get_id}{$set->get_id}
&looks_like_object($set, 26)
$sets{$self->get_id}{$set->get_id}
Truth table33%1/3
A and B
A= &looks_like_object($set, 26)B= $sets{$self->get_id}{$set->get_id}
| |||||||||||||||||||||||||||||
| 607 | 22 | my $i = $self->get_index_of($obj); | |||||||||||||||||||||||||||
| 608 | 22 | ▶ | if ( defined $i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 22 | ▶ | return $set->get_by_index($i) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | else { | ||||||||||||||||||||||||||||
| 612 | 0 | $logger->warn("Container doesn't contain that object."); | |||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | else { | ||||||||||||||||||||||||||||
| 616 | 0 | $logger->warn("That set is not associated with this container."); | |||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | =item add_to_set() | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | Type : Mutator | ||||||||||||||||||||||||||||
| 623 | Title : add_to_set | ||||||||||||||||||||||||||||
| 624 | Usage : $listable->add_to_set($obj,$set); | ||||||||||||||||||||||||||||
| 625 | Function: Adds first argument to the second argument | ||||||||||||||||||||||||||||
| 626 | Returns : Invocant | ||||||||||||||||||||||||||||
| 627 | Args : $obj - an object to add to $set | ||||||||||||||||||||||||||||
| 628 | $set - the Bio::Phylo::Set object to add to | ||||||||||||||||||||||||||||
| 629 | Notes : this method assumes that $obj is already | ||||||||||||||||||||||||||||
| 630 | part of the container. If that assumption is | ||||||||||||||||||||||||||||
| 631 | violated a warning message is printed. | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | =cut | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | 14 | ▶ | sub add_to_set { | ||||||||||||||||||||||||||
|
Subroutine
add_to_set: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 636 | 14 | my ( $self, $obj, $set ) = @_; | |||||||||||||||||||||||||||
| 637 | 14 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 638 | 14 | ▶ | $sets{$id} = {} if not $sets{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 639 | 14 | my $i = $self->get_index_of($obj); | |||||||||||||||||||||||||||
| 640 | 14 | ▶ | if ( defined $i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | 14 | $set->insert_at_index( 1 => $i ); | |||||||||||||||||||||||||||
| 642 | 14 | my $set_id = $set->get_id; | |||||||||||||||||||||||||||
| 643 | 14 | ▶ | if ( not exists $sets{$id}->{$set_id} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 644 | 0 | my $listener = $create_set_listeners->( $self, $set ); | |||||||||||||||||||||||||||
| 645 | 0 | $self->set_listener($listener); | |||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | 14 | $sets{$id}->{$set_id} = $set; | |||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | else { | ||||||||||||||||||||||||||||
| 650 | 0 | $logger->warn( | |||||||||||||||||||||||||||
| 651 | "Container doesn't contain the object you're adding to the set." | ||||||||||||||||||||||||||||
| 652 | ); | ||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||
| 654 | 14 | return $self; | |||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | =item remove_from_set() | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | Type : Mutator | ||||||||||||||||||||||||||||
| 660 | Title : remove_from_set | ||||||||||||||||||||||||||||
| 661 | Usage : $listable->remove_from_set($obj,$set); | ||||||||||||||||||||||||||||
| 662 | Function: Removes first argument from the second argument | ||||||||||||||||||||||||||||
| 663 | Returns : Invocant | ||||||||||||||||||||||||||||
| 664 | Args : $obj - an object to remove from $set | ||||||||||||||||||||||||||||
| 665 | $set - the Bio::Phylo::Set object to remove from | ||||||||||||||||||||||||||||
| 666 | Notes : this method assumes that $obj is already | ||||||||||||||||||||||||||||
| 667 | part of the container. If that assumption is | ||||||||||||||||||||||||||||
| 668 | violated a warning message is printed. | ||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | =cut | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | 0 | ▶ | sub remove_from_set { | ||||||||||||||||||||||||||
|
Subroutine
remove_from_set: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 673 | 0 | my ( $self, $obj, $set ) = @_; | |||||||||||||||||||||||||||
| 674 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 675 | 0 | ▶ | $sets{$id} = {} if not $sets{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | 0 | my $i = $self->get_index_of($obj); | |||||||||||||||||||||||||||
| 677 | 0 | ▶ | if ( defined $i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 678 | 0 | $set->insert_at_index( $i => 0 ); | |||||||||||||||||||||||||||
| 679 | 0 | $sets{$id}->{ $set->get_id } = $set; | |||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||
| 681 | else { | ||||||||||||||||||||||||||||
| 682 | 0 | $logger->warn( | |||||||||||||||||||||||||||
| 683 | "Container doesn't contain the object you're adding to the set." | ||||||||||||||||||||||||||||
| 684 | ); | ||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||
| 686 | 0 | return $self; | |||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | =begin comment | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | Type : Internal method | ||||||||||||||||||||||||||||
| 692 | Title : _cleanup | ||||||||||||||||||||||||||||
| 693 | Usage : $listable->_cleanup; | ||||||||||||||||||||||||||||
| 694 | Function: Called during object destruction, for cleanup of instance data | ||||||||||||||||||||||||||||
| 695 | Returns : | ||||||||||||||||||||||||||||
| 696 | Args : | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | =end comment | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | =cut | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 30693 | ▶ | sub _cleanup : Destructor { | ||||||||||||||||||||||||||
|
Subroutine
_cleanup: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 703 | 30693 | my $self = shift; | |||||||||||||||||||||||||||
| 704 | 30693 | my $id = $self->get_id; | |||||||||||||||||||||||||||
| 705 | 30693 | for my $field (@fields) { | |||||||||||||||||||||||||||
| 706 | 122772 | delete $field->{$id}; | |||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | 51 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | =back | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | =cut | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | # podinherit_insert_token | ||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||||||||||||
| 719 | for any user or developer questions and discussions. | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | =head2 Objects inheriting from Bio::Phylo::Listable | ||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | =over | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | =item L<Bio::Phylo::Forest> | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | Iterate over a set of trees. | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | =item L<Bio::Phylo::Forest::Tree> | ||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | Iterate over nodes in a tree. | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | =item L<Bio::Phylo::Forest::Node> | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | Iterate of children of a node. | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | =item L<Bio::Phylo::Matrices> | ||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | Iterate over a set of matrices. | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | =item L<Bio::Phylo::Matrices::Matrix> | ||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | Iterate over the datum objects in a matrix. | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | =item L<Bio::Phylo::Matrices::Datum> | ||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | Iterate over the characters in a datum. | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | =item L<Bio::Phylo::Taxa> | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | Iterate over a set of taxa. | ||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | =back | ||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||
| 757 | =head2 Superclasses | ||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | =over | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | =item L<Bio::Phylo::NeXML::Writable> | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | This object inherits from L<Bio::Phylo::NeXML::Writable>, so methods | ||||||||||||||||||||||||||||
| 764 | defined there are also applicable here. | ||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | =back | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | =head1 CITATION | ||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||
| 772 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||||||||||||
| 773 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||||||||||||
| 774 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||||||||||||
| 775 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||
| 777 | =cut | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||
| 780 | 51 | 1; | |||||||||||||||||||||||||||