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

Annotation of /Sprout/SearchHelper.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package 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 :     use Time::HiRes 'gettimeofday';
14 :     use Sprout;
15 :     use SFXlate;
16 :     use FIGRules;
17 :     use HTML;
18 :     use BasicLocation;
19 : parrello 1.2 use FeatureQuery;
20 : parrello 1.3 use URI::Escape;
21 :     use PageBuilder;
22 : parrello 1.1
23 :     =head1 Search Helper Base Class
24 :    
25 :     =head2 Introduction
26 :    
27 :     The search helper is a base class for all search objects. It has methods for performing
28 :     all the common tasks required to build and manage a search cache. The subclass must
29 :     provide methods for generating and processing search forms. The base class has the
30 :     following object fields.
31 :    
32 :     =over 4
33 :    
34 :     =item cols
35 :    
36 :     Reference to a list of column header descriptions. If undefined, then the session cache
37 :     file has been opened but nothing has been written to it.
38 :    
39 :     =item fileHandle
40 :    
41 :     File handle for the session cache file.
42 :    
43 :     =item query
44 :    
45 :     CGI query object, which includes the search parameters and the various
46 :     session status variables kept between requests from the user.
47 :    
48 :     =item type
49 :    
50 :     Session type: C<old> if there is an existing cache file from which we are
51 :     displaying search results, or C<new> if the cache file needs to be built.
52 :    
53 :     =item class
54 :    
55 :     Name of the search helper class as it would appear in the CGI query object
56 :     (i.e. without the C<SH> prefix.
57 :    
58 :     =item sprout
59 :    
60 :     Sprout object for accessing the database.
61 :    
62 :     =item message
63 :    
64 :     Message to display if an error has been detected.
65 :    
66 :     =item orgs
67 :    
68 :     Reference to a hash mapping genome IDs to organism names.
69 :    
70 :     =item name
71 :    
72 :     Name to use for this object's form.
73 :    
74 :     =item scriptQueue
75 :    
76 :     List of JavaScript statements to be executed after the form is closed.
77 :    
78 : parrello 1.3 =item genomeHash
79 :    
80 :     Cache of the genome group hash used to build genome selection controls.
81 :    
82 :     =item genomeParms
83 :    
84 :     List of the parameters that are used to select multiple genomes.
85 :    
86 :     =item filtered
87 :    
88 :     TRUE if this is a feature-filtered search, else FALSE. B<NOTE> that this
89 :     field is updated by the B<FeatureQuery> object.
90 :    
91 : parrello 1.1 =back
92 :    
93 : parrello 1.2 =head2 Adding a new Search Tool
94 :    
95 :     To add a new search tool to the system, you must
96 :    
97 :     =over 4
98 :    
99 :     =item 1
100 :    
101 :     Choose a class name for your search tool.
102 :    
103 :     =item 2
104 :    
105 :     Create a new subclass of this object and implement each of the virtual methods. The
106 :     name of the subclass must be C<SH>I<className>.
107 :    
108 :     =item 3
109 :    
110 :     Create an include file among the web server pages that describes how to use
111 :     the search tool. The include file must be in the B<includes> directory, and
112 :     its name must be C<SearchHelp_>I<className>C<.inc>.
113 :    
114 :     =item 4
115 :    
116 :     In the C<SearchSkeleton.cgi> script, add a C<use> statement for your search tool
117 :     and then put the class name in the C<@advancedClasses> list.
118 :    
119 :     =back
120 :    
121 :     =head3 Building a Search Form
122 :    
123 :     All search forms are three-column tables. In general, you want one form
124 :     variable per table row. The first column should contain the label and
125 :     the second should contain the form control for specifying the variable
126 :     value. If the control is wide, you should use C<colspan="2"> to give it
127 :     extra room. B<Do not> specify a width in any of your table cells, as
128 :     width management is handled by this class.
129 :    
130 :     The general code for creating the form should be
131 :    
132 :     sub Form {
133 :     my ($self) = @_;
134 :     # Get the CGI object.
135 :     my $cgi = @self->Q();
136 :     # Start the form.
137 :     my $retVal = $self->FormStart("form title");
138 :     # Assemble the table rows.
139 :     my @rows = ();
140 :     ... push table row Html into @rows ...
141 :     push @rows, $self->SubmitRow();
142 :     ... push more Html into @rows ...
143 :     # Build the table from the rows.
144 :     $retVal .= $self->MakeTable(\@rows);
145 :     # Close the form.
146 :     $retVal .= $self->FormEnd();
147 :     # Return the form Html.
148 :     return $retVal;
149 :     }
150 :    
151 :     Several helper methods are provided for particular purposes.
152 :    
153 :     =over 4
154 :    
155 :     =item 1
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 :     =item 2
164 :    
165 :     L</FeatureFilterRow> formats several rows of controls for filtering features.
166 :     When you start building the code for the L</Find> method, you can use a
167 :     B<FeatureQuery> object to automatically filter each genome's features using
168 :     the values from the filter controls.
169 :    
170 :     =item 3
171 :    
172 :     L</QueueFormScript> allows you to queue JavaScript statements for execution
173 :     after the form is fully generated. If you are using very complicated
174 :     form controls, the L</QueueFormScript> method allows you to perform
175 :     JavaScript initialization. The L</NmpdrGenomeMenu> control uses this
176 :     facility to display a list of the pre-selected genomes.
177 :    
178 :     =back
179 :    
180 :     Finally, when generating the code for your controls, be sure to use any incoming
181 :     query parameters as default values so that the search request is persistent.
182 :    
183 :     =head3 Finding Search Results
184 :    
185 :     The L</Find> method is used to create the search results. For a search that
186 :     wants to return features (which is most of them), the basic code structure
187 :     would work as follows. It is assumed that the L</FeatureFilterRows> method
188 :     has been used to create feature filtering parameters.
189 :    
190 :     sub Find {
191 :     my ($self) = @_;
192 :     # Get the CGI and Sprout objects.
193 :     my $cgi = $self->Q();
194 :     my $sprout = $self->DB();
195 :     # Declare the return variable. If it remains undefined, the caller will
196 :     # know that an error occurred.
197 :     my $retVal;
198 :     ... validate the parameters ...
199 :     if (... invalid parameters...) {
200 :     $self->SetMessage(...appropriate message...);
201 :     } elsif (FeatureQuery::Valid($self)) {
202 :     # Initialize the session file.
203 :     $self->OpenSession();
204 :     # Initialize the result counter.
205 :     $retVal = 0;
206 :     ... get a list of genomes ...
207 :     for my $genomeID (... each genome ...) {
208 :     my $fq = FeatureQuery->new($self, $genomeID);
209 :     while (my $feature = $fq->Fetch()) {
210 :     ... examine the feature ...
211 :     if (... we want to keep it ...) {
212 :     $self->PutFeature($fq);
213 :     $retVal++;
214 :     }
215 :     }
216 :     }
217 :     }
218 :     # Close the session file.
219 :     $self->CloseSession();
220 :     # Return the result count.
221 :     return $retVal;
222 :     }
223 :    
224 :     A Find method is of course much more complicated than generating a form, and there
225 :     are variations on the above them. For example, you could eschew feature filtering
226 :     entirely in favor of your own custom filtering, you could include extra columns
227 :     in the output, or you could search for something that's not a feature at all. The
228 :     above code is just a loose framework.
229 :    
230 :     If you wish to add your own extra columns to the output, use the B<AddExtraColumns>
231 :     method of the feature query object.
232 :    
233 :     $fq->AddExtraColumns(score => $sc);
234 :    
235 :     The L</Find> method must return C<undef> if the search parameters are invalid. If this
236 :     is the case, then a message describing the problem should be passed to the framework
237 :     by calling L</SetMessage>. If the parameters are valid, then the method must return
238 :     the number of items found.
239 :    
240 :     =head2 Virtual Methods
241 :    
242 :     =head3 Form
243 :    
244 :     C<< my $html = $shelp->Form(); >>
245 :    
246 :     Generate the HTML for a form to request a new search.
247 :    
248 :     =head3 Find
249 :    
250 :     C<< my $resultCount = $shelp->Find(); >>
251 :    
252 :     Conduct a search based on the current CGI query parameters. The search results will
253 :     be written to the session cache file and the number of results will be
254 :     returned. If the search parameters are invalid, a result count of C<undef> will be
255 :     returned and a result message will be stored in this object describing the problem.
256 :    
257 :     =head3 Description
258 :    
259 :     C<< my $htmlText = $shelp->Description(); >>
260 :    
261 :     Return a description of this search. The description is used for the table of contents
262 :     on the main search tools page. It may contain HTML, but it should be character-level,
263 :     not block-level, since the description is going to appear in a list.
264 :    
265 : parrello 1.1 =cut
266 :    
267 :     # This counter is used to insure every form on the page has a unique name.
268 :     my $formCount = 0;
269 :    
270 :     =head2 Public Methods
271 :    
272 :     =head3 new
273 :    
274 :     C<< my $shelp = SearchHelper->new($query); >>
275 :    
276 :     Construct a new SearchHelper object.
277 :    
278 :     =over 4
279 :    
280 :     =item query
281 :    
282 :     The CGI query object for the current script.
283 :    
284 :     =back
285 :    
286 :     =cut
287 :    
288 :     sub new {
289 :     # Get the parameters.
290 :     my ($class, $query) = @_;
291 :     # Check for a session ID.
292 :     my $session_id = $query->param("SessionID");
293 :     my $type = "old";
294 :     if (! $session_id) {
295 :     # Here we're starting a new session. We create the session ID and
296 :     # store it in the query object.
297 :     $session_id = NewSessionID();
298 :     $type = "new";
299 :     $query->param(-name => 'SessionID', -value => $session_id);
300 :     }
301 :     # Compute the subclass name.
302 :     $class =~ /SH(.+)$/;
303 :     my $subClass = $1;
304 :     # Insure everybody knows we're in Sprout mode.
305 :     $query->param(-name => 'SPROUT', -value => 1);
306 :     # Generate the form name.
307 :     my $formName = "$class$formCount";
308 :     $formCount++;
309 :     # Create the shelp object. It contains the query object (with the session ID)
310 :     # as well as an indicator as to whether or not the session is new, plus the
311 : parrello 1.2 # class name and a placeholder for the Sprout object.
312 : parrello 1.1 my $retVal = {
313 :     query => $query,
314 :     type => $type,
315 :     class => $subClass,
316 : parrello 1.2 sprout => undef,
317 : parrello 1.1 orgs => {},
318 :     name => $formName,
319 :     scriptQueue => [],
320 : parrello 1.3 genomeList => undef,
321 :     genomeParms => [],
322 :     filtered => 0,
323 : parrello 1.1 };
324 :     # Bless and return it.
325 :     bless $retVal, $class;
326 :     return $retVal;
327 :     }
328 :    
329 :     =head3 Q
330 :    
331 :     C<< my $query = $shelp->Q(); >>
332 :    
333 :     Return the CGI query object.
334 :    
335 :     =cut
336 :    
337 :     sub Q {
338 :     # Get the parameters.
339 :     my ($self) = @_;
340 :     # Return the result.
341 :     return $self->{query};
342 :     }
343 :    
344 :     =head3 DB
345 :    
346 :     C<< my $sprout = $shelp->DB(); >>
347 :    
348 :     Return the Sprout database object.
349 :    
350 :     =cut
351 :    
352 :     sub DB {
353 :     # Get the parameters.
354 :     my ($self) = @_;
355 : parrello 1.2 # Insure we have a database.
356 :     my $retVal = $self->{sprout};
357 :     if (! defined $retVal) {
358 :     $retVal = SFXlate->new_sprout_only();
359 :     $self->{sprout} = $retVal;
360 :     }
361 : parrello 1.1 # Return the result.
362 : parrello 1.2 return $retVal;
363 : parrello 1.1 }
364 :    
365 :     =head3 IsNew
366 :    
367 :     C<< my $flag = $shelp->IsNew(); >>
368 :    
369 :     Return TRUE if this is a new session, FALSE if this is an old session. An old
370 :     session already has search results ready to process.
371 :    
372 :     =cut
373 :    
374 :     sub IsNew {
375 :     # Get the parameters.
376 :     my ($self) = @_;
377 :     # Return the result.
378 :     return ($self->{type} eq 'new');
379 :     }
380 :    
381 :     =head3 ID
382 :    
383 :     C<< my $sessionID = $shelp->ID(); >>
384 :    
385 :     Return the current session ID.
386 :    
387 :     =cut
388 :    
389 :     sub ID {
390 :     # Get the parameters.
391 :     my ($self) = @_;
392 :     # Return the result.
393 :     return $self->Q()->param("SessionID");
394 :     }
395 :    
396 :     =head3 FormName
397 :    
398 :     C<< my $name = $shelp->FormName(); >>
399 :    
400 :     Return the name of the form this helper object will generate.
401 :    
402 :     =cut
403 :    
404 :     sub FormName {
405 :     # Get the parameters.
406 :     my ($self) = @_;
407 :     # Return the result.
408 :     return $self->{name};
409 :     }
410 :    
411 :     =head3 QueueFormScript
412 :    
413 :     C<< $shelp->QueueFormScript($statement); >>
414 :    
415 :     Add the specified statement to the queue of JavaScript statements that are to be
416 :     executed when the form has been fully defined. This is necessary because until
417 :     the closing </FORM> tag is emitted, the form elements cannot be referenced by
418 :     name. When generating the statement, you can refer to the variable C<thisForm>
419 :     in order to reference the form in progress. Thus,
420 :    
421 :     thisForm.simLimit.value = 1e-10;
422 :    
423 :     would set the value of the form element C<simLimit> in the current form to
424 :     C<1e-10>.
425 :    
426 :     =over 4
427 :    
428 :     =item statement
429 :    
430 :     JavaScript statement to be queued for execution after the form is built.
431 :     The trailing semi-colon is required. Theoretically, you could include
432 :     multiple statements separated by semi-colons, but one at a time works
433 :     just as well.
434 :    
435 :     =back
436 :    
437 :     =cut
438 :    
439 :     sub QueueFormScript {
440 :     # Get the parameters.
441 :     my ($self, $statement) = @_;
442 :     # Push the statement onto the script queue.
443 :     push @{$self->{scriptQueue}}, $statement;
444 :     }
445 :    
446 :     =head3 FormStart
447 :    
448 :     C<< my $html = $shelp->FormStart($title); >>
449 :    
450 :     Return the initial section of a form designed to perform another search of the
451 :     same type. The form header is included along with hidden fields to persist the
452 :     tracing, sprout status, and search class.
453 :    
454 :     A call to L</FormEnd> is required to close the form.
455 :    
456 :     =over 4
457 :    
458 :     =item title
459 :    
460 :     Title to be used for the form.
461 :    
462 :     =item RETURN
463 :    
464 :     Returns the initial HTML for the search form.
465 :    
466 :     =back
467 :    
468 :     =cut
469 :    
470 :     sub FormStart {
471 :     # Get the parameters.
472 :     my ($self, $title) = @_;
473 :     # Get the CGI object.
474 :     my $cgi = $self->Q();
475 :     # Start the form.
476 :     my $retVal = "<div class=\"search\">\n" .
477 :     $cgi->start_form(-method => 'POST',
478 :     -action => $cgi->url(-relative => 1),
479 :     -name => $self->FormName()) .
480 :     $cgi->hidden(-name => 'Class',
481 :     -value => $self->{class}) .
482 :     $cgi->hidden(-name => 'SPROUT',
483 :     -value => 1) .
484 :     $cgi->h3($title);
485 :     # If tracing is on, add it to the form.
486 :     if ($cgi->param('Trace')) {
487 :     $retVal .= $cgi->hidden(-name => 'Trace',
488 :     -value => $cgi->param('Trace')) .
489 :     $cgi->hidden(-name => 'TF',
490 :     -value => ($cgi->param('TF') ? 1 : 0));
491 :     }
492 :     # Put in an anchor tag in case there's a table of contents.
493 :     my $anchorName = $self->FormName();
494 :     $retVal .= "<a name=\"$anchorName\"></a>\n";
495 :     # Return the result.
496 :     return $retVal;
497 :     }
498 :    
499 :     =head3 FormEnd
500 :    
501 :     C<< my $htmlText = $shelp->FormEnd(); >>
502 :    
503 :     Return the HTML text for closing a search form. This closes both the C<form> and
504 :     C<div> tags.
505 :    
506 :     =cut
507 :    
508 :     sub FormEnd {
509 :     # Get the parameters.
510 :     my ($self) = @_;
511 :     # Declare the return variable, closing the form and the DIV block.
512 :     my $retVal = "</form></div>\n";
513 :     # Now we flush out the statement queue.
514 :     my @statements = @{$self->{scriptQueue}};
515 :     if (@statements > 0) {
516 :     # Switch to JavaScript and set the "thisForm" variable.
517 :     $retVal .= "<SCRIPT language=\"JavaScript\">\n" .
518 :     " thisForm = document.$self->{name};\n";
519 :     # Unroll the statements.
520 :     while (@statements > 0) {
521 :     my $statement = shift @statements;
522 :     $retVal .= " $statement\n";
523 :     }
524 :     # Close the JavaScript.
525 :     $retVal .= "</SCRIPT>\n";
526 :     }
527 :     # Return the result.
528 :     return $retVal;
529 :     }
530 :    
531 :     =head3 SetMessage
532 :    
533 :     C<< $shelp->SetMessage($msg); >>
534 :    
535 :     Store the specified text as the result message. The result message is displayed
536 :     if an invalid parameter value is specified.
537 :    
538 :     =over 4
539 :    
540 :     =item msg
541 :    
542 :     Text of the result message to be displayed.
543 :    
544 :     =back
545 :    
546 :     =cut
547 :    
548 :     sub SetMessage {
549 :     # Get the parameters.
550 :     my ($self, $msg) = @_;
551 :     # Store the message.
552 :     $self->{message} = $msg;
553 :     }
554 :    
555 :     =head3 Message
556 :    
557 :     C<< my $text = $shelp->Message(); >>
558 :    
559 :     Return the result message. The result message is displayed if an invalid parameter
560 :     value is specified.
561 :    
562 :     =cut
563 :    
564 :     sub Message {
565 :     # Get the parameters.
566 :     my ($self) = @_;
567 :     # Return the result.
568 :     return $self->{message};
569 :     }
570 :    
571 :     =head3 OpenSession
572 :    
573 :     C<< $shelp->OpenSession(); >>
574 :    
575 :     Set up to open the session cache file for writing. Note we don't actually
576 :     open the file until after we know the column headers.
577 :    
578 :     =cut
579 :    
580 :     sub OpenSession {
581 :     # Get the parameters.
582 :     my ($self) = @_;
583 :     # Denote we have not yet written out the column headers.
584 :     $self->{cols} = undef;
585 :     }
586 :    
587 :     =head3 GetCacheFileName
588 :    
589 :     C<< my $fileName = $shelp->GetCacheFileName(); >>
590 :    
591 :     Return the name to be used for this session's cache file.
592 :    
593 :     =cut
594 :    
595 :     sub GetCacheFileName {
596 :     # Get the parameters.
597 :     my ($self) = @_;
598 :     # Return the result.
599 :     return $self->GetTempFileName('cache');
600 :     }
601 :    
602 :     =head3 GetTempFileName
603 :    
604 :     C<< my $fileName = $shelp->GetTempFileName($type); >>
605 :    
606 :     Return the name to be used for a temporary file of the specified type. The
607 :     name is computed from the session name with the type as a suffix.
608 :    
609 :     =over 4
610 :    
611 :     =item type
612 :    
613 :     Type of temporary file to be generated.
614 :    
615 :     =item RETURN
616 :    
617 :     Returns a file name generated from the session name and the specified type.
618 :    
619 :     =back
620 :    
621 :     =cut
622 :    
623 :     sub GetTempFileName {
624 :     # Get the parameters.
625 :     my ($self, $type) = @_;
626 :     # Compute the file name. Note it gets stuffed in the FIG temporary
627 :     # directory.
628 :     my $retVal = "$FIG_Config::temp/tmp_" . $self->ID() . ".$type";
629 :     # Return the result.
630 :     return $retVal;
631 :     }
632 :    
633 :     =head3 PutFeature
634 :    
635 : parrello 1.2 C<< $shelp->PutFeature($fquery); >>
636 : parrello 1.1
637 :     Store a feature in the result cache. This is the workhorse method for most
638 :     searches, since the primary data item in the database is features.
639 :    
640 :     For each feature, there are certain columns that are standard: the feature name, the
641 :     GBrowse and protein page links, the functional assignment, and so forth. If additional
642 : parrello 1.2 columns are required by a particular search subclass, they should be stored in
643 :     the feature query object using the B<AddExtraColumns> method. For example, the following
644 :     code adds columns for essentiality and virulence.
645 : parrello 1.1
646 : parrello 1.2 $fq->AddExtraColumns(essential => $essentialFlag, virulence => $vfactor);
647 :     $shelp->PutFeature($fq);
648 : parrello 1.1
649 :     For correct results, all values should be specified for all extra columns in all calls to
650 :     B<PutFeature>. (In particular, the column header names are computed on the first
651 :     call.) If a column is to be blank for the current feature, its value can be given
652 :     as C<undef>.
653 :    
654 :     if (! $essentialFlag) {
655 :     $essentialFlag = undef;
656 :     }
657 : parrello 1.2 $fq->AddExtraColumns(essential => $essentialFlag, virulence => $vfactor);
658 :     $shelp->PutFeature($fq);
659 : parrello 1.1
660 :     =over 4
661 :    
662 : parrello 1.2 =item fquery
663 : parrello 1.1
664 : parrello 1.2 FeatureQuery object containing the current feature data.
665 : parrello 1.1
666 :     =back
667 :    
668 :     =cut
669 :    
670 :     sub PutFeature {
671 : parrello 1.2 # Get the parameters.
672 :     my ($self, $fq) = @_;
673 : parrello 1.3 # Get the CGI query object.
674 :     my $cgi = $self->Q();
675 : parrello 1.2 # Get the feature data.
676 :     my $record = $fq->Feature();
677 :     my $extraCols = $fq->ExtraCols();
678 : parrello 1.1 # Check for a first-call situation.
679 :     if (! defined $self->{cols}) {
680 :     # Here we need to set up the column information. Start with the defaults.
681 :     $self->{cols} = $self->DefaultFeatureColumns();
682 : parrello 1.3 # Add the externals if they were requested.
683 :     if ($cgi->param('ShowAliases')) {
684 :     push @{$self->{cols}}, 'alias';
685 :     }
686 : parrello 1.2 # Append the extras, sorted by column name.
687 :     for my $col (sort keys %{$extraCols}) {
688 :     push @{$self->{cols}}, "X=$col";
689 : parrello 1.1 }
690 :     # Write out the column headers. This also prepares the cache file to receive
691 :     # output.
692 :     $self->WriteColumnHeaders(map { $self->FeatureColumnTitle($_) } @{$self->{cols}});
693 :     }
694 :     # Get the feature ID.
695 :     my ($fid) = $record->Value('Feature(id)');
696 :     # Loop through the column headers, producing the desired data.
697 :     my @output = ();
698 :     for my $colName (@{$self->{cols}}) {
699 : parrello 1.2 push @output, $self->FeatureColumnValue($colName, $record, $extraCols);
700 : parrello 1.1 }
701 :     # Compute the sort key. The sort key floats NMPDR organism features to the
702 :     # top of the return list.
703 :     my $group = $self->FeatureGroup($fid);
704 :     my $key = ($group ? "A$group" : "ZZ");
705 :     # Write the feature data.
706 :     $self->WriteColumnData($key, @output);
707 :     }
708 :    
709 :     =head3 WriteColumnHeaders
710 :    
711 :     C<< $shelp->WriteColumnHeaders(@colNames); >>
712 :    
713 :     Write out the column headers for the current search session. The column headers
714 :     are sent to the cache file, and then the cache is re-opened as a sort pipe and
715 :     the handle saved.
716 :    
717 :     =over 4
718 :    
719 :     =item colNames
720 :    
721 :     A list of column names in the desired presentation order.
722 :    
723 :     =back
724 :    
725 :     =cut
726 :    
727 :     sub WriteColumnHeaders {
728 :     # Get the parameters.
729 :     my ($self, @colNames) = @_;
730 :     # Get the cache file name and open it for output.
731 :     my $fileName = $self->GetCacheFileName();
732 :     my $handle1 = Open(undef, ">$fileName");
733 :     # Write the column headers and close the file.
734 :     Tracer::PutLine($handle1, \@colNames);
735 :     close $handle1;
736 :     # Now open the sort pipe and save the file handle. Note how we append the
737 :     # sorted data to the column header row already in place. The output will
738 :     # contain a sort key followed by the real columns. The sort key is
739 :     # hacked off before going to the output file.
740 :     $self->{fileHandle} = Open(undef, "| sort | cut --fields=2- >>$fileName");
741 :     }
742 :    
743 :     =head3 WriteColumnData
744 :    
745 :     C<< $shelp->WriteColumnData($key, @colValues); >>
746 :    
747 :     Write a row of column values to the current search session. It is assumed that
748 :     the session file is already open for output.
749 :    
750 :     =over 4
751 :    
752 :     =item key
753 :    
754 :     Sort key.
755 :    
756 :     =item colValues
757 :    
758 :     List of column values to write to the search result cache file for this session.
759 :    
760 :     =back
761 :    
762 :     =cut
763 :    
764 :     sub WriteColumnData {
765 :     # Get the parameters.
766 :     my ($self, $key, @colValues) = @_;
767 :     # Write them to the cache file.
768 :     Tracer::PutLine($self->{fileHandle}, [$key, @colValues]);
769 :     }
770 :    
771 :     =head3 CloseSession
772 :    
773 :     C<< $shelp->CloseSession(); >>
774 :    
775 :     Close the session file.
776 :    
777 :     =cut
778 :    
779 :     sub CloseSession {
780 :     # Get the parameters.
781 :     my ($self) = @_;
782 :     # Check for an open session file.
783 :     if (defined $self->{fileHandle}) {
784 :     # We found one, so close it.
785 :     close $self->{fileHandle};
786 :     }
787 :     }
788 :    
789 :     =head3 NewSessionID
790 :    
791 :     C<< my $id = SearchHelpers::NewSessionID(); >>
792 :    
793 :     Generate a new session ID for the current user.
794 :    
795 :     =cut
796 :    
797 :     sub NewSessionID {
798 :     # Declare the return variable.
799 :     my $retVal;
800 :     # Get a digest encoder.
801 :     my $md5 = Digest::MD5->new();
802 :     # If we have a randomization file, use it to seed the digester.
803 :     if (open(R, "/dev/urandom")) {
804 :     my $b;
805 :     read(R, $b, 1024);
806 :     $md5->add($b);
807 :     }
808 :     # Add the PID and the time stamp.
809 :     $md5->add($$, gettimeofday);
810 :     # Hash it up and clean the result so that it works as a file name.
811 :     $retVal = $md5->b64digest();
812 :     $retVal =~ s,/,\$,g;
813 :     $retVal =~ s,\+,@,g;
814 :     # Return it.
815 :     return $retVal;
816 :     }
817 :    
818 :     =head3 OrganismData
819 :    
820 :     C<< my ($orgName, $group) = $shelp->Organism($genomeID); >>
821 :    
822 :     Return the name and status of the organism corresponding to the specified genome ID.
823 :     For performance reasons, this information is cached in a special hash table, so we
824 :     only compute it once per run.
825 :    
826 :     =over 4
827 :    
828 :     =item genomeID
829 :    
830 :     ID of the genome whose name is desired.
831 :    
832 :     =item RETURN
833 :    
834 :     Returns a list of two items. The first item in the list is the organism name,
835 :     and the second is the name of the NMPDR group, or an empty string if the
836 :     organism is not in an NMPDR group.
837 :    
838 :     =back
839 :    
840 :     =cut
841 :    
842 :     sub OrganismData {
843 :     # Get the parameters.
844 :     my ($self, $genomeID) = @_;
845 :     # Declare the return variables.
846 :     my ($orgName, $group);
847 :     # Check the cache.
848 :     my $cache = $self->{orgs};
849 :     if (exists $cache->{$genomeID}) {
850 :     ($orgName, $group) = @{$cache->{$genomeID}};
851 :     } else {
852 :     # Here we have to use the database.
853 :     my $sprout = $self->DB();
854 :     my ($genus, $species, $strain, $group) = $sprout->GetEntityValues('Genome', $genomeID,
855 :     ['Genome(genus)', 'Genome(species)',
856 :     'Genome(unique-characterization)',
857 :     'Genome(primary-group)']);
858 :     # Null out the supporting group.
859 :     $group = "" if ($group eq $FIG_Config::otherGroup);
860 :     # If the organism does not exist, format an unknown name.
861 :     if (! defined($genus)) {
862 :     $orgName = "Unknown Genome $genomeID";
863 :     } else {
864 :     # It does exist, so format the organism name.
865 :     $orgName = "$genus $species";
866 :     if ($strain) {
867 :     $orgName .= " $strain";
868 :     }
869 :     }
870 :     # Save this organism in the cache.
871 :     $cache->{$genomeID} = [$orgName, $group];
872 :     }
873 :     # Return the result.
874 :     return ($orgName, $group);
875 :     }
876 :    
877 :     =head3 Organism
878 :    
879 :     C<< my $orgName = $shelp->Organism($genomeID); >>
880 :    
881 :     Return the name of the relevant organism. The name is computed from the genus,
882 :     species, and unique characterization. A cache is used to improve performance.
883 :    
884 :     =over 4
885 :    
886 :     =item genomeID
887 :    
888 :     ID of the genome whose name is desired.
889 :    
890 :     =item RETURN
891 :    
892 :     Returns the display name of the specified organism.
893 :    
894 :     =back
895 :    
896 :     =cut
897 :    
898 :     sub Organism {
899 :     # Get the parameters.
900 :     my ($self, $genomeID) = @_;
901 :     # Get the organism data.
902 :     my ($retVal, $group) = $self->OrganismData($genomeID);
903 :     # Return the result.
904 :     return $retVal;
905 :     }
906 :    
907 :     =head3 FeatureGroup
908 :    
909 :     C<< my $groupName = $shelp->FeatureGroup($fid); >>
910 :    
911 :     Return the group name for the specified feature.
912 :    
913 :     =over 4
914 :    
915 :     =item fid
916 :    
917 :     ID of the relevant feature.
918 :    
919 :     =item RETURN
920 :    
921 :     Returns the name of the NMPDR group to which the feature belongs, or an empty
922 :     string if it is not part of an NMPDR group.
923 :    
924 :     =back
925 :    
926 :     =cut
927 :    
928 :     sub FeatureGroup {
929 :     # Get the parameters.
930 :     my ($self, $fid) = @_;
931 :     # Parse the feature ID to get the genome ID.
932 :     my ($genomeID) = FIGRules::ParseFeatureID($fid);
933 :     # Get the organism data.
934 :     my (undef, $retVal) = $self->OrganismData($genomeID);
935 :     # Return the result.
936 :     return $retVal;
937 :     }
938 :    
939 :     =head3 FeatureName
940 :    
941 :     C<< my $fidName = $shelp->FeatureName($fid); >>
942 :    
943 :     Return the display name of the specified feature.
944 :    
945 :     =over 4
946 :    
947 :     =item fid
948 :    
949 :     ID of the feature whose name is desired.
950 :    
951 :     =item RETURN
952 :    
953 :     A displayable feature name, consisting of the organism name plus some feature
954 :     type and location information.
955 :    
956 :     =back
957 :    
958 :     =cut
959 :    
960 :     sub FeatureName {
961 :     # Get the parameters.
962 :     my ($self, $fid) = @_;
963 :     # Declare the return variable
964 :     my $retVal;
965 :     # Parse the feature ID.
966 :     my ($genomeID, $type, $num) = FIGRules::ParseFeatureID($fid);
967 :     if (! defined $genomeID) {
968 :     # Here the feature ID has an invalid format.
969 :     $retVal = "External: $fid";
970 :     } else {
971 :     # Here we can get its genome data.
972 :     $retVal = $self->Organism($genomeID);
973 :     # Append the type and number.
974 :     $retVal .= " [$type $num]";
975 :     }
976 :     # Return the result.
977 :     return $retVal;
978 :     }
979 :    
980 :     =head3 ComputeFASTA
981 :    
982 :     C<< my $fasta = $shelp->ComputeFASTA($incomingType, $desiredType, $sequence); >>
983 :    
984 :     Parse a sequence input and convert it into a FASTA string of the desired type. Note
985 :     that it is possible to convert a DNA sequence into a protein sequence, but the reverse
986 :     is not possible.
987 :    
988 :     =over 4
989 :    
990 :     =item incomingType
991 :    
992 :     C<dna> if this is a DNA sequence, C<prot> if this is a protein sequence.
993 :    
994 :     =item desiredType
995 :    
996 :     C<dna> to return a DNA sequence, C<prot> to return a protein sequence. If the
997 :     I<$incomingType> is C<prot> and this value is C<dna>, an error will be thrown.
998 :    
999 :     =item sequence
1000 :    
1001 :     Sequence to return. It may be a DNA or protein sequence in FASTA form or a feature ID.
1002 :     If a feature ID is specified, the feature's DNA or translation will be returned. The
1003 :     feature ID is recognized by the presence of a vertical bar in the input. Otherwise,
1004 :     if the input does not begin with a greater-than sign (FASTA label line), a default label
1005 :     line will be provided.
1006 :    
1007 :     =item RETURN
1008 :    
1009 :     Returns a string in FASTA format representing the content of the desired sequence with
1010 :     an appropriate label. If the input is invalid, a message will be stored and we will
1011 :     return C<undef>. Note that the output will include a trailing new-line.
1012 :    
1013 :     =back
1014 :    
1015 :     =cut
1016 :    
1017 :     sub ComputeFASTA {
1018 :     # Get the parameters.
1019 :     my ($self, $incomingType, $desiredType, $sequence) = @_;
1020 :     # Declare the return variable. If an error occurs, it will remain undefined.
1021 :     my $retVal;
1022 :     # Create variables to hold the FASTA label and data.
1023 :     my ($fastaLabel, $fastaData);
1024 :     # Check for a feature specification.
1025 :     if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {
1026 :     # Here we have a feature ID in $1. We'll need the Sprout object to process
1027 :     # it.
1028 :     my $fid = $1;
1029 :     my $sprout = $self->DB();
1030 :     # Get the FIG ID. Note that we only use the first feature found. We are not
1031 :     # supposed to have redundant aliases, though we may have an ID that doesn't
1032 :     # exist.
1033 :     my ($figID) = $sprout->FeaturesByAlias($fid);
1034 :     if (! $figID) {
1035 :     $self->SetMessage("No feature found with the ID \"$fid\".");
1036 :     } else {
1037 :     # Set the FASTA label.
1038 :     my $fastaLabel = $fid;
1039 :     # Now proceed according to the sequence type.
1040 :     if ($desiredType =~ /prot/i) {
1041 :     # We want protein, so get the translation.
1042 :     $fastaData = $sprout->FeatureTranslation($figID);
1043 :     } else {
1044 :     # We want DNA, so get the DNA sequence. This is a two-step process.
1045 :     my @locList = $sprout->FeatureLocation($figID);
1046 :     $fastaData = $sprout->DNASeq(\@locList);
1047 :     }
1048 :     }
1049 :     } elsif ($incomingType =~ /prot/ && $desiredType =~ /dna/) {
1050 :     # Here we're being asked to do an impossible conversion.
1051 :     $self->SetMessage("Cannot convert a protein sequence to DNA.");
1052 :     } else {
1053 :     # Here we are expecting a FASTA. We need to see if there's a label.
1054 :     if ($sequence =~ /^>\s*(\S.*)\s*\n(.+)$/) {
1055 :     # Here we have a label, so we split it from the data.
1056 :     $fastaLabel = $1;
1057 :     $fastaData = $2;
1058 :     } else {
1059 :     # Here we have no label, so we create one and use the entire sequence
1060 :     # as data.
1061 :     $fastaLabel = "User-specified $incomingType sequence";
1062 :     $fastaData = $sequence;
1063 :     }
1064 :     # The next step is to clean the junk out of the sequence.
1065 :     $fastaData =~ s/\n//g;
1066 :     $fastaData =~ s/\s+//g;
1067 :     # Finally, if the user wants to convert to protein, we do it here. Note that
1068 :     # we've already prevented a conversion from protein to DNA.
1069 :     if ($incomingType ne $desiredType) {
1070 :     $fastaData = Sprout::Protein($fastaData);
1071 :     }
1072 :     }
1073 :     # At this point, either "$fastaLabel" and "$fastaData" have values or an error is
1074 :     # in progress.
1075 :     if (defined $fastaLabel) {
1076 :     # We need to format the sequence into 60-byte chunks. We use the infamous
1077 :     # grep-split trick. The split, because of the presence of the parentheses,
1078 :     # includes the matched delimiters in the output list. The grep strips out
1079 :     # the empty list items that appear between the so-called delimiters, since
1080 :     # the delimiters are what we want.
1081 :     my @chunks = grep { $_ } split /(.{1,60})/, $fastaData;
1082 :     my $retVal = join("\n", ">$fastaLabel", @chunks, "");
1083 :     }
1084 :     # Return the result.
1085 :     return $retVal;
1086 :     }
1087 :    
1088 :     =head3 NmpdrGenomeMenu
1089 :    
1090 : parrello 1.3 C<< my $htmlText = $shelp->NmpdrGenomeMenu($menuName, $multiple, \@selected, $rows); >>
1091 : parrello 1.1
1092 :     This method creates a hierarchical HTML menu for NMPDR genomes organized by category. The
1093 :     category indicates the low-level NMPDR group. Organizing the genomes in this way makes it
1094 :     easier to select all genomes from a particular category.
1095 :    
1096 :     =over 4
1097 :    
1098 :     =item menuName
1099 :    
1100 :     Name to give to the menu.
1101 :    
1102 : parrello 1.3 =item multiple
1103 : parrello 1.1
1104 : parrello 1.3 TRUE if the user is allowed to select multiple genomes, else FALSE.
1105 : parrello 1.1
1106 :     =item selected
1107 :    
1108 :     Reference to a list containing the IDs of the genomes to be pre-selected. If the menu
1109 :     is not intended to allow multiple selections, the list should be a singleton. If the
1110 :     list is empty, nothing will be pre-selected.
1111 :    
1112 : parrello 1.3 =item rows (optional)
1113 :    
1114 :     Number of rows to display. If omitted, the default is 1 for a single-select list
1115 :     and 10 for a multi-select list.
1116 :    
1117 : parrello 1.1 =item RETURN
1118 :    
1119 :     Returns the HTML text to generate a C<SELECT> menu inside a form.
1120 :    
1121 :     =back
1122 :    
1123 :     =cut
1124 :    
1125 :     sub NmpdrGenomeMenu {
1126 :     # Get the parameters.
1127 : parrello 1.3 my ($self, $menuName, $multiple, $selected, $rows) = @_;
1128 : parrello 1.1 # Get the Sprout and CGI objects.
1129 :     my $sprout = $self->DB();
1130 :     my $cgi = $self->Q();
1131 : parrello 1.3 # Compute the row count.
1132 :     if (! defined $rows) {
1133 :     $rows = ($multiple ? 10 : 1);
1134 :     }
1135 :     # Create the multiple tag.
1136 :     my $multipleTag = ($multiple ? " multiple" : "");
1137 : parrello 1.1 # Get the form name.
1138 :     my $formName = $self->FormName();
1139 : parrello 1.3 # Check to see if we already have a genome list in memory.
1140 :     my $genomes = $self->{genomeList};
1141 :     my $groupHash;
1142 :     if (defined $genomes) {
1143 :     # We have a list ready to use.
1144 :     $groupHash = $genomes;
1145 :     } else {
1146 :     # Get a list of all the genomes in group order. In fact, we only need them ordered
1147 :     # by name (genus,species,strain), but putting primary-group in front enables us to
1148 :     # take advantage of an existing index.
1149 :     my @genomeList = $sprout->GetAll(['Genome'],
1150 :     "ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
1151 :     [], ['Genome(primary-group)', 'Genome(id)',
1152 :     'Genome(genus)', 'Genome(species)',
1153 :     'Genome(unique-characterization)']);
1154 :     # Create a hash to organize the genomes by group. Each group will contain a list of
1155 :     # 2-tuples, the first element being the genome ID and the second being the genome
1156 :     # name.
1157 :     my %gHash = ();
1158 :     for my $genome (@genomeList) {
1159 :     # Get the genome data.
1160 :     my ($group, $genomeID, $genus, $species, $strain) = @{$genome};
1161 :     # Form the genome name.
1162 :     my $name = "$genus $species";
1163 :     if ($strain) {
1164 :     $name .= " $strain";
1165 :     }
1166 :     # Push the genome into the group's list.
1167 :     push @{$gHash{$group}}, [$genomeID, $name];
1168 : parrello 1.1 }
1169 : parrello 1.3 # Save the genome list for future use.
1170 :     $self->{genomeList} = \%gHash;
1171 :     $groupHash = \%gHash;
1172 : parrello 1.1 }
1173 :     # Now we are ready to unroll the menu out of the group hash. First, we sort the groups, putting
1174 :     # the supporting-genome group last.
1175 : parrello 1.3 my @groups = sort grep { $_ ne $FIG_Config::otherGroup } keys %{$groupHash};
1176 : parrello 1.1 push @groups, $FIG_Config::otherGroup;
1177 : parrello 1.3 # Next, create a hash that specifies the pre-selected entries. Note that we need to deal
1178 :     # with the possibility of undefined values in the incoming list.
1179 :     my %selectedHash = ();
1180 :     if (defined $selected) {
1181 :     %selectedHash = map { $_ => 1 } grep { defined($_) } @{$selected};
1182 :     }
1183 : parrello 1.1 # Now it gets complicated. We need a way to mark all the NMPDR genomes.
1184 :     # Create the type counters.
1185 :     my $groupCount = 1;
1186 :     # Compute the ID for the status display.
1187 :     my $divID = "${formName}_${menuName}_status";
1188 :     # Compute the JavaScript call for updating the status.
1189 :     my $showSelect = "showSelected($menuName, '$divID', 1000);";
1190 :     # If multiple selection is supported, create an onChange event.
1191 :     my $onChange = "";
1192 : parrello 1.3 if ($multiple) {
1193 : parrello 1.1 $onChange = " onChange=\"$showSelect\"";
1194 :     }
1195 :     # Create the SELECT tag and stuff it into the output array.
1196 : parrello 1.3 my $select = "<SELECT name=\"$menuName\"$onChange$multipleTag size=\"$rows\">";
1197 : parrello 1.1 my @lines = ($select);
1198 :     # Loop through the groups.
1199 :     for my $group (@groups) {
1200 :     # Create the option group tag.
1201 :     my $tag = "<OPTGROUP label=\"$group\">";
1202 :     push @lines, " $tag";
1203 :     # Compute the label for this group's options. This is seriously dirty stuff, as the
1204 :     # label option may have functionality in future browsers. If that happens, we'll need
1205 :     # to modify the genome text so that the "selectSome" method can tell which are NMPDR
1206 :     # organisms and which aren't. Sadly, the OPTGROUP tag is invisible in the DOM Javascript
1207 : parrello 1.3 # hierarchy, so we can't use it.
1208 : parrello 1.1 my $label = ($group eq $FIG_Config::otherGroup ? "other" : "nmpdr");
1209 :     # Get the genomes in the group.
1210 : parrello 1.3 for my $genome (@{$groupHash->{$group}}) {
1211 : parrello 1.1 my ($genomeID, $name) = @{$genome};
1212 :     # See if it's selected.
1213 :     my $select = ($selectedHash{$genomeID} ? " selected" : "");
1214 :     # Generate the option tag.
1215 :     my $optionTag = "<OPTION value=\"$genomeID\" label=\"$label\"$select>$name <em>($genomeID)</em></OPTION>";
1216 :     push @lines, " $optionTag";
1217 :     }
1218 :     # Close the option group.
1219 :     push @lines, " </OPTGROUP>";
1220 :     }
1221 :     # Close the SELECT tag.
1222 :     push @lines, "</SELECT>";
1223 :     # Check for multiple selection.
1224 : parrello 1.3 if ($multiple) {
1225 :     # Since multi-select is on, we set up some buttons to set and clear selections.
1226 : parrello 1.1 push @lines, "<br />";
1227 :     push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll($menuName); $showSelect\" />";
1228 :     push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\" value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";
1229 :     push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\" value=\"Select NMPDR\" onClick=\"selectSome($menuName, 'nmpdr'); $showSelect\" />";
1230 :     push @lines, "<INPUT type=\"button\" name=\"OtherOnly\" class=\"bigButton\" value=\"Select Supporting\" onClick=\"selectSome($menuName, 'other'); $showSelect\" />";
1231 : parrello 1.3 # Now add the search box. This allows the user to type text and have all genomes containing
1232 :     # the text selected automatically.
1233 :     my $searchThingName = "${menuName}_SearchThing";
1234 :     push @lines, "<br>Select genomes containing <INPUT type=\"text\" name=\"$searchThingName\" size=\"30\" />&nbsp;" .
1235 :     "<INPUT type=\"button\" name=\"Select\" class=\"button\" value=\"Search\" onClick=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />";
1236 : parrello 1.1 # Add the status display, too.
1237 :     push @lines, "<DIV id=\"$divID\" class=\"selectStatus\"></DIV>";
1238 :     # Queue to update the status display when the form loads. We need to modify the show statement
1239 :     # slightly because the queued statements are executed outside the form. This may seem like a lot of
1240 :     # trouble, but we want all of the show statement calls to be generated from a single line of code,
1241 :     # in case we decide to twiddle the parameters.
1242 :     $showSelect =~ s/showSelected\(/showSelected\(thisForm\./;
1243 :     $self->QueueFormScript($showSelect);
1244 : parrello 1.3 # Finally, add this parameter to the list of genome parameters. This enables us to
1245 :     # easily find all the parameters used to select one or more genomes.
1246 :     push @{$self->{genomeParms}}, $menuName;
1247 : parrello 1.1 }
1248 :     # Assemble all the lines into a string.
1249 :     my $retVal = join("\n", @lines, "");
1250 :     # Return the result.
1251 :     return $retVal;
1252 :     }
1253 :    
1254 : parrello 1.3 =head3 PropertyMenu
1255 :    
1256 :     C<< my $htmlText = $shelp->PropertyMenu($menuName, $selected, $force); >>
1257 :    
1258 :     Generate a property name dropdown menu.
1259 :    
1260 :     =over 4
1261 :    
1262 :     =item menuName
1263 :    
1264 :     Name to give to the menu.
1265 :    
1266 :     =item selected
1267 :    
1268 :     Value of the property name to pre-select.
1269 :    
1270 :     =item force (optional)
1271 :    
1272 :     If TRUE, then the user will be forced to choose a property name. If FALSE,
1273 :     then an additional menu choice will be provided to select nothing.
1274 :    
1275 :     =item RETURN
1276 :    
1277 :     Returns a dropdown menu box that allows the user to select a property name. An additional
1278 :     selection entry will be provided for selecting no property name
1279 :    
1280 :     =back
1281 :    
1282 :     =cut
1283 :    
1284 :     sub PropertyMenu {
1285 :     # Get the parameters.
1286 :     my ($self, $menuName, $selected, $force) = @_;
1287 :     # Get the CGI and Sprout objects.
1288 :     my $sprout = $self->DB();
1289 :     my $cgi = $self->Q();
1290 :     # Create the property name list.
1291 :     my @propNames = ();
1292 :     if (! $force) {
1293 :     push @propNames, "";
1294 :     }
1295 :     # Get all the property names, putting them after the null choice if one exists.
1296 :     push @propNames, $sprout->GetChoices('Property', 'property-name');
1297 :     # Create a menu from them.
1298 :     my $retVal = $cgi->popup_menu(-name=> $menuName, -values => \@propNames,
1299 :     -default => $selected);
1300 :     # Return the result.
1301 :     return $retVal;
1302 :     }
1303 :    
1304 : parrello 1.1 =head3 MakeTable
1305 :    
1306 :     C<< my $htmlText = $shelp->MakeTable(\@rows); >>
1307 :    
1308 :     Create a table from a group of table rows. The table rows must be fully pre-formatted: in
1309 :     other words, each must have the TR and TD tags included.
1310 :    
1311 :     The purpose of this method is to provide a uniform look for search form tables. It is
1312 :     almost impossible to control a table using styles, so rather than have a table style,
1313 :     we create the TABLE tag in this method. Note also that the first TD or TH in each row will
1314 :     be updated with an explicit width so the forms look pretty when they are all on one
1315 :     page.
1316 :    
1317 :     =over 4
1318 :    
1319 :     =item rows
1320 :    
1321 :     Reference to a list of table rows. Each table row must be in HTML form with all
1322 :     the TR and TD tags set up. The first TD or TH tag in each row will be modified to
1323 :     set the width. Everything else will be left as is.
1324 :    
1325 :     =item RETURN
1326 :    
1327 :     Returns the full HTML for a table in the approved NMPDR Search Form style.
1328 :    
1329 :     =back
1330 :    
1331 :     =cut
1332 :    
1333 :     sub MakeTable {
1334 :     # Get the parameters.
1335 :     my ($self, $rows) = @_;
1336 :     # Get the CGI object.
1337 :     my $cgi = $self->Q();
1338 :     # Fix the widths on the first column. Note that we eschew the use of the "g"
1339 :     # modifier becase we only want to change the first tag. Also, if a width
1340 :     # is already specified on the first column bad things will happen.
1341 :     for my $row (@{$rows}) {
1342 :     $row =~ s/(<td|th)/$1 width="150"/i;
1343 :     }
1344 :     # Create the table.
1345 :     my $retVal = $cgi->table({border => 2, cellspacing => 2,
1346 :     width => 700, class => 'search'},
1347 :     @{$rows});
1348 :     # Return the result.
1349 :     return $retVal;
1350 :     }
1351 :    
1352 :     =head3 SubmitRow
1353 :    
1354 :     C<< my $htmlText = $shelp->SubmitRow(); >>
1355 :    
1356 :     Returns the HTML text for the row containing the page size control
1357 :     and the submit button. All searches should have this row somewhere
1358 :     near the top of the form.
1359 :    
1360 :     =cut
1361 :    
1362 :     sub SubmitRow {
1363 :     # Get the parameters.
1364 :     my ($self) = @_;
1365 :     my $cgi = $self->Q();
1366 : parrello 1.3 # Get the current page size.
1367 :     my $pageSize = $cgi->param('PageSize');
1368 :     # Get the incoming external-link flag.
1369 :     my $aliases = ($cgi->param('ShowAliases') ? 1 : 0);
1370 :     # Create the row.
1371 : parrello 1.1 my $retVal = $cgi->Tr($cgi->td("Results/Page"),
1372 :     $cgi->td($cgi->popup_menu(-name => 'PageSize',
1373 :     -values => [10, 25, 45, 100, 1000],
1374 : parrello 1.3 -default => $pageSize) . " " .
1375 :     $cgi->checkbox(-name => 'ShowAliases',
1376 :     -value => 1,
1377 :     -label => 'Show Alias Links',
1378 :     -default => $aliases),
1379 :     $cgi->checkbox(-name => 'ShowURL',
1380 :     -value => 1,
1381 :     -label => 'Show URL')),
1382 : parrello 1.1 $cgi->td($cgi->submit(-class => 'goButton',
1383 :     -name => 'Search',
1384 :     -value => 'Go')));
1385 :     # Return the result.
1386 :     return $retVal;
1387 :     }
1388 : parrello 1.2
1389 :     =head3 FeatureFilterRows
1390 :    
1391 :     C<< my $htmlText = $shelp->FeatureFilterRows(); >>
1392 :    
1393 :     This method creates table rows that can be used to filter features. There are
1394 :     two rows returned, and the values can be used to select features by genome
1395 :     using the B<FeatureQuery> object.
1396 :    
1397 :     =cut
1398 :    
1399 :     sub FeatureFilterRows {
1400 :     # Get the parameters.
1401 :     my ($self) = @_;
1402 :     # Return the result.
1403 :     return FeatureQuery::FilterRows($self);
1404 :     }
1405 :    
1406 : parrello 1.1 =head3 GBrowseFeatureURL
1407 :    
1408 :     C<< my $url = SearchHelper::GBrowseFeatureURL($sprout, $feat); >>
1409 :    
1410 :     Compute the URL required to pull up a Gbrowse page for the the specified feature.
1411 :     In order to do this, we need to pull out the ID of the feature's Genome, its
1412 :     contig ID, and some rough starting and stopping offsets.
1413 :    
1414 :     =over 4
1415 :    
1416 :     =item sprout
1417 :    
1418 :     Sprout object for accessing the database.
1419 :    
1420 :     =item feat
1421 :    
1422 :     ID of the feature whose Gbrowse URL is desired.
1423 :    
1424 :     =item RETURN
1425 :    
1426 :     Returns a GET-style URL for the Gbrowse CGI, with parameters specifying the genome
1427 :     ID, contig ID, starting offset, and stopping offset.
1428 :    
1429 :     =back
1430 :    
1431 :     =cut
1432 :    
1433 :     sub GBrowseFeatureURL {
1434 :     # Get the parameters.
1435 :     my ($sprout, $feat) = @_;
1436 :     # Declare the return variable.
1437 :     my $retVal;
1438 :     # Compute the genome ID.
1439 :     my ($genomeID) = FIGRules::ParseFeatureID($feat);
1440 :     # Only proceed if the feature ID produces a valid genome.
1441 :     if ($genomeID) {
1442 :     # Get the feature location string.
1443 :     my $loc = $sprout->FeatureLocation($feat);
1444 :     # Compute the contig, start, and stop points.
1445 :     my($start, $stop, $contig) = BasicLocation::Parse($loc);
1446 :     # Now we need to do some goofiness to insure that the location is not too
1447 :     # big and that we get some surrounding stuff.
1448 :     my $mid = int(($start + $stop) / 2);
1449 :     my $chunk_len = 20000;
1450 :     my $max_feature = 40000;
1451 :     my $feat_len = abs($stop - $start);
1452 :     if ($feat_len > $chunk_len) {
1453 :     if ($feat_len > $max_feature) {
1454 :     $chunk_len = $max_feature;
1455 :     } else {
1456 :     $chunk_len = $feat_len + 100;
1457 :     }
1458 :     }
1459 :     my($show_start, $show_stop);
1460 :     if ($chunk_len == $max_feature) {
1461 :     $show_start = $start - 300;
1462 :     } else {
1463 :     $show_start = $mid - int($chunk_len / 2);
1464 :     }
1465 :     if ($show_start < 1) {
1466 :     $show_start = 1;
1467 :     }
1468 :     $show_stop = $show_start + $chunk_len - 1;
1469 :     my $clen = $sprout->ContigLength($contig);
1470 :     if ($show_stop > $clen) {
1471 :     $show_stop = $clen;
1472 :     }
1473 :     my $seg_id = $contig;
1474 :     $seg_id =~ s/:/--/g;
1475 :     # Assemble all the pieces.
1476 :     $retVal = "gbrowse.cgi/GB_$genomeID?ref=$seg_id&start=$show_start&stop=$show_stop";
1477 :     }
1478 :     # Return the result.
1479 :     return $retVal;
1480 :     }
1481 :    
1482 : parrello 1.3 =head3 GetGenomes
1483 :    
1484 :     C<< my @genomeList = $shelp->GetGenomes($parmName); >>
1485 :    
1486 :     Return the list of genomes specified by the specified CGI query parameter.
1487 :     If the request method is POST, then the list of genome IDs is returned
1488 :     without preamble. If the request method is GET and the parameter is not
1489 :     specified, then it is treated as a request for all genomes. This makes it
1490 :     easier for web pages to link to a search that wants to specify all genomes.
1491 :    
1492 :     =over 4
1493 :    
1494 :     =item parmName
1495 :    
1496 :     Name of the parameter containing the list of genomes. This will be the
1497 :     first parameter passed to the L</NmpdrGenomeMenu> call that created the
1498 :     genome selection control on the form.
1499 :    
1500 :     =item RETURN
1501 :    
1502 :     Returns a list of the genomes to process.
1503 :    
1504 :     =back
1505 :    
1506 :     =cut
1507 :    
1508 :     sub GetGenomes {
1509 :     # Get the parameters.
1510 :     my ($self, $parmName) = @_;
1511 :     # Get the CGI query object.
1512 :     my $cgi = $self->Q();
1513 :     # Get the list of genome IDs in the request header.
1514 :     my @retVal = $cgi->param($parmName);
1515 :     Trace("Genome list for $parmName is (" . join(", ", @retVal) . ") with method " . $cgi->request_method() . ".") if T(3);
1516 :     # Check for the special GET case.
1517 :     if ($cgi->request_method() eq "GET" && ! @retVal) {
1518 :     # Here the caller wants all the genomes.
1519 :     my $sprout = $self->DB();
1520 :     @retVal = $sprout->Genomes();
1521 :     }
1522 :     # Return the result.
1523 :     return @retVal;
1524 :     }
1525 :    
1526 :     =head3 GetHelpText
1527 :    
1528 :     C<< my $htmlText = $shelp->GetHelpText(); >>
1529 :    
1530 :     Get the help text for this search. The help text is stored in files on the template
1531 :     server. The help text for a specific search is taken from a file named
1532 :     C<SearchHelp_>I<class>C<.inc> in the template directory C<$FIG_Config::template_url>.
1533 :     There are also three standard help files: C<SearchHelp1_Filtering.inc> describes the
1534 :     feature filtering performed by the B<FeatureQuery> object, C<SearchHelp1_GenomeControl.inc>
1535 :     describes how to use a multiple-selection genome control, and C<SearchHelp1_Standard.inc>
1536 :     describes the standard controls for a search, such as page size, URL display, and
1537 :     external alias display.
1538 :    
1539 :     =cut
1540 :    
1541 :     sub GetHelpText {
1542 :     # Get the parameters.
1543 :     my ($self) = @_;
1544 :     # Create a list to hold the pieces of the help.
1545 :     my @helps = ();
1546 :     # Get the template directory URL.
1547 :     my $urlBase = $FIG_Config::template_url;
1548 :     # Start with the specific help.
1549 :     my $class = $self->{class};
1550 :     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp_$class.inc");
1551 :     # Add the genome control help if needed.
1552 :     if (scalar @{$self->{genomeParms}}) {
1553 :     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_GenomeControl.inc");
1554 :     }
1555 :     # Next the filter help.
1556 :     if ($self->{filtered}) {
1557 :     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_Filtering.inc");
1558 :     }
1559 :     # Finally, the standard help.
1560 :     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_Standard.inc");
1561 :     # Assemble the pieces.
1562 :     my $retVal = join("\n<p>&nbsp;</p>\n", @helps);
1563 :     # Return the result.
1564 :     return $retVal;
1565 :     }
1566 :    
1567 :     =head3 ComputeSearchURL
1568 :    
1569 :     C<< my $url = $shelp->ComputeSearchURL(); >>
1570 :    
1571 :     Compute the GET-style URL for the current search. In order for this to work, there
1572 :     must be a copy of the search form on the current page. This will always be the
1573 :     case if the search is coming from C<SearchSkeleton.cgi>.
1574 :    
1575 :     A little expense is involved in order to make the URL as smart as possible. The
1576 :     main complication is that if the user specified all genomes, we'll want to
1577 :     remove the parameter entirely from a get-style URL.
1578 :    
1579 :     =cut
1580 :    
1581 :     sub ComputeSearchURL {
1582 :     # Get the parameters.
1583 :     my ($self) = @_;
1584 :     # Get the database and CGI query object.
1585 :     my $cgi = $self->Q();
1586 :     my $sprout = $self->DB();
1587 :     # Start with the full URL.
1588 :     my $retVal = $cgi->url(-full => 1);
1589 :     # Get all the query parameters in a hash.
1590 :     my %parms = $cgi->Vars();
1591 :     # Now we need to do some fixing. Each multi-valued parameter is encoded as a string with null
1592 :     # characters separating the individual values. We have to convert those to lists. In addition,
1593 :     # the multiple-selection genome parameters and the feature type parameter must be checked to
1594 :     # determine whether or not they can be removed from the URL. First, we get a list of the
1595 :     # genome parameters and a list of all genomes. Note that we only need the list if a
1596 :     # multiple-selection genome parameter has been found on the form.
1597 :     my %genomeParms = map { $_ => 1 } @{$self->{genomeParms}};
1598 :     my @genomeList;
1599 :     if (keys %genomeParms) {
1600 :     @genomeList = $sprout->Genomes();
1601 :     }
1602 :     # Create a list to hold the URL parameters we find.
1603 :     my @urlList = ();
1604 :     # Now loop through the parameters in the hash, putting them into the output URL.
1605 :     for my $parmKey (keys %parms) {
1606 :     # Get a list of the parameter values. If there's only one, we'll end up with
1607 :     # a singleton list, but that's okay.
1608 :     my @values = split (/\0/, $parms{$parmKey});
1609 :     # Check for special cases.
1610 :     if ($parmKey eq 'featureTypes') {
1611 :     # Here we need to see if the user wants all the feature types. If he
1612 :     # does, we erase all the values so that the parameter is not output.
1613 :     my %valueCheck = map { $_ => 1 } @values;
1614 :     my @list = FeatureQuery::AllFeatureTypes();
1615 :     my $okFlag = 1;
1616 :     for (my $i = 0; $okFlag && $i <= $#list; $i++) {
1617 :     if (! $valueCheck{$list[$i]}) {
1618 :     $okFlag = 0;
1619 :     }
1620 :     }
1621 :     if ($okFlag) {
1622 :     @values = ();
1623 :     }
1624 :     } elsif (grep { $_ eq $parmKey } qw(SessionID ResultCount Page PageSize Trace TF ShowURL)) {
1625 :     # These are bookkeeping parameters we don't need to start a search.
1626 :     @values = ();
1627 :     } elsif ($parmKey =~ /_SearchThing$/) {
1628 :     # Here the value coming in is from a genome control's search thing. It does
1629 :     # not affect the results of the search, so we clear it.
1630 :     @values = ();
1631 :     } elsif ($genomeParms{$parmKey}) {
1632 :     # Here we need to see if the user wants all the genomes. If he does,
1633 :     # we erase all the values just like with features.
1634 :     my $allFlag = $sprout->IsAllGenomes(\@values, \@genomeList);
1635 :     if ($allFlag) {
1636 :     @values = ();
1637 :     }
1638 :     }
1639 :     # If we still have values, create the URL parameters.
1640 :     if (@values) {
1641 :     push @urlList, map { "$parmKey=" . uri_escape($_) } @values;
1642 :     }
1643 :     }
1644 :     # Add the parameters to the URL.
1645 :     $retVal .= "?" . join(";", @urlList);
1646 :     # Return the result.
1647 :     return $retVal;
1648 :     }
1649 :    
1650 :     =head3 GetRunTimeValue
1651 :    
1652 :     C<< my $htmlText = $shelp->GetRunTimeValue($text); >>
1653 :    
1654 :     Compute a run-time column value.
1655 :    
1656 :     =over 4
1657 :    
1658 :     =item text
1659 :    
1660 :     The run-time column text. It consists of 2 percent signs, a column type, an equal
1661 :     sign, and the data for the current row.
1662 :    
1663 :     =item RETURN
1664 :    
1665 :     Returns the fully-formatted HTML text to go into the current column of the current row.
1666 :    
1667 :     =back
1668 :    
1669 :     =cut
1670 :    
1671 :     sub GetRunTimeValue {
1672 :     # Get the parameters.
1673 :     my ($self, $text) = @_;
1674 :     # Declare the return variable.
1675 :     my $retVal;
1676 :     # Parse the incoming text.
1677 :     if ($text =~ /^%%([^=]+)=(.*)$/) {
1678 :     $retVal = $self->RunTimeColumns($1, $2);
1679 :     } else {
1680 :     Confess("Invalid run-time column string \"$text\" encountered in session file.");
1681 :     }
1682 :     # Return the result.
1683 :     return $retVal;
1684 :     }
1685 :    
1686 : parrello 1.1 =head2 Feature Column Methods
1687 :    
1688 :     The methods in this column manage feature column data. If you want to provide the
1689 :     capability to include new types of data in feature columns, then all the changes
1690 :     are made to this section of the source file. Technically, this should be implemented
1691 :     using object-oriented methods, but this is simpler for non-programmers to maintain.
1692 :     To add a new column of feature data, you must first give it a name. For example,
1693 :     the name for the protein page link column is C<protlink>. If the column is to appear
1694 :     in the default list of feature columns, add it to the list returned by
1695 :     L</DefaultFeatureColumns>. Then add code to produce the column title to
1696 :     L</FeatureColumnTitle> and code to produce its value to L</FeatureColumnValue>, and
1697 :     everything else will happen automatically.
1698 :    
1699 :     There is one special column name syntax for extra columns (that is, nonstandard
1700 :     feature columns). If the column name begins with C<X=>, then it is presumed to be
1701 :     an extra column. The column title is the text after the C<X=>, and its value is
1702 :     pulled from the extra column hash.
1703 :    
1704 :     =head3 DefaultFeatureColumns
1705 :    
1706 :     C<< my $colNames = $shelp->DefaultFeatureColumns(); >>
1707 :    
1708 :     Return a reference to a list of the default feature column identifiers. These
1709 :     identifiers can be passed to L</FeatureColumnTitle> and L</FeatureColumnValue> in
1710 :     order to produce the column titles and row values.
1711 :    
1712 :     =cut
1713 :    
1714 :     sub DefaultFeatureColumns {
1715 :     # Get the parameters.
1716 :     my ($self) = @_;
1717 :     # Return the result.
1718 :     return ['orgName', 'function', 'gblink', 'protlink'];
1719 :     }
1720 :    
1721 :     =head3 FeatureColumnTitle
1722 :    
1723 :     C<< my $title = $shelp->FeatureColumnTitle($colName); >>
1724 :    
1725 :     Return the column heading title to be used for the specified feature column.
1726 :    
1727 :     =over 4
1728 :    
1729 :     =item name
1730 :    
1731 :     Name of the desired feature column.
1732 :    
1733 :     =item RETURN
1734 :    
1735 :     Returns the title to be used as the column header for the named feature column.
1736 :    
1737 :     =back
1738 :    
1739 :     =cut
1740 :    
1741 :     sub FeatureColumnTitle {
1742 :     # Get the parameters.
1743 :     my ($self, $colName) = @_;
1744 :     # Declare the return variable. We default to a blank column name.
1745 :     my $retVal = "&nbsp;";
1746 :     # Process the column name.
1747 :     if ($colName =~ /^X=(.+)$/) {
1748 :     # Here we have an extra column.
1749 :     $retVal = $1;
1750 :     } elsif ($colName eq 'orgName') {
1751 :     $retVal = "Name";
1752 :     } elsif ($colName eq 'fid') {
1753 :     $retVal = "FIG ID";
1754 :     } elsif ($colName eq 'alias') {
1755 :     $retVal = "External Aliases";
1756 :     } elsif ($colName eq 'function') {
1757 :     $retVal = "Functional Assignment";
1758 :     } elsif ($colName eq 'gblink') {
1759 :     $retVal = "GBrowse";
1760 :     } elsif ($colName eq 'protlink') {
1761 :     $retVal = "NMPDR Protein Page";
1762 :     } elsif ($colName eq 'group') {
1763 :     $retVal = "NMDPR Group";
1764 :     }
1765 :     # Return the result.
1766 :     return $retVal;
1767 :     }
1768 :    
1769 :     =head3 FeatureColumnValue
1770 :    
1771 :     C<< my $value = $shelp->FeatureColumnValue($colName, $fid, \%extraCols); >>
1772 :    
1773 :     Return the value to be displayed in the specified feature column.
1774 :    
1775 :     =over 4
1776 :    
1777 :     =item colName
1778 :    
1779 :     Name of the column to be displayed.
1780 :    
1781 :     =item record
1782 :    
1783 :     DBObject record for the feature being displayed in the current row.
1784 :    
1785 :     =item extraCols
1786 :    
1787 :     Reference to a hash of extra column names to values. If the incoming column name
1788 :     begins with C<X=>, its value will be taken from this hash.
1789 :    
1790 :     =item RETURN
1791 :    
1792 :     Returns the HTML to be displayed in the named column for the specified feature.
1793 :    
1794 :     =back
1795 :    
1796 :     =cut
1797 :    
1798 :     sub FeatureColumnValue {
1799 :     # Get the parameters.
1800 :     my ($self, $colName, $record, $extraCols) = @_;
1801 :     # Get the sprout and CGI objects.
1802 :     my $cgi = $self->Q();
1803 :     my $sprout = $self->DB();
1804 :     # Get the feature ID.
1805 :     my ($fid) = $record->Value('Feature(id)');
1806 :     # Declare the return variable. Denote that we default to a non-breaking space,
1807 :     # which will translate to an empty table cell (rather than a table cell with no
1808 :     # interior, which is what you get for a null string).
1809 :     my $retVal = "&nbsp;";
1810 :     # Process according to the column name.
1811 :     if ($colName =~ /^X=(.+)$/) {
1812 :     # Here we have an extra column. Only update if the value exists. Note that
1813 :     # a value of C<undef> is treated as a non-existent value, because the
1814 :     # caller may have put "colName => undef" in the "PutFeature" call in order
1815 :     # to insure we know the extra column exists.
1816 :     if (defined $extraCols->{$1}) {
1817 :     $retVal = $extraCols->{$1};
1818 :     }
1819 :     } elsif ($colName eq 'orgName') {
1820 :     # Here we want the formatted organism name and feature number.
1821 :     $retVal = $self->FeatureName($fid);
1822 :     } elsif ($colName eq 'fid') {
1823 :     # Here we have the raw feature ID. We hyperlink it to the protein page.
1824 :     $retVal = HTML::set_prot_links($fid);
1825 :     } elsif ($colName eq 'alias') {
1826 :     # In this case, the user wants a list of external aliases for the feature.
1827 : parrello 1.3 # These are very expensive, so we compute them when the row is displayed.
1828 :     $retVal = "%%aliases=$fid";
1829 : parrello 1.1 } elsif ($colName eq 'function') {
1830 :     # The functional assignment is just a matter of getting some text.
1831 :     ($retVal) = $record->Value('Feature(assignment)');
1832 :     } elsif ($colName eq 'gblink') {
1833 :     # Here we want a link to the GBrowse page using the official GBrowse button.
1834 :     my $gurl = "GetGBrowse.cgi?fid=$fid";
1835 :     $retVal = $cgi->a({ href => $gurl, title => "GBrowse for $fid" },
1836 :     $cgi->img({ src => "../images/button-gbrowse.png",
1837 :     border => 0 })
1838 :     );
1839 :     } elsif ($colName eq 'protlink') {
1840 :     # Here we want a link to the protein page using the official NMPDR button.
1841 :     my $hurl = HTML::fid_link($cgi, $fid, 0, 1);
1842 :     $retVal = $cgi->a({ href => $hurl, title => "Protein page for $fid" },
1843 :     $cgi->img({ src => "../images/button-nmpdr.png",
1844 :     border => 0 })
1845 :     );
1846 :     } elsif ($colName eq 'group') {
1847 :     # Get the NMPDR group name.
1848 :     my (undef, $group) = $self->OrganismData($fid);
1849 :     # Dress it with a URL to the group's main page.
1850 :     my $nurl = $sprout->GroupPageName($group);
1851 :     $retVal = $cgi->a({ href => $nurl, title => "$group summary" },
1852 :     $group);
1853 :     }
1854 :     # Return the result.
1855 :     return $retVal;
1856 :     }
1857 :    
1858 : parrello 1.3 =head3 RunTimeColumns
1859 :    
1860 :     C<< my $htmlText = $shelp->RunTimeColumns($type, $text); >>
1861 :    
1862 :     Return the HTML text for a run-time column. Run-time columns are evaluated when the
1863 :     list is displayed, rather than when it is generated.
1864 :    
1865 :     =over 4
1866 :    
1867 :     =item type
1868 :    
1869 :     Type of column.
1870 :    
1871 :     =item text
1872 :    
1873 :     Data relevant to this row of the column.
1874 :    
1875 :     =item RETURN
1876 :    
1877 :     Returns the fully-formatted HTML text to go in the specified column.
1878 :    
1879 :     =back
1880 :    
1881 :     =cut
1882 :    
1883 :     sub RunTimeColumns {
1884 :     # Get the parameters.
1885 :     my ($self, $type, $text) = @_;
1886 :     # Declare the return variable.
1887 :     my $retVal = "";
1888 :     # Get the Sprout and CGI objects.
1889 :     my $sprout = $self->DB();
1890 :     my $cgi = $self->Q();
1891 :     # Separate the text into a type and data.
1892 :     if ($type eq 'aliases') {
1893 :     # Here the caller wants external alias links for a feature. The text
1894 :     # is the feature ID.
1895 :     my $fid = $text;
1896 :     # The complicated part is we have to hyperlink them. First, get the
1897 :     # aliases.
1898 :     Trace("Generating aliases for feature $fid.") if T(4);
1899 :     my @aliases = $sprout->FeatureAliases($fid);
1900 :     # Only proceed if we found some.
1901 :     if (@aliases) {
1902 :     # Join the aliases into a comma-delimited list.
1903 :     my $aliasList = join(", ", @aliases);
1904 :     # Ask the HTML processor to hyperlink them.
1905 :     $retVal = HTML::set_prot_links($cgi, $aliasList);
1906 :     }
1907 :     }
1908 :     # Return the result.
1909 :     return $retVal;
1910 :     }
1911 :    
1912 : parrello 1.1 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3