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

Annotation of /Sprout/SHGeneSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package SHGeneSearch;
4 :    
5 :     use strict;
6 :     use Tracer;
7 :     use CGI;
8 :     use HTML;
9 :     use Sprout;
10 :     use RHFeatures;
11 :     use base 'SearchHelper';
12 :    
13 :     =head1 Features in Genomes Search Helper
14 :    
15 :     =head2 Introduction
16 :    
17 :     The single feature search finds features from one or more selected organisms
18 :     using the full power of the B<RHFeature> filtering.
19 :    
20 :     =over 4
21 :    
22 :     =item genome
23 :    
24 :     IDs of the relevant genome
25 :    
26 :     =back
27 :    
28 :     =head2 Virtual Methods
29 :    
30 :     =head3 Form
31 :    
32 : parrello 1.3 my $html = $shelp->Form();
33 : parrello 1.1
34 :     Generate the HTML for a form to request a new search.
35 :    
36 :     =cut
37 :    
38 :     sub Form {
39 :     # Get the parameters.
40 :     my ($self) = @_;
41 :     # Get the CGI and sprout objects.
42 :     my $cgi = $self->Q();
43 :     my $sprout = $self->DB();
44 :     # Get the IDs of the currently-selected genomes (if any).
45 :     my @genomeIDs = $cgi->param('genome');
46 :     # Start the form.
47 :     my $retVal = $self->FormStart("Gene Search");
48 :     # Get the genome menu.
49 :     my $menu = $self->NmpdrGenomeMenu('genome', 'multiple', \@genomeIDs);
50 :     # Create a table for the form data.
51 :     my @table = ();
52 :     push @table, RHFeatures::WordSearchRow($self),
53 :     $cgi->Tr($cgi->td("Select one or more genomes"), $cgi->td({colspan => 2}, $menu)),
54 :     RHFeatures::FeatureFilterFormRows($self),
55 :     $self->SubmitRow();
56 :     $retVal .= $self->MakeTable(\@table);
57 :     # Close the form.
58 :     $retVal .= $self->FormEnd();
59 :     # Return the result.
60 :     return $retVal;
61 :     }
62 :    
63 :     =head3 Find
64 :    
65 : parrello 1.3 my $resultCount = $shelp->Find();
66 : parrello 1.1
67 :     Conduct a search based on the current CGI query parameters. The search results will
68 :     be written to the session cache file and the number of results will be
69 :     returned. If the search parameters are invalid, a result count of C<undef> will be
70 :     returned and a result message will be stored in this object describing the problem.
71 :    
72 :     =cut
73 :    
74 :     sub Find {
75 :     my ($self) = @_;
76 :     # Get the CGI and Sprout objects.
77 :     my $cgi = $self->Q();
78 :     my $sprout = $self->DB();
79 :     # Declare the return variable. If it remains undefined, the caller will
80 :     # know that an error occurred.
81 :     my $retVal;
82 :     # Get the result helper.
83 :     my $rhelp = RHFeatures->new($self);
84 :     # Only proceed if the filter parameters are valid.
85 :     if ($rhelp->Valid()) {
86 :     # Get the genomes.
87 :     $self->PrintLine("Retrieving genomes. ");
88 :     my @genomes = $self->GetGenomes('genome');
89 :     # If the user specified all genomes, we simply use a single
90 :     # undef so that the feature filter knows to act accordingly.
91 :     if ($sprout->IsAllGenomes(\@genomes)) {
92 :     $self->PrintLine("All genomes selected.<br />");
93 :     @genomes = (undef);
94 :     } else {
95 :     my $genomeCount = scalar(@genomes);
96 :     $self->PrintLine("Genomes found: $genomeCount.<br />");
97 :     }
98 :     # Only proceed if at least one genome is specified.
99 :     if (scalar(@genomes) == 0) {
100 :     $self->SetMessage("Please specify at least one genome.");
101 :     } else {
102 :     # Set the column list.
103 :     $self->DefaultColumns($rhelp);
104 :     # Initialize the session file.
105 :     $self->OpenSession($rhelp);
106 :     # Initialize the result counter.
107 :     $retVal = 0;
108 :     # Loop through the selected genomes.
109 :     for my $genomeID (@genomes) {
110 :     if (defined $genomeID) {
111 :     $self->PrintLine("Processing genome $genomeID. ");
112 :     } else {
113 : parrello 1.2 $self->PrintLine("Processing query.");
114 : parrello 1.1 }
115 :     Trace("Creating query. GenomeID = $genomeID") if T(3);
116 :     my $fquery = $rhelp->GetQuery($genomeID);
117 :     my $count = 0;
118 :     while (my $feature = $rhelp->Fetch($fquery)) {
119 :     # Get the feature ID.
120 :     my $fid = $feature->PrimaryValue('Feature(id)');
121 :     # Compute the sort key.
122 :     my $sortKey = $rhelp->SortKey($feature);
123 :     $rhelp->PutData($sortKey, $fid, $feature);
124 :     $count++;
125 :     }
126 :     $self->PrintLine("Results found: $count.<br />");
127 :     $retVal += $count;
128 :     }
129 :     # Close the session file.
130 :     $self->CloseSession();
131 :     }
132 :     }
133 :     # Return the result count.
134 :     return $retVal;
135 :     }
136 :    
137 :     =head3 Description
138 :    
139 : parrello 1.3 my $htmlText = $shelp->Description();
140 : parrello 1.1
141 :     Return a description of this search. The description is used for the table of contents
142 :     on the main search tools page. It may contain HTML, but it should be character-level,
143 :     not block-level, since the description is going to appear in a list.
144 :    
145 :     =cut
146 :    
147 :     sub Description {
148 :     # Get the parameters.
149 :     my ($self) = @_;
150 :     # Return the result.
151 :     return "Search for genes in selected genomes, filtered by subsystem or search keywords.";
152 :     }
153 :    
154 :     =head3 SearchTitle
155 :    
156 : parrello 1.3 my $titleHtml = $shelp->SearchTitle();
157 : parrello 1.1
158 :     Return the display title for this search. The display title appears above the search results.
159 :     If no result is returned, no title will be displayed. The result should be an html string
160 :     that can be legally put inside a block tag such as C<h3> or C<p>.
161 :    
162 :     =cut
163 :    
164 :     sub SearchTitle {
165 :     # Get the parameters.
166 :     my ($self) = @_;
167 :     # Compute the title. We extract the number of genomes from the query parameters.
168 :     my $cgi = $self->Q();
169 :     my @genomes = $cgi->param('genome');
170 :     my $count = scalar(@genomes);
171 :     if ($count == 1) {
172 :     $count = $genomes[0];
173 :     } else {
174 :     $count = "$count Genomes";
175 :     }
176 :     my $retVal = "Search for Genes in $count";
177 :     # Return it.
178 :     return $retVal;
179 :     }
180 :    
181 :    
182 : parrello 1.3 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3