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

Annotation of /Sprout/SHSubSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (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 : parrello 1.7 # We need to build a query to get our features. This involves building
105 :     # a filter clause and a parameter list.
106 : parrello 1.1 my ($filterClause, $parameter);
107 :     if ($spec =~ /^id=(.+)$/) {
108 :     # Here we're filtering for a single subsystem.
109 :     $filterClause = "Subsystem(id) = ?";
110 :     $parameter = $1;
111 :     } elsif ($spec =~ /^classification=(.+)$/) {
112 :     # Here we're filtering for a class.
113 :     $filterClause = "Subsystem(classification) LIKE ?";
114 :     $parameter = $1;
115 :     }
116 :     # Now we do some validation.
117 :     my $keywords = $cgi->param('keywords') || "";
118 :     if (! defined($filterClause)) {
119 :     $self->SetMessage("Invalid subsystem specification \"$spec\".");
120 :     } elsif ($self->ValidateKeywords($keywords)) {
121 :     # We're valid, so we start by collecting the main parameters for the query.
122 :     my @majorParms = (['Subsystem', 'HasRoleInSubsystem', 'Feature'],
123 :     $filterClause, [$parameter]);
124 :     # The way we execute the query is determined by whether or not
125 :     # any keywords were specified.
126 :     my $query;
127 :     if ($keywords) {
128 : parrello 1.5 $self->PrintLine("Word search query submitted.<br />");
129 : parrello 1.1 $query = $sprout->Search($keywords, 2, @majorParms);
130 :     } else {
131 : parrello 1.5 $self->PrintLine("Standard search query submitted.<br />");
132 : parrello 1.1 $query = $sprout->Get(@majorParms);
133 :     }
134 : parrello 1.6 # Get the result helper for a feature search.
135 :     my $rhelp = RHFeatures->new($self);
136 :     # Compute the default columns. This is a very simple search which
137 :     # has no extra columns.
138 :     $self->DefaultColumns($rhelp);
139 : parrello 1.1 # Initialize the session file.
140 : parrello 1.6 $self->OpenSession($rhelp);
141 : parrello 1.7 # Clear the result counter.
142 : parrello 1.1 $retVal = 0;
143 : parrello 1.7 # Process the query results.
144 : parrello 1.1 while (my $record = $query->Fetch()) {
145 : parrello 1.7 # Compute the sort key.
146 :     my $sort = $rhelp->SortKey($record);
147 :     # Store this feature.
148 :     $rhelp->PutData($sort, $record->PrimaryValue('Feature(id)'), $record);
149 :     # Increment the result counter.
150 : parrello 1.1 $retVal++;
151 :     }
152 :     # Close the session file.
153 :     $self->CloseSession();
154 :     }
155 :     }
156 :     # Return the result count.
157 :     return $retVal;
158 :     }
159 :    
160 :     =head3 Description
161 :    
162 :     C<< my $htmlText = $shelp->Description(); >>
163 :    
164 :     Return a description of this search. The description is used for the table of contents
165 :     on the main search tools page. It may contain HTML, but it should be character-level,
166 :     not block-level, since the description is going to appear in a list.
167 :    
168 :     =cut
169 :    
170 :     sub Description {
171 :     # Get the parameters.
172 :     my ($self) = @_;
173 :     # Return the result.
174 :     return "Search for genes by keyword in a specified subsystem or subsystem class.";
175 :     }
176 :    
177 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3