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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package SHDrugSearch;
4 :    
5 :     use strict;
6 :     use Tracer;
7 :     use SearchHelper;
8 :     use CGI;
9 :     use HTML;
10 :     use Sprout;
11 :     use FeatureData;
12 :     use FeatureQuery;
13 :    
14 :     our @ISA = qw(SearchHelper);
15 :    
16 : parrello 1.7 =head1 Drug Target PDB Docking Results Search Helper
17 : parrello 1.1
18 :     =head2 Introduction
19 :    
20 : parrello 1.7 This search helper will display all the docking results for a particular
21 :     PDB. Most search helpers return a list of features. This one returns
22 :     a list of ligands. As a result, it is structurally very different. In
23 :     particular, all the columns are returned as extras.
24 : parrello 1.1
25 : parrello 1.7 This search has the following extra parameters.
26 : parrello 1.1
27 :     =over 4
28 :    
29 : parrello 1.7 =item PDB
30 : parrello 1.1
31 : parrello 1.7 ID of the PDB whose information is to be displayed.
32 : parrello 1.3
33 : parrello 1.1 =back
34 :    
35 : parrello 1.2 =cut
36 :    
37 :     # Table of drug topic category codes.
38 :     my %CodeTable = (
39 : parrello 1.5 'ES' => 'Essential',
40 : parrello 1.6 'ES-X' => 'Essential',
41 :     'ES-L' => 'Essential',
42 :     'KA-T' => 'Antibiotic Target',
43 :     'KA-I' => 'Antibiotic Inhibitor',
44 : parrello 1.5 'VA' => 'Virulence Associated',
45 : parrello 1.6 'VA-K' => 'Virulence Associated',
46 :     'VA-P' => 'Virulence Assocated',
47 :     'TX-K' => 'Toxin',
48 :     'TX-B' => 'Toxin',
49 :     'SA-A' => 'Surface Associated',
50 : parrello 1.5 'SA-P' => 'Surface Associated',
51 :     'SA-S' => 'Surface Associated',
52 :     'SA' => 'Surface Associated',
53 : parrello 1.6 'SE-P' => 'Secreted Protein',
54 : parrello 1.5 'SE' => 'Secreted Protein',
55 : parrello 1.2 );
56 :    
57 : parrello 1.5 =head3 GetCategory
58 :    
59 :     C<< my $description = SHDrugSearch::GetCategory($code); >>
60 :    
61 :     Return the description of the specified category code.
62 :    
63 :     =over 4
64 :    
65 :     =item code
66 :    
67 :     Category code to convert.
68 :    
69 :     =item RETURN
70 :    
71 :     Returns the description of the specified category code, as taken from the C<CodeTable> hash.
72 :    
73 :     =back
74 :    
75 :     =cut
76 :    
77 :     sub GetCategory {
78 :     # Get the parameters.
79 :     my ($code) = @_;
80 :     # Convert to upper case.
81 :     my $catCode = uc $code;
82 :     # Trim spaces.
83 :     $catCode =~ s/\s+//g;
84 :     # Extract it from the hash table.
85 :     my $retVal = $CodeTable{$catCode};
86 :     # Check for a not-found condition.
87 :     if (! $retVal) {
88 :     $retVal = "Unknown Code $catCode";
89 :     }
90 :     # Return the result.
91 :     return $retVal;
92 :     }
93 :    
94 : parrello 1.7 =head3 PDBLink
95 :    
96 :     C<< my $pdbHtml = SHDrugSearch::PDBLink($cgi, $pdbID); >>
97 :    
98 :     This method converts a PDB ID to a hyperlink into the PDB web site.
99 :    
100 :     =over 4
101 :    
102 :     =item cgi
103 :    
104 :     CGI object to be used to create the HTML.
105 :    
106 :     =item pdbID
107 :    
108 :     ID of the PDB to be hyperlinked.
109 :    
110 :     =item RETURN
111 :    
112 :     Returns a hyperlinked PDB ID that points to the PDB's page on the RCSB web site.
113 :    
114 :     =back
115 :    
116 :     =cut
117 :    
118 :     sub PDBLink {
119 :     # Get the parameters.
120 :     my ($cgi, $pdbID) = @_;
121 :     # Compose the link.
122 :     my $retVal = $cgi->a({href => "http://www.rcsb.org/pdb/explore.do?structureId=$pdbID",
123 :     title => "display this protein's page in the Protein Data Bank",
124 :     alt => "display this protein's page in the Protein Data Bank",
125 :     target => "_blank"}, $pdbID);
126 :    
127 :     # Return the result.
128 :     return $retVal;
129 :     }
130 :    
131 : parrello 1.1 =head2 Virtual Methods
132 :    
133 :     =head3 Form
134 :    
135 : parrello 1.3 C<< my $html = $shelp->Form(); >>
136 : parrello 1.1
137 :     Generate the HTML for a form to request a new search.
138 :    
139 :     =cut
140 :    
141 :     sub Form {
142 :     # Get the parameters.
143 :     my ($self) = @_;
144 :     # Get the CGI and sprout objects.
145 :     my $cgi = $self->Q();
146 :     my $sprout = $self->DB();
147 :     # Start the form.
148 : parrello 1.7 my $retVal = $self->FormStart("Select PDB");
149 :     # Get a list of all the PDBs with docking results.
150 :     my @pdbData = $sprout->GetAll(['PDB'], "PDB(docking-count) > 0 ORDER BY PDB(docking-count) DESC",
151 :     [], ['PDB(id)', 'PDB(docking-count)']);
152 :     # See if there's already a PDB selected.
153 :     my $defaultPDB = $cgi->param('PDB');
154 :     # Create the PDB selection strings.
155 :     my @pdbStrings = map { "$_->[0], $_->[1] docking results" } @pdbData;
156 :     # Compute the number of rows to display in the selection list.
157 :     my $rowCount = (scalar(@pdbStrings) < 20 ? scalar(@pdbStrings) : 20);
158 :     # Convert the PDB list into a selection list.
159 :     my $menu = $cgi->popup_menu(-name => 'PDB', -values => \@pdbStrings,
160 :     -default => $defaultPDB, -rows => $rowCount);
161 :     # Build a table from the PDB list and the submit row.
162 : parrello 1.1 my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
163 : parrello 1.3 $self->SubmitRow()
164 :     );
165 : parrello 1.1 $retVal .= $self->MakeTable(\@rows);
166 :     # Close the form.
167 :     $retVal .= $self->FormEnd();
168 :     # Return the result.
169 :     return $retVal;
170 :     }
171 :    
172 :     =head3 Find
173 :    
174 :     C<< my $resultCount = $shelp->Find(); >>
175 :    
176 :     Conduct a search based on the current CGI query parameters. The search results will
177 :     be written to the session cache file and the number of results will be
178 :     returned. If the search parameters are invalid, a result count of C<undef> will be
179 :     returned and a result message will be stored in this object describing the problem.
180 : parrello 1.7 This search does not return features, so it calls B<WriteColumnHeaders> and
181 :     B<WriteColumnData> instead of the handier B<PutFeature>
182 : parrello 1.1
183 :     =cut
184 :    
185 :     sub Find {
186 :     my ($self) = @_;
187 :     # Get the CGI and Sprout objects.
188 :     my $cgi = $self->Q();
189 :     my $sprout = $self->DB();
190 :     # Declare the return variable. If it remains undefined, the caller will
191 :     # know that an error occurred.
192 :     my $retVal;
193 : parrello 1.7 # Insure a PDB is selected.
194 :     my $pdbID = $cgi->param('PDB');
195 :     if (! $pdbID) {
196 :     $self->SetMessage("No PDB specified.");
197 : parrello 1.1 } else {
198 :     # Initialize the session file.
199 :     $self->OpenSession();
200 :     # Initialize the result counter.
201 :     $retVal = 0;
202 : parrello 1.7 PrintLine("Finding docking results for $pdbID.");
203 :     # Get a query that will return the docking results for this PDB.
204 :     my $query= $sprout->Get(['DocksWith', 'Ligand'],
205 :     "DocksWith(from-link) = ?",
206 :     [$pdbID]);
207 :     # Write the column headers.
208 :     $self->WriteColumnHeaders("ZINC ID", "Ligand", "Total Energy", "Electrostatic", "Van der Waals", "Tool");
209 :     PrintLine("Processing results.");
210 :     my $rowCount = 0;
211 : parrello 1.1 # Loop through the results.
212 :     while (my $record = $query->Fetch()) {
213 : parrello 1.7 # Get the data for this row.
214 :     my @data = $record->Values(['Ligand(id)', 'Ligand(name)', 'DocksWith(electrostatic-energy)',
215 :     'DocksWidth(vanderwaals-energy)', 'DocksWith(tool)']);
216 :     # Write it to the session file.
217 :     $self->WriteColumnData(@data);
218 :     # See if we need to update the user.
219 :     $rowCount++;
220 :     if ($rowCount % 1000 == 0) {
221 :     PrintLine("$rowCount ligands processed.");
222 : parrello 1.1 }
223 :     }
224 :     # Close the session file.
225 :     $self->CloseSession();
226 :     }
227 :     # Return the result count.
228 :     return $retVal;
229 :     }
230 :    
231 :     =head3 DefaultFeatureColumns
232 :    
233 :     C<< my @cols = $shelp->DefaultFeatureColumns(); >>
234 :    
235 :     This method returns a list of the descriptors for the columns to be
236 :     displayed by this search, overriding the standard column set.
237 :    
238 :     =cut
239 :    
240 :     sub DefaultFeatureColumns {
241 :     # Get the parameters.
242 :     my ($self) = @_;
243 :     # Return the result.
244 :     return qw(orgName function protlink);
245 :     }
246 :    
247 :     =head3 Description
248 :    
249 :     C<< my $htmlText = $shelp->Description(); >>
250 :    
251 :     Return a description of this search. The description is used for the table of contents
252 :     on the main search tools page. It may contain HTML, but it should be character-level,
253 :     not block-level, since the description is going to appear in a list.
254 :    
255 :     =cut
256 :    
257 :     sub Description {
258 :     # Get the parameters.
259 :     my ($self) = @_;
260 :     # Return the result.
261 : parrello 1.4 return "Show the PDB and gene relationships for a specified drug target analysis project.";
262 : parrello 1.1 }
263 :    
264 : parrello 1.7 =head3 SearchTitle
265 :    
266 :     C<< my $titleHtml = $shelp->SearchTitle(); >>
267 :    
268 :     Return the display title for this search. The display title appears above the search results.
269 :     If no result is returned, no title will be displayed. The result should be an html string
270 :     that can be legally put inside a block tag such as C<h3> or C<p>.
271 :    
272 :     =cut
273 :    
274 :     sub SearchTitle {
275 :     # Get the parameters.
276 :     my ($self) = @_;
277 :     # Compute the title. We extract the PDB ID from the query parameters.
278 :     my $cgi = $self->Q();
279 :     my $pdbID = $cgi->param('PDB');
280 :     my $retVal = "Docking Results for $pdbID";
281 :     # Return it.
282 :     return $retVal;
283 :     }
284 :    
285 :     =head3 DownloadFormatAvailable
286 :    
287 :     C<< my $okFlag = $shelp->DownloadFormatAvailable($format); >>
288 :    
289 :     This method returns TRUE if a specified download format is legal for this type of search
290 :     and FALSE otherwise. For any feature-based search, there is no need to override this
291 :     method.
292 :    
293 :     =over 4
294 :    
295 :     =item format
296 :    
297 :     Download format type code.
298 :    
299 :     =item RETURN
300 :    
301 :     Returns TRUE if the download format is legal for this search and FALSE otherwise.
302 :    
303 :     =back
304 :    
305 :     =cut
306 :    
307 :     sub DownloadFormatAvailable {
308 :     # Get the parameters.
309 :     my ($self, $format) = @_;
310 :     # Declare the return variable.
311 :     my $retVal = ($format eq 'tbl');
312 :     # Return the result.
313 :     return $retVal;
314 :     }
315 :    
316 :    
317 : parrello 1.1 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3