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

Annotation of /Sprout/TargetCriterionLookup.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 TargetCriterionLookup;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use Sprout;
25 :     use base qw(TargetCriterionQuery);
26 :    
27 :     =head1 Exact Match Target Search Criterion Object
28 :    
29 :     =head2 Introduction
30 :    
31 :     This is a search criterion object for search criteria involving an exact match against a
32 :     single database text field. Unlike a generic match, this one is considered sane if it
33 :     is feature-related.
34 :    
35 :     =head3 new
36 :    
37 :     my $tc = TargetCriterionLookup->new($rhelp, $name, $label, $hint, $field => @path);
38 :    
39 :     Construct a new TargetCriterionLookup 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 field
61 :    
62 :     Name of the database field containing the code value.
63 :    
64 :     =item path
65 :    
66 :     List of object names, indicating the path from the Feature or Genome table to the
67 :     table containing the code value. The first object will be C<Feature> for a feature-based
68 :     criterion and C<Genome> for a genome-based one. Frequently, the path will stop with
69 :     the first object. When this happens, the criterion can be processed very efficiently.
70 :    
71 :     =back
72 :    
73 :     =cut
74 :    
75 :     sub new {
76 :     # Get the parameters.
77 :     my ($class, $rhelp, $name, $label, $hint, $field, @path) = @_;
78 :     # Construct the underlying object.
79 :     my $retVal = TargetCriterionQuery::new($class, $rhelp, { label => $label,
80 :     hint => $hint,
81 :     text => 1,
82 :     name => $name },
83 :     $field, @path);
84 :     # Return the object.
85 :     return $retVal;
86 :     }
87 :    
88 :     =head2 Virtual Methods
89 :    
90 :     =head3 Validate
91 :    
92 :     my $okFlag = $tc->Validate($parms);
93 :    
94 :     Return TRUE if the specified parameters are valid for a search criterion of this type
95 :     and FALSE otherwise. If an error is detected, the error message can be retrieved using
96 :     the L</message> method.
97 :    
98 :     =over 4
99 :    
100 :     =item parms
101 :    
102 :     A Criterion Parameter Object whose fields are to be validated.
103 :    
104 :     =item RETURN
105 :    
106 :     Returns TRUE if the parameters are valid, else FALSE.
107 :    
108 :     =back
109 :    
110 :     =cut
111 :    
112 :     sub Validate {
113 :     # Get the parameters.
114 :     my ($self, $parms) = @_;
115 :     # Default to valid.
116 :     my $retVal = 1;
117 :     # Get the string value.
118 :     my $value = $parms->{stringValue};
119 :     # It's only invalid if it's blank.
120 :     if (! defined $value || $value eq '' || $value =~ /^\s+$/) {
121 :     $retVal = 0;
122 :     $self->SetMessage("No value specified for $self->{label}.");
123 :     }
124 :     # Return the validation code.
125 :     return $retVal;
126 :     }
127 :    
128 :     =head3 ComputeQuery
129 :    
130 :     my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion);
131 :    
132 :     Compute the SQL filter, join list, and parameter list for this
133 :     criterion. If the criterion cannot be processed by SQL, then nothing is
134 :     returned, and the criterion must be handled during post-processing.
135 :    
136 :     The join list and the parameter list should both be list references. The
137 :     filter string is a true string.
138 :    
139 :     If the filter string only uses the B<Genome> and B<Feature> tables, then the
140 :     join list can be left empty. Otherwise, the join list should start with the
141 :     particular starting point (B<Genome> or B<Feature>) and list the path through
142 :     the other relevant entities and relationships. Each criterion will have its
143 :     own separate join path.
144 :    
145 :     =over 4
146 :    
147 :     =item criterion
148 :    
149 :     Reference to a Criterion Parameter Object.
150 :    
151 :     =item RETURN
152 :    
153 :     Returns a 3-tuple consisting of the join list, the relevant filter string,
154 :     and the matching parameters. If the criterion cannot be processed using
155 :     SQL, then the return list contains three undefined values. (This is what happens if
156 :     you don't override this method.)
157 :    
158 :     =back
159 :    
160 :     =cut
161 :    
162 :     sub ComputeQuery {
163 :     # Get the parameters.
164 :     my ($self, $criterion) = @_;
165 :     # Get the name of the relevant field with the appropriate suffix.
166 :     my $fieldName = $self->RelevantField($criterion->{idx});
167 :     # Compute the join list.
168 :     my $joins = $self->JoinList();
169 :     # Compute the filter string.
170 :     my $filterString = "$fieldName = ?";
171 :     # Get the parameter value.
172 :     my $parm = $criterion->{stringValue};
173 :     # Return the results.
174 :     return ($joins, $filterString, [$parm]);
175 :     }
176 :    
177 :     =head3 CheckValue
178 :    
179 :     my $match = $tc->CheckValue($criterion, $valueData);
180 :    
181 :     Return TRUE if the current feature matches this criterion, else FALSE.
182 :    
183 :     =over 4
184 :    
185 :     =item criterion
186 :    
187 :     Criterion Parameter object describing this criterion's parameters.
188 :    
189 :     =item valueData
190 :    
191 :     Value computed for the current feature by the L</GetValueData> method.
192 :    
193 :     =item RETURN
194 :    
195 :     Returns TRUE if the current feature matches the criterion, else FALSE.
196 :    
197 :     =back
198 :    
199 :     =cut
200 :    
201 :     sub CheckValue {
202 :     # Get the parameters.
203 :     my ($self, $criterion, $valueData) = @_;
204 :     # Get the criterion value to compare against it.
205 :     my $comparator = $criterion->{stringValue};
206 :     # Search for a match.
207 :     my $retVal = grep { $_ eq $comparator } @$valueData;
208 :     # Return the result.
209 :     return $retVal;
210 :     }
211 :    
212 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3