DataProcessing/Filter.pm

filter: Statementstmt 60.5% 23 / 38 Branchbran 0.0% 0 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 100% 3 / 3 totaltotal 51.6% 31 / 60 CC 6 SCAR 26.7
CC
6
Cov
49%
compare
30.0
new
2.0
is_valid
2.0
CRAP 14.5
« DataProcessing.pm ↑ Summary DataProcessing/MinimumPhredFilter.pm »
1 # *%) $Id: Filter.pm,v 1.7 2004/10/15 22:30:46 scottz Exp $
2 #
3 # Copyright (c) 2004 Scott Zuyderduyn <scottz@bccrc.ca>.
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<Bio::SAGE::DataProcessing> 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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use diagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK $PROTOCOL_SAGE $PROTOCOL_LONGSAGE $DEBUG $ENZYME_NLAIII $ENZYME_SAU3A );
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 require Exporter;
49 1 require AutoLoader;
50  
51 1 @ISA = qw( Exporter AutoLoader );
52 1 @EXPORT = qw();
53 1 $VERSION = $Bio::SAGE::DataProcessing::VERSION;
54  
55 1 my $PACKAGE = "Bio::SAGE::DataProcessing::Filter";
56  
57 =pod
58  
59 =head1 VARIABLES
60  
61 B<Globals>
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<Settings>
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 1 $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 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
101 #######################################################
102 =pod
103  
104 =head2 new [$arg1,$arg2,...]
105  
106 Constructor for a new Bio::SAGE::DataProcessing::Filter
107 object.
108  
109 B<Arguments>
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<Usage>
124  
125 Not explicitly called.
126  
127 =cut
128  
129 2 my $this = shift;
130 2 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
131 2 my $self = {};
132 2 bless( $self, $class );
133  
134 2 $self->{'args'} = \@_;
135  
136 2 return $self;
137  
138 }
139  
140 =pod
141  
142 =head1 INSTANCE METHODS
143  
144 =cut
145  
146 #######################################################
147 0 ▶sub is_valid {
Subroutine is_valid: not called CC=1 SCAR=6.9
Pod documented
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<Arguments>
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<Usage>
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 my $this = shift;
184  
185 0 die( $PACKAGE . "::is_tag_valid needs to implemented by concrete subclass." );
186  
187 }
188  
189 #######################################################
190 0 ▶sub compare {
Subroutine compare: not called CC=5 SCAR=34.0
Pod documented
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<Arguments>
204  
205 I<$scores1,$scores2>
206  
207 Space-separated strings of Phred scores (for example,
208 "20 20 25 12 35").
209  
210 B<Returns>
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<Usage>
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 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 ▶ if( scalar( @scores1 ) != scalar( @scores2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @scores1 != scalar @scores2) 0 0 0
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++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @scores1) 0 0 0
246 0 $sum1 += $scores1[$i];
247 0 $sum2 += $scores2[$i];
248 }
249  
250 0 ▶ return ( $sum1 == $sum2 ? 0 : ( $sum1 > $sum2 ? -1 : 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
$sum1 == $sum2 ? : 0 0 0
$sum1 > $sum2 ? : 0 0 0
251  
252 }
253  
254 1 1;
255  
256 __END__
« DataProcessing.pm ↑ Summary DataProcessing/MinimumPhredFilter.pm »