DataProcessing/AveragePhredFilter.pm

filter: Statementstmt 86.6% 39 / 45 Branchbran 50.0% 6 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 79.7% 55 / 69 CC 9 SCAR 20.7
CC
9
Cov
78%
is_valid
12.5
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« DataProcessing/MinimumPhredFilter.pm ↑ Summary
1 # *%) $Id: AveragePhredFilter.pm,v 1.6 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::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<Bio::SAGE::DataProcessing::Filter> 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 ▶use Bio::SAGE::DataProcessing::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use base qw( Bio::SAGE::DataProcessing::Filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
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 );
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 #require Exporter;
49 #require AutoLoader;
50  
51 #@ISA = qw( Exporter AutoLoader );
52 1 @ISA = qw( Bio::SAGE::DataProcessing::Filter );
53 1 @EXPORT = qw();
54 1 $VERSION = $Bio::SAGE::DataProcessing::VERSION;
55  
56 1 my $PACKAGE = "Bio::SAGE::DataProcessing::AveragePhredFilter";
57  
58 =pod
59  
60 =head1 CLASS METHODS
61  
62 =cut
63  
64 #######################################################
65 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
66 #######################################################
67 =pod
68  
69 =head2 new $avgPhred, <$minPhred>
70  
71 Constructor.
72  
73 B<Arguments>
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<Usage>
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 my $class = shift;
97 1 return $class->SUPER::new( @_ );
98  
99 }
100  
101 =pod
102  
103 =head1 INSTANCE METHODS
104  
105 =cut
106  
107 #######################################################
108 244 ▶sub is_valid {
Subroutine is_valid: called CC=9 SCAR=25.3
Pod documented
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<Arguments>
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<Returns>
129  
130 Returns non-zero if the valid, zero if invalid.
131  
132 B<Usage>
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 my $this = shift;
142 244 ▶ my $sequence = shift || die( $PACKAGE . "::is_valid no sequence defined." );
Condition50%1/2
shift() || die($PACKAGE . '::is_valid no sequence defined.')
l!l
2440
MC/DC0%0/1
shift() || die($PACKAGE . '::is_valid no sequence defined.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
143 244 my $scores = shift; # || die( $PACKAGE . "::is_valid no scores defined." );
144  
145 0 ▶ if( !defined( $scores ) ) { return 1; } # force valid
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $scores) 0 244 244
146  
147 244 ▶ if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SAGE::DataProcessing::DEBUG >= 1) 0 244 244
148 0 print STDERR $PACKAGE . "::is_valid looking at " . $scores . "\n";
149 }
150  
151 244 my $min_avg_phred = $this->{'args'}[0];
152 244 my $min_phred = $this->{'args'}[1];
153  
154 244 my $avg = 0;
155  
156 244 my @scores = split( /\s/, $scores );
157 244 foreach my $score ( @scores ) {
158 3416 ▶ if( $score < $min_phred ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($score < $min_phred) 0 3416 3416
159 0 ▶ if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SAGE::DataProcessing::DEBUG >= 1) 0 0 0
160 0 print STDERR " $score does not meet minimum $min_phred\n";
161 }
162 0 return 0;
163 }
164 3416 $avg += $score;
165 }
166 244 $avg /= scalar( @scores );
167  
168 244 ▶ if( $avg < $min_avg_phred ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($avg < $min_avg_phred) 2 242 244
169 2 ▶ if( $Bio::SAGE::DataProcessing::DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SAGE::DataProcessing::DEBUG >= 1) 0 2 2
170 0 print STDERR " $avg does not meet minimum avg. phred $min_avg_phred\n";
171 }
172 2 return 0;
173 }
174  
175 242 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 1;
192  
193 __END__
« DataProcessing/MinimumPhredFilter.pm ↑ Summary