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

View of /Sprout/SHGeneBbhSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Mon Jan 19 21:56:19 2009 UTC (11 years, 2 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2009_05_18, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, rast_rel_2009_03_26, mgrast_dev_10262011, HEAD
Improved search result support.

#!/usr/bin/perl -w

package SHGeneBbhSearch;

    use strict;
    use Tracer;
    use CGI qw(-nosticky);
    use Sprout;
    use Stats;

    use RHFeatures;
    use base 'SearchHelper';


=head2 Introduction

This is a simple search that accepts as input a FIG ID or alias and lists all of
the bidirectional best hits for the indicated gene. Because some aliases
indicate multiple genes, the source gene is included in the result set.

This search has the following extra parameters.

=over 4

=item gene_id

FIG ID or alias for the gene of interest


=head2 Virtual Methods

=head3 Form

    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("Find Bidirectional Best Hits");
    # Declare a variable to hold the table rows.
    my @rows = ();
    push @rows, CGI::Tr(CGI::td("%FIG{FIG ID}% or %FIG{alias}%"),
                        CGI::td({ colSpan => 2 },
                                CGI::textfield(-name => 'gene_id', -size => 30)));
    # Get the display options for features.
    push @rows, RHFeatures::FeatureFilterFormRows($self, 'options');
    # The last row is for the submit button.
    push @rows, $self->SubmitRow();
    # Create the table.
    $retVal .= $self->MakeTable(\@rows);
    # Close the form.
    $retVal .= $self->FormEnd();
    # Return the result.
    return $retVal;

=head3 Find

    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.


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;
    # Get the result helper.
    my $rhelp = RHFeatures->new($self);
    # Validate the filtering parameters.
    if ($rhelp->Valid()) {
        # Get the search parameters.
        my $gene_id = $cgi->param('gene_id');
        # Get the default columns.
        Trace("Column list is " . join(", ", @{$rhelp->GetColumnHeaders()})) if T(3);
        # Add the source gene and the score.
        $rhelp->AddExtraColumn(queryGene => undef, title => 'Query Gene',
                                 style => 'leftAlign', download => 'text');
        $rhelp->AddExtraColumn(score => undef, title => 'Score',
                                 style => 'left', download => 'num');
        # Start the output session.
        # Find the genes for the specified ID. If it's a FIG ID, this is easy;
        # otherwise, we have to get an alias.
        my $input_id = $cgi->param('gene_id');
        if (! $input_id) {
            $self->SetMessage("Please specify a valid ID.");
        } else {
            # We have an ID. We'll put its list of aliases in here.
            my @queryGenes;
            if ($input_id =~ /^fig|/) {
                # It's a FIG ID. if it exists, we want to keep it.
                if ($sprout->Exists(Feature => $input_id)) {
                    push @queryGenes, $input_id;
            } else {
                # Look for aliases.
                push @queryGenes, $sprout->GetFlat('IsAliasOf',
                                                   "IsAliasOf(from-link) = ?",
            Trace("Query gene list is " . join(", ", @queryGenes) . ".") if T(3);
            # If we don't have anything, the ID is not found.
            if (! @queryGenes) {
                $self->SetMessage("The ID \"$input_id\" was not found in our database.");
            } else {
                # Initialize the result counter.
                $retVal = 0;
                # We're finally ready to search. Loop through the IDs.
                for my $queryGene (@queryGenes) {
                    $self->PrintLine("Locating BBHs of $queryGene.<br />");
                    Trace("Processing $queryGene.") if T(3);
                    # Get this feature's BBHs.
                    my $bbhList = FIGRules::BBHData($queryGene);
                    # Loop through the results.
                    $self->PrintLine(scalar(@$bbhList) . " hits found.<br />");
                    for my $bbh (@$bbhList) {
                        # Get the data.
                        my ($hit, $score) = @$bbh;
                        Trace("Hit found at $hit.") if T(3);
                        # Only proceed if this BBH exists in our database.
                        my $record = $sprout->GetEntity(Feature => $hit);
                        if (defined $record) {
                            Trace("Hit confirmed in Sprout.") if T(3);
                            # Compute the sort key.
                            my $sortKey = $rhelp->SortKey($record);
                            # Store the extra columns.
                            $rhelp->PutExtraColumns(queryGene => $queryGene,
                                                    score => $score);
                            # Put the data into the output.
                            $rhelp->PutData($sortKey, $hit, $record);
                            # Count it.
        # Close the session file.
        Trace("Session closed.") if T(3);
    # Return the result count.
    return $retVal;

=head3 SearchTitle

    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.
    my $cgi = $self->Q();
    # Get a safe copy of the input value.
    my $input = CGI::escapeHTML($cgi->param('gene_id') || "Unknown Gene");
    # Generate the title.
    my $retVal = "Bidirectional Best Hits for $input.";
    # Return it.
    return $retVal;

=head3 Description

    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 "Display the %FIG{bidirectional best hits}% of a specified %FIG{gene}%.";


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3