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

Annotation of /Sprout/TargetCriterionCellLocation.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 TargetCriterionCellLocation;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use Sprout;
25 :     use base qw(TargetCriterionQuery);
26 :    
27 :     =head1 Cell Location Target Search Criterion Object
28 :    
29 :     =head2 Introduction
30 :    
31 :     This is a search criterion object for filtering by cell location. A feature's
32 :     protein is considered a match for a particular cell location if there is an
33 :     C<IsPossiblePlaceFor> record connecting the feature and the location with a match
34 :     score of 2.5 or better.
35 :    
36 :     =head3 new
37 :    
38 :     my $tc = TargetCriterionCellLocation->new($rhelp, $name, $label, $hint);
39 :    
40 :     Construct a new TargetCriterionCellLocation object. The following parameters are
41 :     expected.
42 :    
43 :     =over 4
44 :    
45 :     =item rhelp
46 :    
47 :     [[ResultHelperPm]] object for the active search.
48 :    
49 :     =item name
50 :    
51 :     Identifying name of this criterion type.
52 :    
53 :     =item label
54 :    
55 :     Display label for this criterion type.
56 :    
57 :     =item hint
58 :    
59 :     Hint tooltip for this criterion type.
60 :    
61 :     =back
62 :    
63 :     =cut
64 :    
65 :     sub new {
66 :     # Get the parameters.
67 :     my ($class, $rhelp, $name, $label, $hint) = @_;
68 :     # Compute the possible cell locations.
69 :     my $sprout = $rhelp->DB();
70 :     my %selectionData;
71 :     for my $cello ($sprout->GetFlat('CellLocation', "", [], 'id')) {
72 :     # The cell location code is a wiki word. We convert it into a real
73 :     # word by peeling capitalized sections off one by one.
74 :     my @words;
75 :     while ($cello =~ /([A-Z][a-z]+)/g) {
76 :     push @words, $1;
77 :     }
78 :     $selectionData{$cello} = join(" ", @words);
79 :     }
80 :     # Package them with the label and hint.
81 :     my %options = (
82 :     name => $name,
83 :     label => $label,
84 :     hint => $hint,
85 :     selectionData => \%selectionData,
86 :     );
87 :     # Construct the underlying object, specifying that the main field of interest
88 :     # is the from-link of IsPossiblePlaceFor
89 :     my $retVal = TargetCriterionQuery::new($class, $rhelp, \%options,
90 :     'from-link', qw(Feature IsPossiblePlaceFor));
91 :     # Denote this criterion is insane.
92 :     $retVal->{sanity} = 0;
93 :     # Return the object.
94 :     return $retVal;
95 :     }
96 :    
97 :     =head2 Virtual Methods
98 :    
99 :     =head3 Validate
100 :    
101 :     my $okFlag = $tc->Validate($parms);
102 :    
103 :     Return TRUE if the specified parameters are valid for a search criterion of this type
104 :     and FALSE otherwise. If an error is detected, the error message can be retrieved using
105 :     the L</message> method.
106 :    
107 :     =over 4
108 :    
109 :     =item parms
110 :    
111 :     A Criterion Parameter Object whose fields are to be validated.
112 :    
113 :     =item RETURN
114 :    
115 :     Returns TRUE if the parameters are valid, else FALSE.
116 :    
117 :     =back
118 :    
119 :     =cut
120 :    
121 :     sub Validate {
122 :     # Get the parameters.
123 :     my ($self, $parms) = @_;
124 :     # Default to valid.
125 :     my $retVal = 1;
126 :     # Get the selection value.
127 :     my $value = $parms->{selection};
128 :     # Insure it matches one of the codes in the selection data.
129 :     if (! exists $self->{selectionData}->{$value}) {
130 :     # No, so we have an error.
131 :     $self->SetMessage("Invalid selection \"$value\" for $self->{label}.");
132 :     $retVal = 0;
133 :     }
134 :     # Return the validation code.
135 :     return $retVal;
136 :     }
137 :    
138 :     =head3 ComputeQuery
139 :    
140 :     my ($joins, $filterString, $parms) = $tc->ComputeQuery($criterion);
141 :    
142 :     Compute the SQL filter, join list, and parameter list for this
143 :     criterion. If the criterion cannot be processed by SQL, then nothing is
144 :     returned, and the criterion must be handled during post-processing.
145 :    
146 :     The join list and the parameter list should both be list references. The
147 :     filter string is a true string.
148 :    
149 :     If the filter string only uses the B<Genome> and B<Feature> tables, then the
150 :     join list can be left empty. Otherwise, the join list should start with the
151 :     particular starting point (B<Genome> or B<Feature>) and list the path through
152 :     the other relevant entities and relationships. Each criterion will have its
153 :     own separate join path.
154 :    
155 :     =over 4
156 :    
157 :     =item criterion
158 :    
159 :     Reference to a Criterion Parameter Object.
160 :    
161 :     =item RETURN
162 :    
163 :     Returns a 3-tuple consisting of the join list, the relevant filter string,
164 :     and the matching parameters. If the criterion cannot be processed using
165 :     SQL, then the return list contains three undefined values. (This is what happens if
166 :     you don't override this method.)
167 :    
168 :     =back
169 :    
170 :     =cut
171 :    
172 :     sub ComputeQuery {
173 :     # Get the parameters.
174 :     my ($self, $criterion) = @_;
175 :     # Fetch the join list.
176 :     my $joins = $self->JoinList();
177 :     # Compute the filter string.
178 :     my $filterString = "IsPossiblePlaceFor(from-link) = ? AND IsPossiblePlaceFor(confidence) >= 2.5";
179 :     # Finally, we build the parameter list, which contains the selection value.
180 :     my $parms = [ $criterion->{selection} ];
181 :     # Return the results.
182 :     return ($joins, $filterString, $parms);
183 :     }
184 :    
185 :     =head3 GetValueData
186 :    
187 :     my $value = $tc->GetValueData($feature);
188 :    
189 :     Return the value data from the specified feature that is relevant to this
190 :     criterion. This method is called when the object cache is empty and the
191 :     value is needed in order to call L</PutExtraColumns> or L</CheckValue>.
192 :    
193 :     =over 4
194 :    
195 :     =item feature
196 :    
197 :     An [[ERDBObjectPm]] describing the current feature.
198 :    
199 :     =item RETURN
200 :    
201 :     Returns a reference to a possibly-empty hash that maps all of the feature's
202 :     possible cell locations to the corresponding confidence value.
203 :    
204 :     =back
205 :    
206 :     =cut
207 :    
208 :     sub GetValueData {
209 :     # Get the parameters.
210 :     my ($self, $feature) = @_;
211 :     # Get the Sprout database.
212 :     my $sprout = $feature->DB();
213 :     # Get the feature ID.
214 :     my $id = $feature->PrimaryValue('Feature(id)');
215 :     # Get the possible places for this feature.
216 :     my %retVal = map { $_->[0] => $_->[1] }
217 :     $sprout->GetAll('IsPossiblePlaceFor', 'IsPossiblePlaceFor(to-link) = ?', [$id],
218 :     'IsPossiblePlaceFor(from-link) IsPossiblePlaceFor(confidence)');
219 :     # Return them.
220 :     return \%retVal;
221 :     }
222 :    
223 :     =head3 CheckValue
224 :    
225 :     my $match = $tc->CheckValue($criterion, $valueData);
226 :    
227 :     Return TRUE if the current feature matches this criterion, else FALSE.
228 :    
229 :     =over 4
230 :    
231 :     =item criterion
232 :    
233 :     Criterion Parameter object describing this criterion's parameters.
234 :    
235 :     =item valueData
236 :    
237 :     Reference to a possibly-empty hash that maps all of the feature's
238 :     possible cell locations to the corresponding confidence value.
239 :    
240 :     =item RETURN
241 :    
242 :     Returns TRUE if the current feature matches the criterion, else FALSE.
243 :    
244 :     =back
245 :    
246 :     =cut
247 :    
248 :     sub CheckValue {
249 :     # Get the parameters.
250 :     my ($self, $criterion, $valueData) = @_;
251 :     # Extract the name for the location of interest.
252 :     my $locName = $criterion->{selection};
253 :     # We match if the confidence for the indicated location is 2,5 or better.
254 :     my $confidence = $valueData->{$locName};
255 :     my $retVal = (defined $confidence && $confidence >= 2.5);
256 :     # Return the result.
257 :     return $retVal;
258 :     }
259 :    
260 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3