[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.2, Sun Jan 23 22:31:29 2005 UTC revision 1.14, Thu Jun 9 19:06:55 2005 UTC
# Line 11  Line 11 
11          use Tracer;          use Tracer;
12          use FIGRules;          use FIGRules;
13          use Stats;          use Stats;
14        use POSIX qw(strftime);
15    
16    
17  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 33  Line 34 
34    
35  =cut  =cut
36    
37  #  #: Constructor SFXlate->new_sprout_only();
38    
39  =head2 Public Methods  =head2 Public Methods
40    
# Line 121  Line 122 
122  and 10999.  and 10999.
123    
124  =cut  =cut
125    #: Return Type $;
126  sub MaxSegment {  sub MaxSegment {
127          my $self = shift @_;          my ($self) = @_;
128          return $self->{_options}->{maxSegmentLength};          return $self->{_options}->{maxSegmentLength};
129  }  }
130    
# Line 136  Line 137 
137  we generally only need a few sequences in memory rather than the entire contig.  we generally only need a few sequences in memory rather than the entire contig.
138    
139  =cut  =cut
140    #: Return Type $;
141  sub MaxSequence {  sub MaxSequence {
142          my $self = shift @_;          my ($self) = @_;
143          return $self->{_options}->{maxSequenceLength};          return $self->{_options}->{maxSequenceLength};
144  }  }
145    
# Line 231  Line 232 
232    
233  sub Get {  sub Get {
234          # Get the parameters.          # Get the parameters.
235          my $self = shift @_;          my ($self, $objectNames, $filterClause, $parameterList) = @_;
         my ($objectNames, $filterClause, $parameterList) = @_;  
236          # We differ from the ERDB Get method in that the parameter list is passed in as a list reference          # We differ from the ERDB Get method in that the parameter list is passed in as a list reference
237          # rather than a list of parameters. The next step is to convert the parameters from a reference          # rather than a list of parameters. The next step is to convert the parameters from a reference
238          # to a real list. We can only do this if the parameters have been specified.          # to a real list. We can only do this if the parameters have been specified.
# Line 268  Line 268 
268    
269  sub GetEntity {  sub GetEntity {
270          # Get the parameters.          # Get the parameters.
271          my $self = shift @_;          my ($self, $entityType, $ID) = @_;
272          my ($entityType, $ID) = @_;          # Call the ERDB method.
273          # Create a query.          return $self->{_erdb}->GetEntity($entityType, $ID);
         my $query = $self->Get([$entityType], "$entityType(id) = ?", [$ID]);  
         # Get the first (and only) object.  
         my $retVal = $query->Fetch();  
         # Return the result.  
         return $retVal;  
274  }  }
275    
276  =head3 GetEntityValues  =head3 GetEntityValues
# Line 305  Line 300 
300  =back  =back
301    
302  =cut  =cut
303    #: Return Type @;
304  sub GetEntityValues {  sub GetEntityValues {
305          # Get the parameters.          # Get the parameters.
306          my $self = shift @_;          my ($self, $entityType, $ID, $fields) = @_;
307          my ($entityType, $ID, $fields) = @_;          # Call the ERDB method.
308          # Get the specified entity.          return $self->{_erdb}->GetEntityValues($entityType, $ID, $fields);
         my $entity = $self->GetEntity($entityType, $ID);  
         # Declare the return list.  
         my @retVal = ();  
         # If we found the entity, push the values into the return list.  
         if ($entity) {  
                 push @retVal, $entity->Values($fields);  
         }  
         # Return the result.  
         return @retVal;  
309  }  }
310    
311  =head3 ShowMetaData  =head3 ShowMetaData
# Line 340  Line 326 
326    
327  sub ShowMetaData {  sub ShowMetaData {
328          # Get the parameters.          # Get the parameters.
329          my $self = shift @_;          my ($self, $fileName) = @_;
         my ($fileName) = @_;  
330          # Compute the file name.          # Compute the file name.
331          my $options = $self->{_options};          my $options = $self->{_options};
332          # Call the show method on the underlying ERDB object.          # Call the show method on the underlying ERDB object.
# Line 378  Line 363 
363  =back  =back
364    
365  =cut  =cut
366    #: Return Type %;
367  sub Load {  sub Load {
368          # Get the parameters.          # Get the parameters.
369          my $self = shift @_;          my ($self, $rebuild) = @_;
         my ($rebuild) = @_;  
370          # Get the database object.          # Get the database object.
371          my $erdb = $self->{_erdb};          my $erdb = $self->{_erdb};
372          # Load the tables from the data directory.          # Load the tables from the data directory.
# Line 422  Line 406 
406  =back  =back
407    
408  =cut  =cut
409    #: Return Type $%;
410  sub LoadUpdate {  sub LoadUpdate {
411          # Get the parameters.          # Get the parameters.
412          my $self = shift @_;          my ($self, $truncateFlag, $tableList) = @_;
         my ($truncateFlag, $tableList) = @_;  
413          # Get the database object.          # Get the database object.
414          my $erdb = $self->{_erdb};          my $erdb = $self->{_erdb};
415          # Declare the return value.          # Declare the return value.
# Line 459  Line 442 
442  changed.  changed.
443    
444  =cut  =cut
445    #: Return Type ;
446  sub Build {  sub Build {
447          # Get the parameters.          # Get the parameters.
448          my $self = shift @_;          my ($self) = @_;
449          # Create the tables.          # Create the tables.
450          $self->{_erdb}->CreateTables;          $self->{_erdb}->CreateTables;
451  }  }
# Line 474  Line 457 
457  Return a list of all the genome IDs.  Return a list of all the genome IDs.
458    
459  =cut  =cut
460    #: Return Type @;
461  sub Genomes {  sub Genomes {
462          # Get the parameters.          # Get the parameters.
463          my $self = shift @_;          my ($self) = @_;
464          # Get all the genomes.          # Get all the genomes.
465          my @retVal = $self->GetFlat(['Genome'], "", [], 'Genome(id)');          my @retVal = $self->GetFlat(['Genome'], "", [], 'Genome(id)');
466          # Return the list of IDs.          # Return the list of IDs.
# Line 504  Line 487 
487  =back  =back
488    
489  =cut  =cut
490    #: Return Type $;
491  sub GenusSpecies {  sub GenusSpecies {
492          # Get the parameters.          # Get the parameters.
493          my $self = shift @_;          my ($self, $genomeID) = @_;
         my ($genomeID) = @_;  
494          # Get the data for the specified genome.          # Get the data for the specified genome.
495          my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',          my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',
496                                                                                                                            'Genome(unique-characterization)']);                                                                                                                            'Genome(unique-characterization)']);
# Line 541  Line 523 
523  =back  =back
524    
525  =cut  =cut
526    #: Return Type @;
527  sub FeaturesOf {  sub FeaturesOf {
528          # Get the parameters.          # Get the parameters.
529          my $self = shift @_;          my ($self, $genomeID,$ftype) = @_;
         my ($genomeID,$ftype) = @_;  
530          # Get the features we want.          # Get the features we want.
531          my @features;          my @features;
532          if (!$ftype) {          if (!$ftype) {
# Line 594  Line 575 
575  =back  =back
576    
577  =cut  =cut
578    #: Return Type @;
579    #: Return Type $;
580  sub FeatureLocation {  sub FeatureLocation {
581          # Get the parameters.          # Get the parameters.
582          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
583          # Create a query for the feature locations.          # Create a query for the feature locations.
584          my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",          my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",
585                                                     [$featureID]);                                                     [$featureID]);
# Line 656  Line 637 
637  =back  =back
638    
639  =cut  =cut
640    #: Return Type @;
641  sub ParseLocation {  sub ParseLocation {
642          # Get the parameter.          # Get the parameter. Note that if we're called as an instance method, we ignore
643        # the first parameter.
644        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
645          my ($location) = @_;          my ($location) = @_;
646          # Parse it into segments.          # Parse it into segments.
647          $location =~ /^(.*)_(\d*)([+-_])(\d*)$/;          $location =~ /^(.*)_(\d*)([+-_])(\d*)$/;
# Line 677  Line 660 
660          return ($contigID, $start, $dir, $len);          return ($contigID, $start, $dir, $len);
661  }  }
662    
663    =head3 PointLocation
664    
665    C<< my $found = Sprout::PointLocation($location, $point); >>
666    
667    Return the offset into the specified location of the specified point on the contig. If
668    the specified point is before the location, a negative value will be returned. If it is
669    beyond the location, an undefined value will be returned. It is assumed that the offset
670    is for the location's contig. The location can either be new-style (using a C<+> or C<->
671    and a length) or old-style (using C<_> and start and end positions.
672    
673    =over 4
674    
675    =item location
676    
677    A location specifier (see L</FeatureLocation> for a description).
678    
679    =item point
680    
681    The offset into the contig of the point in which we're interested.
682    
683    =item RETURN
684    
685    Returns the offset inside the specified location of the specified point, a negative
686    number if the point is before the location, or an undefined value if the point is past
687    the location. If the length of the location is 0, this method will B<always> denote
688    that it is outside the location. The offset will always be relative to the left-most
689    position in the location.
690    
691    =back
692    
693    =cut
694    #: Return Type $;
695    sub PointLocation {
696            # Get the parameter. Note that if we're called as an instance method, we ignore
697        # the first parameter.
698        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
699            my ($location, $point) = @_;
700        # Parse out the location elements. Note that this works on both old-style and new-style
701        # locations.
702        my ($contigID, $start, $dir, $len) = ParseLocation($location);
703        # Declare the return variable.
704        my $retVal;
705        # Compute the offset. The computation is dependent on the direction of the location.
706        my $offset = (($dir == '+') ? $point - $start : $point - ($start - $len + 1));
707        # Return the offset if it's valid.
708        if ($offset < $len) {
709            $retVal = $offset;
710        }
711        # Return the offset found.
712        return $retVal;
713    }
714    
715  =head3 DNASeq  =head3 DNASeq
716    
717  C<< my $sequence = $sprout->DNASeq(\@locationList); >>  C<< my $sequence = $sprout->DNASeq(\@locationList); >>
# Line 699  Line 734 
734  =back  =back
735    
736  =cut  =cut
737    #: Return Type $;
738  sub DNASeq {  sub DNASeq {
739          # Get the parameters.          # Get the parameters.
740          my $self = shift @_;          my ($self, $locationList) = @_;
         my ($locationList) = @_;  
741          # Create the return string.          # Create the return string.
742          my $retVal = "";          my $retVal = "";
743          # Loop through the locations.          # Loop through the locations.
# Line 773  Line 807 
807  =back  =back
808    
809  =cut  =cut
810    #: Return Type @;
811  sub AllContigs {  sub AllContigs {
812          # Get the parameters.          # Get the parameters.
813          my $self = shift @_;          my ($self, $genomeID) = @_;
         my ($genomeID) = @_;  
814          # Ask for the genome's Contigs.          # Ask for the genome's Contigs.
815          my @retVal = $self->GetFlat(['HasContig'], "HasContig(from-link) = ?", [$genomeID],          my @retVal = $self->GetFlat(['HasContig'], "HasContig(from-link) = ?", [$genomeID],
816                                                                  'HasContig(to-link)');                                                                  'HasContig(to-link)');
# Line 797  Line 830 
830    
831  ID of the contig whose length is desired.  ID of the contig whose length is desired.
832    
833    =item RETURN
834    
835    Returns the number of positions in the contig.
836    
837  =back  =back
838    
839  =cut  =cut
840    #: Return Type $;
841  sub ContigLength {  sub ContigLength {
842          # Get the parameters.          # Get the parameters.
843          my $self = shift @_;          my ($self, $contigID) = @_;
         my ($contigID) = @_;  
844          # Get the contig's last sequence.          # Get the contig's last sequence.
845          my $query = $self->Get(['IsMadeUpOf'],          my $query = $self->Get(['IsMadeUpOf'],
846                  "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",                  "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",
# Line 846  Line 882 
882  Returns a three-element list. The first element is a list of feature IDs for the features that  Returns a three-element list. The first element is a list of feature IDs for the features that
883  overlap the region of interest. The second and third elements are the minimum and maximum  overlap the region of interest. The second and third elements are the minimum and maximum
884  locations of the features provided on the specified contig. These may extend outside  locations of the features provided on the specified contig. These may extend outside
885  the start and stop values.  the start and stop values. The first element (that is, the list of features) is sorted
886    roughly by location.
887    
888  =back  =back
889    
890  =cut  =cut
891    #: Return Type @@;
892  sub GenesInRegion {  sub GenesInRegion {
893          # Get the parameters.          # Get the parameters.
894          my $self = shift @_;          my ($self, $contigID, $start, $stop) = @_;
         my ($contigID, $start, $stop) = @_;  
895          # Get the maximum segment length.          # Get the maximum segment length.
896          my $maximumSegmentLength = $self->MaxSegment;          my $maximumSegmentLength = $self->MaxSegment;
897          # Create a hash to receive the feature list. We use a hash so that we can eliminate          # Create a hash to receive the feature list. We use a hash so that we can eliminate
898          # duplicates easily.          # duplicates easily. The hash key will be the feature ID. The value will be a two-element
899            # containing the minimum and maximum offsets. We will use the offsets to sort the results
900            # when we're building the result set.
901          my %featuresFound = ();          my %featuresFound = ();
902          # Prime the values we'll use for the returned beginning and end.          # Prime the values we'll use for the returned beginning and end.
903          my ($min, $max) = ($self->ContigLength($contigID), 0);          my @initialMinMax = ($self->ContigLength($contigID), 0);
904            my ($min, $max) = @initialMinMax;
905          # Create a table of parameters for each query. Each query looks for features travelling in          # Create a table of parameters for each query. Each query looks for features travelling in
906          # 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,
907          # 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
# Line 892  Line 931 
931                                          $found = 1;                                          $found = 1;
932                                  }                                  }
933                          } elsif ($dir eq '-') {                          } elsif ($dir eq '-') {
934                                  $end = $beg - $len;                                  # Note we switch things around so that the beginning is to the left of the
935                                  if ($end <= $stop) {                                  # ending.
936                                    ($beg, $end) = ($beg - $len, $beg);
937                                    if ($beg <= $stop) {
938                                          # Denote we found a useful feature.                                          # Denote we found a useful feature.
939                                          $found = 1;                                          $found = 1;
940                                  }                                  }
941                          }                          }
942                          if ($found) {                          if ($found) {
943                                  # Here we need to record the feature and update the minimum and maximum.                                  # Here we need to record the feature and update the minima and maxima. First,
944                                  $featuresFound{$featureID} = 1;                                  # get the current entry for the specified feature.
945                                  if ($beg < $min) { $min = $beg; }                                  my ($loc1, $loc2) = (exists $featuresFound{$featureID} ? @{$featuresFound{$featureID}} :
946                                  if ($end < $min) { $min = $end; }                                                                           @initialMinMax);
947                                  if ($beg > $max) { $max = $beg; }                                  # Merge the current segment's begin and end into the feature begin and end and the
948                                  if ($end > $max) { $max = $end; }                                  # global min and max.
949                                    if ($beg < $loc1) {
950                                            $loc1 = $beg;
951                                            $min = $beg if $beg < $min;
952                                    }
953                                    if ($end > $loc2) {
954                                            $loc2 = $end;
955                                            $max = $end if $end > $max;
956                                    }
957                                    # Store the entry back into the hash table.
958                                    $featuresFound{$featureID} = [$loc1, $loc2];
959                          }                          }
960                  }                  }
961          }          }
962          # Compute a list of the IDs for the features found.          # Now we must compute the list of the IDs for the features found. We start with a list
963          my @list = (sort (keys %featuresFound));          # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
964            # but the result of the sort will be the same.)
965            my @list = map { [$featuresFound{$_}->[0] + $featuresFound{$_}->[1], $_] } keys %featuresFound;
966            # Now we sort by midpoint and yank out the feature IDs.
967            my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
968          # Return it along with the min and max.          # Return it along with the min and max.
969          return (\@list, $min, $max);          return (\@retVal, $min, $max);
970  }  }
971    
972  =head3 FType  =head3 FType
# Line 934  Line 989 
989  =back  =back
990    
991  =cut  =cut
992    #: Return Type $;
993  sub FType {  sub FType {
994          # Get the parameters.          # Get the parameters.
995          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
996          # Get the specified feature's type.          # Get the specified feature's type.
997          my ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(feature-type)']);          my ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(feature-type)']);
998          # Return the result.          # Return the result.
# Line 963  Line 1017 
1017    
1018  * B<featureID> ID of the relevant feature.  * B<featureID> ID of the relevant feature.
1019    
1020  * B<timeStamp> time the annotation was made.  * B<timeStamp> time the annotation was made, in user-friendly format.
1021    
1022  * B<user> ID of the user who made the annotation  * B<user> ID of the user who made the annotation
1023    
# Line 972  Line 1026 
1026  =back  =back
1027    
1028  =cut  =cut
1029    #: Return Type @%;
1030  sub FeatureAnnotations {  sub FeatureAnnotations {
1031          # Get the parameters.          # Get the parameters.
1032          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1033          # Create a query to get the feature's annotations and the associated users.          # Create a query to get the feature's annotations and the associated users.
1034          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1035                                                     "IsTargetOfAnnotation(from-link) = ?", [$featureID]);                                                     "IsTargetOfAnnotation(from-link) = ?", [$featureID]);
# Line 990  Line 1043 
1043                                                                   'Annotation(time)', 'MadeAnnotation(from-link)',                                                                   'Annotation(time)', 'MadeAnnotation(from-link)',
1044                                                                   'Annotation(annotation)']);                                                                   'Annotation(annotation)']);
1045                  # Assemble them into a hash.                  # Assemble them into a hash.
1046                  my $annotationHash = { featureID => $featureID, timeStamp => $timeStamp,          my $annotationHash = { featureID => $featureID,
1047                                   timeStamp => FriendlyTimestamp($timeStamp),
1048                                                             user => $user, text => $text };                                                             user => $user, text => $text };
1049                  # Add it to the return list.                  # Add it to the return list.
1050                  push @retVal, $annotationHash;                  push @retVal, $annotationHash;
# Line 1004  Line 1058 
1058  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>
1059    
1060  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
1061  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,
1062  It has the format "XXXX\nset XXXX function to\nYYYYY". In this instance, XXXX is the user ID  Functional assignments are described in the L</ParseAssignment> function. Its worth noting that
1063  and YYYYY is the functional assignment text. Its worth noting that we cannot filter on the content  we cannot filter on the content of the annotation itself because it's a text field; however,
1064  of the annotation itself because it's a text field; however, this is not a big problem because most  this is not a big problem because most features only have a small number of annotations.
1065  features only have a small number of annotations.  Finally, if a single user has multiple functional assignments, we will only keep the most
1066    recent one.
1067    
1068  =over 4  =over 4
1069    
# Line 1016  Line 1071 
1071    
1072  ID of the feature whose functional assignments are desired.  ID of the feature whose functional assignments are desired.
1073    
1074    =item RETURN
1075    
1076    Returns a hash mapping the functional assignment IDs to user IDs.
1077    
1078  =back  =back
1079    
1080  =cut  =cut
1081    #: Return Type %;
1082  sub AllFunctionsOf {  sub AllFunctionsOf {
1083          # Get the parameters.          # Get the parameters.
1084          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1085          # Get all of the feature's annotations.          # Get all of the feature's annotations.
1086          my @query = $self->GetFlat(['IsTargetOfAnnotation', 'Annotation'],      my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation'],
1087                                                      "IsTargetOfAnnotation(from-link) = ?",                                                      "IsTargetOfAnnotation(from-link) = ?",
1088                                                          [$featureID], 'Annotation(annotation)');                              [$featureID], ['Annotation(time)', 'Annotation(annotation)']);
1089          # Declare the return hash.          # Declare the return hash.
1090          my %retVal;          my %retVal;
1091        # Declare a hash for insuring we only make one assignment per user.
1092        my %timeHash = ();
1093        # Now we sort the assignments by timestamp in reverse.
1094        my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query;
1095          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1096          for my $text (@query) {      for my $annotation (@sortedQuery) {
1097            # Get the annotation fields.
1098            my ($timeStamp, $text) = @{$annotation};
1099                  # Check to see if this is a functional assignment.                  # Check to see if this is a functional assignment.
1100                  my ($user, $function) = ParseAssignment($text);                  my ($user, $function) = _ParseAssignment($text);
1101                  if ($user) {          if ($user && ! exists $timeHash{$user}) {
1102                          # Here it is, so stuff it in the return hash.              # Here it is a functional assignment and there has been no
1103                # previous assignment for this user, so we stuff it in the
1104                # return hash.
1105                          $retVal{$function} = $user;                          $retVal{$function} = $user;
1106                # Insure we don't assign to this user again.
1107                $timeHash{$user} = 1;
1108                  }                  }
1109          }          }
1110          # Return the hash of assignments found.          # Return the hash of assignments found.
# Line 1047  Line 1115 
1115    
1116  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>
1117    
1118  Return the most recently-determined functional assignment of a particular feature. A functional  Return the most recently-determined functional assignment of a particular feature.
1119  assignment is a type of annotation. It has the format "XXXX\nset XXXX function to\nYYYYY". In this  
1120  instance, XXXX is the user ID and YYYYY is the functional assignment text. Its worth noting that  The functional assignment is handled differently depending on the type of feature. If
1121  we cannot filter on the content of the annotation itself because it's a text field; however, this  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional
1122  is not a big problem because most features only have a small number of annotations.  assignment is a type of annotation. The format of an assignment is described in
1123    L</ParseLocation>. Its worth noting that we cannot filter on the content of the
1124    annotation itself because it's a text field; however, this is not a big problem because
1125    most features only have a small number of annotations.
1126    
1127    Each user has an associated list of trusted users. The assignment returned will be the most
1128    recent one by at least one of the trusted users. If no trusted user list is available, then
1129    the specified user and FIG are considered trusted. If the user ID is omitted, only FIG
1130    is trusted.
1131    
1132    If the feature is B<not> identified by a FIG ID, then the functional assignment
1133    information is taken from the B<ExternalAliasFunc> table. If the table does
1134    not contain an entry for the feature, an undefined value is returned.
1135    
1136  =over 4  =over 4
1137    
# Line 1061  Line 1141 
1141    
1142  =item userID (optional)  =item userID (optional)
1143    
1144  ID of the user whose function determination is desired. If omitted, C<FIG> is assumed.  ID of the user whose function determination is desired. If omitted, only the latest
1145    C<FIG> assignment will be returned.
1146    
1147  =item RETURN  =item RETURN
1148    
# Line 1070  Line 1151 
1151  =back  =back
1152    
1153  =cut  =cut
1154    #: Return Type $;
1155  sub FunctionOf {  sub FunctionOf {
1156          # Get the parameters.          # Get the parameters.
1157          my $self = shift @_;          my ($self, $featureID, $userID) = @_;
1158          my ($featureID, $userID) = @_;      # Declare the return value.
         if (!$userID) { $userID = 'FIG'; }  
         # Build a query for all of the feature's annotation, sorted by date.  
         my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],  
                                                     "IsTargetOfAnnotation(from-link) = ?", [$featureID]);  
         # Declare the return value. We'll set this to the most recent annotation for the  
         # specified user.  
1159          my $retVal;          my $retVal;
1160        # Determine the ID type.
1161        if ($featureID =~ m/^fig\|/) {
1162            # Here we have a FIG feature ID. We must build the list of trusted
1163            # users.
1164            my %trusteeTable = ();
1165            # Check the user ID.
1166            if (!$userID) {
1167                # No user ID, so only FIG is trusted.
1168                $trusteeTable{FIG} = 1;
1169            } else {
1170                # Add this user's ID.
1171                $trusteeTable{$userID} = 1;
1172                # Look for the trusted users in the database.
1173                my @trustees = $self->GetFlat(['IsTrustedBy'], 'IsTrustedBy(from-link) = ?', [$userID], 'IsTrustedBy(to-link)');
1174                if (! @trustees) {
1175                    # None were found, so build a default list.
1176                    $trusteeTable{FIG} = 1;
1177                } else {
1178                    # Otherwise, put all the trustees in.
1179                    for my $trustee (@trustees) {
1180                        $trusteeTable{$trustee} = 1;
1181                    }
1182                }
1183            }
1184            # Build a query for all of the feature's annotations, sorted by date.
1185            my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],
1186                                   "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1187                                   [$featureID]);
1188          my $timeSelected = 0;          my $timeSelected = 0;
1189          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1190          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1191                  # Get the annotation text.                  # Get the annotation text.
1192                  my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);                  my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);
1193                  # Check to see if this is a functional assignment for the desired user.              # Check to see if this is a functional assignment for a trusted user.
1194                  my ($user, $type, $function) = split(/\n/, $text);              my ($user, $function) = _ParseAssignment($text);
1195                  if ($type =~ m/^set $userID function to$/i) {              if ($user) {
1196                          # Here it is, so we check the time and save the assignment value.                  # Here it is a functional assignment. Check the time and the user
1197                          if ($time > $timeSelected) {                  # name. The time must be recent and the user must be trusted.
1198                    if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {
1199                                  $retVal = $function;                                  $retVal = $function;
1200                                  $timeSelected = $time;                                  $timeSelected = $time;
1201                          }                          }
1202                  }                  }
1203          }          }
1204        } else {
1205            # Here we have a non-FIG feature ID. In this case the user ID does not
1206            # matter. We simply get the information from the External Alias Function
1207            # table.
1208            ($retVal) = $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);
1209        }
1210          # Return the assignment found.          # Return the assignment found.
1211          return $retVal;          return $retVal;
1212  }  }
# Line 1126  Line 1236 
1236  =back  =back
1237    
1238  =cut  =cut
1239    #: Return Type %;
1240  sub BBHList {  sub BBHList {
1241          # Get the parameters.          # Get the parameters.
1242          my $self = shift @_;          my ($self, $genomeID, $featureList) = @_;
         my ($genomeID, $featureList) = @_;  
1243          # Create the return structure.          # Create the return structure.
1244          my %retVal = ();          my %retVal = ();
1245          # Loop through the incoming features.          # Loop through the incoming features.
# Line 1170  Line 1279 
1279  =back  =back
1280    
1281  =cut  =cut
1282    #: Return Type @;
1283  sub FeatureAliases {  sub FeatureAliases {
1284          # Get the parameters.          # Get the parameters.
1285          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1286          # Get the desired feature's aliases          # Get the desired feature's aliases
1287          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);
1288          # Return the result.          # Return the result.
# Line 1201  Line 1309 
1309  =back  =back
1310    
1311  =cut  =cut
1312    #: Return Type $;
1313  sub GenomeOf {  sub GenomeOf {
1314          # Get the parameters.          # Get the parameters.
1315          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1316          # Create a query to find the genome associated with the feature.          # Create a query to find the genome associated with the feature.
1317          my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);          my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);
1318          # Declare the return value.          # Declare the return value.
# Line 1238  Line 1345 
1345  =back  =back
1346    
1347  =cut  =cut
1348    #: Return Type %;
1349  sub CoupledFeatures {  sub CoupledFeatures {
1350          # Get the parameters.          # Get the parameters.
1351          my $self = shift @_;          my ($self, $featureID) = @_;
1352          my ($featureID) = @_;          # Create a query to retrieve the functionally-coupled features.
1353          # Create a query to retrieve the functionally-coupled features. Note that we depend on the          my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1354          # fact that the functional coupling is physically paired. If (A,B) is in the database, then                                                     "ParticipatesInCoupling(from-link) = ?", [$featureID]);
         # (B,A) will also be found.  
         my $query = $self->Get(['IsClusteredOnChromosomeWith'],  
                                                    "IsClusteredOnChromosomeWith(from-link) = ?", [$featureID]);  
1355          # This value will be set to TRUE if we find at least one coupled feature.          # This value will be set to TRUE if we find at least one coupled feature.
1356          my $found = 0;          my $found = 0;
1357          # Create the return hash.          # Create the return hash.
1358          my %retVal = ();          my %retVal = ();
1359          # Retrieve the relationship records and store them in the hash.          # Retrieve the relationship records and store them in the hash.
1360          while (my $clustering = $query->Fetch()) {          while (my $clustering = $query->Fetch()) {
1361                  my ($otherFeatureID, $score) = $clustering->Values(['IsClusteredOnChromosomeWith(to-link)',                  # Get the ID and score of the coupling.
1362                                                                      'IsClusteredOnChromosomeWith(score)']);                  my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1363                                                                                    'Coupling(score)']);
1364                    # The coupling ID contains the two feature IDs separated by a space. We use
1365                    # this information to find the ID of the other feature.
1366                    my ($fid1, $fid2) = split / /, $couplingID;
1367                    my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);
1368                    # Attach the other feature's score to its ID.
1369                  $retVal{$otherFeatureID} = $score;                  $retVal{$otherFeatureID} = $score;
1370                  $found = 1;                  $found = 1;
1371          }          }
# Line 1275  Line 1385 
1385  Return the list of supported entity types.  Return the list of supported entity types.
1386    
1387  =cut  =cut
1388    #: Return Type @;
1389  sub GetEntityTypes {  sub GetEntityTypes {
1390          # Get the parameters.          # Get the parameters.
1391          my $self = shift @_;          my ($self) = @_;
1392          # Get the underlying database object.          # Get the underlying database object.
1393          my $erdb = $self->{_erdb};          my $erdb = $self->{_erdb};
1394          # Get its entity type list.          # Get its entity type list.
# Line 1310  Line 1420 
1420  =back  =back
1421    
1422  =cut  =cut
1423    #: Return Type %;
1424  sub ReadFasta {  sub ReadFasta {
1425          # Get the parameters.          # Get the parameters.
1426          my ($fileName, $prefix) = @_;          my ($fileName, $prefix) = @_;
# Line 1329  Line 1439 
1439                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {
1440                          # Here we have a new header. Store the current sequence if we have one.                          # Here we have a new header. Store the current sequence if we have one.
1441                          if ($id) {                          if ($id) {
1442                                  $retVal{$id} = $sequence;                                  $retVal{$id} = uc $sequence;
1443                          }                          }
1444                          # Clear the sequence accumulator and save the new ID.                          # Clear the sequence accumulator and save the new ID.
1445                          ($id, $sequence) = ("$prefix$1", "");                          ($id, $sequence) = ("$prefix$1", "");
1446                  } else {                  } else {
1447                          # Here we have a data line, so we add it to the sequence accumulator.                          # Here we have a data line, so we add it to the sequence accumulator.
1448                          # First, we get the actual data out.                          # First, we get the actual data out. Note that we normalize to upper
1449                            # case.
1450                          $line =~ /^\s*(.*?)(\s|\n)/;                          $line =~ /^\s*(.*?)(\s|\n)/;
1451                          $sequence .= $1;                          $sequence .= $1;
1452                  }                  }
1453          }          }
1454          # Flush out the last sequence (if any).          # Flush out the last sequence (if any).
1455          if ($sequence) {          if ($sequence) {
1456                  $retVal {$id} = $sequence;                  $retVal{$id} = uc $sequence;
1457          }          }
1458            # Close the file.
1459            close FASTAFILE;
1460          # Return the hash constructed from the file.          # Return the hash constructed from the file.
1461          return %retVal;          return %retVal;
1462  }  }
# Line 1354  Line 1467 
1467    
1468  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
1469  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
1470  gene. The old format is I<contig>_I<beg>_I<end>.  gene. The old format is I<contig>_I<beg>_I<end>. If a feature is in the new format already,
1471    it will not be changed; otherwise, it will be converted. This method can also be used to
1472    perform the reverse task-- insuring that all the locations are in the old format.
1473    
1474  =over 4  =over 4
1475    
# Line 1378  Line 1493 
1493  =back  =back
1494    
1495  =cut  =cut
1496    #: Return Type @;
1497  sub FormatLocations {  sub FormatLocations {
1498          # Get the parameters.          # Get the parameters.
1499          my $self = shift @_;          my ($self, $prefix, $locations, $oldFormat) = @_;
         my ($prefix, $locations, $oldFormat) = @_;  
1500          # Create the return list.          # Create the return list.
1501          my @retVal = ();          my @retVal = ();
1502          # Check to see if any locations were passed in.          # Check to see if any locations were passed in.
1503          if ($locations eq '') {          if ($locations eq '') {
1504              confess "No locations specified.";              Confess("No locations specified.");
1505          } else {          } else {
1506                  # Loop through the locations, converting them to the new format.                  # Loop through the locations, converting them to the new format.
1507                  for my $location (@{$locations}) {                  for my $location (@{$locations}) {
# Line 1422  Line 1536 
1536    
1537  sub DumpData {  sub DumpData {
1538          # Get the parameters.          # Get the parameters.
1539          my $self = shift @_;          my ($self) = @_;
1540          # Get the data directory name.          # Get the data directory name.
1541          my $outputDirectory = $self->{_options}->{dataDir};          my $outputDirectory = $self->{_options}->{dataDir};
1542          # Dump the relations.          # Dump the relations.
# Line 1436  Line 1550 
1550  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
1551    
1552  =cut  =cut
1553    #: Return Type $;
1554  sub XMLFileName {  sub XMLFileName {
1555          my $self = shift @_;          my ($self) = @_;
1556          return $self->{_xmlName};          return $self->{_xmlName};
1557  }  }
1558    
# Line 1473  Line 1587 
1587  =back  =back
1588    
1589  =cut  =cut
1590    #: Return Type ;
1591  sub Insert {  sub Insert {
1592          # Get the parameters.          # Get the parameters.
1593          my $self = shift @_;          my ($self, $objectType, $fieldHash) = @_;
         my ($objectType, $fieldHash) = @_;  
1594          # Call the underlying method.          # Call the underlying method.
1595          $self->{_erdb}->InsertObject($objectType, $fieldHash);          $self->{_erdb}->InsertObject($objectType, $fieldHash);
1596  }  }
# Line 1515  Line 1628 
1628  =back  =back
1629    
1630  =cut  =cut
1631    #: Return Type $;
1632  sub Annotate {  sub Annotate {
1633          # Get the parameters.          # Get the parameters.
1634          my $self = shift @_;          my ($self, $fid, $timestamp, $user, $text) = @_;
         my ($fid, $timestamp, $user, $text) = @_;  
1635          # Create the annotation ID.          # Create the annotation ID.
1636          my $aid = "$fid:$timestamp";          my $aid = "$fid:$timestamp";
1637          # Insert the Annotation object.          # Insert the Annotation object.
# Line 1539  Line 1651 
1651    
1652  =head3 AssignFunction  =head3 AssignFunction
1653    
1654  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function); >>  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>
1655    
1656  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
1657  format is "XXXX\nset XXXX function to\nYYYYY" where XXXX is the feature type and YYYY is the functional  format is described in L</ParseAssignment>.
 assignment text.  
1658    
1659  =over 4  =over 4
1660    
# Line 1553  Line 1664 
1664    
1665  =item user  =item user
1666    
1667  Name of the user making the assignment. This is frequently a group name, like C<kegg> or C<fig>.  Name of the user group making the assignment, such as C<kegg> or C<fig>.
1668    
1669  =item function  =item function
1670    
1671  Text of the function being assigned.  Text of the function being assigned.
1672    
1673    =item assigningUser (optional)
1674    
1675    Name of the individual user making the assignment. If omitted, defaults to the user group.
1676    
1677  =item RETURN  =item RETURN
1678    
1679  Returns 1 if successful, 0 if an error occurred.  Returns 1 if successful, 0 if an error occurred.
# Line 1566  Line 1681 
1681  =back  =back
1682    
1683  =cut  =cut
1684    #: Return Type $;
1685  sub AssignFunction {  sub AssignFunction {
1686          # Get the parameters.          # Get the parameters.
1687          my $self = shift @_;          my ($self, $featureID, $user, $function, $assigningUser) = @_;
1688          my ($featureID, $user, $function) = @_;      # Default the assigning user.
1689        if (! $assigningUser) {
1690            $assigningUser = $user;
1691        }
1692          # Create an annotation string from the parameters.          # Create an annotation string from the parameters.
1693          my $annotationText = "$user\nset $user function to\n$function";          my $annotationText = "$assigningUser\nset $user function to\n$function";
1694          # Get the current time.          # Get the current time.
1695          my $now = time;          my $now = time;
1696          # Declare the return variable.          # Declare the return variable.
# Line 1614  Line 1732 
1732  =back  =back
1733    
1734  =cut  =cut
1735    #: Return Type @;
1736  sub FeaturesByAlias {  sub FeaturesByAlias {
1737          # Get the parameters.          # Get the parameters.
1738          my $self = shift @_;          my ($self, $alias) = @_;
         my ($alias) = @_;  
1739          # Declare the return variable.          # Declare the return variable.
1740          my @retVal = ();          my @retVal = ();
1741          # Parse the alias.          # Parse the alias.
# Line 1657  Line 1774 
1774  =back  =back
1775    
1776  =cut  =cut
1777    #: Return Type $;
1778  sub Exists {  sub Exists {
1779          # Get the parameters.          # Get the parameters.
1780          my $self = shift @_;          my ($self, $entityName, $entityID) = @_;
         my ($entityName, $entityID) = @_;  
1781          # Check for the entity instance.          # Check for the entity instance.
1782          my $testInstance = $self->GetEntity($entityName, $entityID);          my $testInstance = $self->GetEntity($entityName, $entityID);
1783          # Return an existence indicator.          # Return an existence indicator.
# Line 1688  Line 1804 
1804  =back  =back
1805    
1806  =cut  =cut
1807    #: Return Type $;
1808  sub FeatureTranslation {  sub FeatureTranslation {
1809          # Get the parameters.          # Get the parameters.
1810          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1811          # Get the specified feature's translation.          # Get the specified feature's translation.
1812          my ($retVal) = $self->GetEntityValues("Feature", $featureID, ['Feature(translation)']);          my ($retVal) = $self->GetEntityValues("Feature", $featureID, ['Feature(translation)']);
1813          return $retVal;          return $retVal;
# Line 1721  Line 1836 
1836  =back  =back
1837    
1838  =cut  =cut
1839    #: Return Type @;
1840  sub Taxonomy {  sub Taxonomy {
1841          # Get the parameters.          # Get the parameters.
1842          my $self = shift @_;          my ($self, $genome) = @_;
         my ($genome) = @_;  
1843          # Find the specified genome's taxonomy string.          # Find the specified genome's taxonomy string.
1844          my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);          my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);
1845          # Declare the return variable.          # Declare the return variable.
# Line 1765  Line 1879 
1879  =back  =back
1880    
1881  =cut  =cut
1882    #: Return Type $;
1883  sub CrudeDistance {  sub CrudeDistance {
1884          # Get the parameters.          # Get the parameters.
1885          my $self = shift @_;          my ($self, $genome1, $genome2) = @_;
         my ($genome1, $genome2) = @_;  
1886          # Insure that the distance is commutative by sorting the genome IDs.          # Insure that the distance is commutative by sorting the genome IDs.
1887          my ($genomeA, $genomeB);          my ($genomeA, $genomeB);
1888          if ($genome2 < $genome2) {          if ($genome2 < $genome2) {
# Line 1813  Line 1926 
1926  =back  =back
1927    
1928  =cut  =cut
1929    #: Return Type $;
1930  sub RoleName {  sub RoleName {
1931          # Get the parameters.          # Get the parameters.
1932          my $self = shift @_;          my ($self, $roleID) = @_;
         my ($roleID) = @_;  
1933          # Get the specified role's name.          # Get the specified role's name.
1934          my ($retVal) = $self->GetEntityValues('Role', $roleID, ['Role(name)']);          my ($retVal) = $self->GetEntityValues('Role', $roleID, ['Role(name)']);
1935          # Use the ID if the role has no name.          # Use the ID if the role has no name.
# Line 1847  Line 1959 
1959  =back  =back
1960    
1961  =cut  =cut
1962    #: Return Type @;
1963  sub RoleDiagrams {  sub RoleDiagrams {
1964          # Get the parameters.          # Get the parameters.
1965          my $self = shift @_;          my ($self, $roleID) = @_;
         my ($roleID) = @_;  
1966          # Query for the diagrams.          # Query for the diagrams.
1967          my @retVal = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],          my @retVal = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],
1968                                                                  'RoleOccursIn(to-link)');                                                                  'RoleOccursIn(to-link)');
# Line 1885  Line 1996 
1996  =back  =back
1997    
1998  =cut  =cut
1999    #: Return Type @@;
2000  sub FeatureProperties {  sub FeatureProperties {
2001          # Get the parameters.          # Get the parameters.
2002          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2003          # Get the properties.          # Get the properties.
2004          my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],          my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],
2005                                                          ['Property(property-name)', 'Property(property-value)',                                                          ['Property(property-name)', 'Property(property-value)',
# Line 1917  Line 2027 
2027  =back  =back
2028    
2029  =cut  =cut
2030    #: Return Type $;
2031  sub DiagramName {  sub DiagramName {
2032          # Get the parameters.          # Get the parameters.
2033          my $self = shift @_;          my ($self, $diagramID) = @_;
         my ($diagramID) = @_;  
2034          # Get the specified diagram's name and return it.          # Get the specified diagram's name and return it.
2035          my ($retVal) = $self->GetEntityValues('Diagram', $diagramID, ['Diagram(name)']);          my ($retVal) = $self->GetEntityValues('Diagram', $diagramID, ['Diagram(name)']);
2036          return $retVal;          return $retVal;
# Line 1950  Line 2059 
2059  =back  =back
2060    
2061  =cut  =cut
2062    #: Return Type @;
2063  sub MergedAnnotations {  sub MergedAnnotations {
2064          # Get the parameters.          # Get the parameters.
2065          my $self = shift @_;          my ($self, $list) = @_;
         my ($list) = @_;  
2066          # Create a list to hold the annotation tuples found.          # Create a list to hold the annotation tuples found.
2067          my @tuples = ();          my @tuples = ();
2068          # Loop through the features in the input list.          # Loop through the features in the input list.
# Line 1969  Line 2077 
2077          }          }
2078          # Sort the result list by timestamp.          # Sort the result list by timestamp.
2079          my @retVal = sort { $a->[1] <=> $b->[1] } @tuples;          my @retVal = sort { $a->[1] <=> $b->[1] } @tuples;
2080        # Loop through and make the time stamps friendly.
2081        for my $tuple (@retVal) {
2082            $tuple->[1] = FriendlyTimestamp($tuple->[1]);
2083        }
2084          # Return the sorted list.          # Return the sorted list.
2085          return @retVal;          return @retVal;
2086  }  }
# Line 1995  Line 2107 
2107  =back  =back
2108    
2109  =cut  =cut
2110    #: Return Type @;
2111  sub RoleNeighbors {  sub RoleNeighbors {
2112          # Get the parameters.          # Get the parameters.
2113          my $self = shift @_;          my ($self, $roleID) = @_;
         my ($roleID) = @_;  
2114          # Get all the diagrams containing this role.          # Get all the diagrams containing this role.
2115          my @diagrams = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],          my @diagrams = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],
2116                                                                    'RoleOccursIn(to-link)');                                                                    'RoleOccursIn(to-link)');
# Line 2038  Line 2149 
2149  =back  =back
2150    
2151  =cut  =cut
2152    #: Return Type @;
2153  sub FeatureLinks {  sub FeatureLinks {
2154          # Get the parameters.          # Get the parameters.
2155          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2156          # Get the feature's links.          # Get the feature's links.
2157          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(link)']);          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(link)']);
2158          # Return the feature's links.          # Return the feature's links.
# Line 2069  Line 2179 
2179  =back  =back
2180    
2181  =cut  =cut
2182    #: Return Type %;
2183  sub SubsystemsOf {  sub SubsystemsOf {
2184          # Get the parameters.          # Get the parameters.
2185          my $self = shift @_;          my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2186          # Use the SSCell to connect features to subsystems.          # Use the SSCell to connect features to subsystems.
2187          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],
2188                                                                          "ContainsFeature(to-link) = ?", [$featureID],                                                                          "ContainsFeature(to-link) = ?", [$featureID],
# Line 2118  Line 2227 
2227  =back  =back
2228    
2229  =cut  =cut
2230    #: Return Type @;
2231  sub RelatedFeatures {  sub RelatedFeatures {
2232          # Get the parameters.          # Get the parameters.
2233          my $self = shift @_;          my ($self, $featureID, $function, $userID) = @_;
         my ($featureID, $function, $userID) = @_;  
2234          # 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.
2235          my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],          my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],
2236                                                                           "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],                                                                           "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],
# Line 2167  Line 2275 
2275  =back  =back
2276    
2277  =cut  =cut
2278    #: Return Type @;
2279  sub TaxonomySort {  sub TaxonomySort {
2280          # Get the parameters.          # Get the parameters.
2281          my $self = shift @_;          my ($self, $featureIDs) = @_;
         my ($featureIDs) = @_;  
2282          # Create the working hash table.          # Create the working hash table.
2283          my %hashBuffer = ();          my %hashBuffer = ();
2284          # Loop through the features.          # Loop through the features.
# Line 2180  Line 2287 
2287                  my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",                  my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
2288                                                                                  [$fid], 'Genome(taxonomy)');                                                                                  [$fid], 'Genome(taxonomy)');
2289                  # Add this feature to the hash buffer.                  # Add this feature to the hash buffer.
2290                  if (exists $hashBuffer{$taxonomy}) {          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);
                         push @{$hashBuffer{$taxonomy}}, $fid;  
                 } else {  
                         $hashBuffer{$taxonomy} = [$fid];  
                 }  
2291          }          }
2292          # Sort the keys and get the elements.          # Sort the keys and get the elements.
2293          my @retVal = ();          my @retVal = ();
# Line 2250  Line 2353 
2353  =back  =back
2354    
2355  =cut  =cut
2356    #: Return Type @@;
2357  sub GetAll {  sub GetAll {
2358          # Get the parameters.          # Get the parameters.
2359          my $self = shift @_;          my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;
2360          my ($objectNames, $filterClause, $parameterList, $fields, $count) = @_;          # Call the ERDB method.
2361          # Create the query.          my @retVal = $self->{_erdb}->GetAll($objectNames, $filterClause, $parameterList,
2362          my $query = $self->Get($objectNames, $filterClause, $parameterList);                                                                                  $fields, $count);
         # Set up a counter of the number of records read.  
         my $fetched = 0;  
         # Insure the counter has a value.  
         if (!defined $count) {  
                 $count = 0;  
         }  
         # Loop through the records returned, extracting the fields. Note that if the  
         # counter is non-zero, we stop when the number of records read hits the count.  
         my @retVal = ();  
         while (($count == 0 || $fetched < $count) && (my $row = $query->Fetch())) {  
                 my @rowData = $row->Values($fields);  
                 push @retVal, \@rowData;  
                 $fetched++;  
         }  
2363          # Return the resulting list.          # Return the resulting list.
2364          return @retVal;          return @retVal;
2365  }  }
# Line 2312  Line 2401 
2401  =back  =back
2402    
2403  =cut  =cut
2404    #: Return Type @;
2405  sub GetFlat {  sub GetFlat {
2406          # Get the parameters.          # Get the parameters.
2407          my $self = shift @_;          my ($self, $objectNames, $filterClause, $parameterList, $field) = @_;
         my ($objectNames, $filterClause, $parameterList, $field) = @_;  
2408          # Construct the query.          # Construct the query.
2409          my $query = $self->Get($objectNames, $filterClause, $parameterList);          my $query = $self->Get($objectNames, $filterClause, $parameterList);
2410          # Create the result list.          # Create the result list.
# Line 2423  Line 2511 
2511  to load the entire database.  to load the entire database.
2512    
2513  =cut  =cut
2514    #: Return Type @;
2515  sub LoadInfo {  sub LoadInfo {
2516          # Get the parameters.          # Get the parameters.
2517          my $self = shift @_;          my ($self) = @_;
2518          # Create the return list, priming it with the name of the data directory.          # Create the return list, priming it with the name of the data directory.
2519          my @retVal = ($self->{_options}->{dataDir});          my @retVal = ($self->{_options}->{dataDir});
2520          # Concatenate the table names.          # Concatenate the table names.
# Line 2460  Line 2548 
2548  =back  =back
2549    
2550  =cut  =cut
2551    #: Return Type %;
2552  sub LowBBHs {  sub LowBBHs {
2553          # Get the parsameters.          # Get the parsameters.
2554          my $self = shift @_;          my ($self, $featureID, $cutoff) = @_;
         my ($featureID, $cutoff) = @_;  
2555          # Create the return hash.          # Create the return hash.
2556          my %retVal = ();          my %retVal = ();
2557          # Create a query to get the desired BBHs.          # Create a query to get the desired BBHs.
# Line 2480  Line 2567 
2567          return %retVal;          return %retVal;
2568  }  }
2569    
2570    =head3 GetGroups
2571    
2572    C<< my %groups = $sprout->GetGroups(\@groupList); >>
2573    
2574    Return a hash mapping each group to the IDs of the genomes in the group.
2575    A list of groups may be specified, in which case only those groups will be
2576    shown. Alternatively, if no parameter is supplied, all groups will be
2577    included. Genomes that are not in any group are omitted.
2578    
2579    =cut
2580    #: Return Type %@;
2581    sub GetGroups {
2582        # Get the parameters.
2583        my ($self, $groupList) = @_;
2584        # Declare the return value.
2585        my %retVal = ();
2586        # Determine whether we are getting all the groups or just some.
2587        if (defined $groupList) {
2588            # Here we have a group list. Loop through them individually,
2589            # getting a list of the relevant genomes.
2590            for my $group (@{$groupList}) {
2591                my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",
2592                    [$group], "Genome(id)");
2593                $retVal{$group} = \@genomeIDs;
2594            }
2595        } else {
2596            # Here we need all of the groups. In this case, we run through all
2597            # of the genome records, putting each one found into the appropriate
2598            # group. Note that we use a filter clause to insure that only genomes
2599            # in groups are included in the return set.
2600            my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],
2601                                        ['Genome(id)', 'Genome(group-name)']);
2602            # Loop through the genomes found.
2603            for my $genome (@genomes) {
2604                # Pop this genome's ID off the current list.
2605                my @groups = @{$genome};
2606                my $genomeID = shift @groups;
2607                # Loop through the groups, adding the genome ID to each group's
2608                # list.
2609                for my $group (@groups) {
2610                    Tracer::AddToListMap(\%retVal, $group, $genomeID);
2611                }
2612            }
2613        }
2614        # Return the hash we just built.
2615        return %retVal;
2616    }
2617    
2618  =head2 Internal Utility Methods  =head2 Internal Utility Methods
2619    
2620  =head3 ParseAssignment  =head3 ParseAssignment
2621    
2622  Parse annotation text to determine whether or not it is a functional assignment. If it is,  Parse annotation text to determine whether or not it is a functional assignment. If it is,
2623  the user and function text will be returned as a 2-element list. If it isn't, an empty list  the user, function text, and assigning user will be returned as a 3-element list. If it
2624  will be returned.  isn't, an empty list will be returned.
2625    
2626    A functional assignment is always of the form
2627    
2628        I<XXXX>C<\nset >I<YYYY>C< function to\n>I<ZZZZZ>
2629    
2630    where I<XXXX> is the B<assigning user>, I<YYYY> is the B<user>, and I<ZZZZ> is the
2631    actual functional role. In most cases, the user and the assigning user will be the
2632    same, but that is not always the case.
2633    
2634  This is a static method.  This is a static method.
2635    
# Line 2505  Line 2648 
2648    
2649  =cut  =cut
2650    
2651  sub ParseAssignment {  sub _ParseAssignment {
2652          # Get the parameters.          # Get the parameters.
2653          my ($text) = @_;          my ($text) = @_;
2654          # Declare the return value.          # Declare the return value.
2655          my @retVal = ();          my @retVal = ();
2656          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
2657          my ($user, $type, $function) = split(/\n/, $text);          my ($user, $type, $function) = split(/\n/, $text);
2658          if ($type =~ m/^set $user function to$/i) {          if ($type =~ m/^set ([^ ]+) function to$/i) {
2659                  # Here it is, so we return the user name and function text.                  # Here it is, so we return the user name (which is in $1), the functional role text,
2660                  @retVal = ($user, $function);          # and the assigning user.
2661                    @retVal = ($1, $function, $user);
2662          }          }
2663          # Return the result list.          # Return the result list.
2664          return @retVal;          return @retVal;
2665  }  }
2666    
2667    =head3 FriendlyTimestamp
2668    
2669    Convert a time number to a user-friendly time stamp for display.
2670    
2671    This is a static method.
2672    
2673    =over 4
2674    
2675    =item timeValue
2676    
2677    Numeric time value.
2678    
2679    =item RETURN
2680    
2681    Returns a string containing the same time in user-readable format.
2682    
2683    =back
2684    
2685    =cut
2686    
2687    sub FriendlyTimestamp {
2688        my ($timeValue) = @_;
2689        my $retVal = strftime("%a %b %e %H:%M:%S %Y", localtime($timeValue));
2690        return $retVal;
2691    }
2692    
2693  1;  1;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.14

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3