| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # bioperl module for Bio::PrimaryQual | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||
| 6 | # Cared for by Chad Matsalla <bioinformatics@dieselwurks.com> | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # Copyright Chad Matsalla | ||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | Bio::Seq::PrimaryQual - Bioperl lightweight Quality Object | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | use Bio::Seq::PrimaryQual; | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # you can use either a space-delimited string for quality | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | my $string_quals = "10 20 30 40 50 40 30 20 10"; | ||||||||||||||||||||||||||||||||
| 25 | my $qualobj = Bio::Seq::PrimaryQual->new( | ||||||||||||||||||||||||||||||||
| 26 | -qual => $string_quals, | ||||||||||||||||||||||||||||||||
| 27 | -id => 'QualityFragment-12', | ||||||||||||||||||||||||||||||||
| 28 | -accession_number => 'X78121', | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | # _or_ you can use an array of quality values | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | my @q2 = split/ /,$string_quals; | ||||||||||||||||||||||||||||||||
| 34 | $qualobj = Bio::Seq::PrimaryQual->new( | ||||||||||||||||||||||||||||||||
| 35 | -qual => \@q2, | ||||||||||||||||||||||||||||||||
| 36 | -primary_id => 'chads primary_id', | ||||||||||||||||||||||||||||||||
| 37 | -desc => 'chads desc', | ||||||||||||||||||||||||||||||||
| 38 | -accession_number => 'chads accession_number', | ||||||||||||||||||||||||||||||||
| 39 | -id => 'chads id' | ||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | # to get the quality values out: | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | my @quals = @{$qualobj->qual()}; | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | # to give _new_ quality values | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | my $newqualstring = "50 90 1000 20 12 0 0"; | ||||||||||||||||||||||||||||||||
| 49 | $qualobj->qual($newqualstring); | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | This module provides a mechanism for storing quality | ||||||||||||||||||||||||||||||||
| 55 | values. Much more useful as part of | ||||||||||||||||||||||||||||||||
| 56 | Bio::Seq::Quality where these quality values | ||||||||||||||||||||||||||||||||
| 57 | are associated with the sequence information. | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||
| 64 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||
| 65 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||
| 68 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | =head2 Support | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||
| 77 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||
| 78 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||
| 79 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||
| 84 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||||
| 85 | web: | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | =head1 AUTHOR - Chad Matsalla | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | Email bioinformatics@dieselwurks.com | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | package Bio::Seq::PrimaryQual; | ||||||||||||||||||||||||||||||||
| 101 | 8 | $Bio::Seq::PrimaryQual::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||
| 102 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 8 | ▶ | use base qw(Bio::Root::Root Bio::Seq::QualI); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 8 | our $MATCHPATTERN = '0-9eE\.\s+-'; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | =head2 new() | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | Title : new() | ||||||||||||||||||||||||||||||||
| 112 | Usage : $qual = Bio::Seq::PrimaryQual->new( | ||||||||||||||||||||||||||||||||
| 113 | -qual => '10 20 30 40 50 50 20 10', | ||||||||||||||||||||||||||||||||
| 114 | -id => 'human_id', | ||||||||||||||||||||||||||||||||
| 115 | -accession_number => 'AL000012', | ||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | Function: Returns a new Bio::Seq::PrimaryQual object from basic | ||||||||||||||||||||||||||||||||
| 119 | constructors, being a string _or_ a reference to an array for the | ||||||||||||||||||||||||||||||||
| 120 | sequence and strings for id and accession_number. Note that you | ||||||||||||||||||||||||||||||||
| 121 | can provide an empty quality string. | ||||||||||||||||||||||||||||||||
| 122 | Returns : a new Bio::Seq::PrimaryQual object | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 127 | 11 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||
| 128 | 11 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | # default: turn ON the warnings (duh) | ||||||||||||||||||||||||||||||||
| 131 | 11 | my($qual,$id,$acc,$pid,$desc,$given_id,$header) = | |||||||||||||||||||||||||||||||
| 132 | $self->_rearrange([qw(QUAL | ||||||||||||||||||||||||||||||||
| 133 | DISPLAY_ID | ||||||||||||||||||||||||||||||||
| 134 | ACCESSION_NUMBER | ||||||||||||||||||||||||||||||||
| 135 | PRIMARY_ID | ||||||||||||||||||||||||||||||||
| 136 | DESC | ||||||||||||||||||||||||||||||||
| 137 | ID | ||||||||||||||||||||||||||||||||
| 138 | HEADER | ||||||||||||||||||||||||||||||||
| 139 | )], | ||||||||||||||||||||||||||||||||
| 140 | @args); | ||||||||||||||||||||||||||||||||
| 141 | 11 | ▶ | if( defined $id && defined $given_id ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $id and defined $given_id
MC/DC50%1/2
defined $id and defined $given_id
defined $id
defined $given_id
Truth table66%2/3
A and B
A= defined $idB= defined $given_id
| |||||||||||||||||||||||||||||||||
| 142 | 8 | ▶ | if( $id ne $given_id ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 0 | $self->throw("Provided both id and display_id constructor functions. [$id] [$given_id]"); | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | 11 | ▶ | if( defined $given_id ) { $id = $given_id; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | # note: the sequence string may be empty | ||||||||||||||||||||||||||||||||
| 149 | 11 | ▶ | $self->qual(defined($qual) ? $qual : []); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 11 | ▶ | $header && $self->header($header); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | 11 | ▶ | $id && $self->display_id($id); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | 11 | ▶ | $acc && $self->accession_number($acc); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 11 | ▶ | $pid && $self->primary_id($pid); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 11 | ▶ | $desc && $self->desc($desc); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 11 | return $self; | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | =head2 qual() | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | Title : qual() | ||||||||||||||||||||||||||||||||
| 163 | Usage : @quality_values = @{$obj->qual()}; | ||||||||||||||||||||||||||||||||
| 164 | Function: Get or set the quality as a reference to an array containing the | ||||||||||||||||||||||||||||||||
| 165 | quality values. An error is generated if the quality scores are | ||||||||||||||||||||||||||||||||
| 166 | invalid, see validate_qual(). | ||||||||||||||||||||||||||||||||
| 167 | Returns : A reference to an array. | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 30 | ▶ | sub qual { | ||||||||||||||||||||||||||||||
|
Subroutine
qual: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 172 | 30 | my ($self,$value) = @_; | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 30 | ▶ | if( ! defined $value || length($value) == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not defined $value or CORE::length $value == 0
MC/DC50%1/2
not defined $value or CORE::length $value == 0
not defined $value
CORE::length $value == 0
Truth table66%2/3
not(A) or B
A= not defined $valueB= CORE::length $value == 0
| |||||||||||||||||||||||||||||||||
| 175 | 14 | ▶ | $self->{'qual'} ||= []; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"qual"} ||= []
MC/DC0%0/1
$self->{"qual"} ||= []
$self->{"qual"}
Truth table50%1/2
A
A= $self->{"qual"}
| |||||||||||||||||||||||||||||||||
| 176 | } elsif( ref($value) =~ /ARRAY/i ) { | ||||||||||||||||||||||||||||||||
| 177 | # if the user passed in a reference to an array | ||||||||||||||||||||||||||||||||
| 178 | 3 | $self->{'qual'} = $value; | |||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||
| 180 | 13 | $self->validate_qual($value, 1); | |||||||||||||||||||||||||||||||
| 181 | 12 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||||||
| 182 | 12 | $self->{'qual'} = [split(/\s+/,$value)]; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 29 | return $self->{'qual'}; | |||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | =head2 seq() | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | Title : seq() | ||||||||||||||||||||||||||||||||
| 192 | Usager : $sequence = $obj->seq(); | ||||||||||||||||||||||||||||||||
| 193 | Function : Returns the quality numbers as a space-separated string. | ||||||||||||||||||||||||||||||||
| 194 | Returns : Single string. | ||||||||||||||||||||||||||||||||
| 195 | Args : None. | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub seq { | ||||||||||||||||||||||||||||||
|
Subroutine
seq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 200 | 0 | return join ' ', @{ shift->qual }; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | =head2 validate_qual($qualstring) | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | Title : validate_qual($qualstring) | ||||||||||||||||||||||||||||||||
| 207 | Usage : print("Valid.") if { &validate_qual($self, $quality_string); } | ||||||||||||||||||||||||||||||||
| 208 | Function: Test that the given quality string is valid. It is expected to | ||||||||||||||||||||||||||||||||
| 209 | contain space-delimited numbers that can be parsed using split /\d+/. | ||||||||||||||||||||||||||||||||
| 210 | However, this validation takes shortcuts and only tests that the | ||||||||||||||||||||||||||||||||
| 211 | string contains characters valid in numbers: 0-9 . eE +- | ||||||||||||||||||||||||||||||||
| 212 | Note that empty quality strings are valid too. | ||||||||||||||||||||||||||||||||
| 213 | Returns : 1 for a valid sequence, 0 otherwise | ||||||||||||||||||||||||||||||||
| 214 | Args : - Scalar containing the quality string to validate. | ||||||||||||||||||||||||||||||||
| 215 | - Boolean to optionally throw an error if validation failed | ||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | 25 | ▶ | sub validate_qual { | ||||||||||||||||||||||||||||||
|
Subroutine
validate_qual: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 220 | 25 | my ($self, $qualstr, $throw) = @_; | |||||||||||||||||||||||||||||||
| 221 | 25 | ▶ | if ( (defined $qualstr ) && | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $qualstr and not $qualstr =~ /^[$Bio::Seq::PrimaryQual::MATCHPATTERN]*$/
MC/DC100%2/2
defined $qualstr and not $qualstr =~ /^[$Bio::Seq::PrimaryQual::MATCHPATTERN]*$/
defined $qualstr
not $qualstr =~ /^[$Bio::Seq::PrimaryQual::MATCHPATTERN]*$/
Truth table100%3/3
A and not(B)
A= defined $qualstrB= not $qualstr =~ /^[$Bio::Seq::PrimaryQual::MATCHPATTERN]*$/
| |||||||||||||||||||||||||||||||||
| 222 | ($qualstr !~ /^[$MATCHPATTERN]*$/) ) { | ||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | if ($throw) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | $self->throw("Failed validation of quality score from '". | ||||||||||||||||||||||||||||||
|
Condition50%1/2
defined $self->id || '[unidentified sequence]'
MC/DC0%0/1
defined $self->id || '[unidentified sequence]'
defined $self->id
Truth table50%1/2
A
A= defined $self->id
| |||||||||||||||||||||||||||||||||
| 225 | (defined($self->id)||'[unidentified sequence]')."'. No numeric ". | ||||||||||||||||||||||||||||||||
| 226 | "value found.\n"); | ||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | 2 | return 0; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | 22 | return 1; | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | =head2 subqual($start,$end) | ||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | Title : subqual($start,$end) | ||||||||||||||||||||||||||||||||
| 237 | Usage : @subset_of_quality_values = @{$obj->subqual(10,40)}; | ||||||||||||||||||||||||||||||||
| 238 | Function: returns the quality values from $start to $end, where the | ||||||||||||||||||||||||||||||||
| 239 | first value is 1 and the number is inclusive, ie 1-2 are the | ||||||||||||||||||||||||||||||||
| 240 | first two bases of the sequence. Start cannot be larger than | ||||||||||||||||||||||||||||||||
| 241 | end but can be equal. | ||||||||||||||||||||||||||||||||
| 242 | Returns : A reference to an array. | ||||||||||||||||||||||||||||||||
| 243 | Args : a start position and an end position | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | =cut | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | sub subqual { | ||||||||||||||||||||||||||||||
|
Subroutine
subqual: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 248 | 2 | my ($self,$start,$end) = @_; | |||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | if( $start > $end ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 251 | 0 | $self->throw("in subqual, start [$start] has to be greater than end [$end]"); | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | if( $start <= 0 || $end > $self->length ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$start <= 0 or $end > $self->length
MC/DC0%0/2
$start <= 0 or $end > $self->length
$start <= 0
$end > $self->length
Truth table33%1/3
A or B
A= $start <= 0B= $end > $self->length
| |||||||||||||||||||||||||||||||||
| 255 | 0 | $self->throw("You have to have start positive and length less than the total length of sequence [$start:$end] Total ".$self->length.""); | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | # remove one from start, and then length is end-start | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 2 | $start--; | |||||||||||||||||||||||||||||||
| 261 | 2 | $end--; | |||||||||||||||||||||||||||||||
| 262 | 2 | my @sub_qual_array = @{$self->{qual}}[$start..$end]; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | # return substr $self->seq(), $start, ($end-$start); | ||||||||||||||||||||||||||||||||
| 265 | 2 | return \@sub_qual_array; | |||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | =head2 display_id() | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | Title : display_id() | ||||||||||||||||||||||||||||||||
| 273 | Usage : $id_string = $obj->display_id(); | ||||||||||||||||||||||||||||||||
| 274 | Function: returns the display id, aka the common name of the Quality | ||||||||||||||||||||||||||||||||
| 275 | object. | ||||||||||||||||||||||||||||||||
| 276 | The semantics of this is that it is the most likely string to be | ||||||||||||||||||||||||||||||||
| 277 | used as an identifier of the quality sequence, and likely to have | ||||||||||||||||||||||||||||||||
| 278 | "human" readability. The id is equivalent to the ID field of the | ||||||||||||||||||||||||||||||||
| 279 | GenBank/EMBL databanks and the id field of the Swissprot/sptrembl | ||||||||||||||||||||||||||||||||
| 280 | database. In fasta format, the >(\S+) is presumed to be the id, | ||||||||||||||||||||||||||||||||
| 281 | though some people overload the id to embed other information. | ||||||||||||||||||||||||||||||||
| 282 | Bioperl does not use any embedded information in the ID field, | ||||||||||||||||||||||||||||||||
| 283 | and people are encouraged to use other mechanisms (accession | ||||||||||||||||||||||||||||||||
| 284 | field for example, or extending the sequence object) to solve | ||||||||||||||||||||||||||||||||
| 285 | this. Notice that $seq->id() maps to this function, mainly for | ||||||||||||||||||||||||||||||||
| 286 | legacy/convience issues | ||||||||||||||||||||||||||||||||
| 287 | Returns : A string | ||||||||||||||||||||||||||||||||
| 288 | Args : None | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 16 | ▶ | sub display_id { | ||||||||||||||||||||||||||||||
|
Subroutine
display_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 293 | 16 | my ($obj,$value) = @_; | |||||||||||||||||||||||||||||||
| 294 | 16 | ▶ | if( defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 295 | 11 | $obj->{'display_id'} = $value; | |||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | 16 | return $obj->{'display_id'}; | |||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | =head2 header() | ||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | Title : header() | ||||||||||||||||||||||||||||||||
| 304 | Usage : $header = $obj->header(); | ||||||||||||||||||||||||||||||||
| 305 | Function: Get/set the header that the user wants printed for this | ||||||||||||||||||||||||||||||||
| 306 | quality object. | ||||||||||||||||||||||||||||||||
| 307 | Returns : A string | ||||||||||||||||||||||||||||||||
| 308 | Args : None | ||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | =cut | ||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 9 | ▶ | sub header { | ||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 313 | 9 | my ($obj,$value) = @_; | |||||||||||||||||||||||||||||||
| 314 | 9 | ▶ | if( defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 3 | $obj->{'header'} = $value; | |||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||
| 317 | 9 | return $obj->{'header'}; | |||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | =head2 accession_number() | ||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | Title : accession_number() | ||||||||||||||||||||||||||||||||
| 325 | Usage : $unique_biological_key = $obj->accession_number(); | ||||||||||||||||||||||||||||||||
| 326 | Function: Returns the unique biological id for a sequence, commonly | ||||||||||||||||||||||||||||||||
| 327 | called the accession_number. For sequences from established | ||||||||||||||||||||||||||||||||
| 328 | databases, the implementors should try to use the correct | ||||||||||||||||||||||||||||||||
| 329 | accession number. Notice that primary_id() provides the unique id | ||||||||||||||||||||||||||||||||
| 330 | for the implementation, allowing multiple objects to have the same | ||||||||||||||||||||||||||||||||
| 331 | accession number in a particular implementation. For sequences | ||||||||||||||||||||||||||||||||
| 332 | with no accession number, this method should return "unknown". | ||||||||||||||||||||||||||||||||
| 333 | Returns : A string | ||||||||||||||||||||||||||||||||
| 334 | Args : None | ||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | 4 | ▶ | sub accession_number { | ||||||||||||||||||||||||||||||
|
Subroutine
accession_number: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 339 | 4 | my( $obj, $acc ) = @_; | |||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | 4 | ▶ | if (defined $acc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 342 | 2 | $obj->{'accession_number'} = $acc; | |||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||
| 344 | 2 | $acc = $obj->{'accession_number'}; | |||||||||||||||||||||||||||||||
| 345 | 2 | ▶ | $acc = 'unknown' unless defined $acc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | 4 | return $acc; | |||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||
| 351 | =head2 primary_id() | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | Title : primary_id() | ||||||||||||||||||||||||||||||||
| 354 | Usage : $unique_implementation_key = $obj->primary_id(); | ||||||||||||||||||||||||||||||||
| 355 | Function: Returns the unique id for this object in this implementation. | ||||||||||||||||||||||||||||||||
| 356 | This allows implementations to manage their own object ids in a | ||||||||||||||||||||||||||||||||
| 357 | way the implementation can control clients can expect one id to | ||||||||||||||||||||||||||||||||
| 358 | map to one object. For sequences with no accession number, this | ||||||||||||||||||||||||||||||||
| 359 | method should return a stringified memory location. | ||||||||||||||||||||||||||||||||
| 360 | Returns : A string | ||||||||||||||||||||||||||||||||
| 361 | Args : None | ||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||
| 363 | =cut | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 10 | ▶ | sub primary_id { | ||||||||||||||||||||||||||||||
|
Subroutine
primary_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 366 | 10 | my ($obj,$value) = @_; | |||||||||||||||||||||||||||||||
| 367 | 10 | ▶ | if( defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 368 | 9 | $obj->{'primary_id'} = $value; | |||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||
| 370 | 10 | return $obj->{'primary_id'}; | |||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | =head2 desc() | ||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | Title : desc() | ||||||||||||||||||||||||||||||||
| 377 | Usage : $qual->desc($newval); | ||||||||||||||||||||||||||||||||
| 378 | $description = $qual->desc(); | ||||||||||||||||||||||||||||||||
| 379 | Function: Get/set description text for a qual object | ||||||||||||||||||||||||||||||||
| 380 | Example : | ||||||||||||||||||||||||||||||||
| 381 | Returns : Value of desc | ||||||||||||||||||||||||||||||||
| 382 | Args : newvalue (optional) | ||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | =cut | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | 3 | ▶ | sub desc { | ||||||||||||||||||||||||||||||
|
Subroutine
desc: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 387 | 3 | my ($obj,$value) = @_; | |||||||||||||||||||||||||||||||
| 388 | 3 | ▶ | if( defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 389 | 1 | $obj->{'desc'} = $value; | |||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||
| 391 | 3 | return $obj->{'desc'}; | |||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | =head2 id() | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | Title : id() | ||||||||||||||||||||||||||||||||
| 398 | Usage : $id = $qual->id(); | ||||||||||||||||||||||||||||||||
| 399 | Function: Return the ID of the quality. This should normally be (and | ||||||||||||||||||||||||||||||||
| 400 | actually is in the implementation provided here) just a synonym | ||||||||||||||||||||||||||||||||
| 401 | for display_id(). | ||||||||||||||||||||||||||||||||
| 402 | Returns : A string. | ||||||||||||||||||||||||||||||||
| 403 | Args : None. | ||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | 6 | ▶ | sub id { | ||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 408 | 6 | my ($self,$value) = @_; | |||||||||||||||||||||||||||||||
| 409 | 6 | ▶ | if( defined $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 410 | 1 | return $self->display_id($value); | |||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||
| 412 | 5 | return $self->display_id(); | |||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | =head2 length() | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | Title : length() | ||||||||||||||||||||||||||||||||
| 419 | Usage : $length = $qual->length(); | ||||||||||||||||||||||||||||||||
| 420 | Function: Return the length of the array holding the quality values. | ||||||||||||||||||||||||||||||||
| 421 | Under most circumstances, this should match the number of quality | ||||||||||||||||||||||||||||||||
| 422 | values but no validation is done when the PrimaryQual object is | ||||||||||||||||||||||||||||||||
| 423 | constructed and non-digits could be put into this array. Is this | ||||||||||||||||||||||||||||||||
| 424 | a bug? Just enough rope... | ||||||||||||||||||||||||||||||||
| 425 | Returns : A scalar (the number of elements in the quality array). | ||||||||||||||||||||||||||||||||
| 426 | Args : None. | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | =cut | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 4 | ▶ | sub length { | ||||||||||||||||||||||||||||||
|
Subroutine
length: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 431 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 432 | 4 | ▶ | if (ref($self->{qual}) ne "ARRAY") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 433 | 0 | $self->warn("{qual} is not an array here. Why? It appears to be ".ref($self->{qual})."(".$self->{qual}."). Good thing this can _never_ happen."); | |||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||
| 435 | 4 | return scalar(@{$self->{qual}}); | |||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | =head2 qualat() | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | Title : qualat | ||||||||||||||||||||||||||||||||
| 442 | Usage : $quality = $obj->qualat(10); | ||||||||||||||||||||||||||||||||
| 443 | Function: Return the quality value at the given location, where the | ||||||||||||||||||||||||||||||||
| 444 | first value is 1 and the number is inclusive, ie 1-2 are the first | ||||||||||||||||||||||||||||||||
| 445 | two bases of the sequence. Start cannot be larger than end but can | ||||||||||||||||||||||||||||||||
| 446 | be equal. | ||||||||||||||||||||||||||||||||
| 447 | Returns : A scalar. | ||||||||||||||||||||||||||||||||
| 448 | Args : A position. | ||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||
| 450 | =cut | ||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | sub qualat { | ||||||||||||||||||||||||||||||
|
Subroutine
qualat: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 453 | 1 | my ($self,$val) = @_; | |||||||||||||||||||||||||||||||
| 454 | 1 | my @qualat = @{$self->subqual($val,$val)}; | |||||||||||||||||||||||||||||||
| 455 | 1 | ▶ | if (scalar(@qualat) == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 456 | 1 | return $qualat[0]; | |||||||||||||||||||||||||||||||
| 457 | } else { | ||||||||||||||||||||||||||||||||
| 458 | 0 | $self->throw("qualat() provided more than one quality."); | |||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | =head2 to_string() | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | Title : to_string() | ||||||||||||||||||||||||||||||||
| 465 | Usage : $quality = $obj->to_string(); | ||||||||||||||||||||||||||||||||
| 466 | Function: Return a textual representation of what the object contains. | ||||||||||||||||||||||||||||||||
| 467 | For this module, this function will return: | ||||||||||||||||||||||||||||||||
| 468 | qual | ||||||||||||||||||||||||||||||||
| 469 | display_id | ||||||||||||||||||||||||||||||||
| 470 | accession_number | ||||||||||||||||||||||||||||||||
| 471 | primary_id | ||||||||||||||||||||||||||||||||
| 472 | desc | ||||||||||||||||||||||||||||||||
| 473 | id | ||||||||||||||||||||||||||||||||
| 474 | length | ||||||||||||||||||||||||||||||||
| 475 | Returns : A scalar. | ||||||||||||||||||||||||||||||||
| 476 | Args : None. | ||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||
| 478 | =cut | ||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 481 | 0 | my ($self,$out,$result) = shift; | |||||||||||||||||||||||||||||||
| 482 | 0 | $out = "qual: ".join(',',@{$self->qual()}); | |||||||||||||||||||||||||||||||
| 483 | 0 | foreach (qw(display_id accession_number primary_id desc id length)) { | |||||||||||||||||||||||||||||||
| 484 | 0 | $result = $self->$_(); | |||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if (!$result) { $result = "<unset>"; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 486 | 0 | $out .= "$_: $result\n"; | |||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||
| 488 | 0 | return $out; | |||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | sub to_string_automatic { | ||||||||||||||||||||||||||||||
|
Subroutine
to_string_automatic: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 493 | 0 | my ($self,$sub_result,$out) = shift; | |||||||||||||||||||||||||||||||
| 494 | 0 | foreach (sort keys %$self) { | |||||||||||||||||||||||||||||||
| 495 | 0 | print("Working on $_\n"); | |||||||||||||||||||||||||||||||
| 496 | 0 | eval { $self->$_(); }; | |||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if ($@) { $sub_result = ref($_); } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 498 | elsif (!($sub_result = $self->$_())) { | ||||||||||||||||||||||||||||||||
| 499 | 0 | $sub_result = "<unset>"; | |||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | if (ref($sub_result) eq "ARRAY") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 502 | 0 | print("This thing ($_) is an array!\n"); | |||||||||||||||||||||||||||||||
| 503 | 0 | $sub_result = join(',',@$sub_result); | |||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||
| 505 | 0 | $out .= "$_: ".$sub_result."\n"; | |||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | 0 | return $out; | |||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||
| 510 | 8 | 1; | |||||||||||||||||||||||||||||||