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

Annotation of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3