[Bio] / Sprout / TargetCriterionRange.pm Repository:
ViewVC logotype

Annotation of /Sprout/TargetCriterionRange.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     package TargetCriterionRange;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use Sprout;
25 :     use base qw(TargetCriterionQuery);
26 :    
27 :     =head1 Numeric Value Range Target Search Criterion Object
28 :    
29 :     =head2 Introduction
30 :    
31 :     This is a search criterion object for filtering a numeric value within a specified
32 :     range. The range is specified using the min/max control in the target search form.
33 :    
34 :     =head3 new
35 :    
36 :     my $tc = TargetCriterionRange->new($rhelp, $name, $label, $hint, $field => @path);
37 :    
38 :     Construct a new TargetCriterionRange object. The following parameters are
39 :     expected.
40 :    
41 :     =over 4
42 :    
43 :     =item rhelp
44 :    
45 :     [[ResultHelperPm]] object for the active search.
46 :    
47 :     =item name
48 :    
49 :     Identifying name of this criterion.
50 :    
51 :     =item label
52 :    
53 :     Label to use for this criterion.
54 :    
55 :     =item hint
56 :    
57 :     Hint string to display when this criterion is selected.
58 :    
59 :     =back
60 :    
61 :     =cut
62 :    
63 :     sub new {
64 :     # Get the parameters.
65 :     my ($class, $rhelp, $name, $label, $hint, $sanity, $field, @path) = @_;
66 :     # Package the options.
67 :     my %options = (label => $label, hint => $hint, minMax => 1, name => $name);
68 :     # Construct the underlying object.
69 :     my $retVal = TargetCriterionQuery::new($class, $rhelp, \%options, $field => @path);
70 :     # Override the sanity.
71 :     $retVal->{sane} = $sanity;
72 :     # Return the object.
73 :     return $retVal;
74 :     }
75 :    
76 :     =head2 Virtual Methods
77 :    
78 :     =head3 Validate
79 :    
80 :     my $okFlag = $tc->Validate($parms);
81 :    
82 :     Return TRUE if the specified parameters are valid for a search criterion of this type
83 :     and FALSE otherwise. If an error is detected, the error message can be retrieved using
84 :     the L</message> method.
85 :    
86 :     =over 4
87 :    
88 :     =item parms
89 :    
90 :     A Criterion Parameter Object whose fields are to be validated.
91 :    
92 :     =item RETURN
93 :    
94 :     Returns TRUE if the parameters are valid, else FALSE.
95 :    
96 :     =back
97 :    
98 :     =cut
99 :    
100 :     sub Validate {
101 :     # Get the parameters.
102 :     my ($self, $parms) = @_;
103 :     # Declare the return variable.
104 :     my $retVal;
105 :     # Get the values to validate.
106 :     my ($min, $max) = $self->GetMinMax($parms);
107 :     # An undefined value for either is an error.
108 :     if (! defined $min) {
109 :     $self->SetMessage("Invalid or missing minimum for $self->{label}.");
110 :     } elsif (! defined $max) {
111 :     $self->SetMessage("Invalid or missing maximum for $self->{label}.");
112 :     } elsif ($min > $max) {
113 :     $self->SetMessage("Minimum cannot be greater than maximum for $self->{label}.");
114 :     } else {
115 :     $retVal = 1;
116 :     }
117 :     # Return the validation code.
118 :     return $retVal;
119 :     }
120 :    
121 :     =head3 ComputeQuery
122 :    
123 :     my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion);
124 :    
125 :     Compute the SQL filter, join list, and parameter list for this
126 :     criterion. If the criterion cannot be processed by SQL, then nothing is
127 :     returned, and the criterion must be handled during post-processing.
128 :    
129 :     The join list and the parameter list should both be list references. The
130 :     filter string is a true string.
131 :    
132 :     If the filter string only uses the B<Genome> and B<Feature> tables, then the
133 :     join list can be left empty. Otherwise, the join list should start with the
134 :     particular starting point (B<Genome> or B<Feature>) and list the path through
135 :     the other relevant entities and relationships. Each criterion will have its
136 :     own separate join path.
137 :    
138 :     =over 4
139 :    
140 :     =item criterion
141 :    
142 :     Reference to a Criterion Parameter Object.
143 :    
144 :     =item RETURN
145 :    
146 :     Returns a 3-tuple consisting of the join list, the relevant filter string,
147 :     and the matching parameters. If the criterion cannot be processed using
148 :     SQL, then the return list contains three undefined values. (This is what happens if
149 :     you don't override this method.)
150 :    
151 :     =back
152 :    
153 :     =cut
154 :    
155 :     sub ComputeQuery {
156 :     # Get the parameters.
157 :     my ($self, $criterion) = @_;
158 :     # Get the name of the relevant field with the appropriate suffix.
159 :     my $fieldName = $self->RelevantField($criterion->{idx});
160 :     # Compute the join list.
161 :     my $joins = $self->JoinList();
162 :     # Compute the filter string.
163 :     my $filterString = "$fieldName >= ? AND $fieldName <= ?";
164 :     # Finally, we build the parameter list, which contains the minimum value and
165 :     # the maximum value.
166 :     my $parms = [ $self->GetMinMax($criterion) ];
167 :     # Return the results.
168 :     return ($joins, $filterString, $parms);
169 :     }
170 :    
171 :     =head3 CheckValue
172 :    
173 :     my $match = $tc->CheckValue($criterion, $valueData);
174 :    
175 :     Return TRUE if the current feature matches this criterion, else FALSE.
176 :    
177 :     =over 4
178 :    
179 :     =item criterion
180 :    
181 :     Criterion Parameter object describing this criterion's parameters.
182 :    
183 :     =item valueData
184 :    
185 :     Value computed for the current feature by the L</GetValueData> method.
186 :    
187 :     =item RETURN
188 :    
189 :     Returns TRUE if the current feature matches the criterion, else FALSE.
190 :    
191 :     =back
192 :    
193 :     =cut
194 :    
195 :     sub CheckValue {
196 :     # Get the parameters.
197 :     my ($self, $criterion, $valueData) = @_;
198 :     # Get the min and max parameters.
199 :     my ($min, $max) = $self->GetMinMax($criterion);
200 :     # We match if any value is in the given range.
201 :     my $retVal = grep { $_ >= $min && $_ <= $max } @$valueData;
202 :     # Return the result.
203 :     return $retVal;
204 :     }
205 :    
206 :    
207 :    
208 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3