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

Annotation of /Sprout/SHSubSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package SHSubSearch;
4 :    
5 :     use strict;
6 :     use Tracer;
7 :     use CGI;
8 :     use HTML;
9 :     use Sprout;
10 : parrello 1.6 use RHFeatures;
11 :     use base 'SearchHelper';
12 : parrello 1.1
13 :     =head1 Subsystem Feature Search Helper
14 :    
15 :     =head2 Introduction
16 :    
17 :     This search helper displays a subsystem tree and allows the user to
18 :     select any node in the tree to get back all of the features in a single
19 :     subsystem or all the subsystems in a class. The tree will also have links to
20 :     the subsystem display pages.
21 :    
22 :     It has the following extra parameters.
23 :    
24 :     =over 4
25 :    
26 :     =item specification
27 :    
28 :     A string of the form C<id=>I<string> or C<classification=>I<string>. In the
29 :     first case, I<string> is the ID of a subsystem. In the second case,
30 :     I<string> is a LIKE-style string that can be used to get subsystems in the
31 :     specified class.
32 :    
33 :     =back
34 :    
35 :     =head2 Virtual Methods
36 :    
37 :     =head3 Form
38 :    
39 :     C<< my $html = $shelp->Form(); >>
40 :    
41 :     Generate the HTML for a form to request a new search.
42 :    
43 :     =cut
44 :    
45 :     sub Form {
46 :     # Get the parameters.
47 :     my ($self) = @_;
48 :     # Get the CGI and sprout objects.
49 :     my $cgi = $self->Q();
50 :     my $sprout = $self->DB();
51 :     # Start the form.
52 : parrello 1.2 my $retVal = $self->FormStart("Open Subsystem OR Search for Genes by Subsystem or Class");
53 : parrello 1.1 # Create a subsystem tree.
54 :     my $tree = SearchHelper::SubsystemTree($sprout, radio => 1, links => 1);
55 :     # Build a form field out of it.
56 :     my $treeField = SearchHelper::SelectionTree($cgi, $tree,
57 :     name => "specification",
58 :     target => "_blank",
59 :     selected => $cgi->param("specification"));
60 :     # We'll accumulate the form table in here.
61 :     my @rows = ();
62 : parrello 1.3 # Start with the subsystem tree.
63 :     push @rows, $cgi->Tr($cgi->th({ colspan => 3, align => "center" }, "Subsystem Tree")),
64 :     $cgi->Tr($cgi->td({ colspan => 3 }, $treeField));
65 : parrello 1.4 # Put in the keyword search box.
66 : parrello 1.1 my $expressionString = $cgi->param('keywords') || "";
67 : parrello 1.6 push @rows, RHFeatures::WordSearchRow($self);
68 : parrello 1.1 # Add the special options.
69 : parrello 1.6 push @rows, RHFeatures::FeatureFilterFormRows($self, 'options');
70 : parrello 1.1 # Finish it off with the submit row.
71 :     push @rows, $self->SubmitRow();
72 :     # Convert the form rows into a table.
73 :     $retVal .= $self->MakeTable(\@rows);
74 :     # Close the form.
75 :     $retVal .= $self->FormEnd();
76 :     # Return the result.
77 :     return $retVal;
78 :     }
79 :    
80 :     =head3 Find
81 :    
82 :     C<< my $resultCount = $shelp->Find(); >>
83 :    
84 :     Conduct a search based on the current CGI query parameters. The search results will
85 :     be written to the session cache file and the number of results will be
86 :     returned. If the search parameters are invalid, a result count of C<undef> will be
87 :     returned and a result message will be stored in this object describing the problem.
88 :    
89 :     =cut
90 :    
91 :     sub Find {
92 :     my ($self) = @_;
93 :     # Get the CGI and Sprout objects.
94 :     my $cgi = $self->Q();
95 :     my $sprout = $self->DB();
96 :     # Declare the return variable. If it remains undefined, the caller will
97 :     # know that an error occurred.
98 :     my $retVal;
99 :     # Insure we have a specification.
100 :     my $spec = $cgi->param('specification');
101 :     if (! $spec) {
102 :     $self->SetMessage("No subsystem or class selected.");
103 :     } else {
104 :     # Create a feature data object to store our results.
105 :     my $fd = FeatureData->new($self);
106 :     # We need to build a query to get our features. We need to remember
107 :     # the filter clause format and the parameter.
108 :     my ($filterClause, $parameter);
109 :     if ($spec =~ /^id=(.+)$/) {
110 :     # Here we're filtering for a single subsystem.
111 :     $filterClause = "Subsystem(id) = ?";
112 :     $parameter = $1;
113 :     } elsif ($spec =~ /^classification=(.+)$/) {
114 :     # Here we're filtering for a class.
115 :     $filterClause = "Subsystem(classification) LIKE ?";
116 :     $parameter = $1;
117 :     }
118 :     # Now we do some validation.
119 :     my $keywords = $cgi->param('keywords') || "";
120 :     if (! defined($filterClause)) {
121 :     $self->SetMessage("Invalid subsystem specification \"$spec\".");
122 :     } elsif ($self->ValidateKeywords($keywords)) {
123 :     # We're valid, so we start by collecting the main parameters for the query.
124 :     my @majorParms = (['Subsystem', 'HasRoleInSubsystem', 'Feature'],
125 :     $filterClause, [$parameter]);
126 :     # The way we execute the query is determined by whether or not
127 :     # any keywords were specified.
128 :     my $query;
129 :     if ($keywords) {
130 : parrello 1.5 $self->PrintLine("Word search query submitted.<br />");
131 : parrello 1.1 $query = $sprout->Search($keywords, 2, @majorParms);
132 :     } else {
133 : parrello 1.5 $self->PrintLine("Standard search query submitted.<br />");
134 : parrello 1.1 $query = $sprout->Get(@majorParms);
135 :     }
136 : parrello 1.6 # Get the result helper for a feature search.
137 :     my $rhelp = RHFeatures->new($self);
138 :     # Compute the default columns. This is a very simple search which
139 :     # has no extra columns.
140 :     $self->DefaultColumns($rhelp);
141 : parrello 1.1 # Initialize the session file.
142 : parrello 1.6 $self->OpenSession($rhelp);
143 : parrello 1.1 # Initialize the result counter.
144 :     $retVal = 0;
145 :     # Loop through the selected features.
146 :     while (my $record = $query->Fetch()) {
147 :     $fd->Store($record);
148 :     $self->PutFeature($fd);
149 :     $retVal++;
150 : parrello 1.5 if ($retVal % 100 == 0) {
151 :     $self->PrintLine("$retVal features processed.<br />");
152 :     }
153 : parrello 1.1 }
154 :     # Close the session file.
155 :     $self->CloseSession();
156 :     }
157 :     }
158 :     # Return the result count.
159 :     return $retVal;
160 :     }
161 :    
162 :     =head3 Description
163 :    
164 :     C<< my $htmlText = $shelp->Description(); >>
165 :    
166 :     Return a description of this search. The description is used for the table of contents
167 :     on the main search tools page. It may contain HTML, but it should be character-level,
168 :     not block-level, since the description is going to appear in a list.
169 :    
170 :     =cut
171 :    
172 :     sub Description {
173 :     # Get the parameters.
174 :     my ($self) = @_;
175 :     # Return the result.
176 :     return "Search for genes by keyword in a specified subsystem or subsystem class.";
177 :     }
178 :    
179 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3