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

Diff of /Sprout/Sprout.pm

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

revision 1.86, Sun Sep 24 17:14:16 2006 UTC revision 1.87, Tue Sep 26 13:46:03 2006 UTC
# Line 438  Line 438 
438      $self->CreateTables();      $self->CreateTables();
439  }  }
 =head3 NmpdrGenomeMenu  
 C<< my $htmlText = $sprout->NmpdrGenomeMenu(\%options, \@selected); >>  
 This method creates a hierarchical HTML menu for NMPDR genomes organized by category. The  
 category indicates the low-level NMPDR group. Organizing the genomes in this way makes it  
 easier to select all genomes from a particular category.  
 =over 4  
 =item options  
 Reference to a hash containing the options to be applied to the C<SELECT> tag form the menu.  
 Typical options would include C<name> to specify the field name, C<multiple> to specify  
 that multiple selections are allowed, and C<size> to set the number of rows to display  
 in the menu.  
 =item selected  
 Reference to a list containing the IDs of the genomes to be pre-selected. If the menu  
 is not intended to allow multiple selections, the list should be a singleton. If the  
 list is empty, nothing will be pre-selected.  
 =item RETURN  
 Returns the HTML text to generate a C<SELECT> menu inside a form.  
 sub NmpdrGenomeMenu {  
     # Get the parameters.  
     my ($self, $options, $selected) = @_;  
     # 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 = $self->GetAll(['Genome'],  
                                    "ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",  
                                    [], ['Genome(primary-group)', 'Genome(id)',  
                                         'Genome(genus)', 'Genome(species)',  
     # 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 %groupHash = ();  
     for my $genome (@genomeList) {  
         # Get the genome data.  
         my ($group, $genomeID, $genus, $species, $strain) = @{$genome};  
         # Form the genome name.  
         my $name = "$genus $species";  
         if ($strain) {  
             $name .= " $strain";  
         # Push the genome into the group's list.  
         push @{$groupHash{$group}}, [$genomeID, $name];  
     # Now we are ready to unroll the menu out of the group hash. First, we sort the groups, putting  
     # the supporting-genome group last.  
     my @groups = sort grep { $_ ne $FIG_Config::otherGroup } keys %groupHash;  
     push @groups, $FIG_Config::otherGroup;  
     # Next, create a hash that specifies the pre-selected entries.  
     my %selectedHash = map { $_ => 1 } @{$selected};  
     # Create the SELECT tag and stuff it into the output array.  
     my $select = "<" . join(" ", 'SELECT', map { "$_=\"$options->{$_}\"" } keys %{$options}) . ">";  
     my @lines = ($select);  
     # Loop through the groups.  
     for my $group (@groups) {  
         # Create the option group tag.  
         my $tag = "<OPTGROUP name=\"$group\">";  
         push @lines, "  $tag";  
         # Get the genomes in the group.  
         for my $genome (@{$groupHash{$group}}) {  
             my ($genomeID, $name) = @{$genome};  
             # See if it's selected.  
             my $select = ($selectedHash{$genomeID} ? " selected" : "");  
             # Generate the option tag.  
             my $optionTag = "<OPTION value=\"$genomeID\"$select>$name</OPTION>";  
             push @lines, "    $optionTag";  
         # Close the option group.  
         push @lines, "  </OPTGROUP>";  
     # Close the SELECT tag.  
     push @lines, "</SELECT>";  
     # Assemble the lines into a string.  
     my $retVal = join("\n", @lines, "");  
     # Return the result.  
     return $retVal;  
441  =head3 Genomes  =head3 Genomes
443  C<< my @genomes = $sprout->Genomes(); >>  C<< my @genomes = $sprout->Genomes(); >>

Removed from v.1.86  
changed lines
  Added in v.1.87

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3