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

View of /Sprout/SHDrugSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Mon Dec 11 19:50:05 2006 UTC (12 years, 10 months ago) by parrello
Branch: MAIN
Changes since 1.5: +10 -10 lines
Shortened category names.

#!/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 Project Summary Feature Search Helper

=head2 Introduction

This search helper will display all the features that participated in a particular
drug target project. Each project represents a single study, generally related
to a specified organism. The study finds PDBs that are good drug target
candidates, and these are connected to the relevant B<DrugTargetProject> entity
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.

This search has the following extra parameters in addition to the ones
produced by the B<SpecialOptions> method of the B<FeatureQuery> object.

=over 4

=item project

ID of the drug target project to display.

=item score

Maximum allowable score for a PDB/PEG match to be considered good
enough to display. The default is 1e-15.

=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;
}

=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 Drug Target Project");
    # Get a list of all the projects.
    my @projectNames = $sprout->GetFlat(['DrugProject'], "", [], 'DrugProject(id)');
    # See if there's already a project selected.
    my $defaultProject = $cgi->param('project');
    # Convert the project list into a drop-down menu.
    my $menu = $cgi->popup_menu(-name => 'project', -values => \@projectNames,
                                -default => $defaultProject);
    # Create the drop-down menu for scoring.
    my $defaultScore = $cgi->param('score') || '1e-15';
    my $scoreMenu = $cgi->popup_menu(-name => 'score',
                                     -values => ['1e-30', '1e-15', '1e-10', '1e-5', '1', '10'],
                                     -default => $defaultScore);
    # Build a table from the drop-down menu, the special options, and the submit row.
    my @rows = ($cgi->Tr($cgi->th('Project'), $cgi->td($menu)),
                $cgi->Tr($cgi->th('Max Score'), $cgi->td($scoreMenu)),
                FeatureQuery::SpecialOptions($self),
                $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.

=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 project and score are selected.
    my $project = $cgi->param('project');
    my $score = $cgi->param('score');
    if (! $project) {
        $self->SetMessage("No project specified.");
    } elsif (! $score) {
        $self->SetMessage("No score specified.");
    } else {
        # Initialize the session file.
        $self->OpenSession();
        # Initialize the result counter.
        $retVal = 0;
        # Get a query that will return the features for the project. 
        my $query= $sprout->Get(['ContainsTopic', 'DrugTopic', 'ContainsAnalysisOf', 'PDB',
                                 'DescribesProteinForFeature', 'Feature'],
                                "ContainsTopic(from-link) = ? AND DescribesProteinForFeature(score) <= ?",
                                [$project, $score]);
        # Create a feature data object to manage our results.
        my $fd = FeatureData->new($self);
        # Loop through the results.
        while (my $record = $query->Fetch()) {
            # Validate the PDB ID.
            my ($pdb) = $record->Value('DescribesProteinForFeature(from-link)');
            if ($pdb =~ /^pdb([^.]+)\./i) {
                # Here we're okay, so we yank out the real PDB ID from the file title and
                # apply a link.
                my $pdbID = $1;
                my $pdbInfo = $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);
                # Get the topic category. This explains why the PDB is interesting.
                my ($categoryCode) = $record->Value('DrugTopic(category)');
                my $category = $CodeTable{$categoryCode};
                # Extract the score.
                my ($score) = $record->Value('DescribesProteinForFeature(score)');
                # Store this feature in the data object.
                $fd->Store($record);
                # Add the PDB columns.
                $fd->AddExtraColumns('Free PDB' => $pdbInfo, 'Reason' => $category, 'Score' => $score);
                # Put it in the results list.
                $self->PutFeature($fd);
                $retVal++;
            } else {
                # Here the PDB didn't have the format we expected.
                Confess("Invalid PDB ID \"$pdb\" found in database.")
            }
        }
        # 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 PDB and gene relationships for a specified drug target analysis project.";
}

1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3