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

View of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Thu May 17 23:43:57 2007 UTC (12 years, 5 months ago) by parrello
Branch: MAIN
Changes since 1.7: +55 -16 lines
Fixed some bugs.

#!/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.

=back

=cut

# 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.

=back

=cut

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.

=back

=cut

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.

=cut

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] => "$_->[0], $_->[1] docking results" } @pdbData;
    my @pdbNames = map { $_->[0] } @pdbData;
    # Compute the number of rows to display in the selection list.
    my $rowCount = (scalar(@pdbNames) < 20 ? scalar(@pdbNames) : 20);
    # Convert the PDB list into a selection list.
    my $menu = $cgi->popup_menu(-name => 'PDB', -values => \@pdbNames,
                                -labels => \%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)),
                $self->SubmitRow()
               );
    $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>

=cut

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.
        $self->OpenSession();
        # Initialize the result counter.
        $retVal = 0;
        $self->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) = ? ORDER BY DocksWith(total-energy)",
                                [$pdbID]);
        # Write the column headers.
        $self->WriteColumnHeaders("ZINC ID", "Total Energy", "Electrostatic", "Van der Waals", "Tool");
        $self->PrintLine("Processing results.");
        # Loop through the results.
        while (my $record = $query->Fetch()) {
            # Get the data for this row.
            my ($id, $name, $total, $electro, $vander, $tool) = $record->Values(['Ligand(id)', 'Ligand(name)',
                                                                                 'DocksWith(total-energy)', 
                                                                                 'DocksWith(electrostatic-energy)',
                                                                                 'DocksWith(vanderwalls-energy)',
                                                                                 'DocksWith(tool)']);
            # Format the energy results so they don't look so awful.
            my @data = map { sprintf('%.2f', $_) } ($total, $electro, $vander);
            # Create a tooltip for the ligand name.
            my $linkedID = $cgi->a({ href => "http://blaster.docking.org/zinc/srchdbk.pl?zinc=$id;go=Query",
                                     title => $name }, $id);
            # Finally, we must compute the sort key. We're getting the records in the correct order, so
            # the sort key is the ordinal of this record, which we are keeping in $retVal.
            my $key = $retVal;
            # Write everything to the session file.
            $self->WriteColumnData($retVal, $id, $linkedID, @data, $tool);
            # See if we need to update the user.
            $retVal++;
            if ($retVal % 1000 == 0) {
                $self->PrintLine("$retVal ligands processed.");
            }
        }
        Trace("$retVal rows processed.") if T(3);
        # Close the session file.
        $self->CloseSession();
    }
    # 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.

=cut

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.

=cut

sub Description {
    # Get the parameters.
    my ($self) = @_;
    # Return the result.
    return "Show the docking results for a specific PDB.";
}

=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>.

=cut

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
method.

=over 4

=item format

Download format type code.

=item RETURN

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

=back

=cut

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

=head3 ColumnTitle

C<< my $title = $shelp->ColumnTitle($colName); >>

Return the column heading title to be used for the specified column name.
In this case, we just return the column name unmodified.

=over 4

=item colName

Name of the desired column.

=item RETURN

Returns the title to be used as the column header for the named column.

=back

=cut

sub ColumnTitle {
    my ($self, $colName) = @_;
    return $colName;
}


1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3