File Coverage

lib/Bio/SAGE/DataProcessing/MinimumPhredFilter.pm
Criterion Covered Total %
statement 31 38 81.5
branch 7 14 50.0
condition 1 2 50.0
subroutine 7 7 100.0
pod 2 2 100.0
total 48 63 76.1


line stmt bran cond sub pod time code
1             # *%) $Id: MinimumPhredFilter.pm,v 1.5 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::MinimumPhredFilter;
9              
10             =pod
11              
12             =head1 NAME
13              
14             Bio::SAGE::DataProcessing::MinimumPhredFilter - A filter that validates sequences based on minimum Phred score.
15              
16             =head1 SYNOPSIS
17              
18             use Bio::SAGE::DataProcessing::MinimumPhredFilter;
19             $filter = new Bio::SAGE::DataProcessing::MinimumPhredFilter->new( 20 );
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 all nucleotides have
25             a Phred score that exceeds that specified for the filter.
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         45  
43 1     1   5 use base qw( Bio::SAGE::DataProcessing::Filter );
  1         2  
  1         78  
44 1     1   7 use strict;
  1         2  
  1         30  
45 1     1   5 use diagnostics;
  1         2  
  1         5  
46 1     1   28 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
  1         3  
  1         396  
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::MinimumPhredFilter";
57              
58             =pod
59              
60             =head1 CLASS METHODS
61              
62             =cut
63              
64             #######################################################
65             sub new {
66             #######################################################
67             =pod
68              
69             =head2 new $minPhred
70              
71             Constructor.
72              
73             B
74              
75             I<$minPhred>
76              
77             The minimum phred value that all nucleotides in a
78             sequence must have in order to be considered valid.
79              
80             B
81              
82             my $filter = Bio::SAGE::DataProcessing::MinimumPhredFilter->new( 20 );
83             if( $filter->is_tag_valid( "AAAAAAAAAA" ) ) {
84             print "VALID!\n";
85             }
86              
87             =cut
88              
89 1     1 1 3 my $class = shift;
90 1         7 $class->SUPER::new( @_ );
91              
92             }
93              
94             =pod
95              
96             =head1 INSTANCE METHODS
97              
98             =cut
99              
100             #######################################################
101             sub is_valid {
102             #######################################################
103             =pod
104              
105             =head2 is_valid $sequence, $scores
106              
107             This implements the is_valid subroutine required
108             in concrete subclasses of Bio::SAGE::DataProcessing::Filter.
109              
110             B
111              
112             I<$sequence>
113              
114             The tag sequence.
115              
116             I<$scores>
117              
118             A space-separated string of Phred scores for the
119             specified sequence.
120              
121             B
122              
123             Returns non-zero if the valid, zero if invalid.
124              
125             B
126              
127             my $filter = Bio::SAGE::DataProcessing::MinimumPhredFilter->new();
128             if( $filter->is_tag_valid( "AAAAAAAAAA" ) ) {
129             print "VALID!\n";
130             }
131              
132             =cut
133              
134 90     90 1 119 my $this = shift;
135 90   50     283 my $sequence = shift || die( $PACKAGE . "::is_valid no sequence defined." );
136 90         164 my $scores = shift;
137              
138 90 50       468 if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
139 0         0 print STDERR $PACKAGE . "::is_valid looking at " . $scores . "\n";
140             }
141              
142 90 50       205 if( !defined( $scores ) ) { return 1; }
  0         0  
143              
144 90         167 my $min_phred = $this->{'args'}[0];
145              
146 90 50       352 if( $min_phred == 0 ) {
147 0 0       0 if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
148 0         0 print STDERR $PACKAGE . "::is_valid no need to check, minimum phred is 0\n";
149             }
150 0         0 return 1;
151             }
152              
153 90         9555 my @scores = split( /\s/, $scores );
154 90         495 foreach my $score ( @scores ) {
155 2044 100       6740 if( $score < $min_phred ) {
156 29 50       67 if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
157 0         0 print STDERR $PACKAGE . "::is_valid $score does not meet minimum $min_phred\n";
158             }
159 29         296 return 0;
160             }
161             }
162              
163 61 50       154 if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
164 0         0 print STDERR $PACKAGE . "::is_valid scores passed\n";
165             }
166              
167 61         740 return 1;
168              
169             }
170              
171             #######################################################
172             #######################################################
173             =pod
174              
175             =head2 compare $scores1, $scores2
176              
177             The default implementation provided by the base class
178             Bio::SAGE::DataProcessing::Filter is used. See the
179             documentation for the base class for more information.
180              
181             =cut
182              
183             1;
184              
185             __END__