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

Annotation of /Sprout/SHSubSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3