| 1 | package Bio::Phylo::Matrices::Datatype::Continuous; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use base 'Bio::Phylo::Matrices::Datatype'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | use Bio::Phylo::Util::CONSTANT | ||||||||||||||||||||||||||||
| 6 | 3 | ▶ | qw(looks_like_number looks_like_implementor looks_like_instance); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | our ( $LOOKUP, $MISSING, $GAP ); | |||||||||||||||||||||||||||
| 8 | { | ||||||||||||||||||||||||||||
| 9 | 3 | my $logger = __PACKAGE__->get_logger; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Bio::Phylo::Matrices::Datatype::Continuous - Validator subclass, | ||||||||||||||||||||||||||||
| 14 | no serviceable parts inside | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | The Bio::Phylo::Matrices::Datatype::* classes are used to validated data | ||||||||||||||||||||||||||||
| 19 | contained by L<Bio::Phylo::Matrices::Matrix> and L<Bio::Phylo::Matrices::Datum> | ||||||||||||||||||||||||||||
| 20 | objects. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head2 MUTATORS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =over | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item set_lookup() | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Sets the lookup table (no-op for continuous data!). | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Type : Mutator | ||||||||||||||||||||||||||||
| 33 | Title : set_lookup | ||||||||||||||||||||||||||||
| 34 | Usage : $obj->set_gap($hashref); | ||||||||||||||||||||||||||||
| 35 | Function: Sets the symbol for gaps | ||||||||||||||||||||||||||||
| 36 | Returns : Modified object. | ||||||||||||||||||||||||||||
| 37 | Args : Argument must be a hash | ||||||||||||||||||||||||||||
| 38 | reference that maps allowed | ||||||||||||||||||||||||||||
| 39 | single character symbols | ||||||||||||||||||||||||||||
| 40 | (including ambiguity symbols) | ||||||||||||||||||||||||||||
| 41 | onto the equivalent set of | ||||||||||||||||||||||||||||
| 42 | non-ambiguous symbols | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub set_lookup { | ||||||||||||||||||||||||||
|
Subroutine
set_lookup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | $logger->info("Can't set lookup table for continuous characters"); | |||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head2 ACCESSORS | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =over | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =item get_lookup() | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Gets the lookup table (no-op for continuous data!). | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Type : Accessor | ||||||||||||||||||||||||||||
| 62 | Title : get_lookup | ||||||||||||||||||||||||||||
| 63 | Usage : my $lookup = $obj->get_lookup; | ||||||||||||||||||||||||||||
| 64 | Function: Returns the object's lookup hash | ||||||||||||||||||||||||||||
| 65 | Returns : A hash reference | ||||||||||||||||||||||||||||
| 66 | Args : None | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 15 | ▶ | sub get_lookup { | ||||||||||||||||||||||||||
|
Subroutine
get_lookup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 15 | $logger->info("Can't get lookup table for continuous characters"); | |||||||||||||||||||||||||||
| 72 | 15 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =back | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 TESTS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =over | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item is_valid() | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Validates arguments for data validity. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Type : Test | ||||||||||||||||||||||||||||
| 86 | Title : is_valid | ||||||||||||||||||||||||||||
| 87 | Usage : if ( $obj->is_valid($datum) ) { | ||||||||||||||||||||||||||||
| 88 | # do something | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | Function: Returns true if $datum only contains valid characters | ||||||||||||||||||||||||||||
| 91 | Returns : BOOLEAN | ||||||||||||||||||||||||||||
| 92 | Args : A list of Bio::Phylo::Matrices::Datum object, and/or | ||||||||||||||||||||||||||||
| 93 | character array references, and/or character strings, | ||||||||||||||||||||||||||||
| 94 | and/or single characters | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 20 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 20 | my @data; | |||||||||||||||||||||||||||
| 101 | 20 | for my $arg (@_) { | |||||||||||||||||||||||||||
| 102 | 33 | ▶ | if ( looks_like_implementor $arg, 'get_char' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 103 | 9 | push @data, $arg->get_char; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | elsif ( looks_like_instance $arg, 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 106 | 0 | push @data, @{$arg}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 24 | push @data, @{ $self->split($arg) }; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 20 | my $missing = $self->get_missing; | |||||||||||||||||||||||||||
| 113 | 20 | CHAR_CHECK: for my $char (@data) { | |||||||||||||||||||||||||||
| 114 | 25 | ▶ | if ( looks_like_number $char || $char eq $missing ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&looks_like_number($char) or $char eq $missing
MC/DC50%1/2
&looks_like_number($char) or $char eq $missing
&looks_like_number($char)
$char eq $missing
Truth table66%2/3
A or B
A= &looks_like_number($char)B= $char eq $missing
| |||||||||||||||||||||||||||||
| 115 | 23 | next CHAR_CHECK; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||
| 118 | 2 | return 0; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 18 | return 1; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =back | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 UTILITY METHODS | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =over | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =item split() | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Splits string of characters on whitespaces. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Type : Utility method | ||||||||||||||||||||||||||||
| 135 | Title : split | ||||||||||||||||||||||||||||
| 136 | Usage : $obj->split($string) | ||||||||||||||||||||||||||||
| 137 | Function: Splits $string into characters | ||||||||||||||||||||||||||||
| 138 | Returns : An array reference of characters | ||||||||||||||||||||||||||||
| 139 | Args : A string | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 31 | ▶ | sub split { | ||||||||||||||||||||||||||
|
Subroutine
split: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 31 | my ( $self, $string ) = @_; | |||||||||||||||||||||||||||
| 145 | 31 | my @array = CORE::split( /\s+/, $string ); | |||||||||||||||||||||||||||
| 146 | 31 | return \@array; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =item join() | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Joins array ref of characters to a space-separated string. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Type : Utility method | ||||||||||||||||||||||||||||
| 154 | Title : join | ||||||||||||||||||||||||||||
| 155 | Usage : $obj->join($arrayref) | ||||||||||||||||||||||||||||
| 156 | Function: Joins $arrayref into a string | ||||||||||||||||||||||||||||
| 157 | Returns : A string | ||||||||||||||||||||||||||||
| 158 | Args : An array reference | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 6 | ▶ | sub join { | ||||||||||||||||||||||||||
|
Subroutine
join: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 6 | my ( $self, $array ) = @_; | |||||||||||||||||||||||||||
| 164 | 6 | return CORE::join ' ', @{$array}; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 3 | $MISSING = '?'; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =back | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # podinherit_insert_token | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||||||||||||
| 177 | for any user or developer questions and discussions. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =over | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =item L<Bio::Phylo::Matrices::Datatype> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | This object inherits from L<Bio::Phylo::Matrices::Datatype>, so the methods defined | ||||||||||||||||||||||||||||
| 184 | therein are also applicable to L<Bio::Phylo::Matrices::Datatype::Continuous> | ||||||||||||||||||||||||||||
| 185 | objects. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item L<Bio::Phylo::Manual> | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =back | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head1 CITATION | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||||||||||||
| 198 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||||||||||||
| 199 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||||||||||||
| 200 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =cut | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | 3 | 1; | |||||||||||||||||||||||||||