[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.99, Fri Apr 27 22:21:46 2007 UTC revision 1.108, Thu Feb 14 19:13:33 2008 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
     require Exporter;  
     use ERDB;  
     @ISA = qw(Exporter ERDB);  
3      use Data::Dumper;      use Data::Dumper;
4      use strict;      use strict;
5      use DBKernel;      use DBKernel;
# Line 17  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17        use base qw(ERDB);
18    
19  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
20    
# Line 29  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 46  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 80  Line 78 
78    
79  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE
80    
81    * B<host> name of the database host
82    
83  =back  =back
84    
85  For example, the following constructor call specifies a database named I<Sprout> and a user name of  For example, the following constructor call specifies a database named I<Sprout> and a user name of
86  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
87  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
88    
89  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' });
90    
91  =cut  =cut
92    
# Line 110  Line 110 
110                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
111                                                          # database connection port                                                          # database connection port
112                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::dbsock,
113                         host         => $FIG_Config::dbhost,                         host         => $FIG_Config::sprout_host,
114                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
115                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
116                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 123  Line 123 
123      # Connect to the database.      # Connect to the database.
124      my $dbh;      my $dbh;
125      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
126            Trace("Connect data: host = $optionTable->{host}, port = $optionTable->{port}.") if T(3);
127          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
128                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
129      }      }
# Line 134  Line 135 
135      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
136      # Set up space for the group file data.      # Set up space for the group file data.
137      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
138        # Set up space for the genome hash. We use this to identify NMPDR genomes.
139        $retVal->{genomeHash} = undef;
140      # Connect to the attributes.      # Connect to the attributes.
141      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
142          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
# Line 147  Line 150 
150      return $retVal;      return $retVal;
151  }  }
152    
153    =head3 CoreGenomes
154    
155        my @genomes = $sprout->CoreGenomes($scope);
156    
157    Return the IDs of NMPDR genomes in the specified scope.
158    
159    =over 4
160    
161    =item scope
162    
163    Scope of the desired genomes. C<core> covers the original core genomes,
164    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
165    genomes in the system.
166    
167    =item RETURN
168    
169    Returns a list of the IDs for the genomes in the specified scope.
170    
171    =back
172    
173    =cut
174    
175    sub CoreGenomes {
176        # Get the parameters.
177        my ($self, $scope) = @_;
178        # Declare the return variable.
179        my @retVal = ();
180        # If we want all genomes, then this is easy.
181        if ($scope eq 'all') {
182            @retVal = $self->Genomes();
183        } else {
184            # Here we're dealing with groups. Get the hash of all the
185            # genome groups.
186            my %groups = $self->GetGroups();
187            # Loop through the groups, keeping the ones that we want.
188            for my $group (keys %groups) {
189                # Decide if we want to keep this group.
190                my $keepGroup = 0;
191                if ($scope eq 'nmpdr') {
192                    # NMPDR mode: keep all groups.
193                    $keepGroup = 1;
194                } elsif ($scope eq 'core') {
195                    # CORE mode. Only keep real core groups.
196                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
197                        $keepGroup = 1;
198                    }
199                }
200                # Add this group if we're keeping it.
201                if ($keepGroup) {
202                    push @retVal, @{$groups{$group}};
203                }
204            }
205        }
206        # Return the result.
207        return @retVal;
208    }
209    
210    =head3 SuperGroup
211    
212        my $superGroup = $sprout->SuperGroup($groupName);
213    
214    Return the name of the super-group containing the specified NMPDR genome
215    group. If no appropriate super-group can be found, an error will be
216    thrown.
217    
218    =over 4
219    
220    =item groupName
221    
222    Name of the group whose super-group is desired.
223    
224    =item RETURN
225    
226    Returns the name of the super-group containing the incoming group.
227    
228    =back
229    
230    =cut
231    
232    sub SuperGroup {
233        # Get the parameters.
234        my ($self, $groupName) = @_;
235        # Declare the return variable.
236        my $retVal;
237        # Get the group hash.
238        my %groupHash = $self->CheckGroupFile();
239        # Find the super-group genus.
240        $groupName =~ /([A-Z]\w+)/;
241        my $nameThing = $1;
242        # See if it's directly in the group hash.
243        if (exists $groupHash{$nameThing}) {
244            # Yes, then it's our result.
245            $retVal = $nameThing;
246        } else {
247            # No, so we have to search.
248            for my $superGroup (keys %groupHash) {
249                # Get this super-group's item list.
250                my $list = $groupHash{$superGroup}->{contents};
251                # Search it.
252                if (grep { $_->[0] eq $nameThing } @{$list}) {
253                    $retVal = $superGroup;
254                }
255            }
256            # Make sure we found something.
257            if (! $retVal) {
258                Confess("No super-group found for \"$groupName\".");
259            }
260        }
261        # Return the result.
262        return $retVal;
263    }
264    
265  =head3 MaxSegment  =head3 MaxSegment
266    
267  C<< my $length = $sprout->MaxSegment(); >>      my $length = $sprout->MaxSegment();
268    
269  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
270  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 166  Line 281 
281    
282  =head3 MaxSequence  =head3 MaxSequence
283    
284  C<< my $length = $sprout->MaxSequence(); >>      my $length = $sprout->MaxSequence();
285    
286  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
287  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 181  Line 296 
296    
297  =head3 Load  =head3 Load
298    
299  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
300    
301  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.
302    
# Line 221  Line 336 
336    
337  =head3 LoadUpdate  =head3 LoadUpdate
338    
339  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
340    
341  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
342  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 267  Line 382 
382              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
383          } else {          } else {
384              # Attempt to load this table.              # Attempt to load this table.
385              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
386              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
387              $retVal->Accumulate($result);              $retVal->Accumulate($result);
388          }          }
# Line 278  Line 393 
393    
394  =head3 GenomeCounts  =head3 GenomeCounts
395    
396  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>      my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
397    
398  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
399  genomes will be included in the counts.  genomes will be included in the counts.
# Line 323  Line 438 
438    
439  =head3 ContigCount  =head3 ContigCount
440    
441  C<< my $count = $sprout->ContigCount($genomeID); >>      my $count = $sprout->ContigCount($genomeID);
442    
443  Return the number of contigs for the specified genome ID.  Return the number of contigs for the specified genome ID.
444    
# Line 352  Line 467 
467    
468  =head3 GeneMenu  =head3 GeneMenu
469    
470  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>      my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected);
471    
472  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,
473  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 433  Line 548 
548    
549  =head3 Build  =head3 Build
550    
551  C<< $sprout->Build(); >>      $sprout->Build();
552    
553  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.
554  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 450  Line 565 
565    
566  =head3 Genomes  =head3 Genomes
567    
568  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
569    
570  Return a list of all the genome IDs.  Return a list of all the genome IDs.
571    
# Line 467  Line 582 
582    
583  =head3 GenusSpecies  =head3 GenusSpecies
584    
585  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
586    
587  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
588    
# Line 499  Line 614 
614    
615  =head3 FeaturesOf  =head3 FeaturesOf
616    
617  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
618    
619  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
620    
# Line 544  Line 659 
659    
660  =head3 FeatureLocation  =head3 FeatureLocation
661    
662  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
663    
664  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
665  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 573  Line 688 
688  =back  =back
689    
690  =cut  =cut
691  #: Return Type @;  
 #: Return Type $;  
692  sub FeatureLocation {  sub FeatureLocation {
693      # Get the parameters.      # Get the parameters.
694      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
695      # Create a query for the feature locations.      # Get the feature record.
696      my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",      my $object = $self->GetEntity('Feature', $featureID);
697                             [$featureID]);      Confess("Feature $featureID not found.") if ! defined($object);
698        # Get the location string.
699        my $locString = $object->PrimaryValue('Feature(location-string)');
700      # Create the return list.      # Create the return list.
701      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";  
     }  
702      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
703      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
704  }  }
705    
706  =head3 ParseLocation  =head3 ParseLocation
707    
708  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
709    
710  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
711  length.  length.
# Line 642  Line 724 
724  =back  =back
725    
726  =cut  =cut
727  #: Return Type @;  
728  sub ParseLocation {  sub ParseLocation {
729      # 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
730      # the first parameter.      # the first parameter.
# Line 669  Line 751 
751    
752  =head3 PointLocation  =head3 PointLocation
753    
754  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
755    
756  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
757  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 698  Line 780 
780  =back  =back
781    
782  =cut  =cut
783  #: Return Type $;  
784  sub PointLocation {  sub PointLocation {
785      # 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
786      # the first parameter.      # the first parameter.
# Line 721  Line 803 
803    
804  =head3 DNASeq  =head3 DNASeq
805    
806  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
807    
808  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
809  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 805  Line 887 
887    
888  =head3 AllContigs  =head3 AllContigs
889    
890  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
891    
892  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
893    
# Line 835  Line 917 
917    
918  =head3 GenomeLength  =head3 GenomeLength
919    
920  C<< my $length = $sprout->GenomeLength($genomeID); >>      my $length = $sprout->GenomeLength($genomeID);
921    
922  Return the length of the specified genome in base pairs.  Return the length of the specified genome in base pairs.
923    
# Line 870  Line 952 
952    
953  =head3 FeatureCount  =head3 FeatureCount
954    
955  C<< my $count = $sprout->FeatureCount($genomeID, $type); >>      my $count = $sprout->FeatureCount($genomeID, $type);
956    
957  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.
958    
# Line 905  Line 987 
987    
988  =head3 GenomeAssignments  =head3 GenomeAssignments
989    
990  C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>      my $fidHash = $sprout->GenomeAssignments($genomeID);
991    
992  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
993  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 948  Line 1030 
1030    
1031  =head3 ContigLength  =head3 ContigLength
1032    
1033  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->ContigLength($contigID);
1034    
1035  Compute the length of a contig.  Compute the length of a contig.
1036    
# Line 987  Line 1069 
1069    
1070  =head3 ClusterPEGs  =head3 ClusterPEGs
1071    
1072  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
1073    
1074  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
1075  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
1076  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
1077  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
1078  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
1079  sequence.  appear in the output sequence.
1080    
1081  =over 4  =over 4
1082    
# Line 1035  Line 1117 
1117    
1118  =head3 GenesInRegion  =head3 GenesInRegion
1119    
1120  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1121    
1122  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1123    
# Line 1064  Line 1146 
1146  =back  =back
1147    
1148  =cut  =cut
1149  #: Return Type @@;  
1150  sub GenesInRegion {  sub GenesInRegion {
1151      # Get the parameters.      # Get the parameters.
1152      my ($self, $contigID, $start, $stop) = @_;      my ($self, $contigID, $start, $stop) = @_;
1153      # Get the maximum segment length.      # Get the maximum segment length.
1154      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 = ();  
1155      # Prime the values we'll use for the returned beginning and end.      # Prime the values we'll use for the returned beginning and end.
1156      my @initialMinMax = ($self->ContigLength($contigID), 0);      my @initialMinMax = ($self->ContigLength($contigID), 0);
1157      my ($min, $max) = @initialMinMax;      my ($min, $max) = @initialMinMax;
1158      # Create a table of parameters for each query. Each query looks for features travelling in      # Get the overlapping features.
1159        my @featureObjects = $self->GeneDataInRegion($contigID, $start, $stop);
1160        # We'l use this hash to help us track the feature IDs and sort them. The key is the
1161        # feature ID and the value is a [$left,$right] pair indicating the maximum extent
1162        # of the feature's locations.
1163        my %featureMap = ();
1164        # Loop through them to do the begin/end analysis.
1165        for my $featureObject (@featureObjects) {
1166            # Get the feature's location string. This may contain multiple actual locations.
1167            my ($locations, $fid) = $featureObject->Values([qw(Feature(location-string) Feature(id))]);
1168            my @locationSegments = split /\s*,\s*/, $locations;
1169            # Loop through the locations.
1170            for my $locationSegment (@locationSegments) {
1171                # Construct an object for the location.
1172                my $locationObject = BasicLocation->new($locationSegment);
1173                # Merge the current segment's begin and end into the min and max.
1174                my ($left, $right) = ($locationObject->Left, $locationObject->Right);
1175                my ($beg, $end);
1176                if (exists $featureMap{$fid}) {
1177                    ($beg, $end) = @{$featureMap{$fid}};
1178                    $beg = $left if $left < $beg;
1179                    $end = $right if $right > $end;
1180                } else {
1181                    ($beg, $end) = ($left, $right);
1182                }
1183                $min = $beg if $beg < $min;
1184                $max = $end if $end > $max;
1185                # Store the feature's new extent back into the hash table.
1186                $featureMap{$fid} = [$beg, $end];
1187            }
1188        }
1189        # Now we must compute the list of the IDs for the features found. We start with a list
1190        # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
1191        # but the result of the sort will be the same.)
1192        my @list = map { [$featureMap{$_}->[0] + $featureMap{$_}->[1], $_] } keys %featureMap;
1193        # Now we sort by midpoint and yank out the feature IDs.
1194        my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
1195        # Return it along with the min and max.
1196        return (\@retVal, $min, $max);
1197    }
1198    
1199    =head3 GeneDataInRegion
1200    
1201        my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1202    
1203    List the features which overlap a specified region in a contig.
1204    
1205    =over 4
1206    
1207    =item contigID
1208    
1209    ID of the contig containing the region of interest.
1210    
1211    =item start
1212    
1213    Offset of the first residue in the region of interest.
1214    
1215    =item stop
1216    
1217    Offset of the last residue in the region of interest.
1218    
1219    =item RETURN
1220    
1221    Returns a list of B<ERDBObjects> for the desired features. Each object will
1222    contain a B<Feature> record.
1223    
1224    =back
1225    
1226    =cut
1227    
1228    sub GeneDataInRegion {
1229        # Get the parameters.
1230        my ($self, $contigID, $start, $stop) = @_;
1231        # Get the maximum segment length.
1232        my $maximumSegmentLength = $self->MaxSegment;
1233        # Create a hash to receive the feature list. We use a hash so that we can eliminate
1234        # duplicates easily. The hash key will be the feature ID. The value will be the feature's
1235        # ERDBObject from the query.
1236        my %featuresFound = ();
1237        # Create a table of parameters for the queries. Each query looks for features travelling in
1238      # 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,
1239      # 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
1240      # 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 1087  Line 1243 
1243      # Loop through the query parameters.      # Loop through the query parameters.
1244      for my $parms (values %queryParms) {      for my $parms (values %queryParms) {
1245          # Create the query.          # Create the query.
1246          my $query = $self->Get(['IsLocatedIn'],          my $query = $self->Get([qw(Feature IsLocatedIn)],
1247              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",
1248              $parms);              $parms);
1249          # Loop through the feature segments found.          # Loop through the feature segments found.
1250          while (my $segment = $query->Fetch) {          while (my $segment = $query->Fetch) {
1251              # Get the data about this segment.              # Get the data about this segment.
1252              my ($featureID, $dir, $beg, $len) = $segment->Values(['IsLocatedIn(from-link)',              my ($featureID, $contig, $dir, $beg, $len) = $segment->Values([qw(IsLocatedIn(from-link)
1253                  'IsLocatedIn(dir)', 'IsLocatedIn(beg)', 'IsLocatedIn(len)']);                  IsLocatedIn(to-link) IsLocatedIn(dir) IsLocatedIn(beg) IsLocatedIn(len))]);
1254              # 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
1255              # 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
1256              # 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
1257              # length.              # length.
1258              my ($found, $end) = (0, 0);              my $loc = BasicLocation->new($contig, $beg, $dir, $len);
1259              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;  
                 }  
             }  
1260              if ($found) {              if ($found) {
1261                  # Here we need to record the feature and update the minima and maxima. First,                  # Save this feature in the result list.
1262                  # 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;  
                 }  
                 # Store the entry back into the hash table.  
                 $featuresFound{$featureID} = [$loc1, $loc2];  
1263              }              }
1264          }          }
1265      }      }
1266      # Now we must compute the list of the IDs for the features found. We start with a list      # Return the ERDB objects for the features found.
1267      # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,      return values %featuresFound;
     # 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);  
1268  }  }
1269    
1270  =head3 FType  =head3 FType
1271    
1272  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1273    
1274  Return the type of a feature.  Return the type of a feature.
1275    
# Line 1177  Line 1299 
1299    
1300  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1301    
1302  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1303    
1304  Return the annotations of a feature.  Return the annotations of a feature.
1305    
# Line 1240  Line 1362 
1362    
1363  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1364    
1365  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1366    
1367  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
1368  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 1295  Line 1417 
1417    
1418  =head3 FunctionOf  =head3 FunctionOf
1419    
1420  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1421    
1422  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1423    
# Line 1399  Line 1521 
1521    
1522  =head3 FunctionsOf  =head3 FunctionsOf
1523    
1524  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1525    
1526  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1527    
# Line 1471  Line 1593 
1593    
1594  =head3 BBHList  =head3 BBHList
1595    
1596  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1597    
1598  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
1599  on a specified target genome.  on a specified target genome.
# Line 1521  Line 1643 
1643    
1644  =head3 SimList  =head3 SimList
1645    
1646  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1647    
1648  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1649    
# Line 1557  Line 1679 
1679    
1680  =head3 IsComplete  =head3 IsComplete
1681    
1682  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1683    
1684  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1685    
# Line 1585  Line 1707 
1707      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1708      if ($genomeData) {      if ($genomeData) {
1709          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1710          ($retVal) = $genomeData->Value('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1711      }      }
1712      # Return the result.      # Return the result.
1713      return $retVal;      return $retVal;
# Line 1593  Line 1715 
1715    
1716  =head3 FeatureAliases  =head3 FeatureAliases
1717    
1718  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1719    
1720  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1721    
# Line 1616  Line 1738 
1738      # Get the parameters.      # Get the parameters.
1739      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1740      # Get the desired feature's aliases      # Get the desired feature's aliases
1741      my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);      my @retVal = $self->GetFlat(['IsAliasOf'], "IsAliasOf(to-link) = ?", [$featureID], 'IsAliasOf(from-link)');
1742      # Return the result.      # Return the result.
1743      return @retVal;      return @retVal;
1744  }  }
1745    
1746  =head3 GenomeOf  =head3 GenomeOf
1747    
1748  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1749    
1750  Return the genome that contains a specified feature or contig.  Return the genome that contains a specified feature or contig.
1751    
# Line 1645  Line 1767 
1767  sub GenomeOf {  sub GenomeOf {
1768      # Get the parameters.      # Get the parameters.
1769      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]);  
1770      # Declare the return value.      # Declare the return value.
1771      my $retVal;      my $retVal;
1772      # Get the genome ID.      # Parse the genome ID from the feature ID.
1773      if (my $relationship = $query->Fetch()) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1774          ($retVal) = $relationship->Value('HasContig(from-link)');          $retVal = $1;
1775        } else {
1776            Confess("Invalid feature ID $featureID.");
1777      }      }
1778      # Return the value found.      # Return the value found.
1779      return $retVal;      return $retVal;
# Line 1660  Line 1781 
1781    
1782  =head3 CoupledFeatures  =head3 CoupledFeatures
1783    
1784  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
1785    
1786  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
1787  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 1682  Line 1803 
1803  sub CoupledFeatures {  sub CoupledFeatures {
1804      # Get the parameters.      # Get the parameters.
1805      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1806        # Ask the coupling server for the data.
1807      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1808      # Create a query to retrieve the functionally-coupled features.      my @rawPairs = FIGRules::NetCouplingData('coupled_to', id1 => $featureID);
1809      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      Trace(scalar(@rawPairs) . " couplings returned.") if T(coupling => 3);
1810                             "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.  
1811      my %retVal = ();      my %retVal = ();
1812      # Retrieve the relationship records and store them in the hash.      for my $pair (@rawPairs) {
1813      while (my $clustering = $query->Fetch()) {          # Get the feature ID and score.
1814          # Get the ID and score of the coupling.          my ($featureID2, $score) = @{$pair};
1815          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          # Only proceed if the feature is in NMPDR.
1816                                                          'Coupling(score)']);          if ($self->_CheckFeature($featureID2)) {
1817          Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);              $retVal{$featureID2} = $score;
1818          # 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;  
1819      }      }
1820      # 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
1821      # the incoming feature as well.      # the incoming feature as well.
1822      if ($found) {      if (keys %retVal) {
1823          $retVal{$featureID} = 9999;          $retVal{$featureID} = 9999;
1824      }      }
1825      # Return the hash.      # Return the hash.
# Line 1716  Line 1828 
1828    
1829  =head3 CouplingEvidence  =head3 CouplingEvidence
1830    
1831  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
1832    
1833  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
1834    
# Line 1764  Line 1876 
1876      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
1877      # Declare the return variable.      # Declare the return variable.
1878      my @retVal = ();      my @retVal = ();
1879      # Our first task is to find out the nature of the coupling: whether or not      # Get the coupling and evidence data.
1880      # it exists, its score, and whether the features are stored in the same      my @rawData = FIGRules::NetCouplingData('coupling_evidence', id1 => $peg1, id2 => $peg2);
1881      # order as the ones coming in.      # Loop through the raw data, saving the ones that are in NMPDR genomes.
1882      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);      for my $rawTuple (@rawData) {
1883      # Only proceed if a coupling exists.          if ($self->_CheckFeature($rawTuple->[0]) && $self->_CheckFeature($rawTuple->[1])) {
1884      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);  
1885      }      }
     # Return the result.  
     return @retVal;  
 }  
   
 =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);  
1886      }      }
1887      # Return the result.      # Return the result.
1888      return ($retVal, $inverted, $score);      return @retVal;
1889  }  }
1890    
1891  =head3 GetSynonymGroup  =head3 GetSynonymGroup
1892    
1893  C<< my $id = $sprout->GetSynonymGroup($fid); >>      my $id = $sprout->GetSynonymGroup($fid);
1894    
1895  Return the synonym group name for the specified feature.  Return the synonym group name for the specified feature.
1896    
# Line 1895  Line 1929 
1929    
1930  =head3 GetBoundaries  =head3 GetBoundaries
1931    
1932  C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
1933    
1934  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
1935  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 1957  Line 1991 
1991      return ($contig, $beg, $end);      return ($contig, $beg, $end);
1992  }  }
1993    
 =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);  
 }  
   
1994  =head3 ReadFasta  =head3 ReadFasta
1995    
1996  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
1997    
1998  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
1999  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 2064  Line 2059 
2059    
2060  =head3 FormatLocations  =head3 FormatLocations
2061    
2062  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
2063    
2064  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
2065  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 2129  Line 2124 
2124    
2125  =head3 DumpData  =head3 DumpData
2126    
2127  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2128    
2129  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.
2130    
# Line 2146  Line 2141 
2141    
2142  =head3 XMLFileName  =head3 XMLFileName
2143    
2144  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2145    
2146  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2147    
# Line 2157  Line 2152 
2152      return $self->{_xmlName};      return $self->{_xmlName};
2153  }  }
2154    
2155    =head3 GetGenomeNameData
2156    
2157        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2158    
2159    Return the genus, species, and unique characterization for a genome. This
2160    is similar to L</GenusSpecies>, with the exception that it returns the
2161    values in three seperate fields.
2162    
2163    =over 4
2164    
2165    =item genomeID
2166    
2167    ID of the genome whose name data is desired.
2168    
2169    =item RETURN
2170    
2171    Returns a three-element list, consisting of the genus, species, and strain
2172    of the specified genome. If the genome is not found, an error occurs.
2173    
2174    =back
2175    
2176    =cut
2177    
2178    sub GetGenomeNameData {
2179        # Get the parameters.
2180        my ($self, $genomeID) = @_;
2181        # Get the desired values.
2182        my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>
2183                                                                [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);
2184        # Throw an error if they were not found.
2185        if (! defined $genus) {
2186            Confess("Genome $genomeID not found in database.");
2187        }
2188        # Return the results.
2189        return ($genus, $species, $strain);
2190    }
2191    
2192    =head3 GetGenomeByNameData
2193    
2194        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2195    
2196    Return a list of the IDs of the genomes with the specified genus,
2197    species, and strain. In almost every case, there will be either zero or
2198    one IDs returned; however, two or more IDs could be returned if there are
2199    multiple versions of the genome in the database.
2200    
2201    =over 4
2202    
2203    =item genus
2204    
2205    Genus of the desired genome.
2206    
2207    =item species
2208    
2209    Species of the desired genome.
2210    
2211    =item strain
2212    
2213    Strain (unique characterization) of the desired genome. This may be an empty
2214    string, in which case it is presumed that the desired genome has no strain
2215    specified.
2216    
2217    =item RETURN
2218    
2219    Returns a list of the IDs of the genomes having the specified genus, species, and
2220    strain.
2221    
2222    =back
2223    
2224    =cut
2225    
2226    sub GetGenomeByNameData {
2227        # Get the parameters.
2228        my ($self, $genus, $species, $strain) = @_;
2229        # Try to find the genomes.
2230        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2231                                    [$genus, $species, $strain], 'Genome(id)');
2232        # Return the result.
2233        return @retVal;
2234    }
2235    
2236  =head3 Insert  =head3 Insert
2237    
2238  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2239    
2240  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
2241  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 2168  Line 2244 
2244  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
2245  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>.
2246    
2247  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']});
2248    
2249  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
2250  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>.
2251    
2252  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'});
2253    
2254  =over 4  =over 4
2255    
# Line 2198  Line 2274 
2274    
2275  =head3 Annotate  =head3 Annotate
2276    
2277  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2278    
2279  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
2280  specified feature and user.  specified feature and user.
# Line 2252  Line 2328 
2328    
2329  =head3 AssignFunction  =head3 AssignFunction
2330    
2331  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2332    
2333  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
2334  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2312  Line 2388 
2388    
2389  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2390    
2391  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2392    
2393  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
2394  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 2346  Line 2422 
2422          push @retVal, $mappedAlias;          push @retVal, $mappedAlias;
2423      } else {      } else {
2424          # 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.
2425          @retVal = $self->GetFlat(['Feature'], 'Feature(alias) = ?', [$mappedAlias], 'Feature(id)');          @retVal = $self->GetFlat(['IsAliasOf'], 'IsAliasOf(from-link) = ?', [$mappedAlias], 'IsAliasOf(to-link)');
2426      }      }
2427      # Return the result.      # Return the result.
2428      return @retVal;      return @retVal;
# Line 2354  Line 2430 
2430    
2431  =head3 FeatureTranslation  =head3 FeatureTranslation
2432    
2433  C<< my $translation = $sprout->FeatureTranslation($featureID); >>      my $translation = $sprout->FeatureTranslation($featureID);
2434    
2435  Return the translation of a feature.  Return the translation of a feature.
2436    
# Line 2382  Line 2458 
2458    
2459  =head3 Taxonomy  =head3 Taxonomy
2460    
2461  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2462    
2463  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
2464  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>,
2465  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2466    
2467  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2468    
2469  =over 4  =over 4
2470    
# Line 2423  Line 2499 
2499    
2500  =head3 CrudeDistance  =head3 CrudeDistance
2501    
2502  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2503    
2504  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
2505  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 2475  Line 2551 
2551    
2552  =head3 RoleName  =head3 RoleName
2553    
2554  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2555    
2556  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
2557  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 2509  Line 2585 
2585    
2586  =head3 RoleDiagrams  =head3 RoleDiagrams
2587    
2588  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2589    
2590  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2591    
# Line 2539  Line 2615 
2615    
2616  =head3 GetProperties  =head3 GetProperties
2617    
2618  C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>      my @list = $sprout->GetProperties($fid, $key, $value, $url);
2619    
2620  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2621    
# Line 2625  Line 2701 
2701    
2702  =head3 FeatureProperties  =head3 FeatureProperties
2703    
2704  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2705    
2706  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
2707  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
# Line 2664  Line 2740 
2740    
2741  =head3 DiagramName  =head3 DiagramName
2742    
2743  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2744    
2745  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2746    
# Line 2692  Line 2768 
2768    
2769  =head3 PropertyID  =head3 PropertyID
2770    
2771  C<< my $id = $sprout->PropertyID($propName, $propValue); >>      my $id = $sprout->PropertyID($propName, $propValue);
2772    
2773  Return the ID of the specified property name and value pair, if the  Return the ID of the specified property name and value pair, if the
2774  pair exists. Only a small subset of the FIG attributes are stored as  pair exists. Only a small subset of the FIG attributes are stored as
# Line 2729  Line 2805 
2805    
2806  =head3 MergedAnnotations  =head3 MergedAnnotations
2807    
2808  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2809    
2810  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
2811  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 2778  Line 2854 
2854    
2855  =head3 RoleNeighbors  =head3 RoleNeighbors
2856    
2857  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
2858    
2859  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
2860  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 2821  Line 2897 
2897    
2898  =head3 FeatureLinks  =head3 FeatureLinks
2899    
2900  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
2901    
2902  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
2903  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 2852  Line 2928 
2928    
2929  =head3 SubsystemsOf  =head3 SubsystemsOf
2930    
2931  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
2932    
2933  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
2934  to the roles the feature performs.  to the roles the feature performs.
# Line 2900  Line 2976 
2976    
2977  =head3 SubsystemList  =head3 SubsystemList
2978    
2979  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
2980    
2981  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
2982  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2932  Line 3008 
3008    
3009  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
3010    
3011  C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>      my %featureData = $sprout->GenomeSubsystemData($genomeID);
3012    
3013  Return a hash mapping genome features to their subsystem roles.  Return a hash mapping genome features to their subsystem roles.
3014    
# Line 2992  Line 3068 
3068    
3069  =head3 RelatedFeatures  =head3 RelatedFeatures
3070    
3071  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
3072    
3073  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
3074  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 3043  Line 3119 
3119    
3120  =head3 TaxonomySort  =head3 TaxonomySort
3121    
3122  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3123    
3124  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
3125  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 3078  Line 3154 
3154          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3155                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3156          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3157          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3158      }      }
3159      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3160      my @retVal = ();      my @retVal = ();
# Line 3091  Line 3167 
3167    
3168  =head3 Protein  =head3 Protein
3169    
3170  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3171    
3172  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3173    
# Line 3177  Line 3253 
3253    
3254  =head3 LoadInfo  =head3 LoadInfo
3255    
3256  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3257    
3258  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
3259  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 3198  Line 3274 
3274    
3275  =head3 BBHMatrix  =head3 BBHMatrix
3276    
3277  C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>      my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3278    
3279  Find all the bidirectional best hits for the features of a genome in a  Find all the bidirectional best hits for the features of a genome in a
3280  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3252  Line 3328 
3328    
3329  =head3 SimMatrix  =head3 SimMatrix
3330    
3331  C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>      my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3332    
3333  Find all the similarities for the features of a genome in a  Find all the similarities for the features of a genome in a
3334  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3322  Line 3398 
3398    
3399  =head3 LowBBHs  =head3 LowBBHs
3400    
3401  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3402    
3403  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
3404  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 3366  Line 3442 
3442    
3443  =head3 Sims  =head3 Sims
3444    
3445  C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>      my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3446    
3447  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
3448  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 3383  Line 3459 
3459    
3460  =item fid  =item fid
3461    
3462  ID of the feature whose similarities are desired.  ID of the feature whose similarities are desired, or reference to a list of IDs
3463    of features whose similarities are desired.
3464    
3465  =item maxN  =item maxN
3466    
# Line 3431  Line 3508 
3508    
3509  =head3 IsAllGenomes  =head3 IsAllGenomes
3510    
3511  C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>      my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3512    
3513  Return TRUE if all genomes in the second list are represented in the first list at  Return TRUE if all genomes in the second list are represented in the first list at
3514  least one. Otherwise, return FALSE. If the second list is omitted, the first list is  least one. Otherwise, return FALSE. If the second list is omitted, the first list is
# Line 3480  Line 3557 
3557    
3558  =head3 GetGroups  =head3 GetGroups
3559    
3560  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3561    
3562  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.
3563  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 3512  Line 3589 
3589                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3590          # Loop through the genomes found.          # Loop through the genomes found.
3591          for my $genome (@genomes) {          for my $genome (@genomes) {
3592              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3593              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3594              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);  
             }  
3595          }          }
3596      }      }
3597      # Return the hash we just built.      # Return the hash we just built.
# Line 3528  Line 3600 
3600    
3601  =head3 MyGenomes  =head3 MyGenomes
3602    
3603  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3604    
3605  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3606    
# Line 3560  Line 3632 
3632    
3633  =head3 LoadFileName  =head3 LoadFileName
3634    
3635  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3636    
3637  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
3638  directory.  directory.
# Line 3601  Line 3673 
3673    
3674  =head3 DeleteGenome  =head3 DeleteGenome
3675    
3676  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3677    
3678  Delete a genome from the database.  Delete a genome from the database.
3679    
# Line 3637  Line 3709 
3709    
3710  =head3 Fix  =head3 Fix
3711    
3712  C<< my %fixedHash = Sprout::Fix(%groupHash); >>      my %fixedHash = $sprout->Fix(%groupHash);
3713    
3714  Prepare a genome group hash (like that returned by L</GetGroups> for processing.  Prepare a genome group hash (like that returned by L</GetGroups>) for processing.
3715  Groups with the same primary name will be combined. The primary name is the  The groups will be combined into the appropriate super-groups.
 first capitalized word in the group name.  
3716    
3717  =over 4  =over 4
3718    
# Line 3659  Line 3730 
3730    
3731  sub Fix {  sub Fix {
3732      # Get the parameters.      # Get the parameters.
3733      my (%groupHash) = @_;      my ($self, %groupHash) = @_;
3734      # Create the result hash.      # Create the result hash.
3735      my %retVal = ();      my %retVal = ();
3736      # Copy over the genomes.      # Copy over the genomes.
3737      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3738          # Make a safety copy of the group ID.          # Get the super-group name.
3739          my $realGroupID = $groupID;          my $realGroupID = $self->SuperGroup($groupID);
3740          # Yank the primary name.          # Append this group's genomes into the result hash
3741          if ($groupID =~ /([A-Z]\w+)/) {          # using the super-group name.
3742              $realGroupID = $1;          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
         }  
         # Append this group's genomes into the result hash.  
         Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});  
3743      }      }
3744      # Return the result hash.      # Return the result hash.
3745      return %retVal;      return %retVal;
# Line 3679  Line 3747 
3747    
3748  =head3 GroupPageName  =head3 GroupPageName
3749    
3750  C<< my $name = $sprout->GroupPageName($group); >>      my $name = $sprout->GroupPageName($group);
3751    
3752  Return the name of the page for the specified NMPDR group.  Return the name of the page for the specified NMPDR group.
3753    
# Line 3701  Line 3769 
3769  sub GroupPageName {  sub GroupPageName {
3770      # Get the parameters.      # Get the parameters.
3771      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3772      # Check for the group file data.      # Check for the group file data.
3773      if (! defined $self->{groupHash}) {      my %superTable = $self->CheckGroupFile();
         # Read the group file.  
         my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");  
         # Store it in our object.  
         $self->{groupHash} = \%groupData;  
     }  
3774      # Compute the real group name.      # Compute the real group name.
3775      my $realGroup = $group;      my $realGroup = $self->SuperGroup($group);
3776      if ($group =~ /([A-Z]\w+)/) {      # Get the associated page name.
3777          $realGroup = $1;      my $retVal = "../content/$superTable{$realGroup}->{page}";
     }  
     # Return the page name.  
     $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];  
3778      # Return the result.      # Return the result.
3779      return $retVal;      return $retVal;
3780  }  }
3781    
 =head3 ReadGroupFile  
   
 C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  
   
 Read in the data from the specified group file. The group file contains information  
 about each of the NMPDR groups.  
   
 =over 4  
   
 =item name  
3782    
3783  Name of the group.  =head3 AddProperty
   
 =item page  
   
 Name of the group's page on the web site (e.g. C<campy.php> for  
 Campylobacter)  
   
 =item genus  
   
 Genus of the group  
3784    
3785  =item species      $sprout->AddProperty($featureID, $key, @values);
3786    
3787  Species of the group, or an empty string if the group is for an entire  Add a new attribute value (Property) to a feature.
 genus. If the group contains more than one species, the species names  
 should be separated by commas.  
3788    
3789  =back  =over 4
3790    
3791  The parameters to this method are as follows  =item peg
3792    
3793  =over 4  ID of the feature to which the attribute is to be added.
3794    
3795  =item groupFile  =item key
3796    
3797  Name of the file containing the group data.  Name of the attribute (key).
3798    
3799  =item RETURN  =item values
3800    
3801  Returns a hash keyed on group name. The value of each hash  Values of the attribute.
3802    
3803  =back  =back
3804    
3805  =cut  =cut
3806    #: Return Type ;
3807  sub ReadGroupFile {  sub AddProperty {
3808      # Get the parameters.      # Get the parameters.
3809      my ($groupFileName) = @_;      my ($self, $featureID, $key, @values) = @_;
3810      # Declare the return variable.      # Add the property using the attached attributes object.
3811      my %retVal;      $self->{_ca}->AddAttribute($featureID, $key, @values);
     # Read the group file.  
     my @groupLines = Tracer::GetFile($groupFileName);  
     for my $groupLine (@groupLines) {  
         my ($name, $page, $genus, $species) = split(/\t/, $groupLine);  
         $retVal{$name} = [$page, $genus, $species];  
     }  
     # Return the result.  
     return %retVal;  
3812  }  }
3813    
3814  =head3 AddProperty  =head3 CheckGroupFile
3815    
3816  C<< my  = $sprout->AddProperty($featureID, $key, @values); >>      my %groupData = $sprout->CheckGroupFile();
3817    
3818  Add a new attribute value (Property) to a feature.  Get the group file hash. The group file hash describes the relationship
3819    between a group and the super-group to which it belongs for purposes of
3820    display. The super-group name is computed from the first capitalized word
3821    in the actual group name. For each super-group, the group file contains
3822    the page name and a list of the species expected to be in the group.
3823    Each species is specified by a genus and a species name. A species name
3824    of C<0> implies an entire genus.
3825    
3826  =over 4  This method returns a hash from super-group names to a hash reference. Each
3827    resulting hash reference contains the following fields.
3828    
3829  =item peg  =over 4
   
 ID of the feature to which the attribute is to be added.  
3830    
3831  =item key  =item page
3832    
3833  Name of the attribute (key).  The super-group's web page in the NMPDR.
3834    
3835  =item values  =item contents
3836    
3837  Values of the attribute.  A list of 2-tuples, each containing a genus name followed by a species name
3838    (or 0, indicating all species). This list indicates which organisms belong
3839    in the super-group.
3840    
3841  =back  =back
3842    
3843  =cut  =cut
3844  #: Return Type ;  
3845  sub AddProperty {  sub CheckGroupFile{
3846      # Get the parameters.      # Get the parameters.
3847      my ($self, $featureID, $key, @values) = @_;      my ($self) = @_;
3848      # Add the property using the attached attributes object.      # Check to see if we already have this hash.
3849      $self->{_ca}->AddAttribute($featureID, $key, @values);      if (! defined $self->{groupHash}) {
3850            # We don't, so we need to read it in.
3851            my %groupHash;
3852            # Read the group file.
3853            my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3854            # Loop through the list of sort-of groups.
3855            for my $groupLine (@groupLines) {
3856                my ($name, $page, @contents) = split /\t/, $groupLine;
3857                $groupHash{$name} = { page => $page,
3858                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3859                                    };
3860            }
3861            # Save the hash.
3862            $self->{groupHash} = \%groupHash;
3863        }
3864        # Return the result.
3865        return %{$self->{groupHash}};
3866  }  }
3867    
3868  =head2 Virtual Methods  =head2 Virtual Methods
3869    
3870  =head3 CleanKeywords  =head3 CleanKeywords
3871    
3872  C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>      my $cleanedString = $sprout->CleanKeywords($searchExpression);
3873    
3874  Clean up a search expression or keyword list. This involves converting the periods  Clean up a search expression or keyword list. This involves converting the periods
3875  in EC numbers to underscores, converting non-leading minus signs to underscores,  in EC numbers to underscores, converting non-leading minus signs to underscores,
# Line 3867  Line 3919 
3919    
3920  A functional assignment is always of the form  A functional assignment is always of the form
3921    
3922      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
3923        ZZZZ
3924    
3925  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,
3926  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 3920  Line 3973 
3973      return @retVal;      return @retVal;
3974  }  }
3975    
3976    =head3 _CheckFeature
3977    
3978        my $flag = $sprout->_CheckFeature($fid);
3979    
3980    Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.
3981    
3982    =over 4
3983    
3984    =item fid
3985    
3986    Feature ID to check.
3987    
3988    =item RETURN
3989    
3990    Returns TRUE if the FID is for one of the NMPDR genomes, else FALSE.
3991    
3992    =back
3993    
3994    =cut
3995    
3996    sub _CheckFeature {
3997        # Get the parameters.
3998        my ($self, $fid) = @_;
3999        # Insure we have a genome hash.
4000        if (! defined $self->{genomeHash}) {
4001            my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');
4002            $self->{genomeHash} = \%genomeHash;
4003        }
4004        # Get the feature's genome ID.
4005        my ($genomeID) = FIGRules::ParseFeatureID($fid);
4006        # Return an indicator of whether or not the genome ID is in the hash.
4007        return ($self->{genomeHash}->{$genomeID} ? 1 : 0);
4008    }
4009    
4010  =head3 FriendlyTimestamp  =head3 FriendlyTimestamp
4011    
4012  Convert a time number to a user-friendly time stamp for display.  Convert a time number to a user-friendly time stamp for display.

Legend:
Removed from v.1.99  
changed lines
  Added in v.1.108

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3