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

View of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.7 - (download) (as text) (annotate)
Fri May 11 06:30:48 2007 UTC (13 years ago) by parrello
Branch: MAIN
Changes since 1.6: +136 -71 lines
Converted to search for a PDB's docking results.

#!/usr/bin/perl -w

package SHDrugSearch;

    use strict;
    use Tracer;
    use SearchHelper;
    use CGI;
    use HTML;
    use Sprout;
    use FeatureData;
    use FeatureQuery;

    our @ISA = qw(SearchHelper);

=head1 Drug Target PDB Docking Results Search Helper

=head2 Introduction

This search helper will display all the docking results for a particular
PDB. Most search helpers return a list of features. This one returns
a list of ligands. As a result, it is structurally very different. In
particular, all the columns are returned as extras.

This search has the following extra parameters.

=over 4

=item PDB

ID of the PDB whose information is to be displayed.



# Table of drug topic category codes.
my %CodeTable = (
                 'ES'   => 'Essential',
                 'ES-X' => 'Essential',
                 'ES-L' => 'Essential',
                 'KA-T' => 'Antibiotic Target',
                 'KA-I' => 'Antibiotic Inhibitor',
                 'VA'   => 'Virulence Associated',
                 'VA-K' => 'Virulence Associated',
                 'VA-P' => 'Virulence Assocated',
                 'TX-K' => 'Toxin',
                 'TX-B' => 'Toxin',
                 'SA-A' => 'Surface Associated',
                 'SA-P' => 'Surface Associated',
                 'SA-S' => 'Surface Associated',
                 'SA'   => 'Surface Associated',
                 'SE-P' => 'Secreted Protein',
                 'SE'   => 'Secreted Protein',

=head3 GetCategory

C<< my $description = SHDrugSearch::GetCategory($code); >>

Return the description of the specified category code.

=over 4

=item code

Category code to convert.

=item RETURN

Returns the description of the specified category code, as taken from the C<CodeTable> hash.



sub GetCategory {
    # Get the parameters.
    my ($code) = @_;
    # Convert to upper case.
    my $catCode = uc $code;
    # Trim spaces.
    $catCode =~ s/\s+//g;
    # Extract it from the hash table.
    my $retVal = $CodeTable{$catCode};
    # Check for a not-found condition.
    if (! $retVal) {
        $retVal = "Unknown Code $catCode";
    # Return the result.
    return $retVal;

=head3 PDBLink

C<< my $pdbHtml = SHDrugSearch::PDBLink($cgi, $pdbID); >>

This method converts a PDB ID to a hyperlink into the PDB web site.

=over 4

=item cgi

CGI object to be used to create the HTML.

=item pdbID

ID of the PDB to be hyperlinked.

=item RETURN

Returns a hyperlinked PDB ID that points to the PDB's page on the RCSB web site.



sub PDBLink {
    # Get the parameters.
    my ($cgi, $pdbID) = @_;
    # Compose the link.
    my $retVal = $cgi->a({href => "http://www.rcsb.org/pdb/explore.do?structureId=$pdbID",
                          title => "display this protein's page in the Protein Data Bank",
                          alt =>  "display this protein's page in the Protein Data Bank",
                          target => "_blank"}, $pdbID);

    # Return the result.
    return $retVal;

=head2 Virtual Methods

=head3 Form

C<< my $html = $shelp->Form(); >>

Generate the HTML for a form to request a new search.


sub Form {
    # Get the parameters.
    my ($self) = @_;
    # Get the CGI and sprout objects.
    my $cgi = $self->Q();
    my $sprout = $self->DB();
    # Start the form.
    my $retVal = $self->FormStart("Select PDB");
    # Get a list of all the PDBs with docking results.
    my @pdbData = $sprout->GetAll(['PDB'], "PDB(docking-count) > 0 ORDER BY PDB(docking-count) DESC",
                                  [], ['PDB(id)', 'PDB(docking-count)']);
    # See if there's already a PDB selected.
    my $defaultPDB = $cgi->param('PDB');
    # Create the PDB selection strings.
    my @pdbStrings = map { "$_->[0], $_->[1] docking results" } @pdbData;
    # Compute the number of rows to display in the selection list.
    my $rowCount = (scalar(@pdbStrings) < 20 ? scalar(@pdbStrings) : 20);
    # Convert the PDB list into a selection list.
    my $menu = $cgi->popup_menu(-name => 'PDB', -values => \@pdbStrings,
                                -default => $defaultPDB, -rows => $rowCount);
    # Build a table from the PDB list and the submit row.
    my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
    $retVal .= $self->MakeTable(\@rows);
    # Close the form.
    $retVal .= $self->FormEnd();
    # Return the result.
    return $retVal;

=head3 Find

C<< my $resultCount = $shelp->Find(); >>

Conduct a search based on the current CGI query parameters. The search results will
be written to the session cache file and the number of results will be
returned. If the search parameters are invalid, a result count of C<undef> will be
returned and a result message will be stored in this object describing the problem.
This search does not return features, so it calls B<WriteColumnHeaders> and
B<WriteColumnData> instead of the handier B<PutFeature>


sub Find {
    my ($self) = @_;
    # Get the CGI and Sprout objects.
    my $cgi = $self->Q();
    my $sprout = $self->DB();
    # Declare the return variable. If it remains undefined, the caller will
    # know that an error occurred.
    my $retVal;
    # Insure a PDB is selected.
    my $pdbID = $cgi->param('PDB');
    if (! $pdbID) {
        $self->SetMessage("No PDB specified.");
    } else {
        # Initialize the session file.
        # Initialize the result counter.
        $retVal = 0;
        PrintLine("Finding docking results for $pdbID.");
        # Get a query that will return the docking results for this PDB.
        my $query= $sprout->Get(['DocksWith', 'Ligand'],
                                "DocksWith(from-link) = ?",
        # Write the column headers.
        $self->WriteColumnHeaders("ZINC ID", "Ligand", "Total Energy", "Electrostatic", "Van der Waals", "Tool");
        PrintLine("Processing results.");
        my $rowCount = 0;
        # Loop through the results.
        while (my $record = $query->Fetch()) {
            # Get the data for this row.
            my @data = $record->Values(['Ligand(id)', 'Ligand(name)', 'DocksWith(electrostatic-energy)',
                                        'DocksWidth(vanderwaals-energy)', 'DocksWith(tool)']);
            # Write it to the session file.
            # See if we need to update the user.
            if ($rowCount % 1000 == 0) {
                PrintLine("$rowCount ligands processed.");
        # Close the session file.
    # Return the result count.
    return $retVal;

=head3 DefaultFeatureColumns

C<< my @cols = $shelp->DefaultFeatureColumns(); >>

This method returns a list of the descriptors for the columns to be
displayed by this search, overriding the standard column set.


sub DefaultFeatureColumns {
    # Get the parameters.
    my ($self) = @_;
    # Return the result.
    return qw(orgName function protlink);

=head3 Description

C<< my $htmlText = $shelp->Description(); >>

Return a description of this search. The description is used for the table of contents
on the main search tools page. It may contain HTML, but it should be character-level,
not block-level, since the description is going to appear in a list.


sub Description {
    # Get the parameters.
    my ($self) = @_;
    # Return the result.
    return "Show the PDB and gene relationships for a specified drug target analysis project.";

=head3 SearchTitle

C<< my $titleHtml = $shelp->SearchTitle(); >>

Return the display title for this search. The display title appears above the search results.
If no result is returned, no title will be displayed. The result should be an html string
that can be legally put inside a block tag such as C<h3> or C<p>.


sub SearchTitle {
    # Get the parameters.
    my ($self) = @_;
    # Compute the title. We extract the PDB ID from the query parameters.
    my $cgi = $self->Q();
    my $pdbID = $cgi->param('PDB');
    my $retVal = "Docking Results for $pdbID";
    # Return it.
    return $retVal;

=head3 DownloadFormatAvailable

C<< my $okFlag = $shelp->DownloadFormatAvailable($format); >>

This method returns TRUE if a specified download format is legal for this type of search
and FALSE otherwise. For any feature-based search, there is no need to override this

=over 4

=item format

Download format type code.

=item RETURN

Returns TRUE if the download format is legal for this search and FALSE otherwise.



sub DownloadFormatAvailable {
    # Get the parameters.
    my ($self, $format) = @_;
    # Declare the return variable.
    my $retVal = ($format eq 'tbl');
    # Return the result.
    return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3