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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3