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

Diff of /Sprout/SearchHelper.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.42, Fri Oct 17 16:41:47 2008 UTC revision 1.46, Sat Mar 7 18:07:36 2009 UTC
# Line 19  Line 19 
19      use URI::Escape;      use URI::Escape;
20      use PageBuilder;      use PageBuilder;
21      use AliasAnalysis;      use AliasAnalysis;
22        use CGI::Cookie;
23      use FreezeThaw qw(freeze thaw);      use FreezeThaw qw(freeze thaw);
24    
25  =head1 Search Helper Base Class  =head1 Search Helper Base Class
# Line 85  Line 86 
86    
87  List of the parameters that are used to select multiple genomes.  List of the parameters that are used to select multiple genomes.
88    
89    =item notices
90    
91    A list of messages to be put in the notice file.
92    
93  =back  =back
94    
95  =head2 Adding a new Search Tool  =head2 Adding a new Search Tool
# Line 258  Line 263 
263  sub new {  sub new {
264      # Get the parameters.      # Get the parameters.
265      my ($class, $cgi) = @_;      my ($class, $cgi) = @_;
266      # Check for a session ID.      # Check for a session ID. First we look in the CGI parameters.
267      my $session_id = $cgi->param("SessionID");      my $session_id = $cgi->param("SessionID");
268      my $type = "old";      my $type = "old";
269      if (! $session_id) {      if (! $session_id) {
270            # 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);          Trace("No session ID found.") if T(3);
275          # Here we're starting a new session. We create the session ID and          # Here we're starting a new session. We create the session ID and
276          # store it in the query object.              # store it in a cookie.
277          $session_id = FIGRules::NewSessionID();          $session_id = FIGRules::NewSessionID();
278          Trace("New session ID is $session_id.") if T(3);          Trace("New session ID is $session_id.") if T(3);
279                $session_cookie = new CGI::Cookie(-name => $class,
280                                                  -value => $session_id);
281                $session_cookie->bake();
282            } else {
283                # Here we're recovering an old session. The session ID is
284                # used to find any old search options lying around, but we're
285                # still considered a new session.
286                $session_id = $session_cookie->value();
287                Trace("Session $session_id recovered from cookie.") if T(3);
288            }
289            # Denote this is a new session.
290          $type = "new";          $type = "new";
291            # Put the session ID in the parameters.
292          $cgi->param(-name => 'SessionID', -value => $session_id);          $cgi->param(-name => 'SessionID', -value => $session_id);
293      } else {      } else {
294          Trace("Session ID is $session_id.") if T(3);          Trace("Session ID is $session_id.") if T(3);
# Line 303  Line 324 
324                    scriptQueue => [],                    scriptQueue => [],
325                    genomeList => undef,                    genomeList => undef,
326                    genomeParms => [],                    genomeParms => [],
327                      notices => [],
328                   };                   };
329      # Bless and return it.      # Bless and return it.
330      bless $retVal, $class;      bless $retVal, $class;
# Line 325  Line 347 
347  }  }
348    
349    
   
350  =head3 DB  =head3 DB
351    
352      my $sprout = $shelp->DB();      my $sprout = $shelp->DB();
# Line 460  Line 481 
481      # Start the form. Note we use the override option on the Class value, in      # Start the form. Note we use the override option on the Class value, in
482      # case the Advanced button was used.      # case the Advanced button was used.
483      my $retVal = "<div class=\"search\">\n" .      my $retVal = "<div class=\"search\">\n" .
484                   $cgi->start_form(-method => 'POST',                   CGI::start_form(-method => 'POST',
485                                    -action => "$FIG_Config::cgi_url/SearchSkeleton.cgi",                                    -action => "$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/search",
486                                    -name => $self->FormName()) .                                    -name => $self->FormName(),
487                   $cgi->hidden(-name => 'Class',                                    -id => $self->FormName()) .
488                                -value => $self->{class},                   CGI::hidden(-name => 'Class',
489                                -override => 1) .                                -value => $self->{class}) .
490                   $cgi->hidden(-name => 'SPROUT',                   CGI::hidden(-name => 'SPROUT',
491                                -value => 1) .                                -value => 1) .
492                   $cgi->h3("$title" . Hint($self->{class}, "Click here for more information."));                   CGI::h3("$title" . Hint($self->{class}, "Click here for more information."));
493      # Put in an anchor tag in case there's a table of contents.      # Put in an anchor tag in case there's a table of contents.
494      my $anchorName = $self->FormName();      my $anchorName = $self->FormName();
495      $retVal .= "<a name=\"$anchorName\"></a>\n";      $retVal .= "<a name=\"$anchorName\"></a>\n";
# Line 666  Line 687 
687      $self->{fileHandle} = Open(undef, "| sort | cut --fields=2- >>$fileName");      $self->{fileHandle} = Open(undef, "| sort | cut --fields=2- >>$fileName");
688  }  }
689    
690    =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  =head3 ReadColumnHeaders  =head3 ReadColumnHeaders
717    
718      my @colHdrs = $shelp->ReadColumnHeaders($fh);      my @colHdrs = $shelp->ReadColumnHeaders($fh);
# Line 747  Line 794 
794          my $cgi = $self->Q();          my $cgi = $self->Q();
795          $self->PrintLine("Output formatting complete.<br />");          $self->PrintLine("Output formatting complete.<br />");
796      }      }
797        # 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  }  }
808    
809  =head3 OrganismData  =head3 OrganismData
# Line 886  Line 943 
943      Trace("FASTA desired type is $desiredType.") if T(4);      Trace("FASTA desired type is $desiredType.") if T(4);
944      # Check for a feature specification. The smoking gun for that is a vertical bar.      # Check for a feature specification. The smoking gun for that is a vertical bar.
945      if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {      if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {
946          # Here we have a feature ID in $1. We'll need the Sprout object to process          # Here we have a feature ID in $1. We'll need a Sprout object to process it.
         # it.  
947          my $fid = $1;          my $fid = $1;
948          Trace("Feature ID for fasta is $fid.") if T(3);          Trace("Feature ID for fasta is $fid.") if T(3);
949          my $sprout = $self->DB();          my $sprout = $self->DB();
# Line 973  Line 1029 
1029          if ($desiredType !~ /pattern/i) {          if ($desiredType !~ /pattern/i) {
1030              $fastaData =~ s/\n//g;              $fastaData =~ s/\n//g;
1031              $fastaData =~ s/\s+//g;              $fastaData =~ s/\s+//g;
1032                $fastaData =~ s/\d+//g;
1033          }          }
1034          # Finally, verify that it's DNA if we're doing DNA stuff.          # Finally, verify that it's DNA if we're doing DNA stuff.
1035          if ($desiredType eq 'dna' && $fastaData =~ /[^agctxn-]/i) {          if ($desiredType eq 'dna' && $fastaData =~ /[^agctxn-]/i) {
# Line 1218  Line 1275 
1275      return $retVal;      return $retVal;
1276  }  }
1277    
 =head3 PropertyMenu  
   
     my $htmlText = $shelp->PropertyMenu($menuName, $selected, $force);  
   
 Generate a property name dropdown menu.  
   
 =over 4  
   
 =item menuName  
   
 Name to give to the menu.  
   
 =item selected  
   
 Value of the property name to pre-select.  
   
 =item force (optional)  
   
 If TRUE, then the user will be forced to choose a property name. If FALSE,  
 then an additional menu choice will be provided to select nothing.  
   
 =item RETURN  
   
 Returns a dropdown menu box that allows the user to select a property name. An additional  
 selection entry will be provided for selecting no property name  
   
 =back  
   
 =cut  
   
 sub PropertyMenu {  
     # Get the parameters.  
     my ($self, $menuName, $selected, $force) = @_;  
     # Get the CGI and Sprout objects.  
     my $sprout = $self->DB();  
     my $cgi = $self->Q();  
     # Create the property name list.  
     my @propNames = ();  
     if (! $force) {  
         push @propNames, "";  
     }  
     # Get all the property names, putting them after the null choice if one exists.  
     push @propNames, $sprout->GetChoices('Property', 'property-name');  
     # Create a menu from them.  
     my $retVal = $cgi->popup_menu(-name=> $menuName, -values => \@propNames,  
                                   -default => $selected);  
     # Return the result.  
     return $retVal;  
 }  
   
1278  =head3 MakeTable  =head3 MakeTable
1279    
1280      my $htmlText = $shelp->MakeTable(\@rows);      my $htmlText = $shelp->MakeTable(\@rows);
# Line 1324  Line 1331 
1331          }          }
1332      }      }
1333      # Create the table.      # Create the table.
1334      my $retVal = $cgi->table({border => 2, cellspacing => 2,      my $retVal = CGI::table({border => 2, cellspacing => 2,
1335                                width => 700, class => 'search'},                                width => 700, class => 'search'},
1336                               @{$rows});                               @{$rows});
1337      # Return the result.      # Return the result.
# Line 1362  Line 1369 
1369      my $realCaption = (defined $caption ? $caption : 'Go');      my $realCaption = (defined $caption ? $caption : 'Go');
1370      # Get the current page size.      # Get the current page size.
1371      my $pageSize = $cgi->param('PageSize');      my $pageSize = $cgi->param('PageSize');
1372        # Get the form name.
1373        my $formName = $self->FormName();
1374      # Get the current feature ID type.      # Get the current feature ID type.
1375      my $aliasType = $self->GetPreferredAliasType();      my $aliasType = $self->GetPreferredAliasType();
1376      # Create the rows.      # Create the rows.
1377      my $retVal = $cgi->Tr($cgi->td("Identifier Type "),      my $retVal = CGI::Tr(CGI::td("Identifier Type "),
1378                            $cgi->td({ colspan => 2 },                            CGI::td({ colspan => 2 },
1379                                     $cgi->popup_menu(-name => 'AliasType',                                     CGI::popup_menu(-name => 'AliasType',
1380                                                      -values => ['FIG', AliasAnalysis::AliasTypes() ],                                                      -values => ['FIG', AliasAnalysis::AliasTypes() ],
1381                                                      -default => $aliasType) .                                                      -default => $aliasType) .
1382                                     Hint("Identifier Type", "Specify how you want gene names to be displayed."))) .                                     Hint("Identifier Type", "Specify how you want gene names to be displayed."))) .
1383                   "\n" .                   "\n" .
1384                   $cgi->Tr($cgi->td("Results/Page"),                   CGI::Tr(CGI::td("Results/Page"),
1385                            $cgi->td($cgi->popup_menu(-name => 'PageSize',                            CGI::td(CGI::popup_menu(-name => 'PageSize',
1386                                                      -values => [10, 25, 50, 100, 1000],                                                    -values => [50, 10, 25, 100, 1000],
1387                                                      -default => $pageSize)),                                                      -default => $pageSize)),
1388                            $cgi->td($cgi->submit(-class => 'goButton',                            CGI::td(CGI::submit(-class => 'goButton',
1389                                                  -name => 'Search',                                                  -name => 'Search',
1390                                                  -value => $realCaption)));                                                  -value => $realCaption)));
1391      # Return the result.      # Return the result.
# Line 1719  Line 1728 
1728              Confess("Hash reference found at start of selection tree. The tree as a whole cannot have attributes, only tree nodes.");              Confess("Hash reference found at start of selection tree. The tree as a whole cannot have attributes, only tree nodes.");
1729          } else {          } else {
1730              # Here we have a real tree. Apply the tree style.              # Here we have a real tree. Apply the tree style.
1731              push @retVal, $cgi->start_div({ class => $optionThing->{style} });              push @retVal, CGI::start_div({ class => $optionThing->{style} });
1732              # Give us a DIV ID.              # Give us a DIV ID.
1733              my $divID = GetDivID($optionThing->{name});              my $divID = GetDivID($optionThing->{name});
1734              # Show the tree.              # Show the tree.
1735              push @retVal, ShowBranch($cgi, "(root)", $divID, $tree, $optionThing, 'block');              push @retVal, ShowBranch($cgi, "(root)", $divID, $tree, $optionThing, 'block');
1736              # Close the DIV block.              # Close the DIV block.
1737              push @retVal, $cgi->end_div();              push @retVal, CGI::end_div();
1738          }          }
1739      }      }
1740      # Return the result.      # Return the result.
# Line 1783  Line 1792 
1792      # Declare the return variable.      # Declare the return variable.
1793      my @retVal = ();      my @retVal = ();
1794      # Start the branch.      # Start the branch.
1795      push @retVal, $cgi->start_ul({ id => $id, style => "display:$displayType" });      push @retVal, CGI::start_ul({ id => $id, style => "display:$displayType" });
1796      # Check for the hash and choose the start location accordingly.      # Check for the hash and choose the start location accordingly.
1797      my $i0 = (ref $branch->[0] eq 'HASH' ? 1 : 0);      my $i0 = (ref $branch->[0] eq 'HASH' ? 1 : 0);
1798      # Get the list length.      # Get the list length.
# Line 1841  Line 1850 
1850              # closed images.              # closed images.
1851              my @images = ($options->{nodeImageOpen}, $options->{nodeImageClosed});              my @images = ($options->{nodeImageOpen}, $options->{nodeImageClosed});
1852              my $image = $images[$hasChildren];              my $image = $images[$hasChildren];
1853              my $prefixHtml = $cgi->img({src => $image, id => "${myID}img"});              my $prefixHtml = CGI::img({src => $image, id => "${myID}img"});
1854              if ($hasChildren) {              if ($hasChildren) {
1855                  # If there are children, we wrap the image in a toggle hyperlink.                  # If there are children, we wrap the image in a toggle hyperlink.
1856                  $prefixHtml = $cgi->a({ onClick => "javascript:treeToggle('$myID','$images[0]', '$images[1]')" },                  $prefixHtml = CGI::a({ onClick => "javascript:treeToggle('$myID','$images[0]', '$images[1]')" },
1857                                        $prefixHtml);                                        $prefixHtml);
1858              }              }
1859              # Now the radio button, if any. Note we use "defined" in case the user wants the              # Now the radio button, if any. Note we use "defined" in case the user wants the
# Line 1861  Line 1870 
1870                  if (defined $options->{selected} && $options->{selected} eq $attrHash->{value}) {                  if (defined $options->{selected} && $options->{selected} eq $attrHash->{value}) {
1871                      $radioParms->{checked} = undef;                      $radioParms->{checked} = undef;
1872                  }                  }
1873                  $prefixHtml .= $cgi->input($radioParms);                  $prefixHtml .= CGI::input($radioParms);
1874              }              }
1875              # Next, we format the label.              # Next, we format the label.
1876              my $labelHtml = $myLabel;              my $labelHtml = $myLabel;
1877              Trace("Formatting tree node for \"$myLabel\".") if T(4);              Trace("Formatting tree node for \"$myLabel\".") if T(4);
1878              # Apply a hyperlink if necessary.              # Apply a hyperlink if necessary.
1879              if (defined $attrHash->{link}) {              if (defined $attrHash->{link}) {
1880                  $labelHtml = $cgi->a({ href => $attrHash->{link}, target => $options->{target} },                  $labelHtml = CGI::a({ href => $attrHash->{link}, target => $options->{target} },
1881                                       $labelHtml);                                       $labelHtml);
1882              }              }
1883              # Finally, roll up the child HTML. If there are no children, we'll get a null string              # Finally, roll up the child HTML. If there are no children, we'll get a null string
1884              # here.              # here.
1885              my $childHtml = join("\n", @childHtml);              my $childHtml = join("\n", @childHtml);
1886              # Now we have all the pieces, so we can put them together.              # Now we have all the pieces, so we can put them together.
1887              push @retVal, $cgi->li("$prefixHtml$labelHtml$childHtml");              push @retVal, CGI::li("$prefixHtml$labelHtml$childHtml");
1888          }          }
1889      }      }
1890      # Close the tree branch.      # Close the tree branch.
1891      push @retVal, $cgi->end_ul();      push @retVal, CGI::end_ul();
1892      # Return the result.      # Return the result.
1893      return @retVal;      return @retVal;
1894  }  }
# Line 1935  Line 1944 
1944  sub PrintLine {  sub PrintLine {
1945      # Get the parameters.      # Get the parameters.
1946      my ($self, $message) = @_;      my ($self, $message) = @_;
1947      # Send them to the output.      # Send the message to the output.
1948      print "$message\n";      print "$message\n";
1949  }  }
1950    
# Line 1987  Line 1996 
1996          # Commit suicide if it didn't work.          # Commit suicide if it didn't work.
1997          if (! defined $retVal) {          if (! defined $retVal) {
1998              die "Could not find a $type handler of type $className.";              die "Could not find a $type handler of type $className.";
1999            } else {
2000                # Perform any necessary subclass initialization.
2001                $retVal->Initialize();
2002          }          }
2003      };      };
2004      # Check for errors.      # Check for errors.
# Line 2184  Line 2196 
2196      return $retVal;      return $retVal;
2197  }  }
2198    
2199    =head3 Hint
2200    
2201        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
2202    
2203    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
2204    This HTML can be put in forms to provide a useful hinting mechanism.
2205    
2206    =over 4
2207    
2208    =item wikiPage
2209    
2210    Name of the wiki page to be popped up when the hint mark is clicked.
2211    
2212    =item hintText
2213    
2214    Text to display for the hint. It is raw html, but may not contain any double quotes.
2215    
2216    =item RETURN
2217    
2218    Returns the html for the hint facility. The resulting html shows a small button-like thing that
2219    uses the standard FIG popup technology.
2220    
2221    =back
2222    
2223    =cut
2224    
2225    sub Hint {
2226        # Get the parameters.
2227        my ($wikiPage, $hintText) = @_;
2228        # Ask Sprout to draw the hint button for us.
2229        return Sprout::Hint($wikiPage, $hintText);
2230    }
2231    
2232    
2233    
2234  =head2 Virtual Methods  =head2 Virtual Methods
2235    
2236    =head3 HeaderHtml
2237    
2238        my $html = $shelp->HeaderHtml();
2239    
2240    Generate HTML for the HTML header. If extra styles or javascript are required,
2241    they should go in here.
2242    
2243    =cut
2244    
2245    sub HeaderHtml {
2246        return "";
2247    }
2248    
2249  =head3 Form  =head3 Form
2250    
2251      my $html = $shelp->Form();      my $html = $shelp->Form($mode);
2252    
2253  Generate the HTML for a form to request a new search.  Generate the HTML for a form to request a new search. If the subclass does not
2254    override this method, then the search is formless, and must be started from an
2255    external page.
2256    
2257    =cut
2258    
2259    sub Form {
2260        # Get the parameters.
2261        my ($self) = @_;
2262        return "";
2263    }
2264    
2265  =head3 Find  =head3 Find
2266    
# Line 2273  Line 2343 
2343      $rhelp->SetColumns(@cols);      $rhelp->SetColumns(@cols);
2344  }  }
2345    
 =head3 Hint  
2346    
2347      my $htmlText = SearchHelper::Hint($wikiPage, $hintText);  =head3 Initialize
2348    
2349  Return the HTML for a small question mark that displays the specified hint text when it is clicked.      $shelp->Initialize();
 This HTML can be put in forms to provide a useful hinting mechanism.  
2350    
2351  =over 4  Perform any initialization required after construction of the helper.
2352    
2353  =item wikiPage  =cut
2354    
2355  Name of the wiki page to be popped up when the hint mark is clicked.  sub Initialize {
2356        # The default is to do nothing.
2357    }
2358    
2359  =item hintText  =head3 GetResultHelper
2360    
2361  Text to display for the hint. It is raw html, but may not contain any double quotes.      my $rhelp = $shelp->GetResultHelper($className);
2362    
2363    Return a result helper for this search helper. The default action is to create
2364    a result helper from scratch; however, if the subclass has an internal result
2365    helper it can override this method to return it without having to create a new
2366    one.
2367    
2368    =over 4
2369    
2370    =item className
2371    
2372    Result helper class name.
2373    
2374  =item RETURN  =item RETURN
2375    
2376  Returns the html for the hint facility. The resulting html shows a small button-like thing that  Returns a result helper of the specified class connected to this search helper.
 uses the standard FIG popup technology.  
2377    
2378  =back  =back
2379    
2380  =cut  =cut
2381    
2382  sub Hint {  sub GetResultHelper {
2383      # Get the parameters.      # Get the parameters.
2384      my ($wikiPage, $hintText) = @_;      my ($self, $className) = @_;
2385      # Ask Sprout to draw the hint button for us.      # Create the helper.
2386      return Sprout::Hint($wikiPage, $hintText);      my $retVal = GetHelper($self, RH => $className);
2387        # return it.
2388        return $retVal;
2389  }  }
2390    
   
2391  1;  1;

Legend:
Removed from v.1.42  
changed lines
  Added in v.1.46

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3