[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.80, Thu Aug 10 07:34:37 2006 UTC revision 1.104, Wed Jan 23 00:56:31 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;
     use Carp;  
5      use DBKernel;      use DBKernel;
6      use XML::Simple;      use XML::Simple;
7      use DBQuery;      use DBQuery;
8      use DBObject;      use ERDBObject;
9      use Tracer;      use Tracer;
10      use FIGRules;      use FIGRules;
11      use FidCheck;      use FidCheck;
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 base qw(ERDB);
18    
19  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
20    
# Line 28  Line 27 
27  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>
28  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>.
29    
30  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' });
31    
32  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
33  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
34  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
35  L</dna_seq> returns the DNA sequence for a specified genome location.  L</DNASeq> returns the DNA sequence for a specified genome location.
36    
37  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.
38    
# Line 45  Line 44 
44    
45  =head3 new  =head3 new
46    
47  C<< my $sprout = Sprout->new($dbName, \%options); >>      my $sprout = Sprout->new($dbName, \%options);
48    
49  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
50  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 85  Line 84 
84  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
85  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
86    
87  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' });
88    
89  =cut  =cut
90    
# Line 131  Line 130 
130      # Add the option table and XML file name.      # Add the option table and XML file name.
131      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
132      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
133        # Set up space for the group file data.
134        $retVal->{groupHash} = undef;
135        # Set up space for the genome hash. We use this to identify NMPDR genomes.
136        $retVal->{genomeHash} = undef;
137        # Connect to the attributes.
138        if ($FIG_Config::attrURL) {
139            Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
140            $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);
141        } elsif ($FIG_Config::attrDbName) {
142            Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
143            my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
144            $retVal->{_ca} = CustomAttributes->new(user => $user);
145        }
146      # Return it.      # Return it.
147      return $retVal;      return $retVal;
148  }  }
149    
150  =head3 MaxSegment  =head3 MaxSegment
151    
152  C<< my $length = $sprout->MaxSegment(); >>      my $length = $sprout->MaxSegment();
153    
154  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
155  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 154  Line 166 
166    
167  =head3 MaxSequence  =head3 MaxSequence
168    
169  C<< my $length = $sprout->MaxSequence(); >>      my $length = $sprout->MaxSequence();
170    
171  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
172  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 169  Line 181 
181    
182  =head3 Load  =head3 Load
183    
184  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
185    
186  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.
187    
# Line 209  Line 221 
221    
222  =head3 LoadUpdate  =head3 LoadUpdate
223    
224  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
225    
226  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
227  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 255  Line 267 
267              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
268          } else {          } else {
269              # Attempt to load this table.              # Attempt to load this table.
270              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
271              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
272              $retVal->Accumulate($result);              $retVal->Accumulate($result);
273          }          }
# Line 266  Line 278 
278    
279  =head3 GenomeCounts  =head3 GenomeCounts
280    
281  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>      my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
282    
283  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
284  genomes will be included in the counts.  genomes will be included in the counts.
# Line 311  Line 323 
323    
324  =head3 ContigCount  =head3 ContigCount
325    
326  C<< my $count = $sprout->ContigCount($genomeID); >>      my $count = $sprout->ContigCount($genomeID);
327    
328  Return the number of contigs for the specified genome ID.  Return the number of contigs for the specified genome ID.
329    
# Line 340  Line 352 
352    
353  =head3 GeneMenu  =head3 GeneMenu
354    
355  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>      my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected);
356    
357  Return an HTML select menu of genomes. Each genome will be an option in the menu,  Return an HTML select menu of genomes. Each genome will be an option in the menu,
358  and will be displayed by name with the ID and a contig count attached. The selection  and will be displayed by name with the ID and a contig count attached. The selection
# Line 362  Line 374 
374  Reference to a list of values to be substituted in for the parameter marks in  Reference to a list of values to be substituted in for the parameter marks in
375  the filter string.  the filter string.
376    
377    =item selected (optional)
378    
379    ID of the genome to be initially selected.
380    
381    =item fast (optional)
382    
383    If specified and TRUE, the contig counts will be omitted to improve performance.
384    
385  =item RETURN  =item RETURN
386    
387  Returns an HTML select menu with the specified genomes as selectable options.  Returns an HTML select menu with the specified genomes as selectable options.
# Line 372  Line 392 
392    
393  sub GeneMenu {  sub GeneMenu {
394      # Get the parameters.      # Get the parameters.
395      my ($self, $attributes, $filterString, $params) = @_;      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;
396        my $slowMode = ! $fast;
397        # Default to nothing selected. This prevents an execution warning if "$selected"
398        # is undefined.
399        $selected = "" unless defined $selected;
400        Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);
401      # Start the menu.      # Start the menu.
402      my $retVal = "<select " .      my $retVal = "<select " .
403          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
# Line 389  Line 414 
414          # Get the data for this genome.          # Get the data for this genome.
415          my ($genomeID, $genus, $species, $strain) = @{$genomeData};          my ($genomeID, $genus, $species, $strain) = @{$genomeData};
416          # Get the contig count.          # Get the contig count.
417            my $contigInfo = "";
418            if ($slowMode) {
419          my $count = $self->ContigCount($genomeID);          my $count = $self->ContigCount($genomeID);
420          my $counting = ($count == 1 ? "contig" : "contigs");          my $counting = ($count == 1 ? "contig" : "contigs");
421                $contigInfo = "[$count $counting]";
422            }
423            # Find out if we're selected.
424            my $selectOption = ($selected eq $genomeID ? " selected" : "");
425          # Build the option tag.          # Build the option tag.
426          $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";
         Trace("Option tag built for $genomeID: $genus $species $strain.") if T(3);  
427      }      }
428      # Close the SELECT tag.      # Close the SELECT tag.
429      $retVal .= "</select>\n";      $retVal .= "</select>\n";
430      # Return the result.      # Return the result.
431      return $retVal;      return $retVal;
432  }  }
433    
434  =head3 Build  =head3 Build
435    
436  C<< $sprout->Build(); >>      $sprout->Build();
437    
438  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.
439  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 419  Line 450 
450    
451  =head3 Genomes  =head3 Genomes
452    
453  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
454    
455  Return a list of all the genome IDs.  Return a list of all the genome IDs.
456    
# Line 436  Line 467 
467    
468  =head3 GenusSpecies  =head3 GenusSpecies
469    
470  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
471    
472  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
473    
# Line 468  Line 499 
499    
500  =head3 FeaturesOf  =head3 FeaturesOf
501    
502  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
503    
504  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
505    
# Line 513  Line 544 
544    
545  =head3 FeatureLocation  =head3 FeatureLocation
546    
547  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
548    
549  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
550  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 542  Line 573 
573  =back  =back
574    
575  =cut  =cut
576  #: Return Type @;  
 #: Return Type $;  
577  sub FeatureLocation {  sub FeatureLocation {
578      # Get the parameters.      # Get the parameters.
579      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
580      # Create a query for the feature locations.      # Get the feature record.
581      my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",      my $object = $self->GetEntity('Feature', $featureID);
582                             [$featureID]);      Confess("Feature $featureID not found.") if ! defined($object);
583        # Get the location string.
584        my $locString = $object->PrimaryValue('Feature(location-string)');
585      # Create the return list.      # Create the return list.
586      my @retVal = ();      my @retVal = split /\s*,\s*/, $locString;
     # Set up the variables used to determine if we have adjacent segments. This initial setup will  
     # not match anything.  
     my ($prevContig, $prevBeg, $prevDir, $prevLen) = ("", 0, "0", 0);  
     # Loop through the query results, creating location specifiers.  
     while (my $location = $query->Fetch()) {  
         # Get the location parameters.  
         my ($contigID, $beg, $dir, $len) = $location->Values(['IsLocatedIn(to-link)',  
             'IsLocatedIn(beg)', 'IsLocatedIn(dir)', 'IsLocatedIn(len)']);  
         # 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";  
     }  
587      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
588      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
589  }  }
590    
591  =head3 ParseLocation  =head3 ParseLocation
592    
593  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
594    
595  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
596  length.  length.
# Line 611  Line 609 
609  =back  =back
610    
611  =cut  =cut
612  #: Return Type @;  
613  sub ParseLocation {  sub ParseLocation {
614      # 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
615      # the first parameter.      # the first parameter.
# Line 634  Line 632 
632      return ($contigID, $start, $dir, $len);      return ($contigID, $start, $dir, $len);
633  }  }
634    
635    
636    
637  =head3 PointLocation  =head3 PointLocation
638    
639  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
640    
641  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
642  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 665  Line 665 
665  =back  =back
666    
667  =cut  =cut
668  #: Return Type $;  
669  sub PointLocation {  sub PointLocation {
670      # 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
671      # the first parameter.      # the first parameter.
# Line 688  Line 688 
688    
689  =head3 DNASeq  =head3 DNASeq
690    
691  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
692    
693  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
694  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 772  Line 772 
772    
773  =head3 AllContigs  =head3 AllContigs
774    
775  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
776    
777  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
778    
# Line 802  Line 802 
802    
803  =head3 GenomeLength  =head3 GenomeLength
804    
805  C<< my $length = $sprout->GenomeLength($genomeID); >>      my $length = $sprout->GenomeLength($genomeID);
806    
807  Return the length of the specified genome in base pairs.  Return the length of the specified genome in base pairs.
808    
# Line 837  Line 837 
837    
838  =head3 FeatureCount  =head3 FeatureCount
839    
840  C<< my $count = $sprout->FeatureCount($genomeID, $type); >>      my $count = $sprout->FeatureCount($genomeID, $type);
841    
842  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.
843    
# Line 872  Line 872 
872    
873  =head3 GenomeAssignments  =head3 GenomeAssignments
874    
875  C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>      my $fidHash = $sprout->GenomeAssignments($genomeID);
876    
877  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
878  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 898  Line 898 
898      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
899      # Declare the return variable.      # Declare the return variable.
900      my $retVal = {};      my $retVal = {};
901      # Query the genome's features and annotations. We'll put the oldest annotations      # Query the genome's features.
902      # first so that the last assignment to go into the hash will be the correct one.      my $query = $self->Get(['HasFeature', 'Feature'], "HasFeature(from-link) = ?",
     my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'],  
                            "HasFeature(from-link) = ? ORDER BY Annotation(time)",  
903                             [$genomeID]);                             [$genomeID]);
904      # Loop through the annotations.      # Loop through the features.
905      while (my $data = $query->Fetch) {      while (my $data = $query->Fetch) {
906          # Get the feature ID and annotation text.          # Get the feature ID and assignment.
907          my ($fid, $annotation) = $data->Values(['HasFeature(to-link)',          my ($fid, $assignment) = $data->Values(['Feature(id)', 'Feature(assignment)']);
908                                                  'Annotation(annotation)']);          if ($assignment) {
         # Check to see if this is an assignment. Note that the user really  
         # doesn't matter to us, other than we use it to determine whether or  
         # not this is an assignment.  
         my ($user, $assignment) = _ParseAssignment('fig', $annotation);  
         if ($user) {  
             # Here it's an assignment. We put it in the return hash, overwriting  
             # any older assignment that might be present.  
909              $retVal->{$fid} = $assignment;              $retVal->{$fid} = $assignment;
910          }          }
911      }      }
# Line 924  Line 915 
915    
916  =head3 ContigLength  =head3 ContigLength
917    
918  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->ContigLength($contigID);
919    
920  Compute the length of a contig.  Compute the length of a contig.
921    
# Line 963  Line 954 
954    
955  =head3 ClusterPEGs  =head3 ClusterPEGs
956    
957  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
958    
959  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
960  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
961  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
962  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
963  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
964  sequence.  appear in the output sequence.
965    
966  =over 4  =over 4
967    
# Line 1011  Line 1002 
1002    
1003  =head3 GenesInRegion  =head3 GenesInRegion
1004    
1005  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1006    
1007  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1008    
# Line 1040  Line 1031 
1031  =back  =back
1032    
1033  =cut  =cut
1034  #: Return Type @@;  
1035  sub GenesInRegion {  sub GenesInRegion {
1036      # Get the parameters.      # Get the parameters.
1037      my ($self, $contigID, $start, $stop) = @_;      my ($self, $contigID, $start, $stop) = @_;
1038      # Get the maximum segment length.      # Get the maximum segment length.
1039      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 = ();  
1040      # Prime the values we'll use for the returned beginning and end.      # Prime the values we'll use for the returned beginning and end.
1041      my @initialMinMax = ($self->ContigLength($contigID), 0);      my @initialMinMax = ($self->ContigLength($contigID), 0);
1042      my ($min, $max) = @initialMinMax;      my ($min, $max) = @initialMinMax;
1043      # Create a table of parameters for each query. Each query looks for features travelling in      # Get the overlapping features.
1044        my @featureObjects = $self->GeneDataInRegion($contigID, $start, $stop);
1045        # We'l use this hash to help us track the feature IDs and sort them. The key is the
1046        # feature ID and the value is a [$left,$right] pair indicating the maximum extent
1047        # of the feature's locations.
1048        my %featureMap = ();
1049        # Loop through them to do the begin/end analysis.
1050        for my $featureObject (@featureObjects) {
1051            # Get the feature's location string. This may contain multiple actual locations.
1052            my ($locations, $fid) = $featureObject->Values([qw(Feature(location-string) Feature(id))]);
1053            my @locationSegments = split /\s*,\s*/, $locations;
1054            # Loop through the locations.
1055            for my $locationSegment (@locationSegments) {
1056                # Construct an object for the location.
1057                my $locationObject = BasicLocation->new($locationSegment);
1058                # Merge the current segment's begin and end into the min and max.
1059                my ($left, $right) = ($locationObject->Left, $locationObject->Right);
1060                my ($beg, $end);
1061                if (exists $featureMap{$fid}) {
1062                    ($beg, $end) = @{$featureMap{$fid}};
1063                    $beg = $left if $left < $beg;
1064                    $end = $right if $right > $end;
1065                } else {
1066                    ($beg, $end) = ($left, $right);
1067                }
1068                $min = $beg if $beg < $min;
1069                $max = $end if $end > $max;
1070                # Store the feature's new extent back into the hash table.
1071                $featureMap{$fid} = [$beg, $end];
1072            }
1073        }
1074        # Now we must compute the list of the IDs for the features found. We start with a list
1075        # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
1076        # but the result of the sort will be the same.)
1077        my @list = map { [$featureMap{$_}->[0] + $featureMap{$_}->[1], $_] } keys %featureMap;
1078        # Now we sort by midpoint and yank out the feature IDs.
1079        my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
1080        # Return it along with the min and max.
1081        return (\@retVal, $min, $max);
1082    }
1083    
1084    =head3 GeneDataInRegion
1085    
1086        my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1087    
1088    List the features which overlap a specified region in a contig.
1089    
1090    =over 4
1091    
1092    =item contigID
1093    
1094    ID of the contig containing the region of interest.
1095    
1096    =item start
1097    
1098    Offset of the first residue in the region of interest.
1099    
1100    =item stop
1101    
1102    Offset of the last residue in the region of interest.
1103    
1104    =item RETURN
1105    
1106    Returns a list of B<ERDBObjects> for the desired features. Each object will
1107    contain a B<Feature> record.
1108    
1109    =back
1110    
1111    =cut
1112    
1113    sub GeneDataInRegion {
1114        # Get the parameters.
1115        my ($self, $contigID, $start, $stop) = @_;
1116        # Get the maximum segment length.
1117        my $maximumSegmentLength = $self->MaxSegment;
1118        # Create a hash to receive the feature list. We use a hash so that we can eliminate
1119        # duplicates easily. The hash key will be the feature ID. The value will be the feature's
1120        # ERDBObject from the query.
1121        my %featuresFound = ();
1122        # Create a table of parameters for the queries. Each query looks for features travelling in
1123      # 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,
1124      # 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
1125      # 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 1063  Line 1128 
1128      # Loop through the query parameters.      # Loop through the query parameters.
1129      for my $parms (values %queryParms) {      for my $parms (values %queryParms) {
1130          # Create the query.          # Create the query.
1131          my $query = $self->Get(['IsLocatedIn'],          my $query = $self->Get([qw(Feature IsLocatedIn)],
1132              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",
1133              $parms);              $parms);
1134          # Loop through the feature segments found.          # Loop through the feature segments found.
1135          while (my $segment = $query->Fetch) {          while (my $segment = $query->Fetch) {
1136              # Get the data about this segment.              # Get the data about this segment.
1137              my ($featureID, $dir, $beg, $len) = $segment->Values(['IsLocatedIn(from-link)',              my ($featureID, $contig, $dir, $beg, $len) = $segment->Values([qw(IsLocatedIn(from-link)
1138                  'IsLocatedIn(dir)', 'IsLocatedIn(beg)', 'IsLocatedIn(len)']);                  IsLocatedIn(to-link) IsLocatedIn(dir) IsLocatedIn(beg) IsLocatedIn(len))]);
1139              # 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
1140              # 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
1141              # 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
1142              # length.              # length.
1143              my ($found, $end) = (0, 0);              my $loc = BasicLocation->new($contig, $beg, $dir, $len);
1144              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;  
                 }  
             }  
1145              if ($found) {              if ($found) {
1146                  # Here we need to record the feature and update the minima and maxima. First,                  # Save this feature in the result list.
1147                  # 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;  
1148                  }                  }
                 # Store the entry back into the hash table.  
                 $featuresFound{$featureID} = [$loc1, $loc2];  
1149              }              }
1150          }          }
1151      }      # Return the ERDB objects for the features found.
1152      # 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);  
1153  }  }
1154    
1155  =head3 FType  =head3 FType
1156    
1157  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1158    
1159  Return the type of a feature.  Return the type of a feature.
1160    
# Line 1153  Line 1184 
1184    
1185  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1186    
1187  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1188    
1189  Return the annotations of a feature.  Return the annotations of a feature.
1190    
# Line 1216  Line 1247 
1247    
1248  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1249    
1250  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1251    
1252  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
1253  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 1271  Line 1302 
1302    
1303  =head3 FunctionOf  =head3 FunctionOf
1304    
1305  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1306    
1307  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1308    
1309  The functional assignment is handled differently depending on the type of feature. If  The functional assignment is handled differently depending on the type of feature. If
1310  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional  the feature is identified by a FIG ID (begins with the string C<fig|>), then the functional
1311  assignment is a type of annotation. The format of an assignment is described in  assignment is taken from the B<Feature> or C<Annotation> table, depending.
 L</ParseAssignment>. Its worth noting that we cannot filter on the content of the  
 annotation itself because it's a text field; however, this is not a big problem because  
 most features only have a small number of annotations.  
1312    
1313  Each user has an associated list of trusted users. The assignment returned will be the most  Each user has an associated list of trusted users. The assignment returned will be the most
1314  recent one by at least one of the trusted users. If no trusted user list is available, then  recent one by at least one of the trusted users. If no trusted user list is available, then
# Line 1299  Line 1327 
1327    
1328  =item userID (optional)  =item userID (optional)
1329    
1330  ID of the user whose function determination is desired. If omitted, only the latest  ID of the user whose function determination is desired. If omitted, the primary
1331  C<FIG> assignment will be returned.  functional assignment in the B<Feature> table will be returned.
1332    
1333  =item RETURN  =item RETURN
1334    
# Line 1317  Line 1345 
1345      my $retVal;      my $retVal;
1346      # Determine the ID type.      # Determine the ID type.
1347      if ($featureID =~ m/^fig\|/) {      if ($featureID =~ m/^fig\|/) {
1348          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID.
1349          # users.          if (!$userID) {
1350                # Use the primary assignment.
1351                ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);
1352            } else {
1353                # We must build the list of trusted users.
1354          my %trusteeTable = ();          my %trusteeTable = ();
1355          # Check the user ID.          # Check the user ID.
1356          if (!$userID) {          if (!$userID) {
# Line 1361  Line 1393 
1393                  }                  }
1394              }              }
1395          }          }
1396            }
1397      } else {      } else {
1398          # Here we have a non-FIG feature ID. In this case the user ID does not          # Here we have a non-FIG feature ID. In this case the user ID does not
1399          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
# Line 1373  Line 1406 
1406    
1407  =head3 FunctionsOf  =head3 FunctionsOf
1408    
1409  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1410    
1411  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1412    
# Line 1445  Line 1478 
1478    
1479  =head3 BBHList  =head3 BBHList
1480    
1481  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1482    
1483  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
1484  on a specified target genome.  on a specified target genome.
# Line 1476  Line 1509 
1509      my %retVal = ();      my %retVal = ();
1510      # Loop through the incoming features.      # Loop through the incoming features.
1511      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1512          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1513          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1514          # Peel off the BBHs found.          # Peel off the BBHs found.
1515          my @found = ();          my @found = ();
1516          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1517              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              my $fid = $bbh->[0];
1518                my $bbGenome = $self->GenomeOf($fid);
1519                if ($bbGenome eq $genomeID) {
1520                    push @found, $fid;
1521                }
1522          }          }
1523          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1524      }      }
# Line 1493  Line 1528 
1528    
1529  =head3 SimList  =head3 SimList
1530    
1531  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1532    
1533  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1534    
1535  Sprout does not support real similarities, so this method just returns the bidirectional  This method just returns the bidirectional best hits for performance reasons.
 best hits.  
1536    
1537  =over 4  =over 4
1538    
# Line 1518  Line 1552 
1552      # Get the parameters.      # Get the parameters.
1553      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1554      # Ask for the best hits.      # Ask for the best hits.
1555      my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],      my @lists = FIGRules::BBHData($featureID);
                               "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",  
                               [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],  
                               $count);  
1556      # Create the return value.      # Create the return value.
1557      my %retVal = ();      my %retVal = ();
1558      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1531  Line 1562 
1562      return %retVal;      return %retVal;
1563  }  }
1564    
   
   
1565  =head3 IsComplete  =head3 IsComplete
1566    
1567  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1568    
1569  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1570    
# Line 1563  Line 1592 
1592      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1593      if ($genomeData) {      if ($genomeData) {
1594          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1595          ($retVal) = $genomeData->Value('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1596      }      }
1597      # Return the result.      # Return the result.
1598      return $retVal;      return $retVal;
# Line 1571  Line 1600 
1600    
1601  =head3 FeatureAliases  =head3 FeatureAliases
1602    
1603  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1604    
1605  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1606    
# Line 1594  Line 1623 
1623      # Get the parameters.      # Get the parameters.
1624      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1625      # Get the desired feature's aliases      # Get the desired feature's aliases
1626      my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);      my @retVal = $self->GetFlat(['IsAliasOf'], "IsAliasOf(to-link) = ?", [$featureID], 'IsAliasOf(from-link)');
1627      # Return the result.      # Return the result.
1628      return @retVal;      return @retVal;
1629  }  }
1630    
1631  =head3 GenomeOf  =head3 GenomeOf
1632    
1633  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1634    
1635  Return the genome that contains a specified feature or contig.  Return the genome that contains a specified feature or contig.
1636    
# Line 1623  Line 1652 
1652  sub GenomeOf {  sub GenomeOf {
1653      # Get the parameters.      # Get the parameters.
1654      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]);  
1655      # Declare the return value.      # Declare the return value.
1656      my $retVal;      my $retVal;
1657      # Get the genome ID.      # Parse the genome ID from the feature ID.
1658      if (my $relationship = $query->Fetch()) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1659          ($retVal) = $relationship->Value('HasContig(from-link)');          $retVal = $1;
1660        } else {
1661            Confess("Invalid feature ID $featureID.");
1662      }      }
1663      # Return the value found.      # Return the value found.
1664      return $retVal;      return $retVal;
# Line 1638  Line 1666 
1666    
1667  =head3 CoupledFeatures  =head3 CoupledFeatures
1668    
1669  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
1670    
1671  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
1672  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 1660  Line 1688 
1688  sub CoupledFeatures {  sub CoupledFeatures {
1689      # Get the parameters.      # Get the parameters.
1690      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1691        # Ask the coupling server for the data.
1692      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1693      # Create a query to retrieve the functionally-coupled features.      my @rawPairs = FIGRules::NetCouplingData('coupled_to', id1 => $featureID);
1694      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      Trace(scalar(@rawPairs) . " couplings returned.") if T(coupling => 3);
1695                             "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.  
1696      my %retVal = ();      my %retVal = ();
1697      # Retrieve the relationship records and store them in the hash.      for my $pair (@rawPairs) {
1698      while (my $clustering = $query->Fetch()) {          # Get the feature ID and score.
1699          # Get the ID and score of the coupling.          my ($featureID2, $score) = @{$pair};
1700          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          # Only proceed if the feature is in NMPDR.
1701                                                          'Coupling(score)']);          if ($self->_CheckFeature($featureID2)) {
1702          Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);              $retVal{$featureID2} = $score;
1703          # 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;  
1704      }      }
1705      # 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
1706      # the incoming feature as well.      # the incoming feature as well.
1707      if ($found) {      if (keys %retVal) {
1708          $retVal{$featureID} = 9999;          $retVal{$featureID} = 9999;
1709      }      }
1710      # Return the hash.      # Return the hash.
# Line 1694  Line 1713 
1713    
1714  =head3 CouplingEvidence  =head3 CouplingEvidence
1715    
1716  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
1717    
1718  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
1719    
# Line 1742  Line 1761 
1761      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
1762      # Declare the return variable.      # Declare the return variable.
1763      my @retVal = ();      my @retVal = ();
1764      # Our first task is to find out the nature of the coupling: whether or not      # Get the coupling and evidence data.
1765      # it exists, its score, and whether the features are stored in the same      my @rawData = FIGRules::NetCouplingData('coupling_evidence', id1 => $peg1, id2 => $peg2);
1766      # order as the ones coming in.      # Loop through the raw data, saving the ones that are in NMPDR genomes.
1767      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);      for my $rawTuple (@rawData) {
1768      # Only proceed if a coupling exists.          if ($self->_CheckFeature($rawTuple->[0]) && $self->_CheckFeature($rawTuple->[1])) {
1769      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;  
1770  }  }
   
 =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);  
1771      }      }
1772      # Return the result.      # Return the result.
1773      return ($retVal, $inverted, $score);      return @retVal;
1774  }  }
1775    
1776  =head3 GetSynonymGroup  =head3 GetSynonymGroup
1777    
1778  C<< my $id = $sprout->GetSynonymGroup($fid); >>      my $id = $sprout->GetSynonymGroup($fid);
1779    
1780  Return the synonym group name for the specified feature.  Return the synonym group name for the specified feature.
1781    
# Line 1873  Line 1814 
1814    
1815  =head3 GetBoundaries  =head3 GetBoundaries
1816    
1817  C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
1818    
1819  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
1820  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 1935  Line 1876 
1876      return ($contig, $beg, $end);      return ($contig, $beg, $end);
1877  }  }
1878    
 =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);  
 }  
   
1879  =head3 ReadFasta  =head3 ReadFasta
1880    
1881  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
1882    
1883  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
1884  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 2042  Line 1944 
1944    
1945  =head3 FormatLocations  =head3 FormatLocations
1946    
1947  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
1948    
1949  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
1950  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 2107  Line 2009 
2009    
2010  =head3 DumpData  =head3 DumpData
2011    
2012  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2013    
2014  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.
2015    
# Line 2124  Line 2026 
2026    
2027  =head3 XMLFileName  =head3 XMLFileName
2028    
2029  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2030    
2031  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2032    
# Line 2135  Line 2037 
2037      return $self->{_xmlName};      return $self->{_xmlName};
2038  }  }
2039    
2040    =head3 GetGenomeNameData
2041    
2042        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2043    
2044    Return the genus, species, and unique characterization for a genome. This
2045    is similar to L</GenusSpecies>, with the exception that it returns the
2046    values in three seperate fields.
2047    
2048    =over 4
2049    
2050    =item genomeID
2051    
2052    ID of the genome whose name data is desired.
2053    
2054    =item RETURN
2055    
2056    Returns a three-element list, consisting of the genus, species, and strain
2057    of the specified genome. If the genome is not found, an error occurs.
2058    
2059    =back
2060    
2061    =cut
2062    
2063    sub GetGenomeNameData {
2064        # Get the parameters.
2065        my ($self, $genomeID) = @_;
2066        # Get the desired values.
2067        my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>
2068                                                                [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);
2069        # Throw an error if they were not found.
2070        if (! defined $genus) {
2071            Confess("Genome $genomeID not found in database.");
2072        }
2073        # Return the results.
2074        return ($genus, $species, $strain);
2075    }
2076    
2077    =head3 GetGenomeByNameData
2078    
2079        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2080    
2081    Return a list of the IDs of the genomes with the specified genus,
2082    species, and strain. In almost every case, there will be either zero or
2083    one IDs returned; however, two or more IDs could be returned if there are
2084    multiple versions of the genome in the database.
2085    
2086    =over 4
2087    
2088    =item genus
2089    
2090    Genus of the desired genome.
2091    
2092    =item species
2093    
2094    Species of the desired genome.
2095    
2096    =item strain
2097    
2098    Strain (unique characterization) of the desired genome. This may be an empty
2099    string, in which case it is presumed that the desired genome has no strain
2100    specified.
2101    
2102    =item RETURN
2103    
2104    Returns a list of the IDs of the genomes having the specified genus, species, and
2105    strain.
2106    
2107    =back
2108    
2109    =cut
2110    
2111    sub GetGenomeByNameData {
2112        # Get the parameters.
2113        my ($self, $genus, $species, $strain) = @_;
2114        # Try to find the genomes.
2115        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2116                                    [$genus, $species, $strain], 'Genome(id)');
2117        # Return the result.
2118        return @retVal;
2119    }
2120    
2121  =head3 Insert  =head3 Insert
2122    
2123  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2124    
2125  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
2126  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 2146  Line 2129 
2129  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
2130  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>.
2131    
2132  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']});
2133    
2134  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
2135  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>.
2136    
2137  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'});
2138    
2139  =over 4  =over 4
2140    
# Line 2176  Line 2159 
2159    
2160  =head3 Annotate  =head3 Annotate
2161    
2162  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2163    
2164  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
2165  specified feature and user.  specified feature and user.
# Line 2230  Line 2213 
2213    
2214  =head3 AssignFunction  =head3 AssignFunction
2215    
2216  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2217    
2218  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
2219  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2290  Line 2273 
2273    
2274  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2275    
2276  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2277    
2278  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
2279  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 2324  Line 2307 
2307          push @retVal, $mappedAlias;          push @retVal, $mappedAlias;
2308      } else {      } else {
2309          # 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.
2310          @retVal = $self->GetFlat(['Feature'], 'Feature(alias) = ?', [$mappedAlias], 'Feature(id)');          @retVal = $self->GetFlat(['IsAliasOf'], 'IsAliasOf(from-link) = ?', [$mappedAlias], 'IsAliasOf(to-link)');
2311      }      }
2312      # Return the result.      # Return the result.
2313      return @retVal;      return @retVal;
# Line 2332  Line 2315 
2315    
2316  =head3 FeatureTranslation  =head3 FeatureTranslation
2317    
2318  C<< my $translation = $sprout->FeatureTranslation($featureID); >>      my $translation = $sprout->FeatureTranslation($featureID);
2319    
2320  Return the translation of a feature.  Return the translation of a feature.
2321    
# Line 2360  Line 2343 
2343    
2344  =head3 Taxonomy  =head3 Taxonomy
2345    
2346  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2347    
2348  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
2349  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>,
2350  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2351    
2352  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2353    
2354  =over 4  =over 4
2355    
# Line 2401  Line 2384 
2384    
2385  =head3 CrudeDistance  =head3 CrudeDistance
2386    
2387  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2388    
2389  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
2390  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 2453  Line 2436 
2436    
2437  =head3 RoleName  =head3 RoleName
2438    
2439  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2440    
2441  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
2442  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 2487  Line 2470 
2470    
2471  =head3 RoleDiagrams  =head3 RoleDiagrams
2472    
2473  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2474    
2475  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2476    
# Line 2517  Line 2500 
2500    
2501  =head3 GetProperties  =head3 GetProperties
2502    
2503  C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>      my @list = $sprout->GetProperties($fid, $key, $value, $url);
2504    
2505  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2506    
2507  Properties are arbitrary key-value pairs associated with a feature. (At some point they  Properties are the Sprout analog of the FIG attributes. The call is
2508  will also be associated with genomes.) A property value is represented by a 4-tuple of  passed directly to the CustomAttributes or RemoteCustomAttributes object
2509  the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter  contained in this object.
2510    
2511  =over 4  This method returns a series of tuples that match the specified criteria. Each tuple
2512    will contain an object ID, a key, and one or more values. The parameters to this
2513    method therefore correspond structurally to the values expected in each tuple. In
2514    addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any
2515    of the parameters. So, for example,
2516    
2517  =item fid      my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);
2518    
2519  ID of the feature possessing the property.  would return something like
2520    
2521  =item key      ['fig}100226.1.peg.1004', 'structure', 1, 2]
2522        ['fig}100226.1.peg.1004', 'structure1', 1, 2]
2523        ['fig}100226.1.peg.1004', 'structure2', 1, 2]
2524        ['fig}100226.1.peg.1004', 'structureA', 1, 2]
2525    
2526  Name or key of the property.  Use of C<undef> in any position acts as a wild card (all values). You can also specify
2527    a list reference in the ID column. Thus,
2528    
2529  =item value      my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');
2530    
2531  Value of the property.  would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its
2532    features.
2533    
2534  =item url  In addition to values in multiple sections, a single attribute key can have multiple
2535    values, so even
2536    
2537  URL of the document that indicated the property should have this particular value, or an      my @attributeList = $sprout->GetProperties($peg, 'virulent');
 empty string if no such document exists.  
2538    
2539  =back  which has no wildcard in the key or the object ID, may return multiple tuples.
2540    
2541    =over 4
2542    
2543    =item objectID
2544    
2545  The parameters act as a filter for the desired data. Any non-null parameter will  ID of object whose attributes are desired. If the attributes are desired for multiple
2546  automatically match all the tuples returned. So, specifying just the I<$fid> will  objects, this parameter can be specified as a list reference. If the attributes are
2547  return all the properties of the specified feature; similarly, specifying the I<$key>  desired for all objects, specify C<undef> or an empty string. Finally, you can specify
2548  and I<$value> parameters will return all the features having the specified property  attributes for a range of object IDs by putting a percent sign (C<%>) at the end.
 value.  
2549    
2550  A single property key can have many values, representing different ideas about the  =item key
2551  feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is  
2552  virulent, and another may declare that it is not virulent. A query about the virulence of  Attribute key name. A value of C<undef> or an empty string will match all
2553  C<fig|83333.1.peg.10> would be coded as  attribute keys. If the values are desired for multiple keys, this parameter can be
2554    specified as a list reference. Finally, you can specify attributes for a range of
2555    keys by putting a percent sign (C<%>) at the end.
2556    
2557    =item values
2558    
2559    List of the desired attribute values, section by section. If C<undef>
2560    or an empty string is specified, all values in that section will match. A
2561    generic match can be requested by placing a percent sign (C<%>) at the end.
2562    In that case, all values that match up to and not including the percent sign
2563    will match. You may also specify a regular expression enclosed
2564    in slashes. All values that match the regular expression will be returned. For
2565    performance reasons, only values have this extra capability.
2566    
2567      my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');  =item RETURN
2568    
2569  Here the I<$value> and I<$url> fields are left blank, indicating that those fields are  Returns a list of tuples. The first element in the tuple is an object ID, the
2570  not to be filtered. The tuples returned would be  second is an attribute key, and the remaining elements are the sections of
2571    the attribute value. All of the tuples will match the criteria set forth in
2572    the parameter list.
2573    
2574      ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')  =back
     ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')  
2575    
2576  =cut  =cut
2577  #: Return Type @@;  
2578  sub GetProperties {  sub GetProperties {
2579      # Get the parameters.      # Get the parameters.
2580      my ($self, @parms) = @_;      my ($self, @parms) = @_;
2581      # Declare the return variable.      # Declare the return variable.
2582      my @retVal = ();      my @retVal = $self->{_ca}->GetAttributes(@parms);
     # 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;  
     }  
2583      # Return the result.      # Return the result.
2584      return @retVal;      return @retVal;
2585  }  }
2586    
2587  =head3 FeatureProperties  =head3 FeatureProperties
2588    
2589  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2590    
2591  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
2592  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
2593  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
2594  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
2595  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.  
2596    
2597  =over 4  =over 4
2598    
# Line 2618  Line 2602 
2602    
2603  =item RETURN  =item RETURN
2604    
2605  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.  
2606    
2607  =back  =back
2608    
# Line 2629  Line 2612 
2612      # Get the parameters.      # Get the parameters.
2613      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2614      # Get the properties.      # Get the properties.
2615      my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],      my @attributes = $self->{_ca}->GetAttributes($featureID);
2616                              ['Property(property-name)', 'Property(property-value)',      # Strip the feature ID off each tuple.
2617                               'HasProperty(evidence)']);      my @retVal = ();
2618        for my $attributeRow (@attributes) {
2619            shift @{$attributeRow};
2620            push @retVal, $attributeRow;
2621        }
2622      # Return the resulting list.      # Return the resulting list.
2623      return @retVal;      return @retVal;
2624  }  }
2625    
2626  =head3 DiagramName  =head3 DiagramName
2627    
2628  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2629    
2630  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2631    
# Line 2664  Line 2651 
2651      return $retVal;      return $retVal;
2652  }  }
2653    
2654    =head3 PropertyID
2655    
2656        my $id = $sprout->PropertyID($propName, $propValue);
2657    
2658    Return the ID of the specified property name and value pair, if the
2659    pair exists. Only a small subset of the FIG attributes are stored as
2660    Sprout properties, mostly for use in search optimization.
2661    
2662    =over 4
2663    
2664    =item propName
2665    
2666    Name of the desired property.
2667    
2668    =item propValue
2669    
2670    Value expected for the desired property.
2671    
2672    =item RETURN
2673    
2674    Returns the ID of the name/value pair, or C<undef> if the pair does not exist.
2675    
2676    =back
2677    
2678    =cut
2679    
2680    sub PropertyID {
2681        # Get the parameters.
2682        my ($self, $propName, $propValue) = @_;
2683        # Try to find the ID.
2684        my ($retVal) = $self->GetFlat(['Property'],
2685                                      "Property(property-name) = ? AND Property(property-value) = ?",
2686                                      [$propName, $propValue], 'Property(id)');
2687        # Return the result.
2688        return $retVal;
2689    }
2690    
2691  =head3 MergedAnnotations  =head3 MergedAnnotations
2692    
2693  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2694    
2695  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
2696  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 2715  Line 2739 
2739    
2740  =head3 RoleNeighbors  =head3 RoleNeighbors
2741    
2742  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
2743    
2744  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
2745  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 2758  Line 2782 
2782    
2783  =head3 FeatureLinks  =head3 FeatureLinks
2784    
2785  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
2786    
2787  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
2788  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 2789  Line 2813 
2813    
2814  =head3 SubsystemsOf  =head3 SubsystemsOf
2815    
2816  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
2817    
2818  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
2819  to the roles the feature performs.  to the roles the feature performs.
# Line 2837  Line 2861 
2861    
2862  =head3 SubsystemList  =head3 SubsystemList
2863    
2864  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
2865    
2866  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
2867  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2861  Line 2885 
2885      # Get the parameters.      # Get the parameters.
2886      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2887      # Get the list of names.      # Get the list of names.
2888      my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
2889                                  [$featureID], 'HasSSCell(from-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
2890      # Return the result.      # Return the result, sorted.
2891      return @retVal;      return sort @retVal;
2892  }  }
2893    
2894  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
2895    
2896  C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>      my %featureData = $sprout->GenomeSubsystemData($genomeID);
2897    
2898  Return a hash mapping genome features to their subsystem roles.  Return a hash mapping genome features to their subsystem roles.
2899    
# Line 2929  Line 2953 
2953    
2954  =head3 RelatedFeatures  =head3 RelatedFeatures
2955    
2956  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
2957    
2958  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
2959  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 2962  Line 2986 
2986      # Get the parameters.      # Get the parameters.
2987      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
2988      # 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.
2989      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
2990      # 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
2991      # functional assignment.      # functional assignment.
2992      my @retVal = ();      my @retVal = ();
# Line 2982  Line 3004 
3004    
3005  =head3 TaxonomySort  =head3 TaxonomySort
3006    
3007  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3008    
3009  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
3010  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 3030  Line 3052 
3052    
3053  =head3 Protein  =head3 Protein
3054    
3055  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3056    
3057  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3058    
# Line 3100  Line 3122 
3122      # Loop through the input triples.      # Loop through the input triples.
3123      my $n = length $sequence;      my $n = length $sequence;
3124      for (my $i = 0; $i < $n; $i += 3) {      for (my $i = 0; $i < $n; $i += 3) {
3125          # Get the current triple from the sequence.          # Get the current triple from the sequence. Note we convert to
3126          my $triple = substr($sequence, $i, 3);          # upper case to insure a match.
3127            my $triple = uc substr($sequence, $i, 3);
3128          # Translate it using the table.          # Translate it using the table.
3129          my $protein = "X";          my $protein = "X";
3130          if (exists $table->{$triple}) { $protein = $table->{$triple}; }          if (exists $table->{$triple}) { $protein = $table->{$triple}; }
# Line 3115  Line 3138 
3138    
3139  =head3 LoadInfo  =head3 LoadInfo
3140    
3141  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3142    
3143  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
3144  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 3134  Line 3157 
3157      return @retVal;      return @retVal;
3158  }  }
3159    
3160    =head3 BBHMatrix
3161    
3162        my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3163    
3164    Find all the bidirectional best hits for the features of a genome in a
3165    specified list of target genomes. The return value will be a hash mapping
3166    features in the original genome to their bidirectional best hits in the
3167    target genomes.
3168    
3169    =over 4
3170    
3171    =item genomeID
3172    
3173    ID of the genome whose features are to be examined for bidirectional best hits.
3174    
3175    =item cutoff
3176    
3177    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3178    
3179    =item targets
3180    
3181    List of target genomes. Only pairs originating in the original
3182    genome and landing in one of the target genomes will be returned.
3183    
3184    =item RETURN
3185    
3186    Returns a hash mapping each feature in the original genome to a hash mapping its
3187    BBH pegs in the target genomes to their scores.
3188    
3189    =back
3190    
3191    =cut
3192    
3193    sub BBHMatrix {
3194        # Get the parameters.
3195        my ($self, $genomeID, $cutoff, @targets) = @_;
3196        # Declare the return variable.
3197        my %retVal = ();
3198        # Ask for the BBHs.
3199        my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3200        # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3201        for my $bbhData (@bbhList) {
3202            my ($peg1, $peg2, $score) = @{$bbhData};
3203            if (! exists $retVal{$peg1}) {
3204                $retVal{$peg1} = { $peg2 => $score };
3205            } else {
3206                $retVal{$peg1}->{$peg2} = $score;
3207            }
3208        }
3209        # Return the result.
3210        return %retVal;
3211    }
3212    
3213    
3214    =head3 SimMatrix
3215    
3216        my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3217    
3218    Find all the similarities for the features of a genome in a
3219    specified list of target genomes. The return value will be a hash mapping
3220    features in the original genome to their similarites in the
3221    target genomes.
3222    
3223    =over 4
3224    
3225    =item genomeID
3226    
3227    ID of the genome whose features are to be examined for similarities.
3228    
3229    =item cutoff
3230    
3231    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3232    
3233    =item targets
3234    
3235    List of target genomes. Only pairs originating in the original
3236    genome and landing in one of the target genomes will be returned.
3237    
3238    =item RETURN
3239    
3240    Returns a hash mapping each feature in the original genome to a hash mapping its
3241    similar pegs in the target genomes to their scores.
3242    
3243    =back
3244    
3245    =cut
3246    
3247    sub SimMatrix {
3248        # Get the parameters.
3249        my ($self, $genomeID, $cutoff, @targets) = @_;
3250        # Declare the return variable.
3251        my %retVal = ();
3252        # Get the list of features in the source organism.
3253        my @fids = $self->FeaturesOf($genomeID);
3254        # Ask for the sims. We only want similarities to fig features.
3255        my $simList = FIGRules::GetNetworkSims($self, \@fids, {}, 1000, $cutoff, "fig");
3256        if (! defined $simList) {
3257            Confess("Unable to retrieve similarities from server.");
3258        } else {
3259            Trace("Processing sims.") if T(3);
3260            # We now have a set of sims that we need to convert into a hash of hashes. First, we
3261            # Create a hash for the target genomes.
3262            my %targetHash = map { $_ => 1 } @targets;
3263            for my $simData (@{$simList}) {
3264                # Get the PEGs and the score.
3265                my ($peg1, $peg2, $score) = ($simData->id1, $simData->id2, $simData->psc);
3266                # Insure the second ID is in the target list.
3267                my ($genome2) = FIGRules::ParseFeatureID($peg2);
3268                if (exists $targetHash{$genome2}) {
3269                    # Here it is. Now we need to add it to the return hash. How we do that depends
3270                    # on whether or not $peg1 is new to us.
3271                    if (! exists $retVal{$peg1}) {
3272                        $retVal{$peg1} = { $peg2 => $score };
3273                    } else {
3274                        $retVal{$peg1}->{$peg2} = $score;
3275                    }
3276                }
3277            }
3278        }
3279        # Return the result.
3280        return %retVal;
3281    }
3282    
3283    
3284  =head3 LowBBHs  =head3 LowBBHs
3285    
3286  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3287    
3288  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
3289  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 3165  Line 3312 
3312      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3313      # Create the return hash.      # Create the return hash.
3314      my %retVal = ();      my %retVal = ();
3315      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3316      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3317      # Form the results into the return hash.      # Form the results into the return hash.
3318      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3319          $retVal{$pair->[0]} = $pair->[1];          my $fid = $pair->[0];
3320            if ($self->Exists('Feature', $fid)) {
3321                $retVal{$fid} = $pair->[1];
3322            }
3323      }      }
3324      # Return the result.      # Return the result.
3325      return %retVal;      return %retVal;
# Line 3180  Line 3327 
3327    
3328  =head3 Sims  =head3 Sims
3329    
3330  C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>      my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3331    
3332  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
3333  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 3190  Line 3337 
3337  Similarities can be either raw or expanded. The raw similarities are basic  Similarities can be either raw or expanded. The raw similarities are basic
3338  hits between features with similar DNA. Expanding a raw similarity drags in any  hits between features with similar DNA. Expanding a raw similarity drags in any
3339  features considered substantially identical. So, for example, if features B<A1>,  features considered substantially identical. So, for example, if features B<A1>,
3340  B<A2>, and B<A3> are all substatially identical to B<A>, then a raw similarity  B<A2>, and B<A3> are all substantially identical to B<A>, then a raw similarity
3341  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.
3342    
3343  =over 4  =over 4
3344    
3345  =item fid  =item fid
3346    
3347  ID of the feature whose similarities are desired.  ID of the feature whose similarities are desired, or reference to a list of IDs
3348    of features whose similarities are desired.
3349    
3350  =item maxN  =item maxN
3351    
# Line 3243  Line 3391 
3391      return $retVal;      return $retVal;
3392  }  }
3393    
3394    =head3 IsAllGenomes
3395    
3396        my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3397    
3398    Return TRUE if all genomes in the second list are represented in the first list at
3399    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3400    compared to a list of all the genomes.
3401    
3402    =over 4
3403    
3404    =item list
3405    
3406    Reference to the list to be compared to the second list.
3407    
3408    =item checkList (optional)
3409    
3410    Reference to the comparison target list. Every genome ID in this list must occur at
3411    least once in the first list. If this parameter is omitted, a list of all the genomes
3412    is used.
3413    
3414    =item RETURN
3415    
3416    Returns TRUE if every item in the second list appears at least once in the
3417    first list, else FALSE.
3418    
3419    =back
3420    
3421    =cut
3422    
3423    sub IsAllGenomes {
3424        # Get the parameters.
3425        my ($self, $list, $checkList) = @_;
3426        # Supply the checklist if it was omitted.
3427        $checkList = [$self->Genomes()] if ! defined($checkList);
3428        # Create a hash of the original list.
3429        my %testList = map { $_ => 1 } @{$list};
3430        # Declare the return variable. We assume that the representation
3431        # is complete and stop at the first failure.
3432        my $retVal = 1;
3433        my $n = scalar @{$checkList};
3434        for (my $i = 0; $retVal && $i < $n; $i++) {
3435            if (! $testList{$checkList->[$i]}) {
3436                $retVal = 0;
3437            }
3438        }
3439        # Return the result.
3440        return $retVal;
3441    }
3442    
3443  =head3 GetGroups  =head3 GetGroups
3444    
3445  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3446    
3447  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.
3448  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 3264  Line 3461 
3461          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3462          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3463          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3464              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3465                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3466              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3467          }          }
# Line 3272  Line 3469 
3469          # Here we need all of the groups. In this case, we run through all          # Here we need all of the groups. In this case, we run through all
3470          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3471          # group. Note that we use a filter clause to insure that only genomes          # group. Note that we use a filter clause to insure that only genomes
3472          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3473          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3474                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3475          # Loop through the genomes found.          # Loop through the genomes found.
3476          for my $genome (@genomes) {          for my $genome (@genomes) {
3477              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3478              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3479              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);  
             }  
3480          }          }
3481      }      }
3482      # Return the hash we just built.      # Return the hash we just built.
# Line 3293  Line 3485 
3485    
3486  =head3 MyGenomes  =head3 MyGenomes
3487    
3488  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3489    
3490  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3491    
# Line 3325  Line 3517 
3517    
3518  =head3 LoadFileName  =head3 LoadFileName
3519    
3520  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3521    
3522  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
3523  directory.  directory.
# Line 3366  Line 3558 
3558    
3559  =head3 DeleteGenome  =head3 DeleteGenome
3560    
3561  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3562    
3563  Delete a genome from the database.  Delete a genome from the database.
3564    
# Line 3392  Line 3584 
3584      # Get the parameters.      # Get the parameters.
3585      my ($self, $genomeID, $testFlag) = @_;      my ($self, $genomeID, $testFlag) = @_;
3586      # Perform the delete for the genome's features.      # Perform the delete for the genome's features.
3587      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", $testFlag);      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", testMode => $testFlag);
3588      # Perform the delete for the primary genome data.      # Perform the delete for the primary genome data.
3589      my $stats = $self->Delete('Genome', $genomeID, $testFlag);      my $stats = $self->Delete('Genome', $genomeID, testMode => $testFlag);
3590      $retVal->Accumulate($stats);      $retVal->Accumulate($stats);
3591      # Return the result.      # Return the result.
3592      return $retVal;      return $retVal;
3593  }  }
3594    
3595    =head3 Fix
3596    
3597        my %fixedHash = $sprout->Fix(%groupHash);
3598    
3599    Prepare a genome group hash (like that returned by L</GetGroups>) for processing.
3600    The groups will be combined into the appropriate super-groups.
3601    
3602    =over 4
3603    
3604    =item groupHash
3605    
3606    Hash to be fixed up.
3607    
3608    =item RETURN
3609    
3610    Returns a fixed-up version of the hash.
3611    
3612    =back
3613    
3614    =cut
3615    
3616    sub Fix {
3617        # Get the parameters.
3618        my ($self, %groupHash) = @_;
3619        # Create the result hash.
3620        my %retVal = ();
3621        # Get the super-group table.
3622        my %superTable = $self->CheckGroupFile();
3623        # Copy over the genomes.
3624        for my $groupID (keys %groupHash) {
3625            # Get the super-group name.
3626            my $realGroupID;
3627            if ($groupID =~ /([A-Z]\w+)/) {
3628                if (! defined($superTable{$1})) {
3629                    Confess("Super-group name not found for group $groupID.");
3630                } else {
3631                    $realGroupID = $1;
3632                }
3633            } else {
3634                Confess("Invalid group name $groupID.");
3635            }
3636            # Append this group's genomes into the result hash.
3637            push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
3638        }
3639        # Return the result hash.
3640        return %retVal;
3641    }
3642    
3643    =head3 GroupPageName
3644    
3645        my $name = $sprout->GroupPageName($group);
3646    
3647    Return the name of the page for the specified NMPDR group.
3648    
3649    =over 4
3650    
3651    =item group
3652    
3653    Name of the relevant group.
3654    
3655    =item RETURN
3656    
3657    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3658    memory it will be read in.
3659    
3660    =back
3661    
3662    =cut
3663    
3664    sub GroupPageName {
3665        # Get the parameters.
3666        my ($self, $group) = @_;
3667        # Declare the return variable.
3668        my $retVal;
3669        # Check for the group file data.
3670        my %superTable = $self->CheckGroupFile();
3671        # Compute the real group name.
3672        if ($group =~ /([A-Z]\w+)/) {
3673            my $realGroup = $1;
3674            if (! defined($superTable{$1})) {
3675                Confess("No super-group found for \"$group\".");
3676            } else {
3677                $retVal = "../content/$superTable{$1}->{page}";
3678            }
3679        } else {
3680            Confess("\"group\" is not a valid group name.");
3681        }
3682        # Return the result.
3683        return $retVal;
3684    }
3685    
3686    
3687    =head3 AddProperty
3688    
3689        $sprout->AddProperty($featureID, $key, @values);
3690    
3691    Add a new attribute value (Property) to a feature.
3692    
3693    =over 4
3694    
3695    =item peg
3696    
3697    ID of the feature to which the attribute is to be added.
3698    
3699    =item key
3700    
3701    Name of the attribute (key).
3702    
3703    =item values
3704    
3705    Values of the attribute.
3706    
3707    =back
3708    
3709    =cut
3710    #: Return Type ;
3711    sub AddProperty {
3712        # Get the parameters.
3713        my ($self, $featureID, $key, @values) = @_;
3714        # Add the property using the attached attributes object.
3715        $self->{_ca}->AddAttribute($featureID, $key, @values);
3716    }
3717    
3718    =head3 CheckGroupFile
3719    
3720        my %groupData = $sprout->CheckGroupFile();
3721    
3722    Get the group file hash. The group file hash describes the relationship
3723    between a group and the super-group to which it belongs for purposes of
3724    display. The super-group name is computed from the first capitalized word
3725    in the actual group name. For each super-group, the group file contains
3726    the page name and a list of the species expected to be in the group.
3727    Each species is specified by a genus and a species name. A species name
3728    of C<0> implies an entire genus.
3729    
3730    This method returns a hash from super-group names to a hash reference. Each
3731    resulting hash reference contains the following fields.
3732    
3733    =over 4
3734    
3735    =item page
3736    
3737    The super-group's web page in the NMPDR.
3738    
3739    =item contents
3740    
3741    A list of 2-tuples, each containing a genus name followed by a species name
3742    (or 0, indicating all species). This list indicates which organisms belong
3743    in the super-group.
3744    
3745    =back
3746    
3747    =cut
3748    
3749    sub CheckGroupFile{
3750        # Get the parameters.
3751        my ($self) = @_;
3752        # Check to see if we already have this hash.
3753        if (! defined $self->{groupHash}) {
3754            # We don't, so we need to read it in.
3755            my %groupHash;
3756            # Read the group file.
3757            my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3758            # Loop through the list of sort-of groups.
3759            for my $groupLine (@groupLines) {
3760                my ($name, $page, @contents) = split /\t/, $groupLine;
3761                $groupHash{$name} = { page => $page,
3762                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3763                                    };
3764            }
3765            # Save the hash.
3766            $self->{groupHash} = \%groupHash;
3767        }
3768        # Return the result.
3769        return %{$self->{groupHash}};
3770    }
3771    
3772    =head2 Virtual Methods
3773    
3774    =head3 CleanKeywords
3775    
3776        my $cleanedString = $sprout->CleanKeywords($searchExpression);
3777    
3778    Clean up a search expression or keyword list. This involves converting the periods
3779    in EC numbers to underscores, converting non-leading minus signs to underscores,
3780    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3781    characters. In addition, any extra spaces are removed.
3782    
3783    =over 4
3784    
3785    =item searchExpression
3786    
3787    Search expression or keyword list to clean. Note that a search expression may
3788    contain boolean operators which need to be preserved. This includes leading
3789    minus signs.
3790    
3791    =item RETURN
3792    
3793    Cleaned expression or keyword list.
3794    
3795    =back
3796    
3797    =cut
3798    
3799    sub CleanKeywords {
3800        # Get the parameters.
3801        my ($self, $searchExpression) = @_;
3802        # Perform the standard cleanup.
3803        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3804        # Fix the periods in EC and TC numbers.
3805        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3806        # Fix non-trailing periods.
3807        $retVal =~ s/\.(\w)/_$1/g;
3808        # Fix non-leading minus signs.
3809        $retVal =~ s/(\w)[\-]/$1_/g;
3810        # Fix the vertical bars and colons
3811        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3812        # Return the result.
3813        return $retVal;
3814    }
3815    
3816  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3817    
3818  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3410  Line 3823 
3823    
3824  A functional assignment is always of the form  A functional assignment is always of the form
3825    
3826      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
3827        ZZZZ
3828    
3829  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,
3830  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 3456  Line 3870 
3870      }      }
3871      # If we have an assignment, we need to clean the function text. There may be      # If we have an assignment, we need to clean the function text. There may be
3872      # extra junk at the end added as a note from the user.      # extra junk at the end added as a note from the user.
3873      if (@retVal > 1) {      if (defined( $retVal[1] )) {
3874          $retVal[1] =~ s/(\t\S)?\s*$//;          $retVal[1] =~ s/(\t\S)?\s*$//;
3875      }      }
3876      # Return the result list.      # Return the result list.
3877      return @retVal;      return @retVal;
3878  }  }
3879    
3880  =head3 FriendlyTimestamp  =head3 _CheckFeature
3881    
3882  Convert a time number to a user-friendly time stamp for display.      my $flag = $sprout->_CheckFeature($fid);
3883    
3884  This is a static method.  Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.
3885    
3886  =over 4  =over 4
3887    
3888  =item timeValue  =item fid
3889    
3890  Numeric time value.  Feature ID to check.
3891    
3892  =item RETURN  =item RETURN
3893    
3894  Returns a string containing the same time in user-readable format.  Returns TRUE if the FID is for one of the NMPDR genomes, else FALSE.
3895    
3896  =back  =back
3897    
3898  =cut  =cut
3899    
3900  sub FriendlyTimestamp {  sub _CheckFeature {
3901      my ($timeValue) = @_;      # Get the parameters.
3902      my $retVal = localtime($timeValue);      my ($self, $fid) = @_;
3903      return $retVal;      # Insure we have a genome hash.
3904        if (! defined $self->{genomeHash}) {
3905            my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');
3906            $self->{genomeHash} = \%genomeHash;
3907        }
3908        # Get the feature's genome ID.
3909        my ($genomeID) = FIGRules::ParseFeatureID($fid);
3910        # Return an indicator of whether or not the genome ID is in the hash.
3911        return ($self->{genomeHash}->{$genomeID} ? 1 : 0);
3912  }  }
3913    
3914  =head3 AddProperty  =head3 FriendlyTimestamp
3915    
3916  C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>  Convert a time number to a user-friendly time stamp for display.
3917    
3918  Add a new attribute value (Property) to a feature. In the SEED system, attributes can  This is a static method.
 be added to almost any object. In Sprout, they can only be added to features. In  
 Sprout, attributes are implemented using I<properties>. A property represents a key/value  
 pair. If the particular key/value pair coming in is not already in the database, a new  
 B<Property> record is created to hold it.  
3919    
3920  =over 4  =over 4
3921    
3922  =item peg  =item timeValue
   
 ID of the feature to which the attribute is to be replied.  
   
 =item key  
   
 Name of the attribute (key).  
   
 =item value  
3923    
3924  Value of the attribute.  Numeric time value.
3925    
3926  =item url  =item RETURN
3927    
3928  URL or text citation from which the property was obtained.  Returns a string containing the same time in user-readable format.
3929    
3930  =back  =back
3931    
3932  =cut  =cut
3933  #: Return Type ;  
3934  sub AddProperty {  sub FriendlyTimestamp {
3935      # Get the parameters.      my ($timeValue) = @_;
3936      my ($self, $featureID, $key, $value, $url) = @_;      my $retVal = localtime($timeValue);
3937      # Declare the variable to hold the desired property ID.      return $retVal;
     my $propID;  
     # Attempt to find a property record for this key/value pair.  
     my @properties = $self->GetFlat(['Property'],  
                                    "Property(property-name) = ? AND Property(property-value) = ?",  
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
         # 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 });  
3938  }  }
3939    
3940    

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.104

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3