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

Annotation of /Sprout/TargetCriterionExternalId.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 TargetCriterionExternalId;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use Sprout;
25 :     use base qw(TargetCriterionQuery);
26 :    
27 :     =head1 External Database Gene ID Target Search Criterion Object
28 :    
29 :     =head2 Introduction
30 :    
31 :     This is a search criterion object for search criteria involving one of the
32 :     curated external IDs. Each criterion object is for a single ID type.
33 :    
34 :     =head3 new
35 :    
36 :     my $tc = TargetCriterionExternalId->new($rhelp, $name, $label, $hint, $databaseID);
37 :    
38 :     Construct a new TargetCriterionExternalId 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 display for this criterion in the type dropdown.
54 :    
55 :     =item hint
56 :    
57 :     The hint tooltip to be displayed for this criterion.
58 :    
59 :     =item databaseID
60 :    
61 :     The ID of the relevant external database.
62 :    
63 :     =back
64 :    
65 :     =cut
66 :    
67 :     sub new {
68 :     # Get the parameters.
69 :     my ($class, $rhelp, $name, $label, $hint, $databaseID) = @_;
70 :     # Construct the underlying object.
71 :     my $retVal = TargetCriterionQuery::new($class, $rhelp, { label => $label,
72 :     hint => $hint,
73 :     text => 1,
74 :     name => $name },
75 :     alias => qw(Feature IsAlsoFoundIn));
76 :     # Save the database ID.
77 :     $retVal->{externalDatabase} = $databaseID;
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 :     # Get the parameters.
108 :     my ($self, $parms) = @_;
109 :     # Default to valid.
110 :     my $retVal = 1;
111 :     # Get the string value.
112 :     my $value = $parms->{stringValue};
113 :     # It's only invalid if it's blank.
114 :     if (! defined $value || $value eq '' || $value =~ /^\s+$/) {
115 :     $retVal = 0;
116 :     $self->SetMessage("No value specified for $self->{label}.");
117 :     }
118 :     # Return the validation code.
119 :     return $retVal;
120 :     }
121 :    
122 :     =head3 ComputeQuery
123 :    
124 :     my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion);
125 :    
126 :     Compute the SQL filter, join list, and parameter list for this
127 :     criterion. If the criterion cannot be processed by SQL, then nothing is
128 :     returned, and the criterion must be handled during post-processing.
129 :    
130 :     The join list and the parameter list should both be list references. The
131 :     filter string is a true string.
132 :    
133 :     If the filter string only uses the B<Genome> and B<Feature> tables, then the
134 :     join list can be left empty. Otherwise, the join list should start with the
135 :     particular starting point (B<Genome> or B<Feature>) and list the path through
136 :     the other relevant entities and relationships. Each criterion will have its
137 :     own separate join path.
138 :    
139 :     =over 4
140 :    
141 :     =item criterion
142 :    
143 :     Reference to a Criterion Parameter Object.
144 :    
145 :     =item RETURN
146 :    
147 :     Returns a 3-tuple consisting of the join list, the relevant filter string,
148 :     and the matching parameters. If the criterion cannot be processed using
149 :     SQL, then the return list contains three undefined values. (This is what happens if
150 :     you don't override this method.)
151 :    
152 :     =back
153 :    
154 :     =cut
155 :    
156 :     sub ComputeQuery {
157 :     # Get the parameters.
158 :     my ($self, $criterion) = @_;
159 :     # Get the name of the relevant field with the appropriate suffix.
160 :     my $fieldName = $self->RelevantField($criterion->{idx});
161 :     # Compute the join list.
162 :     my $joins = $self->JoinList();
163 :     # Compute the filter string.
164 :     my $filterString = "$fieldName = ? AND IsAlsoFoundIn(to-link) = ?";
165 :     # Get the parameter value.
166 :     my $parm = $criterion->{stringValue};
167 :     # Return the results.
168 :     return ($joins, $filterString, [$parm, $self->{externalDatabase}]);
169 :     }
170 :    
171 :     =head3 Sane
172 :    
173 :     my $flag = $tc->Sane($parms);
174 :    
175 :     Return TRUE if this is a sane criterion, else FALSE. Every search must have at least one
176 :     sane criterion in order to be valid.
177 :    
178 :     =over 4
179 :    
180 :     =item parms (optional)
181 :    
182 :     A Criterion Parameter Object for the current query.
183 :    
184 :     =item RETURN
185 :    
186 :     Returns TRUE if this query returns a relatively limited result set and uses SQL,
187 :     else FALSE. If you do not override this method, it returns FALSE.
188 :    
189 :     =back
190 :    
191 :     =cut
192 :    
193 :     sub Sane {
194 :     return 1;
195 :     }
196 :    
197 :     =head3 ReadDatabaseValues
198 :    
199 :     my @values = $tc->ReadDatabaseValues($fid);
200 :    
201 :     Read this field's values from the database. This method is called when we
202 :     need a field at search time and it's not a basic field (that is, it isn't
203 :     in the Feature or Genome tables) or when we need a field at runtime.
204 :    
205 :     =over 4
206 :    
207 :     =item fid
208 :    
209 :     ID of the current feature.
210 :    
211 :     =item RETURN
212 :    
213 :     Returns a list of the values for the given field.
214 :    
215 :     =back
216 :    
217 :     =cut
218 :    
219 :     sub ReadDatabaseValues {
220 :     # Get the parameters.
221 :     my ($self, $fid) = @_;
222 :     # Get the Sprout database.
223 :     my $sprout = $self->DB();
224 :     # Get the key table name.
225 :     my $keyTable = $self->{keyTable};
226 :     # Get the field name.
227 :     my $field = $self->RelevantField();
228 :     # Get the value list from the database.
229 :     my @retVal = $sprout->GetFlat("IsAlsoFoundIn",
230 :     "IsAlsoFoundIn(from-link) = ? AND IsAlsoFoundIn(to-link) = ?",
231 :     [$fid, $self->{externalDatabase}], "alias");
232 :     # Return the value list.
233 :     return @retVal;
234 :     }
235 :    
236 :    
237 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3