[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.11, Mon Oct 16 07:44:13 2006 UTC revision 1.15, Fri Nov 10 22:01:36 2006 UTC
# Line 113  Line 113 
113    
114  =item 4  =item 4
115    
116  In the C<SearchSkeleton.cgi> script, add a C<use> statement for your search tool  In the C<SearchSkeleton.cgi> script and add a C<use> statement for your search tool.
 and then put the class name in the C<@advancedClasses> list.  
117    
118  =back  =back
119    
# Line 177  Line 176 
176    
177  =back  =back
178    
179    If you are doing a feature search, you can also change the list of feature
180    columns displayed and their display order by overriding
181    L</DefaultFeatureColumns>.
182    
183  Finally, when generating the code for your controls, be sure to use any incoming  Finally, when generating the code for your controls, be sure to use any incoming
184  query parameters as default values so that the search request is persistent.  query parameters as default values so that the search request is persistent.
185    
# Line 222  Line 225 
225      }      }
226    
227  A Find method is of course much more complicated than generating a form, and there  A Find method is of course much more complicated than generating a form, and there
228  are variations on the above them. For example, you could eschew feature filtering  are variations on the above theme. For example, you could eschew feature filtering
229  entirely in favor of your own custom filtering, you could include extra columns  entirely in favor of your own custom filtering, you could include extra columns
230  in the output, or you could search for something that's not a feature at all. The  in the output, or you could search for something that's not a feature at all. The
231  above code is just a loose framework.  above code is just a loose framework.
# Line 654  Line 657 
657      my $extraCols = $fd->ExtraCols();      my $extraCols = $fd->ExtraCols();
658      # Check for a first-call situation.      # Check for a first-call situation.
659      if (! defined $self->{cols}) {      if (! defined $self->{cols}) {
660          # Here we need to set up the column information. Start with the defaults.          Trace("Setting up the columns.") if T(3);
661          $self->{cols} = $self->DefaultFeatureColumns();          # Here we need to set up the column information. Start with the extras,
662          # Add any additional columns requested by the feature filter.          # sorted by column name.
663          push @{$self->{cols}}, FeatureQuery::AdditionalColumns($self);          my @colNames = ();
         # Append the extras, sorted by column name.  
664          for my $col (sort keys %{$extraCols}) {          for my $col (sort keys %{$extraCols}) {
665              push @{$self->{cols}}, "X=$col";              push @colNames, "X=$col";
666          }          }
667            # Add the default columns.
668            push @colNames, $self->DefaultFeatureColumns();
669            # Add any additional columns requested by the feature filter.
670            push @colNames, FeatureQuery::AdditionalColumns($self);
671            # Save the full list.
672            $self->{cols} = \@colNames;
673          # Write out the column headers. This also prepares the cache file to receive          # Write out the column headers. This also prepares the cache file to receive
674          # output.          # output.
675          $self->WriteColumnHeaders(map { $self->FeatureColumnTitle($_) } @{$self->{cols}});          $self->WriteColumnHeaders(map { $self->FeatureColumnTitle($_) } @{$self->{cols}});
# Line 1163  Line 1171 
1171      if (defined $selected) {      if (defined $selected) {
1172          %selectedHash = map { $_ => 1 } grep { defined($_) } @{$selected};          %selectedHash = map { $_ => 1 } grep { defined($_) } @{$selected};
1173      }      }
1174      # Now it gets complicated. We need a way to mark all the NMPDR genomes.      # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
1175        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
1176        # and use that to make the selections.
1177        my $nmpdrCount = 0;
1178      # Create the type counters.      # Create the type counters.
1179      my $groupCount = 1;      my $groupCount = 1;
1180      # Compute the ID for the status display.      # Compute the ID for the status display.
# Line 1173  Line 1184 
1184      # If multiple selection is supported, create an onChange event.      # If multiple selection is supported, create an onChange event.
1185      my $onChange = "";      my $onChange = "";
1186      if ($cross) {      if ($cross) {
1187            # Here we have a paired menu. Selecting something in our menu unselects it in the
1188            # other and redisplays the status of both.
1189          $onChange = " onChange=\"crossUnSelect($menuName, '$divID', $cross, '${formName}_${cross}_status', 1000)\"";          $onChange = " onChange=\"crossUnSelect($menuName, '$divID', $cross, '${formName}_${cross}_status', 1000)\"";
1190      } elsif ($multiple) {      } elsif ($multiple) {
1191            # This is an unpaired menu, so all we do is redisplay our status.
1192          $onChange = " onChange=\"$showSelect\"";          $onChange = " onChange=\"$showSelect\"";
1193      }      }
1194      # Create the SELECT tag and stuff it into the output array.      # Create the SELECT tag and stuff it into the output array.
1195      my $select = "<SELECT name=\"$menuName\"$onChange$multipleTag size=\"$rows\">";      my @lines = ("<SELECT name=\"$menuName\"$onChange$multipleTag size=\"$rows\">");
     my @lines = ($select);  
1196      # Loop through the groups.      # Loop through the groups.
1197      for my $group (@groups) {      for my $group (@groups) {
1198          # Create the option group tag.          # Create the option group tag.
1199          my $tag = "<OPTGROUP label=\"$group\">";          my $tag = "<OPTGROUP label=\"$group\">";
1200          push @lines, "  $tag";          push @lines, "  $tag";
         # Compute the label for this group's options. This is seriously dirty stuff, as the  
         # label option may have functionality in future browsers. If that happens, we'll need  
         # to modify the genome text so that the "selectSome" method can tell which are NMPDR  
         # organisms and which aren't. Sadly, the OPTGROUP tag is invisible in the DOM Javascript  
         # hierarchy, so we can't use it.  
         my $label = ($group eq $FIG_Config::otherGroup ? "other" : "nmpdr");  
1201          # Get the genomes in the group.          # Get the genomes in the group.
1202          for my $genome (@{$groupHash->{$group}}) {          for my $genome (@{$groupHash->{$group}}) {
1203                # Count this organism if it's NMPDR.
1204                if ($group ne $FIG_Config::otherGroup) {
1205                    $nmpdrCount++;
1206                }
1207                # Get the organism ID and name.
1208              my ($genomeID, $name) = @{$genome};              my ($genomeID, $name) = @{$genome};
1209              # See if it's selected.              # See if it's selected.
1210              my $select = ($selectedHash{$genomeID} ? " selected" : "");              my $select = ($selectedHash{$genomeID} ? " selected" : "");
1211              # Generate the option tag.              # Generate the option tag.
1212              my $optionTag = "<OPTION value=\"$genomeID\" label=\"$label\"$select>$name <em>($genomeID)</em></OPTION>";              my $optionTag = "<OPTION value=\"$genomeID\"$select>$name <em>($genomeID)</em></OPTION>";
1213              push @lines, "    $optionTag";              push @lines, "    $optionTag";
1214          }          }
1215          # Close the option group.          # Close the option group.
# Line 1207  Line 1219 
1219      push @lines, "</SELECT>";      push @lines, "</SELECT>";
1220      # Check for multiple selection.      # Check for multiple selection.
1221      if ($multiple) {      if ($multiple) {
1222          # Since multi-select is on, we set up some buttons to set and clear selections.          # Multi-select is on, so we need to add some selection helpers. First is
1223          push @lines, "<br />";          # the search box. This allows the user to type text and have all genomes containing
         push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll($menuName); $showSelect\" />";  
         push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";  
         push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome($menuName, 'nmpdr'); $showSelect\" />";  
         push @lines, "<INPUT type=\"button\" name=\"OtherOnly\" class=\"bigButton\" value=\"Select Supporting\" onClick=\"selectSome($menuName, 'other'); $showSelect\" />";  
         # Now add the search box. This allows the user to type text and have all genomes containing  
1224          # the text selected automatically.          # the text selected automatically.
1225          my $searchThingName = "${menuName}_SearchThing";          my $searchThingName = "${menuName}_SearchThing";
1226          push @lines, "<br>Select genomes containing <INPUT type=\"text\" name=\"$searchThingName\" size=\"30\" />&nbsp;" .          push @lines, "<br>Select genomes containing <INPUT type=\"text\" name=\"$searchThingName\" " .
1227                       "<INPUT type=\"button\" name=\"Select\" class=\"button\" value=\"Search\" onClick=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />";                       "size=\"30\" onBlur=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />";
1228            # Next are the buttons to set and clear selections.
1229            push @lines, "<br />";
1230            push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";
1231            push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll($menuName); $showSelect\" />";
1232            push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome($menuName, $nmpdrCount, true); $showSelect\" />";
1233            push @lines, "<INPUT type=\"button\" name=\"OtherOnly\" class=\"bigButton\" value=\"Select Supporting\" onClick=\"selectSome($menuName, $nmpdrCount, false); $showSelect\" />";
1234          # Add the status display, too.          # Add the status display, too.
1235          push @lines, "<DIV id=\"$divID\" class=\"selectStatus\"></DIV>";          push @lines, "<DIV id=\"$divID\" class=\"selectStatus\"></DIV>";
1236          # Queue to update the status display when the form loads. We need to modify the show statement          # Queue to update the status display when the form loads. We need to modify the show statement
# Line 1590  Line 1603 
1603          # a singleton list, but that's okay.          # a singleton list, but that's okay.
1604          my @values = split (/\0/, $parms{$parmKey});          my @values = split (/\0/, $parms{$parmKey});
1605          # Check for special cases.          # Check for special cases.
1606          if ($parmKey eq 'featureTypes') {          if (grep { $_ eq $parmKey } qw(SessionID ResultCount Page PageSize Trace TF ShowURL)) {
             # Here we need to see if the user wants all the feature types. If he  
             # does, we erase all the values so that the parameter is not output.  
             my %valueCheck = map { $_ => 1 } @values;  
             my @list = FeatureQuery::AllFeatureTypes();  
             my $okFlag = 1;  
             for (my $i = 0; $okFlag && $i <= $#list; $i++) {  
                 if (! $valueCheck{$list[$i]}) {  
                     $okFlag = 0;  
                 }  
             }  
             if ($okFlag) {  
                 @values = ();  
             }  
         } elsif (grep { $_ eq $parmKey } qw(SessionID ResultCount Page PageSize Trace TF ShowURL)) {  
1607              # These are bookkeeping parameters we don't need to start a search.              # These are bookkeeping parameters we don't need to start a search.
1608              @values = ();              @values = ();
1609          } elsif ($parmKey =~ /_SearchThing$/) {          } elsif ($parmKey =~ /_SearchThing$/) {
# Line 1666  Line 1665 
1665      return $retVal;      return $retVal;
1666  }  }
1667    
 =head3 FeatureTypeMap  
   
 C<< my %features = SearchHelper::FeatureTypeMap(); >>  
   
 Return a map of feature types to descriptions. The feature type data is stored  
 in the B<FIG_Config> file. Currently, it only contains a space-delimited list of  
 feature types. The map returned by this method is a hash mapping the type codes to  
 descriptive names.  
   
 The reason we have to convert the list from a string is that the B<NMPDRSetup.pl>  
 script is only able to insert strings into the generated B<FIG_Config> file.  
   
 =cut  
   
 sub FeatureTypeMap {  
     my @list = split /\s+/, $FIG_Config::feature_types;  
     my %retVal = map { $_ => $_ } @list;  
     return %retVal;  
 }  
   
1668  =head3 AdvancedClassList  =head3 AdvancedClassList
1669    
1670  C<< my @classes = SearchHelper::AdvancedClassList(); >>  C<< my @classes = SearchHelper::AdvancedClassList(); >>
# Line 1693  Line 1672 
1672  Return a list of advanced class names. This list is used to generate the directory  Return a list of advanced class names. This list is used to generate the directory
1673  of available searches on the search page.  of available searches on the search page.
1674    
1675  The reason we have to convert the list from a string is that the B<NMPDRSetup.pl>  We use the %INC variable to accomplish this.
 script is only able to insert strings into the generated B<FIG_Config> file.  
1676    
1677  =cut  =cut
1678    
1679  sub AdvancedClassList {  sub AdvancedClassList {
1680      return split /\s+/, $FIG_Config::advanced_classes;      my @retVal = map { $_ =~ /^SH(\w+)\.pm/; $1 } grep { $_ =~ /^SH/ } keys %INC;
1681        return @retVal;
1682  }  }
1683    
1684  =head2 Feature Column Methods  =head2 Feature Column Methods
# Line 1722  Line 1701 
1701    
1702  =head3 DefaultFeatureColumns  =head3 DefaultFeatureColumns
1703    
1704  C<< my $colNames = $shelp->DefaultFeatureColumns(); >>  C<< my @colNames = $shelp->DefaultFeatureColumns(); >>
1705    
1706  Return a reference to a list of the default feature column identifiers. These  Return a list of the default feature column identifiers. These identifiers can
1707  identifiers can be passed to L</FeatureColumnTitle> and L</FeatureColumnValue> in  be passed to L</FeatureColumnTitle> and L</FeatureColumnValue> in order to
1708  order to produce the column titles and row values.  produce the column titles and row values.
1709    
1710  =cut  =cut
1711    
# Line 1734  Line 1713 
1713      # Get the parameters.      # Get the parameters.
1714      my ($self) = @_;      my ($self) = @_;
1715      # Return the result.      # Return the result.
1716      return ['orgName', 'function', 'gblink', 'protlink',      return qw(orgName function gblink protlink);
             FeatureQuery::AdditionalColumns($self)];  
1717  }  }
1718    
1719  =head3 FeatureColumnTitle  =head3 FeatureColumnTitle
# Line 1767  Line 1745 
1745      if ($colName =~ /^X=(.+)$/) {      if ($colName =~ /^X=(.+)$/) {
1746          # Here we have an extra column.          # Here we have an extra column.
1747          $retVal = $1;          $retVal = $1;
     } elsif ($colName eq 'orgName') {  
         $retVal = "Name";  
     } elsif ($colName eq 'fid') {  
         $retVal = "FIG ID";  
1748      } elsif ($colName eq 'alias') {      } elsif ($colName eq 'alias') {
1749          $retVal = "External Aliases";          $retVal = "External Aliases";
1750        } elsif ($colName eq 'fid') {
1751            $retVal = "FIG ID";
1752      } elsif ($colName eq 'function') {      } elsif ($colName eq 'function') {
1753          $retVal = "Functional Assignment";          $retVal = "Functional Assignment";
1754      } elsif ($colName eq 'gblink') {      } elsif ($colName eq 'gblink') {
1755          $retVal = "GBrowse";          $retVal = "GBrowse";
     } elsif ($colName eq 'protlink') {  
         $retVal = "NMPDR Protein Page";  
1756      } elsif ($colName eq 'group') {      } elsif ($colName eq 'group') {
1757          $retVal = "NMDPR Group";          $retVal = "NMDPR Group";
1758        } elsif ($colName =~ /^keyword:(.+)$/) {
1759            $retVal = ucfirst $1;
1760        } elsif ($colName eq 'orgName') {
1761            $retVal = "Feature Name";
1762        } elsif ($colName eq 'protlink') {
1763            $retVal = "NMPDR Protein Page";
1764        } elsif ($colName eq 'subsystem') {
1765            $retVal = "Subsystems";
1766      }      }
1767      # Return the result.      # Return the result.
1768      return $retVal;      return $retVal;
1769  }  }
1770    
1771    
1772  =head3 FeatureColumnValue  =head3 FeatureColumnValue
1773    
1774  C<< my $value = $shelp->FeatureColumnValue($colName, $fid, \%extraCols); >>  C<< my $value = $shelp->FeatureColumnValue($colName, $fid, \%extraCols); >>
# Line 1836  Line 1819 
1819          if (defined $extraCols->{$1}) {          if (defined $extraCols->{$1}) {
1820              $retVal = $extraCols->{$1};              $retVal = $extraCols->{$1};
1821          }          }
     } elsif ($colName eq 'orgName') {  
         # Here we want the formatted organism name and feature number.  
         $retVal = $self->FeatureName($fid);  
     } elsif ($colName eq 'fid') {  
         # Here we have the raw feature ID. We hyperlink it to the protein page.  
         $retVal = HTML::set_prot_links($fid);  
1822      } elsif ($colName eq 'alias') {      } elsif ($colName eq 'alias') {
1823          # In this case, the user wants a list of external aliases for the feature.          # In this case, the user wants a list of external aliases for the feature.
1824          # These are very expensive, so we compute them when the row is displayed.          # These are very expensive, so we compute them when the row is displayed.
1825          $retVal = "%%aliases=$fid";          $retVal = "%%alias=$fid";
1826        } elsif ($colName eq 'fid') {
1827            # Here we have the raw feature ID. We hyperlink it to the protein page.
1828            $retVal = HTML::set_prot_links($fid);
1829      } elsif ($colName eq 'function') {      } elsif ($colName eq 'function') {
1830          # The functional assignment is just a matter of getting some text.          # The functional assignment is just a matter of getting some text.
1831          ($retVal) = $record->Value('Feature(assignment)');          ($retVal) = $record->Value('Feature(assignment)');
# Line 1856  Line 1836 
1836                            $cgi->img({ src => "../images/button-gbrowse.png",                            $cgi->img({ src => "../images/button-gbrowse.png",
1837                                        border => 0 })                                        border => 0 })
1838                           );                           );
     } elsif ($colName eq 'protlink') {  
         # Here we want a link to the protein page using the official NMPDR button.  
         my $hurl = HTML::fid_link($cgi, $fid, 0, 1);  
         $retVal = $cgi->a({ href => $hurl, title => "Protein page for $fid" },  
                           $cgi->img({ src => "../images/button-nmpdr.png",  
                                      border => 0 })  
                          );  
1839      } elsif ($colName eq 'group') {      } elsif ($colName eq 'group') {
1840          # Get the NMPDR group name.          # Get the NMPDR group name.
1841          my (undef, $group) = $self->OrganismData($fid);          my (undef, $group) = $self->OrganismData($fid);
# Line 1870  Line 1843 
1843          my $nurl = $sprout->GroupPageName($group);          my $nurl = $sprout->GroupPageName($group);
1844          $retVal = $cgi->a({ href => $nurl, title => "$group summary" },          $retVal = $cgi->a({ href => $nurl, title => "$group summary" },
1845                            $group);                            $group);
1846        } elsif ($colName =~ /^keyword:(.+)$/) {
1847            # Here we want keyword-related values. This is also expensive, so
1848            # we compute them when the row is displayed.
1849            $retVal = "%%$colName=$fid";
1850        } elsif ($colName eq 'orgName') {
1851            # Here we want the formatted organism name and feature number.
1852            $retVal = $self->FeatureName($fid);
1853        } elsif ($colName eq 'protlink') {
1854            # Here we want a link to the protein page using the official NMPDR button.
1855            my $hurl = HTML::fid_link($cgi, $fid, 0, 1);
1856            $retVal = $cgi->a({ href => $hurl, title => "Protein page for $fid" },
1857                              $cgi->img({ src => "../images/button-nmpdr.png",
1858                                         border => 0 })
1859                             );
1860        }elsif ($colName eq 'subsystem') {
1861            # Another run-time column: subsystem list.
1862            $retVal = "%%subsystem=$fid";
1863      }      }
1864      # Return the result.      # Return the result.
1865      return $retVal;      return $retVal;
# Line 1908  Line 1898 
1898      # Get the Sprout and CGI objects.      # Get the Sprout and CGI objects.
1899      my $sprout = $self->DB();      my $sprout = $self->DB();
1900      my $cgi = $self->Q();      my $cgi = $self->Q();
1901        Trace("Runtime column $type with text \"$text\" found.") if T(4);
1902      # Separate the text into a type and data.      # Separate the text into a type and data.
1903      if ($type eq 'aliases') {      if ($type eq 'alias') {
1904          # Here the caller wants external alias links for a feature. The text          # Here the caller wants external alias links for a feature. The text
1905          # is the feature ID.          # is the feature ID.
1906          my $fid = $text;          my $fid = $text;
# Line 1924  Line 1915 
1915              # Ask the HTML processor to hyperlink them.              # Ask the HTML processor to hyperlink them.
1916              $retVal = HTML::set_prot_links($cgi, $aliasList);              $retVal = HTML::set_prot_links($cgi, $aliasList);
1917          }          }
1918        } elsif ($type eq 'subsystem') {
1919            # Here the caller wants the subsystems in which this feature participates.
1920            # The text is the feature ID. We will list the subsystem names with links
1921            # to the subsystem's summary page.
1922            my $fid = $text;
1923            # Get the subsystems.
1924            Trace("Generating subsystems for feature $fid.") if T(4);
1925            my %subs = $sprout->SubsystemsOf($fid);
1926            # Convert them to links.
1927            my @links = map { HTML::sub_link($cgi, $_) } sort keys %subs;
1928            # String them into a list.
1929            $retVal = join(", ", @links);
1930        } elsif ($type =~ /^keyword:(.+)$/) {
1931            # Here the caller wants the value of the named keyword. The text is the
1932            # feature ID.
1933            my $keywordName = $1;
1934            my $fid = $text;
1935            # Get the attribute values.
1936            Trace("Getting $keywordName values for feature $fid.") if T(4);
1937            my @values = $sprout->GetFlat(['Feature'], "Feature(id) = ?", [$fid],
1938                                          "Feature($keywordName)");
1939            # String them into a list.
1940            $retVal = join(", ", @values);
1941      }      }
1942      # Return the result.      # Return the result.
1943      return $retVal;      return $retVal;

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3