| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# *%) $Id: Filter.pm,v 1.7 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::Filter; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=pod |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Bio::SAGE::DataProcessing::Filter - An abstract filter for determining whether a [di]tag is worth keeping. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Bio::SAGE::DataProcessing::Filter; |
|
19
|
|
|
|
|
|
|
$filter = Bio::SAGE::DataProcessing::Filter->new(); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module encapsulates an abstract filtering procedure |
|
24
|
|
|
|
|
|
|
that is used during library processing with |
|
25
|
|
|
|
|
|
|
Bio::SAGE::DataProcessing. For example, a concrete |
|
26
|
|
|
|
|
|
|
implementation might indicate a tag is not worth keeping |
|
27
|
|
|
|
|
|
|
because the Phred scores are too low. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Included with Bio::SAGE::DataProcessing. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 PREREQUISITES |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module requires the C package. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 CHANGES |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1.10 2004.06.19 - Initial release. |
|
40
|
|
|
|
|
|
|
0.01 2004.05.02 - prototype |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
|
43
|
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
45
|
1
|
|
|
1
|
|
5
|
use diagnostics; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
46
|
1
|
|
|
1
|
|
35
|
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK $PROTOCOL_SAGE $PROTOCOL_LONGSAGE $DEBUG $ENZYME_NLAIII $ENZYME_SAU3A ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
474
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
require Exporter; |
|
49
|
|
|
|
|
|
|
require AutoLoader; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
@ISA = qw( Exporter AutoLoader ); |
|
52
|
|
|
|
|
|
|
@EXPORT = qw(); |
|
53
|
|
|
|
|
|
|
$VERSION = $Bio::SAGE::DataProcessing::VERSION; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $PACKAGE = "Bio::SAGE::DataProcessing::Filter"; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VARIABLES |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
B |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=over 2 |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
I<$PROTOCOL_SAGE> |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Hashref containing protocol parameters for the |
|
68
|
|
|
|
|
|
|
regular/original SAGE protocol (see set_protocol |
|
69
|
|
|
|
|
|
|
documentation for more information). |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
I<$PROTOCOL_LONGSAGE> |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Hashref containing protocol parameters for the |
|
74
|
|
|
|
|
|
|
LongSAGE protocol (see set_protocol documentation |
|
75
|
|
|
|
|
|
|
for more information). |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=back |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
B |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 2 |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
I<$DEBUG = 0> |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Prints debugging output if value if >= 1. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$DEBUG = 0; # set this flag to non-zero to enable debugging messages |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CLASS METHODS |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
####################################################### |
|
100
|
|
|
|
|
|
|
sub new { |
|
101
|
|
|
|
|
|
|
####################################################### |
|
102
|
|
|
|
|
|
|
=pod |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 new [$arg1,$arg2,...] |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Constructor for a new Bio::SAGE::DataProcessing::Filter |
|
107
|
|
|
|
|
|
|
object. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
B |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
I<$arg1,$arg2,...> (optional) |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Any arguments can be specified. These are stored in |
|
114
|
|
|
|
|
|
|
the 'args' hash element (ie. $self->{'args'}). Concrete |
|
115
|
|
|
|
|
|
|
subclasses must call this constructor explictly from |
|
116
|
|
|
|
|
|
|
within their constructor. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
i.e. $class->SUPER::new( @_ ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The required parameters are dependent on the |
|
121
|
|
|
|
|
|
|
concrete implementation of a Filter. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
B |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Not explicitly called. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
2
|
|
|
2
|
1
|
4
|
my $this = shift; |
|
130
|
2
|
|
33
|
|
|
14
|
my $class = ref( $this ) || $this; |
|
131
|
2
|
|
|
|
|
6
|
my $self = {}; |
|
132
|
2
|
|
|
|
|
5
|
bless( $self, $class ); |
|
133
|
|
|
|
|
|
|
|
|
134
|
2
|
|
|
|
|
21
|
$self->{'args'} = \@_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
2
|
|
|
|
|
9
|
return $self; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=pod |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
####################################################### |
|
147
|
|
|
|
|
|
|
sub is_valid { |
|
148
|
|
|
|
|
|
|
####################################################### |
|
149
|
|
|
|
|
|
|
=pod |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 is_valid $sequence, <\@scores> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This method must be implementated by the developer |
|
154
|
|
|
|
|
|
|
in a concrete subclass. The contract of this method |
|
155
|
|
|
|
|
|
|
is to return a boolean value indicating whether the |
|
156
|
|
|
|
|
|
|
tag is valid or not. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The subclass implementation should always work for |
|
159
|
|
|
|
|
|
|
cases where the \@scores argument is not provided |
|
160
|
|
|
|
|
|
|
(i.e. !defined(\@scores)). |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
B |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
I<$sequence> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The tag sequence. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
I<\@scores> (optional) |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
An arrayref to scores for this tag (it should be |
|
171
|
|
|
|
|
|
|
assumed that the quality scores for the leading |
|
172
|
|
|
|
|
|
|
anchoring enzyme site nucleotides are included). |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
B |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my $filter = Bio::SAGE::DataProcessing::Filter->new(); |
|
177
|
|
|
|
|
|
|
if( $filter->is_tag_valid( "AAAAAAAAAA" ) ) { |
|
178
|
|
|
|
|
|
|
print "VALID!\n"; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
die( $PACKAGE . "::is_tag_valid needs to implemented by concrete subclass." ); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
####################################################### |
|
190
|
|
|
|
|
|
|
sub compare { |
|
191
|
|
|
|
|
|
|
####################################################### |
|
192
|
|
|
|
|
|
|
=pod |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 compare $scores1, $scores2 |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This method determines which set of scores is "better" |
|
197
|
|
|
|
|
|
|
(defined by the implementation). |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This method can be overridden by the developer in a |
|
200
|
|
|
|
|
|
|
subclass. The default method chooses the scores that |
|
201
|
|
|
|
|
|
|
have the highest cumulative sum. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
B |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
I<$scores1,$scores2> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Space-separated strings of Phred scores (for example, |
|
208
|
|
|
|
|
|
|
"20 20 25 12 35"). |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
B |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns <0 if the first scores are best, >0 if |
|
213
|
|
|
|
|
|
|
the second scores are best, and 0 if the two |
|
214
|
|
|
|
|
|
|
score sets are equivalent. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
B |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $filter = Bio::SAGE::DataProcessing::Filter->new(); |
|
219
|
|
|
|
|
|
|
my $res = $filter->compare( "20 20 20", "40 40 40" ); |
|
220
|
|
|
|
|
|
|
if( $res == -1 ) { # this would be the result in this example |
|
221
|
|
|
|
|
|
|
print "First set is better.\n"; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
if( $res == +1 ) { |
|
224
|
|
|
|
|
|
|
print "Second set is better.\n"; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
if( $res == 0 ) { |
|
227
|
|
|
|
|
|
|
print "Both sets are equivalent.\n"; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
|
233
|
0
|
|
|
|
|
|
my $score1 = shift; |
|
234
|
0
|
|
|
|
|
|
my $score2 = shift; |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
my @scores1 = split( /\s/, $score1 ); |
|
237
|
0
|
|
|
|
|
|
my @scores2 = split( /\s/, $score2 ); |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
0
|
|
|
|
|
if( scalar( @scores1 ) != scalar( @scores2 ) ) { |
|
240
|
0
|
|
|
|
|
|
die( $PACKAGE . "::compare can't compare score sets of different size." ); |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
my $sum1 = 0; |
|
244
|
0
|
|
|
|
|
|
my $sum2 = 0; |
|
245
|
0
|
|
|
|
|
|
for( my $i = 0; $i < scalar( @scores1 ); $i++ ) { |
|
246
|
0
|
|
|
|
|
|
$sum1 += $scores1[$i]; |
|
247
|
0
|
|
|
|
|
|
$sum2 += $scores2[$i]; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
0
|
0
|
|
|
|
|
return ( $sum1 == $sum2 ? 0 : ( $sum1 > $sum2 ? -1 : 1 ) ); |
|
|
|
0
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
__END__ |