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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3