[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.40, Tue Apr 29 20:52:05 2008 UTC revision 1.42, Fri Oct 17 16:41: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 833  Line 833 
833    
834  =head3 ComputeFASTA  =head3 ComputeFASTA
835    
836      my $fasta = $shelp->ComputeFASTA($desiredType, $sequence, $flankingWidth);      my $fasta = $shelp->ComputeFASTA($desiredType, $sequence, $flankingWidth, $comments);
837    
838  Parse a sequence input and convert it into a FASTA string of the desired type with  Parse a sequence input and convert it into a FASTA string of the desired type with
839  the desired flanking width.  the desired flanking width.
# Line 860  Line 860 
860  protein translation of a feature doesn't always match the DNA and is taken directly  protein translation of a feature doesn't always match the DNA and is taken directly
861  from the database.  from the database.
862    
863    =item comments
864    
865    Comment string to be added to the FASTA header.
866    
867  =item RETURN  =item RETURN
868    
869  Returns a string in FASTA format representing the content of the desired sequence with  Returns a string in FASTA format representing the content of the desired sequence with
# Line 872  Line 876 
876    
877  sub ComputeFASTA {  sub ComputeFASTA {
878      # Get the parameters.      # Get the parameters.
879      my ($self, $desiredType, $sequence, $flankingWidth) = @_;      my ($self, $desiredType, $sequence, $flankingWidth, $comment) = @_;
880      # Declare the return variable. If an error occurs, it will remain undefined.      # Declare the return variable. If an error occurs, it will remain undefined.
881      my $retVal;      my $retVal;
882      # This variable will be cleared if an error is detected.      # This variable will be cleared if an error is detected.
# Line 903  Line 907 
907                  # In an emergency, fall back to the original ID.                  # In an emergency, fall back to the original ID.
908                  $fastaLabel = $fid;                  $fastaLabel = $fid;
909              }              }
910                # Add any specified comments.
911                if ($comment) {
912                    $fastaLabel .= " $comment";
913                }
914              # Now proceed according to the sequence type.              # Now proceed according to the sequence type.
915              if ($desiredType =~ /prot/) {              if ($desiredType =~ /prot/) {
916                  # We want protein, so get the translation.                  # We want protein, so get the translation.
# Line 1052  Line 1060 
1060              push @subs, $classLess;              push @subs, $classLess;
1061          }          }
1062      }      }
1063        # Get the seedviewer URL.
1064        my $svURL = $FIG_Config::linkinSV || "$FIG_Config::cgi_url/seedviewer.cgi";
1065        Trace("Seed Viewer URL is $svURL.") if T(3);
1066      # Declare the return variable.      # Declare the return variable.
1067      my @retVal = ();      my @retVal = ();
1068      # 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 1137 
1137              if ($optionThing->{links}) {              if ($optionThing->{links}) {
1138                  # Compute the link value.                  # Compute the link value.
1139                  my $linkable = uri_escape($id);                  my $linkable = uri_escape($id);
1140                  $nodeContent->{link} = "../FIG/seedviewer.cgi?page=Subsystems;subsystem=$linkable";                  $nodeContent->{link} = "$svURL?page=Subsystems;subsystem=$linkable";
1141              }              }
1142              if ($optionThing->{radio}) {              if ($optionThing->{radio}) {
1143                  # Compute the radio value.                  # Compute the radio value.
# Line 1173  Line 1184 
1184    
1185  =item crossMenu (optional)  =item crossMenu (optional)
1186    
1187  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.  
1188    
1189  =item RETURN  =item RETURN
1190    
# Line 1196  Line 1204 
1204      if (! defined $rows) {      if (! defined $rows) {
1205          $rows = ($multiple ? 10 : 1);          $rows = ($multiple ? 10 : 1);
1206      }      }
1207      # Create the multiple tag.      # Get a comma-delimited list of the preselected genomes.
1208      my $multipleTag = ($multiple ? " multiple" : "");      my $preselected = "";
1209      # Get the form name.      if ($selected) {
1210      my $formName = $self->FormName();          $preselected = join(", ", @$selected);
1211      # Check to see if we already have a genome list in memory.      }
1212      my $groupHash;      # Ask Sprout for a genome menu.
1213      my @groups;      my $retVal = $sprout->GenomeMenu(name => $menuName,
1214      my $nmpdrGroupCount;                                       multiSelect => $multiple,
1215      my $genomes = $self->{genomeList};                                       selected => $preselected,
1216      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, "");  
1217      # Return the result.      # Return the result.
1218      return $retVal;      return $retVal;
1219  }  }
# Line 1569  Line 1427 
1427      return @retVal;      return @retVal;
1428  }  }
1429    
 =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;  
 }  
   
1430  =head3 ComputeSearchURL  =head3 ComputeSearchURL
1431    
1432      my $url = $shelp->ComputeSearchURL(%overrides);      my $url = $shelp->ComputeSearchURL(%overrides);
# Line 1645  Line 1462 
1462      my $cgi = $self->Q();      my $cgi = $self->Q();
1463      my $sprout = $self->DB();      my $sprout = $self->DB();
1464      # Start with the full URL.      # Start with the full URL.
1465      my $retVal = $cgi->url(-full => 1);      my $retVal = "$FIG_Config::cgi_url/SearchSkeleton.cgi";
1466      # Get all the query parameters in a hash.      # Get all the query parameters in a hash.
1467      my %parms = $cgi->Vars();      my %parms = $cgi->Vars();
1468      # 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 1654 
1654  =item nodeImageClosed  =item nodeImageClosed
1655    
1656  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
1657  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>.
1658    
1659  =item nodeImageOpen  =item nodeImageOpen
1660    
1661  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
1662  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>.
1663    
1664  =item style  =item style
1665    
# Line 1882  Line 1699 
1699      my ($cgi, $tree, %options) = @_;      my ($cgi, $tree, %options) = @_;
1700      # Get the options.      # Get the options.
1701      my $optionThing = Tracer::GetOptions({ name => 'selection',      my $optionThing = Tracer::GetOptions({ name => 'selection',
1702                                             nodeImageClosed => '../FIG/Html/plus.gif',                                             nodeImageClosed => "$FIG_Config::cgi_url/Html/plus.gif",
1703                                             nodeImageOpen => '../FIG/Html/minus.gif',                                             nodeImageOpen => "$FIG_Config::cgi_url/Html/minus.gif",
1704                                             style => 'tree',                                             style => 'tree',
1705                                             target => '_self',                                             target => '_self',
1706                                             selected => undef},                                             selected => undef},
# Line 2012  Line 1829 
1829                      # If we have children, create the child list with a recursive call.                      # If we have children, create the child list with a recursive call.
1830                      if ($hasChildren) {                      if ($hasChildren) {
1831                          Trace("Processing children of $myLabel.") if T(4);                          Trace("Processing children of $myLabel.") if T(4);
1832                          push @childHtml, ShowBranch($cgi, $myLabel, $myID, $myContent, $options, 'none');                          push @childHtml, ShowBranch($cgi, $myLabel, $myID, $myContent, $options, 'block');
1833                          Trace("Children of $myLabel finished.") if T(4);                          Trace("Children of $myLabel finished.") if T(4);
1834                      }                      }
1835                  }                  }
# Line 2485  Line 2302 
2302  sub Hint {  sub Hint {
2303      # Get the parameters.      # Get the parameters.
2304      my ($wikiPage, $hintText) = @_;      my ($wikiPage, $hintText) = @_;
2305      # Escape the single quotes in the hint text.      # Ask Sprout to draw the hint button for us.
2306      my $quotedText = $hintText;      return Sprout::Hint($wikiPage, $hintText);
     $quotedText =~ s/'/\\'/g;  
     # Convert the wiki page name to a URL.  
     my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);  
     $wikiURL = "wiki/view.cgi/FIG/$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;  
2307  }  }
2308    
2309    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3