| 1 | package Bio::Phylo::Taxa::Taxon; | ||||||||||||||||||
| 2 | 18 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 18 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 18 | ▶ | use base 'Bio::Phylo::NeXML::Writable'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 18 | ▶ | use Bio::Phylo::Util::CONSTANT qw':objecttypes looks_like_object'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 18 | ▶ | use Bio::Phylo::Mediators::TaxaMediator; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | { | ||||||||||||||||||
| 8 | 18 | my $TYPE_CONSTANT = _TAXON_; | |||||||||||||||||
| 9 | 18 | my $CONTAINER_CONSTANT = _TAXA_; | |||||||||||||||||
| 10 | 18 | my $DATUM_CONSTANT = _DATUM_; | |||||||||||||||||
| 11 | 18 | my $NODE_CONSTANT = _NODE_; | |||||||||||||||||
| 12 | 18 | my $logger = __PACKAGE__->get_logger; | |||||||||||||||||
| 13 | 18 | my $mediator = 'Bio::Phylo::Mediators::TaxaMediator'; | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | Bio::Phylo::Taxa::Taxon - Operational taxonomic unit | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | use Bio::Phylo::IO qw(parse); | ||||||||||||||||||
| 22 | use Bio::Phylo::Factory; | ||||||||||||||||||
| 23 | my $fac = Bio::Phylo::Factory->new; | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | # array of names | ||||||||||||||||||
| 26 | my @apes = qw( | ||||||||||||||||||
| 27 | Homo_sapiens | ||||||||||||||||||
| 28 | Pan_paniscus | ||||||||||||||||||
| 29 | Pan_troglodytes | ||||||||||||||||||
| 30 | Gorilla_gorilla | ||||||||||||||||||
| 31 | ); | ||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | # newick string | ||||||||||||||||||
| 34 | my $str = '(((Pan_paniscus,Pan_troglodytes),'; | ||||||||||||||||||
| 35 | $str .= 'Homo_sapiens),Gorilla_gorilla);'; | ||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | # create tree object | ||||||||||||||||||
| 38 | my $tree = parse( | ||||||||||||||||||
| 39 | -format => 'newick', | ||||||||||||||||||
| 40 | -string => $str | ||||||||||||||||||
| 41 | )->first; | ||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | # instantiate taxa object | ||||||||||||||||||
| 44 | my $taxa = $fac->create_taxa; | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | # instantiate taxon objects, insert in taxa object | ||||||||||||||||||
| 47 | foreach( @apes ) { | ||||||||||||||||||
| 48 | my $taxon = $fac->create_taxon( | ||||||||||||||||||
| 49 | -name => $_, | ||||||||||||||||||
| 50 | ); | ||||||||||||||||||
| 51 | $taxa->insert($taxon); | ||||||||||||||||||
| 52 | } | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | # crossreference tree and taxa | ||||||||||||||||||
| 55 | $tree->cross_reference($taxa); | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | # iterate over nodes | ||||||||||||||||||
| 58 | while ( my $node = $tree->next ) { | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | # check references | ||||||||||||||||||
| 61 | if ( $node->get_taxon ) { | ||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | # prints crossreferenced tips | ||||||||||||||||||
| 64 | print "match: ", $node->get_name, "\n"; | ||||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | =head1 DESCRIPTION | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | The taxon object models a single operational taxonomic unit. It is useful for | ||||||||||||||||||
| 71 | cross-referencing datum objects and tree nodes. | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | =head1 METHODS | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | =head2 MUTATORS | ||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | =over | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | =item set_data() | ||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | Associates argument data with invocant. | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | Type : Mutator | ||||||||||||||||||
| 84 | Title : set_data | ||||||||||||||||||
| 85 | Usage : $taxon->set_data( $datum ); | ||||||||||||||||||
| 86 | Function: Associates data with | ||||||||||||||||||
| 87 | the current taxon. | ||||||||||||||||||
| 88 | Returns : Modified object. | ||||||||||||||||||
| 89 | Args : Must be an object of type | ||||||||||||||||||
| 90 | Bio::Phylo::Matrices::Datum | ||||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | =cut | ||||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | 10 | ▶ | sub set_data : Clonable { | ||||||||||||||||
|
Subroutine
set_data: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||
| 95 | 10 | my ( $self, $datum ) = @_; | |||||||||||||||||
| 96 | 10 | ▶ | if ( not defined $datum ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 97 | 0 | return $self; | |||||||||||||||||
| 98 | } | ||||||||||||||||||
| 99 | elsif ( ref $datum eq 'ARRAY' ) { | ||||||||||||||||||
| 100 | 3 | for my $d ( @{ $datum } ) { | |||||||||||||||||
| 101 | 4 | $self->set_data($d); | |||||||||||||||||
| 102 | } | ||||||||||||||||||
| 103 | } | ||||||||||||||||||
| 104 | elsif ( looks_like_object $datum, $DATUM_CONSTANT ) { | ||||||||||||||||||
| 105 | 5 | $mediator->set_link( | |||||||||||||||||
| 106 | '-one' => $self, | ||||||||||||||||||
| 107 | '-many' => $datum, | ||||||||||||||||||
| 108 | ); | ||||||||||||||||||
| 109 | } | ||||||||||||||||||
| 110 | 8 | return $self; | |||||||||||||||||
| 111 | 18 | ▶ | } | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | =item set_nodes() | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | Associates argument node with invocant. | ||||||||||||||||||
| 116 | |||||||||||||||||||
| 117 | Type : Mutator | ||||||||||||||||||
| 118 | Title : set_nodes | ||||||||||||||||||
| 119 | Usage : $taxon->set_nodes($node); | ||||||||||||||||||
| 120 | Function: Associates tree nodes | ||||||||||||||||||
| 121 | with the current taxon. | ||||||||||||||||||
| 122 | Returns : Modified object. | ||||||||||||||||||
| 123 | Args : A Bio::Phylo::Forest::Node object | ||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | =cut | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | 6 | ▶ | sub set_nodes : Clonable { | ||||||||||||||||
|
Subroutine
set_nodes: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||
| 128 | 6 | my ( $self, $node ) = @_; | |||||||||||||||||
| 129 | 6 | ▶ | if ( not defined $node ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 130 | 0 | return $self; | |||||||||||||||||
| 131 | } | ||||||||||||||||||
| 132 | elsif ( ref $node eq 'ARRAY' ) { | ||||||||||||||||||
| 133 | 3 | for my $n ( @{ $node } ) { | |||||||||||||||||
| 134 | 0 | $self->set_nodes($n); | |||||||||||||||||
| 135 | } | ||||||||||||||||||
| 136 | } | ||||||||||||||||||
| 137 | elsif ( looks_like_object $node, $NODE_CONSTANT ) { | ||||||||||||||||||
| 138 | 1 | $mediator->set_link( | |||||||||||||||||
| 139 | '-one' => $self, | ||||||||||||||||||
| 140 | '-many' => $node, | ||||||||||||||||||
| 141 | ); | ||||||||||||||||||
| 142 | } | ||||||||||||||||||
| 143 | 4 | return $self; | |||||||||||||||||
| 144 | 18 | ▶ | } | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | =item unset_datum() | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | Removes association between argument data and invocant. | ||||||||||||||||||
| 149 | |||||||||||||||||||
| 150 | Type : Mutator | ||||||||||||||||||
| 151 | Title : unset_datum | ||||||||||||||||||
| 152 | Usage : $taxon->unset_datum($node); | ||||||||||||||||||
| 153 | Function: Disassociates datum from | ||||||||||||||||||
| 154 | the invocant taxon (i.e. | ||||||||||||||||||
| 155 | removes reference). | ||||||||||||||||||
| 156 | Returns : Modified object. | ||||||||||||||||||
| 157 | Args : A Bio::Phylo::Matrix::Datum object | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | =cut | ||||||||||||||||||
| 160 | |||||||||||||||||||
| 161 | 0 | ▶ | sub unset_datum { | ||||||||||||||||
|
Subroutine
unset_datum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 162 | 0 | my ( $self, $datum ) = @_; | |||||||||||||||||
| 163 | 0 | $mediator->remove_link( | |||||||||||||||||
| 164 | '-one' => $self, | ||||||||||||||||||
| 165 | '-many' => $datum, | ||||||||||||||||||
| 166 | ); | ||||||||||||||||||
| 167 | 0 | return $self; | |||||||||||||||||
| 168 | } | ||||||||||||||||||
| 169 | |||||||||||||||||||
| 170 | =item unset_node() | ||||||||||||||||||
| 171 | |||||||||||||||||||
| 172 | Removes association between argument node and invocant. | ||||||||||||||||||
| 173 | |||||||||||||||||||
| 174 | Type : Mutator | ||||||||||||||||||
| 175 | Title : unset_node | ||||||||||||||||||
| 176 | Usage : $taxon->unset_node($node); | ||||||||||||||||||
| 177 | Function: Disassociates tree node from | ||||||||||||||||||
| 178 | the invocant taxon (i.e. | ||||||||||||||||||
| 179 | removes reference). | ||||||||||||||||||
| 180 | Returns : Modified object. | ||||||||||||||||||
| 181 | Args : A Bio::Phylo::Forest::Node object | ||||||||||||||||||
| 182 | |||||||||||||||||||
| 183 | =cut | ||||||||||||||||||
| 184 | |||||||||||||||||||
| 185 | 0 | ▶ | sub unset_node { | ||||||||||||||||
|
Subroutine
unset_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 186 | 0 | my ( $self, $node ) = @_; | |||||||||||||||||
| 187 | 0 | $mediator->remove_link( | |||||||||||||||||
| 188 | '-one' => $self, | ||||||||||||||||||
| 189 | '-many' => $node, | ||||||||||||||||||
| 190 | ); | ||||||||||||||||||
| 191 | 0 | return $self; | |||||||||||||||||
| 192 | } | ||||||||||||||||||
| 193 | |||||||||||||||||||
| 194 | =back | ||||||||||||||||||
| 195 | |||||||||||||||||||
| 196 | =head2 ACCESSORS | ||||||||||||||||||
| 197 | |||||||||||||||||||
| 198 | =over | ||||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | =item get_data() | ||||||||||||||||||
| 201 | |||||||||||||||||||
| 202 | Retrieves associated datum objects. | ||||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | Type : Accessor | ||||||||||||||||||
| 205 | Title : get_data | ||||||||||||||||||
| 206 | Usage : @data = @{ $taxon->get_data }; | ||||||||||||||||||
| 207 | Function: Retrieves data associated | ||||||||||||||||||
| 208 | with the current taxon. | ||||||||||||||||||
| 209 | Returns : An ARRAY reference of | ||||||||||||||||||
| 210 | Bio::Phylo::Matrices::Datum | ||||||||||||||||||
| 211 | objects. | ||||||||||||||||||
| 212 | Args : None. | ||||||||||||||||||
| 213 | |||||||||||||||||||
| 214 | =cut | ||||||||||||||||||
| 215 | |||||||||||||||||||
| 216 | 24 | ▶ | sub get_data { | ||||||||||||||||
|
Subroutine
get_data: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||
| 217 | 24 | my $self = shift; | |||||||||||||||||
| 218 | 24 | ▶ | return $mediator->get_link( | ||||||||||||||||
|
Condition50%1/2
$mediator->get_link('-source', $self, '-type', $DATUM_CONSTANT) || []
MC/DC0%0/1
$mediator->get_link('-source', $self, '-type', $DATUM_CONSTANT) || []
$mediator->get_link('-source', $self, '-type', $DATUM_CONSTANT)
Truth table50%1/2
A
A= $mediator->get_link('-source', $self, '-type', $DATUM_CONSTANT)
| |||||||||||||||||||
| 219 | '-source' => $self, | ||||||||||||||||||
| 220 | '-type' => $DATUM_CONSTANT, | ||||||||||||||||||
| 221 | ) || []; | ||||||||||||||||||
| 222 | } | ||||||||||||||||||
| 223 | |||||||||||||||||||
| 224 | =item get_nodes() | ||||||||||||||||||
| 225 | |||||||||||||||||||
| 226 | Retrieves associated node objects. | ||||||||||||||||||
| 227 | |||||||||||||||||||
| 228 | Type : Accessor | ||||||||||||||||||
| 229 | Title : get_nodes | ||||||||||||||||||
| 230 | Usage : @nodes = @{ $taxon->get_nodes }; | ||||||||||||||||||
| 231 | Function: Retrieves tree nodes associated | ||||||||||||||||||
| 232 | with the current taxon. | ||||||||||||||||||
| 233 | Returns : An ARRAY reference of | ||||||||||||||||||
| 234 | Bio::Phylo::Trees::Node objects | ||||||||||||||||||
| 235 | Args : None. | ||||||||||||||||||
| 236 | |||||||||||||||||||
| 237 | =cut | ||||||||||||||||||
| 238 | |||||||||||||||||||
| 239 | 24 | ▶ | sub get_nodes { | ||||||||||||||||
|
Subroutine
get_nodes: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||
| 240 | 24 | my $self = shift; | |||||||||||||||||
| 241 | 24 | ▶ | return $mediator->get_link( | ||||||||||||||||
|
Condition50%1/2
$mediator->get_link('-source', $self, '-type', $NODE_CONSTANT) || []
MC/DC0%0/1
$mediator->get_link('-source', $self, '-type', $NODE_CONSTANT) || []
$mediator->get_link('-source', $self, '-type', $NODE_CONSTANT)
Truth table50%1/2
A
A= $mediator->get_link('-source', $self, '-type', $NODE_CONSTANT)
| |||||||||||||||||||
| 242 | '-source' => $self, | ||||||||||||||||||
| 243 | '-type' => $NODE_CONSTANT, | ||||||||||||||||||
| 244 | ) || []; | ||||||||||||||||||
| 245 | } | ||||||||||||||||||
| 246 | |||||||||||||||||||
| 247 | =begin comment | ||||||||||||||||||
| 248 | |||||||||||||||||||
| 249 | Type : Internal method | ||||||||||||||||||
| 250 | Title : _container | ||||||||||||||||||
| 251 | Usage : $taxon->_container; | ||||||||||||||||||
| 252 | Function: | ||||||||||||||||||
| 253 | Returns : CONSTANT | ||||||||||||||||||
| 254 | Args : | ||||||||||||||||||
| 255 | |||||||||||||||||||
| 256 | =end comment | ||||||||||||||||||
| 257 | |||||||||||||||||||
| 258 | =cut | ||||||||||||||||||
| 259 | |||||||||||||||||||
| 260 | 365 | ▶ | sub _container { $CONTAINER_CONSTANT } | ||||||||||||||||
|
Subroutine
_container: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 261 | |||||||||||||||||||
| 262 | =begin comment | ||||||||||||||||||
| 263 | |||||||||||||||||||
| 264 | Type : Internal method | ||||||||||||||||||
| 265 | Title : _type | ||||||||||||||||||
| 266 | Usage : $taxon->_type; | ||||||||||||||||||
| 267 | Function: | ||||||||||||||||||
| 268 | Returns : CONSTANT | ||||||||||||||||||
| 269 | Args : | ||||||||||||||||||
| 270 | |||||||||||||||||||
| 271 | =end comment | ||||||||||||||||||
| 272 | |||||||||||||||||||
| 273 | =cut | ||||||||||||||||||
| 274 | |||||||||||||||||||
| 275 | 424 | ▶ | sub _type { $TYPE_CONSTANT } | ||||||||||||||||
|
Subroutine
_type: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 276 | 2 | ▶ | sub _tag { 'otu' } | ||||||||||||||||
|
Subroutine
_tag: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 277 | |||||||||||||||||||
| 278 | =back | ||||||||||||||||||
| 279 | |||||||||||||||||||
| 280 | =cut | ||||||||||||||||||
| 281 | |||||||||||||||||||
| 282 | # podinherit_insert_token | ||||||||||||||||||
| 283 | |||||||||||||||||||
| 284 | =head1 SEE ALSO | ||||||||||||||||||
| 285 | |||||||||||||||||||
| 286 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||
| 287 | for any user or developer questions and discussions. | ||||||||||||||||||
| 288 | |||||||||||||||||||
| 289 | =over | ||||||||||||||||||
| 290 | |||||||||||||||||||
| 291 | =item L<Bio::Phylo::NeXML::Writable> | ||||||||||||||||||
| 292 | |||||||||||||||||||
| 293 | The taxon objects inherits from the L<Bio::Phylo::NeXML::Writable> object. The methods defined | ||||||||||||||||||
| 294 | there are also applicable to the taxon object. | ||||||||||||||||||
| 295 | |||||||||||||||||||
| 296 | =item L<Bio::Phylo::Manual> | ||||||||||||||||||
| 297 | |||||||||||||||||||
| 298 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||
| 299 | |||||||||||||||||||
| 300 | =back | ||||||||||||||||||
| 301 | |||||||||||||||||||
| 302 | =head1 CITATION | ||||||||||||||||||
| 303 | |||||||||||||||||||
| 304 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||
| 305 | |||||||||||||||||||
| 306 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||
| 307 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||
| 308 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||
| 309 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||
| 310 | |||||||||||||||||||
| 311 | =cut | ||||||||||||||||||
| 312 | |||||||||||||||||||
| 313 | } | ||||||||||||||||||
| 314 | 18 | 1; | |||||||||||||||||