[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.84, Thu Sep 14 14:11:09 2006 UTC revision 1.86, Sun Sep 24 17:14:16 2006 UTC
# Line 131  Line 131 
131      # Add the option table and XML file name.      # Add the option table and XML file name.
132      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
133      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
134        # Set up space for the group file data.
135        $retVal->{groupHash} = undef;
136      # Return it.      # Return it.
137      return $retVal;      return $retVal;
138  }  }
# Line 340  Line 342 
342    
343  =head3 GeneMenu  =head3 GeneMenu
344    
345  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>
346    
347  Return an HTML select menu of genomes. Each genome will be an option in the menu,  Return an HTML select menu of genomes. Each genome will be an option in the menu,
348  and will be displayed by name with the ID and a contig count attached. The selection  and will be displayed by name with the ID and a contig count attached. The selection
# Line 362  Line 364 
364  Reference to a list of values to be substituted in for the parameter marks in  Reference to a list of values to be substituted in for the parameter marks in
365  the filter string.  the filter string.
366    
367    =item selected (optional)
368    
369    ID of the genome to be initially selected.
370    
371    =item fast (optional)
372    
373    If specified and TRUE, the contig counts will be omitted to improve performance.
374    
375  =item RETURN  =item RETURN
376    
377  Returns an HTML select menu with the specified genomes as selectable options.  Returns an HTML select menu with the specified genomes as selectable options.
# Line 372  Line 382 
382    
383  sub GeneMenu {  sub GeneMenu {
384      # Get the parameters.      # Get the parameters.
385      my ($self, $attributes, $filterString, $params) = @_;      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;
386        my $slowMode = ! $fast;
387        # Default to nothing selected. This prevents an execution warning if "$selected"
388        # is undefined.
389        $selected = "" unless defined $selected;
390        Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);
391      # Start the menu.      # Start the menu.
392      my $retVal = "<select " .      my $retVal = "<select " .
393          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
# Line 389  Line 404 
404          # Get the data for this genome.          # Get the data for this genome.
405          my ($genomeID, $genus, $species, $strain) = @{$genomeData};          my ($genomeID, $genus, $species, $strain) = @{$genomeData};
406          # Get the contig count.          # Get the contig count.
407            my $contigInfo = "";
408            if ($slowMode) {
409          my $count = $self->ContigCount($genomeID);          my $count = $self->ContigCount($genomeID);
410          my $counting = ($count == 1 ? "contig" : "contigs");          my $counting = ($count == 1 ? "contig" : "contigs");
411                $contigInfo = "[$count $counting]";
412            }
413            # Find out if we're selected.
414            my $selectOption = ($selected eq $genomeID ? " selected" : "");
415          # Build the option tag.          # Build the option tag.
416          $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";
         Trace("Option tag built for $genomeID: $genus $species $strain.") if T(3);  
417      }      }
418      # Close the SELECT tag.      # Close the SELECT tag.
419      $retVal .= "</select>\n";      $retVal .= "</select>\n";
420      # Return the result.      # Return the result.
421      return $retVal;      return $retVal;
422  }  }
423    
424  =head3 Build  =head3 Build
425    
426  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 417  Line 438 
438      $self->CreateTables();      $self->CreateTables();
439  }  }
440    
441    =head3 NmpdrGenomeMenu
442    
443    C<< my $htmlText = $sprout->NmpdrGenomeMenu(\%options, \@selected); >>
444    
445    This method creates a hierarchical HTML menu for NMPDR genomes organized by category. The
446    category indicates the low-level NMPDR group. Organizing the genomes in this way makes it
447    easier to select all genomes from a particular category.
448    
449    =over 4
450    
451    =item options
452    
453    Reference to a hash containing the options to be applied to the C<SELECT> tag form the menu.
454    Typical options would include C<name> to specify the field name, C<multiple> to specify
455    that multiple selections are allowed, and C<size> to set the number of rows to display
456    in the menu.
457    
458    =item selected
459    
460    Reference to a list containing the IDs of the genomes to be pre-selected. If the menu
461    is not intended to allow multiple selections, the list should be a singleton. If the
462    list is empty, nothing will be pre-selected.
463    
464    =item RETURN
465    
466    Returns the HTML text to generate a C<SELECT> menu inside a form.
467    
468    =back
469    
470    =cut
471    
472    sub NmpdrGenomeMenu {
473        # Get the parameters.
474        my ($self, $options, $selected) = @_;
475        # Get a list of all the genomes in group order. In fact, we only need them ordered
476        # by name (genus,species,strain), but putting primary-group in front enables us to
477        # take advantage of an existing index.
478        my @genomeList = $self->GetAll(['Genome'],
479                                       "ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
480                                       [], ['Genome(primary-group)', 'Genome(id)',
481                                            'Genome(genus)', 'Genome(species)',
482                                            'Genome(unique-characterization)']);
483        # Create a hash to organize the genomes by group. Each group will contain a list of
484        # 2-tuples, the first element being the genome ID and the second being the genome
485        # name.
486        my %groupHash = ();
487        for my $genome (@genomeList) {
488            # Get the genome data.
489            my ($group, $genomeID, $genus, $species, $strain) = @{$genome};
490            # Form the genome name.
491            my $name = "$genus $species";
492            if ($strain) {
493                $name .= " $strain";
494            }
495            # Push the genome into the group's list.
496            push @{$groupHash{$group}}, [$genomeID, $name];
497        }
498        # Now we are ready to unroll the menu out of the group hash. First, we sort the groups, putting
499        # the supporting-genome group last.
500        my @groups = sort grep { $_ ne $FIG_Config::otherGroup } keys %groupHash;
501        push @groups, $FIG_Config::otherGroup;
502        # Next, create a hash that specifies the pre-selected entries.
503        my %selectedHash = map { $_ => 1 } @{$selected};
504        # Create the SELECT tag and stuff it into the output array.
505        my $select = "<" . join(" ", 'SELECT', map { "$_=\"$options->{$_}\"" } keys %{$options}) . ">";
506        my @lines = ($select);
507        # Loop through the groups.
508        for my $group (@groups) {
509            # Create the option group tag.
510            my $tag = "<OPTGROUP name=\"$group\">";
511            push @lines, "  $tag";
512            # Get the genomes in the group.
513            for my $genome (@{$groupHash{$group}}) {
514                my ($genomeID, $name) = @{$genome};
515                # See if it's selected.
516                my $select = ($selectedHash{$genomeID} ? " selected" : "");
517                # Generate the option tag.
518                my $optionTag = "<OPTION value=\"$genomeID\"$select>$name</OPTION>";
519                push @lines, "    $optionTag";
520            }
521            # Close the option group.
522            push @lines, "  </OPTGROUP>";
523        }
524        # Close the SELECT tag.
525        push @lines, "</SELECT>";
526        # Assemble the lines into a string.
527        my $retVal = join("\n", @lines, "");
528        # Return the result.
529        return $retVal;
530    }
531    
532  =head3 Genomes  =head3 Genomes
533    
534  C<< my @genomes = $sprout->Genomes(); >>  C<< my @genomes = $sprout->Genomes(); >>
# Line 634  Line 746 
746      return ($contigID, $start, $dir, $len);      return ($contigID, $start, $dir, $len);
747  }  }
748    
749    
750    
751  =head3 PointLocation  =head3 PointLocation
752    
753  C<< my $found = Sprout::PointLocation($location, $point); >>  C<< my $found = Sprout::PointLocation($location, $point); >>
# Line 3251  Line 3365 
3365          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3366          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3367          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3368              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3369                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3370              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3371          }          }
# Line 3259  Line 3373 
3373          # Here we need all of the groups. In this case, we run through all          # Here we need all of the groups. In this case, we run through all
3374          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3375          # group. Note that we use a filter clause to insure that only genomes          # group. Note that we use a filter clause to insure that only genomes
3376          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3377          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3378                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3379          # Loop through the genomes found.          # Loop through the genomes found.
3380          for my $genome (@genomes) {          for my $genome (@genomes) {
3381              # Pop this genome's ID off the current list.              # Pop this genome's ID off the current list.
# Line 3429  Line 3543 
3543      return %retVal;      return %retVal;
3544  }  }
3545    
3546    =head3 GroupPageName
3547    
3548    C<< my $name = $sprout->GroupPageName($group); >>
3549    
3550    Return the name of the page for the specified NMPDR group.
3551    
3552    =over 4
3553    
3554    =item group
3555    
3556    Name of the relevant group.
3557    
3558    =item RETURN
3559    
3560    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3561    memory it will be read in.
3562    
3563    =back
3564    
3565    =cut
3566    
3567    sub GroupPageName {
3568        # Get the parameters.
3569        my ($self, $group) = @_;
3570        # Declare the return variable.
3571        my $retVal;
3572        # Check for the group file data.
3573        if (! defined $self->{groupHash}) {
3574            # Read the group file.
3575            my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
3576            # Store it in our object.
3577            $self->{groupHash} = \%groupData;
3578        }
3579        # Compute the real group name.
3580        my $realGroup = $group;
3581        if ($group =~ /([A-Z]\w+)/) {
3582            $realGroup = $1;
3583        }
3584        # Return the page name.
3585        $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
3586        # Return the result.
3587        return $retVal;
3588    }
3589    
3590  =head3 ReadGroupFile  =head3 ReadGroupFile
3591    
3592  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>

Legend:
Removed from v.1.84  
changed lines
  Added in v.1.86

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3