[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.116, Tue Sep 9 21:02:10 2008 UTC revision 1.125, Mon Mar 16 00:24:23 2009 UTC
# Line 4  Line 4 
4      use strict;      use strict;
5      use DBKernel;      use DBKernel;
6      use XML::Simple;      use XML::Simple;
7      use DBQuery;      use ERDBQuery;
8      use ERDBObject;      use ERDBObject;
9      use Tracer;      use Tracer;
10      use FIGRules;      use FIGRules;
# Line 14  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17      use CGI;      use CGI qw(-nosticky);
18      use WikiTools;      use WikiTools;
19        use BioWords;
20      use base qw(ERDB);      use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 40  Line 41 
41    
42  =cut  =cut
43    
 #: Constructor SFXlate->new_sprout_only();  
   
44  =head2 Public Methods  =head2 Public Methods
45    
46  =head3 new  =head3 new
# Line 56  Line 55 
55    
56  =item dbName  =item dbName
57    
58  Name of the database.  Name of the database. If omitted, the default Sprout database name is used.
59    
60  =item options  =item options
61    
# Line 90  Line 89 
89    
90      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });
91    
92    In order to work properly with [[ERDBGeneratorPl]], the constructor has an alternate
93    form.
94    
95        my $sprout = Sprout->new(dbd => $filename);
96    
97    Where I<$fileName> is the name of the DBD file. This enables us to specify an alternate
98    DBD for the loader, which is important when the database format changes.
99    
100  =cut  =cut
101    
102  sub new {  sub new {
103      # Get the parameters.      # Get the parameters.
104      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
105        # Check for the alternate signature, and default the database name if it is missing.
106        if ($dbName eq 'dbd') {
107            $dbName = $FIG_Config::sproutDB;
108            $options = { xmlFileName => $options };
109        } elsif (! defined $dbName) {
110            $dbName = $FIG_Config::sproutDB;
111        } elsif (ref $dbName eq 'HASH') {
112            $options = $dbName;
113            $dbName = $FIG_Config::sproutDB;
114        }
115      # Compute the DBD directory.      # Compute the DBD directory.
116      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
117                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 116  Line 133 
133                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
134                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
135                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
136                           demandDriven => 0,               # 1 for forward-only queries
137                        }, $options);                        }, $options);
138      # Get the data directory.      # Get the data directory.
139      my $dataDir = $optionTable->{dataDir};      my $dataDir = $optionTable->{dataDir};
# Line 131  Line 149 
149      }      }
150      # Create the ERDB object.      # Create the ERDB object.
151      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
152      my $retVal = ERDB::new($class, $dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName, %$optionTable);
153      # Add the option table and XML file name.      # Add the option table and XML file name.
154      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
155      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
156      # Set up space for the group file data.      # Set up space for the group file data.
157      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
158      # Set up space for the genome hash. We use this to identify NMPDR genomes.      # Set up space for the genome hash. We use this to identify NMPDR genomes
159      $retVal->{genomeHash} = undef;      # and remember genome data.
160      # Connect to the attributes.      $retVal->{genomeHash} = {};
161        $retVal->{genomeHashFilled} = 0;
162        # Remember the data directory name.
163        $retVal->{dataDir} = $dataDir;
164        # Return it.
165        return $retVal;
166    }
167    
168    =head3 ca
169    
170        my $ca = $sprout->ca():;
171    
172    Return the [[CustomAttributesPm]] object for retrieving object
173    properties.
174    
175    =cut
176    
177    sub ca {
178        # Get the parameters.
179        my ($self) = @_;
180        # Do we already have an attribute object?
181        my $retVal = $self->{_ca};
182        if (! defined $retVal) {
183            # No, create one. How we do it depends on the configuration.
184      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
185          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
186          $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);              $retVal = RemoteCustomAttributes->new($FIG_Config::attrURL);
187      } elsif ($FIG_Config::attrDbName) {      } elsif ($FIG_Config::attrDbName) {
188          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
189          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
190          $retVal->{_ca} = CustomAttributes->new(user => $user);              $retVal = CustomAttributes->new(user => $user);
191      }      }
192      # Return it.          # Save it for next time.
193            $self->{_ca} = $retVal;
194        }
195        # Return the result.
196      return $retVal;      return $retVal;
197  }  }
198    
# Line 255  Line 299 
299                  $retVal = $superGroup;                  $retVal = $superGroup;
300              }              }
301          }          }
         # Make sure we found something.  
         if (! $retVal) {  
             Confess("No super-group found for \"$groupName\".");  
         }  
302      }      }
303      # Return the result.      # Return the result.
304      return $retVal;      return $retVal;
# Line 310  Line 350 
350  The files are loaded based on the presumption that each line of the file is a record in the  The files are loaded based on the presumption that each line of the file is a record in the
351  relation, and the individual fields are delimited by tabs. Tab and new-line characters inside  relation, and the individual fields are delimited by tabs. Tab and new-line characters inside
352  fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must  fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must
353  be presented in the order given in the relation tables produced by the L</ShowMetaData> method.  be presented in the order given in the relation tables produced by the database documentation.
354    
355  =over 4  =over 4
356    
# Line 499  Line 539 
539  =item filter  =item filter
540    
541  If specified, a filter for the list of genomes to display. The filter should be in the form of a  If specified, a filter for the list of genomes to display. The filter should be in the form of a
542  list reference. The first element of the list should be the filter string, and the remaining elements  list reference, a string, or a hash reference. If it is a list reference, the first element
543  the filter parameters.  of the list should be the filter string, and the remaining elements the filter parameters. If it is a
544    string, it will be split into a list at each included tab. If it is a hash reference, it should be
545    a hash that maps genomes which should be included to a TRUE value.
546    
547  =item multiSelect  =item multiSelect
548    
# Line 539  Line 581 
581      my $divID = "${menuID}_status";      my $divID = "${menuID}_status";
582      my $urlID = "${menuID}_url";      my $urlID = "${menuID}_url";
583      # Compute the code to show selected genomes in the status area.      # Compute the code to show selected genomes in the status area.
584      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', $FIG_Config::genome_control_cap)";
585      # Check for single-select or multi-select.      # Check for single-select or multi-select.
586      my $multiSelect = $options{multiSelect} || 0;      my $multiSelect = $options{multiSelect} || 0;
587      # Get the style data.      # Get the style data.
# Line 551  Line 593 
593      }      }
594      my %selected = map { $_ => 1 } @{$selections};      my %selected = map { $_ => 1 } @{$selections};
595      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
596      # string or a list reference.      # string, a hash reference, or a list reference.
597        my ($filterHash, $filterString);
598      my $filterParms = $options{filter} || "";      my $filterParms = $options{filter} || "";
599        if (ref $filterParms eq 'HASH') {
600            $filterHash = $filterParms;
601            $filterParms = [];
602            $filterString = "";
603        } else {
604      if (! ref $filterParms) {      if (! ref $filterParms) {
605          $filterParms = [split /\t|\\t/, $filterParms];          $filterParms = [split /\t|\\t/, $filterParms];
606      }      }
607      my $filterString = shift @{$filterParms};          $filterString = shift @{$filterParms};
608        }
609        # Check for possible subsystem filtering. If there is one, we will tack the
610        # relationship onto the object name list.
611        my @objectNames = qw(Genome);
612        if ($filterString =~ /ParticipatesIn\(/) {
613            push @objectNames, 'ParticipatesIn';
614        }
615      # Get a list of all the genomes in group order. In fact, we only need them ordered      # Get a list of all the genomes in group order. In fact, we only need them ordered
616      # by name (genus,species,strain), but putting primary-group in front enables us to      # by name (genus,species,strain), but putting primary-group in front enables us to
617      # take advantage of an existing index.      # take advantage of an existing index.
618      my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",      my @genomeList = $self->GetAll(\@objectNames, "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
619                                     $filterParms,                                     $filterParms,
620                                     [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);                                     [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
621        # Apply the hash filter (if any).
622        if (defined $filterHash) {
623            @genomeList = grep { $filterHash->{$_->[1]} } @genomeList;
624        }
625      # Create a hash to organize the genomes by group. Each group will contain a list of      # Create a hash to organize the genomes by group. Each group will contain a list of
626      # 2-tuples, the first element being the genome ID and the second being the genome      # 2-tuples, the first element being the genome ID and the second being the genome
627      # name.      # name.
# Line 592  Line 651 
651      my @groups = map { $sortGroups{$_} } sort keys %sortGroups;      my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
652      # Remember the number of NMPDR groups.      # Remember the number of NMPDR groups.
653      my $nmpdrGroupCount = scalar @groups;      my $nmpdrGroupCount = scalar @groups;
654        # Are there any supporting genomes?
655        if (exists $gHash{$FIG_Config::otherGroup}) {
656      # Loop through the supporting genomes, classifying them by domain. We'll also keep a list      # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
657      # of the domains found.      # of the domains found.
658      my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};      my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
# Line 610  Line 671 
671      push @groups, sort @domains;      push @groups, sort @domains;
672      # Delete the supporting group.      # Delete the supporting group.
673      delete $gHash{$FIG_Config::otherGroup};      delete $gHash{$FIG_Config::otherGroup};
674        }
675      # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage      # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
676      # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes      # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
677      # and use that to make the selections.      # and use that to make the selections.
# Line 623  Line 685 
685      # Set up the multiple-select flag.      # Set up the multiple-select flag.
686      my $multipleTag = ($multiSelect ? " multiple" : "" );      my $multipleTag = ($multiSelect ? " multiple" : "" );
687      # Set up the style class.      # Set up the style class.
688      my $classTag = ($class ? " class=\"$class\"" : "" );      my $classTag = ($class ? " $class" : "" );
689      # Create the SELECT tag and stuff it into the output array.      # Create the SELECT tag and stuff it into the output array.
690      my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");      my @lines = qq(<SELECT name="$menuName" id="$menuID" class="genomeSelect $class" $onChangeTag$multipleTag$classTag size="$rows">);
691      # Loop through the groups.      # Loop through the groups.
692      for my $group (@groups) {      for my $group (@groups) {
693          # Get the genomes in the group.          # Get the genomes in the group.
# Line 658  Line 720 
720          # displayed. For multiple-select mode, we include a button that selects the displayed          # displayed. For multiple-select mode, we include a button that selects the displayed
721          # genes. For single-select mode, we use a plain label instead.          # genes. For single-select mode, we use a plain label instead.
722          my $searchThingName = "${menuID}_SearchThing";          my $searchThingName = "${menuID}_SearchThing";
723          my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"          my $searchThingLabel = "Type to narrow selection";
724                                               : "Show genomes containing");          my $searchThingButton = "";
725            if ($multiSelect) {
726                $searchThingButton = qq(<INPUT type="button" name="MacroSearch" class="button" value="Go" onClick="selectShowing('$menuID', '$searchThingName'); $showSelect;" />);
727            }
728          push @lines, "<br />$searchThingLabel&nbsp;" .          push @lines, "<br />$searchThingLabel&nbsp;" .
729                       "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .                       qq(<INPUT type="text" id="$searchThingName" name="$searchThingName" class="genomeSearchThing" onKeyup="showTyped('$menuID', '$searchThingName');" />) .
730                       Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";                       $searchThingButton .
731                         Hint("GenomeControl", 28) . "<br />";
732          # For multi-select mode, we also have buttons to set and clear selections.          # For multi-select mode, we also have buttons to set and clear selections.
733          if ($multiSelect) {          if ($multiSelect) {
734              push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";              push @lines, qq(<INPUT type="button" name="ClearAll" class="bigButton genomeButton" value="Clear All" onClick="clearAll(getElementById('$menuID')); $showSelect" />);
735              push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";              push @lines, qq(<INPUT type="button" name="SelectAll" class="bigButton genomeButton" value="Select All" onClick="selectAll(getElementById('$menuID')); $showSelect" />);
736              push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";              push @lines, qq(<INPUT type="button" name="NMPDROnly" class="bigButton genomeButton" value="Select NMPDR" onClick="selectSome(getElementById('$menuID'), $nmpdrCount, true); $showSelect;" />);
737          }          }
738          # Add a hidden field we can use to generate organism page hyperlinks.          # Add a hidden field we can use to generate organism page hyperlinks.
739          push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";          push @lines, qq(<INPUT type="hidden" id="$urlID" value="$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=" />);
740          # Add the status display. This tells the user what's selected no matter where the list is scrolled.          # Add the status display. This tells the user what's selected no matter where the list is scrolled.
741          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";          push @lines, qq(<DIV id="$divID" class="Panel"></DIV>);
742      }      }
743      # Assemble all the lines into a string.      # Assemble all the lines into a string.
744      my $retVal = join("\n", @lines, "");      my $retVal = join("\n", @lines, "");
# Line 707  Line 773 
773  sub Stem {  sub Stem {
774      # Get the parameters.      # Get the parameters.
775      my ($self, $word) = @_;      my ($self, $word) = @_;
776      # Declare the return variable.      # Get the stemmer object.
777      my $retVal;      my $stemmer = $self->{stemmer};
778      # See if it's stemmable.      if (! defined $stemmer) {
779      if ($word =~ /^[A-Za-z]+$/) {          # We don't have one pre-built, so we build and save it now.
780          # Compute the stem. Currently, it's just the word.          $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
781          my $stem = $word;                                   stops => "$FIG_Config::sproutData/StopWords.txt",
782          # Check to see if it's long enough.                                   cache => 0);
783          if (length $stem >= 3) {          $self->{stemmer} = $stemmer;
             # Yes, keep it.  
             $retVal = $stem;  
         } else {  
             # No, use the original word.  
             $retVal = $word;  
         }  
784      }      }
785        # Try to stem the word.
786        my $retVal = $stemmer->Process($word);
787      # Return the result.      # Return the result.
788      return $retVal;      return $retVal;
789  }  }
# Line 785  Line 847 
847  sub GenusSpecies {  sub GenusSpecies {
848      # Get the parameters.      # Get the parameters.
849      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
850      # Get the data for the specified genome.      # Declare the return value.
851      my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',      my $retVal;
852                                                                'Genome(unique-characterization)']);      # Get the genome data.
853      # Format the result and return it.      my $genomeData = $self->_GenomeData($genomeID);
854      my $retVal = join(' ', @values);      # Only proceed if we found the genome.
855        if (defined $genomeData) {
856            $retVal = $genomeData->PrimaryValue('Genome(scientific-name)');
857        }
858        # Return it.
859      return $retVal;      return $retVal;
860  }  }
861    
# Line 1127  Line 1193 
1193      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
1194      # Declare the return variable.      # Declare the return variable.
1195      my $retVal = 0;      my $retVal = 0;
1196      # Get the genome's contig sequence lengths.      # Get the genome data.
1197      my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',      my $genomeData = $self->_GenomeData($genomeID);
1198                         [$genomeID], 'IsMadeUpOf(len)');      # Only proceed if it exists.
1199      # Sum the lengths.      if (defined $genomeData) {
1200      map { $retVal += $_ } @lens;          $retVal = $genomeData->PrimaryValue('Genome(dna-size)');
1201        }
1202      # Return the result.      # Return the result.
1203      return $retVal;      return $retVal;
1204  }  }
# Line 1616  Line 1683 
1683  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
1684  is trusted.  is trusted.
1685    
1686  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.
1687  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.  
1688    
1689  =over 4  =over 4
1690    
# Line 1644  Line 1710 
1710      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1711      # Declare the return value.      # Declare the return value.
1712      my $retVal;      my $retVal;
1713      # Determine the ID type.      # Find a FIG ID for this feature.
1714      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1715        # Only proceed if we have an ID.
1716        if ($fid) {
1717          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1718          if (!$userID) {          if (!$userID) {
1719              # Use the primary assignment.              # Use the primary assignment.
1720              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1721          } else {          } else {
1722              # We must build the list of trusted users.              # We must build the list of trusted users.
1723              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1675  Line 1743 
1743              # 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.
1744              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1745                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1746                                     [$featureID]);                                     [$fid]);
1747              my $timeSelected = 0;              my $timeSelected = 0;
1748              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1749              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1695  Line 1763 
1763                  }                  }
1764              }              }
1765          }          }
     } 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)']);  
1766      }      }
1767      # Return the assignment found.      # Return the assignment found.
1768      return $retVal;      return $retVal;
# Line 1718  Line 1781 
1781  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
1782  most features only have a small number of annotations.  most features only have a small number of annotations.
1783    
 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.  
   
1784  =over 4  =over 4
1785    
1786  =item featureID  =item featureID
# Line 1742  Line 1801 
1801      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1802      # Declare the return value.      # Declare the return value.
1803      my @retVal = ();      my @retVal = ();
1804      # Determine the ID type.      # Convert to a FIG ID.
1805      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1806        # Only proceed if we found one.
1807        if ($fid) {
1808          # 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
1809          # users.          # users.
1810          my %trusteeTable = ();          my %trusteeTable = ();
1811          # 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.
1812          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1813                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1814                                 [$featureID]);                                 [$fid]);
1815          my $timeSelected = 0;          my $timeSelected = 0;
1816          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1817          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1765  Line 1826 
1826                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1827              }              }
1828          }          }
     } 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;  
1829      }      }
1830      # Return the assignments found.      # Return the assignments found.
1831      return @retVal;      return @retVal;
# Line 1811  Line 1865 
1865      # Loop through the incoming features.      # Loop through the incoming features.
1866      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1867          # Ask the server for the feature's best hit.          # Ask the server for the feature's best hit.
1868          my @bbhData = FIGRules::BBHData($featureID);          my $bbhData = FIGRules::BBHData($featureID);
1869          # Peel off the BBHs found.          # Peel off the BBHs found.
1870          my @found = ();          my @found = ();
1871          for my $bbh (@bbhData) {          for my $bbh (@$bbhData) {
1872              my $fid = $bbh->[0];              my $fid = $bbh->[0];
1873              my $bbGenome = $self->GenomeOf($fid);              my $bbGenome = $self->GenomeOf($fid);
1874              if ($bbGenome eq $genomeID) {              if ($bbGenome eq $genomeID) {
# Line 1853  Line 1907 
1907      # Get the parameters.      # Get the parameters.
1908      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1909      # Ask for the best hits.      # Ask for the best hits.
1910      my @lists = FIGRules::BBHData($featureID);      my $lists = FIGRules::BBHData($featureID);
1911      # Create the return value.      # Create the return value.
1912      my %retVal = ();      my %retVal = ();
1913      for my $tuple (@lists) {      for my $tuple (@$lists) {
1914          $retVal{$tuple->[0]} = $tuple->[1];          $retVal{$tuple->[0]} = $tuple->[1];
1915      }      }
1916      # Return the result.      # Return the result.
# Line 1890  Line 1944 
1944      # Declare the return variable.      # Declare the return variable.
1945      my $retVal;      my $retVal;
1946      # Get the genome's data.      # Get the genome's data.
1947      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->_GenomeData($genomeID);
1948      if ($genomeData) {      # Only proceed if it exists.
1949        if (defined $genomeData) {
1950          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1951          $retVal = $genomeData->PrimaryValue('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1952      }      }
# Line 1963  Line 2018 
2018          my ($realFeatureID) = $self->FeaturesByAlias($featureID);          my ($realFeatureID) = $self->FeaturesByAlias($featureID);
2019          if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {          if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
2020              $retVal = $1;              $retVal = $1;
         } else {  
             # Use the external table.  
             my ($org) = $self->GetFlat(['ExternalAliasOrg'], "ExternalAliasOrg(id) = ?",  
                                        [$featureID], "ExternalAliasOrg(org)");  
             if ($org) {  
                 $retVal = $org;  
             } else {  
                 Confess("Invalid feature ID $featureID.");  
             }  
2021          }          }
2022      }      }
2023      # Return the value found.      # Return the value found.
# Line 2016  Line 2062 
2062              $retVal{$featureID2} = $score;              $retVal{$featureID2} = $score;
2063          }          }
2064      }      }
     # Functional coupling is reflexive. If we found at least one coupled feature, we must add  
     # the incoming feature as well.  
     if (keys %retVal) {  
         $retVal{$featureID} = 9999;  
     }  
2065      # Return the hash.      # Return the hash.
2066      return %retVal;      return %retVal;
2067  }  }
# Line 2377  Line 2418 
2418  sub GetGenomeNameData {  sub GetGenomeNameData {
2419      # Get the parameters.      # Get the parameters.
2420      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
2421        # Declare the return variables.
2422        my ($genus, $species, $strain);
2423        # Get the genome's data.
2424        my $genomeData = $self->_GenomeData($genomeID);
2425        # Only proceed if the genome exists.
2426        if (defined $genomeData) {
2427      # Get the desired values.      # Get the desired values.
2428      my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>          ($genus, $species, $strain) = $genomeData->Values(['Genome(genus)',
2429                                                              [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);                                                             'Genome(species)',
2430      # Throw an error if they were not found.                                                             'Genome(unique-characterization)']);
2431      if (! defined $genus) {      } else {
2432            # Throw an error because they were not found.
2433          Confess("Genome $genomeID not found in database.");          Confess("Genome $genomeID not found in database.");
2434      }      }
2435      # Return the results.      # Return the results.
# Line 2682  Line 2730 
2730  sub Taxonomy {  sub Taxonomy {
2731      # Get the parameters.      # Get the parameters.
2732      my ($self, $genome) = @_;      my ($self, $genome) = @_;
     # Find the specified genome's taxonomy string.  
     my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);  
2733      # Declare the return variable.      # Declare the return variable.
2734      my @retVal = ();      my @retVal = ();
2735      # If we found the genome, return its taxonomy string.      # Get the genome data.
2736      if ($list) {      my $genomeData = $self->_GenomeData($genome);
2737          @retVal = split /\s*;\s*/, $list;      # Only proceed if it exists.
2738        if (defined $genomeData) {
2739            # Create the taxonomy from the taxonomy string.
2740            @retVal = split /\s*;\s*/, $genomeData->PrimaryValue('Genome(taxonomy)');
2741      } else {      } else {
2742            # Genome doesn't exist, so emit a warning.
2743          Trace("Genome \"$genome\" does not have a taxonomy in the database.\n") if T(0);          Trace("Genome \"$genome\" does not have a taxonomy in the database.\n") if T(0);
2744      }      }
2745      # Return the value found.      # Return the value found.
# Line 2734  Line 2784 
2784      }      }
2785      my @taxA = $self->Taxonomy($genomeA);      my @taxA = $self->Taxonomy($genomeA);
2786      my @taxB = $self->Taxonomy($genomeB);      my @taxB = $self->Taxonomy($genomeB);
2787      # Initialize the distance to 1. We'll reduce it each time we find a match between the      # Compute the distance.
2788      # taxonomies.      my $retVal = FIGRules::CrudeDistanceFormula(\@taxA, \@taxB);
     my $retVal = 1.0;  
     # Initialize the subtraction amount. This amount determines the distance reduction caused  
     # by a mismatch at the current level.  
     my $v = 0.5;  
     # Loop through the taxonomies.  
     for (my $i = 0; ($i < @taxA) && ($i < @taxB) && ($taxA[$i] eq $taxB[$i]); $i++) {  
         $retVal -= $v;  
         $v /= 2;  
     }  
2789      return $retVal;      return $retVal;
2790  }  }
2791    
# Line 2840  Line 2881 
2881      # Get the parameters.      # Get the parameters.
2882      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2883      # Get the properties.      # Get the properties.
2884      my @attributes = $self->{_ca}->GetAttributes($featureID);      my @attributes = $self->ca->GetAttributes($featureID);
2885      # Strip the feature ID off each tuple.      # Strip the feature ID off each tuple.
2886      my @retVal = ();      my @retVal = ();
2887      for my $attributeRow (@attributes) {      for my $attributeRow (@attributes) {
# Line 3112  Line 3153 
3153  sub SubsystemList {  sub SubsystemList {
3154      # Get the parameters.      # Get the parameters.
3155      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3156      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3157      ##HACK: we do a join to the Subsystem table because we have missing subsystems in      # the Sprout database!
     ## the Sprout database!  
3158      my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3159                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3160      # Return the result, sorted.      # Return the result, sorted.
# Line 3148  Line 3188 
3188      # Declare the return variable.      # Declare the return variable.
3189      my %retVal = ();      my %retVal = ();
3190      # 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
3191      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3192      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3193                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3194                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3195      # 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
3196      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3197      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3198      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3199      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3200                                   "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.  
3201      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3202          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3203          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3204          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3205          my $subsys = $subHash{$cellID};          # Check the subsystem;
3206          if ($subsys) {          if ($subs{$subsys}) {
3207                Trace("Subsystem found.") if T(4);
3208              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3209              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3210              # Merge in this new data.              # Merge in this new data.
# Line 3216  Line 3250 
3250      # Get the parameters.      # Get the parameters.
3251      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3252      # Get a list of the features that are BBHs of the incoming feature.      # Get a list of the features that are BBHs of the incoming feature.
3253      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);      my $bbhData = FIGRules::BBHData($featureID);
3254        my @bbhFeatures = map { $_->[0] } @$bbhData;
3255      # Now we loop through the features, pulling out the ones that have the correct      # Now we loop through the features, pulling out the ones that have the correct
3256      # functional assignment.      # functional assignment.
3257      my @retVal = ();      my @retVal = ();
# Line 3389  Line 3424 
3424    
3425  =head3 BBHMatrix  =head3 BBHMatrix
3426    
3427      my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);      my $bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3428    
3429  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
3430  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 3413  Line 3448 
3448    
3449  =item RETURN  =item RETURN
3450    
3451  Returns a hash mapping each feature in the original genome to a hash mapping its  Returns a reference to a hash mapping each feature in the original genome
3452  BBH pegs in the target genomes to their scores.  to a sub-hash mapping its BBH pegs in the target genomes to their scores.
3453    
3454  =back  =back
3455    
# Line 3427  Line 3462 
3462      my %retVal = ();      my %retVal = ();
3463      # Ask for the BBHs.      # Ask for the BBHs.
3464      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3465        Trace("Retrieved " . scalar(@bbhList) . " BBH results.") if T(3);
3466      # We now have a set of 4-tuples that we need to convert into a hash of hashes.      # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3467      for my $bbhData (@bbhList) {      for my $bbhData (@bbhList) {
3468          my ($peg1, $peg2, $score) = @{$bbhData};          my ($peg1, $peg2, $score) = @{$bbhData};
# Line 3437  Line 3473 
3473          }          }
3474      }      }
3475      # Return the result.      # Return the result.
3476      return %retVal;      return \%retVal;
3477  }  }
3478    
3479    
# Line 3543  Line 3579 
3579      # Create the return hash.      # Create the return hash.
3580      my %retVal = ();      my %retVal = ();
3581      # Query for the desired BBHs.      # Query for the desired BBHs.
3582      my @bbhList = FIGRules::BBHData($featureID, $cutoff);      my $bbhList = FIGRules::BBHData($featureID, $cutoff);
3583      # Form the results into the return hash.      # Form the results into the return hash.
3584      for my $pair (@bbhList) {      for my $pair (@$bbhList) {
3585          my $fid = $pair->[0];          my $fid = $pair->[0];
3586          if ($self->Exists('Feature', $fid)) {          if ($self->Exists('Feature', $fid)) {
3587              $retVal{$fid} = $pair->[1];              $retVal{$fid} = $pair->[1];
# Line 3923  Line 3959 
3959      # Get the parameters.      # Get the parameters.
3960      my ($self, $featureID, $key, @values) = @_;      my ($self, $featureID, $key, @values) = @_;
3961      # Add the property using the attached attributes object.      # Add the property using the attached attributes object.
3962      $self->{_ca}->AddAttribute($featureID, $key, @values);      $self->ca->AddAttribute($featureID, $key, @values);
3963  }  }
3964    
3965  =head3 CheckGroupFile  =head3 CheckGroupFile
# Line 3943  Line 3979 
3979    
3980  =over 4  =over 4
3981    
3982  =item page  =item specials
3983    
3984  The super-group's web page in the NMPDR.  Reference to a hash whose keys are the names of special species.
3985    
3986  =item contents  =item contents
3987    
# Line 3968  Line 4004 
4004          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
4005          # Loop through the list of sort-of groups.          # Loop through the list of sort-of groups.
4006          for my $groupLine (@groupLines) {          for my $groupLine (@groupLines) {
4007              my ($name, $page, @contents) = split /\t/, $groupLine;              my ($name, $specials, @contents) = split /\t/, $groupLine;
4008              $groupHash{$name} = { page => $page,              $groupHash{$name} = { specials => { map { $_ => 1 } split /\s*,\s*/, $specials },
4009                                    contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]                                    contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
4010                                  };                                  };
4011          }          }
# Line 4010  Line 4046 
4046  sub CleanKeywords {  sub CleanKeywords {
4047      # Get the parameters.      # Get the parameters.
4048      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
4049      # Perform the standard cleanup.      # Get the stemmer.
4050      my $words = $self->ERDB::CleanKeywords($searchExpression);      my $stemmer = $self->GetStemmer();
4051      # Fix the periods in EC and TC numbers.      # Convert the search expression using the stemmer.
4052      $words =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
     # Fix non-trailing periods.  
     $words =~ s/\.(\w)/_$1/g;  
     # Fix non-leading minus signs.  
     $words =~ s/(\w)[\-]/$1_/g;  
     # Fix the vertical bars and colons  
     $words =~ s/(\w)[|:](\w)/$1'$2/g;  
     # Now split up the list so that each keyword is in its own string. We keep the delimiters  
     # because they may contain boolean expression data.  
     my @words = split /([^A-Za-z'0-9_]+)/, $words;  
     # We'll convert the stemmable words into stems and re-assemble the result.  
     my $retVal = "";  
     for my $word (@words) {  
         my $stem = $self->Stem($word);  
         if (defined $stem) {  
             $retVal .= $stem;  
         } else {  
             $retVal .= $word;  
         }  
     }  
4053      Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);      Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
4054      # Return the result.      # Return the result.
4055      return $retVal;      return $retVal;
4056  }  }
4057    
4058    =head3 GetSourceObject
4059    
4060        my $source = $erdb->GetSourceObject();
4061    
4062    Return the object to be used in creating load files for this database.
4063    
4064    =cut
4065    
4066    sub GetSourceObject {
4067        # Get the parameters.
4068        my ($self) = @_;
4069        # Check to see if we already have a source object.
4070        my $retVal = $self->{_fig};
4071        if (! defined $retVal) {
4072            # No, so create one.
4073            require FIG;
4074            $retVal = FIG->new();
4075        }
4076        # Return the object.
4077        return $retVal;
4078    }
4079    
4080    =head3 SectionList
4081    
4082        my @sections = $erdb->SectionList();
4083    
4084    Return a list of the names for the different data sections used when loading this database.
4085    The default is a single string, in which case there is only one section representing the
4086    entire database.
4087    
4088    =cut
4089    
4090    sub SectionList {
4091        # Get the parameters.
4092        my ($self, $source) = @_;
4093        # Ask the BaseSproutLoader for a section list.
4094        require BaseSproutLoader;
4095        my @retVal = BaseSproutLoader::GetSectionList($self);
4096        # Return the list.
4097        return @retVal;
4098    }
4099    
4100    =head3 Loader
4101    
4102        my $groupLoader = $erdb->Loader($groupName, $options);
4103    
4104    Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4105    by [[ERDBGeneratorPl]] to create the load group objects. If you are not using
4106    [[ERDBGeneratorPl]], you don't need to override this method.
4107    
4108    =over 4
4109    
4110    =item groupName
4111    
4112    Name of the load group whose object is to be returned. The group name is
4113    guaranteed to be a single word with only the first letter capitalized.
4114    
4115    =item options
4116    
4117    Reference to a hash of command-line options.
4118    
4119    =item RETURN
4120    
4121    Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4122    for this database.
4123    
4124    =back
4125    
4126    =cut
4127    
4128    sub Loader {
4129        # Get the parameters.
4130        my ($self, $groupName, $options) = @_;
4131        # Compute the loader name.
4132        my $loaderClass = "${groupName}SproutLoader";
4133        # Pull in its definition.
4134        require "$loaderClass.pm";
4135        # Create an object for it.
4136        my $retVal = eval("$loaderClass->new(\$self, \$options)");
4137        # Insure it worked.
4138        Confess("Could not create $loaderClass object: $@") if $@;
4139        # Return it to the caller.
4140        return $retVal;
4141    }
4142    
4143    
4144    =head3 LoadGroupList
4145    
4146        my @groups = $erdb->LoadGroupList();
4147    
4148    Returns a list of the names for this database's load groups. This method is used
4149    by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default
4150    is a single group called 'All' that loads everything.
4151    
4152    =cut
4153    
4154    sub LoadGroupList {
4155        # Return the list.
4156        return qw(Genome Subsystem Annotation Property Source Reaction Synonym Feature Drug);
4157    }
4158    
4159    =head3 LoadDirectory
4160    
4161        my $dirName = $erdb->LoadDirectory();
4162    
4163    Return the name of the directory in which load files are kept. The default is
4164    the FIG temporary directory, which is a really bad choice, but it's always there.
4165    
4166    =cut
4167    
4168    sub LoadDirectory {
4169        # Get the parameters.
4170        my ($self) = @_;
4171        # Return the directory name.
4172        return $self->{dataDir};
4173    }
4174    
4175  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4176    
4177    =head3 GetStemmer
4178    
4179        my $stermmer = $sprout->GetStemmer();
4180    
4181    Return the stemmer object for this database.
4182    
4183    =cut
4184    
4185    sub GetStemmer {
4186        # Get the parameters.
4187        my ($self) = @_;
4188        # Declare the return variable.
4189        my $retVal = $self->{stemmer};
4190        if (! defined $retVal) {
4191            # We don't have one pre-built, so we build and save it now.
4192            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4193                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4194                                     cache => 0);
4195            $self->{stemmer} = $retVal;
4196        }
4197        # Return the result.
4198        return $retVal;
4199    }
4200    
4201  =head3 ParseAssignment  =head3 ParseAssignment
4202    
4203  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 4126  Line 4284 
4284      # Get the parameters.      # Get the parameters.
4285      my ($self, $fid) = @_;      my ($self, $fid) = @_;
4286      # Insure we have a genome hash.      # Insure we have a genome hash.
4287      if (! defined $self->{genomeHash}) {      my $genomes = $self->_GenomeHash();
         my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');  
         $self->{genomeHash} = \%genomeHash;  
     }  
4288      # Get the feature's genome ID.      # Get the feature's genome ID.
4289      my ($genomeID) = FIGRules::ParseFeatureID($fid);      my ($genomeID) = FIGRules::ParseFeatureID($fid);
4290      # Return an indicator of whether or not the genome ID is in the hash.      # Return an indicator of whether or not the genome ID is in the hash.
# Line 4165  Line 4320 
4320    
4321  =head3 Hint  =head3 Hint
4322    
4323      my $htmlText = SearchHelper::Hint($wikiPage, $hintText);      my $htmlText = Sprout::Hint($wikiPage, $hintID);
4324    
4325  Return the HTML for a small question mark that displays the specified hint text when it is clicked.  Return the HTML for a help link that displays the specified hint text when it is clicked.
4326  This HTML can be put in forms to provide a useful hinting mechanism.  This HTML can be put in forms to provide a useful hinting mechanism.
4327    
4328  =over 4  =over 4
# Line 4176  Line 4331 
4331    
4332  Name of the wiki page to be popped up when the hint mark is clicked.  Name of the wiki page to be popped up when the hint mark is clicked.
4333    
4334  =item hintText  =item hintID
4335    
4336  Text to display for the hint. It is raw html, but may not contain any double quotes.  ID of the text to display for the hint. This should correspond to a tip number
4337    in the Wiki.
4338    
4339  =item RETURN  =item RETURN
4340    
4341  Returns the html for the hint facility. The resulting html shows a small button-like thing that  Returns the html for the hint facility. The resulting html shows the word "help" and
4342  uses the standard FIG popup technology.  uses the standard FIG popup technology.
4343    
4344  =back  =back
# Line 4191  Line 4347 
4347    
4348  sub Hint {  sub Hint {
4349      # Get the parameters.      # Get the parameters.
4350      my ($wikiPage, $hintText) = @_;      my ($wikiPage, $hintID) = @_;
4351      # Escape the single quotes in the hint text.      # Declare the return variable.
4352      my $quotedText = $hintText;      my $retVal;
     $quotedText =~ s/'/\\'/g;  
4353      # Convert the wiki page name to a URL.      # Convert the wiki page name to a URL.
4354      my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);      my $wikiURL;
4355      $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";      if ($wikiPage =~ m#/#) {
4356      # Compute the mouseover script.          # Here it's a URL of some sort.
4357      my $mouseOver = "doTooltip(this, '$quotedText')";          $wikiURL = $wikiPage;
4358      # Create the html.      } else {
4359      my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";          # Here it's a wiki page.
4360      # Return it.          my $page = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4361            if ($page =~ /^(.+?)\.(.+)$/) {
4362                $page = "$1/$2";
4363            } else {
4364                $page = "FIG/$page";
4365            }
4366            $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/$page";
4367        }
4368        # Is there hint text?
4369        if (! $hintID) {
4370            # No. Create a new-page hint.
4371            $retVal = qq(&nbsp;<a class="hint" onclick="doPagePopup(this, '$wikiURL')">(help)</a>);
4372        } else {
4373            # With hint text, we create a popup window hint. We need to compute the hint URL.
4374            my $tipURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/TWikiCustomTip" .
4375                Tracer::Pad($hintID, 3, 1, "0");
4376            # Create a hint pop-up link.
4377            $retVal = qq(&nbsp;<a class="hint" onclick="doHintPopup(this, '$wikiURL', '$tipURL')">(help)</a>);
4378        }
4379        # Return the HTML.
4380      return $retVal;      return $retVal;
4381  }  }
4382    
4383    =head3 _GenomeHash
4384    
4385        my $gHash = $sprout->_GenomeHash();
4386    
4387    Return a hash mapping all NMPDR genome IDs to [[ERDBObjectPm]] genome objects.
4388    
4389    =cut
4390    
4391    sub _GenomeHash {
4392        # Get the parameters.
4393        my ($self) = @_;
4394        # Do we already have a filled hash?
4395        if (! $self->{genomeHashFilled}) {
4396            # No, create it.
4397            my %gHash = map { $_->PrimaryValue('id') => $_ } $self->GetList("Genome", "", []);
4398            $self->{genomeHash} = \%gHash;
4399            # Denote we have it.
4400            $self->{genomeHashFilled} = 1;
4401        }
4402        # Return the hash.
4403        return $self->{genomeHash};
4404    }
4405    
4406    =head3 _GenomeData
4407    
4408        my $genomeData = $sprout->_GenomeData($genomeID);
4409    
4410    Return an [[ERDBObjectPm]] object for the specified genome, or an undefined
4411    value if the genome does not exist.
4412    
4413    =over 4
4414    
4415    =item genomeID
4416    
4417    ID of the desired genome.
4418    
4419    =item RETURN
4420    
4421    Returns either an [[ERDBObjectPm]] containing the genome, or an undefined value.
4422    If the genome exists, it will have been read into the genome cache.
4423    
4424    =back
4425    
4426    =cut
4427    
4428    sub _GenomeData {
4429        # Get the parameters.
4430        my ($self, $genomeID) = @_;
4431        # Are we in the genome hash?
4432        if (! exists $self->{genomeHash}->{$genomeID} && ! $self->{genomeHashFilled}) {
4433            # The genome isn't in the hash, and the hash is not complete, so we try to
4434            # read it.
4435            $self->{genomeHash}->{$genomeID} = $self->GetEntity(Genome => $genomeID);
4436        }
4437        # Return the result.
4438        return $self->{genomeHash}->{$genomeID};
4439    }
4440    
4441    =head3 _CacheGenome
4442    
4443        $sprout->_CacheGenome($genomeID, $genomeData);
4444    
4445    Store the specified genome object in the genome cache if it is already there.
4446    
4447    =over 4
4448    
4449    =item genomeID
4450    
4451    ID of the genome to store in the cache.
4452    
4453    =item genomeData
4454    
4455    An [[ERDBObjectPm]] containing at least the data for the specified genome.
4456    Note that the Genome may not be the primary object in it, so a fully-qualified
4457    field name has to be used to retrieve data from it.
4458    
4459    =back
4460    
4461    =cut
4462    
4463    sub _CacheGenome {
4464        # Get the parameters.
4465        my ($self, $genomeID, $genomeData) = @_;
4466        # Only proceed if we don't already have the genome.
4467        if (! exists $self->{genomeHash}->{$genomeID}) {
4468            $self->{genomeHash}->{$genomeID} = $genomeData;
4469        }
4470    }
4471    
4472  1;  1;

Legend:
Removed from v.1.116  
changed lines
  Added in v.1.125

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3