[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.102, Thu Dec 6 14:56:23 2007 UTC revision 1.119, Tue Sep 30 15:23:55 2008 UTC
# Line 14  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17        use CGI;
18        use WikiTools;
19        use BioWords;
20      use base qw(ERDB);      use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 54  Line 57 
57    
58  =item dbName  =item dbName
59    
60  Name of the database.  Name of the database. If omitted, the default Sprout database name is used.
61    
62  =item options  =item options
63    
# Line 78  Line 81 
81    
82  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE
83    
84    * B<host> name of the database host
85    
86  =back  =back
87    
88  For example, the following constructor call specifies a database named I<Sprout> and a user name of  For example, the following constructor call specifies a database named I<Sprout> and a user name of
89  I<fig> with a password of I<admin>. The database load files are in the directory  I<fig> with a password of I<admin>. The database load files are in the directory
90  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
91    
92      my $sprout = Sprout->new('Sprout', { userData =>; 'fig/admin', dataDir => '/usr/fig/SproutData' });      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });
93    
94  =cut  =cut
95    
96  sub new {  sub new {
97      # Get the parameters.      # Get the parameters.
98      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
99        # Default the database name if it is missing.
100        if (! defined $dbName) {
101            $dbName = $FIG_Config::sproutDB;
102        } elsif (ref $dbName eq 'HASH') {
103            $options = $dbName;
104            $dbName = $FIG_Config::sproutDB;
105        }
106      # Compute the DBD directory.      # Compute the DBD directory.
107      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
108                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 103  Line 115 
115                                                          # data file directory                                                          # data file directory
116                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
117                                                          # database definition file name                                                          # database definition file name
118                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
119                                                          # user name and password                                                          # user name and password
120                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
121                                                          # database connection port                                                          # database connection port
122                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
123                         host         => $FIG_Config::dbhost,                         host         => $FIG_Config::sprout_host,
124                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
125                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
126                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 121  Line 133 
133      # Connect to the database.      # Connect to the database.
134      my $dbh;      my $dbh;
135      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
136            Trace("Connect data: host = $optionTable->{host}, port = $optionTable->{port}.") if T(3);
137          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
138                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
139      }      }
# Line 134  Line 147 
147      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
148      # Set up space for the genome hash. We use this to identify NMPDR genomes.      # Set up space for the genome hash. We use this to identify NMPDR genomes.
149      $retVal->{genomeHash} = undef;      $retVal->{genomeHash} = undef;
150        # Remember the data directory name.
151        $retVal->{dataDir} = $dataDir;
152      # Connect to the attributes.      # Connect to the attributes.
153      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
154          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
# Line 147  Line 162 
162      return $retVal;      return $retVal;
163  }  }
164    
165    =head3 CoreGenomes
166    
167        my @genomes = $sprout->CoreGenomes($scope);
168    
169    Return the IDs of NMPDR genomes in the specified scope.
170    
171    =over 4
172    
173    =item scope
174    
175    Scope of the desired genomes. C<core> covers the original core genomes,
176    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
177    genomes in the system.
178    
179    =item RETURN
180    
181    Returns a list of the IDs for the genomes in the specified scope.
182    
183    =back
184    
185    =cut
186    
187    sub CoreGenomes {
188        # Get the parameters.
189        my ($self, $scope) = @_;
190        # Declare the return variable.
191        my @retVal = ();
192        # If we want all genomes, then this is easy.
193        if ($scope eq 'all') {
194            @retVal = $self->Genomes();
195        } else {
196            # Here we're dealing with groups. Get the hash of all the
197            # genome groups.
198            my %groups = $self->GetGroups();
199            # Loop through the groups, keeping the ones that we want.
200            for my $group (keys %groups) {
201                # Decide if we want to keep this group.
202                my $keepGroup = 0;
203                if ($scope eq 'nmpdr') {
204                    # NMPDR mode: keep all groups.
205                    $keepGroup = 1;
206                } elsif ($scope eq 'core') {
207                    # CORE mode. Only keep real core groups.
208                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
209                        $keepGroup = 1;
210                    }
211                }
212                # Add this group if we're keeping it.
213                if ($keepGroup) {
214                    push @retVal, @{$groups{$group}};
215                }
216            }
217        }
218        # Return the result.
219        return @retVal;
220    }
221    
222    =head3 SuperGroup
223    
224        my $superGroup = $sprout->SuperGroup($groupName);
225    
226    Return the name of the super-group containing the specified NMPDR genome
227    group. If no appropriate super-group can be found, an error will be
228    thrown.
229    
230    =over 4
231    
232    =item groupName
233    
234    Name of the group whose super-group is desired.
235    
236    =item RETURN
237    
238    Returns the name of the super-group containing the incoming group.
239    
240    =back
241    
242    =cut
243    
244    sub SuperGroup {
245        # Get the parameters.
246        my ($self, $groupName) = @_;
247        # Declare the return variable.
248        my $retVal;
249        # Get the group hash.
250        my %groupHash = $self->CheckGroupFile();
251        # Find the super-group genus.
252        $groupName =~ /([A-Z]\w+)/;
253        my $nameThing = $1;
254        # See if it's directly in the group hash.
255        if (exists $groupHash{$nameThing}) {
256            # Yes, then it's our result.
257            $retVal = $nameThing;
258        } else {
259            # No, so we have to search.
260            for my $superGroup (keys %groupHash) {
261                # Get this super-group's item list.
262                my $list = $groupHash{$superGroup}->{contents};
263                # Search it.
264                if (grep { $_->[0] eq $nameThing } @{$list}) {
265                    $retVal = $superGroup;
266                }
267            }
268            # Make sure we found something.
269            if (! $retVal) {
270                Confess("No super-group found for \"$groupName\".");
271            }
272        }
273        # Return the result.
274        return $retVal;
275    }
276    
277  =head3 MaxSegment  =head3 MaxSegment
278    
279      my $length = $sprout->MaxSegment();      my $length = $sprout->MaxSegment();
# Line 267  Line 394 
394              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
395          } else {          } else {
396              # Attempt to load this table.              # Attempt to load this table.
397              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
398              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
399              $retVal->Accumulate($result);              $retVal->Accumulate($result);
400          }          }
# Line 350  Line 477 
477      return $retVal;      return $retVal;
478  }  }
479    
480  =head3 GeneMenu  =head3 GenomeMenu
481    
482      my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected);      my $html = $sprout->GenomeMenu(%options);
483    
484  Return an HTML select menu of genomes. Each genome will be an option in the menu,  Generate a genome selection control with the specified name and options.
485  and will be displayed by name with the ID and a contig count attached. The selection  This control is almost but not quite the same as the genome control in the
486  value will be the genome ID. The genomes will be sorted by genus/species name.  B<SearchHelper> class. Eventually, the two will be combined.
487    
488  =over 4  =over 4
489    
490  =item attributes  =item options
491    
492    Optional parameters for the control (see below).
493    
494    =item RETURN
495    
496  Reference to a hash mapping attributes to values for the SELECT tag generated.  Returns the HTML for a genome selection control on a form (sometimes called a popup menu).
497    
498  =item filterString  =back
499    
500  A filter string for use in selecting the genomes. The filter string must conform  The valid options are as follows.
 to the rules for the C<< ERDB->Get >> method.  
501    
502  =item params  =over 4
503    
504  Reference to a list of values to be substituted in for the parameter marks in  =item name
 the filter string.  
505    
506  =item selected (optional)  Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
507    Terrible things will happen if you have two controls with the same name on the same page.
508    
509  ID of the genome to be initially selected.  =item filter
510    
511  =item fast (optional)  If specified, a filter for the list of genomes to display. The filter should be in the form of a
512    list reference. The first element of the list should be the filter string, and the remaining elements
513    the filter parameters.
514    
515  If specified and TRUE, the contig counts will be omitted to improve performance.  =item multiSelect
516    
517  =item RETURN  If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
518    
519    =item size
520    
521    Number of rows to display in the control. The default is C<10>
522    
523    =item id
524    
525    ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
526    unless this ID is unique.
527    
528  Returns an HTML select menu with the specified genomes as selectable options.  =item selected
529    
530    A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
531    default is none.
532    
533    =item class
534    
535    If specified, a style class to assign to the genome control.
536    
537  =back  =back
538    
539  =cut  =cut
540    
541  sub GeneMenu {  sub GenomeMenu {
542      # Get the parameters.      # Get the parameters.
543      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;      my ($self, %options) = @_;
544      my $slowMode = ! $fast;      # Get the control's name and ID.
545      # Default to nothing selected. This prevents an execution warning if "$selected"      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
546      # is undefined.      my $menuID = $options{id} || $menuName;
547      $selected = "" unless defined $selected;      Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
548      Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);      # Compute the IDs for the status display.
549      # Start the menu.      my $divID = "${menuID}_status";
550      my $retVal = "<select " .      my $urlID = "${menuID}_url";
551          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .      # Compute the code to show selected genomes in the status area.
552          ">\n";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
553      # Get the genomes.      # Check for single-select or multi-select.
554      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',      my $multiSelect = $options{multiSelect} || 0;
555                                                                       'Genome(genus)',      # Get the style data.
556                                                                       'Genome(species)',      my $class = $options{class} || '';
557                                                                       'Genome(unique-characterization)']);      # Get the list of pre-selected items.
558      # Sort them by name.      my $selections = $options{selected} || [];
559      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;      if (ref $selections ne 'ARRAY') {
560      # Loop through the genomes, creating the option tags.          $selections = [ split /\s*,\s*/, $selections ];
561      for my $genomeData (@sorted) {      }
562          # Get the data for this genome.      my %selected = map { $_ => 1 } @{$selections};
563          my ($genomeID, $genus, $species, $strain) = @{$genomeData};      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
564          # Get the contig count.      # string or a list reference.
565          my $contigInfo = "";      my $filterParms = $options{filter} || "";
566          if ($slowMode) {      if (! ref $filterParms) {
567              my $count = $self->ContigCount($genomeID);          $filterParms = [split /\t|\\t/, $filterParms];
568              my $counting = ($count == 1 ? "contig" : "contigs");      }
569              $contigInfo = "[$count $counting]";      my $filterString = shift @{$filterParms};
570          }      # Get a list of all the genomes in group order. In fact, we only need them ordered
571          # Find out if we're selected.      # by name (genus,species,strain), but putting primary-group in front enables us to
572          my $selectOption = ($selected eq $genomeID ? " selected" : "");      # take advantage of an existing index.
573          # Build the option tag.      my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
574          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";                                     $filterParms,
575                                       [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
576        # Create a hash to organize the genomes by group. Each group will contain a list of
577        # 2-tuples, the first element being the genome ID and the second being the genome
578        # name.
579        my %gHash = ();
580        for my $genome (@genomeList) {
581            # Get the genome data.
582            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
583            # Compute its name. This is the genus, species, strain (if any), and the contig count.
584            my $name = "$genus $species ";
585            $name .= "$strain " if $strain;
586            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
587            # Now we get the domain. The domain tells us the display style of the organism.
588            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
589            # Now compute the display group. This is normally the primary group, but if the
590            # organism is supporting, we blank it out.
591            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
592            # Push the genome into the group's list. Note that we use the real group
593            # name for the hash key here, not the display group name.
594            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
595        }
596        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
597        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
598        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
599        # that aren't "other". At some point, we will want to make this less complicated.
600        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
601                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
602        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
603        # Remember the number of NMPDR groups.
604        my $nmpdrGroupCount = scalar @groups;
605        # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
606        # of the domains found.
607        my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
608        my @domains = ();
609        for my $genomeData (@otherGenomes) {
610            my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
611            if (exists $gHash{$domain}) {
612                push @{$gHash{$domain}}, $genomeData;
613            } else {
614                $gHash{$domain} = [$genomeData];
615                push @domains, $domain;
616            }
617        }
618        # Add the domain groups at the end of the main group list. The main group list will now
619        # contain all the categories we need to display the genomes.
620        push @groups, sort @domains;
621        # Delete the supporting group.
622        delete $gHash{$FIG_Config::otherGroup};
623        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
624        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
625        # and use that to make the selections.
626        my $nmpdrCount = 0;
627        # Create the type counters.
628        my $groupCount = 1;
629        # Get the number of rows to display.
630        my $rows = $options{size} || 10;
631        # If we're multi-row, create an onChange event.
632        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
633        # Set up the multiple-select flag.
634        my $multipleTag = ($multiSelect ? " multiple" : "" );
635        # Set up the style class.
636        my $classTag = ($class ? " class=\"$class\"" : "" );
637        # Create the SELECT tag and stuff it into the output array.
638        my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
639        # Loop through the groups.
640        for my $group (@groups) {
641            # Get the genomes in the group.
642            for my $genome (@{$gHash{$group}}) {
643                # If this is an NMPDR organism, we add an extra style and count it.
644                my $nmpdrStyle = "";
645                if ($nmpdrGroupCount > 0) {
646                    $nmpdrCount++;
647                    $nmpdrStyle = " Core";
648                }
649                # Get the organism ID, name, contig count, and domain.
650                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
651                # See if we're pre-selected.
652                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
653                # Compute the display name.
654                my $nameString = "$name ($genomeID$contigCount)";
655                # Generate the option tag.
656                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
657                push @lines, "    $optionTag";
658            }
659            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
660            # groups.
661            $nmpdrGroupCount--;
662      }      }
663      # Close the SELECT tag.      # Close the SELECT tag.
664      $retVal .= "</select>\n";      push @lines, "</SELECT>";
665        if ($rows > 1) {
666            # We're in a non-compact mode, so we need to add some selection helpers. First is
667            # the search box. This allows the user to type text and change which genomes are
668            # displayed. For multiple-select mode, we include a button that selects the displayed
669            # genes. For single-select mode, we use a plain label instead.
670            my $searchThingName = "${menuID}_SearchThing";
671            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
672                                                 : "Show genomes containing");
673            push @lines, "<br />$searchThingLabel&nbsp;" .
674                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .
675                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
676            # For multi-select mode, we also have buttons to set and clear selections.
677            if ($multiSelect) {
678                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";
679                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";
680                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";
681            }
682            # Add a hidden field we can use to generate organism page hyperlinks.
683            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";
684            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
685            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
686        }
687        # Assemble all the lines into a string.
688        my $retVal = join("\n", @lines, "");
689        # Return the result.
690        return $retVal;
691    }
692    
693    
694    =head3 Stem
695    
696        my $stem = $sprout->Stem($word);
697    
698    Return the stem of the specified word, or C<undef> if the word is not
699    stemmable. Note that even if the word is stemmable, the stem may be
700    the same as the original word.
701    
702    =over 4
703    
704    =item word
705    
706    Word to convert into a stem.
707    
708    =item RETURN
709    
710    Returns a stem of the word (which may be the word itself), or C<undef> if
711    the word is not stemmable.
712    
713    =back
714    
715    =cut
716    
717    sub Stem {
718        # Get the parameters.
719        my ($self, $word) = @_;
720        # Get the stemmer object.
721        my $stemmer = $self->{stemmer};
722        if (! defined $stemmer) {
723            # We don't have one pre-built, so we build and save it now.
724            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
725                                     stops => "$FIG_Config::sproutData/StopWords.txt",
726                                     cache => 0);
727            $self->{stemmer} = $stemmer;
728        }
729        # Try to stem the word.
730        my $retVal = $stemmer->Process($word);
731      # Return the result.      # Return the result.
732      return $retVal;      return $retVal;
733  }  }
734    
735    
736  =head3 Build  =head3 Build
737    
738      $sprout->Build();      $sprout->Build();
# Line 568  Line 870 
870  =item RETURN  =item RETURN
871    
872  Returns a list of the feature's contig segments. The locations are returned as a list in a list  Returns a list of the feature's contig segments. The locations are returned as a list in a list
873  context and as a comma-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context. An empty list means the feature
874    wasn't found.
875    
876  =back  =back
877    
# Line 577  Line 880 
880  sub FeatureLocation {  sub FeatureLocation {
881      # Get the parameters.      # Get the parameters.
882      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
883        # Declare the return variable.
884        my @retVal = ();
885      # Get the feature record.      # Get the feature record.
886      my $object = $self->GetEntity('Feature', $featureID);      my $object = $self->GetEntity('Feature', $featureID);
887      Confess("Feature $featureID not found.") if ! defined($object);      # Only proceed if we found it.
888        if (defined $object) {
889      # Get the location string.      # Get the location string.
890      my $locString = $object->PrimaryValue('Feature(location-string)');      my $locString = $object->PrimaryValue('Feature(location-string)');
891      # Create the return list.      # Create the return list.
892      my @retVal = split /\s*,\s*/, $locString;          @retVal = split /\s*,\s*/, $locString;
893        }
894      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
895      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
896  }  }
# Line 1315  Line 1622 
1622  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG
1623  is trusted.  is trusted.
1624    
1625  If the feature is B<not> identified by a FIG ID, then the functional assignment  If the feature is B<not> identified by a FIG ID, then we search the aliases for it.
1626  information is taken from the B<ExternalAliasFunc> table. If the table does  If no matching alias is found, we return an undefined value.
 not contain an entry for the feature, an undefined value is returned.  
1627    
1628  =over 4  =over 4
1629    
# Line 1343  Line 1649 
1649      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1650      # Declare the return value.      # Declare the return value.
1651      my $retVal;      my $retVal;
1652      # Determine the ID type.      # Find a FIG ID for this feature.
1653      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1654        # Only proceed if we have an ID.
1655        if ($fid) {
1656          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1657          if (!$userID) {          if (!$userID) {
1658              # Use the primary assignment.              # Use the primary assignment.
1659              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1660          } else {          } else {
1661              # We must build the list of trusted users.              # We must build the list of trusted users.
1662              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1374  Line 1682 
1682              # Build a query for all of the feature's annotations, sorted by date.              # Build a query for all of the feature's annotations, sorted by date.
1683              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1684                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1685                                     [$featureID]);                                     [$fid]);
1686              my $timeSelected = 0;              my $timeSelected = 0;
1687              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1688              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1394  Line 1702 
1702                  }                  }
1703              }              }
1704          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         ($retVal) = $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);  
1705      }      }
1706      # Return the assignment found.      # Return the assignment found.
1707      return $retVal;      return $retVal;
# Line 1417  Line 1720 
1720  annotation itself because it's a text field; however, this is not a big problem because  annotation itself because it's a text field; however, this is not a big problem because
1721  most features only have a small number of annotations.  most features only have a small number of annotations.
1722    
 If the feature is B<not> identified by a FIG ID, then the functional assignment  
 information is taken from the B<ExternalAliasFunc> table. If the table does  
 not contain an entry for the feature, an empty list is returned.  
   
1723  =over 4  =over 4
1724    
1725  =item featureID  =item featureID
# Line 1441  Line 1740 
1740      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1741      # Declare the return value.      # Declare the return value.
1742      my @retVal = ();      my @retVal = ();
1743      # Determine the ID type.      # Convert to a FIG ID.
1744      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1745        # Only proceed if we found one.
1746        if ($fid) {
1747          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID. We must build the list of trusted
1748          # users.          # users.
1749          my %trusteeTable = ();          my %trusteeTable = ();
1750          # Build a query for all of the feature's annotations, sorted by date.          # Build a query for all of the feature's annotations, sorted by date.
1751          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1752                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1753                                 [$featureID]);                                 [$fid]);
1754          my $timeSelected = 0;          my $timeSelected = 0;
1755          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1756          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1464  Line 1765 
1765                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1766              }              }
1767          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,  
                                                  ['ExternalAliasFunc(func)']);  
         push @retVal, map { ['master', $_] } @assignments;  
1768      }      }
1769      # Return the assignments found.      # Return the assignments found.
1770      return @retVal;      return @retVal;
# Line 1658  Line 1952 
1952      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1953          $retVal = $1;          $retVal = $1;
1954      } else {      } else {
1955          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
1956            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1957            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1958                $retVal = $1;
1959            }
1960      }      }
1961      # Return the value found.      # Return the value found.
1962      return $retVal;      return $retVal;
# Line 2498  Line 2796 
2796      return @retVal;      return @retVal;
2797  }  }
2798    
 =head3 GetProperties  
   
     my @list = $sprout->GetProperties($fid, $key, $value, $url);  
   
 Return a list of the properties with the specified characteristics.  
   
 Properties are the Sprout analog of the FIG attributes. The call is  
 passed directly to the CustomAttributes or RemoteCustomAttributes object  
 contained in this object.  
   
 This method returns a series of tuples that match the specified criteria. Each tuple  
 will contain an object ID, a key, and one or more values. The parameters to this  
 method therefore correspond structurally to the values expected in each tuple. In  
 addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any  
 of the parameters. So, for example,  
   
     my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);  
   
 would return something like  
   
     ['fig}100226.1.peg.1004', 'structure', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure1', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure2', 1, 2]  
     ['fig}100226.1.peg.1004', 'structureA', 1, 2]  
   
 Use of C<undef> in any position acts as a wild card (all values). You can also specify  
 a list reference in the ID column. Thus,  
   
     my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');  
   
 would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its  
 features.  
   
 In addition to values in multiple sections, a single attribute key can have multiple  
 values, so even  
   
     my @attributeList = $sprout->GetProperties($peg, 'virulent');  
   
 which has no wildcard in the key or the object ID, may return multiple tuples.  
   
 =over 4  
   
 =item objectID  
   
 ID of object whose attributes are desired. If the attributes are desired for multiple  
 objects, this parameter can be specified as a list reference. If the attributes are  
 desired for all objects, specify C<undef> or an empty string. Finally, you can specify  
 attributes for a range of object IDs by putting a percent sign (C<%>) at the end.  
   
 =item key  
   
 Attribute key name. A value of C<undef> or an empty string will match all  
 attribute keys. If the values are desired for multiple keys, this parameter can be  
 specified as a list reference. Finally, you can specify attributes for a range of  
 keys by putting a percent sign (C<%>) at the end.  
   
 =item values  
   
 List of the desired attribute values, section by section. If C<undef>  
 or an empty string is specified, all values in that section will match. A  
 generic match can be requested by placing a percent sign (C<%>) at the end.  
 In that case, all values that match up to and not including the percent sign  
 will match. You may also specify a regular expression enclosed  
 in slashes. All values that match the regular expression will be returned. For  
 performance reasons, only values have this extra capability.  
   
 =item RETURN  
   
 Returns a list of tuples. The first element in the tuple is an object ID, the  
 second is an attribute key, and the remaining elements are the sections of  
 the attribute value. All of the tuples will match the criteria set forth in  
 the parameter list.  
   
 =back  
   
 =cut  
   
 sub GetProperties {  
     # Get the parameters.  
     my ($self, @parms) = @_;  
     # Declare the return variable.  
     my @retVal = $self->{_ca}->GetAttributes(@parms);  
     # Return the result.  
     return @retVal;  
 }  
   
2799  =head3 FeatureProperties  =head3 FeatureProperties
2800    
2801      my @properties = $sprout->FeatureProperties($featureID);      my @properties = $sprout->FeatureProperties($featureID);
# Line 2884  Line 3096 
3096  sub SubsystemList {  sub SubsystemList {
3097      # Get the parameters.      # Get the parameters.
3098      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3099      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3100      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3101        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3102                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3103      # Return the result, sorted.      # Return the result, sorted.
3104      return sort @retVal;      return sort @retVal;
# Line 2918  Line 3131 
3131      # Declare the return variable.      # Declare the return variable.
3132      my %retVal = ();      my %retVal = ();
3133      # Get a list of the genome features that participate in subsystems. For each      # Get a list of the genome features that participate in subsystems. For each
3134      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3135      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3136                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3137                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3138      # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems      # Now we get a list of valid subsystems. These are the subsystems connected to the genome with
3139      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3140      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3141      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3142      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3143                                   "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",      # We loop through @roleData to build the hash.
                                  [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);  
     # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.  
     # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We  
     # link these two lists together to create the result. First, we want a hash mapping  
     # spreadsheet cells to subsystem names.  
     my %subHash = map { $_->[0] => $_->[1] } @cellData;  
     # We loop through @cellData to build the hash.  
3144      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3145          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3146          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3147          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3148          my $subsys = $subHash{$cellID};          # Check the subsystem;
3149          if ($subsys) {          if ($subs{$subsys}) {
3150                Trace("Subsystem found.") if T(4);
3151              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3152              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3153              # Merge in this new data.              # Merge in this new data.
# Line 3039  Line 3246 
3246          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3247                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3248          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3249          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3250      }      }
3251      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3252      my @retVal = ();      my @retVal = ();
# Line 3618  Line 3825 
3825      my ($self, %groupHash) = @_;      my ($self, %groupHash) = @_;
3826      # Create the result hash.      # Create the result hash.
3827      my %retVal = ();      my %retVal = ();
     # Get the super-group table.  
     my %superTable = $self->CheckGroupFile();  
3828      # Copy over the genomes.      # Copy over the genomes.
3829      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3830          # Get the super-group name.          # Get the super-group name.
3831          my $realGroupID;          my $realGroupID = $self->SuperGroup($groupID);
3832          if ($groupID =~ /([A-Z]\w+)/) {          # Append this group's genomes into the result hash
3833              my $sortOfGroup = $1;          # using the super-group name.
             if (! defined($superTable{$1})) {  
                 Confess("Super-group name not found for group $groupID.");  
             } else {  
                 $realGroupID = $superTable{$1}->{superGroup};  
             }  
         } else {  
             Confess("Invalid group name $groupID.");  
         }  
         # Append this group's genomes into the result hash.  
3834          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
3835      }      }
3836      # Return the result hash.      # Return the result hash.
# Line 3665  Line 3861 
3861  sub GroupPageName {  sub GroupPageName {
3862      # Get the parameters.      # Get the parameters.
3863      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3864      # Check for the group file data.      # Check for the group file data.
3865      my %superTable = $self->CheckGroupFile();      my %superTable = $self->CheckGroupFile();
3866      # Compute the real group name.      # Compute the real group name.
3867      my ($realGroup, $pageLink);      my $realGroup = $self->SuperGroup($group);
3868      if ($group =~ /([A-Z]\w+)/) {      # Get the associated page name.
3869          my $sortOfGroup = $1;      my $retVal = "../content/$superTable{$realGroup}->{page}";
         if (! defined($superTable{$1})) {  
             Confess("No sort-of group found for \"$group\".");  
         } else {  
             $pageLink = $superTable{$1}->{page};  
         }  
     } else {  
         Confess("\"group\" is not a valid group name.");  
     }  
     # Return the page name.  
     $retVal = "../content/" . $pageLink;  
3870      # Return the result.      # Return the result.
3871      return $retVal;      return $retVal;
3872  }  }
# Line 3725  Line 3909 
3909    
3910  Get the group file hash. The group file hash describes the relationship  Get the group file hash. The group file hash describes the relationship
3911  between a group and the super-group to which it belongs for purposes of  between a group and the super-group to which it belongs for purposes of
3912  display. The super-group name is computed from the sort-of group name,  display. The super-group name is computed from the first capitalized word
3913  which is the first capitalized word in the actual group name. For each  in the actual group name. For each super-group, the group file contains
3914  sort-of group, the group file contains the super-group name, the group  the page name and a list of the species expected to be in the group.
3915  genus, the list of applicable species (if any), and the name of the NMPDR  Each species is specified by a genus and a species name. A species name
3916  display page for the super-group.  of C<0> implies an entire genus.
3917    
3918  This method returns a hash from sort-of group names to hash reference. Each  This method returns a hash from super-group names to a hash reference. Each
3919  resulting hash reference contains the following fields.  resulting hash reference contains the following fields.
3920    
3921  =over 4  =over 4
3922    
 =item superGroup  
   
 Super-group name.  
   
3923  =item page  =item page
3924    
3925  The super-group's web page in the NMPDR.  The super-group's web page in the NMPDR.
3926    
3927  =item genus  =item contents
   
 The genus of the sort-of group.  
3928    
3929  =item species  A list of 2-tuples, each containing a genus name followed by a species name
3930    (or 0, indicating all species). This list indicates which organisms belong
3931  A reference to a list of the species for the sort-of group.  in the super-group.
3932    
3933  =back  =back
3934    
# Line 3767  Line 3945 
3945          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3946          # Loop through the list of sort-of groups.          # Loop through the list of sort-of groups.
3947          for my $groupLine (@groupLines) {          for my $groupLine (@groupLines) {
3948              my ($mainName, $name, $page, $genus, $species) = split(/\t/, $groupLine);              my ($name, $page, @contents) = split /\t/, $groupLine;
3949              $groupHash{$name} = { page => $page,              $groupHash{$name} = { page => $page,
3950                                 genus => $genus,                                    contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3951                                 species => [ split(/\s*,\s*/, $species) ],                                  };
                                superGroup => $mainName };  
3952          }          }
3953          # Save the hash.          # Save the hash.
3954          $self->{groupHash} = \%groupHash;          $self->{groupHash} = \%groupHash;
# Line 3810  Line 3987 
3987  sub CleanKeywords {  sub CleanKeywords {
3988      # Get the parameters.      # Get the parameters.
3989      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
3990      # Perform the standard cleanup.      # Get the stemmer.
3991      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $stemmer = $self->GetStemmer();
3992      # Fix the periods in EC and TC numbers.      # Convert the search expression using the stemmer.
3993      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
3994      # Fix non-trailing periods.      Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
     $retVal =~ s/\.(\w)/_$1/g;  
     # Fix non-leading minus signs.  
     $retVal =~ s/(\w)[\-]/$1_/g;  
     # Fix the vertical bars and colons  
     $retVal =~ s/(\w)[|:](\w)/$1'$2/g;  
3995      # Return the result.      # Return the result.
3996      return $retVal;      return $retVal;
3997  }  }
3998    
3999    =head3 GetSourceObject
4000    
4001        my $source = $erdb->GetSourceObject();
4002    
4003    Return the object to be used in creating load files for this database.
4004    
4005    =cut
4006    
4007    sub GetSourceObject {
4008        # Get access to the FIG code.
4009        require FIG;
4010        # Return a FIG object.
4011        return FIG->new();
4012    }
4013    
4014    =head3 SectionList
4015    
4016        my @sections = $erdb->SectionList($source);
4017    
4018    Return a list of the names for the different data sections used when loading this database.
4019    The default is an empty string, in which case there is only one section representing the
4020    entire database.
4021    
4022    =over 4
4023    
4024    =item source
4025    
4026    Source object used to access the data from which the database is loaded. This is the
4027    same object returned by L</GetSourceObject>; however, we ask the caller to pass it
4028    in as a parameter so that we don't end up creating multiple copies of a potentially
4029    expensive data structure.
4030    
4031    =item RETURN
4032    
4033    Returns a list of section names.
4034    
4035    =back
4036    
4037    =cut
4038    
4039    sub SectionList {
4040        # Get the parameters.
4041        my ($self, $source) = @_;
4042        # Ask the BaseSproutLoader for a section list.
4043        require BaseSproutLoader;
4044        my @retVal = BaseSproutLoader::GetSectionList($self, $source);
4045        # Return the list.
4046        return @retVal;
4047    }
4048    
4049    =head3 Loader
4050    
4051        my $groupLoader = $erdb->Loader($groupName, $source, $options);
4052    
4053    Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4054    by [[ERDBGeneratorPl]] to create the load group objects. If you are not using
4055    [[ERDBGeneratorPl]], you don't need to override this method.
4056    
4057    =over 4
4058    
4059    =item groupName
4060    
4061    Name of the load group whose object is to be returned. The group name is
4062    guaranteed to be a single word with only the first letter capitalized.
4063    
4064    =item source
4065    
4066    The source object used to access the data from which the load file is derived. This
4067    is the same object returned by L</GetSourceObject>; however, we ask the caller to pass
4068    it in as a parameter so that we don't end up creating multiple copies of a potentially
4069    expensive data structure.
4070    
4071    =item options
4072    
4073    Reference to a hash of command-line options.
4074    
4075    =item RETURN
4076    
4077    Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4078    for this database.
4079    
4080    =back
4081    
4082    =cut
4083    
4084    sub Loader {
4085        # Get the parameters.
4086        my ($self, $groupName, $source, $options) = @_;
4087        # Compute the loader name.
4088        my $loaderClass = "${groupName}SproutLoader";
4089        # Pull in its definition.
4090        require "$loaderClass.pm";
4091        # Create an object for it.
4092        my $retVal = eval("$loaderClass->new(\$self, \$source, \$options)");
4093        # Insure it worked.
4094        Confess("Could not create $loaderClass object: $@") if $@;
4095        # Return it to the caller.
4096        return $retVal;
4097    }
4098    
4099    =head3 LoadGroupList
4100    
4101        my @groups = $erdb->LoadGroupList();
4102    
4103    Returns a list of the names for this database's load groups. This method is used
4104    by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default
4105    is a single group called 'All' that loads everything.
4106    
4107    =cut
4108    
4109    sub LoadGroupList {
4110        # Return the list.
4111        return qw(Genome Subsystem Feature Annotation Property Source Reaction Synonym Drug);
4112    }
4113    
4114    =head3 LoadDirectory
4115    
4116        my $dirName = $erdb->LoadDirectory();
4117    
4118    Return the name of the directory in which load files are kept. The default is
4119    the FIG temporary directory, which is a really bad choice, but it's always there.
4120    
4121    =cut
4122    
4123    sub LoadDirectory {
4124        # Get the parameters.
4125        my ($self) = @_;
4126        # Return the directory name.
4127        return $self->{dataDir};
4128    }
4129    
4130  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4131    
4132    =head3 GetStemmer
4133    
4134        my $stermmer = $sprout->GetStemmer();
4135    
4136    Return the stemmer object for this database.
4137    
4138    =cut
4139    
4140    sub GetStemmer {
4141        # Get the parameters.
4142        my ($self) = @_;
4143        # Declare the return variable.
4144        my $retVal = $self->{stemmer};
4145        if (! defined $retVal) {
4146            # We don't have one pre-built, so we build and save it now.
4147            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4148                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4149                                     cache => 1);
4150            $self->{stemmer} = $retVal;
4151        }
4152        # Return the result.
4153        return $retVal;
4154    }
4155    
4156  =head3 ParseAssignment  =head3 ParseAssignment
4157    
4158  Parse annotation text to determine whether or not it is a functional assignment. If it is,  Parse annotation text to determine whether or not it is a functional assignment. If it is,
# Line 3949  Line 4276 
4276  }  }
4277    
4278    
4279    =head3 Hint
4280    
4281        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4282    
4283    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4284    This HTML can be put in forms to provide a useful hinting mechanism.
4285    
4286    =over 4
4287    
4288    =item wikiPage
4289    
4290    Name of the wiki page to be popped up when the hint mark is clicked.
4291    
4292    =item hintText
4293    
4294    Text to display for the hint. It is raw html, but may not contain any double quotes.
4295    
4296    =item RETURN
4297    
4298    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4299    uses the standard FIG popup technology.
4300    
4301    =back
4302    
4303    =cut
4304    
4305    sub Hint {
4306        # Get the parameters.
4307        my ($wikiPage, $hintText) = @_;
4308        # Escape the single quotes in the hint text.
4309        my $quotedText = $hintText;
4310        $quotedText =~ s/'/\\'/g;
4311        # Convert the wiki page name to a URL.
4312        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4313        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4314        # Compute the mouseover script.
4315        my $mouseOver = "doTooltip(this, '$quotedText')";
4316        # Create the html.
4317        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4318        # Return it.
4319        return $retVal;
4320    }
4321    
4322  1;  1;

Legend:
Removed from v.1.102  
changed lines
  Added in v.1.119

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3