Bio/Seq/Quality.pm

filter: Statementstmt 32.2% 50 / 155 Branchbran 13.6% 9 / 66 Conditioncond 17.6% 3 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 51.7% 15 / 29 Podpod 80.0% 20 / 25 totaltotal 32.1% 97 / 302 CC 42 SCAR 31.5
CC
42
Cov
26%
get_trace_graph
56.0
_find_clear_ranges
56.0
get_all_clean_ranges
42.0
CRAP 23.4
« Bio/AlignIO/phylip.pm ↑ Summary Bio/SeqIO/qual.pm »
1 #
2 # BioPerl module for Bio::Seq::Quality
3 #
4 # Please direct questions and support issues to
5 # <bioperl-l@bioperl.org>
6 #
7 # Cared for by Heikki Lehvaslaiho
8 #
9 # Copyright Heikki Lehvaslaiho
10 #
11 # You may distribute this module under the same terms as perl itself
12  
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Seq::Quality - Implementation of sequence with residue quality
18 and trace values
19  
20 =head1 SYNOPSIS
21  
22 use Bio::Seq::Quality;
23  
24 # input can be space delimited string or array ref
25 my $qual = '0 1 2 3 4 5 6 7 8 9 11 12';
26 my $trace = '0 5 10 15 20 25 30 35 40 45 50 55';
27  
28 my $seq = Bio::Seq::Quality->new
29 ( -qual => $qual,
30 -trace_indices => $trace,
31 -seq => 'atcgatcgatcg',
32 -id => 'human_id',
33 -accession_number => 'S000012',
34 -verbose => -1 # to silence deprecated methods
35 );
36  
37 my $quals = $seq->qual; # array ref
38 my $traces = $seq->trace; # array ref
39  
40 my $quals = $seq->qual_text; # string
41 my $traces = $seq->trace_text; # string
42  
43  
44 # get sub values
45 $quals = $seq->subqual(2, 3); # array ref
46 $traces = $seq->subtrace(2, 3); # array ref
47 $quals = $seq->subqual_text(2, 3); # string
48 $quals = $seq->subtrace_text(2, 3); # string
49  
50 # set sub values
51 $seq->subqual(2, 3, "9 9");
52 $seq->subtrace(2, 3, "9 9");
53  
54  
55  
56 =head1 DESCRIPTION
57  
58 This object stores base quality values together with the sequence
59 string.
60  
61 The implementation is based on Bio::Seq::Meta::Array. qual() and
62 trace() are base methods to store and retrieve information that have
63 extensions to retrieve values as a scalar (e.g. qual_text() ), or get
64 or set subvalues (e.g. subqual() ). See L<Bio::Seq::MetaI> for more
65 details.
66  
67 All the functional code is in Bio::Seq::Meta::Array.
68  
69 There deprecated methods that are included for compatibility with
70 Bio::Seq::SeqWithQuality. These will print a warning unless verbosity
71 of the object is set to be less than zero.
72  
73 =head1 SEE ALSO
74  
75 L<Bio::Seq::MetaI>,
76 L<Bio::Seq::Meta::Array>
77  
78 =head1 FEEDBACK
79  
80 =head2 Mailing Lists
81  
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to one
84 of the Bioperl mailing lists. Your participation is much appreciated.
85  
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
88  
89 =head2 Support
90  
91 Please direct usage questions or support issues to the mailing list:
92  
93 I<bioperl-l@bioperl.org>
94  
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
99  
100 =head2 Reporting Bugs
101  
102 Report bugs to the Bioperl bug tracking system to help us keep track
103 the bugs and their resolution. Bug reports can be submitted via the
104 web:
105  
106 https://github.com/bioperl/bioperl-live/issues
107  
108 =head1 AUTHOR - Heikki Lehvaslaiho
109  
110 Email heikki-at-bioperl-dot-org
111  
112 =head1 CONTRIBUTORS
113  
114 Chad Matsalla, bioinformatics at dieselwurks dot com
115  
116 Dan Bolser, dan dot bolser at gmail dot com
117  
118 =head1 APPENDIX
119  
120 The rest of the documentation details each of the object methods.
121 Internal methods are usually preceded with a _
122  
123 =cut
124  
125  
126 # Let the code begin...
127  
128  
129 package Bio::Seq::Quality;
130 12 $Bio::Seq::Quality::VERSION = '1.7.8';
131 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 12 ▶use base qw(Bio::Seq::Meta::Array);
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 ## Is this the right place (and way) to define this?
136 12 our $MASK_CHAR = 'X';
137 12 our $DEFAULT_NAME = 'DEFAULT';
138 12 our $GAP = '-';
139 12 our $META_GAP = ' ';
140  
141 =head2 new
142  
143 Title : new
144 Usage : $metaseq = Bio::Seq::Quality->new
145 ( -qual => '0 1 2 3 4 5 6 7 8 9 11 12',
146 -trace => '0 5 10 15 20 25 30 35 40 45 50 55',
147 -seq => 'atcgatcgatcg',
148 -id => 'human_id',
149 -accession_number => 'S000012',
150 );
151 Function: Constructor for Bio::Seq::Quality class. Note that you can
152 provide an empty quality and trace strings.
153  
154 Returns : a new Bio::Seq::Quality object
155  
156 =cut
157  
158  
159 366 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
160 366 my ($class, @args) = @_;
161  
162 366 my $self = $class->SUPER::new(@args);
163  
164 366 my($meta, $qual, $trace, $trace_indices, $trace_data) =
165 $self->_rearrange([qw(META
166 QUAL
167 TRACE
168 TRACE_INDICES
169 TRACE_DATA)],
170 @args);
171  
172 366 $self->{'_meta'}->{$DEFAULT_NAME} = [];
173 366 $self->{'_meta'}->{'trace'} = [];
174 366 $self->{trace_data} = $trace_data;
175  
176 366 ▶ $meta && $self->meta($meta);
Branch: 1 branch
BranchTrueFalseTotal
$meta and $self->meta($meta) 0 366 366
177 366 ▶ $qual && $self->qual($qual);
Branch: 1 branch
BranchTrueFalseTotal
$qual and $self->qual($qual) 327 39 366
178 366 ▶ $trace && $self->named_meta('trace', $trace);
Branch: 1 branch
BranchTrueFalseTotal
$trace and $self->named_meta("trace", $trace) 1 365 366
179 366 ▶ $trace_indices && $self->named_meta('trace', $trace_indices);
Branch: 1 branch
BranchTrueFalseTotal
$trace_indices and $self->named_meta("trace", $trace_indices) 0 366 366
180  
181 366 return $self;
182 }
183  
184  
185  
186 ## QUAL
187  
188 =head2 qual
189  
190 Title : qual
191 Usage : $qual_values = $obj->qual($values_string);
192 Function:
193  
194 Get and set method for the meta data starting from residue
195 position one. Since it is dependent on the length of the
196 sequence, it needs to be manipulated after the sequence.
197  
198 The length of the returned value always matches the length
199 of the sequence.
200  
201 Returns : reference to an array of meta data
202 Args : new value, string or array ref or Bio::Seq::PrimaryQual, optional
203  
204 Setting quality values resets the clear range.
205  
206 =cut
207  
208 414 ▶sub qual {
Subroutine qual: called CC=5 SCAR=17.0
Pod documented
209 414 my $self = shift;
210 414 my $value = shift;
211 414 ▶ $value = $value->qual
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and ref $value ne "ARRAY" and $value->isa("Bio::Seq::PrimaryQual") 0 414 414
Condition50%3/6
ref $value and ref $value ne "ARRAY" and $value->isa("Bio::Seq::PrimaryQual")
!ll&&!rl&&r
41400
ref $value and ref $value ne "ARRAY"
!ll&&!rl&&r
623520
MC/DC0%0/3
ref $value and ref $value ne "ARRAY" and $value->isa("Bio::Seq::PrimaryQual")
ref $value ref $value ne "ARRAY" $value->isa("Bio::Seq::PrimaryQual")
Truth table50%2/4
A and B and C
A= ref $valueB= ref $value ne "ARRAY"C= $value->isa("Bio::Seq::PrimaryQual")
ABCresult
0XX0
10X0
1100
1111
212 if ref($value) and ref($value) ne 'ARRAY' and
213 $value->isa('Bio::Seq::PrimaryQual');
214 414 ▶ $self->_empty_cache if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 356 58 414
215 414 return $self->named_meta($DEFAULT_NAME, $value);
216 }
217  
218 =head2 qual_text
219  
220 Title : qual_text
221 Usage : $qual_values = $obj->qual_text($values_arrayref);
222 Function: Variant of meta() and qual() guarantied to return a string
223 representation of meta data. For details, see L<meta>.
224 Returns : a string
225 Args : new value, optional
226  
227 =cut
228  
229 0 ▶sub qual_text {
Subroutine qual_text: not called CC=1 SCAR=6.9
Pod documented
230 0 return join ' ', @{shift->named_submeta($DEFAULT_NAME, @_)};
231 }
232  
233 =head2 subqual
234  
235 Title : subqual
236 Usage : $subset_of_qual_values = $obj->subqual(10, 20, $value_string);
237 $subset_of_qual_values = $obj->subqual(10, undef, $value_string);
238 Function:
239  
240 Get and set method for meta data for subsequences.
241  
242 Numbering starts from 1 and the number is inclusive, ie 1-2
243 are the first two residue of the sequence. Start cannot be
244 larger than end but can be equal.
245  
246 If the second argument is missing the returned values
247 should extend to the end of the sequence.
248  
249 Returns : A reference to an array
250 Args : integer, start position
251 integer, end position, optional when a third argument present
252 new value, optional
253  
254 =cut
255  
256 3 ▶sub subqual {
Subroutine subqual: called CC=1 SCAR=0.0
Pod documented
257 3 shift->named_submeta($DEFAULT_NAME, @_);
258 }
259  
260 =head2 subqual_text
261  
262 Title : subqual_text
263 Usage : $meta_values = $obj->subqual_text(20, $value_string);
264 Function: Variant of subqual() returning a stringified
265 representation of meta data. For details, see L<Bio::Seq::MetaI>.
266 Returns : a string
267 Args : new value, optional
268  
269 =cut
270  
271 3 ▶sub subqual_text {
Subroutine subqual_text: called CC=1 SCAR=0.0
Pod documented
272 3 return join ' ', @{shift->named_submeta($DEFAULT_NAME, @_)};
273 }
274  
275 =head2 quality_length
276  
277 Title : quality_length()
278 Usage : $qual_len = $obj->quality_length();
279 Function: return the number of elements in the quality array
280 Returns : integer
281 Args : -
282  
283 =cut
284  
285 0 ▶sub quality_length {
Subroutine quality_length: not called CC=1 SCAR=6.9
Pod documented
286 0 my ($self) = @_;
287 0 return $self->named_meta_length($DEFAULT_NAME);
288 }
289  
290 =head2 quality_is_flush
291  
292 Title : quality_is_flush
293 Usage : $quality_is_flush = $obj->quality_is_flush()
294 Function: Boolean to tell if the trace length equals the sequence length.
295 Returns true if force_flush() is set.
296 Returns : boolean 1 or 0
297 Args : none
298  
299 =cut
300  
301 1 ▶sub quality_is_flush {
Subroutine quality_is_flush: called CC=1 SCAR=0.0
Pod documented
302 1 return shift->is_flush('quality');
303 }
304  
305  
306  
307 ## TRACE
308  
309 =head2 trace
310  
311 Title : trace
312 Usage : $trace_values = $obj->trace($values_string);
313 Function:
314  
315 Get and set method for the meta data starting from residue
316 position one. Since it is dependent on the length of the
317 sequence, it needs to be manipulated after the sequence.
318  
319 The length of the returned value always matches the length
320 of the sequence.
321  
322 Returns : reference to an array of meta data
323 Args : new value, string or array ref, optional
324  
325 =cut
326  
327 6 ▶sub trace {
Subroutine trace: called CC=1 SCAR=0.0
Pod documented
328 6 my $self = shift;
329 6 my $value = shift;
330 6 return $self->named_meta('trace', $value);
331 }
332  
333 =head2 trace_text
334  
335 Title : trace_text
336 Usage : $trace_values = $obj->trace_text($values_arrayref);
337 Function: Variant of meta() and trace() guarantied to return a string
338 representation of meta data. For details, see L<meta>.
339 Returns : a string
340 Args : new value, optional
341  
342 =cut
343  
344 0 ▶sub trace_text {
Subroutine trace_text: not called CC=1 SCAR=6.9
Pod documented
345 0 return join ' ', @{shift->named_submeta('trace', @_)};
346 }
347  
348 =head2 subtrace
349  
350 Title : subtrace
351 Usage : $subset_of_trace_values = $obj->subtrace(10, 20, $value_string);
352 $subset_of_trace_values = $obj->subtrace(10, undef, $value_string);
353 Function:
354  
355 Get and set method for meta data for subsequences.
356  
357 Numbering starts from 1 and the number is inclusive, ie 1-2
358 are the first two residue of the sequence. Start cannot be
359 larger than end but can be equal.
360  
361 If the second argument is missing the returned values
362 should extend to the end of the sequence.
363  
364 Returns : A reference to an array
365 Args : integer, start position
366 integer, end position, optional when a third argument present
367 new value, optional
368  
369  
370 =cut
371  
372 0 ▶sub subtrace {
Subroutine subtrace: not called CC=1 SCAR=6.9
Pod documented
373 0 return shift->named_submeta('trace', @_);
374 }
375  
376 =head2 subtrace_text
377  
378 Title : subtrace_text
379 Usage : $meta_values = $obj->subtrace_text(20, $value_string);
380 Function: Variant of subtrace() returning a stringified
381 representation of meta data. For details, see L<Bio::Seq::MetaI>.
382 Returns : a string
383 Args : new value, optional
384  
385 =cut
386  
387 3 ▶sub subtrace_text {
Subroutine subtrace_text: called CC=1 SCAR=0.0
Pod documented
388 3 return join ' ', @{shift->named_submeta('trace', @_)};
389 }
390  
391 =head2 trace_length
392  
393 Title : trace_length()
394 Usage : $trace_len = $obj->trace_length();
395 Function: return the number of elements in the trace set
396 Returns : integer
397 Args : -
398  
399 =cut
400  
401 1 ▶sub trace_length {
Subroutine trace_length: called CC=1 SCAR=0.0
Pod documented
402 1 my ($self) = @_;
403 1 return $self->named_meta_length('trace');
404 }
405  
406 =head2 trace_is_flush
407  
408 Title : trace_is_flush
409 Usage : $trace_is_flush = $obj->trace_is_flush()
410 Function: Boolean to tell if the trace length equals the sequence length.
411 Returns true if force_flush() is set.
412 Returns : boolean 1 or 0
413 Args : none
414  
415 =cut
416  
417 1 ▶sub trace_is_flush {
Subroutine trace_is_flush: called CC=1 SCAR=0.0
Pod documented
418 1 return shift->is_flush('trace');
419 }
420  
421  
422  
423 =head2 get_trace_graph
424  
425 Title : get_trace_graph
426 Usage : @trace_values = $obj->get_trace_graph( -trace => 'a',
427 -scale => 100)
428 Function : Returns array of raw trace values for a trace file, or
429 false if no trace data exists. Requires a value for trace
430 to get either the a, g, c or t trace information, and an
431 optional value for scale, which rescales the data between
432 0 and the provided value, a scale value of '0' performs no
433 scaling
434 Returns : Array or 0
435 Args : string, trace to retrieve, one of a, g, c or t integer,
436 scale, for scaling of trace between 0 and scale, or 0 for
437 no scaling, optional
438  
439 =cut
440  
441 sub get_trace_graph
442 0 ▶{
Subroutine get_trace_graph: not called CC=7 SCAR=40.3
Pod documented
443 0 my $self = shift;
444 0 my($trace, $scale) =
445 $self->_rearrange([qw(TRACE
446 SCALE
447 )],
448 @_);
449 0 ▶ unless (defined($self->{trace_data})) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"trace_data"}) 0 0 0
450 0 ▶ unless (grep { lc($trace) eq $_ } ('a', 'g', 'c', 't')) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {lc $trace eq $_;} "a", "g", "c", "t") 0 0 0
451 0 $trace = lc($trace) . "_trace";
452 my @trace_data = exists $self->{trace_data}->{$trace} &&
453 ref $self->{trace_data}->{$trace} eq 'ARRAY' ?
454 0 ▶ @{$self->{trace_data}->{$trace}} : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'trace_data'}{$trace} && ref $self->{'trace_data'}{$trace} eq 'ARRAY' ? : 0 0 0
Condition0%0/3
exists $self->{"trace_data"}{$trace} and ref $self->{"trace_data"}{$trace} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"trace_data"}{$trace} and ref $self->{"trace_data"}{$trace} eq "ARRAY"
exists $self->{"trace_data"}{$trace} ref $self->{"trace_data"}{$trace} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $self->{"trace_data"}{$trace}B= ref $self->{"trace_data"}{$trace} eq "ARRAY"
ABresult
0X0
100
111
455 0 my $max = $self->{trace_data}->{max_height};
456 0 ▶ if (defined($scale) and $scale != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scale and $scale != 0) 0 0 0
Condition0%0/3
defined $scale and $scale != 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $scale and $scale != 0
defined $scale $scale != 0
Truth table0%0/3
A and B
A= defined $scaleB= $scale != 0
ABresult
0X0
100
111
457 {
458 0 @trace_data = map { $_ / $max * $scale } @trace_data;
459 }
460 0 return @trace_data;
461 }
462  
463  
464 =head2 threshold
465  
466 Title : threshold
467 Usage : $qual->threshold($value);
468 Function: Sets the quality threshold.
469 Returns : an integer
470 Args : new value, optional
471  
472 Value used by *clear_range* method below.
473  
474 =cut
475  
476 0 ▶sub threshold {
Subroutine threshold: not called CC=5 SCAR=34.0
Pod documented
477 0 my $self = shift;
478 0 my $value = shift;
479 0 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
480 0 ▶ $self->throw("Threshold needs to be an integer [$value]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[-+]?\d+$/ 0 0 0
481 unless $value =~ /^[-+]?\d+$/;
482 $self->_empty_cache
483 0 ▶ if defined $self->{_threshold} and $self->{_threshold} ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_threshold"} and $self->{"_threshold"} ne $value 0 0 0
Condition0%0/3
defined $self->{"_threshold"} and $self->{"_threshold"} ne $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"_threshold"} and $self->{"_threshold"} ne $value
defined $self->{"_threshold"} $self->{"_threshold"} ne $value
Truth table0%0/3
A and B
A= defined $self->{"_threshold"}B= $self->{"_threshold"} ne $value
ABresult
0X0
100
111
484 0 $self->{_threshold} = $value;
485 }
486 0 return $self->{_threshold};
487 }
488  
489  
490 =head2 mask_below_threshold
491  
492 Title : mask_below_threshold
493 Usage : $count = $obj->count_clear_ranges($threshold);
494 Function: Counts number of ranges in the sequence where quality
495 values are above the threshold
496 Returns : count integer
497 Args : threshold integer, optional
498  
499 Set threshold first using method L<threshold>.
500  
501 =cut
502  
503 0 ▶sub mask_below_threshold {
Subroutine mask_below_threshold: not called CC=5 SCAR=34.0
Pod documented
504 0 my $self = shift;
505 0 my $threshold = shift;
506  
507 0 ▶ $self->threshold($threshold) if defined $threshold;
Branch: 1 branch
BranchTrueFalseTotal
if defined $threshold 0 0 0
508  
509 # populate the cache if needed
510 0 ▶ $self->_find_clear_ranges unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
511  
512 0 my $maskSeq = $self->seq;
513 0 my $maskQual = $self->qual;
514  
515 ## There must be a more efficient way than this!
516 0 ▶ for(my $i=0; $i<length($maskSeq); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $maskSeq) 0 0 0
517 #print join ("\t", $i, $maskQual->[$i]), "\n";
518 substr($maskSeq, $i, 1, $MASK_CHAR)
519 0 ▶ if $maskQual->[$i] < $self->{_threshold};
Branch: 1 branch
BranchTrueFalseTotal
if $maskQual->[$i] < $self->{"_threshold"} 0 0 0
520 }
521  
522 ## This is the *wrong* way to do it!
523 #for my $r (@{$self->{_ranges}} ){
524 # substr($maskSeq, $r->{start}, $r->{length}, $MASK_CHAR x $r->{length});
525 #}
526  
527 0 return $maskSeq;
528 }
529  
530 =head2 count_clear_ranges
531  
532 Title : count_clear_ranges
533 Usage : $count = $obj->count_clear_ranges($threshold);
534 Function: Counts number of ranges in the sequence where quality
535 values are above the threshold
536 Returns : count integer
537 Args : threshold integer, optional
538  
539 Set threshold first using method L<threshold>.
540  
541 =cut
542  
543 0 ▶sub count_clear_ranges {
Subroutine count_clear_ranges: not called CC=3 SCAR=24.8
Pod documented
544 0 my $self = shift;
545 0 my $threshold = shift;
546 0 ▶ $self->threshold($threshold) if defined $threshold;
Branch: 1 branch
BranchTrueFalseTotal
if defined $threshold 0 0 0
547  
548 # populate the cache if needed
549 0 ▶ $self->_find_clear_ranges unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
550  
551 0 return scalar @{$self->{_ranges}};
552 }
553  
554 =head2 clear_ranges_length
555  
556 Title : clear_ranges_length
557 Usage : $total_lenght = $obj->clear_ranges_length($threshold);
558 Function: Return number of residues with quality values above
559 the threshold in all clear ranges
560 Returns : an integer
561 Args : threshold, optional
562  
563 Set threshold first using method L<threshold>.
564  
565 I think this method needs a better name! count_high_quality_bases? or
566 sum_clear_ranges?
567  
568 =cut
569  
570 0 ▶sub clear_ranges_length {
Subroutine clear_ranges_length: not called CC=3 SCAR=24.8
Pod documented
571 0 my $self = shift;
572 0 my $threshold = shift;
573 0 ▶ $self->threshold($threshold) if defined $threshold;
Branch: 1 branch
BranchTrueFalseTotal
if defined $threshold 0 0 0
574  
575 # populate the cache if needed
576 0 ▶ $self->_find_clear_ranges unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
577  
578 0 my $sum;
579 0 map {$sum += $_->{length}} @{$self->{_ranges}};
580 0 return $sum;
581 }
582  
583 =head2 get_clear_range
584  
585 Title : get_clear_range
586 Usage : $newqualobj = $obj->get_clear_range($threshold);
587 Function: Return longest subsequence that has quality values above
588 the given threshold, or a default value of 13
589 Returns : a new Bio::Seq::Quality object
590 Args : threshold, optional
591  
592 Set threshold first using method L<threshold>.
593  
594 Note, this method could be implemented using some gaussian smoothing
595 of the quality scores. Currently one base below the threshold is
596 enough to end the clear range.
597  
598 =cut
599  
600 0 ▶sub get_clear_range {
Subroutine get_clear_range: not called CC=5 SCAR=34.0
Pod documented
601 0 my $self = shift;
602 0 my $threshold = shift;
603 0 ▶ $self->threshold($threshold) if defined $threshold;
Branch: 1 branch
BranchTrueFalseTotal
if defined $threshold 0 0 0
604  
605 # populate the cache if needed
606 0 ▶ $self->_find_clear_ranges unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
607  
608 # fix for bug 2847
609 0 ▶ return unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
610  
611 # pick the longest
612 0 for (sort {$b->{length} <=> $a->{length} } @{$self->{_ranges}} ){
613 my $newqualobj = Bio::Seq::Quality->new(
614 -seq => $self->subseq( $_->{start}, $_->{end}),
615 0 -qual => $self->subqual($_->{start}, $_->{end}),
616 -id => $self->id);
617
618 0 $newqualobj->threshold($threshold);
619
620 0 return $newqualobj;
621 }
622 }
623  
624  
625  
626 =head2 get_all_clean_ranges
627  
628 Title : get_all_clean_ranges
629 Usage : @ranges = $obj->get_all_clean_ranges($minlength);
630 Function: Return all ranges where quality values are above
631 the threshold. Original ordering.
632 Returns : an ordered array of new Bio::Seq::Quality objects
633 Args : minimum length , optional
634  
635 Set threshold first using method L<threshold>.
636  
637 =cut
638  
639 0 ▶sub get_all_clean_ranges {
Subroutine get_all_clean_ranges: not called CC=6 SCAR=37.4
Pod documented
640 0 my $self = shift;
641 0 ▶ my $minl = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
642  
643 0 ▶ $self->throw("Mimimum length needs to be zero or a positive integer [$minl]")
Branch: 1 branch
BranchTrueFalseTotal
unless $minl =~ /^\+?\d+$/ 0 0 0
644 unless $minl =~ /^\+?\d+$/;
645  
646 # populate the cache if needed
647 0 ▶ $self->_find_clear_ranges unless defined $self->{_ranges};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_ranges"} 0 0 0
648  
649 # return in the order of occurrence
650 0 my @ranges;
651 0 for my $r (sort {$b->{start} <=> $a->{start} } @{$self->{_ranges}} ){
652 0 ▶ next if $r->{length} < $minl;
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"length"} < $minl 0 0 0
653
654 ## Constructor should allow "-threshold => ..."!
655 push @ranges, Bio::Seq::Quality->new
656 ( -seq => $self->subseq( $r->{start}, $r->{end}),
657 0 -qual => $self->subqual($r->{start}, $r->{end}),
658 -id => $self->id
659 );
660 }
661 0 return @ranges;
662 }
663  
664  
665 #
666 # _find_clear_ranges: where range/threshold calculations happen
667 #
668  
669 0 ▶sub _find_clear_ranges {
Subroutine _find_clear_ranges: not called CC=7 SCAR=40.3
670 0 my $self = shift;
671 0 my $qual = $self->qual;
672
673 0 ▶ $self->throw("You need to set the threshold value first")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->threshold 0 0 0
674 unless defined $self->threshold;
675
676 0 my $threshold = $self->threshold;
677
678 0 my $rangeFlag = 0;
679
680 0 ▶ for(my $i=0; $i<@$qual; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$qual) 0 0 0
681 ## Are we currently within a clear range or not?
682 0 ▶ if($rangeFlag){
Branch: 1 branch
BranchTrueFalseTotal
if ($rangeFlag) { } 0 0 0
683 ## Did we just leave the clear range?
684 0 ▶ if($qual->[$i]<$threshold){
Branch: 1 branch
BranchTrueFalseTotal
if ($qual->[$i] < $threshold) 0 0 0
685 ## Log the range
686 0 my $range;
687 0 $range->{end} = $i-1;
688 0 $range->{start} = $rangeFlag;
689 0 $range->{length} = $i - $rangeFlag;
690 0 push @{$self->{_ranges}}, $range;
691 ## and reset the range flag.
692 0 $rangeFlag = 0;
693 }
694 ## else nothing changes
695 }
696 else{
697 ## Did we just enter a clear range?
698 0 ▶ if($qual->[$i]>=$threshold){
Branch: 1 branch
BranchTrueFalseTotal
if ($qual->[$i] >= $threshold) 0 0 0
699 ## then set the range flag!
700 0 $rangeFlag = $i;
701 }
702 ## else nothing changes
703 }
704 }
705 ## Did we exit the last clear range?
706 0 ▶ if($rangeFlag){
Branch: 1 branch
BranchTrueFalseTotal
if ($rangeFlag) 0 0 0
707 0 my $i = scalar(@$qual);
708 ## Log the range
709 0 my $range;
710 0 $range->{end} = $i-1;
711 0 $range->{start} = $rangeFlag;
712 0 $range->{length} = $i - $rangeFlag;
713 0 push @{$self->{_ranges}}, $range;
714 }
715
716 0 1;
717 }
718  
719  
720 356 ▶sub _empty_cache {
Subroutine _empty_cache: called CC=1 SCAR=0.0
721 356 my $self = shift;
722 356 undef $self->{_ranges};
723 }
724  
725  
726 ################## deprecated methods ##################
727  
728 0 ▶sub trace_indices {
Subroutine trace_indices: not called CC=1 SCAR=6.9
Pod undocumented
729 0 my $self = shift;
730 0 return $self->named_meta('trace');
731 }
732  
733 763 ▶sub trace_index_at {
Subroutine trace_index_at: called CC=1 SCAR=0.0
Pod undocumented
734 763 my ($self, $val) =@_;
735 763 return shift @{$self->named_submeta('trace', $val, $val)};
736 }
737  
738  
739 0 ▶sub sub_trace_index {
Subroutine sub_trace_index: not called CC=1 SCAR=6.9
Pod undocumented
740 0 my $self = shift;
741 0 return $self->named_submeta('trace', @_);
742 }
743  
744  
745 1030 ▶sub qualat {
Subroutine qualat: called CC=1 SCAR=0.0
Pod undocumented
746 1030 my ($self, $val) =@_;
747 1030 return shift @{$self->submeta($val, $val)};
748 }
749  
750  
751 763 ▶sub baseat {
Subroutine baseat: called CC=1 SCAR=0.0
Pod undocumented
752 763 my ($self,$val) = @_;
753 763 return $self->subseq($val,$val);
754 }
755  
756  
757  
758 12 1;
« Bio/AlignIO/phylip.pm ↑ Summary Bio/SeqIO/qual.pm »