line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# *%) $Id: AveragePhredFilter.pm,v 1.6 2004/10/15 22:30:46 scottz Exp $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2004 Scott Zuyderduyn . |
4
|
|
|
|
|
|
|
# All rights reserved. This program is free software; you |
5
|
|
|
|
|
|
|
# can redistribute it and/or modify it under the same |
6
|
|
|
|
|
|
|
# terms as Perl itself. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Bio::SAGE::DataProcessing::AveragePhredFilter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=pod |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Bio::SAGE::DataProcessing::AveragePhredFilter - A filter that validates sequences based on average Phred score. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Bio::SAGE::DataProcessing::AveragePhredFilter; |
19
|
|
|
|
|
|
|
$filter = new Bio::SAGE::DataProcessing::AveragePhredFilter->new( 30, 15 ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module is a concrete subclass of Bio::SAGE::DataProcessing::Filter. |
24
|
|
|
|
|
|
|
The implementation considers a sequence valid if the average quality of |
25
|
|
|
|
|
|
|
all nucleotides meet a given value. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 INSTALLATION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Included with Bio::SAGE::DataProcessing. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 PREREQUISITES |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module requires the C package. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 CHANGES |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1.10 2004.06.19 - Initial release. |
38
|
|
|
|
|
|
|
0.01 2004.05.02 - prototype |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
5
|
use Bio::SAGE::DataProcessing::Filter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
43
|
1
|
|
|
1
|
|
5
|
use base qw( Bio::SAGE::DataProcessing::Filter ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
104
|
|
44
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
45
|
1
|
|
|
1
|
|
6
|
use diagnostics; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
46
|
1
|
|
|
1
|
|
33
|
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
383
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#require Exporter; |
49
|
|
|
|
|
|
|
#require AutoLoader; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#@ISA = qw( Exporter AutoLoader ); |
52
|
|
|
|
|
|
|
@ISA = qw( Bio::SAGE::DataProcessing::Filter ); |
53
|
|
|
|
|
|
|
@EXPORT = qw(); |
54
|
|
|
|
|
|
|
$VERSION = $Bio::SAGE::DataProcessing::VERSION; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $PACKAGE = "Bio::SAGE::DataProcessing::AveragePhredFilter"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 CLASS METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
####################################################### |
65
|
|
|
|
|
|
|
sub new { |
66
|
|
|
|
|
|
|
####################################################### |
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 new $avgPhred, <$minPhred> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Constructor. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
B |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
I<$avgPhred> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The average phred value of all nucleotides required |
78
|
|
|
|
|
|
|
for a sequence to be considered valid. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
I<$minPhred> (optional) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The minimum phred value that all nucleotides in a |
83
|
|
|
|
|
|
|
sequence must have in order to be considered valid. |
84
|
|
|
|
|
|
|
The default value if this argument is not specified |
85
|
|
|
|
|
|
|
is 0. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
B |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $filter = Bio::SAGE::DataProcessing::MinimumPhredFilter->new( 30, 20 ); |
90
|
|
|
|
|
|
|
if( $filter->is_tag_valid( "AAAAAA", "20 40 40 40 30 35" ) ) { |
91
|
|
|
|
|
|
|
print "VALID!\n"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
1
|
1
|
3
|
my $class = shift; |
97
|
1
|
|
|
|
|
15
|
return $class->SUPER::new( @_ ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
####################################################### |
108
|
|
|
|
|
|
|
sub is_valid { |
109
|
|
|
|
|
|
|
####################################################### |
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 is_valid $sequence, $scores |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This implements the is_valid subroutine required |
115
|
|
|
|
|
|
|
in concrete subclasses of Bio::SAGE::DataProcessing::Filter. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
B |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
I<$sequence> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The tag sequence. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
I<$scores> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
A space-separated string of Phred scores for the |
126
|
|
|
|
|
|
|
specified sequence. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
B |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns non-zero if the valid, zero if invalid. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
B |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $filter = Bio::SAGE::DataProcessing::MinimumPhredFilter->new(); |
135
|
|
|
|
|
|
|
if( $filter->is_tag_valid( "AAAAAA", "20 40 40 40 30 35" ) ) { |
136
|
|
|
|
|
|
|
print "VALID!\n"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
244
|
|
|
244
|
1
|
371
|
my $this = shift; |
142
|
244
|
|
50
|
|
|
577
|
my $sequence = shift || die( $PACKAGE . "::is_valid no sequence defined." ); |
143
|
244
|
|
|
|
|
446
|
my $scores = shift; # || die( $PACKAGE . "::is_valid no scores defined." ); |
144
|
|
|
|
|
|
|
|
145
|
244
|
50
|
|
|
|
1037
|
if( !defined( $scores ) ) { return 1; } # force valid |
|
0
|
|
|
|
|
0
|
|
146
|
|
|
|
|
|
|
|
147
|
244
|
50
|
|
|
|
546
|
if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) { |
148
|
0
|
|
|
|
|
0
|
print STDERR $PACKAGE . "::is_valid looking at " . $scores . "\n"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
244
|
|
|
|
|
426
|
my $min_avg_phred = $this->{'args'}[0]; |
152
|
244
|
|
|
|
|
335
|
my $min_phred = $this->{'args'}[1]; |
153
|
|
|
|
|
|
|
|
154
|
244
|
|
|
|
|
277
|
my $avg = 0; |
155
|
|
|
|
|
|
|
|
156
|
244
|
|
|
|
|
3905
|
my @scores = split( /\s/, $scores ); |
157
|
244
|
|
|
|
|
934
|
foreach my $score ( @scores ) { |
158
|
3416
|
50
|
|
|
|
8275
|
if( $score < $min_phred ) { |
159
|
0
|
0
|
|
|
|
0
|
if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) { |
160
|
0
|
|
|
|
|
0
|
print STDERR " $score does not meet minimum $min_phred\n"; |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
0
|
return 0; |
163
|
|
|
|
|
|
|
} |
164
|
3416
|
|
|
|
|
6615
|
$avg += $score; |
165
|
|
|
|
|
|
|
} |
166
|
244
|
|
|
|
|
598
|
$avg /= scalar( @scores ); |
167
|
|
|
|
|
|
|
|
168
|
244
|
100
|
|
|
|
698
|
if( $avg < $min_avg_phred ) { |
169
|
2
|
50
|
|
|
|
8
|
if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) { |
170
|
0
|
|
|
|
|
0
|
print STDERR " $avg does not meet minimum avg. phred $min_avg_phred\n"; |
171
|
|
|
|
|
|
|
} |
172
|
2
|
|
|
|
|
15
|
return 0; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
242
|
|
|
|
|
1769
|
return 1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
####################################################### |
180
|
|
|
|
|
|
|
####################################################### |
181
|
|
|
|
|
|
|
=pod |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 compare $scores1, $scores2 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The default implementation provided by the base class |
186
|
|
|
|
|
|
|
Bio::SAGE::DataProcessing::Filter is used. See the |
187
|
|
|
|
|
|
|
documentation for the base class for more information. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |