[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.38, Thu Dec 6 14:58:03 2007 UTC revision 1.41, Wed Sep 3 20:54:47 2008 UTC
# Line 461  Line 461 
461      # case the Advanced button was used.      # case the Advanced button was used.
462      my $retVal = "<div class=\"search\">\n" .      my $retVal = "<div class=\"search\">\n" .
463                   $cgi->start_form(-method => 'POST',                   $cgi->start_form(-method => 'POST',
464                                    -action => $cgi->url(-relative => 1),                                    -action => "$FIG_Config::cgi_url/SearchSkeleton.cgi",
465                                    -name => $self->FormName()) .                                    -name => $self->FormName()) .
466                   $cgi->hidden(-name => 'Class',                   $cgi->hidden(-name => 'Class',
467                                -value => $self->{class},                                -value => $self->{class},
# Line 1052  Line 1052 
1052              push @subs, $classLess;              push @subs, $classLess;
1053          }          }
1054      }      }
1055        # Get the seedviewer URL.
1056        my $svURL = $FIG_Config::linkinSV || "$FIG_Config::cgi_url/seedviewer.cgi";
1057        Trace("Seed Viewer URL is $svURL.") if T(3);
1058      # Declare the return variable.      # Declare the return variable.
1059      my @retVal = ();      my @retVal = ();
1060      # Each element in @subs represents a leaf node, so as we loop through it we will be      # Each element in @subs represents a leaf node, so as we loop through it we will be
# Line 1126  Line 1129 
1129              if ($optionThing->{links}) {              if ($optionThing->{links}) {
1130                  # Compute the link value.                  # Compute the link value.
1131                  my $linkable = uri_escape($id);                  my $linkable = uri_escape($id);
1132                  $nodeContent->{link} = "../FIG/display_subsys.cgi?ssa_name=$linkable;request=show_ssa;sort=by_phylo;show_clusters=1;SPROUT=1";                  $nodeContent->{link} = "$svURL?page=Subsystems;subsystem=$linkable";
1133              }              }
1134              if ($optionThing->{radio}) {              if ($optionThing->{radio}) {
1135                  # Compute the radio value.                  # Compute the radio value.
# Line 1173  Line 1176 
1176    
1177  =item crossMenu (optional)  =item crossMenu (optional)
1178    
1179  If specified, is presumed to be the name of another genome menu whose contents  This is currently not supported.
 are to be mutually exclusive with the contents of this menu. As a result, instead  
 of the standard onChange event, the onChange event will deselect any entries in  
 the other menu.  
1180    
1181  =item RETURN  =item RETURN
1182    
# Line 1196  Line 1196 
1196      if (! defined $rows) {      if (! defined $rows) {
1197          $rows = ($multiple ? 10 : 1);          $rows = ($multiple ? 10 : 1);
1198      }      }
1199      # Create the multiple tag.      # Get a comma-delimited list of the preselected genomes.
1200      my $multipleTag = ($multiple ? " multiple" : "");      my $preselected = "";
1201      # Get the form name.      if ($selected) {
1202      my $formName = $self->FormName();          $preselected = join(", ", @$selected);
1203      # Check to see if we already have a genome list in memory.      }
1204      my $groupHash;      # Ask Sprout for a genome menu.
1205      my @groups;      my $retVal = $sprout->GenomeMenu(name => $menuName,
1206      my $nmpdrGroupCount;                                       multiSelect => $multiple,
1207      my $genomes = $self->{genomeList};                                       selected => $preselected,
1208      if (defined $genomes) {                                       size => $rows);
         # We have a list ready to use.  
         $groupHash = $genomes;  
         @groups = @{$self->{groupList}};  
         $nmpdrGroupCount = $self->{groupCount};  
     } else {  
         # Get a list of all the genomes in group order. In fact, we only need them ordered  
         # by name (genus,species,strain), but putting primary-group in front enables us to  
         # take advantage of an existing index.  
         my @genomeList = $sprout->GetAll(['Genome'],  
                                          "ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",  
                                          [], ['Genome(primary-group)', 'Genome(id)',  
                                               'Genome(genus)', 'Genome(species)',  
                                               'Genome(unique-characterization)',  
                                               'Genome(taxonomy)']);  
         # Create a hash to organize the genomes by group. Each group will contain a list of  
         # 2-tuples, the first element being the genome ID and the second being the genome  
         # name.  
         my %gHash = ();  
         for my $genome (@genomeList) {  
             # Get the genome data.  
             my ($group, $genomeID, $genus, $species, $strain, $taxonomy) = @{$genome};  
             # Compute and cache its name and display group.  
             my ($name, $displayGroup, $domain) = $self->SaveOrganismData($group, $genomeID, $genus, $species,  
                                                                          $strain, $taxonomy);  
             # Push the genome into the group's list. Note that we use the real group  
             # name here, not the display group name.  
             push @{$gHash{$group}}, [$genomeID, $name, $domain];  
         }  
         # We are almost ready to unroll the menu out of the group hash. The final step is to separate  
         # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They  
         # are sorted by the first capitalized word. Groups with "other" are sorted after groups  
         # that aren't "other". At some point, we will want to make this less complicated.  
         my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }  
                              grep { $_ ne $FIG_Config::otherGroup } keys %gHash;  
         @groups = map { $sortGroups{$_} } sort keys %sortGroups;  
         # Remember the number of NMPDR groups.  
         $nmpdrGroupCount = scalar @groups;  
         # Loop through the supporting genomes, classifying them by domain. We'll also keep a list  
         # of the domains found.  
         my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};  
         my @domains = ();  
         for my $genomeData (@otherGenomes) {  
             my ($genomeID, $name, $domain) = @{$genomeData};  
             if (exists $gHash{$domain}) {  
                 push @{$gHash{$domain}}, $genomeData;  
             } else {  
                 $gHash{$domain} = [$genomeData];  
                 push @domains, $domain;  
             }  
         }  
         # Add the domain groups at the end of the main group list. The main group list will now  
         # contain all the categories we need to display the genomes.  
         push @groups, sort @domains;  
         # Delete the supporting group.  
         delete $gHash{$FIG_Config::otherGroup};  
         # Save the genome list for future use.  
         $self->{genomeList} = \%gHash;  
         $self->{groupList} = \@groups;  
         $self->{groupCount} = $nmpdrGroupCount;  
         $groupHash = \%gHash;  
     }  
     # Next, create a hash that specifies the pre-selected entries. Note that we need to deal  
     # with the possibility of undefined values in the incoming list.  
     my %selectedHash = ();  
     if (defined $selected) {  
         %selectedHash = map { $_ => 1 } grep { defined($_) } @{$selected};  
     }  
     # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage  
     # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes  
     # and use that to make the selections.  
     my $nmpdrCount = 0;  
     # Create the type counters.  
     my $groupCount = 1;  
     # Compute the ID for the status display.  
     my $divID = "${formName}_${menuName}_status";  
     # Compute the JavaScript call for updating the status.  
     my $showSelect = "showSelected($menuName, '$divID', 1000);";  
     # If multiple selection is supported, create an onChange event.  
     my $onChange = "";  
     if ($cross) {  
         # Here we have a paired menu. Selecting something in our menu unselects it in the  
         # other and redisplays the status of both.  
         $onChange = " onChange=\"crossUnSelect($menuName, '$divID', $cross, '${formName}_${cross}_status', 1000)\"";  
     } elsif ($multiple) {  
         # This is an unpaired menu, so all we do is redisplay our status.  
         $onChange = " onChange=\"$showSelect\"";  
     }  
     # Create the SELECT tag and stuff it into the output array.  
     my @lines = ("<SELECT name=\"$menuName\"$onChange$multipleTag size=\"$rows\">");  
     # Loop through the groups.  
     for my $group (@groups) {  
         # Create the option group tag.  
         my $tag = "<OPTGROUP label=\"$group\">";  
         push @lines, "  $tag";  
         # Get the genomes in the group.  
         for my $genome (@{$groupHash->{$group}}) {  
             # Count this organism if it's NMPDR.  
             if ($nmpdrGroupCount > 0) {  
                 $nmpdrCount++;  
             }  
             # Get the organism ID, name, and domain.  
             my ($genomeID, $name, $domain) = @{$genome};  
             # See if it's selected.  
             my $select = ($selectedHash{$genomeID} ? " selected" : "");  
             # Generate the option tag.  
             my $optionTag = "<OPTION class=\"$domain\" value=\"$genomeID\"$select>$name <em>($genomeID)</em></OPTION>";  
             push @lines, "    $optionTag";  
         }  
         # Close the option group.  
         push @lines, "  </OPTGROUP>";  
         # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR  
         # groups.  
         $nmpdrGroupCount--;  
     }  
     # Close the SELECT tag.  
     push @lines, "</SELECT>";  
     # Check for multiple selection.  
     if ($multiple) {  
         # Multi-select is on, so we need to add some selection helpers. First is  
         # the search box. This allows the user to type text and have all genomes containing  
         # the text selected automatically.  
         my $searchThingName = "${menuName}_SearchThing";  
         push @lines, "<br />" .  
                      "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />&nbsp;" .  
                      "<INPUT type=\"text\" name=\"$searchThingName\" size=\"30\" />" . Hint("Genome Control",  
                                                                                             "Enter a genome number, then click the button to the left " .  
                                                                                             "in order to select the genome with that number. " .  
                                                                                             "Enter a genus, species, or strain and click the " .  
                                                                                             "button to select all genomes with that genus, species, " .  
                                                                                             "or strain name.");  
         # Next are the buttons to set and clear selections.  
         push @lines, "<br />";  
         push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";  
         push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll($menuName); $showSelect\" />";  
         push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome($menuName, $nmpdrCount, true); $showSelect\" />";  
         # push @lines, "<INPUT type=\"button\" name=\"OtherOnly\" class=\"bigButton\" value=\"Select Supporting\" onClick=\"selectSome($menuName, $nmpdrCount, false); $showSelect\" />";  
         # Add the status display, too.  
         push @lines, "<DIV id=\"$divID\" class=\"selectStatus\"></DIV>";  
         # Queue to update the status display when the form loads. We need to modify the show statement  
         # slightly because the queued statements are executed outside the form. This may seem like a lot of  
         # trouble, but we want all of the show statement calls to be generated from a single line of code,  
         # in case we decide to twiddle the parameters.  
         $showSelect =~ s/showSelected\(/showSelected\(thisForm\./;  
         $self->QueueFormScript($showSelect);  
         # Finally, add this parameter to the list of genome parameters. This enables us to  
         # easily find all the parameters used to select one or more genomes.  
         push @{$self->{genomeParms}}, $menuName;  
     }  
     # Assemble all the lines into a string.  
     my $retVal = join("\n", @lines, "");  
1209      # Return the result.      # Return the result.
1210      return $retVal;      return $retVal;
1211  }  }
# Line 1512  Line 1362 
1362                                     $cgi->popup_menu(-name => 'AliasType',                                     $cgi->popup_menu(-name => 'AliasType',
1363                                                      -values => ['FIG', AliasAnalysis::AliasTypes() ],                                                      -values => ['FIG', AliasAnalysis::AliasTypes() ],
1364                                                      -default => $aliasType) .                                                      -default => $aliasType) .
1365                                     Hint("Identifier type", "Specify how you want gene names to be displayed."))) .                                     Hint("Identifier Type", "Specify how you want gene names to be displayed."))) .
1366                   "\n" .                   "\n" .
1367                   $cgi->Tr($cgi->td("Results/Page"),                   $cgi->Tr($cgi->td("Results/Page"),
1368                            $cgi->td($cgi->popup_menu(-name => 'PageSize',                            $cgi->td($cgi->popup_menu(-name => 'PageSize',
# Line 1569  Line 1419 
1419      return @retVal;      return @retVal;
1420  }  }
1421    
 =head3 GetHelpText  
   
     my $htmlText = $shelp->GetHelpText();  
   
 Get the help text for this search. The help text is stored in files on the template  
 server. The help text for a specific search is taken from a file named  
 C<SearchHelp_>I<class>C<.inc> in the template directory C<$FIG_Config::template_url>.  
 There are also three standard help files: C<SearchHelp1_Filtering.inc> describes the  
 feature filtering performed by the B<RHFeatures> object, C<SearchHelp1_GenomeControl.inc>  
 describes how to use a multiple-selection genome control, and C<SearchHelp1_Standard.inc>  
 describes the standard controls for a search, such as page size, URL display, and  
 external alias display.  
   
 =cut  
   
 sub GetHelpText {  
     # Get the parameters.  
     my ($self) = @_;  
     # Create a list to hold the pieces of the help.  
     my @helps = ();  
     # Get the template directory URL.  
     my $urlBase = $FIG_Config::template_url;  
     # Start with the specific help.  
     my $class = $self->{class};  
     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp_$class.inc");  
     # Add the genome control help if needed.  
     if (scalar @{$self->{genomeParms}}) {  
         push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_GenomeControl.inc");  
     }  
     # Next the filter help.  
     if ($self->{filtered}) {  
         push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_Filtering.inc");  
     }  
     # Finally, the standard help.  
     push @helps, PageBuilder::GetPage("$urlBase/SearchHelp1_Standard.inc");  
     # Assemble the pieces.  
     my $retVal = join("\n<p>&nbsp;</p>\n", @helps);  
     # Return the result.  
     return $retVal;  
 }  
   
1422  =head3 ComputeSearchURL  =head3 ComputeSearchURL
1423    
1424      my $url = $shelp->ComputeSearchURL(%overrides);      my $url = $shelp->ComputeSearchURL(%overrides);
# Line 1645  Line 1454 
1454      my $cgi = $self->Q();      my $cgi = $self->Q();
1455      my $sprout = $self->DB();      my $sprout = $self->DB();
1456      # Start with the full URL.      # Start with the full URL.
1457      my $retVal = $cgi->url(-full => 1);      my $retVal = "$FIG_Config::cgi_url/SearchSkeleton.cgi";
1458      # Get all the query parameters in a hash.      # Get all the query parameters in a hash.
1459      my %parms = $cgi->Vars();      my %parms = $cgi->Vars();
1460      # Now we need to do some fixing. Each multi-valued parameter is encoded as a string with null      # Now we need to do some fixing. Each multi-valued parameter is encoded as a string with null
# Line 1837  Line 1646 
1646  =item nodeImageClosed  =item nodeImageClosed
1647    
1648  URL of the image to display next to the tree nodes when they are collapsed. Clicking  URL of the image to display next to the tree nodes when they are collapsed. Clicking
1649  on the image will expand a section of the tree. The default is C<../FIG/Html/plus.gif>.  on the image will expand a section of the tree. The default is C<plus.gif>.
1650    
1651  =item nodeImageOpen  =item nodeImageOpen
1652    
1653  URL of the image to display next to the tree nodes when they are expanded. Clicking  URL of the image to display next to the tree nodes when they are expanded. Clicking
1654  on the image will collapse a section of the tree. The default is C<../FIG/Html/minus.gif>.  on the image will collapse a section of the tree. The default is C<minus.gif>.
1655    
1656  =item style  =item style
1657    
# Line 1882  Line 1691 
1691      my ($cgi, $tree, %options) = @_;      my ($cgi, $tree, %options) = @_;
1692      # Get the options.      # Get the options.
1693      my $optionThing = Tracer::GetOptions({ name => 'selection',      my $optionThing = Tracer::GetOptions({ name => 'selection',
1694                                             nodeImageClosed => '../FIG/Html/plus.gif',                                             nodeImageClosed => "$FIG_Config::cgi_url/Html/plus.gif",
1695                                             nodeImageOpen => '../FIG/Html/minus.gif',                                             nodeImageOpen => "$FIG_Config::cgi_url/Html/minus.gif",
1696                                             style => 'tree',                                             style => 'tree',
1697                                             target => '_self',                                             target => '_self',
1698                                             selected => undef},                                             selected => undef},
# Line 2467  Line 2276 
2276    
2277  =item wikiPage  =item wikiPage
2278    
2279  Name of the wiki page to be popped up when the hint maek is clicked.  Name of the wiki page to be popped up when the hint mark is clicked.
2280    
2281  =item hintText  =item hintText
2282    
# Line 2485  Line 2294 
2294  sub Hint {  sub Hint {
2295      # Get the parameters.      # Get the parameters.
2296      my ($wikiPage, $hintText) = @_;      my ($wikiPage, $hintText) = @_;
2297      # Escape the single quotes in the hint text.      # Ask Sprout to draw the hint button for us.
2298      my $quotedText = $hintText;      return Sprout::Hint($wikiPage, $hintText);
     $quotedText =~ s/'/\\'/g;  
     # Convert the wiki page name to a URL.  
     my $wikiURL = ucfirst $wikiPage;  
     $wikiURL =~ s/ /_/g;  
     $wikiURL = "../wiki/index.php/$wikiURL";  
     # Create the html.  
     my $retVal = "&nbsp;<input type=\"button\" class=\"hintbutton\" onMouseOver=\"javascript:if (!this.tooltip) { " .  
                  "this.tooltip = new Popup_Tooltip(this, 'Search Hint', '$quotedText', '', 1); this.tooltip.addHandler(); } " .  
                  "return false;\" value=\"?\" onClick=\"javascript:window.open('$wikiURL', 'nmpdrHelp');\" />";  
     # Return it.  
     return $retVal;  
2299  }  }
2300    
2301    

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.41

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3