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

Annotation of /Sprout/TargetCriterionKeyword.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 TargetCriterionKeyword;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use Sprout;
25 :     use base qw(TargetCriterionQuery);
26 :    
27 :     =head1 Keyword Value Target Search Criterion Object
28 :    
29 :     =head2 Introduction
30 :    
31 :     This is a search criterion object for search criteria involving one of the
32 :     special keyword fields in the Feature record. The criterion matches if the
33 :     keyword field has at least one value.
34 :    
35 :     =head3 new
36 :    
37 :     my $tc = TargetCriterionKeyword->new($rhelp, $name, $label, $hint, $keyword);
38 :    
39 :     Construct a new TargetCriterionKeyword 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 keyword
61 :    
62 :     The name of the relevant special keyword field.
63 :    
64 :     =back
65 :    
66 :     =cut
67 :    
68 :     sub new {
69 :     # Get the parameters.
70 :     my ($class, $rhelp, $name, $label, $hint, $keyword) = @_;
71 :     # Construct the underlying object.
72 :     my $retVal = TargetCriterionQuery::new($class, $rhelp, { label => $label,
73 :     hint => $hint,
74 :     name => $name },
75 :     $keyword => qw(Feature));
76 :     # Save the keyword name.
77 :     $retVal->{keyword} = $keyword;
78 :     # Return the object.
79 :     return $retVal;
80 :     }
81 :    
82 :     =head2 Virtual Methods
83 :    
84 :     =head3 Validate
85 :    
86 :     my $okFlag = $tc->Validate($parms);
87 :    
88 :     Return TRUE if the specified parameters are valid for a search criterion of this type
89 :     and FALSE otherwise. If an error is detected, the error message can be retrieved using
90 :     the L</message> method.
91 :    
92 :     =over 4
93 :    
94 :     =item parms
95 :    
96 :     A Criterion Parameter Object whose fields are to be validated.
97 :    
98 :     =item RETURN
99 :    
100 :     Returns TRUE if the parameters are valid, else FALSE.
101 :    
102 :     =back
103 :    
104 :     =cut
105 :    
106 :     sub Validate {
107 :     # This field has no parameters, so it's always valid.
108 :     return 1;
109 :     }
110 :    
111 :     =head3 ComputeQuery
112 :    
113 :     my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion);
114 :    
115 :     Compute the SQL filter, join list, and parameter list for this
116 :     criterion. If the criterion cannot be processed by SQL, then nothing is
117 :     returned, and the criterion must be handled during post-processing.
118 :    
119 :     The join list and the parameter list should both be list references. The
120 :     filter string is a true string.
121 :    
122 :     If the filter string only uses the B<Genome> and B<Feature> tables, then the
123 :     join list can be left empty. Otherwise, the join list should start with the
124 :     particular starting point (B<Genome> or B<Feature>) and list the path through
125 :     the other relevant entities and relationships. Each criterion will have its
126 :     own separate join path.
127 :    
128 :     =over 4
129 :    
130 :     =item criterion
131 :    
132 :     Reference to a Criterion Parameter Object.
133 :    
134 :     =item RETURN
135 :    
136 :     Returns a 3-tuple consisting of the join list, the relevant filter string,
137 :     and the matching parameters. If the criterion cannot be processed using
138 :     SQL, then the return list contains three undefined values. (This is what happens if
139 :     you don't override this method.)
140 :    
141 :     =back
142 :    
143 :     =cut
144 :    
145 :     sub ComputeQuery {
146 :     # Get the parameters.
147 :     my ($self, $criterion) = @_;
148 :     # Get the name of the relevant field with the appropriate suffix.
149 :     my $fieldName = "Feature($self->{keyword})";
150 :     # Compute the filter string.
151 :     my $filterString = "$fieldName <> ?";
152 :     # Return the results.
153 :     return ([], $filterString, ['']);
154 :     }
155 :    
156 :     =head3 Sane
157 :    
158 :     my $flag = $tc->Sane($parms);
159 :    
160 :     Return TRUE if this is a sane criterion, else FALSE. Every search must have at least one
161 :     sane criterion in order to be valid.
162 :    
163 :     =over 4
164 :    
165 :     =item parms (optional)
166 :    
167 :     A Criterion Parameter Object for the current query.
168 :    
169 :     =item RETURN
170 :    
171 :     Returns TRUE if this query returns a relatively limited result set and uses SQL,
172 :     else FALSE. If you do not override this method, it returns FALSE.
173 :    
174 :     =back
175 :    
176 :     =cut
177 :    
178 :     sub Sane {
179 :     return 1;
180 :     }
181 :    
182 :    
183 :     =head3 ReadDatabaseValues
184 :    
185 :     my @values = $tc->ReadDatabaseValues($fid);
186 :    
187 :     Read this field's values from the database. This method is called when we
188 :     need a field at search time and it's not a basic field (that is, it isn't
189 :     in the Feature or Genome tables) or when we need a field at runtime.
190 :    
191 :     =over 4
192 :    
193 :     =item fid
194 :    
195 :     ID of the current feature.
196 :    
197 :     =item RETURN
198 :    
199 :     Returns a list of the values for the given field.
200 :    
201 :     =back
202 :    
203 :     =cut
204 :    
205 :     sub ReadDatabaseValues {
206 :     # Get the parameters.
207 :     my ($self, $fid) = @_;
208 :     # Get the Sprout database.
209 :     my $sprout = $self->DB();
210 :     # Get the field name.
211 :     my $field = $self->RelevantField();
212 :     # Get the value list from the database.
213 :     my @retVal = $sprout->GetFlat("Feature", "Feature(id) = ?", [$fid], $field);
214 :     # Return the value list.
215 :     return @retVal;
216 :     }
217 :    
218 :    
219 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3