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

View of /Sprout/SHGeneSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.3 - (download) (as text) (annotate)
Thu Dec 6 14:58:03 2007 UTC (12 years, 4 months ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2008_06_18, rast_rel_2008_06_16, rast_rel_2008_12_18, rast_rel_2008_07_21, rast_2008_0924, rast_rel_2008_04_23, rast_rel_2008_09_30, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, mgrast_rel_2008_0625, rast_rel_2008_10_09, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, mgrast_rel_2008_1110, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, rast_rel_2008_11_24, rast_rel_2008_08_07
Changes since 1.2: +5 -5 lines
Changed POD format for better compatability with Wiki.

#!/usr/bin/perl -w

package SHGeneSearch;

    use strict;
    use Tracer;
    use CGI;
    use HTML;
    use Sprout;
    use RHFeatures;
    use base 'SearchHelper';

=head1 Features in Genomes Search Helper

=head2 Introduction

The single feature search finds features from one or more selected organisms
using the full power of the B<RHFeature> filtering.

=over 4

=item genome

IDs of the relevant genome


=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();
    # Get the IDs of the currently-selected genomes (if any).
    my @genomeIDs = $cgi->param('genome');
    # Start the form.
    my $retVal = $self->FormStart("Gene Search");
    # Get the genome menu.
    my $menu = $self->NmpdrGenomeMenu('genome', 'multiple', \@genomeIDs);
    # Create a table for the form data.
    my @table = ();
    push @table, RHFeatures::WordSearchRow($self),
                 $cgi->Tr($cgi->td("Select one or more genomes"), $cgi->td({colspan => 2}, $menu)),
    $retVal .= $self->MakeTable(\@table);
    # 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);
    # Only proceed if the filter parameters are valid.
    if ($rhelp->Valid()) {
        # Get the genomes.
        $self->PrintLine("Retrieving genomes.  ");
        my @genomes = $self->GetGenomes('genome');
        # If the user specified all genomes, we simply use a single
        # undef so that the feature filter knows to act accordingly.
        if ($sprout->IsAllGenomes(\@genomes)) {
            $self->PrintLine("All genomes selected.<br />");
            @genomes = (undef);
        } else {
            my $genomeCount = scalar(@genomes);
            $self->PrintLine("Genomes found: $genomeCount.<br />");
        # Only proceed if at least one genome is specified.
        if (scalar(@genomes) == 0) {
            $self->SetMessage("Please specify at least one genome.");
        } else {
            # Set the column list.
            # Initialize the session file.
            # Initialize the result counter.
            $retVal = 0;
            # Loop through the selected genomes.
            for my $genomeID (@genomes) {
                if (defined $genomeID) {
                    $self->PrintLine("Processing genome $genomeID.  ");
                } else {
                    $self->PrintLine("Processing query.");
                Trace("Creating query. GenomeID = $genomeID") if T(3);
                my $fquery = $rhelp->GetQuery($genomeID);
                my $count = 0;
                while (my $feature = $rhelp->Fetch($fquery)) {
                    # Get the feature ID.
                    my $fid = $feature->PrimaryValue('Feature(id)');
                    # Compute the sort key.
                    my $sortKey = $rhelp->SortKey($feature);
                    $rhelp->PutData($sortKey, $fid, $feature);
                $self->PrintLine("Results found: $count.<br />");
                $retVal += $count;
            # Close the session file.
    # Return the result count.
    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 "Search for genes in selected genomes, filtered by subsystem or search keywords.";

=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. We extract the number of genomes from the query parameters.
    my $cgi = $self->Q();
    my @genomes = $cgi->param('genome');
    my $count = scalar(@genomes);
    if ($count == 1) {
        $count = $genomes[0];
    } else {
        $count = "$count Genomes";
    my $retVal = "Search for Genes in $count";
    # Return it.
    return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3