[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.98, Tue Apr 10 06:13:33 2007 UTC revision 1.121, Wed Oct 15 11:46:22 2008 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
     require Exporter;  
     use ERDB;  
     @ISA = qw(Exporter ERDB);  
3      use Data::Dumper;      use Data::Dumper;
4      use strict;      use strict;
5      use DBKernel;      use DBKernel;
# Line 15  Line 12 
12      use Stats;      use Stats;
13      use POSIX qw(strftime);      use POSIX qw(strftime);
14      use BasicLocation;      use BasicLocation;
15        use CustomAttributes;
16        use RemoteCustomAttributes;
17        use CGI;
18        use WikiTools;
19        use BioWords;
20        use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
23    
# Line 27  Line 30 
30  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>
31  whose definition and data files are in a co-directory named F<Data>.  whose definition and data files are in a co-directory named F<Data>.
32    
33  C<< my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' }); >>      my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' });
34    
35  Once you have a sprout object, you may use it to re-create the database, load the tables from  Once you have a sprout object, you may use it to re-create the database, load the tables from
36  tab-delimited flat files and perform queries. Several special methods are provided for common  tab-delimited flat files and perform queries. Several special methods are provided for common
37  query tasks. For example, L</genomes> lists the IDs of all the genomes in the database and  query tasks. For example, L</Genomes> lists the IDs of all the genomes in the database and
38  L</dna_seq> returns the DNA sequence for a specified genome location.  L</DNASeq> returns the DNA sequence for a specified genome location.
39    
40  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.
41    
# Line 44  Line 47 
47    
48  =head3 new  =head3 new
49    
50  C<< my $sprout = Sprout->new($dbName, \%options); >>      my $sprout = Sprout->new($dbName, \%options);
51    
52  This is the constructor for a sprout object. It connects to the database and loads the  This is the constructor for a sprout object. It connects to the database and loads the
53  database definition into memory. The positional first parameter specifies the name of the  database definition into memory. The positional first parameter specifies the name of the
# 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  C<< 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 132  Line 145 
145      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
146      # Set up space for the group file data.      # Set up space for the group file data.
147      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
148        # Set up space for the genome hash. We use this to identify NMPDR genomes.
149        $retVal->{genomeHash} = undef;
150        # Remember the data directory name.
151        $retVal->{dataDir} = $dataDir;
152      # Return it.      # Return it.
153      return $retVal;      return $retVal;
154  }  }
155    
156    =head3 ca
157    
158        my $ca = $sprout->ca():;
159    
160    Return the [[CustomAttributesPm]] object for retrieving object
161    properties.
162    
163    =cut
164    
165    sub ca {
166        # Get the parameters.
167        my ($self) = @_;
168        # Do we already have an attribute object?
169        my $retVal = $self->{_ca};
170        if (! defined $retVal) {
171            # No, create one. How we do it depends on the configuration.
172            if ($FIG_Config::attrURL) {
173                Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
174                $retVal = RemoteCustomAttributes->new($FIG_Config::attrURL);
175            } elsif ($FIG_Config::attrDbName) {
176                Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
177                my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
178                $retVal = CustomAttributes->new(user => $user);
179            }
180            # Save it for next time.
181            $self->{_ca} = $retVal;
182        }
183        # Return the result.
184        return $retVal;
185    }
186    
187    =head3 CoreGenomes
188    
189        my @genomes = $sprout->CoreGenomes($scope);
190    
191    Return the IDs of NMPDR genomes in the specified scope.
192    
193    =over 4
194    
195    =item scope
196    
197    Scope of the desired genomes. C<core> covers the original core genomes,
198    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
199    genomes in the system.
200    
201    =item RETURN
202    
203    Returns a list of the IDs for the genomes in the specified scope.
204    
205    =back
206    
207    =cut
208    
209    sub CoreGenomes {
210        # Get the parameters.
211        my ($self, $scope) = @_;
212        # Declare the return variable.
213        my @retVal = ();
214        # If we want all genomes, then this is easy.
215        if ($scope eq 'all') {
216            @retVal = $self->Genomes();
217        } else {
218            # Here we're dealing with groups. Get the hash of all the
219            # genome groups.
220            my %groups = $self->GetGroups();
221            # Loop through the groups, keeping the ones that we want.
222            for my $group (keys %groups) {
223                # Decide if we want to keep this group.
224                my $keepGroup = 0;
225                if ($scope eq 'nmpdr') {
226                    # NMPDR mode: keep all groups.
227                    $keepGroup = 1;
228                } elsif ($scope eq 'core') {
229                    # CORE mode. Only keep real core groups.
230                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
231                        $keepGroup = 1;
232                    }
233                }
234                # Add this group if we're keeping it.
235                if ($keepGroup) {
236                    push @retVal, @{$groups{$group}};
237                }
238            }
239        }
240        # Return the result.
241        return @retVal;
242    }
243    
244    =head3 SuperGroup
245    
246        my $superGroup = $sprout->SuperGroup($groupName);
247    
248    Return the name of the super-group containing the specified NMPDR genome
249    group. If no appropriate super-group can be found, an error will be
250    thrown.
251    
252    =over 4
253    
254    =item groupName
255    
256    Name of the group whose super-group is desired.
257    
258    =item RETURN
259    
260    Returns the name of the super-group containing the incoming group.
261    
262    =back
263    
264    =cut
265    
266    sub SuperGroup {
267        # Get the parameters.
268        my ($self, $groupName) = @_;
269        # Declare the return variable.
270        my $retVal;
271        # Get the group hash.
272        my %groupHash = $self->CheckGroupFile();
273        # Find the super-group genus.
274        $groupName =~ /([A-Z]\w+)/;
275        my $nameThing = $1;
276        # See if it's directly in the group hash.
277        if (exists $groupHash{$nameThing}) {
278            # Yes, then it's our result.
279            $retVal = $nameThing;
280        } else {
281            # No, so we have to search.
282            for my $superGroup (keys %groupHash) {
283                # Get this super-group's item list.
284                my $list = $groupHash{$superGroup}->{contents};
285                # Search it.
286                if (grep { $_->[0] eq $nameThing } @{$list}) {
287                    $retVal = $superGroup;
288                }
289            }
290            # Make sure we found something.
291            if (! $retVal) {
292                Confess("No super-group found for \"$groupName\".");
293            }
294        }
295        # Return the result.
296        return $retVal;
297    }
298    
299  =head3 MaxSegment  =head3 MaxSegment
300    
301  C<< my $length = $sprout->MaxSegment(); >>      my $length = $sprout->MaxSegment();
302    
303  This method returns the maximum permissible length of a feature segment. The length is important  This method returns the maximum permissible length of a feature segment. The length is important
304  because it enables us to make reasonable guesses at how to find features inside a particular  because it enables us to make reasonable guesses at how to find features inside a particular
# Line 155  Line 315 
315    
316  =head3 MaxSequence  =head3 MaxSequence
317    
318  C<< my $length = $sprout->MaxSequence(); >>      my $length = $sprout->MaxSequence();
319    
320  This method returns the maximum permissible length of a contig sequence. A contig is broken  This method returns the maximum permissible length of a contig sequence. A contig is broken
321  into sequences in order to save memory resources. In particular, when manipulating features,  into sequences in order to save memory resources. In particular, when manipulating features,
# Line 170  Line 330 
330    
331  =head3 Load  =head3 Load
332    
333  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
334    
335  Load the database from files in the data directory, optionally re-creating the tables.  Load the database from files in the data directory, optionally re-creating the tables.
336    
# Line 210  Line 370 
370    
371  =head3 LoadUpdate  =head3 LoadUpdate
372    
373  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
374    
375  Load updates to one or more database tables. This method enables the client to make changes to one  Load updates to one or more database tables. This method enables the client to make changes to one
376  or two tables without reloading the whole database. For each table, there must be a corresponding  or two tables without reloading the whole database. For each table, there must be a corresponding
# Line 256  Line 416 
416              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
417          } else {          } else {
418              # Attempt to load this table.              # Attempt to load this table.
419              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
420              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
421              $retVal->Accumulate($result);              $retVal->Accumulate($result);
422          }          }
# Line 267  Line 427 
427    
428  =head3 GenomeCounts  =head3 GenomeCounts
429    
430  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>      my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
431    
432  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
433  genomes will be included in the counts.  genomes will be included in the counts.
# Line 312  Line 472 
472    
473  =head3 ContigCount  =head3 ContigCount
474    
475  C<< my $count = $sprout->ContigCount($genomeID); >>      my $count = $sprout->ContigCount($genomeID);
476    
477  Return the number of contigs for the specified genome ID.  Return the number of contigs for the specified genome ID.
478    
# Line 339  Line 499 
499      return $retVal;      return $retVal;
500  }  }
501    
502  =head3 GeneMenu  =head3 GenomeMenu
503    
504        my $html = $sprout->GenomeMenu(%options);
505    
506    Generate a genome selection control with the specified name and options.
507    This control is almost but not quite the same as the genome control in the
508    B<SearchHelper> class. Eventually, the two will be combined.
509    
510    =over 4
511    
512    =item options
513    
514    Optional parameters for the control (see below).
515    
516    =item RETURN
517    
518    Returns the HTML for a genome selection control on a form (sometimes called a popup menu).
519    
520  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>  =back
521    
522  Return an HTML select menu of genomes. Each genome will be an option in the menu,  The valid options are as follows.
 and will be displayed by name with the ID and a contig count attached. The selection  
 value will be the genome ID. The genomes will be sorted by genus/species name.  
523    
524  =over 4  =over 4
525    
526  =item attributes  =item name
527    
528    Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
529    Terrible things will happen if you have two controls with the same name on the same page.
530    
531  Reference to a hash mapping attributes to values for the SELECT tag generated.  =item filter
532    
533  =item filterString  If specified, a filter for the list of genomes to display. The filter should be in the form of a
534    list reference. The first element of the list should be the filter string, and the remaining elements
535    the filter parameters.
536    
537    =item multiSelect
538    
539    If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
540    
541    =item size
542    
543    Number of rows to display in the control. The default is C<10>
544    
545    =item id
546    
547    ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
548    unless this ID is unique.
549    
550    =item selected
551    
552    A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
553    default is none.
554    
555    =item class
556    
557    If specified, a style class to assign to the genome control.
558    
559    =back
560    
561    =cut
562    
563    sub GenomeMenu {
564        # Get the parameters.
565        my ($self, %options) = @_;
566        # Get the control's name and ID.
567        my $menuName = $options{name} || $options{id} || 'myGenomeControl';
568        my $menuID = $options{id} || $menuName;
569        Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
570        # Compute the IDs for the status display.
571        my $divID = "${menuID}_status";
572        my $urlID = "${menuID}_url";
573        # Compute the code to show selected genomes in the status area.
574        my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
575        # Check for single-select or multi-select.
576        my $multiSelect = $options{multiSelect} || 0;
577        # Get the style data.
578        my $class = $options{class} || '';
579        # Get the list of pre-selected items.
580        my $selections = $options{selected} || [];
581        if (ref $selections ne 'ARRAY') {
582            $selections = [ split /\s*,\s*/, $selections ];
583        }
584        my %selected = map { $_ => 1 } @{$selections};
585        # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
586        # string or a list reference.
587        my $filterParms = $options{filter} || "";
588        if (! ref $filterParms) {
589            $filterParms = [split /\t|\\t/, $filterParms];
590        }
591        my $filterString = shift @{$filterParms};
592        # Get a list of all the genomes in group order. In fact, we only need them ordered
593        # by name (genus,species,strain), but putting primary-group in front enables us to
594        # take advantage of an existing index.
595        my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
596                                       $filterParms,
597                                       [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
598        # Create a hash to organize the genomes by group. Each group will contain a list of
599        # 2-tuples, the first element being the genome ID and the second being the genome
600        # name.
601        my %gHash = ();
602        for my $genome (@genomeList) {
603            # Get the genome data.
604            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
605            # Compute its name. This is the genus, species, strain (if any), and the contig count.
606            my $name = "$genus $species ";
607            $name .= "$strain " if $strain;
608            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
609            # Now we get the domain. The domain tells us the display style of the organism.
610            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
611            # Now compute the display group. This is normally the primary group, but if the
612            # organism is supporting, we blank it out.
613            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
614            # Push the genome into the group's list. Note that we use the real group
615            # name for the hash key here, not the display group name.
616            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
617        }
618        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
619        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
620        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
621        # that aren't "other". At some point, we will want to make this less complicated.
622        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
623                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
624        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
625        # Remember the number of NMPDR groups.
626        my $nmpdrGroupCount = scalar @groups;
627        # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
628        # of the domains found.
629        my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
630        my @domains = ();
631        for my $genomeData (@otherGenomes) {
632            my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
633            if (exists $gHash{$domain}) {
634                push @{$gHash{$domain}}, $genomeData;
635            } else {
636                $gHash{$domain} = [$genomeData];
637                push @domains, $domain;
638            }
639        }
640        # Add the domain groups at the end of the main group list. The main group list will now
641        # contain all the categories we need to display the genomes.
642        push @groups, sort @domains;
643        # Delete the supporting group.
644        delete $gHash{$FIG_Config::otherGroup};
645        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
646        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
647        # and use that to make the selections.
648        my $nmpdrCount = 0;
649        # Create the type counters.
650        my $groupCount = 1;
651        # Get the number of rows to display.
652        my $rows = $options{size} || 10;
653        # If we're multi-row, create an onChange event.
654        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
655        # Set up the multiple-select flag.
656        my $multipleTag = ($multiSelect ? " multiple" : "" );
657        # Set up the style class.
658        my $classTag = ($class ? " class=\"$class\"" : "" );
659        # Create the SELECT tag and stuff it into the output array.
660        my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
661        # Loop through the groups.
662        for my $group (@groups) {
663            # Get the genomes in the group.
664            for my $genome (@{$gHash{$group}}) {
665                # If this is an NMPDR organism, we add an extra style and count it.
666                my $nmpdrStyle = "";
667                if ($nmpdrGroupCount > 0) {
668                    $nmpdrCount++;
669                    $nmpdrStyle = " Core";
670                }
671                # Get the organism ID, name, contig count, and domain.
672                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
673                # See if we're pre-selected.
674                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
675                # Compute the display name.
676                my $nameString = "$name ($genomeID$contigCount)";
677                # Generate the option tag.
678                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
679                push @lines, "    $optionTag";
680            }
681            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
682            # groups.
683            $nmpdrGroupCount--;
684        }
685        # Close the SELECT tag.
686        push @lines, "</SELECT>";
687        if ($rows > 1) {
688            # We're in a non-compact mode, so we need to add some selection helpers. First is
689            # the search box. This allows the user to type text and change which genomes are
690            # displayed. For multiple-select mode, we include a button that selects the displayed
691            # genes. For single-select mode, we use a plain label instead.
692            my $searchThingName = "${menuID}_SearchThing";
693            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
694                                                 : "Show genomes containing");
695            push @lines, "<br />$searchThingLabel&nbsp;" .
696                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .
697                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
698            # For multi-select mode, we also have buttons to set and clear selections.
699            if ($multiSelect) {
700                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll(getElementById('$menuID')); $showSelect\" />";
701                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll(getElementById('$menuID')); $showSelect\" />";
702                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome(getElementById('$menuID'), $nmpdrCount, true); $showSelect;\" />";
703            }
704            # Add a hidden field we can use to generate organism page hyperlinks.
705            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";
706            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
707            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
708        }
709        # Assemble all the lines into a string.
710        my $retVal = join("\n", @lines, "");
711        # Return the result.
712        return $retVal;
713    }
714    
 A filter string for use in selecting the genomes. The filter string must conform  
 to the rules for the C<< ERDB->Get >> method.  
715    
716  =item params  =head3 Stem
717    
718  Reference to a list of values to be substituted in for the parameter marks in      my $stem = $sprout->Stem($word);
 the filter string.  
719    
720  =item selected (optional)  Return the stem of the specified word, or C<undef> if the word is not
721    stemmable. Note that even if the word is stemmable, the stem may be
722    the same as the original word.
723    
724  ID of the genome to be initially selected.  =over 4
725    
726  =item fast (optional)  =item word
727    
728  If specified and TRUE, the contig counts will be omitted to improve performance.  Word to convert into a stem.
729    
730  =item RETURN  =item RETURN
731    
732  Returns an HTML select menu with the specified genomes as selectable options.  Returns a stem of the word (which may be the word itself), or C<undef> if
733    the word is not stemmable.
734    
735  =back  =back
736    
737  =cut  =cut
738    
739  sub GeneMenu {  sub Stem {
740      # Get the parameters.      # Get the parameters.
741      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;      my ($self, $word) = @_;
742      my $slowMode = ! $fast;      # Get the stemmer object.
743      # Default to nothing selected. This prevents an execution warning if "$selected"      my $stemmer = $self->{stemmer};
744      # is undefined.      if (! defined $stemmer) {
745      $selected = "" unless defined $selected;          # We don't have one pre-built, so we build and save it now.
746      Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);          $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
747      # Start the menu.                                   stops => "$FIG_Config::sproutData/StopWords.txt",
748      my $retVal = "<select " .                                   cache => 0);
749          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .          $self->{stemmer} = $stemmer;
         ">\n";  
     # Get the genomes.  
     my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',  
                                                                      'Genome(genus)',  
                                                                      'Genome(species)',  
                                                                      'Genome(unique-characterization)']);  
     # Sort them by name.  
     my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;  
     # Loop through the genomes, creating the option tags.  
     for my $genomeData (@sorted) {  
         # Get the data for this genome.  
         my ($genomeID, $genus, $species, $strain) = @{$genomeData};  
         # Get the contig count.  
         my $contigInfo = "";  
         if ($slowMode) {  
             my $count = $self->ContigCount($genomeID);  
             my $counting = ($count == 1 ? "contig" : "contigs");  
             $contigInfo = "[$count $counting]";  
         }  
         # Find out if we're selected.  
         my $selectOption = ($selected eq $genomeID ? " selected" : "");  
         # Build the option tag.  
         $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";  
750      }      }
751      # Close the SELECT tag.      # Try to stem the word.
752      $retVal .= "</select>\n";      my $retVal = $stemmer->Process($word);
753      # Return the result.      # Return the result.
754      return $retVal;      return $retVal;
755  }  }
756    
757    
758  =head3 Build  =head3 Build
759    
760  C<< $sprout->Build(); >>      $sprout->Build();
761    
762  Build the database. The database will be cleared and the tables re-created from the metadata.  Build the database. The database will be cleared and the tables re-created from the metadata.
763  This method is useful when a database is brand new or when the database definition has  This method is useful when a database is brand new or when the database definition has
# Line 439  Line 774 
774    
775  =head3 Genomes  =head3 Genomes
776    
777  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
778    
779  Return a list of all the genome IDs.  Return a list of all the genome IDs.
780    
# Line 456  Line 791 
791    
792  =head3 GenusSpecies  =head3 GenusSpecies
793    
794  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
795    
796  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
797    
# Line 488  Line 823 
823    
824  =head3 FeaturesOf  =head3 FeaturesOf
825    
826  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
827    
828  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
829    
# Line 533  Line 868 
868    
869  =head3 FeatureLocation  =head3 FeatureLocation
870    
871  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
872    
873  Return the location of a feature in its genome's contig segments. In a list context, this method  Return the location of a feature in its genome's contig segments. In a list context, this method
874  will return a list of the locations. In a scalar context, it will return the locations as a space-  will return a list of the locations. In a scalar context, it will return the locations as a space-
# Line 557  Line 892 
892  =item RETURN  =item RETURN
893    
894  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
895  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
896    wasn't found.
897    
898  =back  =back
899    
900  =cut  =cut
901  #: Return Type @;  
 #: Return Type $;  
902  sub FeatureLocation {  sub FeatureLocation {
903      # Get the parameters.      # Get the parameters.
904      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
905      # Create a query for the feature locations.      # Declare the return variable.
     my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",  
                            [$featureID]);  
     # Create the return list.  
906      my @retVal = ();      my @retVal = ();
907      # Set up the variables used to determine if we have adjacent segments. This initial setup will      # Get the feature record.
908      # not match anything.      my $object = $self->GetEntity('Feature', $featureID);
909      my ($prevContig, $prevBeg, $prevDir, $prevLen) = ("", 0, "0", 0);      # Only proceed if we found it.
910      # Loop through the query results, creating location specifiers.      if (defined $object) {
911      while (my $location = $query->Fetch()) {          # Get the location string.
912          # Get the location parameters.          my $locString = $object->PrimaryValue('Feature(location-string)');
913          my ($contigID, $beg, $dir, $len) = $location->Values(['IsLocatedIn(to-link)',          # Create the return list.
914              'IsLocatedIn(beg)', 'IsLocatedIn(dir)', 'IsLocatedIn(len)']);          @retVal = split /\s*,\s*/, $locString;
         # Check to see if we are adjacent to the previous segment.  
         if ($prevContig eq $contigID && $dir eq $prevDir) {  
             # Here the new segment is in the same direction on the same contig. Insure the  
             # new segment's beginning is next to the old segment's end.  
             if ($dir eq "-" && $beg + $len == $prevBeg) {  
                 # Here we're merging two backward blocks, so we keep the new begin point  
                 # and adjust the length.  
                 $len += $prevLen;  
                 # Pop the old segment off. The new one will replace it later.  
                 pop @retVal;  
             } elsif ($dir eq "+" && $beg == $prevBeg + $prevLen) {  
                 # Here we need to merge two forward blocks. Adjust the beginning and  
                 # length values to include both segments.  
                 $beg = $prevBeg;  
                 $len += $prevLen;  
                 # Pop the old segment off. The new one will replace it later.  
                 pop @retVal;  
             }  
         }  
         # Remember this specifier for the adjacent-segment test the next time through.  
         ($prevContig, $prevBeg, $prevDir, $prevLen) = ($contigID, $beg, $dir, $len);  
         # Compute the initial base pair.  
         my $start = ($dir eq "+" ? $beg : $beg + $len - 1);  
         # Add the specifier to the list.  
         push @retVal, "${contigID}_$start$dir$len";  
915      }      }
916      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
917      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
# Line 612  Line 919 
919    
920  =head3 ParseLocation  =head3 ParseLocation
921    
922  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
923    
924  Split a location specifier into the contig ID, the starting point, the direction, and the  Split a location specifier into the contig ID, the starting point, the direction, and the
925  length.  length.
# Line 631  Line 938 
938  =back  =back
939    
940  =cut  =cut
941  #: Return Type @;  
942  sub ParseLocation {  sub ParseLocation {
943      # Get the parameter. Note that if we're called as an instance method, we ignore      # Get the parameter. Note that if we're called as an instance method, we ignore
944      # the first parameter.      # the first parameter.
# Line 658  Line 965 
965    
966  =head3 PointLocation  =head3 PointLocation
967    
968  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
969    
970  Return the offset into the specified location of the specified point on the contig. If  Return the offset into the specified location of the specified point on the contig. If
971  the specified point is before the location, a negative value will be returned. If it is  the specified point is before the location, a negative value will be returned. If it is
# Line 687  Line 994 
994  =back  =back
995    
996  =cut  =cut
997  #: Return Type $;  
998  sub PointLocation {  sub PointLocation {
999      # Get the parameter. Note that if we're called as an instance method, we ignore      # Get the parameter. Note that if we're called as an instance method, we ignore
1000      # the first parameter.      # the first parameter.
# Line 710  Line 1017 
1017    
1018  =head3 DNASeq  =head3 DNASeq
1019    
1020  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
1021    
1022  This method returns the DNA sequence represented by a list of locations. The list of locations  This method returns the DNA sequence represented by a list of locations. The list of locations
1023  should be of the form returned by L</featureLocation> when in a list context. In other words,  should be of the form returned by L</featureLocation> when in a list context. In other words,
# Line 794  Line 1101 
1101    
1102  =head3 AllContigs  =head3 AllContigs
1103    
1104  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
1105    
1106  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
1107    
# Line 824  Line 1131 
1131    
1132  =head3 GenomeLength  =head3 GenomeLength
1133    
1134  C<< my $length = $sprout->GenomeLength($genomeID); >>      my $length = $sprout->GenomeLength($genomeID);
1135    
1136  Return the length of the specified genome in base pairs.  Return the length of the specified genome in base pairs.
1137    
# Line 859  Line 1166 
1166    
1167  =head3 FeatureCount  =head3 FeatureCount
1168    
1169  C<< my $count = $sprout->FeatureCount($genomeID, $type); >>      my $count = $sprout->FeatureCount($genomeID, $type);
1170    
1171  Return the number of features of the specified type in the specified genome.  Return the number of features of the specified type in the specified genome.
1172    
# Line 894  Line 1201 
1201    
1202  =head3 GenomeAssignments  =head3 GenomeAssignments
1203    
1204  C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>      my $fidHash = $sprout->GenomeAssignments($genomeID);
1205    
1206  Return a list of a genome's assigned features. The return hash will contain each  Return a list of a genome's assigned features. The return hash will contain each
1207  assigned feature of the genome mapped to the text of its most recent functional  assigned feature of the genome mapped to the text of its most recent functional
# Line 937  Line 1244 
1244    
1245  =head3 ContigLength  =head3 ContigLength
1246    
1247  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->ContigLength($contigID);
1248    
1249  Compute the length of a contig.  Compute the length of a contig.
1250    
# Line 976  Line 1283 
1283    
1284  =head3 ClusterPEGs  =head3 ClusterPEGs
1285    
1286  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
1287    
1288  Cluster the PEGs in a list according to the cluster coding scheme of the specified  Cluster the PEGs in a list according to the cluster coding scheme of the specified
1289  subsystem. In order for this to work properly, the subsystem object must have  subsystem. In order for this to work properly, the subsystem object must have
1290  been used recently to retrieve the PEGs using the B<get_pegs_from_cell> method.  been used recently to retrieve the PEGs using the B<get_pegs_from_cell> or
1291  This causes the cluster numbers to be pulled into the subsystem's color hash.  B<get_row> methods. This causes the cluster numbers to be pulled into the
1292  If a PEG is not found in the color hash, it will not appear in the output  subsystem's color hash. If a PEG is not found in the color hash, it will not
1293  sequence.  appear in the output sequence.
1294    
1295  =over 4  =over 4
1296    
# Line 1024  Line 1331 
1331    
1332  =head3 GenesInRegion  =head3 GenesInRegion
1333    
1334  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1335    
1336  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1337    
# Line 1053  Line 1360 
1360  =back  =back
1361    
1362  =cut  =cut
1363  #: Return Type @@;  
1364  sub GenesInRegion {  sub GenesInRegion {
1365      # Get the parameters.      # Get the parameters.
1366      my ($self, $contigID, $start, $stop) = @_;      my ($self, $contigID, $start, $stop) = @_;
1367      # Get the maximum segment length.      # Get the maximum segment length.
1368      my $maximumSegmentLength = $self->MaxSegment;      my $maximumSegmentLength = $self->MaxSegment;
     # Create a hash to receive the feature list. We use a hash so that we can eliminate  
     # duplicates easily. The hash key will be the feature ID. The value will be a two-element  
     # containing the minimum and maximum offsets. We will use the offsets to sort the results  
     # when we're building the result set.  
     my %featuresFound = ();  
1369      # Prime the values we'll use for the returned beginning and end.      # Prime the values we'll use for the returned beginning and end.
1370      my @initialMinMax = ($self->ContigLength($contigID), 0);      my @initialMinMax = ($self->ContigLength($contigID), 0);
1371      my ($min, $max) = @initialMinMax;      my ($min, $max) = @initialMinMax;
1372      # Create a table of parameters for each query. Each query looks for features travelling in      # Get the overlapping features.
1373        my @featureObjects = $self->GeneDataInRegion($contigID, $start, $stop);
1374        # We'l use this hash to help us track the feature IDs and sort them. The key is the
1375        # feature ID and the value is a [$left,$right] pair indicating the maximum extent
1376        # of the feature's locations.
1377        my %featureMap = ();
1378        # Loop through them to do the begin/end analysis.
1379        for my $featureObject (@featureObjects) {
1380            # Get the feature's location string. This may contain multiple actual locations.
1381            my ($locations, $fid) = $featureObject->Values([qw(Feature(location-string) Feature(id))]);
1382            my @locationSegments = split /\s*,\s*/, $locations;
1383            # Loop through the locations.
1384            for my $locationSegment (@locationSegments) {
1385                # Construct an object for the location.
1386                my $locationObject = BasicLocation->new($locationSegment);
1387                # Merge the current segment's begin and end into the min and max.
1388                my ($left, $right) = ($locationObject->Left, $locationObject->Right);
1389                my ($beg, $end);
1390                if (exists $featureMap{$fid}) {
1391                    ($beg, $end) = @{$featureMap{$fid}};
1392                    $beg = $left if $left < $beg;
1393                    $end = $right if $right > $end;
1394                } else {
1395                    ($beg, $end) = ($left, $right);
1396                }
1397                $min = $beg if $beg < $min;
1398                $max = $end if $end > $max;
1399                # Store the feature's new extent back into the hash table.
1400                $featureMap{$fid} = [$beg, $end];
1401            }
1402        }
1403        # Now we must compute the list of the IDs for the features found. We start with a list
1404        # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
1405        # but the result of the sort will be the same.)
1406        my @list = map { [$featureMap{$_}->[0] + $featureMap{$_}->[1], $_] } keys %featureMap;
1407        # Now we sort by midpoint and yank out the feature IDs.
1408        my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
1409        # Return it along with the min and max.
1410        return (\@retVal, $min, $max);
1411    }
1412    
1413    =head3 GeneDataInRegion
1414    
1415        my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1416    
1417    List the features which overlap a specified region in a contig.
1418    
1419    =over 4
1420    
1421    =item contigID
1422    
1423    ID of the contig containing the region of interest.
1424    
1425    =item start
1426    
1427    Offset of the first residue in the region of interest.
1428    
1429    =item stop
1430    
1431    Offset of the last residue in the region of interest.
1432    
1433    =item RETURN
1434    
1435    Returns a list of B<ERDBObjects> for the desired features. Each object will
1436    contain a B<Feature> record.
1437    
1438    =back
1439    
1440    =cut
1441    
1442    sub GeneDataInRegion {
1443        # Get the parameters.
1444        my ($self, $contigID, $start, $stop) = @_;
1445        # Get the maximum segment length.
1446        my $maximumSegmentLength = $self->MaxSegment;
1447        # Create a hash to receive the feature list. We use a hash so that we can eliminate
1448        # duplicates easily. The hash key will be the feature ID. The value will be the feature's
1449        # ERDBObject from the query.
1450        my %featuresFound = ();
1451        # Create a table of parameters for the queries. Each query looks for features travelling in
1452      # a particular direction. The query parameters include the contig ID, the feature direction,      # a particular direction. The query parameters include the contig ID, the feature direction,
1453      # the lowest possible start position, and the highest possible start position. This works      # the lowest possible start position, and the highest possible start position. This works
1454      # because each feature segment length must be no greater than the maximum segment length.      # because each feature segment length must be no greater than the maximum segment length.
# Line 1076  Line 1457 
1457      # Loop through the query parameters.      # Loop through the query parameters.
1458      for my $parms (values %queryParms) {      for my $parms (values %queryParms) {
1459          # Create the query.          # Create the query.
1460          my $query = $self->Get(['IsLocatedIn'],          my $query = $self->Get([qw(Feature IsLocatedIn)],
1461              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",
1462              $parms);              $parms);
1463          # Loop through the feature segments found.          # Loop through the feature segments found.
1464          while (my $segment = $query->Fetch) {          while (my $segment = $query->Fetch) {
1465              # Get the data about this segment.              # Get the data about this segment.
1466              my ($featureID, $dir, $beg, $len) = $segment->Values(['IsLocatedIn(from-link)',              my ($featureID, $contig, $dir, $beg, $len) = $segment->Values([qw(IsLocatedIn(from-link)
1467                  'IsLocatedIn(dir)', 'IsLocatedIn(beg)', 'IsLocatedIn(len)']);                  IsLocatedIn(to-link) IsLocatedIn(dir) IsLocatedIn(beg) IsLocatedIn(len))]);
1468              # Determine if this feature actually overlaps the region. The query insures that              # Determine if this feature segment actually overlaps the region. The query insures that
1469              # this will be the case if the segment is the maximum length, so to fine-tune              # this will be the case if the segment is the maximum length, so to fine-tune
1470              # the results we insure that the inequality from the query holds using the actual              # the results we insure that the inequality from the query holds using the actual
1471              # length.              # length.
1472              my ($found, $end) = (0, 0);              my $loc = BasicLocation->new($contig, $beg, $dir, $len);
1473              if ($dir eq '+') {              my $found = $loc->Overlap($start, $stop);
                 $end = $beg + $len;  
                 if ($end >= $start) {  
                     # Denote we found a useful feature.  
                     $found = 1;  
                 }  
             } elsif ($dir eq '-') {  
                 # Note we switch things around so that the beginning is to the left of the  
                 # ending.  
                 ($beg, $end) = ($beg - $len, $beg);  
                 if ($beg <= $stop) {  
                     # Denote we found a useful feature.  
                     $found = 1;  
                 }  
             }  
1474              if ($found) {              if ($found) {
1475                  # Here we need to record the feature and update the minima and maxima. First,                  # Save this feature in the result list.
1476                  # get the current entry for the specified feature.                  $featuresFound{$featureID} = $segment;
                 my ($loc1, $loc2) = (exists $featuresFound{$featureID} ? @{$featuresFound{$featureID}} :  
                                      @initialMinMax);  
                 # Merge the current segment's begin and end into the feature begin and end and the  
                 # global min and max.  
                 if ($beg < $loc1) {  
                     $loc1 = $beg;  
                     $min = $beg if $beg < $min;  
                 }  
                 if ($end > $loc2) {  
                     $loc2 = $end;  
                     $max = $end if $end > $max;  
1477                  }                  }
                 # Store the entry back into the hash table.  
                 $featuresFound{$featureID} = [$loc1, $loc2];  
1478              }              }
1479          }          }
1480      }      # Return the ERDB objects for the features found.
1481      # Now we must compute the list of the IDs for the features found. We start with a list      return values %featuresFound;
     # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,  
     # but the result of the sort will be the same.)  
     my @list = map { [$featuresFound{$_}->[0] + $featuresFound{$_}->[1], $_] } keys %featuresFound;  
     # Now we sort by midpoint and yank out the feature IDs.  
     my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;  
     # Return it along with the min and max.  
     return (\@retVal, $min, $max);  
1482  }  }
1483    
1484  =head3 FType  =head3 FType
1485    
1486  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1487    
1488  Return the type of a feature.  Return the type of a feature.
1489    
# Line 1166  Line 1513 
1513    
1514  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1515    
1516  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1517    
1518  Return the annotations of a feature.  Return the annotations of a feature.
1519    
# Line 1229  Line 1576 
1576    
1577  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1578    
1579  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1580    
1581  Return all of the functional assignments for a particular feature. The data is returned as a  Return all of the functional assignments for a particular feature. The data is returned as a
1582  hash of functional assignments to user IDs. A functional assignment is a type of annotation,  hash of functional assignments to user IDs. A functional assignment is a type of annotation,
# Line 1284  Line 1631 
1631    
1632  =head3 FunctionOf  =head3 FunctionOf
1633    
1634  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1635    
1636  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1637    
# Line 1297  Line 1644 
1644  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
1645  is trusted.  is trusted.
1646    
1647  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.
1648  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.  
1649    
1650  =over 4  =over 4
1651    
# Line 1325  Line 1671 
1671      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1672      # Declare the return value.      # Declare the return value.
1673      my $retVal;      my $retVal;
1674      # Determine the ID type.      # Find a FIG ID for this feature.
1675      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1676        # Only proceed if we have an ID.
1677        if ($fid) {
1678          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1679          if (!$userID) {          if (!$userID) {
1680              # Use the primary assignment.              # Use the primary assignment.
1681              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1682          } else {          } else {
1683              # We must build the list of trusted users.              # We must build the list of trusted users.
1684              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1356  Line 1704 
1704              # 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.
1705              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1706                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1707                                     [$featureID]);                                     [$fid]);
1708              my $timeSelected = 0;              my $timeSelected = 0;
1709              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1710              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1376  Line 1724 
1724                  }                  }
1725              }              }
1726          }          }
     } 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)']);  
1727      }      }
1728      # Return the assignment found.      # Return the assignment found.
1729      return $retVal;      return $retVal;
# Line 1388  Line 1731 
1731    
1732  =head3 FunctionsOf  =head3 FunctionsOf
1733    
1734  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1735    
1736  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1737    
# Line 1399  Line 1742 
1742  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
1743  most features only have a small number of annotations.  most features only have a small number of annotations.
1744    
 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.  
   
1745  =over 4  =over 4
1746    
1747  =item featureID  =item featureID
# Line 1423  Line 1762 
1762      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1763      # Declare the return value.      # Declare the return value.
1764      my @retVal = ();      my @retVal = ();
1765      # Determine the ID type.      # Convert to a FIG ID.
1766      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1767        # Only proceed if we found one.
1768        if ($fid) {
1769          # 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
1770          # users.          # users.
1771          my %trusteeTable = ();          my %trusteeTable = ();
1772          # 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.
1773          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1774                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1775                                 [$featureID]);                                 [$fid]);
1776          my $timeSelected = 0;          my $timeSelected = 0;
1777          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1778          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1446  Line 1787 
1787                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1788              }              }
1789          }          }
     } 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;  
1790      }      }
1791      # Return the assignments found.      # Return the assignments found.
1792      return @retVal;      return @retVal;
# Line 1460  Line 1794 
1794    
1795  =head3 BBHList  =head3 BBHList
1796    
1797  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1798    
1799  Return a hash mapping the features in a specified list to their bidirectional best hits  Return a hash mapping the features in a specified list to their bidirectional best hits
1800  on a specified target genome.  on a specified target genome.
# Line 1510  Line 1844 
1844    
1845  =head3 SimList  =head3 SimList
1846    
1847  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1848    
1849  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1850    
# Line 1546  Line 1880 
1880    
1881  =head3 IsComplete  =head3 IsComplete
1882    
1883  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1884    
1885  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1886    
# Line 1574  Line 1908 
1908      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1909      if ($genomeData) {      if ($genomeData) {
1910          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1911          ($retVal) = $genomeData->Value('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1912      }      }
1913      # Return the result.      # Return the result.
1914      return $retVal;      return $retVal;
# Line 1582  Line 1916 
1916    
1917  =head3 FeatureAliases  =head3 FeatureAliases
1918    
1919  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1920    
1921  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1922    
# Line 1605  Line 1939 
1939      # Get the parameters.      # Get the parameters.
1940      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1941      # Get the desired feature's aliases      # Get the desired feature's aliases
1942      my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);      my @retVal = $self->GetFlat(['IsAliasOf'], "IsAliasOf(to-link) = ?", [$featureID], 'IsAliasOf(from-link)');
1943      # Return the result.      # Return the result.
1944      return @retVal;      return @retVal;
1945  }  }
1946    
1947  =head3 GenomeOf  =head3 GenomeOf
1948    
1949  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1950    
1951  Return the genome that contains a specified feature or contig.  Return the genome that contains a specified feature or contig.
1952    
# Line 1634  Line 1968 
1968  sub GenomeOf {  sub GenomeOf {
1969      # Get the parameters.      # Get the parameters.
1970      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
     # Create a query to find the genome associated with the incoming ID.  
     my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ? OR HasContig(to-link) = ?",  
                            [$featureID, $featureID]);  
1971      # Declare the return value.      # Declare the return value.
1972      my $retVal;      my $retVal;
1973      # Get the genome ID.      # Parse the genome ID from the feature ID.
1974      if (my $relationship = $query->Fetch()) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1975          ($retVal) = $relationship->Value('HasContig(from-link)');          $retVal = $1;
1976        } else {
1977            # Find the feature by alias.
1978            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1979            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1980                $retVal = $1;
1981            }
1982      }      }
1983      # Return the value found.      # Return the value found.
1984      return $retVal;      return $retVal;
# Line 1649  Line 1986 
1986    
1987  =head3 CoupledFeatures  =head3 CoupledFeatures
1988    
1989  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
1990    
1991  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
1992  functionally coupled if they tend to be clustered on the same chromosome.  functionally coupled if they tend to be clustered on the same chromosome.
# Line 1671  Line 2008 
2008  sub CoupledFeatures {  sub CoupledFeatures {
2009      # Get the parameters.      # Get the parameters.
2010      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2011        # Ask the coupling server for the data.
2012      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
2013      # Create a query to retrieve the functionally-coupled features.      my @rawPairs = FIGRules::NetCouplingData('coupled_to', id1 => $featureID);
2014      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      Trace(scalar(@rawPairs) . " couplings returned.") if T(coupling => 3);
2015                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);      # Form them into a hash.
     # This value will be set to TRUE if we find at least one coupled feature.  
     my $found = 0;  
     # Create the return hash.  
2016      my %retVal = ();      my %retVal = ();
2017      # Retrieve the relationship records and store them in the hash.      for my $pair (@rawPairs) {
2018      while (my $clustering = $query->Fetch()) {          # Get the feature ID and score.
2019          # Get the ID and score of the coupling.          my ($featureID2, $score) = @{$pair};
2020          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          # Only proceed if the feature is in NMPDR.
2021                                                          'Coupling(score)']);          if ($self->_CheckFeature($featureID2)) {
2022          Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);              $retVal{$featureID2} = $score;
2023          # Get the other feature that participates in the coupling.          }
         my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],  
                                            "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",  
                                            [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');  
         Trace("$couplingID target feature is $otherFeatureID.") if T(coupling => 4);  
         # Attach the other feature's score to its ID.  
         $retVal{$otherFeatureID} = $score;  
         $found = 1;  
2024      }      }
2025      # Functional coupling is reflexive. If we found at least one coupled feature, we must add      # Functional coupling is reflexive. If we found at least one coupled feature, we must add
2026      # the incoming feature as well.      # the incoming feature as well.
2027      if ($found) {      if (keys %retVal) {
2028          $retVal{$featureID} = 9999;          $retVal{$featureID} = 9999;
2029      }      }
2030      # Return the hash.      # Return the hash.
# Line 1705  Line 2033 
2033    
2034  =head3 CouplingEvidence  =head3 CouplingEvidence
2035    
2036  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
2037    
2038  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
2039    
# Line 1753  Line 2081 
2081      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
2082      # Declare the return variable.      # Declare the return variable.
2083      my @retVal = ();      my @retVal = ();
2084      # Our first task is to find out the nature of the coupling: whether or not      # Get the coupling and evidence data.
2085      # it exists, its score, and whether the features are stored in the same      my @rawData = FIGRules::NetCouplingData('coupling_evidence', id1 => $peg1, id2 => $peg2);
2086      # order as the ones coming in.      # Loop through the raw data, saving the ones that are in NMPDR genomes.
2087      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);      for my $rawTuple (@rawData) {
2088      # Only proceed if a coupling exists.          if ($self->_CheckFeature($rawTuple->[0]) && $self->_CheckFeature($rawTuple->[1])) {
2089      if ($couplingID) {              push @retVal, $rawTuple;
         # Determine the ordering to place on the evidence items. If we're  
         # inverted, we want to see feature 2 before feature 1 (descending); otherwise,  
         # we want feature 1 before feature 2 (normal).  
         Trace("Coupling evidence for ($peg1, $peg2) with inversion flag $inverted.") if T(Coupling => 4);  
         my $ordering = ($inverted ? "DESC" : "");  
         # Get the coupling evidence.  
         my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],  
                                           "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",  
                                           [$couplingID],  
                                           ['PCH(used)', 'UsesAsEvidence(to-link)']);  
         # Loop through the evidence items. Each piece of evidence is represented by two  
         # positions in the evidence list, one for each feature on the other side of the  
         # evidence link. If at some point we want to generalize to couplings with  
         # more than two positions, this section of code will need to be re-done.  
         while (@evidenceList > 0) {  
             my $peg1Data = shift @evidenceList;  
             my $peg2Data = shift @evidenceList;  
             Trace("Peg 1 is " . $peg1Data->[1] . " and Peg 2 is " . $peg2Data->[1] . ".") if T(Coupling => 4);  
             push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];  
         }  
         Trace("Last index in evidence result is is $#retVal.") if T(Coupling => 4);  
     }  
     # Return the result.  
     return @retVal;  
2090  }  }
   
 =head3 GetCoupling  
   
 C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>  
   
 Return the coupling (if any) for the specified pair of PEGs. If a coupling  
 exists, we return the coupling ID along with an indicator of whether the  
 coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.  
 In the second case, we say the coupling is I<inverted>. The importance of an  
 inverted coupling is that the PEGs in the evidence will appear in reverse order.  
   
 =over 4  
   
 =item peg1  
   
 ID of the feature of interest.  
   
 =item peg2  
   
 ID of the potentially coupled feature.  
   
 =item RETURN  
   
 Returns a three-element list. The first element contains the database ID of  
 the coupling. The second element is FALSE if the coupling is stored in the  
 database in the caller specified order and TRUE if it is stored in the  
 inverted order. The third element is the coupling's score. If the coupling  
 does not exist, all three list elements will be C<undef>.  
   
 =back  
   
 =cut  
 #: Return Type $%@;  
 sub GetCoupling {  
     # Get the parameters.  
     my ($self, $peg1, $peg2) = @_;  
     # Declare the return values. We'll start with the coupling ID and undefine the  
     # flag and score until we have more information.  
     my ($retVal, $inverted, $score) = ($self->CouplingID($peg1, $peg2), undef, undef);  
     # Find the coupling data.  
     my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],  
                                  "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",  
                                  [$retVal], ["ParticipatesInCoupling(from-link)", "Coupling(score)"]);  
     # Check to see if we found anything.  
     if (!@pegs) {  
         Trace("No coupling found.") if T(Coupling => 4);  
         # No coupling, so undefine the return value.  
         $retVal = undef;  
     } else {  
         # We have a coupling! Get the score and check for inversion.  
         $score = $pegs[0]->[1];  
         my $firstFound = $pegs[0]->[0];  
         $inverted = ($firstFound ne $peg1);  
         Trace("Coupling score is $score. First peg is $firstFound, peg 1 is $peg1.") if T(Coupling => 4);  
2091      }      }
2092      # Return the result.      # Return the result.
2093      return ($retVal, $inverted, $score);      return @retVal;
2094  }  }
2095    
2096  =head3 GetSynonymGroup  =head3 GetSynonymGroup
2097    
2098  C<< my $id = $sprout->GetSynonymGroup($fid); >>      my $id = $sprout->GetSynonymGroup($fid);
2099    
2100  Return the synonym group name for the specified feature.  Return the synonym group name for the specified feature.
2101    
# Line 1884  Line 2134 
2134    
2135  =head3 GetBoundaries  =head3 GetBoundaries
2136    
2137  C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
2138    
2139  Determine the begin and end boundaries for the locations in a list. All of the  Determine the begin and end boundaries for the locations in a list. All of the
2140  locations must belong to the same contig and have mostly the same direction in  locations must belong to the same contig and have mostly the same direction in
# Line 1946  Line 2196 
2196      return ($contig, $beg, $end);      return ($contig, $beg, $end);
2197  }  }
2198    
 =head3 CouplingID  
   
 C<< my $couplingID = $sprout->CouplingID($peg1, $peg2); >>  
   
 Return the coupling ID for a pair of feature IDs.  
   
 The coupling ID is currently computed by joining the feature IDs in  
 sorted order with a space. Client modules (that is, modules which  
 use Sprout) should not, however, count on this always being the  
 case. This method provides a way for abstracting the concept of a  
 coupling ID. All that we know for sure about it is that it can be  
 generated easily from the feature IDs and the order of the IDs  
 in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>  
 will have the same value as C<CouplingID("b1", "a1")>.  
   
 =over 4  
   
 =item peg1  
   
 First feature of interest.  
   
 =item peg2  
   
 Second feature of interest.  
   
 =item RETURN  
   
 Returns the ID that would be used to represent a functional coupling of  
 the two specified PEGs.  
   
 =back  
   
 =cut  
 #: Return Type $;  
 sub CouplingID {  
     my ($self, @pegs) = @_;  
     return $self->DigestKey(join " ", sort @pegs);  
 }  
   
2199  =head3 ReadFasta  =head3 ReadFasta
2200    
2201  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
2202    
2203  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by
2204  one or more lines of data. The first line begins with a > character and contains an ID.  one or more lines of data. The first line begins with a > character and contains an ID.
# Line 2053  Line 2264 
2264    
2265  =head3 FormatLocations  =head3 FormatLocations
2266    
2267  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
2268    
2269  Insure that a list of feature locations is in the Sprout format. The Sprout feature location  Insure that a list of feature locations is in the Sprout format. The Sprout feature location
2270  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward
# Line 2118  Line 2329 
2329    
2330  =head3 DumpData  =head3 DumpData
2331    
2332  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2333    
2334  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.
2335    
# Line 2135  Line 2346 
2346    
2347  =head3 XMLFileName  =head3 XMLFileName
2348    
2349  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2350    
2351  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2352    
# Line 2146  Line 2357 
2357      return $self->{_xmlName};      return $self->{_xmlName};
2358  }  }
2359    
2360    =head3 GetGenomeNameData
2361    
2362        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2363    
2364    Return the genus, species, and unique characterization for a genome. This
2365    is similar to L</GenusSpecies>, with the exception that it returns the
2366    values in three seperate fields.
2367    
2368    =over 4
2369    
2370    =item genomeID
2371    
2372    ID of the genome whose name data is desired.
2373    
2374    =item RETURN
2375    
2376    Returns a three-element list, consisting of the genus, species, and strain
2377    of the specified genome. If the genome is not found, an error occurs.
2378    
2379    =back
2380    
2381    =cut
2382    
2383    sub GetGenomeNameData {
2384        # Get the parameters.
2385        my ($self, $genomeID) = @_;
2386        # Get the desired values.
2387        my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>
2388                                                                [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);
2389        # Throw an error if they were not found.
2390        if (! defined $genus) {
2391            Confess("Genome $genomeID not found in database.");
2392        }
2393        # Return the results.
2394        return ($genus, $species, $strain);
2395    }
2396    
2397    =head3 GetGenomeByNameData
2398    
2399        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2400    
2401    Return a list of the IDs of the genomes with the specified genus,
2402    species, and strain. In almost every case, there will be either zero or
2403    one IDs returned; however, two or more IDs could be returned if there are
2404    multiple versions of the genome in the database.
2405    
2406    =over 4
2407    
2408    =item genus
2409    
2410    Genus of the desired genome.
2411    
2412    =item species
2413    
2414    Species of the desired genome.
2415    
2416    =item strain
2417    
2418    Strain (unique characterization) of the desired genome. This may be an empty
2419    string, in which case it is presumed that the desired genome has no strain
2420    specified.
2421    
2422    =item RETURN
2423    
2424    Returns a list of the IDs of the genomes having the specified genus, species, and
2425    strain.
2426    
2427    =back
2428    
2429    =cut
2430    
2431    sub GetGenomeByNameData {
2432        # Get the parameters.
2433        my ($self, $genus, $species, $strain) = @_;
2434        # Try to find the genomes.
2435        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2436                                    [$genus, $species, $strain], 'Genome(id)');
2437        # Return the result.
2438        return @retVal;
2439    }
2440    
2441  =head3 Insert  =head3 Insert
2442    
2443  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2444    
2445  Insert an entity or relationship instance into the database. The entity or relationship of interest  Insert an entity or relationship instance into the database. The entity or relationship of interest
2446  is defined by a type name and then a hash of field names to values. Field values in the primary  is defined by a type name and then a hash of field names to values. Field values in the primary
# Line 2157  Line 2449 
2449  list references. For example, the following line inserts an inactive PEG feature named  list references. For example, the following line inserts an inactive PEG feature named
2450  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.
2451    
2452  C<< $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>      $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']});
2453    
2454  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
2455  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
2456    
2457  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>      $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'});
2458    
2459  =over 4  =over 4
2460    
# Line 2187  Line 2479 
2479    
2480  =head3 Annotate  =head3 Annotate
2481    
2482  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2483    
2484  Annotate a feature. This inserts an Annotation record into the database and links it to the  Annotate a feature. This inserts an Annotation record into the database and links it to the
2485  specified feature and user.  specified feature and user.
# Line 2241  Line 2533 
2533    
2534  =head3 AssignFunction  =head3 AssignFunction
2535    
2536  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2537    
2538  This method assigns a function to a feature. Functions are a special type of annotation. The general  This method assigns a function to a feature. Functions are a special type of annotation. The general
2539  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2301  Line 2593 
2593    
2594  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2595    
2596  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2597    
2598  Returns a list of features with the specified alias. The alias is parsed to determine  Returns a list of features with the specified alias. The alias is parsed to determine
2599  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6
# Line 2335  Line 2627 
2627          push @retVal, $mappedAlias;          push @retVal, $mappedAlias;
2628      } else {      } else {
2629          # Here we have a non-FIG alias. Get the features with the normalized alias.          # Here we have a non-FIG alias. Get the features with the normalized alias.
2630          @retVal = $self->GetFlat(['Feature'], 'Feature(alias) = ?', [$mappedAlias], 'Feature(id)');          @retVal = $self->GetFlat(['IsAliasOf'], 'IsAliasOf(from-link) = ?', [$mappedAlias], 'IsAliasOf(to-link)');
2631      }      }
2632      # Return the result.      # Return the result.
2633      return @retVal;      return @retVal;
# Line 2343  Line 2635 
2635    
2636  =head3 FeatureTranslation  =head3 FeatureTranslation
2637    
2638  C<< my $translation = $sprout->FeatureTranslation($featureID); >>      my $translation = $sprout->FeatureTranslation($featureID);
2639    
2640  Return the translation of a feature.  Return the translation of a feature.
2641    
# Line 2371  Line 2663 
2663    
2664  =head3 Taxonomy  =head3 Taxonomy
2665    
2666  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2667    
2668  Return the taxonomy of the specified genome. This will be in the form of a list  Return the taxonomy of the specified genome. This will be in the form of a list
2669  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,
2670  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2671    
2672  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2673    
2674  =over 4  =over 4
2675    
# Line 2412  Line 2704 
2704    
2705  =head3 CrudeDistance  =head3 CrudeDistance
2706    
2707  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2708    
2709  Returns a crude estimate of the distance between two genomes. The distance is construed so  Returns a crude estimate of the distance between two genomes. The distance is construed so
2710  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.
# Line 2464  Line 2756 
2756    
2757  =head3 RoleName  =head3 RoleName
2758    
2759  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2760    
2761  Return the descriptive name of the role with the specified ID. In general, a role  Return the descriptive name of the role with the specified ID. In general, a role
2762  will only have a descriptive name if it is coded as an EC number.  will only have a descriptive name if it is coded as an EC number.
# Line 2498  Line 2790 
2790    
2791  =head3 RoleDiagrams  =head3 RoleDiagrams
2792    
2793  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2794    
2795  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2796    
# Line 2526  Line 2818 
2818      return @retVal;      return @retVal;
2819  }  }
2820    
 =head3 GetProperties  
   
 C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>  
   
 Return a list of the properties with the specified characteristics.  
   
 Properties are arbitrary key-value pairs associated with a feature. (At some point they  
 will also be associated with genomes.) A property value is represented by a 4-tuple of  
 the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter  
   
 =over 4  
   
 =item fid  
   
 ID of the feature possessing the property.  
   
 =item key  
   
 Name or key of the property.  
   
 =item value  
   
 Value of the property.  
   
 =item url  
   
 URL of the document that indicated the property should have this particular value, or an  
 empty string if no such document exists.  
   
 =back  
   
 The parameters act as a filter for the desired data. Any non-null parameter will  
 automatically match all the tuples returned. So, specifying just the I<$fid> will  
 return all the properties of the specified feature; similarly, specifying the I<$key>  
 and I<$value> parameters will return all the features having the specified property  
 value.  
   
 A single property key can have many values, representing different ideas about the  
 feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is  
 virulent, and another may declare that it is not virulent. A query about the virulence of  
 C<fig|83333.1.peg.10> would be coded as  
   
     my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');  
   
 Here the I<$value> and I<$url> fields are left blank, indicating that those fields are  
 not to be filtered. The tuples returned would be  
   
     ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')  
     ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')  
   
 =cut  
 #: Return Type @@;  
 sub GetProperties {  
     # Get the parameters.  
     my ($self, @parms) = @_;  
     # Declare the return variable.  
     my @retVal = ();  
     # Now we need to create a WHERE clause that will get us the data we want. First,  
     # we create a list of the columns containing the data for each parameter.  
     my @colNames = ('HasProperty(from-link)', 'Property(property-name)',  
                     'Property(property-value)', 'HasProperty(evidence)');  
     # Now we build the WHERE clause and the list of parameter values.  
     my @where = ();  
     my @values = ();  
     for (my $i = 0; $i <= $#colNames; $i++) {  
         my $parm = $parms[$i];  
         if (defined $parm && ($parm ne '')) {  
             push @where, "$colNames[$i] = ?";  
             push @values, $parm;  
         }  
     }  
     # Format the WHERE clause.  
     my $filter = (@values > 0 ? (join " AND ", @where) : undef);  
     # Ask for all the propertie values with the desired characteristics.  
     my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);  
     while (my $valueObject = $query->Fetch()) {  
         my @tuple = $valueObject->Values(\@colNames);  
         push @retVal, \@tuple;  
     }  
     # Return the result.  
     return @retVal;  
 }  
   
2821  =head3 FeatureProperties  =head3 FeatureProperties
2822    
2823  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2824    
2825  Return a list of the properties for the specified feature. Properties are key-value pairs  Return a list of the properties for the specified feature. Properties are key-value pairs
2826  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
2827  that a feature is essential to the survival of the organism or that it has benign influence  that a feature is essential to the survival of the organism or that it has benign influence
2828  on the activities of a pathogen. Each property is returned as a triple of the form  on the activities of a pathogen. Each property is returned as a triple of the form
2829  C<($key,$value,$url)>, where C<$key> is the property name, C<$value> is its value (commonly  C<($key,@values)>, where C<$key> is the property name and  C<@values> are its values.
 a 1 or a 0, but possibly a string or a floating-point value), and C<$url> is a string describing  
 the web address or citation in which the property's value for the feature was identified.  
2830    
2831  =over 4  =over 4
2832    
# Line 2629  Line 2836 
2836    
2837  =item RETURN  =item RETURN
2838    
2839  Returns a list of triples, each triple containing the property name, its value, and a URL or  Returns a list of tuples, each tuple containing the property name and its values.
 citation.  
2840    
2841  =back  =back
2842    
# Line 2640  Line 2846 
2846      # Get the parameters.      # Get the parameters.
2847      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2848      # Get the properties.      # Get the properties.
2849      my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],      my @attributes = $self->ca->GetAttributes($featureID);
2850                              ['Property(property-name)', 'Property(property-value)',      # Strip the feature ID off each tuple.
2851                               'HasProperty(evidence)']);      my @retVal = ();
2852        for my $attributeRow (@attributes) {
2853            shift @{$attributeRow};
2854            push @retVal, $attributeRow;
2855        }
2856      # Return the resulting list.      # Return the resulting list.
2857      return @retVal;      return @retVal;
2858  }  }
2859    
2860  =head3 DiagramName  =head3 DiagramName
2861    
2862  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2863    
2864  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2865    
# Line 2677  Line 2887 
2887    
2888  =head3 PropertyID  =head3 PropertyID
2889    
2890  C<< my $id = $sprout->PropertyID($propName, $propValue); >>      my $id = $sprout->PropertyID($propName, $propValue);
2891    
2892  Return the ID of the specified property name and value pair, if the  Return the ID of the specified property name and value pair, if the
2893  pair exists.  pair exists. Only a small subset of the FIG attributes are stored as
2894    Sprout properties, mostly for use in search optimization.
2895    
2896  =over 4  =over 4
2897    
# Line 2713  Line 2924 
2924    
2925  =head3 MergedAnnotations  =head3 MergedAnnotations
2926    
2927  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2928    
2929  Returns a merged list of the annotations for the features in a list. Each annotation is  Returns a merged list of the annotations for the features in a list. Each annotation is
2930  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where
# Line 2762  Line 2973 
2973    
2974  =head3 RoleNeighbors  =head3 RoleNeighbors
2975    
2976  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
2977    
2978  Returns a list of the roles that occur in the same diagram as the specified role. Because  Returns a list of the roles that occur in the same diagram as the specified role. Because
2979  diagrams and roles are in a many-to-many relationship with each other, the list is  diagrams and roles are in a many-to-many relationship with each other, the list is
# Line 2805  Line 3016 
3016    
3017  =head3 FeatureLinks  =head3 FeatureLinks
3018    
3019  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
3020    
3021  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are
3022  to external websites describing either the feature itself or the organism containing it  to external websites describing either the feature itself or the organism containing it
# Line 2836  Line 3047 
3047    
3048  =head3 SubsystemsOf  =head3 SubsystemsOf
3049    
3050  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
3051    
3052  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped
3053  to the roles the feature performs.  to the roles the feature performs.
# Line 2884  Line 3095 
3095    
3096  =head3 SubsystemList  =head3 SubsystemList
3097    
3098  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
3099    
3100  Return a list containing the names of the subsystems in which the specified  Return a list containing the names of the subsystems in which the specified
3101  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2907  Line 3118 
3118  sub SubsystemList {  sub SubsystemList {
3119      # Get the parameters.      # Get the parameters.
3120      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3121      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3122      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3123        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3124                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3125      # Return the result, sorted.      # Return the result, sorted.
3126      return sort @retVal;      return sort @retVal;
# Line 2916  Line 3128 
3128    
3129  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
3130    
3131  C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>      my %featureData = $sprout->GenomeSubsystemData($genomeID);
3132    
3133  Return a hash mapping genome features to their subsystem roles.  Return a hash mapping genome features to their subsystem roles.
3134    
# Line 2941  Line 3153 
3153      # Declare the return variable.      # Declare the return variable.
3154      my %retVal = ();      my %retVal = ();
3155      # 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
3156      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3157      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3158                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3159                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3160      # 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
3161      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3162      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3163      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3164      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3165                                   "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.  
3166      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3167          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3168          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3169          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3170          my $subsys = $subHash{$cellID};          # Check the subsystem;
3171          if ($subsys) {          if ($subs{$subsys}) {
3172                Trace("Subsystem found.") if T(4);
3173              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3174              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3175              # Merge in this new data.              # Merge in this new data.
# Line 2976  Line 3182 
3182    
3183  =head3 RelatedFeatures  =head3 RelatedFeatures
3184    
3185  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
3186    
3187  Return a list of the features which are bi-directional best hits of the specified feature and  Return a list of the features which are bi-directional best hits of the specified feature and
3188  have been assigned the specified function by the specified user. If no such features exists,  have been assigned the specified function by the specified user. If no such features exists,
# Line 3027  Line 3233 
3233    
3234  =head3 TaxonomySort  =head3 TaxonomySort
3235    
3236  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3237    
3238  Return a list formed by sorting the specified features by the taxonomy of the containing  Return a list formed by sorting the specified features by the taxonomy of the containing
3239  genome. This will cause genomes from similar organisms to float close to each other.  genome. This will cause genomes from similar organisms to float close to each other.
# Line 3062  Line 3268 
3268          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3269                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3270          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3271          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3272      }      }
3273      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3274      my @retVal = ();      my @retVal = ();
# Line 3075  Line 3281 
3281    
3282  =head3 Protein  =head3 Protein
3283    
3284  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3285    
3286  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3287    
# Line 3161  Line 3367 
3367    
3368  =head3 LoadInfo  =head3 LoadInfo
3369    
3370  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3371    
3372  Return the name of the directory from which data is to be loaded and a list of the relation  Return the name of the directory from which data is to be loaded and a list of the relation
3373  names. This information is useful when trying to analyze what needs to be put where in order  names. This information is useful when trying to analyze what needs to be put where in order
# Line 3182  Line 3388 
3388    
3389  =head3 BBHMatrix  =head3 BBHMatrix
3390    
3391  C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>      my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3392    
3393  Find all the bidirectional best hits for the features of a genome in a  Find all the bidirectional best hits for the features of a genome in a
3394  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3236  Line 3442 
3442    
3443  =head3 SimMatrix  =head3 SimMatrix
3444    
3445  C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>      my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3446    
3447  Find all the similarities for the features of a genome in a  Find all the similarities for the features of a genome in a
3448  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3306  Line 3512 
3512    
3513  =head3 LowBBHs  =head3 LowBBHs
3514    
3515  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3516    
3517  Return the bidirectional best hits of a feature whose score is no greater than a  Return the bidirectional best hits of a feature whose score is no greater than a
3518  specified cutoff value. A higher cutoff value will allow inclusion of hits with  specified cutoff value. A higher cutoff value will allow inclusion of hits with
# Line 3350  Line 3556 
3556    
3557  =head3 Sims  =head3 Sims
3558    
3559  C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>      my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3560    
3561  Get a list of similarities for a specified feature. Similarity information is not kept in the  Get a list of similarities for a specified feature. Similarity information is not kept in the
3562  Sprout database; rather, they are retrieved from a network server. The similarities are  Sprout database; rather, they are retrieved from a network server. The similarities are
# Line 3367  Line 3573 
3573    
3574  =item fid  =item fid
3575    
3576  ID of the feature whose similarities are desired.  ID of the feature whose similarities are desired, or reference to a list of IDs
3577    of features whose similarities are desired.
3578    
3579  =item maxN  =item maxN
3580    
# Line 3415  Line 3622 
3622    
3623  =head3 IsAllGenomes  =head3 IsAllGenomes
3624    
3625  C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>      my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3626    
3627  Return TRUE if all genomes in the second list are represented in the first list at  Return TRUE if all genomes in the second list are represented in the first list at
3628  least one. Otherwise, return FALSE. If the second list is omitted, the first list is  least one. Otherwise, return FALSE. If the second list is omitted, the first list is
# Line 3464  Line 3671 
3671    
3672  =head3 GetGroups  =head3 GetGroups
3673    
3674  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3675    
3676  Return a hash mapping each group to the IDs of the genomes in the group.  Return a hash mapping each group to the IDs of the genomes in the group.
3677  A list of groups may be specified, in which case only those groups will be  A list of groups may be specified, in which case only those groups will be
# Line 3496  Line 3703 
3703                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3704          # Loop through the genomes found.          # Loop through the genomes found.
3705          for my $genome (@genomes) {          for my $genome (@genomes) {
3706              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3707              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3708              my $genomeID = shift @groups;              push @{$retVal{$group}}, $genomeID;
             # Loop through the groups, adding the genome ID to each group's  
             # list.  
             for my $group (@groups) {  
                 Tracer::AddToListMap(\%retVal, $group, $genomeID);  
             }  
3709          }          }
3710      }      }
3711      # Return the hash we just built.      # Return the hash we just built.
# Line 3512  Line 3714 
3714    
3715  =head3 MyGenomes  =head3 MyGenomes
3716    
3717  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3718    
3719  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3720    
# Line 3544  Line 3746 
3746    
3747  =head3 LoadFileName  =head3 LoadFileName
3748    
3749  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3750    
3751  Return the name of the load file for the specified table in the specified data  Return the name of the load file for the specified table in the specified data
3752  directory.  directory.
# Line 3585  Line 3787 
3787    
3788  =head3 DeleteGenome  =head3 DeleteGenome
3789    
3790  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3791    
3792  Delete a genome from the database.  Delete a genome from the database.
3793    
# Line 3621  Line 3823 
3823    
3824  =head3 Fix  =head3 Fix
3825    
3826  C<< my %fixedHash = Sprout::Fix(%groupHash); >>      my %fixedHash = $sprout->Fix(%groupHash);
3827    
3828  Prepare a genome group hash (like that returned by L</GetGroups> for processing.  Prepare a genome group hash (like that returned by L</GetGroups>) for processing.
3829  Groups with the same primary name will be combined. The primary name is the  The groups will be combined into the appropriate super-groups.
 first capitalized word in the group name.  
3830    
3831  =over 4  =over 4
3832    
# Line 3643  Line 3844 
3844    
3845  sub Fix {  sub Fix {
3846      # Get the parameters.      # Get the parameters.
3847      my (%groupHash) = @_;      my ($self, %groupHash) = @_;
3848      # Create the result hash.      # Create the result hash.
3849      my %retVal = ();      my %retVal = ();
3850      # Copy over the genomes.      # Copy over the genomes.
3851      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3852          # Make a safety copy of the group ID.          # Get the super-group name.
3853          my $realGroupID = $groupID;          my $realGroupID = $self->SuperGroup($groupID);
3854          # Yank the primary name.          # Append this group's genomes into the result hash
3855          if ($groupID =~ /([A-Z]\w+)/) {          # using the super-group name.
3856              $realGroupID = $1;          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
         }  
         # Append this group's genomes into the result hash.  
         Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});  
3857      }      }
3858      # Return the result hash.      # Return the result hash.
3859      return %retVal;      return %retVal;
# Line 3663  Line 3861 
3861    
3862  =head3 GroupPageName  =head3 GroupPageName
3863    
3864  C<< my $name = $sprout->GroupPageName($group); >>      my $name = $sprout->GroupPageName($group);
3865    
3866  Return the name of the page for the specified NMPDR group.  Return the name of the page for the specified NMPDR group.
3867    
# Line 3685  Line 3883 
3883  sub GroupPageName {  sub GroupPageName {
3884      # Get the parameters.      # Get the parameters.
3885      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3886      # Check for the group file data.      # Check for the group file data.
3887      if (! defined $self->{groupHash}) {      my %superTable = $self->CheckGroupFile();
         # Read the group file.  
         my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");  
         # Store it in our object.  
         $self->{groupHash} = \%groupData;  
     }  
3888      # Compute the real group name.      # Compute the real group name.
3889      my $realGroup = $group;      my $realGroup = $self->SuperGroup($group);
3890      if ($group =~ /([A-Z]\w+)/) {      # Get the associated page name.
3891          $realGroup = $1;      my $retVal = "../content/$superTable{$realGroup}->{page}";
     }  
     # Return the page name.  
     $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];  
3892      # Return the result.      # Return the result.
3893      return $retVal;      return $retVal;
3894  }  }
3895    
 =head3 ReadGroupFile  
3896    
3897  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  =head3 AddProperty
3898    
3899        $sprout->AddProperty($featureID, $key, @values);
3900    
3901  Read in the data from the specified group file. The group file contains information  Add a new attribute value (Property) to a feature.
 about each of the NMPDR groups.  
3902    
3903  =over 4  =over 4
3904    
3905  =item name  =item peg
3906    
3907  Name of the group.  ID of the feature to which the attribute is to be added.
3908    
3909  =item page  =item key
3910    
3911  Name of the group's page on the web site (e.g. C<campy.php> for  Name of the attribute (key).
 Campylobacter)  
3912    
3913  =item genus  =item values
3914    
3915  Genus of the group  Values of the attribute.
3916    
3917  =item species  =back
3918    
3919    =cut
3920    #: Return Type ;
3921    sub AddProperty {
3922        # Get the parameters.
3923        my ($self, $featureID, $key, @values) = @_;
3924        # Add the property using the attached attributes object.
3925        $self->ca->AddAttribute($featureID, $key, @values);
3926    }
3927    
3928  Species of the group, or an empty string if the group is for an entire  =head3 CheckGroupFile
 genus. If the group contains more than one species, the species names  
 should be separated by commas.  
3929    
3930  =back      my %groupData = $sprout->CheckGroupFile();
3931    
3932  The parameters to this method are as follows  Get the group file hash. The group file hash describes the relationship
3933    between a group and the super-group to which it belongs for purposes of
3934    display. The super-group name is computed from the first capitalized word
3935    in the actual group name. For each super-group, the group file contains
3936    the page name and a list of the species expected to be in the group.
3937    Each species is specified by a genus and a species name. A species name
3938    of C<0> implies an entire genus.
3939    
3940    This method returns a hash from super-group names to a hash reference. Each
3941    resulting hash reference contains the following fields.
3942    
3943  =over 4  =over 4
3944    
3945  =item groupFile  =item page
3946    
3947  Name of the file containing the group data.  The super-group's web page in the NMPDR.
3948    
3949  =item RETURN  =item contents
3950    
3951  Returns a hash keyed on group name. The value of each hash  A list of 2-tuples, each containing a genus name followed by a species name
3952    (or 0, indicating all species). This list indicates which organisms belong
3953    in the super-group.
3954    
3955  =back  =back
3956    
3957  =cut  =cut
3958    
3959  sub ReadGroupFile {  sub CheckGroupFile {
3960      # Get the parameters.      # Get the parameters.
3961      my ($groupFileName) = @_;      my ($self) = @_;
3962      # Declare the return variable.      # Check to see if we already have this hash.
3963      my %retVal;      if (! defined $self->{groupHash}) {
3964            # We don't, so we need to read it in.
3965            my %groupHash;
3966      # Read the group file.      # Read the group file.
3967      my @groupLines = Tracer::GetFile($groupFileName);          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3968            # Loop through the list of sort-of groups.
3969      for my $groupLine (@groupLines) {      for my $groupLine (@groupLines) {
3970          my ($name, $page, $genus, $species) = split(/\t/, $groupLine);              my ($name, $page, @contents) = split /\t/, $groupLine;
3971          $retVal{$name} = [$page, $genus, $species];              $groupHash{$name} = { page => $page,
3972                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3973                                    };
3974            }
3975            # Save the hash.
3976            $self->{groupHash} = \%groupHash;
3977      }      }
3978      # Return the result.      # Return the result.
3979      return %retVal;      return %{$self->{groupHash}};
3980  }  }
3981    
3982  =head3 AddProperty  =head2 Virtual Methods
3983    
3984    =head3 CleanKeywords
3985    
3986  C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>      my $cleanedString = $sprout->CleanKeywords($searchExpression);
3987    
3988  Add a new attribute value (Property) to a feature. In the SEED system, attributes can  Clean up a search expression or keyword list. This involves converting the periods
3989  be added to almost any object. In Sprout, they can only be added to features. In  in EC numbers to underscores, converting non-leading minus signs to underscores,
3990  Sprout, attributes are implemented using I<properties>. A property represents a key/value  a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3991  pair. If the particular key/value pair coming in is not already in the database, a new  characters. In addition, any extra spaces are removed.
 B<Property> record is created to hold it.  
3992    
3993  =over 4  =over 4
3994    
3995  =item peg  =item searchExpression
3996    
3997  ID of the feature to which the attribute is to be replied.  Search expression or keyword list to clean. Note that a search expression may
3998    contain boolean operators which need to be preserved. This includes leading
3999    minus signs.
4000    
4001  =item key  =item RETURN
4002    
4003  Name of the attribute (key).  Cleaned expression or keyword list.
4004    
4005    =back
4006    
4007    =cut
4008    
4009    sub CleanKeywords {
4010        # Get the parameters.
4011        my ($self, $searchExpression) = @_;
4012        # Get the stemmer.
4013        my $stemmer = $self->GetStemmer();
4014        # Convert the search expression using the stemmer.
4015        my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
4016        Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
4017        # Return the result.
4018        return $retVal;
4019    }
4020    
4021    =head3 GetSourceObject
4022    
4023        my $source = $erdb->GetSourceObject();
4024    
4025    Return the object to be used in creating load files for this database.
4026    
4027  =item value  =cut
4028    
4029    sub GetSourceObject {
4030        # Get access to the FIG code.
4031        require FIG;
4032        # Return a FIG object.
4033        return FIG->new();
4034    }
4035    
4036    =head3 SectionList
4037    
4038  Value of the attribute.      my @sections = $erdb->SectionList($source);
4039    
4040  =item url  Return a list of the names for the different data sections used when loading this database.
4041    The default is an empty string, in which case there is only one section representing the
4042    entire database.
4043    
4044  URL or text citation from which the property was obtained.  =over 4
4045    
4046    =item source
4047    
4048    Source object used to access the data from which the database is loaded. This is the
4049    same object returned by L</GetSourceObject>; however, we ask the caller to pass it
4050    in as a parameter so that we don't end up creating multiple copies of a potentially
4051    expensive data structure.
4052    
4053    =item RETURN
4054    
4055    Returns a list of section names.
4056    
4057  =back  =back
4058    
4059  =cut  =cut
4060  #: Return Type ;  
4061  sub AddProperty {  sub SectionList {
4062      # Get the parameters.      # Get the parameters.
4063      my ($self, $featureID, $key, $value, $url) = @_;      my ($self, $source) = @_;
4064      # Declare the variable to hold the desired property ID.      # Ask the BaseSproutLoader for a section list.
4065      my $propID;      require BaseSproutLoader;
4066      # Attempt to find a property record for this key/value pair.      my @retVal = BaseSproutLoader::GetSectionList($self, $source);
4067      my @properties = $self->GetFlat(['Property'],      # Return the list.
4068                                     "Property(property-name) = ? AND Property(property-value) = ?",      return @retVal;
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
     } else {  
         # Here the property value does not exist. We need to generate an ID. It will be set  
         # to a number one greater than the maximum value in the database. This call to  
         # GetAll will stop after one record.  
         my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],  
                                         1);  
         $propID = $maxProperty[0]->[0] + 1;  
         # Insert the new property value.  
         $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });  
     }  
     # Now we connect the incoming feature to the property.  
     $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });  
4069  }  }
4070    
4071  =head2 Virtual Methods  =head3 Loader
   
 =head3 CleanKeywords  
4072    
4073  C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>      my $groupLoader = $erdb->Loader($groupName, $source, $options);
4074    
4075  Clean up a search expression or keyword list. This involves converting the periods  Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4076  in EC numbers to underscores, converting non-leading minus signs to underscores,  by [[ERDBGeneratorPl]] to create the load group objects. If you are not using
4077  a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic  [[ERDBGeneratorPl]], you don't need to override this method.
 characters. In addition, any extra spaces are removed.  
4078    
4079  =over 4  =over 4
4080    
4081  =item searchExpression  =item groupName
4082    
4083  Search expression or keyword list to clean. Note that a search expression may  Name of the load group whose object is to be returned. The group name is
4084  contain boolean operators which need to be preserved. This includes leading  guaranteed to be a single word with only the first letter capitalized.
4085  minus signs.  
4086    =item source
4087    
4088    The source object used to access the data from which the load file is derived. This
4089    is the same object returned by L</GetSourceObject>; however, we ask the caller to pass
4090    it in as a parameter so that we don't end up creating multiple copies of a potentially
4091    expensive data structure.
4092    
4093    =item options
4094    
4095    Reference to a hash of command-line options.
4096    
4097  =item RETURN  =item RETURN
4098    
4099  Cleaned expression or keyword list.  Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4100    for this database.
4101    
4102  =back  =back
4103    
4104  =cut  =cut
4105    
4106  sub CleanKeywords {  sub Loader {
4107      # Get the parameters.      # Get the parameters.
4108      my ($self, $searchExpression) = @_;      my ($self, $groupName, $source, $options) = @_;
4109      # Perform the standard cleanup.      # Compute the loader name.
4110      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $loaderClass = "${groupName}SproutLoader";
4111      # Fix the periods in EC and TC numbers.      # Pull in its definition.
4112      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      require "$loaderClass.pm";
4113      # Fix non-trailing periods.      # Create an object for it.
4114      $retVal =~ s/\.(\w)/_$1/g;      my $retVal = eval("$loaderClass->new(\$self, \$source, \$options)");
4115      # Fix non-leading minus signs.      # Insure it worked.
4116      $retVal =~ s/(\w)[\-]/$1_/g;      Confess("Could not create $loaderClass object: $@") if $@;
4117      # Fix the vertical bars and colons      # Return it to the caller.
     $retVal =~ s/(\w)[|:](\w)/$1'$2/g;  
     # Return the result.  
4118      return $retVal;      return $retVal;
4119  }  }
4120    
4121    =head3 LoadGroupList
4122    
4123        my @groups = $erdb->LoadGroupList();
4124    
4125    Returns a list of the names for this database's load groups. This method is used
4126    by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default
4127    is a single group called 'All' that loads everything.
4128    
4129    =cut
4130    
4131    sub LoadGroupList {
4132        # Return the list.
4133        return qw(Genome Subsystem Annotation Property Source Reaction Synonym Drug Feature);
4134    }
4135    
4136    =head3 LoadDirectory
4137    
4138        my $dirName = $erdb->LoadDirectory();
4139    
4140    Return the name of the directory in which load files are kept. The default is
4141    the FIG temporary directory, which is a really bad choice, but it's always there.
4142    
4143    =cut
4144    
4145    sub LoadDirectory {
4146        # Get the parameters.
4147        my ($self) = @_;
4148        # Return the directory name.
4149        return $self->{dataDir};
4150    }
4151    
4152  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4153    
4154    =head3 GetStemmer
4155    
4156        my $stermmer = $sprout->GetStemmer();
4157    
4158    Return the stemmer object for this database.
4159    
4160    =cut
4161    
4162    sub GetStemmer {
4163        # Get the parameters.
4164        my ($self) = @_;
4165        # Declare the return variable.
4166        my $retVal = $self->{stemmer};
4167        if (! defined $retVal) {
4168            # We don't have one pre-built, so we build and save it now.
4169            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4170                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4171                                     cache => 1);
4172            $self->{stemmer} = $retVal;
4173        }
4174        # Return the result.
4175        return $retVal;
4176    }
4177    
4178  =head3 ParseAssignment  =head3 ParseAssignment
4179    
4180  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 3878  Line 4183 
4183    
4184  A functional assignment is always of the form  A functional assignment is always of the form
4185    
4186      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
4187        ZZZZ
4188    
4189  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
4190  the user and the assigning user (from MadeAnnotation) will be the same, but that is  the user and the assigning user (from MadeAnnotation) will be the same, but that is
# Line 3931  Line 4237 
4237      return @retVal;      return @retVal;
4238  }  }
4239    
4240    =head3 _CheckFeature
4241    
4242        my $flag = $sprout->_CheckFeature($fid);
4243    
4244    Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.
4245    
4246    =over 4
4247    
4248    =item fid
4249    
4250    Feature ID to check.
4251    
4252    =item RETURN
4253    
4254    Returns TRUE if the FID is for one of the NMPDR genomes, else FALSE.
4255    
4256    =back
4257    
4258    =cut
4259    
4260    sub _CheckFeature {
4261        # Get the parameters.
4262        my ($self, $fid) = @_;
4263        # Insure we have a genome hash.
4264        if (! defined $self->{genomeHash}) {
4265            my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');
4266            $self->{genomeHash} = \%genomeHash;
4267        }
4268        # Get the feature's genome ID.
4269        my ($genomeID) = FIGRules::ParseFeatureID($fid);
4270        # Return an indicator of whether or not the genome ID is in the hash.
4271        return ($self->{genomeHash}->{$genomeID} ? 1 : 0);
4272    }
4273    
4274  =head3 FriendlyTimestamp  =head3 FriendlyTimestamp
4275    
4276  Convert a time number to a user-friendly time stamp for display.  Convert a time number to a user-friendly time stamp for display.
# Line 3958  Line 4298 
4298  }  }
4299    
4300    
4301    =head3 Hint
4302    
4303        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4304    
4305    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4306    This HTML can be put in forms to provide a useful hinting mechanism.
4307    
4308    =over 4
4309    
4310    =item wikiPage
4311    
4312    Name of the wiki page to be popped up when the hint mark is clicked.
4313    
4314    =item hintText
4315    
4316    Text to display for the hint. It is raw html, but may not contain any double quotes.
4317    
4318    =item RETURN
4319    
4320    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4321    uses the standard FIG popup technology.
4322    
4323    =back
4324    
4325    =cut
4326    
4327    sub Hint {
4328        # Get the parameters.
4329        my ($wikiPage, $hintText) = @_;
4330        # Escape the single quotes in the hint text.
4331        my $quotedText = $hintText;
4332        $quotedText =~ s/'/\\'/g;
4333        # Convert the wiki page name to a URL.
4334        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4335        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4336        # Compute the mouseover script.
4337        my $mouseOver = "doTooltip(this, '$quotedText')";
4338        # Create the html.
4339        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4340        # Return it.
4341        return $retVal;
4342    }
4343    
4344  1;  1;

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.121

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3