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

Diff of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed Nov 8 23:18:54 2006 UTC revision 1.9, Mon Jul 16 20:04:51 2007 UTC
# Line 4  Line 4 
4    
5      use strict;      use strict;
6      use Tracer;      use Tracer;
     use SearchHelper;  
7      use CGI;      use CGI;
8      use HTML;      use HTML;
9      use Sprout;      use Sprout;
10      use FeatureData;      use RHLigands;
11      use FeatureQuery;      use base 'SearchHelper';
12    
13      our @ISA = qw(SearchHelper);  =head1 Drug Target PDB Docking Results Search Helper
   
 =head1 Drug Target Project Summary Feature Search Helper  
14    
15  =head2 Introduction  =head2 Introduction
16    
17  This search helper will display all the features that participated in a particular  This search helper will display all the docking results for a particular
18  drug target project. Each project represents a single study, generally related  PDB. Most search helpers return a list of features. This one returns
19  to a specified organism. The study finds PDBs that are good drug target  a list of ligands. As a result, it is structurally very different. In
20  candidates, and these are connected to the relevant B<DrugTargetProject> entity  particular, all the columns are returned as extras.
 instance in the database. From the PDB, we can get a list of the related  
 features, and these features are the ones we return in the search.  
21    
22  This search has the following extra parameters in addition to the ones  This search has the following extra parameters.
 produced by the B<SpecialOptions> method of the B<FeatureQuery> object.  
23    
24  =over 4  =over 4
25    
26  =item project  =item PDB
27    
28    ID of the PDB whose information is to be displayed.
29    
30    =back
31    
32    =cut
33    
34    # Table of drug topic category codes.
35    my %CodeTable = (
36                     'ES'   => 'Essential',
37                     'ES-X' => 'Essential',
38                     'ES-L' => 'Essential',
39                     'KA-T' => 'Antibiotic Target',
40                     'KA-I' => 'Antibiotic Inhibitor',
41                     'VA'   => 'Virulence Associated',
42                     'VA-K' => 'Virulence Associated',
43                     'VA-P' => 'Virulence Assocated',
44                     'TX-K' => 'Toxin',
45                     'TX-B' => 'Toxin',
46                     'SA-A' => 'Surface Associated',
47                     'SA-P' => 'Surface Associated',
48                     'SA-S' => 'Surface Associated',
49                     'SA'   => 'Surface Associated',
50                     'SE-P' => 'Secreted Protein',
51                     'SE'   => 'Secreted Protein',
52                    );
53    
54    =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    =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  ID of the drug target project to display.  =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  =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  =head2 Virtual Methods  =head2 Virtual Methods
129    
130  =head3 Form  =head3 Form
131    
132  C<< my $html = $shelp->Include(); >>  C<< my $html = $shelp->Form(); >>
133    
134  Generate the HTML for a form to request a new search.  Generate the HTML for a form to request a new search.
135    
# Line 52  Line 142 
142      my $cgi = $self->Q();      my $cgi = $self->Q();
143      my $sprout = $self->DB();      my $sprout = $self->DB();
144      # Start the form.      # Start the form.
145      my $retVal = $self->FormStart("Select Drug Target Project");      my $retVal = $self->FormStart("Select PDB");
146      # Get a list of all the projects.      # Get a list of all the PDBs with docking results.
147      my @projectNames = $sprout->GetFlat(['DrugProject'], "", [], 'DrugProject(id)');      my @pdbData = $sprout->GetAll(['PDB'], "PDB(docking-count) > 0 ORDER BY PDB(docking-count) DESC",
148      # See if there's already a project selected.                                    [], ['PDB(id)', 'PDB(docking-count)']);
149      my $defaultProject = $cgi->param('project');      # See if there's already a PDB selected.
150      # Convert the project list into a drop-down menu.      my $defaultPDB = $cgi->param('PDB');
151      my $menu = $cgi->popup_menu(-name => 'project', -values => \@projectNames,      # Create the PDB selection strings.
152                                  -default => $defaultProject);      my %pdbStrings = map { $_->[0] => "$_->[0], $_->[1] docking results" } @pdbData;
153      # Build a table from the drop-down menu, the special options, and the submit row.      my @pdbNames = map { $_->[0] } @pdbData;
154        # Compute the number of rows to display in the selection list.
155        my $rowCount = (scalar(@pdbNames) < 20 ? scalar(@pdbNames) : 20);
156        # Convert the PDB list into a selection list.
157        my $menu = $cgi->popup_menu(-name => 'PDB', -values => \@pdbNames,
158                                    -labels => \%pdbStrings,
159                                    -default => $defaultPDB, -rows => $rowCount);
160        # Build a table from the PDB list and the submit row.
161      my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),      my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
162                 FeatureQuery::SpecialOptions($self),                  $self->SubmitRow()
163                 $self->SubmitRow());                 );
164      $retVal .= $self->MakeTable(\@rows);      $retVal .= $self->MakeTable(\@rows);
165      # Close the form.      # Close the form.
166      $retVal .= $self->FormEnd();      $retVal .= $self->FormEnd();
# Line 79  Line 176 
176  be written to the session cache file and the number of results will be  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  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.  returned and a result message will be stored in this object describing the problem.
179    This search does not return features, so it calls B<WriteColumnHeaders> and
180    B<WriteColumnData> instead of the handier B<PutFeature>
181    
182  =cut  =cut
183    
# Line 90  Line 189 
189      # Declare the return variable. If it remains undefined, the caller will      # Declare the return variable. If it remains undefined, the caller will
190      # know that an error occurred.      # know that an error occurred.
191      my $retVal;      my $retVal;
192      # Insure a project is selected.      # Insure a PDB is selected.
193      my $project = $cgi->param('project');      my $pdbID = $cgi->param('PDB');
194      if (! $project) {      if (! $pdbID) {
195          $self->SetMessage("No project specified.");          $self->SetMessage("No PDB specified.");
196      } else {      } else {
197            # 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          # Initialize the session file.          # Initialize the session file.
207          $self->OpenSession();          $self->OpenSession($rhelp);
208          # Initialize the result counter.          # Initialize the result counter.
209          $retVal = 0;          $retVal = 0;
210          # Get a query that will return the features for the project.          $self->PrintLine("Finding docking results for $pdbID.");
211          my $query= $sprout->Get(['ContainsTopic', 'ContainsAnalysisOf', 'PDB',          # Get a query that will return the docking results for this PDB.
212                                   'DescribesProteinForFeature', 'Feature'],          my $query= $sprout->Get(['DocksWith', 'Ligand'],
213                                  "ContainsTopic(from-link) = ?", [$project]);                                  "DocksWith(from-link) = ? ORDER BY DocksWith(total-energy)",
214          # Create a feature data object to manage our results.                                  [$pdbID]);
215          my $fd = FeatureData->new($self);          # Write the column headers.
216            $self->PrintLine("Processing results.");
217          # Loop through the results.          # Loop through the results.
218          while (my $record = $query->Fetch()) {          while (my $record = $query->Fetch()) {
219              # Validate the PDB ID.              # Get the data for this row.
220              my ($pdb) = $record->Value('DescribesProteinForFeature(from-link)');              my ($id, $total, $electro, $vander, $tool) = $record->Values(['Ligand(id)',
221              if ($pdb =~ /^pdb([^.]+)\./i) {                                                                            'DocksWith(total-energy)',
222                  # Here we're okay, so we yank out the real PDB ID from the file title and                                                                            'DocksWith(electrostatic-energy)',
223                  # apply a link.                                                                            'DocksWith(vanderwalls-energy)',
224                  my $pdbID = $1;                                                                            'DocksWith(tool)']);
225                  my $pdbInfo = $cgi->a({href => "http://www.rcsb.org/pdb/explore.do?structureId=$pdbID",              # Format the energy results so they don't look so awful.
226                                        title => "display this protein's page in the Protein Data Bank",              ($total, $electro, $vander) = map { sprintf('%.2f', $_) } ($total, $electro, $vander);
227                                        alt =>  "display this protein's page in the Protein Data Bank",              # Put the extra columns.
228                                        target => "_blank"}, $pdbID);              $rhelp->PutExtraColumns(total => $total, electrostatic => $electro, vanderwaals => $vander,
229                  # Get the PDB title.                                      tool => $tool);
230                  my ($pdbTitle) = $record->Value('PDB(title)');              # Finally, we must compute the sort key. We're getting the records in the correct order, so
231                  # Store this feature in the data object.              # the sort key is the ordinal of this record, which we are keeping in $retVal.
232                  $fd->Store($record);              my $key = $retVal;
233                  # Add the PDB columns.              # Write everything to the session file.
234                  $fd->AddExtraColumns('Free PDB' => $pdbInfo, 'Title' => $pdbTitle);              $rhelp->PutData($key, $id, $record);
235                  # Put it in the results list.              # See if we need to update the user.
                 $self->PutFeature($fd);  
236                  $retVal++;                  $retVal++;
237              } else {              if ($retVal % 1000 == 0) {
238                  # Here the PDB didn't have the format we expected.                  $self->PrintLine("$retVal ligands processed.");
                 Confess("Invalid PDB ID \"$pdb\" found in database.")  
239              }              }
240          }          }
241            Trace("$retVal rows processed.") if T(3);
242          # Close the session file.          # Close the session file.
243          $self->CloseSession();          $self->CloseSession();
244      }      }
# Line 138  Line 246 
246      return $retVal;      return $retVal;
247  }  }
248    
249  =head3 DefaultFeatureColumns  =head3 Description
250    
251  C<< my @cols = $shelp->DefaultFeatureColumns(); >>  C<< my $htmlText = $shelp->Description(); >>
252    
253  This method returns a list of the descriptors for the columns to be  Return a description of this search. The description is used for the table of contents
254  displayed by this search, overriding the standard column set.  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  =cut
258    
259  sub DefaultFeatureColumns {  sub Description {
260      # Get the parameters.      # Get the parameters.
261      my ($self) = @_;      my ($self) = @_;
262      # Return the result.      # Return the result.
263      return qw(orgName function protlink);      return "Show the docking results for a specific PDB.";
264  }  }
265    
266  =head3 Description  =head3 SearchTitle
267    
268  C<< my $htmlText = $shelp->Description(); >>  C<< my $titleHtml = $shelp->SearchTitle(); >>
269    
270  Return a description of this search. The description is used for the table of contents  Return the display title for this search. The display title appears above the search results.
271  on the main search tools page. It may contain HTML, but it should be character-level,  If no result is returned, no title will be displayed. The result should be an html string
272  not block-level, since the description is going to appear in a list.  that can be legally put inside a block tag such as C<h3> or C<p>.
273    
274  =cut  =cut
275    
276  sub Description {  sub SearchTitle {
277      # Get the parameters.      # Get the parameters.
278      my ($self) = @_;      my ($self) = @_;
279      # Return the result.      # Compute the title. We extract the PDB ID from the query parameters.
280      return "Show the PDB and feature relationships for a specified drug target analysis project.";      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  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3