Parent Directory
|
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 TargetCriterionCodeMatch; | ||
21 : | |||
22 : | use strict; | ||
23 : | use Tracer; | ||
24 : | use Sprout; | ||
25 : | use base qw(TargetCriterionQuery); | ||
26 : | |||
27 : | =head1 Code Match Target Search Criterion Object | ||
28 : | |||
29 : | =head2 Introduction | ||
30 : | |||
31 : | This is a search criterion object for search criteria involving a match against a | ||
32 : | single database field that has a code value. The user inputs the code value using | ||
33 : | the selection control, which is a configurable dropdown list. | ||
34 : | |||
35 : | =head3 new | ||
36 : | |||
37 : | my $tc = TargetCriterionCodeMatch->new($rhelp, $name, $label, $hint, \%codes, $field => @path); | ||
38 : | |||
39 : | Construct a new TargetCriterionCodeMatch object. The following parameters are | ||
40 : | expected. | ||
41 : | |||
42 : | =over 4 | ||
43 : | |||
44 : | =item rhelp | ||
45 : | |||
46 : | [[ResultHelperPm]] object for the active search. | ||
47 : | |||
48 : | =item name | ||
49 : | |||
50 : | Identifying name of this criterion. | ||
51 : | |||
52 : | =item label | ||
53 : | |||
54 : | Label to display for this criterion in the type dropdown. | ||
55 : | |||
56 : | =item hint | ||
57 : | |||
58 : | The hint tooltip to be displayed for this criterion. | ||
59 : | |||
60 : | =item codes | ||
61 : | |||
62 : | Hash of code values to the corresponding labels to be used in the selection | ||
63 : | dropdown. | ||
64 : | |||
65 : | =item field | ||
66 : | |||
67 : | Name of the database field containing the code value. | ||
68 : | |||
69 : | =item path | ||
70 : | |||
71 : | List of object names, indicating the path from the Feature or Genome table to the | ||
72 : | table containing the code value. The first object will be C<Feature> for a feature-based | ||
73 : | criterion and C<Genome> for a genome-based one. Frequently, the path will stop with | ||
74 : | the first object. When this happens, the criterion can be processed very efficiently. | ||
75 : | |||
76 : | =back | ||
77 : | |||
78 : | =cut | ||
79 : | |||
80 : | sub new { | ||
81 : | # Get the parameters. | ||
82 : | my ($class, $rhelp, $name, $label, $hint, $codes, $field, @path) = @_; | ||
83 : | # Construct the underlying object. | ||
84 : | my $retVal = TargetCriterionQuery::new($class, $rhelp, { label => $label, | ||
85 : | hint => $hint, | ||
86 : | selectionData => $codes, | ||
87 : | name => $name}, | ||
88 : | $field, @path); | ||
89 : | # Return the object. | ||
90 : | return $retVal; | ||
91 : | } | ||
92 : | |||
93 : | =head2 Virtual Methods | ||
94 : | |||
95 : | =head3 Validate | ||
96 : | |||
97 : | my $okFlag = $tc->Validate($parms); | ||
98 : | |||
99 : | Return TRUE if the specified parameters are valid for a search criterion of this type | ||
100 : | and FALSE otherwise. If an error is detected, the error message can be retrieved using | ||
101 : | the L</message> method. | ||
102 : | |||
103 : | =over 4 | ||
104 : | |||
105 : | =item parms | ||
106 : | |||
107 : | A Criterion Parameter Object whose fields are to be validated. | ||
108 : | |||
109 : | =item RETURN | ||
110 : | |||
111 : | Returns TRUE if the parameters are valid, else FALSE. | ||
112 : | |||
113 : | =back | ||
114 : | |||
115 : | =cut | ||
116 : | |||
117 : | sub Validate { | ||
118 : | # Get the parameters. | ||
119 : | my ($self, $parms) = @_; | ||
120 : | # Default to valid. | ||
121 : | my $retVal = 1; | ||
122 : | # Get the selection value. | ||
123 : | my $value = $parms->{selection}; | ||
124 : | # Insure it matches one of the codes in the selection data. | ||
125 : | if (! exists $self->{selectionData}->{$value}) { | ||
126 : | # No, so we have an error. | ||
127 : | $self->SetMessage("Invalid selection \"$value\" for $self->{label}."); | ||
128 : | $retVal = 0; | ||
129 : | } | ||
130 : | # Return the validation code. | ||
131 : | return $retVal; | ||
132 : | } | ||
133 : | |||
134 : | =head3 ComputeQuery | ||
135 : | |||
136 : | my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion); | ||
137 : | |||
138 : | Compute the SQL filter, join list, and parameter list for this | ||
139 : | criterion. If the criterion cannot be processed by SQL, then nothing is | ||
140 : | returned, and the criterion must be handled during post-processing. | ||
141 : | |||
142 : | The join list and the parameter list should both be list references. The | ||
143 : | filter string is a true string. | ||
144 : | |||
145 : | If the filter string only uses the B<Genome> and B<Feature> tables, then the | ||
146 : | join list can be left empty. Otherwise, the join list should start with the | ||
147 : | particular starting point (B<Genome> or B<Feature>) and list the path through | ||
148 : | the other relevant entities and relationships. Each criterion will have its | ||
149 : | own separate join path. | ||
150 : | |||
151 : | =over 4 | ||
152 : | |||
153 : | =item criterion | ||
154 : | |||
155 : | Reference to a Criterion Parameter Object. | ||
156 : | |||
157 : | =item RETURN | ||
158 : | |||
159 : | Returns a 3-tuple consisting of the join list, the relevant filter string, | ||
160 : | and the matching parameters. If the criterion cannot be processed using | ||
161 : | SQL, then the return list contains three undefined values. (This is what happens if | ||
162 : | you don't override this method.) | ||
163 : | |||
164 : | =back | ||
165 : | |||
166 : | =cut | ||
167 : | |||
168 : | sub ComputeQuery { | ||
169 : | # Get the parameters. | ||
170 : | my ($self, $criterion) = @_; | ||
171 : | # Get the name of the relevant field with the appropriate suffix. | ||
172 : | my $fieldName = $self->RelevantField($criterion->{idx}); | ||
173 : | # Compute the join list. | ||
174 : | my $joins = $self->JoinList(); | ||
175 : | # Compute the filter string. | ||
176 : | my $filterString = "$fieldName = ?"; | ||
177 : | # Finally, we build the parameter list, which contains the selection value. | ||
178 : | my $parms = [ $criterion->{selection} ]; | ||
179 : | # Return the results. | ||
180 : | return ($joins, $filterString, $parms); | ||
181 : | } | ||
182 : | |||
183 : | =head3 CheckValue | ||
184 : | |||
185 : | my $match = $tc->CheckValue($criterion, $valueData); | ||
186 : | |||
187 : | Return TRUE if the current feature matches this criterion, else FALSE. | ||
188 : | |||
189 : | =over 4 | ||
190 : | |||
191 : | =item criterion | ||
192 : | |||
193 : | Criterion Parameter object describing this criterion's parameters. | ||
194 : | |||
195 : | =item valueData | ||
196 : | |||
197 : | Value computed for the current feature by the L</GetValueData> method. | ||
198 : | |||
199 : | =item RETURN | ||
200 : | |||
201 : | Returns TRUE if the current feature matches the criterion, else FALSE. | ||
202 : | |||
203 : | =back | ||
204 : | |||
205 : | =cut | ||
206 : | |||
207 : | sub CheckValue { | ||
208 : | # Get the parameters. | ||
209 : | my ($self, $criterion, $valueData) = @_; | ||
210 : | # Declare the return variable. | ||
211 : | my $value = $criterion->{selection}; | ||
212 : | # See if we can find a match. | ||
213 : | my $retVal = grep { $_ eq $value } @$valueData; | ||
214 : | # Return the result. | ||
215 : | return $retVal; | ||
216 : | } | ||
217 : | |||
218 : | =head3 Sane | ||
219 : | |||
220 : | my $flag = $tc->Sane($parms); | ||
221 : | |||
222 : | Return TRUE if this is a sane criterion, else FALSE. Every search must have at least one | ||
223 : | sane criterion in order to be valid. | ||
224 : | |||
225 : | =over 4 | ||
226 : | |||
227 : | =item parms (optional) | ||
228 : | |||
229 : | A Criterion Parameter Object for the current query. | ||
230 : | |||
231 : | =item RETURN | ||
232 : | |||
233 : | Returns TRUE if this query returns a relatively limited result set and uses SQL, | ||
234 : | else FALSE. If you do not override this method, it returns FALSE. | ||
235 : | |||
236 : | =back | ||
237 : | |||
238 : | =cut | ||
239 : | |||
240 : | sub Sane { | ||
241 : | return 0; | ||
242 : | } | ||
243 : | |||
244 : | 1; |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |