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

Annotation of /Sprout/SearchHelper.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package SearchHelper;
4 :    
5 :     use strict;
6 :     use Tracer;
7 :     use PageBuilder;
8 :     use Digest::MD5;
9 :     use File::Basename;
10 :     use File::Path;
11 :     use File::stat;
12 :     use LWP::UserAgent;
13 : parrello 1.34 use FIGRules;
14 : parrello 1.1 use Sprout;
15 :     use SFXlate;
16 :     use FIGRules;
17 :     use HTML;
18 :     use BasicLocation;
19 : parrello 1.3 use URI::Escape;
20 :     use PageBuilder;
21 : parrello 1.34 use AliasAnalysis;
22 : parrello 1.43 use CGI::Cookie;
23 : parrello 1.34 use FreezeThaw qw(freeze thaw);
24 : parrello 1.1
25 :     =head1 Search Helper Base Class
26 :    
27 :     =head2 Introduction
28 :    
29 :     The search helper is a base class for all search objects. It has methods for performing
30 :     all the common tasks required to build and manage a search cache. The subclass must
31 :     provide methods for generating and processing search forms. The base class has the
32 :     following object fields.
33 :    
34 :     =over 4
35 :    
36 :     =item cols
37 :    
38 :     Reference to a list of column header descriptions. If undefined, then the session cache
39 :     file has been opened but nothing has been written to it.
40 :    
41 :     =item fileHandle
42 :    
43 :     File handle for the session cache file.
44 :    
45 :     =item query
46 :    
47 :     CGI query object, which includes the search parameters and the various
48 :     session status variables kept between requests from the user.
49 :    
50 :     =item type
51 :    
52 :     Session type: C<old> if there is an existing cache file from which we are
53 :     displaying search results, or C<new> if the cache file needs to be built.
54 :    
55 :     =item class
56 :    
57 :     Name of the search helper class as it would appear in the CGI query object
58 :     (i.e. without the C<SH> prefix.
59 :    
60 :     =item sprout
61 :    
62 :     Sprout object for accessing the database.
63 :    
64 :     =item message
65 :    
66 :     Message to display if an error has been detected.
67 :    
68 :     =item orgs
69 :    
70 : parrello 1.34 Reference to a hash mapping genome IDs to organism data. (Used to
71 :     improve performance.)
72 : parrello 1.1
73 :     =item name
74 :    
75 :     Name to use for this object's form.
76 :    
77 :     =item scriptQueue
78 :    
79 :     List of JavaScript statements to be executed after the form is closed.
80 :    
81 : parrello 1.3 =item genomeHash
82 :    
83 :     Cache of the genome group hash used to build genome selection controls.
84 :    
85 :     =item genomeParms
86 :    
87 :     List of the parameters that are used to select multiple genomes.
88 :    
89 : parrello 1.43 =item notices
90 :    
91 :     A list of messages to be put in the notice file.
92 :    
93 : parrello 1.1 =back
94 :    
95 : parrello 1.2 =head2 Adding a new Search Tool
96 :    
97 :     To add a new search tool to the system, you must
98 :    
99 :     =over 4
100 :    
101 :     =item 1
102 :    
103 :     Choose a class name for your search tool.
104 :    
105 :     =item 2
106 :    
107 :     Create a new subclass of this object and implement each of the virtual methods. The
108 : parrello 1.34 name of the subclass must be C<SH>I<className>, where I<className> is the
109 :     type of search.
110 : parrello 1.2
111 :     =item 3
112 :    
113 :     Create an include file among the web server pages that describes how to use
114 :     the search tool. The include file must be in the B<includes> directory, and
115 :     its name must be C<SearchHelp_>I<className>C<.inc>.
116 :    
117 :     =item 4
118 :    
119 : parrello 1.34 If your search produces a result for which a helper does not exist, you
120 :     must create a new subclass of B<ResultHelper>. Its name must be
121 :     C<RH>I<className>, where I<className> is the type of result.
122 : parrello 1.2
123 :     =back
124 :    
125 :     =head3 Building a Search Form
126 :    
127 :     All search forms are three-column tables. In general, you want one form
128 :     variable per table row. The first column should contain the label and
129 :     the second should contain the form control for specifying the variable
130 :     value. If the control is wide, you should use C<colspan="2"> to give it
131 :     extra room. B<Do not> specify a width in any of your table cells, as
132 :     width management is handled by this class.
133 :    
134 :     The general code for creating the form should be
135 :    
136 :     sub Form {
137 :     my ($self) = @_;
138 :     # Get the CGI object.
139 :     my $cgi = @self->Q();
140 :     # Start the form.
141 :     my $retVal = $self->FormStart("form title");
142 :     # Assemble the table rows.
143 :     my @rows = ();
144 :     ... push table row Html into @rows ...
145 :     push @rows, $self->SubmitRow();
146 :     ... push more Html into @rows ...
147 :     # Build the table from the rows.
148 :     $retVal .= $self->MakeTable(\@rows);
149 :     # Close the form.
150 :     $retVal .= $self->FormEnd();
151 :     # Return the form Html.
152 :     return $retVal;
153 :     }
154 :    
155 :     Several helper methods are provided for particular purposes.
156 :    
157 : parrello 1.3 L</NmpdrGenomeMenu> generates a control for selecting one or more genomes. Use
158 :     L</GetGenomes> to retrieve all the genomes passed in for a specified parameter
159 :     name. Note that as an assist to people working with GET-style links, if no
160 :     genomes are specified and the incoming request style is GET, all genomes will
161 :     be returned.
162 : parrello 1.2
163 :     L</QueueFormScript> allows you to queue JavaScript statements for execution
164 :     after the form is fully generated. If you are using very complicated
165 :     form controls, the L</QueueFormScript> method allows you to perform
166 :     JavaScript initialization. The L</NmpdrGenomeMenu> control uses this
167 :     facility to display a list of the pre-selected genomes.
168 :    
169 :     Finally, when generating the code for your controls, be sure to use any incoming
170 :     query parameters as default values so that the search request is persistent.
171 :    
172 :     =head3 Finding Search Results
173 :    
174 : parrello 1.34 The L</Find> method is used to create the search results. The basic code
175 :     structure would work as follows.
176 : parrello 1.2
177 :     sub Find {
178 :     my ($self) = @_;
179 :     # Get the CGI and Sprout objects.
180 :     my $cgi = $self->Q();
181 :     my $sprout = $self->DB();
182 :     # Declare the return variable. If it remains undefined, the caller will
183 :     # know that an error occurred.
184 :     my $retVal;
185 :     ... validate the parameters ...
186 :     if (... invalid parameters...) {
187 :     $self->SetMessage(...appropriate message...);
188 : parrello 1.34 } else {
189 :     # Determine the result type.
190 :     my $rhelp = SearchHelper::GetHelper($self, RH => $resultType);
191 : parrello 1.38 # Specify the columns.
192 : parrello 1.34 $self->DefaultColumns($rhelp);
193 :     # You may want to add extra columns. $name is the column name and
194 :     # $loc is its location. The other parameters take their names from the
195 :     # corresponding column methods.
196 :     $rhelp->AddExtraColumn($name => $loc, style => $style, download => $flag,
197 :     title => $title);
198 :     # Some searches require optional columns that are configured by the
199 :     # user or by the search query itself. There are some special methods
200 :     # for this in the result helpers, but there's also the direct approach
201 :     # shown below.
202 :     $rhelp->AddOptionalColumn($name => $loc);
203 : parrello 1.2 # Initialize the session file.
204 : parrello 1.34 $self->OpenSession($rhelp);
205 : parrello 1.2 # Initialize the result counter.
206 :     $retVal = 0;
207 : parrello 1.34 ... set up to loop through the results ...
208 :     while (...more results...) {
209 :     ...compute extra columns and call PutExtraColumns...
210 :     $rhelp->PutData($sortKey, $objectID, $record);
211 :     $retVal++;
212 : parrello 1.2 }
213 : parrello 1.9 # Close the session file.
214 :     $self->CloseSession();
215 : parrello 1.2 }
216 :     # Return the result count.
217 :     return $retVal;
218 :     }
219 :    
220 :     A Find method is of course much more complicated than generating a form, and there
221 : parrello 1.34 are variations on the above theme.
222 : parrello 1.2
223 : parrello 1.28 In addition to the finding and filtering, it is necessary to send status messages
224 :     to the output so that the user does not get bored waiting for results. The L</PrintLine>
225 :     method performs this function. The single parameter should be text to be
226 :     output to the browser. In general, you'll invoke it as follows.
227 :    
228 :     $self->PrintLine("...my message text...<br />");
229 :    
230 :     The break tag is optional. When the Find method gets control, a paragraph will
231 :     have been started so that everything is XHTML-compliant.
232 :    
233 : parrello 1.2 The L</Find> method must return C<undef> if the search parameters are invalid. If this
234 :     is the case, then a message describing the problem should be passed to the framework
235 :     by calling L</SetMessage>. If the parameters are valid, then the method must return
236 :     the number of items found.
237 :    
238 : parrello 1.1 =cut
239 :    
240 :     # This counter is used to insure every form on the page has a unique name.
241 :     my $formCount = 0;
242 : parrello 1.16 # This counter is used to generate unique DIV IDs.
243 :     my $divCount = 0;
244 : parrello 1.1
245 :     =head2 Public Methods
246 :    
247 :     =head3 new
248 :    
249 : parrello 1.38 my $shelp = SearchHelper->new($cgi);
250 : parrello 1.1
251 :     Construct a new SearchHelper object.
252 :    
253 :     =over 4
254 :    
255 : parrello 1.19 =item cgi
256 : parrello 1.1
257 :     The CGI query object for the current script.
258 :    
259 :     =back
260 :    
261 :     =cut
262 :    
263 :     sub new {
264 :     # Get the parameters.
265 : parrello 1.19 my ($class, $cgi) = @_;
266 : parrello 1.43 # Check for a session ID. First we look in the CGI parameters.
267 : parrello 1.19 my $session_id = $cgi->param("SessionID");
268 : parrello 1.1 my $type = "old";
269 :     if (! $session_id) {
270 : parrello 1.43 # We need a session ID. Try to get it from the cookies.
271 :     my %cookies = fetch CGI::Cookie;
272 :     my $session_cookie = $cookies{$class};
273 :     if (! $session_cookie) {
274 :     Trace("No session ID found.") if T(3);
275 :     # Here we're starting a new session. We create the session ID and
276 :     # store it in a cookie.
277 :     $session_id = FIGRules::NewSessionID();
278 :     Trace("New session ID is $session_id.") if T(3);
279 :     $session_cookie = new CGI::Cookie(-name => $class,
280 :     -value => $session_id,
281 :     -expires => '+7d');
282 :     $session_cookie->bake();
283 :     } else {
284 :     # Here we're recovering an old session. The session ID is
285 :     # used to find any old search options lying around, but we're
286 :     # still considered a new session.
287 :     $session_id = $session_cookie->value();
288 :     Trace("Session $session_id recovered from cookie.") if T(3);
289 :     }
290 :     # Denote this is a new session.
291 : parrello 1.1 $type = "new";
292 : parrello 1.43 # Put the session IS in the parameters.
293 : parrello 1.19 $cgi->param(-name => 'SessionID', -value => $session_id);
294 : parrello 1.26 } else {
295 :     Trace("Session ID is $session_id.") if T(3);
296 : parrello 1.1 }
297 : parrello 1.34 Trace("Computing subclass.") if T(3);
298 : parrello 1.1 # Compute the subclass name.
299 : parrello 1.19 my $subClass;
300 :     if ($class =~ /SH(.+)$/) {
301 :     # Here we have a real search class.
302 :     $subClass = $1;
303 :     } else {
304 :     # Here we have a bare class. The bare class cannot search, but it can
305 :     # process search results.
306 :     $subClass = 'SearchHelper';
307 :     }
308 : parrello 1.34 Trace("Subclass name is $subClass.") if T(3);
309 : parrello 1.1 # Insure everybody knows we're in Sprout mode.
310 : parrello 1.19 $cgi->param(-name => 'SPROUT', -value => 1);
311 : parrello 1.1 # Generate the form name.
312 :     my $formName = "$class$formCount";
313 :     $formCount++;
314 : parrello 1.34 Trace("Creating helper.") if T(3);
315 : parrello 1.1 # Create the shelp object. It contains the query object (with the session ID)
316 :     # as well as an indicator as to whether or not the session is new, plus the
317 : parrello 1.2 # class name and a placeholder for the Sprout object.
318 : parrello 1.1 my $retVal = {
319 : parrello 1.19 query => $cgi,
320 : parrello 1.1 type => $type,
321 :     class => $subClass,
322 : parrello 1.2 sprout => undef,
323 : parrello 1.1 orgs => {},
324 :     name => $formName,
325 :     scriptQueue => [],
326 : parrello 1.3 genomeList => undef,
327 :     genomeParms => [],
328 : parrello 1.43 notices => [],
329 : parrello 1.1 };
330 :     # Bless and return it.
331 :     bless $retVal, $class;
332 :     return $retVal;
333 :     }
334 :    
335 :     =head3 Q
336 :    
337 : parrello 1.38 my $query = $shelp->Q();
338 : parrello 1.1
339 :     Return the CGI query object.
340 :    
341 :     =cut
342 :    
343 :     sub Q {
344 :     # Get the parameters.
345 :     my ($self) = @_;
346 :     # Return the result.
347 :     return $self->{query};
348 :     }
349 :    
350 : parrello 1.9
351 : parrello 1.1 =head3 DB
352 :    
353 : parrello 1.38 my $sprout = $shelp->DB();
354 : parrello 1.1
355 :     Return the Sprout database object.
356 :    
357 :     =cut
358 :    
359 :     sub DB {
360 :     # Get the parameters.
361 :     my ($self) = @_;
362 : parrello 1.2 # Insure we have a database.
363 :     my $retVal = $self->{sprout};
364 :     if (! defined $retVal) {
365 :     $retVal = SFXlate->new_sprout_only();
366 :     $self->{sprout} = $retVal;
367 :     }
368 : parrello 1.1 # Return the result.
369 : parrello 1.2 return $retVal;
370 : parrello 1.1 }
371 :    
372 :     =head3 IsNew
373 :    
374 : parrello 1.38 my $flag = $shelp->IsNew();
375 : parrello 1.1
376 :     Return TRUE if this is a new session, FALSE if this is an old session. An old
377 :     session already has search results ready to process.
378 :    
379 :     =cut
380 :    
381 :     sub IsNew {
382 :     # Get the parameters.
383 :     my ($self) = @_;
384 :     # Return the result.
385 :     return ($self->{type} eq 'new');
386 :     }
387 :    
388 :     =head3 ID
389 :    
390 : parrello 1.38 my $sessionID = $shelp->ID();
391 : parrello 1.1
392 :     Return the current session ID.
393 :    
394 :     =cut
395 :    
396 :     sub ID {
397 :     # Get the parameters.
398 :     my ($self) = @_;
399 :     # Return the result.
400 :     return $self->Q()->param("SessionID");
401 :     }
402 :    
403 :     =head3 FormName
404 :    
405 : parrello 1.38 my $name = $shelp->FormName();
406 : parrello 1.1
407 :     Return the name of the form this helper object will generate.
408 :    
409 :     =cut
410 :    
411 :     sub FormName {
412 :     # Get the parameters.
413 :     my ($self) = @_;
414 :     # Return the result.
415 :     return $self->{name};
416 :     }
417 :    
418 :     =head3 QueueFormScript
419 :    
420 : parrello 1.38 $shelp->QueueFormScript($statement);
421 : parrello 1.1
422 :     Add the specified statement to the queue of JavaScript statements that are to be
423 :     executed when the form has been fully defined. This is necessary because until
424 :     the closing </FORM> tag is emitted, the form elements cannot be referenced by
425 :     name. When generating the statement, you can refer to the variable C<thisForm>
426 :     in order to reference the form in progress. Thus,
427 :    
428 :     thisForm.simLimit.value = 1e-10;
429 :    
430 :     would set the value of the form element C<simLimit> in the current form to
431 :     C<1e-10>.
432 :    
433 :     =over 4
434 :    
435 :     =item statement
436 :    
437 :     JavaScript statement to be queued for execution after the form is built.
438 :     The trailing semi-colon is required. Theoretically, you could include
439 :     multiple statements separated by semi-colons, but one at a time works
440 :     just as well.
441 :    
442 :     =back
443 :    
444 :     =cut
445 :    
446 :     sub QueueFormScript {
447 :     # Get the parameters.
448 :     my ($self, $statement) = @_;
449 :     # Push the statement onto the script queue.
450 :     push @{$self->{scriptQueue}}, $statement;
451 :     }
452 :    
453 :     =head3 FormStart
454 :    
455 : parrello 1.38 my $html = $shelp->FormStart($title);
456 : parrello 1.1
457 :     Return the initial section of a form designed to perform another search of the
458 :     same type. The form header is included along with hidden fields to persist the
459 :     tracing, sprout status, and search class.
460 :    
461 :     A call to L</FormEnd> is required to close the form.
462 :    
463 :     =over 4
464 :    
465 :     =item title
466 :    
467 :     Title to be used for the form.
468 :    
469 :     =item RETURN
470 :    
471 :     Returns the initial HTML for the search form.
472 :    
473 :     =back
474 :    
475 :     =cut
476 :    
477 :     sub FormStart {
478 :     # Get the parameters.
479 :     my ($self, $title) = @_;
480 :     # Get the CGI object.
481 :     my $cgi = $self->Q();
482 : parrello 1.18 # Start the form. Note we use the override option on the Class value, in
483 :     # case the Advanced button was used.
484 : parrello 1.1 my $retVal = "<div class=\"search\">\n" .
485 : parrello 1.43 CGI::start_form(-method => 'POST',
486 :     -action => "$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/search",
487 : parrello 1.1 -name => $self->FormName()) .
488 : parrello 1.43 CGI::hidden(-name => 'Class',
489 :     -value => $self->{class}) .
490 :     CGI::hidden(-name => 'SPROUT',
491 : parrello 1.1 -value => 1) .
492 : parrello 1.43 CGI::h3("$title" . Hint($self->{class}, "Click here for more information."));
493 : parrello 1.1 # Put in an anchor tag in case there's a table of contents.
494 :     my $anchorName = $self->FormName();
495 :     $retVal .= "<a name=\"$anchorName\"></a>\n";
496 :     # Return the result.
497 :     return $retVal;
498 :     }
499 :    
500 :     =head3 FormEnd
501 :    
502 : parrello 1.38 my $htmlText = $shelp->FormEnd();
503 : parrello 1.1
504 :     Return the HTML text for closing a search form. This closes both the C<form> and
505 :     C<div> tags.
506 :    
507 :     =cut
508 :    
509 :     sub FormEnd {
510 :     # Get the parameters.
511 :     my ($self) = @_;
512 :     # Declare the return variable, closing the form and the DIV block.
513 :     my $retVal = "</form></div>\n";
514 :     # Now we flush out the statement queue.
515 :     my @statements = @{$self->{scriptQueue}};
516 :     if (@statements > 0) {
517 :     # Switch to JavaScript and set the "thisForm" variable.
518 :     $retVal .= "<SCRIPT language=\"JavaScript\">\n" .
519 :     " thisForm = document.$self->{name};\n";
520 :     # Unroll the statements.
521 :     while (@statements > 0) {
522 :     my $statement = shift @statements;
523 :     $retVal .= " $statement\n";
524 :     }
525 :     # Close the JavaScript.
526 :     $retVal .= "</SCRIPT>\n";
527 :     }
528 :     # Return the result.
529 :     return $retVal;
530 :     }
531 :    
532 :     =head3 SetMessage
533 :    
534 : parrello 1.38 $shelp->SetMessage($msg);
535 : parrello 1.1
536 :     Store the specified text as the result message. The result message is displayed
537 :     if an invalid parameter value is specified.
538 :    
539 :     =over 4
540 :    
541 :     =item msg
542 :    
543 :     Text of the result message to be displayed.
544 :    
545 :     =back
546 :    
547 :     =cut
548 :    
549 :     sub SetMessage {
550 :     # Get the parameters.
551 :     my ($self, $msg) = @_;
552 :     # Store the message.
553 :     $self->{message} = $msg;
554 :     }
555 :    
556 :     =head3 Message
557 :    
558 : parrello 1.38 my $text = $shelp->Message();
559 : parrello 1.1
560 :     Return the result message. The result message is displayed if an invalid parameter
561 :     value is specified.
562 :    
563 :     =cut
564 :    
565 :     sub Message {
566 :     # Get the parameters.
567 :     my ($self) = @_;
568 :     # Return the result.
569 :     return $self->{message};
570 :     }
571 :    
572 :     =head3 OpenSession
573 :    
574 : parrello 1.38 $shelp->OpenSession($rhelp);
575 : parrello 1.34
576 :     Set up the session cache file and write out the column headers.
577 :     This method should not be called until all the columns have
578 :     been configured, including the extra columns.
579 :    
580 :     =over 4
581 :    
582 :     =item rhelp
583 :    
584 :     Result helper for formatting the output. This has the column
585 :     headers stored in it.
586 : parrello 1.1
587 : parrello 1.34 =back
588 : parrello 1.1
589 :     =cut
590 :    
591 :     sub OpenSession {
592 :     # Get the parameters.
593 : parrello 1.34 my ($self, $rhelp) = @_;
594 :     # Insure the result helper is valid.
595 :     if (! defined($rhelp)) {
596 :     Confess("No result type specified for $self->{class}.");
597 :     } elsif(! $rhelp->isa('ResultHelper')) {
598 :     Confess("Invalid result type specified for $self->{class}.");
599 :     } else {
600 :     # Get the column headers and write them out.
601 :     my $colHdrs = $rhelp->GetColumnHeaders();
602 :     Trace(scalar(@{$colHdrs}) . " column headers written to output.") if T(3);
603 :     $self->WriteColumnHeaders(@{$colHdrs});
604 :     }
605 : parrello 1.1 }
606 :    
607 :     =head3 GetCacheFileName
608 :    
609 : parrello 1.38 my $fileName = $shelp->GetCacheFileName();
610 : parrello 1.1
611 :     Return the name to be used for this session's cache file.
612 :    
613 :     =cut
614 :    
615 :     sub GetCacheFileName {
616 :     # Get the parameters.
617 :     my ($self) = @_;
618 :     # Return the result.
619 :     return $self->GetTempFileName('cache');
620 :     }
621 :    
622 :     =head3 GetTempFileName
623 :    
624 : parrello 1.38 my $fileName = $shelp->GetTempFileName($type);
625 : parrello 1.1
626 :     Return the name to be used for a temporary file of the specified type. The
627 :     name is computed from the session name with the type as a suffix.
628 :    
629 :     =over 4
630 :    
631 :     =item type
632 :    
633 :     Type of temporary file to be generated.
634 :    
635 :     =item RETURN
636 :    
637 :     Returns a file name generated from the session name and the specified type.
638 :    
639 :     =back
640 :    
641 :     =cut
642 :    
643 :     sub GetTempFileName {
644 :     # Get the parameters.
645 :     my ($self, $type) = @_;
646 :     # Compute the file name. Note it gets stuffed in the FIG temporary
647 :     # directory.
648 : parrello 1.34 my $retVal = FIGRules::GetTempFileName(sessionID => $self->ID(), extension => $type);
649 : parrello 1.1 # Return the result.
650 :     return $retVal;
651 :     }
652 :    
653 :     =head3 WriteColumnHeaders
654 :    
655 : parrello 1.38 $shelp->WriteColumnHeaders(@colNames);
656 : parrello 1.1
657 :     Write out the column headers for the current search session. The column headers
658 :     are sent to the cache file, and then the cache is re-opened as a sort pipe and
659 :     the handle saved.
660 :    
661 :     =over 4
662 :    
663 :     =item colNames
664 :    
665 : parrello 1.34 A list of column names in the desired presentation order. For extra columns,
666 :     the column name is the hash supplied as the column definition.
667 : parrello 1.1
668 :     =back
669 :    
670 :     =cut
671 :    
672 :     sub WriteColumnHeaders {
673 :     # Get the parameters.
674 :     my ($self, @colNames) = @_;
675 :     # Get the cache file name and open it for output.
676 :     my $fileName = $self->GetCacheFileName();
677 :     my $handle1 = Open(undef, ">$fileName");
678 : parrello 1.34 # Freeze the column headers.
679 :     my @colHdrs = map { freeze($_) } @colNames;
680 : parrello 1.1 # Write the column headers and close the file.
681 : parrello 1.34 Tracer::PutLine($handle1, \@colHdrs);
682 : parrello 1.1 close $handle1;
683 :     # Now open the sort pipe and save the file handle. Note how we append the
684 :     # sorted data to the column header row already in place. The output will
685 :     # contain a sort key followed by the real columns. The sort key is
686 :     # hacked off before going to the output file.
687 :     $self->{fileHandle} = Open(undef, "| sort | cut --fields=2- >>$fileName");
688 :     }
689 :    
690 : parrello 1.43 =head3 SetNotice
691 :    
692 :     $shelp->SetNotice($message);
693 :    
694 :     This method creates a notice that will be displayed on the search results
695 :     page. After the search is complete, notices are placed in a small temporary
696 :     file that is checked by the results display engine.
697 :    
698 :     =over 4
699 :    
700 :     =item message
701 :    
702 :     Message to write to the notice file.
703 :    
704 :     =back
705 :    
706 :     =cut
707 :    
708 :     sub SetNotice {
709 :     # Get the parameters.
710 :     my ($self, $message) = @_;
711 :     # Save the message.
712 :     push @{$self->{notices}}, $message;
713 :     }
714 :    
715 :    
716 : parrello 1.34 =head3 ReadColumnHeaders
717 :    
718 : parrello 1.38 my @colHdrs = $shelp->ReadColumnHeaders($fh);
719 : parrello 1.34
720 :     Read the column headers from the specified file handle. The column headers are
721 :     frozen strings intermixed with frozen hash references. The strings represent
722 :     column names defined in the result helper. The hash references represent the
723 :     definitions of the extra columns.
724 :    
725 :     =over 4
726 :    
727 :     =item fh
728 :    
729 :     File handle from which the column headers are to be read.
730 :    
731 :     =item RETURN
732 :    
733 :     Returns a list of the column headers pulled from the specified file's first line.
734 :    
735 :     =back
736 :    
737 :     =cut
738 :    
739 :     sub ReadColumnHeaders {
740 :     # Get the parameters.
741 :     my ($self, $fh) = @_;
742 :     # Read and thaw the columns.
743 :     my @retVal = map { thaw($_) } Tracer::GetLine($fh);
744 :     # Return them to the caller.
745 :     return @retVal;
746 :     }
747 :    
748 : parrello 1.1 =head3 WriteColumnData
749 :    
750 : parrello 1.38 $shelp->WriteColumnData($key, @colValues);
751 : parrello 1.1
752 :     Write a row of column values to the current search session. It is assumed that
753 :     the session file is already open for output.
754 :    
755 :     =over 4
756 :    
757 :     =item key
758 :    
759 :     Sort key.
760 :    
761 :     =item colValues
762 :    
763 :     List of column values to write to the search result cache file for this session.
764 :    
765 :     =back
766 :    
767 :     =cut
768 :    
769 :     sub WriteColumnData {
770 :     # Get the parameters.
771 :     my ($self, $key, @colValues) = @_;
772 :     # Write them to the cache file.
773 :     Tracer::PutLine($self->{fileHandle}, [$key, @colValues]);
774 : parrello 1.32 Trace("Column data is " . join("; ", $key, @colValues) . ".") if T(4);
775 : parrello 1.1 }
776 :    
777 :     =head3 CloseSession
778 :    
779 : parrello 1.38 $shelp->CloseSession();
780 : parrello 1.1
781 :     Close the session file.
782 :    
783 :     =cut
784 :    
785 :     sub CloseSession {
786 :     # Get the parameters.
787 :     my ($self) = @_;
788 :     # Check for an open session file.
789 :     if (defined $self->{fileHandle}) {
790 :     # We found one, so close it.
791 : parrello 1.9 Trace("Closing session file.") if T(2);
792 : parrello 1.1 close $self->{fileHandle};
793 : parrello 1.28 # Tell the user.
794 :     my $cgi = $self->Q();
795 :     $self->PrintLine("Output formatting complete.<br />");
796 : parrello 1.1 }
797 : parrello 1.43 # Check for notices.
798 :     my @notices = @{$self->{notices}};
799 :     if (scalar @notices) {
800 :     # We have some, so put then in a notice file.
801 :     my $noticeFile = $self->GetTempFileName('notices');
802 :     my $nh = Open(undef, ">$noticeFile");
803 :     print $nh join("\n", @notices, "");
804 :     close $nh;
805 :     $self->PrintLine(scalar(@notices) . " notices saved.<br />");
806 :     }
807 : parrello 1.1 }
808 :    
809 :     =head3 OrganismData
810 :    
811 : parrello 1.38 my ($orgName, $group) = $shelp->Organism($genomeID);
812 : parrello 1.1
813 :     Return the name and status of the organism corresponding to the specified genome ID.
814 :     For performance reasons, this information is cached in a special hash table, so we
815 :     only compute it once per run.
816 :    
817 :     =over 4
818 :    
819 :     =item genomeID
820 :    
821 :     ID of the genome whose name is desired.
822 :    
823 :     =item RETURN
824 :    
825 : parrello 1.32 Returns a list of three items. The first item in the list is the organism name,
826 : parrello 1.1 and the second is the name of the NMPDR group, or an empty string if the
827 : parrello 1.32 organism is not in an NMPDR group. The third item is the organism's domain.
828 : parrello 1.1
829 :     =back
830 :    
831 :     =cut
832 :    
833 :     sub OrganismData {
834 :     # Get the parameters.
835 :     my ($self, $genomeID) = @_;
836 :     # Declare the return variables.
837 : parrello 1.32 my ($orgName, $group, $domain);
838 : parrello 1.1 # Check the cache.
839 :     my $cache = $self->{orgs};
840 :     if (exists $cache->{$genomeID}) {
841 : parrello 1.32 ($orgName, $group, $domain) = @{$cache->{$genomeID}};
842 : parrello 1.36 Trace("Cached organism $genomeID has group \"$group\".") if T(4);
843 : parrello 1.1 } else {
844 :     # Here we have to use the database.
845 :     my $sprout = $self->DB();
846 : parrello 1.36 my ($genus, $species, $strain, $newGroup, $taxonomy) = $sprout->GetEntityValues('Genome', $genomeID,
847 : parrello 1.32 ['Genome(genus)', 'Genome(species)',
848 :     'Genome(unique-characterization)',
849 :     'Genome(primary-group)',
850 :     'Genome(taxonomy)']);
851 : parrello 1.10 # Format and cache the name and display group.
852 : parrello 1.36 Trace("Caching organism $genomeID with group \"$newGroup\".") if T(4);
853 :     ($orgName, $group, $domain) = $self->SaveOrganismData($newGroup, $genomeID, $genus, $species,
854 : parrello 1.32 $strain, $taxonomy);
855 : parrello 1.36 Trace("Returning group $group.") if T(4);
856 : parrello 1.1 }
857 :     # Return the result.
858 : parrello 1.32 return ($orgName, $group, $domain);
859 : parrello 1.1 }
860 :    
861 :     =head3 Organism
862 :    
863 : parrello 1.38 my $orgName = $shelp->Organism($genomeID);
864 : parrello 1.1
865 :     Return the name of the relevant organism. The name is computed from the genus,
866 :     species, and unique characterization. A cache is used to improve performance.
867 :    
868 :     =over 4
869 :    
870 :     =item genomeID
871 :    
872 :     ID of the genome whose name is desired.
873 :    
874 :     =item RETURN
875 :    
876 :     Returns the display name of the specified organism.
877 :    
878 :     =back
879 :    
880 :     =cut
881 :    
882 :     sub Organism {
883 :     # Get the parameters.
884 :     my ($self, $genomeID) = @_;
885 :     # Get the organism data.
886 : parrello 1.32 my ($retVal) = $self->OrganismData($genomeID);
887 : parrello 1.1 # Return the result.
888 :     return $retVal;
889 :     }
890 :    
891 :     =head3 ComputeFASTA
892 :    
893 : parrello 1.42 my $fasta = $shelp->ComputeFASTA($desiredType, $sequence, $flankingWidth, $comments);
894 : parrello 1.1
895 : parrello 1.32 Parse a sequence input and convert it into a FASTA string of the desired type with
896 :     the desired flanking width.
897 : parrello 1.1
898 :     =over 4
899 :    
900 :     =item desiredType
901 :    
902 : parrello 1.34 C<dna> to return a DNA sequence, C<prot> to return a protein sequence, C<dnaPattern>
903 :     to return a DNA search pattern, C<protPattern> to return a protein search pattern.
904 : parrello 1.1
905 :     =item sequence
906 :    
907 :     Sequence to return. It may be a DNA or protein sequence in FASTA form or a feature ID.
908 :     If a feature ID is specified, the feature's DNA or translation will be returned. The
909 :     feature ID is recognized by the presence of a vertical bar in the input. Otherwise,
910 :     if the input does not begin with a greater-than sign (FASTA label line), a default label
911 :     line will be provided.
912 :    
913 : parrello 1.32 =item flankingWidth
914 :    
915 :     If the DNA FASTA of a feature is desired, the number of base pairs to either side of the
916 :     feature that should be included. Currently we can't do this for Proteins because the
917 :     protein translation of a feature doesn't always match the DNA and is taken directly
918 :     from the database.
919 :    
920 : parrello 1.42 =item comments
921 :    
922 :     Comment string to be added to the FASTA header.
923 :    
924 : parrello 1.1 =item RETURN
925 :    
926 :     Returns a string in FASTA format representing the content of the desired sequence with
927 :     an appropriate label. If the input is invalid, a message will be stored and we will
928 :     return C<undef>. Note that the output will include a trailing new-line.
929 :    
930 :     =back
931 :    
932 :     =cut
933 :    
934 :     sub ComputeFASTA {
935 :     # Get the parameters.
936 : parrello 1.42 my ($self, $desiredType, $sequence, $flankingWidth, $comment) = @_;
937 : parrello 1.1 # Declare the return variable. If an error occurs, it will remain undefined.
938 :     my $retVal;
939 : parrello 1.11 # This variable will be cleared if an error is detected.
940 :     my $okFlag = 1;
941 : parrello 1.1 # Create variables to hold the FASTA label and data.
942 :     my ($fastaLabel, $fastaData);
943 : parrello 1.18 Trace("FASTA desired type is $desiredType.") if T(4);
944 : parrello 1.29 # Check for a feature specification. The smoking gun for that is a vertical bar.
945 : parrello 1.1 if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {
946 :     # Here we have a feature ID in $1. We'll need the Sprout object to process
947 :     # it.
948 :     my $fid = $1;
949 : parrello 1.11 Trace("Feature ID for fasta is $fid.") if T(3);
950 : parrello 1.1 my $sprout = $self->DB();
951 :     # Get the FIG ID. Note that we only use the first feature found. We are not
952 :     # supposed to have redundant aliases, though we may have an ID that doesn't
953 :     # exist.
954 :     my ($figID) = $sprout->FeaturesByAlias($fid);
955 :     if (! $figID) {
956 : parrello 1.17 $self->SetMessage("No gene found with the ID \"$fid\".");
957 : parrello 1.11 $okFlag = 0;
958 : parrello 1.1 } else {
959 : parrello 1.29 # Set the FASTA label. The ID is the first favored alias.
960 :     my $favored = $self->Q()->param('FavoredAlias') || 'fig';
961 :     my $favorLen = length $favored;
962 :     ($fastaLabel) = grep { substr($_, 0, $favorLen) eq $favored } $sprout->FeatureAliases($fid);
963 :     if (! $fastaLabel) {
964 :     # In an emergency, fall back to the original ID.
965 :     $fastaLabel = $fid;
966 :     }
967 : parrello 1.42 # Add any specified comments.
968 :     if ($comment) {
969 :     $fastaLabel .= " $comment";
970 :     }
971 : parrello 1.1 # Now proceed according to the sequence type.
972 : parrello 1.33 if ($desiredType =~ /prot/) {
973 : parrello 1.1 # We want protein, so get the translation.
974 :     $fastaData = $sprout->FeatureTranslation($figID);
975 : parrello 1.11 Trace(length $fastaData . " characters returned for translation of $fastaLabel.") if T(3);
976 : parrello 1.34 } elsif ($desiredType =~ /dna/) {
977 : parrello 1.32 # We want DNA, so get the DNA sequence. This is a two-step process. First, we get the
978 :     # locations.
979 : parrello 1.1 my @locList = $sprout->FeatureLocation($figID);
980 : parrello 1.32 if ($flankingWidth > 0) {
981 :     # Here we need to add flanking data. Convert the locations to a list
982 :     # of location objects.
983 :     my @locObjects = map { BasicLocation->new($_) } @locList;
984 :     # Initialize the return variable. We will put the DNA in here segment by segment.
985 :     $fastaData = "";
986 :     # Now we widen each location by the flanking width and stash the results. This
987 :     # requires getting the contig length for each contig so we don't fall off the end.
988 :     for my $locObject (@locObjects) {
989 :     Trace("Current location is " . $locObject->String . ".") if T(4);
990 :     # Remember the current start and length.
991 :     my ($start, $len) = ($locObject->Left, $locObject->Length);
992 :     # Get the contig length.
993 :     my $contigLen = $sprout->ContigLength($locObject->Contig);
994 :     # Widen the location and get its DNA.
995 :     $locObject->Widen($flankingWidth, $contigLen);
996 :     my $fastaSegment = $sprout->DNASeq([$locObject->String()]);
997 :     # Now we need to do some case changing. The main DNA is upper case and
998 :     # the flanking DNA is lower case.
999 :     my $leftFlank = $start - $locObject->Left;
1000 :     my $rightFlank = $leftFlank + $len;
1001 :     Trace("Wide location is " . $locObject->String . ". Flanks are $leftFlank and $rightFlank. Contig len is $contigLen.") if T(4);
1002 :     my $fancyFastaSegment = lc(substr($fastaSegment, 0, $leftFlank)) .
1003 :     uc(substr($fastaSegment, $leftFlank, $rightFlank - $leftFlank)) .
1004 :     lc(substr($fastaSegment, $rightFlank));
1005 :     $fastaData .= $fancyFastaSegment;
1006 :     }
1007 :     } else {
1008 :     # Here we have just the raw sequence.
1009 :     $fastaData = $sprout->DNASeq(\@locList);
1010 :     }
1011 :     Trace((length $fastaData) . " characters returned for DNA of $fastaLabel.") if T(3);
1012 : parrello 1.1 }
1013 :     }
1014 :     } else {
1015 : parrello 1.11 Trace("Analyzing FASTA sequence.") if T(4);
1016 : parrello 1.1 # Here we are expecting a FASTA. We need to see if there's a label.
1017 : parrello 1.11 if ($sequence =~ /^>[\n\s]*(\S[^\n]*)\n(.+)$/s) {
1018 :     Trace("Label \"$1\" found in match to sequence:\n$sequence") if T(4);
1019 : parrello 1.1 # Here we have a label, so we split it from the data.
1020 :     $fastaLabel = $1;
1021 :     $fastaData = $2;
1022 :     } else {
1023 : parrello 1.11 Trace("No label found in match to sequence:\n$sequence") if T(4);
1024 : parrello 1.1 # Here we have no label, so we create one and use the entire sequence
1025 :     # as data.
1026 : parrello 1.34 $fastaLabel = "$desiredType sequence specified by user";
1027 : parrello 1.1 $fastaData = $sequence;
1028 :     }
1029 : parrello 1.34 # If we are not doing a pattern search, we need to clean the junk out of the sequence.
1030 :     if ($desiredType !~ /pattern/i) {
1031 :     $fastaData =~ s/\n//g;
1032 :     $fastaData =~ s/\s+//g;
1033 :     }
1034 : parrello 1.18 # Finally, verify that it's DNA if we're doing DNA stuff.
1035 : parrello 1.34 if ($desiredType eq 'dna' && $fastaData =~ /[^agctxn-]/i) {
1036 : parrello 1.24 $self->SetMessage("Invalid characters detected. Is the input really a DNA sequence?");
1037 : parrello 1.11 $okFlag = 0;
1038 : parrello 1.1 }
1039 :     }
1040 : parrello 1.11 Trace("FASTA data sequence: $fastaData") if T(4);
1041 :     # Only proceed if no error was detected.
1042 :     if ($okFlag) {
1043 : parrello 1.33 if ($desiredType =~ /pattern/i) {
1044 : parrello 1.34 # For a scan, there is no label and no breakup.
1045 : parrello 1.33 $retVal = $fastaData;
1046 :     } else {
1047 :     # We need to format the sequence into 60-byte chunks. We use the infamous
1048 :     # grep-split trick. The split, because of the presence of the parentheses,
1049 :     # includes the matched delimiters in the output list. The grep strips out
1050 :     # the empty list items that appear between the so-called delimiters, since
1051 :     # the delimiters are what we want.
1052 :     my @chunks = grep { $_ } split /(.{1,60})/, $fastaData;
1053 :     $retVal = join("\n", ">$fastaLabel", @chunks, "");
1054 :     }
1055 : parrello 1.1 }
1056 :     # Return the result.
1057 :     return $retVal;
1058 :     }
1059 :    
1060 : parrello 1.16 =head3 SubsystemTree
1061 :    
1062 : parrello 1.38 my $tree = SearchHelper::SubsystemTree($sprout, %options);
1063 : parrello 1.16
1064 :     This method creates a subsystem selection tree suitable for passing to
1065 :     L</SelectionTree>. Each leaf node in the tree will have a link to the
1066 :     subsystem display page. In addition, each node can have a radio button. The
1067 :     radio button alue is either C<classification=>I<string>, where I<string> is
1068 :     a classification string, or C<id=>I<string>, where I<string> is a subsystem ID.
1069 :     Thus, it can either be used to filter by a group of related subsystems or a
1070 :     single subsystem.
1071 :    
1072 :     =over 4
1073 :    
1074 :     =item sprout
1075 :    
1076 :     Sprout database object used to get the list of subsystems.
1077 :    
1078 :     =item options
1079 :    
1080 :     Hash containing options for building the tree.
1081 :    
1082 :     =item RETURN
1083 :    
1084 :     Returns a reference to a tree list suitable for passing to L</SelectionTree>.
1085 :    
1086 :     =back
1087 :    
1088 :     The supported options are as follows.
1089 :    
1090 :     =over 4
1091 :    
1092 :     =item radio
1093 :    
1094 :     TRUE if the tree should be configured for radio buttons. The default is FALSE.
1095 :    
1096 :     =item links
1097 :    
1098 :     TRUE if the tree should be configured for links. The default is TRUE.
1099 :    
1100 :     =back
1101 :    
1102 :     =cut
1103 :    
1104 :     sub SubsystemTree {
1105 :     # Get the parameters.
1106 :     my ($sprout, %options) = @_;
1107 :     # Process the options.
1108 :     my $optionThing = Tracer::GetOptions({ radio => 0, links => 1 }, \%options);
1109 :     # Read in the subsystems.
1110 :     my @subs = $sprout->GetAll(['Subsystem'], "ORDER BY Subsystem(classification), Subsystem(id)", [],
1111 :     ['Subsystem(classification)', 'Subsystem(id)']);
1112 : parrello 1.26 # Put any unclassified subsystems at the end. They will always be at the beginning, so if one
1113 :     # is at the end, ALL subsystems are unclassified and we don't bother.
1114 :     if ($#subs >= 0 && $subs[$#subs]->[0] ne '') {
1115 :     while ($subs[0]->[0] eq '') {
1116 :     my $classLess = shift @subs;
1117 :     push @subs, $classLess;
1118 :     }
1119 :     }
1120 : parrello 1.41 # Get the seedviewer URL.
1121 :     my $svURL = $FIG_Config::linkinSV || "$FIG_Config::cgi_url/seedviewer.cgi";
1122 :     Trace("Seed Viewer URL is $svURL.") if T(3);
1123 : parrello 1.16 # Declare the return variable.
1124 :     my @retVal = ();
1125 :     # Each element in @subs represents a leaf node, so as we loop through it we will be
1126 :     # producing one leaf node at a time. The leaf node is represented as a 2-tuple. The
1127 :     # first element is a semi-colon-delimited list of the classifications for the
1128 :     # subsystem. There will be a stack of currently-active classifications, which we will
1129 :     # compare to the incoming classifications from the end backward. A new classification
1130 :     # requires starting a new branch. A different classification requires closing an old
1131 :     # branch and starting a new one. Each classification in the stack will also contain
1132 :     # that classification's current branch. We'll add a fake classification at the
1133 :     # beginning that we can use to represent the tree as a whole.
1134 :     my $rootName = '<root>';
1135 :     # Create the classification stack. Note the stack is a pair of parallel lists,
1136 :     # one containing names and the other containing content.
1137 :     my @stackNames = ($rootName);
1138 :     my @stackContents = (\@retVal);
1139 :     # Add a null entry at the end of the subsystem list to force an unrolling.
1140 : parrello 1.27 push @subs, ['', undef];
1141 : parrello 1.16 # Loop through the subsystems.
1142 :     for my $sub (@subs) {
1143 :     # Pull out the classification list and the subsystem ID.
1144 :     my ($classString, $id) = @{$sub};
1145 :     Trace("Processing class \"$classString\" and subsystem $id.") if T(4);
1146 :     # Convert the classification string to a list with the root classification in
1147 :     # the front.
1148 :     my @classList = ($rootName, split($FIG_Config::splitter, $classString));
1149 :     # Find the leftmost point at which the class list differs from the stack.
1150 :     my $matchPoint = 0;
1151 :     while ($matchPoint <= $#stackNames && $matchPoint <= $#classList &&
1152 :     $stackNames[$matchPoint] eq $classList[$matchPoint]) {
1153 :     $matchPoint++;
1154 :     }
1155 :     Trace("Match point is $matchPoint. Stack length is " . scalar(@stackNames) .
1156 :     ". Class List length is " . scalar(@classList) . ".") if T(4);
1157 :     # Unroll the stack to the matchpoint.
1158 :     while ($#stackNames >= $matchPoint) {
1159 :     my $popped = pop @stackNames;
1160 :     pop @stackContents;
1161 :     Trace("\"$popped\" popped from stack.") if T(4);
1162 :     }
1163 :     # Start branches for any new classifications.
1164 :     while ($#stackNames < $#classList) {
1165 :     # The branch for a new classification contains its radio button
1166 :     # data and then a list of children. So, at this point, if radio buttons
1167 :     # are desired, we put them into the content.
1168 :     my $newLevel = scalar(@stackNames);
1169 :     my @newClassContent = ();
1170 :     if ($optionThing->{radio}) {
1171 :     my $newClassString = join($FIG_Config::splitter, @classList[1..$newLevel]);
1172 :     push @newClassContent, { value => "classification=$newClassString%" };
1173 :     }
1174 :     # The new classification node is appended to its parent's content
1175 :     # and then pushed onto the stack. First, we need the node name.
1176 :     my $nodeName = $classList[$newLevel];
1177 :     # Add the classification to its parent. This makes it part of the
1178 :     # tree we'll be returning to the user.
1179 :     push @{$stackContents[$#stackNames]}, $nodeName, \@newClassContent;
1180 :     # Push the classification onto the stack.
1181 :     push @stackContents, \@newClassContent;
1182 :     push @stackNames, $nodeName;
1183 :     Trace("\"$nodeName\" pushed onto stack.") if T(4);
1184 :     }
1185 :     # Now the stack contains all our parent branches. We add the subsystem to
1186 :     # the branch at the top of the stack, but only if it's NOT the dummy node.
1187 :     if (defined $id) {
1188 :     # Compute the node name from the ID.
1189 :     my $nodeName = $id;
1190 :     $nodeName =~ s/_/ /g;
1191 :     # Create the node's leaf hash. This depends on the value of the radio
1192 :     # and link options.
1193 :     my $nodeContent = {};
1194 :     if ($optionThing->{links}) {
1195 :     # Compute the link value.
1196 :     my $linkable = uri_escape($id);
1197 : parrello 1.41 $nodeContent->{link} = "$svURL?page=Subsystems;subsystem=$linkable";
1198 : parrello 1.16 }
1199 :     if ($optionThing->{radio}) {
1200 :     # Compute the radio value.
1201 :     $nodeContent->{value} = "id=$id";
1202 :     }
1203 :     # Push the node into its parent branch.
1204 :     Trace("\"$nodeName\" added to node list.") if T(4);
1205 :     push @{$stackContents[$#stackNames]}, $nodeName, $nodeContent;
1206 :     }
1207 :     }
1208 :     # Return the result.
1209 :     return \@retVal;
1210 :     }
1211 :    
1212 :    
1213 : parrello 1.1 =head3 NmpdrGenomeMenu
1214 :    
1215 : parrello 1.38 my $htmlText = $shelp->NmpdrGenomeMenu($menuName, $multiple, \@selected, $rows);
1216 : parrello 1.1
1217 :     This method creates a hierarchical HTML menu for NMPDR genomes organized by category. The
1218 :     category indicates the low-level NMPDR group. Organizing the genomes in this way makes it
1219 :     easier to select all genomes from a particular category.
1220 :    
1221 :     =over 4
1222 :    
1223 :     =item menuName
1224 :    
1225 :     Name to give to the menu.
1226 :    
1227 : parrello 1.3 =item multiple
1228 : parrello 1.1
1229 : parrello 1.3 TRUE if the user is allowed to select multiple genomes, else FALSE.
1230 : parrello 1.1
1231 :     =item selected
1232 :    
1233 :     Reference to a list containing the IDs of the genomes to be pre-selected. If the menu
1234 :     is not intended to allow multiple selections, the list should be a singleton. If the
1235 :     list is empty, nothing will be pre-selected.
1236 :    
1237 : parrello 1.3 =item rows (optional)
1238 :    
1239 :     Number of rows to display. If omitted, the default is 1 for a single-select list
1240 :     and 10 for a multi-select list.
1241 :    
1242 : parrello 1.8 =item crossMenu (optional)
1243 :    
1244 : parrello 1.41 This is currently not supported.
1245 : parrello 1.8
1246 : parrello 1.1 =item RETURN
1247 :    
1248 :     Returns the HTML text to generate a C<SELECT> menu inside a form.
1249 :    
1250 :     =back
1251 :    
1252 :     =cut
1253 :    
1254 :     sub NmpdrGenomeMenu {
1255 :     # Get the parameters.
1256 : parrello 1.8 my ($self, $menuName, $multiple, $selected, $rows, $cross) = @_;
1257 : parrello 1.1 # Get the Sprout and CGI objects.
1258 :     my $sprout = $self->DB();
1259 :     my $cgi = $self->Q();
1260 : parrello 1.3 # Compute the row count.
1261 :     if (! defined $rows) {
1262 :     $rows = ($multiple ? 10 : 1);
1263 :     }
1264 : parrello 1.41 # Get a comma-delimited list of the preselected genomes.
1265 :     my $preselected = "";
1266 :     if ($selected) {
1267 :     $preselected = join(", ", @$selected);
1268 :     }
1269 :     # Ask Sprout for a genome menu.
1270 :     my $retVal = $sprout->GenomeMenu(name => $menuName,
1271 :     multiSelect => $multiple,
1272 :     selected => $preselected,
1273 :     size => $rows);
1274 : parrello 1.1 # Return the result.
1275 :     return $retVal;
1276 :     }
1277 :    
1278 : parrello 1.3 =head3 PropertyMenu
1279 :    
1280 : parrello 1.38 my $htmlText = $shelp->PropertyMenu($menuName, $selected, $force);
1281 : parrello 1.3
1282 :     Generate a property name dropdown menu.
1283 :    
1284 :     =over 4
1285 :    
1286 :     =item menuName
1287 :    
1288 :     Name to give to the menu.
1289 :    
1290 :     =item selected
1291 :    
1292 :     Value of the property name to pre-select.
1293 :    
1294 :     =item force (optional)
1295 :    
1296 :     If TRUE, then the user will be forced to choose a property name. If FALSE,
1297 :     then an additional menu choice will be provided to select nothing.
1298 :    
1299 :     =item RETURN
1300 :    
1301 :     Returns a dropdown menu box that allows the user to select a property name. An additional
1302 :     selection entry will be provided for selecting no property name
1303 :    
1304 :     =back
1305 :    
1306 :     =cut
1307 :    
1308 :     sub PropertyMenu {
1309 :     # Get the parameters.
1310 :     my ($self, $menuName, $selected, $force) = @_;
1311 :     # Get the CGI and Sprout objects.
1312 :     my $sprout = $self->DB();
1313 :     my $cgi = $self->Q();
1314 :     # Create the property name list.
1315 :     my @propNames = ();
1316 :     if (! $force) {
1317 :     push @propNames, "";
1318 :     }
1319 :     # Get all the property names, putting them after the null choice if one exists.
1320 :     push @propNames, $sprout->GetChoices('Property', 'property-name');
1321 :     # Create a menu from them.
1322 : parrello 1.43 my $retVal = CGI::popup_menu(-name=> $menuName, -values => \@propNames,
1323 : parrello 1.3 -default => $selected);
1324 :     # Return the result.
1325 :     return $retVal;
1326 :     }
1327 :    
1328 : parrello 1.1 =head3 MakeTable
1329 :    
1330 : parrello 1.38 my $htmlText = $shelp->MakeTable(\@rows);
1331 : parrello 1.1
1332 :     Create a table from a group of table rows. The table rows must be fully pre-formatted: in
1333 :     other words, each must have the TR and TD tags included.
1334 :    
1335 :     The purpose of this method is to provide a uniform look for search form tables. It is
1336 :     almost impossible to control a table using styles, so rather than have a table style,
1337 :     we create the TABLE tag in this method. Note also that the first TD or TH in each row will
1338 :     be updated with an explicit width so the forms look pretty when they are all on one
1339 :     page.
1340 :    
1341 :     =over 4
1342 :    
1343 :     =item rows
1344 :    
1345 :     Reference to a list of table rows. Each table row must be in HTML form with all
1346 : parrello 1.29 the TR and TD tags set up. The first TD or TH tag in the first non-colspanned row
1347 :     will be modified to set the width. Everything else will be left as is.
1348 : parrello 1.1
1349 :     =item RETURN
1350 :    
1351 :     Returns the full HTML for a table in the approved NMPDR Search Form style.
1352 :    
1353 :     =back
1354 :    
1355 :     =cut
1356 :    
1357 :     sub MakeTable {
1358 :     # Get the parameters.
1359 :     my ($self, $rows) = @_;
1360 :     # Get the CGI object.
1361 :     my $cgi = $self->Q();
1362 : parrello 1.29 # The first column of the first row must have its width fixed.
1363 :     # This flag will be set to FALSE when that happens.
1364 :     my $needWidth = 1;
1365 : parrello 1.1 # modifier becase we only want to change the first tag. Also, if a width
1366 :     # is already specified on the first column bad things will happen.
1367 :     for my $row (@{$rows}) {
1368 : parrello 1.29 # See if this row needs a width.
1369 :     if ($needWidth && $row =~ /<(td|th) ([^>]+)>/i) {
1370 :     # Here we have a first cell and its tag parameters are in $2.
1371 :     my $elements = $2;
1372 :     if ($elements !~ /colspan/i) {
1373 :     Trace("No colspan tag found in element \'$elements\'.") if T(3);
1374 :     # Here there's no colspan, so we plug in the width. We
1375 :     # eschew the "g" modifier on the substitution because we
1376 :     # only want to update the first cell.
1377 :     $row =~ s/(<(td|th))/$1 width="150"/i;
1378 :     # Denote we don't need this any more.
1379 :     $needWidth = 0;
1380 :     }
1381 :     }
1382 : parrello 1.1 }
1383 :     # Create the table.
1384 : parrello 1.43 my $retVal = CGI::table({border => 2, cellspacing => 2,
1385 : parrello 1.1 width => 700, class => 'search'},
1386 :     @{$rows});
1387 :     # Return the result.
1388 :     return $retVal;
1389 :     }
1390 :    
1391 :     =head3 SubmitRow
1392 :    
1393 : parrello 1.38 my $htmlText = $shelp->SubmitRow($caption);
1394 : parrello 1.1
1395 :     Returns the HTML text for the row containing the page size control
1396 :     and the submit button. All searches should have this row somewhere
1397 :     near the top of the form.
1398 :    
1399 : parrello 1.18 =over 4
1400 :    
1401 :     =item caption (optional)
1402 :    
1403 :     Caption to be put on the search button. The default is C<Go>.
1404 :    
1405 :     =item RETURN
1406 :    
1407 :     Returns a table row containing the controls for submitting the search
1408 :     and tuning the results.
1409 :    
1410 :     =back
1411 :    
1412 : parrello 1.1 =cut
1413 :    
1414 :     sub SubmitRow {
1415 :     # Get the parameters.
1416 : parrello 1.18 my ($self, $caption) = @_;
1417 : parrello 1.1 my $cgi = $self->Q();
1418 : parrello 1.18 # Compute the button caption.
1419 :     my $realCaption = (defined $caption ? $caption : 'Go');
1420 : parrello 1.3 # Get the current page size.
1421 :     my $pageSize = $cgi->param('PageSize');
1422 : parrello 1.34 # Get the current feature ID type.
1423 :     my $aliasType = $self->GetPreferredAliasType();
1424 :     # Create the rows.
1425 : parrello 1.43 my $retVal = CGI::Tr(CGI::td("Identifier Type "),
1426 :     CGI::td({ colspan => 2 },
1427 :     CGI::popup_menu(-name => 'AliasType',
1428 : parrello 1.37 -values => ['FIG', AliasAnalysis::AliasTypes() ],
1429 :     -default => $aliasType) .
1430 : parrello 1.40 Hint("Identifier Type", "Specify how you want gene names to be displayed."))) .
1431 : parrello 1.34 "\n" .
1432 : parrello 1.43 CGI::Tr(CGI::td("Results/Page"),
1433 :     CGI::td(CGI::popup_menu(-name => 'PageSize',
1434 : parrello 1.7 -values => [10, 25, 50, 100, 1000],
1435 : parrello 1.25 -default => $pageSize)),
1436 : parrello 1.43 CGI::td(CGI::submit(-class => 'goButton',
1437 : parrello 1.1 -name => 'Search',
1438 : parrello 1.18 -value => $realCaption)));
1439 : parrello 1.1 # Return the result.
1440 :     return $retVal;
1441 :     }
1442 : parrello 1.2
1443 : parrello 1.3 =head3 GetGenomes
1444 :    
1445 : parrello 1.38 my @genomeList = $shelp->GetGenomes($parmName);
1446 : parrello 1.3
1447 :     Return the list of genomes specified by the specified CGI query parameter.
1448 :     If the request method is POST, then the list of genome IDs is returned
1449 :     without preamble. If the request method is GET and the parameter is not
1450 :     specified, then it is treated as a request for all genomes. This makes it
1451 :     easier for web pages to link to a search that wants to specify all genomes.
1452 :    
1453 :     =over 4
1454 :    
1455 :     =item parmName
1456 :    
1457 :     Name of the parameter containing the list of genomes. This will be the
1458 :     first parameter passed to the L</NmpdrGenomeMenu> call that created the
1459 :     genome selection control on the form.
1460 :    
1461 :     =item RETURN
1462 :    
1463 :     Returns a list of the genomes to process.
1464 :    
1465 :     =back
1466 :    
1467 :     =cut
1468 :    
1469 :     sub GetGenomes {
1470 :     # Get the parameters.
1471 :     my ($self, $parmName) = @_;
1472 :     # Get the CGI query object.
1473 :     my $cgi = $self->Q();
1474 :     # Get the list of genome IDs in the request header.
1475 :     my @retVal = $cgi->param($parmName);
1476 :     Trace("Genome list for $parmName is (" . join(", ", @retVal) . ") with method " . $cgi->request_method() . ".") if T(3);
1477 :     # Check for the special GET case.
1478 :     if ($cgi->request_method() eq "GET" && ! @retVal) {
1479 :     # Here the caller wants all the genomes.
1480 :     my $sprout = $self->DB();
1481 :     @retVal = $sprout->Genomes();
1482 :     }
1483 :     # Return the result.
1484 :     return @retVal;
1485 :     }
1486 :    
1487 :     =head3 ComputeSearchURL
1488 :    
1489 : parrello 1.38 my $url = $shelp->ComputeSearchURL(%overrides);
1490 : parrello 1.3
1491 :     Compute the GET-style URL for the current search. In order for this to work, there
1492 :     must be a copy of the search form on the current page. This will always be the
1493 :     case if the search is coming from C<SearchSkeleton.cgi>.
1494 :    
1495 :     A little expense is involved in order to make the URL as smart as possible. The
1496 :     main complication is that if the user specified all genomes, we'll want to
1497 :     remove the parameter entirely from a get-style URL.
1498 :    
1499 : parrello 1.19 =over 4
1500 :    
1501 :     =item overrides
1502 :    
1503 :     Hash containing override values for the parameters, where the parameter name is
1504 :     the key and the parameter value is the override value. If the override value is
1505 :     C<undef>, the parameter will be deleted from the result.
1506 :    
1507 :     =item RETURN
1508 :    
1509 :     Returns a GET-style URL for invoking the search with the specified overrides.
1510 :    
1511 :     =back
1512 :    
1513 : parrello 1.3 =cut
1514 :    
1515 :     sub ComputeSearchURL {
1516 :     # Get the parameters.
1517 : parrello 1.19 my ($self, %overrides) = @_;
1518 : parrello 1.3 # Get the database and CGI query object.
1519 :     my $cgi = $self->Q();
1520 :     my $sprout = $self->DB();
1521 :     # Start with the full URL.
1522 : parrello 1.41 my $retVal = "$FIG_Config::cgi_url/SearchSkeleton.cgi";
1523 : parrello 1.3 # Get all the query parameters in a hash.
1524 :     my %parms = $cgi->Vars();
1525 :     # Now we need to do some fixing. Each multi-valued parameter is encoded as a string with null
1526 :     # characters separating the individual values. We have to convert those to lists. In addition,
1527 :     # the multiple-selection genome parameters and the feature type parameter must be checked to
1528 :     # determine whether or not they can be removed from the URL. First, we get a list of the
1529 :     # genome parameters and a list of all genomes. Note that we only need the list if a
1530 :     # multiple-selection genome parameter has been found on the form.
1531 :     my %genomeParms = map { $_ => 1 } @{$self->{genomeParms}};
1532 :     my @genomeList;
1533 :     if (keys %genomeParms) {
1534 :     @genomeList = $sprout->Genomes();
1535 :     }
1536 :     # Create a list to hold the URL parameters we find.
1537 :     my @urlList = ();
1538 :     # Now loop through the parameters in the hash, putting them into the output URL.
1539 :     for my $parmKey (keys %parms) {
1540 :     # Get a list of the parameter values. If there's only one, we'll end up with
1541 :     # a singleton list, but that's okay.
1542 :     my @values = split (/\0/, $parms{$parmKey});
1543 :     # Check for special cases.
1544 : parrello 1.26 if (grep { $_ eq $parmKey } qw(SessionID ResultCount Page PageSize Trace TF)) {
1545 : parrello 1.3 # These are bookkeeping parameters we don't need to start a search.
1546 :     @values = ();
1547 :     } elsif ($parmKey =~ /_SearchThing$/) {
1548 :     # Here the value coming in is from a genome control's search thing. It does
1549 :     # not affect the results of the search, so we clear it.
1550 :     @values = ();
1551 :     } elsif ($genomeParms{$parmKey}) {
1552 :     # Here we need to see if the user wants all the genomes. If he does,
1553 :     # we erase all the values just like with features.
1554 :     my $allFlag = $sprout->IsAllGenomes(\@values, \@genomeList);
1555 :     if ($allFlag) {
1556 :     @values = ();
1557 :     }
1558 : parrello 1.19 } elsif (exists $overrides{$parmKey}) {
1559 :     # Here the value is being overridden, so we skip it for now.
1560 :     @values = ();
1561 : parrello 1.3 }
1562 :     # If we still have values, create the URL parameters.
1563 :     if (@values) {
1564 :     push @urlList, map { "$parmKey=" . uri_escape($_) } @values;
1565 :     }
1566 :     }
1567 : parrello 1.19 # Now do the overrides.
1568 :     for my $overKey (keys %overrides) {
1569 :     # Only use this override if it's not a delete marker.
1570 :     if (defined $overrides{$overKey}) {
1571 :     push @urlList, "$overKey=" . uri_escape($overrides{$overKey});
1572 :     }
1573 :     }
1574 : parrello 1.3 # Add the parameters to the URL.
1575 :     $retVal .= "?" . join(";", @urlList);
1576 :     # Return the result.
1577 :     return $retVal;
1578 :     }
1579 :    
1580 : parrello 1.9 =head3 AdvancedClassList
1581 :    
1582 : parrello 1.38 my @classes = SearchHelper::AdvancedClassList();
1583 : parrello 1.9
1584 :     Return a list of advanced class names. This list is used to generate the directory
1585 :     of available searches on the search page.
1586 :    
1587 : parrello 1.34 We do a file search to accomplish this, but to pull it off we need to look at %INC.
1588 : parrello 1.9
1589 :     =cut
1590 :    
1591 :     sub AdvancedClassList {
1592 : parrello 1.34 # Determine the search helper module directory.
1593 :     my $libDirectory = $INC{'SearchHelper.pm'};
1594 :     $libDirectory =~ s/SearchHelper\.pm//;
1595 :     # Read it, keeping only the helper modules.
1596 :     my @modules = grep { /^SH\w+\.pm/ } Tracer::OpenDir($libDirectory, 0);
1597 :     # Convert the file names to search types.
1598 :     my @retVal = map { $_ =~ /^SH(\w+)\.pm/; $1 } @modules;
1599 :     # Return the result in alphabetical order.
1600 : parrello 1.30 return sort @retVal;
1601 : parrello 1.9 }
1602 :    
1603 : parrello 1.16 =head3 SelectionTree
1604 :    
1605 : parrello 1.38 my $htmlText = SearchHelper::SelectionTree($cgi, \%tree, %options);
1606 : parrello 1.16
1607 :     Display a selection tree.
1608 :    
1609 :     This method creates the HTML for a tree selection control. The tree is implemented as a set of
1610 :     nested HTML unordered lists. Each selectable element of the tree will contain a radio button. In
1611 :     addition, some of the tree nodes can contain hyperlinks.
1612 :    
1613 :     The tree itself is passed in as a multi-level list containing node names followed by
1614 :     contents. Each content element is a reference to a similar list. The first element of
1615 :     each list may be a hash reference. If so, it should contain one or both of the following
1616 :     keys.
1617 :    
1618 :     =over 4
1619 :    
1620 :     =item link
1621 :    
1622 :     The navigation URL to be popped up if the user clicks on the node name.
1623 :    
1624 :     =item value
1625 :    
1626 :     The form value to be returned if the user selects the tree node.
1627 :    
1628 :     =back
1629 :    
1630 :     The presence of a C<link> key indicates the node name will be hyperlinked. The presence of
1631 :     a C<value> key indicates the node name will have a radio button. If a node has no children,
1632 :     you may pass it a hash reference instead of a list reference.
1633 :    
1634 :     The following example shows the hash for a three-level tree with links on the second level and
1635 :     radio buttons on the third.
1636 :    
1637 :     [ Objects => [
1638 :     Entities => [
1639 :     {link => "../docs/WhatIsAnEntity.html"},
1640 :     Genome => {value => 'GenomeData'},
1641 :     Feature => {value => 'FeatureData'},
1642 :     Contig => {value => 'ContigData'},
1643 :     ],
1644 :     Relationships => [
1645 :     {link => "../docs/WhatIsARelationShip.html"},
1646 :     HasFeature => {value => 'GenomeToFeature'},
1647 :     IsOnContig => {value => 'FeatureToContig'},
1648 :     ]
1649 :     ]
1650 :     ]
1651 :    
1652 :     Note how each leaf of the tree has a hash reference for its value, while the branch nodes
1653 :     all have list references.
1654 :    
1655 :     This next example shows how to set up a taxonomy selection field. The value returned
1656 :     by the tree control will be the taxonomy string for the selected node ready for use
1657 :     in a LIKE-style SQL filter. Only the single branch ending in campylobacter is shown for
1658 :     reasons of space.
1659 :    
1660 :     [ All => [
1661 :     {value => "%"},
1662 :     Bacteria => [
1663 :     {value => "Bacteria%"},
1664 :     Proteobacteria => [
1665 :     {value => "Bacteria; Proteobacteria%"},
1666 :     Epsilonproteobacteria => [
1667 :     {value => "Bacteria; Proteobacteria;Epsilonproteobacteria%"},
1668 :     Campylobacterales => [
1669 :     {value => "Bacteria; Proteobacteria; Epsilonproteobacteria; Campylobacterales%"},
1670 : parrello 1.38 Campylobacteraceae =>
1671 : parrello 1.16 {value => "Bacteria; Proteobacteria; Epsilonproteobacteria; Campylobacterales; Campylobacteraceae%"},
1672 :     ...
1673 :     ]
1674 :     ...
1675 :     ]
1676 :     ...
1677 :     ]
1678 :     ...
1679 :     ]
1680 :     ...
1681 :     ]
1682 :     ]
1683 :    
1684 :    
1685 :     This method of tree storage allows the caller to control the order in which the tree nodes
1686 :     are displayed and to completely control value selection and use of hyperlinks. It is, however
1687 :     a bit complicated. Eventually, tree-building classes will be provided to simplify things.
1688 :    
1689 :     The parameters to this method are as follows.
1690 :    
1691 :     =over 4
1692 :    
1693 :     =item cgi
1694 :    
1695 :     CGI object used to generate the HTML.
1696 :    
1697 :     =item tree
1698 :    
1699 :     Reference to a hash describing a tree. See the description above.
1700 :    
1701 :     =item options
1702 :    
1703 :     Hash containing options for the tree display.
1704 :    
1705 :     =back
1706 :    
1707 :     The allowable options are as follows
1708 :    
1709 :     =over 4
1710 :    
1711 :     =item nodeImageClosed
1712 :    
1713 :     URL of the image to display next to the tree nodes when they are collapsed. Clicking
1714 : parrello 1.41 on the image will expand a section of the tree. The default is C<plus.gif>.
1715 : parrello 1.16
1716 :     =item nodeImageOpen
1717 :    
1718 :     URL of the image to display next to the tree nodes when they are expanded. Clicking
1719 : parrello 1.41 on the image will collapse a section of the tree. The default is C<minus.gif>.
1720 : parrello 1.16
1721 :     =item style
1722 :    
1723 :     Style to use for the tree. The default is C<tree>. Because the tree style is implemented
1724 :     as nested lists, the key components of this style are the definitions for the C<ul> and
1725 :     C<li> tags. The default style file contains the following definitions.
1726 :    
1727 :     .tree ul {
1728 : parrello 1.38 margin-left: 0; padding-left: 22px
1729 : parrello 1.16 }
1730 :     .tree li {
1731 :     list-style-type: none;
1732 :     }
1733 :    
1734 :     The default image is 22 pixels wide, so in the above scheme each tree level is indented from its
1735 :     parent by the width of the node image. This use of styles limits the things we can do in formatting
1736 :     the tree, but it has the advantage of vastly simplifying the tree creation.
1737 :    
1738 :     =item name
1739 :    
1740 :     Field name to give to the radio buttons in the tree. The default is C<selection>.
1741 :    
1742 :     =item target
1743 :    
1744 :     Frame target for links. The default is C<_self>.
1745 :    
1746 :     =item selected
1747 :    
1748 :     If specified, the value of the radio button to be pre-selected.
1749 :    
1750 :     =back
1751 :    
1752 :     =cut
1753 :    
1754 :     sub SelectionTree {
1755 :     # Get the parameters.
1756 :     my ($cgi, $tree, %options) = @_;
1757 :     # Get the options.
1758 :     my $optionThing = Tracer::GetOptions({ name => 'selection',
1759 : parrello 1.41 nodeImageClosed => "$FIG_Config::cgi_url/Html/plus.gif",
1760 :     nodeImageOpen => "$FIG_Config::cgi_url/Html/minus.gif",
1761 : parrello 1.16 style => 'tree',
1762 :     target => '_self',
1763 :     selected => undef},
1764 :     \%options);
1765 :     # Declare the return variable. We'll do the standard thing with creating a list
1766 :     # of HTML lines and rolling them together at the end.
1767 :     my @retVal = ();
1768 :     # Only proceed if the tree is present.
1769 :     if (defined($tree)) {
1770 :     # Validate the tree.
1771 :     if (ref $tree ne 'ARRAY') {
1772 :     Confess("Selection tree is not a list reference.");
1773 :     } elsif (scalar @{$tree} == 0) {
1774 :     # The tree is empty, so we do nothing.
1775 :     } elsif ($tree->[0] eq 'HASH') {
1776 :     Confess("Hash reference found at start of selection tree. The tree as a whole cannot have attributes, only tree nodes.");
1777 :     } else {
1778 :     # Here we have a real tree. Apply the tree style.
1779 : parrello 1.43 push @retVal, CGI::start_div({ class => $optionThing->{style} });
1780 : parrello 1.16 # Give us a DIV ID.
1781 :     my $divID = GetDivID($optionThing->{name});
1782 :     # Show the tree.
1783 :     push @retVal, ShowBranch($cgi, "(root)", $divID, $tree, $optionThing, 'block');
1784 :     # Close the DIV block.
1785 : parrello 1.43 push @retVal, CGI::end_div();
1786 : parrello 1.16 }
1787 :     }
1788 :     # Return the result.
1789 :     return join("\n", @retVal, "");
1790 :     }
1791 :    
1792 :     =head3 ShowBranch
1793 :    
1794 : parrello 1.38 my @htmlLines = SearchHelper::ShowBranch($cgi, $label, $id, $branch, $options, $displayType);
1795 : parrello 1.16
1796 : parrello 1.38 This is a recursive method that displays a branch of the tree.
1797 : parrello 1.16
1798 :     =over 4
1799 :    
1800 :     =item cgi
1801 :    
1802 :     CGI object used to format HTML.
1803 :    
1804 :     =item label
1805 :    
1806 :     Label of this tree branch. It is only used in error messages.
1807 :    
1808 :     =item id
1809 :    
1810 :     ID to be given to this tree branch. The ID is used in the code that expands and collapses
1811 :     tree nodes.
1812 :    
1813 :     =item branch
1814 :    
1815 :     Reference to a list containing the content of the tree branch. The list contains an optional
1816 :     hash reference that is ignored and the list of children, each child represented by a name
1817 :     and then its contents. The contents could by a hash reference (indicating the attributes
1818 :     of a leaf node), or another tree branch.
1819 :    
1820 :     =item options
1821 :    
1822 :     Options from the original call to L</SelectionTree>.
1823 :    
1824 :     =item displayType
1825 :    
1826 :     C<block> if the contents of this list are to be displayed, C<none> if they are to be
1827 :     hidden.
1828 :    
1829 :     =item RETURN
1830 :    
1831 :     Returns one or more HTML lines that can be used to display the tree branch.
1832 :    
1833 :     =back
1834 :    
1835 :     =cut
1836 :    
1837 :     sub ShowBranch {
1838 :     # Get the parameters.
1839 :     my ($cgi, $label, $id, $branch, $options, $displayType) = @_;
1840 :     # Declare the return variable.
1841 :     my @retVal = ();
1842 :     # Start the branch.
1843 : parrello 1.43 push @retVal, CGI::start_ul({ id => $id, style => "display:$displayType" });
1844 : parrello 1.16 # Check for the hash and choose the start location accordingly.
1845 :     my $i0 = (ref $branch->[0] eq 'HASH' ? 1 : 0);
1846 :     # Get the list length.
1847 :     my $i1 = scalar(@{$branch});
1848 :     # Verify we have an even number of elements.
1849 :     if (($i1 - $i0) % 2 != 0) {
1850 :     Trace("Branch elements are from $i0 to $i1.") if T(3);
1851 :     Confess("Odd number of elements in tree branch $label.");
1852 :     } else {
1853 :     # Loop through the elements.
1854 :     for (my $i = $i0; $i < $i1; $i += 2) {
1855 :     # Get this node's label and contents.
1856 :     my ($myLabel, $myContent) = ($branch->[$i], $branch->[$i+1]);
1857 :     # Get an ID for this node's children (if any).
1858 :     my $myID = GetDivID($options->{name});
1859 :     # Now we need to find the list of children and the options hash.
1860 :     # This is a bit ugly because we allow the shortcut of a hash without an
1861 :     # enclosing list. First, we need some variables.
1862 :     my $attrHash = {};
1863 :     my @childHtml = ();
1864 :     my $hasChildren = 0;
1865 :     if (! ref $myContent) {
1866 :     Confess("Invalid tree definition. Scalar found as content of node \"$myLabel\".");
1867 :     } elsif (ref $myContent eq 'HASH') {
1868 :     # Here the node is a leaf and its content contains the link/value hash.
1869 :     $attrHash = $myContent;
1870 :     } elsif (ref $myContent eq 'ARRAY') {
1871 :     # Here the node may be a branch. Its content is a list.
1872 :     my $len = scalar @{$myContent};
1873 :     if ($len >= 1) {
1874 :     # Here the first element of the list could by the link/value hash.
1875 :     if (ref $myContent->[0] eq 'HASH') {
1876 :     $attrHash = $myContent->[0];
1877 :     # If there's data in the list besides the hash, it's our child list.
1878 :     # We can pass the entire thing as the child list, because the hash
1879 :     # is ignored.
1880 :     if ($len > 1) {
1881 :     $hasChildren = 1;
1882 :     }
1883 :     } else {
1884 :     $hasChildren = 1;
1885 :     }
1886 :     # If we have children, create the child list with a recursive call.
1887 :     if ($hasChildren) {
1888 :     Trace("Processing children of $myLabel.") if T(4);
1889 : parrello 1.42 push @childHtml, ShowBranch($cgi, $myLabel, $myID, $myContent, $options, 'block');
1890 : parrello 1.27 Trace("Children of $myLabel finished.") if T(4);
1891 : parrello 1.16 }
1892 :     }
1893 :     }
1894 :     # Okay, it's time to pause and take stock. We have the label of the current node
1895 :     # in $myLabel, its attributes in $attrHash, and if it is NOT a leaf node, we
1896 :     # have a child list in @childHtml. If it IS a leaf node, $hasChildren is 0.
1897 :     # Compute the image HTML. It's tricky, because we have to deal with the open and
1898 :     # closed images.
1899 :     my @images = ($options->{nodeImageOpen}, $options->{nodeImageClosed});
1900 :     my $image = $images[$hasChildren];
1901 : parrello 1.43 my $prefixHtml = CGI::img({src => $image, id => "${myID}img"});
1902 : parrello 1.16 if ($hasChildren) {
1903 :     # If there are children, we wrap the image in a toggle hyperlink.
1904 : parrello 1.43 $prefixHtml = CGI::a({ onClick => "javascript:treeToggle('$myID','$images[0]', '$images[1]')" },
1905 : parrello 1.16 $prefixHtml);
1906 :     }
1907 :     # Now the radio button, if any. Note we use "defined" in case the user wants the
1908 :     # value to be 0.
1909 :     if (defined $attrHash->{value}) {
1910 :     # Due to a glitchiness in the CGI stuff, we have to build the attribute
1911 :     # hash for the "input" method. If the item is pre-selected, we add
1912 :     # "checked => undef" to the hash. Otherwise, we can't have "checked"
1913 :     # at all.
1914 :     my $radioParms = { type => 'radio',
1915 :     name => $options->{name},
1916 :     value => $attrHash->{value},
1917 :     };
1918 :     if (defined $options->{selected} && $options->{selected} eq $attrHash->{value}) {
1919 :     $radioParms->{checked} = undef;
1920 :     }
1921 : parrello 1.43 $prefixHtml .= CGI::input($radioParms);
1922 : parrello 1.16 }
1923 :     # Next, we format the label.
1924 :     my $labelHtml = $myLabel;
1925 : parrello 1.27 Trace("Formatting tree node for \"$myLabel\".") if T(4);
1926 : parrello 1.16 # Apply a hyperlink if necessary.
1927 :     if (defined $attrHash->{link}) {
1928 : parrello 1.43 $labelHtml = CGI::a({ href => $attrHash->{link}, target => $options->{target} },
1929 : parrello 1.16 $labelHtml);
1930 :     }
1931 :     # Finally, roll up the child HTML. If there are no children, we'll get a null string
1932 :     # here.
1933 :     my $childHtml = join("\n", @childHtml);
1934 :     # Now we have all the pieces, so we can put them together.
1935 : parrello 1.43 push @retVal, CGI::li("$prefixHtml$labelHtml$childHtml");
1936 : parrello 1.16 }
1937 :     }
1938 :     # Close the tree branch.
1939 : parrello 1.43 push @retVal, CGI::end_ul();
1940 : parrello 1.16 # Return the result.
1941 :     return @retVal;
1942 :     }
1943 :    
1944 :     =head3 GetDivID
1945 :    
1946 : parrello 1.38 my $idString = SearchHelper::GetDivID($name);
1947 : parrello 1.16
1948 :     Return a new HTML ID string.
1949 :    
1950 :     =over 4
1951 :    
1952 :     =item name
1953 :    
1954 :     Name to be prefixed to the ID string.
1955 :    
1956 :     =item RETURN
1957 :    
1958 :     Returns a hopefully-unique ID string.
1959 :    
1960 :     =back
1961 :    
1962 :     =cut
1963 :    
1964 :     sub GetDivID {
1965 :     # Get the parameters.
1966 :     my ($name) = @_;
1967 :     # Compute the ID.
1968 :     my $retVal = "elt_$name$divCount";
1969 :     # Increment the counter to make sure this ID is not re-used.
1970 :     $divCount++;
1971 :     # Return the result.
1972 :     return $retVal;
1973 :     }
1974 :    
1975 : parrello 1.31 =head3 PrintLine
1976 :    
1977 : parrello 1.38 $shelp->PrintLine($message);
1978 : parrello 1.31
1979 :     Print a line of CGI output. This is used during the operation of the B<Find> method while
1980 :     searching, so the user sees progress in real-time.
1981 :    
1982 :     =over 4
1983 :    
1984 :     =item message
1985 :    
1986 :     HTML text to display.
1987 :    
1988 :     =back
1989 :    
1990 :     =cut
1991 :    
1992 :     sub PrintLine {
1993 :     # Get the parameters.
1994 :     my ($self, $message) = @_;
1995 : parrello 1.43 # Send the message to the output.
1996 : parrello 1.31 print "$message\n";
1997 :     }
1998 :    
1999 : parrello 1.34 =head3 GetHelper
2000 : parrello 1.13
2001 : parrello 1.38 my $shelp = SearchHelper::GetHelper($parm, $type => $className);
2002 : parrello 1.1
2003 : parrello 1.34 Return a helper object with the given class name. If no such class exists, an
2004 :     error will be thrown.
2005 : parrello 1.1
2006 :     =over 4
2007 :    
2008 : parrello 1.34 =item parm
2009 : parrello 1.1
2010 : parrello 1.34 Parameter to pass to the constructor. This is a CGI object for a search helper
2011 :     and a search helper object for the result helper.
2012 : parrello 1.3
2013 :     =item type
2014 :    
2015 : parrello 1.34 Type of helper: C<RH> for a result helper and C<SH> for a search helper.
2016 : parrello 1.3
2017 : parrello 1.34 =item className
2018 : parrello 1.3
2019 : parrello 1.34 Class name for the helper object, without the preceding C<SH> or C<RH>. This is
2020 :     identical to what the script expects for the C<Class> or C<ResultType> parameter.
2021 : parrello 1.3
2022 :     =item RETURN
2023 :    
2024 : parrello 1.34 Returns a helper object for the specified class.
2025 : parrello 1.3
2026 :     =back
2027 :    
2028 :     =cut
2029 :    
2030 : parrello 1.34 sub GetHelper {
2031 : parrello 1.3 # Get the parameters.
2032 : parrello 1.34 my ($parm, $type, $className) = @_;
2033 : parrello 1.3 # Declare the return variable.
2034 : parrello 1.34 my $retVal;
2035 :     # Try to create the helper.
2036 :     eval {
2037 :     # Load it into memory. If it's already there nothing will happen here.
2038 :     my $realName = "$type$className";
2039 :     Trace("Requiring helper $realName.") if T(3);
2040 :     require "$realName.pm";
2041 :     Trace("Constructing helper object.") if T(3);
2042 :     # Construct the object.
2043 :     $retVal = eval("$realName->new(\$parm)");
2044 :     # Commit suicide if it didn't work.
2045 :     if (! defined $retVal) {
2046 :     die "Could not find a $type handler of type $className.";
2047 : parrello 1.43 } else {
2048 :     # Perform any necessary subclass initialization.
2049 :     $retVal->Initialize();
2050 : parrello 1.34 }
2051 :     };
2052 :     # Check for errors.
2053 :     if ($@) {
2054 :     Confess("Error retrieving $type$className: $@");
2055 : parrello 1.3 }
2056 :     # Return the result.
2057 :     return $retVal;
2058 :     }
2059 :    
2060 : parrello 1.10 =head3 SaveOrganismData
2061 :    
2062 : parrello 1.38 my ($name, $displayGroup, $domain) = $shelp->SaveOrganismData($group, $genomeID, $genus, $species, $strain, $taxonomy);
2063 : parrello 1.10
2064 :     Format the name of an organism and the display version of its group name. The incoming
2065 :     data should be the relevant fields from the B<Genome> record in the database. The
2066 :     data will also be stored in the genome cache for later use in posting search results.
2067 :    
2068 :     =over 4
2069 :    
2070 :     =item group
2071 :    
2072 :     Name of the genome's group as it appears in the database.
2073 :    
2074 :     =item genomeID
2075 :    
2076 :     ID of the relevant genome.
2077 :    
2078 :     =item genus
2079 :    
2080 :     Genus of the genome's organism. If undefined or null, it will be assumed the genome is not
2081 :     in the database. In this case, the organism name is derived from the genomeID and the group
2082 :     is automatically the supporting-genomes group.
2083 :    
2084 :     =item species
2085 :    
2086 :     Species of the genome's organism.
2087 :    
2088 :     =item strain
2089 :    
2090 :     Strain of the species represented by the genome.
2091 :    
2092 : parrello 1.32 =item taxonomy
2093 :    
2094 :     Taxonomy of the species represented by the genome.
2095 :    
2096 : parrello 1.10 =item RETURN
2097 :    
2098 : parrello 1.32 Returns a three-element list. The first element is the formatted genome name. The second
2099 :     element is the display name of the genome's group. The third is the genome's domain.
2100 : parrello 1.10
2101 :     =back
2102 :    
2103 :     =cut
2104 :    
2105 :     sub SaveOrganismData {
2106 :     # Get the parameters.
2107 : parrello 1.32 my ($self, $group, $genomeID, $genus, $species, $strain, $taxonomy) = @_;
2108 : parrello 1.10 # Declare the return values.
2109 :     my ($name, $displayGroup);
2110 :     # If the organism does not exist, format an unknown name and a blank group.
2111 :     if (! defined($genus)) {
2112 :     $name = "Unknown Genome $genomeID";
2113 :     $displayGroup = "";
2114 :     } else {
2115 :     # It does exist, so format the organism name.
2116 :     $name = "$genus $species";
2117 :     if ($strain) {
2118 :     $name .= " $strain";
2119 :     }
2120 :     # Compute the display group. This is currently the same as the incoming group
2121 :     # name unless it's the supporting group, which is nulled out.
2122 :     $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
2123 : parrello 1.36 Trace("Group = $displayGroup, translated from \"$group\".") if T(4);
2124 : parrello 1.10 }
2125 : parrello 1.32 # Compute the domain from the taxonomy.
2126 :     my ($domain) = split /\s*;\s*/, $taxonomy, 2;
2127 : parrello 1.10 # Cache the group and organism data.
2128 :     my $cache = $self->{orgs};
2129 : parrello 1.32 $cache->{$genomeID} = [$name, $displayGroup, $domain];
2130 : parrello 1.10 # Return the result.
2131 : parrello 1.32 return ($name, $displayGroup, $domain);
2132 : parrello 1.10 }
2133 :    
2134 : parrello 1.16 =head3 ValidateKeywords
2135 :    
2136 : parrello 1.38 my $okFlag = $shelp->ValidateKeywords($keywordString, $required);
2137 : parrello 1.16
2138 :     Insure that a keyword string is reasonably valid. If it is invalid, a message will be
2139 :     set.
2140 :    
2141 :     =over 4
2142 :    
2143 :     =item keywordString
2144 :    
2145 :     Keyword string specified as a parameter to the current search.
2146 :    
2147 :     =item required
2148 :    
2149 :     TRUE if there must be at least one keyword specified, else FALSE.
2150 :    
2151 :     =item RETURN
2152 :    
2153 :     Returns TRUE if the keyword string is valid, else FALSE. Note that a null keyword string
2154 :     is acceptable if the I<$required> parameter is not specified.
2155 :    
2156 :     =back
2157 :    
2158 :     =cut
2159 :    
2160 :     sub ValidateKeywords {
2161 :     # Get the parameters.
2162 :     my ($self, $keywordString, $required) = @_;
2163 :     # Declare the return variable.
2164 :     my $retVal = 0;
2165 :     my @wordList = split /\s+/, $keywordString;
2166 :     # Right now our only real worry is a list of all minus words. The problem with it is that
2167 :     # it will return an incorrect result.
2168 :     my @plusWords = grep { $_ =~ /^[^\-]/ } @wordList;
2169 :     if (! @wordList) {
2170 :     if ($required) {
2171 :     $self->SetMessage("No search words specified.");
2172 : parrello 1.22 } else {
2173 :     $retVal = 1;
2174 : parrello 1.16 }
2175 :     } elsif (! @plusWords) {
2176 :     $self->SetMessage("At least one keyword must be positive. All the keywords entered are preceded by minus signs.");
2177 :     } else {
2178 :     $retVal = 1;
2179 :     }
2180 :     # Return the result.
2181 :     return $retVal;
2182 :     }
2183 :    
2184 : parrello 1.30 =head3 TuningParameters
2185 :    
2186 : parrello 1.38 my $options = $shelp->TuningParameters(%parmHash);
2187 : parrello 1.30
2188 :     Retrieve tuning parameters from the CGI query object. The parameter is a hash that maps parameter names
2189 :     to their default values. The parameters and their values will be returned as a hash reference.
2190 :    
2191 :     =over 4
2192 :    
2193 :     =item parmHash
2194 :    
2195 :     Hash mapping parameter names to their default values.
2196 :    
2197 :     =item RETURN
2198 :    
2199 :     Returns a reference to a hash containing the parameter names mapped to their actual values.
2200 :    
2201 :     =back
2202 :    
2203 :     =cut
2204 :    
2205 :     sub TuningParameters {
2206 :     # Get the parameters.
2207 :     my ($self, %parmHash) = @_;
2208 :     # Declare the return variable.
2209 :     my $retVal = {};
2210 :     # Get the CGI Query Object.
2211 :     my $cgi = $self->Q();
2212 :     # Loop through the parameter names.
2213 :     for my $parm (keys %parmHash) {
2214 :     # Get the incoming value for this parameter.
2215 :     my $value = $cgi->param($parm);
2216 :     # Zero might be a valid value, so we do an is-defined check rather than an OR.
2217 :     if (defined($value)) {
2218 :     $retVal->{$parm} = $value;
2219 :     } else {
2220 :     $retVal->{$parm} = $parmHash{$parm};
2221 :     }
2222 :     }
2223 :     # Return the result.
2224 :     return $retVal;
2225 :     }
2226 :    
2227 : parrello 1.34 =head3 GetPreferredAliasType
2228 :    
2229 : parrello 1.38 my $type = $shelp->GetPreferredAliasType();
2230 : parrello 1.34
2231 :     Return the preferred alias type for the current session. This information is stored
2232 :     in the C<AliasType> parameter of the CGI query object, and the default is C<FIG>
2233 :     (which indicates the FIG ID).
2234 :    
2235 :     =cut
2236 :    
2237 :     sub GetPreferredAliasType {
2238 :     # Get the parameters.
2239 :     my ($self) = @_;
2240 :     # Determine the preferred type.
2241 :     my $cgi = $self->Q();
2242 :     my $retVal = $cgi->param('AliasType') || 'FIG';
2243 :     # Return it.
2244 :     return $retVal;
2245 :     }
2246 :    
2247 : parrello 1.43 =head3 Hint
2248 :    
2249 :     my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
2250 :    
2251 :     Return the HTML for a small question mark that displays the specified hint text when it is clicked.
2252 :     This HTML can be put in forms to provide a useful hinting mechanism.
2253 :    
2254 :     =over 4
2255 :    
2256 :     =item wikiPage
2257 :    
2258 :     Name of the wiki page to be popped up when the hint mark is clicked.
2259 :    
2260 :     =item hintText
2261 :    
2262 :     Text to display for the hint. It is raw html, but may not contain any double quotes.
2263 :    
2264 :     =item RETURN
2265 :    
2266 :     Returns the html for the hint facility. The resulting html shows a small button-like thing that
2267 :     uses the standard FIG popup technology.
2268 :    
2269 :     =back
2270 :    
2271 :     =cut
2272 :    
2273 :     sub Hint {
2274 :     # Get the parameters.
2275 :     my ($wikiPage, $hintText) = @_;
2276 :     # Ask Sprout to draw the hint button for us.
2277 :     return Sprout::Hint($wikiPage, $hintText);
2278 :     }
2279 :    
2280 :    
2281 :    
2282 : parrello 1.4 =head2 Virtual Methods
2283 :    
2284 : parrello 1.43 =head3 HeaderHtml
2285 :    
2286 :     my $html = $shelp->HeaderHtml();
2287 :    
2288 :     Generate HTML for the HTML header. If extra styles or javascript are required,
2289 :     they should go in here.
2290 :    
2291 :     =cut
2292 :    
2293 :     sub HeaderHtml {
2294 :     return "";
2295 :     }
2296 :    
2297 : parrello 1.4 =head3 Form
2298 :    
2299 : parrello 1.43 my $html = $shelp->Form($mode);
2300 :    
2301 :     Generate the HTML for a form to request a new search. If the subclass does not
2302 :     override this method, then the search is formless, and must be started from an
2303 :     external page.
2304 : parrello 1.4
2305 : parrello 1.43 =cut
2306 :    
2307 :     sub Form {
2308 :     # Get the parameters.
2309 :     my ($self) = @_;
2310 :     return "";
2311 :     }
2312 : parrello 1.4
2313 :     =head3 Find
2314 :    
2315 : parrello 1.38 my $resultCount = $shelp->Find();
2316 : parrello 1.4
2317 :     Conduct a search based on the current CGI query parameters. The search results will
2318 :     be written to the session cache file and the number of results will be
2319 :     returned. If the search parameters are invalid, a result count of C<undef> will be
2320 :     returned and a result message will be stored in this object describing the problem.
2321 :    
2322 : parrello 1.34 =cut
2323 :    
2324 :     sub Find {
2325 :     # Get the parameters.
2326 :     my ($self) = @_;
2327 :     $self->Message("Call to pure virtual Find method in helper of type " . ref($self) . ".");
2328 :     return undef;
2329 :     }
2330 :    
2331 : parrello 1.4 =head3 Description
2332 :    
2333 : parrello 1.38 my $htmlText = $shelp->Description();
2334 : parrello 1.4
2335 :     Return a description of this search. The description is used for the table of contents
2336 :     on the main search tools page. It may contain HTML, but it should be character-level,
2337 :     not block-level, since the description is going to appear in a list.
2338 :    
2339 :     =cut
2340 :    
2341 : parrello 1.34 sub Description {
2342 : parrello 1.4 # Get the parameters.
2343 : parrello 1.34 my ($self) = @_;
2344 :     $self->Message("Call to pure virtual Description method in helper of type " . ref($self) . ".");
2345 :     return "Unknown search type";
2346 : parrello 1.4 }
2347 : parrello 1.9
2348 : parrello 1.31 =head3 SearchTitle
2349 :    
2350 : parrello 1.38 my $titleHtml = $shelp->SearchTitle();
2351 : parrello 1.31
2352 :     Return the display title for this search. The display title appears above the search results.
2353 :     If no result is returned, no title will be displayed. The result should be an html string
2354 :     that can be legally put inside a block tag such as C<h3> or C<p>.
2355 :    
2356 :     =cut
2357 :    
2358 :     sub SearchTitle {
2359 :     # Get the parameters.
2360 :     my ($self) = @_;
2361 :     # Declare the return variable.
2362 : parrello 1.34 my $retVal = "";
2363 : parrello 1.31 # Return it.
2364 :     return $retVal;
2365 :     }
2366 :    
2367 : parrello 1.34 =head3 DefaultColumns
2368 : parrello 1.28
2369 : parrello 1.38 $shelp->DefaultColumns($rhelp);
2370 : parrello 1.28
2371 : parrello 1.34 Store the default columns in the result helper. The default action is just to ask
2372 :     the result helper for its default columns, but this may be changed by overriding
2373 :     this method.
2374 : parrello 1.28
2375 :     =over 4
2376 :    
2377 : parrello 1.34 =item rhelp
2378 : parrello 1.28
2379 : parrello 1.34 Result helper object in which the column list should be stored.
2380 : parrello 1.28
2381 :     =back
2382 :    
2383 :     =cut
2384 :    
2385 : parrello 1.34 sub DefaultColumns {
2386 : parrello 1.28 # Get the parameters.
2387 : parrello 1.34 my ($self, $rhelp) = @_;
2388 :     # Get the default columns from the result helper.
2389 :     my @cols = $rhelp->DefaultResultColumns();
2390 :     # Store them back.
2391 :     $rhelp->SetColumns(@cols);
2392 : parrello 1.28 }
2393 :    
2394 : parrello 1.32
2395 : parrello 1.43 =head3 Initialize
2396 :    
2397 :     $shelp->Initialize();
2398 :    
2399 :     Perform any initialization required after construction of the helper.
2400 :    
2401 :     =cut
2402 :    
2403 :     sub Initialize {
2404 :     # The default is to do nothing.
2405 :     }
2406 : parrello 1.32
2407 : parrello 1.43 =head3 GetResultHelper
2408 : parrello 1.32
2409 : parrello 1.43 my $rhelp = $shelp->GetResultHelper($className);
2410 : parrello 1.32
2411 : parrello 1.43 Return a result helper for this search helper. The default action is to create
2412 :     a result helper from scratch; however, if the subclass has an internal result
2413 :     helper it can override this method to return it without having to create a new
2414 :     one.
2415 : parrello 1.37
2416 : parrello 1.43 =over 4
2417 : parrello 1.37
2418 : parrello 1.43 =item className
2419 : parrello 1.32
2420 : parrello 1.43 Result helper class name.
2421 : parrello 1.32
2422 :     =item RETURN
2423 :    
2424 : parrello 1.43 Returns a result helper of the specified class connected to this search helper.
2425 : parrello 1.32
2426 :     =back
2427 :    
2428 :     =cut
2429 :    
2430 : parrello 1.43 sub GetResultHelper {
2431 : parrello 1.34 # Get the parameters.
2432 : parrello 1.43 my ($self, $className) = @_;
2433 :     # Create the helper.
2434 :     my $retVal = GetHelper($self, RH => $className);
2435 :     # return it.
2436 :     return $retVal;
2437 : parrello 1.32 }
2438 :    
2439 : parrello 1.38 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3