[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.1, Sun Jan 23 16:12:29 2005 UTC revision 1.59, Wed Jun 7 01:53:03 2006 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
3        require Exporter;
4        use ERDB;
5        @ISA = qw(Exporter ERDB);
6          use Data::Dumper;          use Data::Dumper;
7          use strict;          use strict;
8          use Carp;          use Carp;
# Line 7  Line 10 
10          use XML::Simple;          use XML::Simple;
11          use DBQuery;          use DBQuery;
12          use DBObject;          use DBObject;
         use ERDB;  
13          use Tracer;          use Tracer;
14          use FIGRules;          use FIGRules;
15          use Stats;          use Stats;
16        use POSIX qw(strftime);
17    
18    
19  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 31  Line 34 
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</dna_seq> 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.
38    
39  =cut  =cut
40    
41  #  #: Constructor SFXlate->new_sprout_only();
42    
43  =head2 Public Methods  =head2 Public Methods
44    
# Line 61  Line 66 
66    
67  * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)  * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)
68    
69  * B<userData> user name and password, delimited by a slash (default C<root/>)  * B<userData> user name and password, delimited by a slash (default same as SEED)
70    
71  * B<port> connection port (default C<0>)  * B<port> connection port (default C<0>)
72    
73    * B<sock> connection socket (default same as SEED)
74    
75  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)
76    
77  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)
78    
79    * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE
80    
81  =back  =back
82    
83  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
# Line 85  Line 94 
94          # Compute the options. We do this by starting with a table of defaults and overwriting with          # Compute the options. We do this by starting with a table of defaults and overwriting with
95          # the incoming data.          # the incoming data.
96          my $optionTable = Tracer::GetOptions({          my $optionTable = Tracer::GetOptions({
97                                             dbType               => 'mysql',                     # database type                         dbType       => $FIG_Config::dbms,
98                                             dataDir              => 'Data',                      # data file directory                                                          # database type
99                                             xmlFileName  => 'SproutDBD.xml', # database definition file name                         dataDir      => $FIG_Config::sproutData,
100                                             userData             => 'root/',                     # user name and password                                                          # data file directory
101                                             port                 => 0,                           # database connection port                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",
102                                                            # database definition file name
103                           userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
104                                                            # user name and password
105                           port         => $FIG_Config::dbport,
106                                                            # database connection port
107                           sock         => $FIG_Config::dbsock,
108                                             maxSegmentLength => 4500,            # maximum feature segment length                                             maxSegmentLength => 4500,            # maximum feature segment length
109                                             maxSequenceLength => 8000,           # maximum contig sequence length                                             maxSequenceLength => 8000,           # maximum contig sequence length
110                           noDBOpen     => 0,               # 1 to suppress the database open
111                                            }, $options);                                            }, $options);
112          # Get the data directory.          # Get the data directory.
113          my $dataDir = $optionTable->{dataDir};          my $dataDir = $optionTable->{dataDir};
# Line 99  Line 115 
115          $optionTable->{userData} =~ m!([^/]*)/(.*)$!;          $optionTable->{userData} =~ m!([^/]*)/(.*)$!;
116          my ($userName, $password) = ($1, $2);          my ($userName, $password) = ($1, $2);
117          # Connect to the database.          # Connect to the database.
118          my $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName, $password, $optionTable->{port});      my $dbh;
119        if (! $optionTable->{noDBOpen}) {
120            $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
121                                    $password, $optionTable->{port}, undef, $optionTable->{sock});
122        }
123          # Create the ERDB object.          # Create the ERDB object.
124          my $xmlFileName = "$optionTable->{xmlFileName}";          my $xmlFileName = "$optionTable->{xmlFileName}";
125          my $erdb = ERDB->new($dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName);
126          # Create this object.      # Add the option table and XML file name.
127          my $self = { _erdb => $erdb, _options => $optionTable, _xmlName => $xmlFileName };      $retVal->{_options} = $optionTable;
128          # Bless and return it.      $retVal->{_xmlName} = $xmlFileName;
129          bless $self;      # Return it.
130          return $self;      return $retVal;
131  }  }
132    
133  =head3 MaxSegment  =head3 MaxSegment
# Line 121  Line 141 
141  and 10999.  and 10999.
142    
143  =cut  =cut
144    #: Return Type $;
145  sub MaxSegment {  sub MaxSegment {
146          my $self = shift @_;      my ($self) = @_;
147          return $self->{_options}->{maxSegmentLength};          return $self->{_options}->{maxSegmentLength};
148  }  }
149    
# Line 136  Line 156 
156  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.
157    
158  =cut  =cut
159    #: Return Type $;
160  sub MaxSequence {  sub MaxSequence {
161          my $self = shift @_;      my ($self) = @_;
162          return $self->{_options}->{maxSequenceLength};          return $self->{_options}->{maxSequenceLength};
163  }  }
164    
165  =head3 Get  =head3 Load
   
 C<< my $query = $sprout->Get(\@objectNames, $filterClause, \@parameterList); >>  
   
 This method allows a general query against the Sprout data using a specified filter clause.  
   
 The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each  
 field name represented in the form B<I<objectName>(I<fieldName>)>. For example, the  
 following call requests all B<Genome> objects for the genus specified in the variable  
 $genus.  
   
 C<< $query = $sprout->Get(['Genome'], "Genome(genus) = ?", [$genus]); >>  
   
 The WHERE clause contains a single question mark, so there is a single additional  
 parameter representing the parameter value. It would also be possible to code  
   
 C<< $query = $sprout->Get(['Genome'], "Genome(genus) = \'$genus\'"); >>  
   
 however, this version of the call would generate a syntax error if there were any quote  
 characters inside the variable C<$genus>.  
   
 The use of the strange parenthesized notation for field names enables us to distinguish  
 hyphens contained within field names from minus signs that participate in the computation  
 of the WHERE clause. All of the methods that manipulate fields will use this same notation.  
   
 It is possible to specify multiple entity and relationship names in order to retrieve more than  
 one object's data at the same time, which allows highly complex joined queries. For example,  
   
 C<< $query = $sprout->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", [$genus]); >>  
   
 This query returns all the genomes for a particular genus and allows access to the  
 sources from which they came. The join clauses to go from Genome to Source are generated  
 automatically.  
   
 Finally, the filter clause can contain sort information. To do this, simply put an C<ORDER BY>  
 clause at the end of the filter. Field references in the ORDER BY section follow the same rules  
 as they do in the filter itself; in other words, each one must be of the form B<I<objectName>(I<fieldName>)>.  
 For example, the following filter string gets all genomes for a particular genus and sorts  
 them by species name.  
   
 C<< $query = $sprout->Get(['Genome'], "Genome(genus) = ? ORDER BY Genome(species)", [$genus]); >>  
166    
167  It is also permissible to specify I<only> an ORDER BY clause. For example, the following invocation gets  C<< $sprout->Load($rebuild); >>;
 all genomes ordered by genus and species.  
168    
169  C<< $query = $sprout->Get(['Genome'], "ORDER BY Genome(genus), Genome(species)"); >>  Load the database from files in the data directory, optionally re-creating the tables.
170    
171  Odd things may happen if one of the ORDER BY fields is in a secondary relation. So, for example, an  This method always deletes the data from the database before loading, even if the tables are not
172  attempt to order B<Feature>s by alias may (depending on the underlying database engine used) cause  re-created. The data is loaded into the relations from files in the data directory either having the
173  a single feature to appear more than once.  same name as the target relation with no extension or with an extension of C<.dtx>. Files without an
174    extension are used in preference to the files with an extension.
175    
176  If multiple names are specified, then the query processor will automatically determine a  The files are loaded based on the presumption that each line of the file is a record in the
177  join path between the entities and relationships. The algorithm used is very simplistic.  relation, and the individual fields are delimited by tabs. Tab and new-line characters inside
178  In particular, you can't specify any entity or relationship more than once, and if a  fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must
179  relationship is recursive, the path is determined by the order in which the entity  be presented in the order given in the relation tables produced by the L</ShowMetaData> method.
 and the relationship appear. For example, consider a recursive relationship B<IsParentOf>  
 which relates B<People> objects to other B<People> objects. If the join path is  
 coded as C<['People', 'IsParentOf']>, then the people returned will be parents. If, however,  
 the join path is C<['IsParentOf', 'People']>, then the people returned will be children.  
180    
181  =over 4  =over 4
182    
183  =item objectNames  =item rebuild
   
 List containing the names of the entity and relationship objects to be retrieved.  
   
 =item filterClause  
   
 WHERE/ORDER BY clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can  
 be parameterized with parameter markers (C<?>). Each field used must be specified in the standard form  
 B<I<objectName>(I<fieldName>)>. Any parameters specified in the filter clause should be added to the  
 parameter list as additional parameters. The fields in a filter clause can come from primary  
 entity relations, relationship relations, or secondary entity relations; however, all of the  
 entities and relationships involved must be included in the list of object names.  
   
 =item parameterList  
184    
185  List of the parameters to be substituted in for the parameters marks in the filter clause.  TRUE if the data tables need to be created or re-created, else FALSE
186    
187  =item RETURN  =item RETURN
188    
189  Returns a B<DBQuery> that can be used to iterate through all of the results.  Returns a statistical object containing the number of records read, the number of duplicates found,
190    the number of errors, and a list of the error messages.
191    
192  =back  =back
193    
194  =cut  =cut
195    #: Return Type %;
196  sub Get {  sub Load {
197          # Get the parameters.          # Get the parameters.
198          my $self = shift @_;      my ($self, $rebuild) = @_;
199          my ($objectNames, $filterClause, $parameterList) = @_;      # Load the tables from the data directory.
200          # We differ from the ERDB Get method in that the parameter list is passed in as a list reference      my $retVal = $self->LoadTables($self->{_options}->{dataDir}, $rebuild);
201          # rather than a list of parameters. The next step is to convert the parameters from a reference      # Return the statistics.
202          # to a real list. We can only do this if the parameters have been specified.      return $retVal;
         my @parameters;  
         if ($parameterList) { @parameters = @{$parameterList}; }  
         return $self->{_erdb}->Get($objectNames, $filterClause, @parameters);  
203  }  }
204    
205  =head3 GetEntity  =head3 LoadUpdate
206    
207  C<< my $entityObject = $sprout->GetEntity($entityType, $ID); >>  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>
208    
209  Return an object describing the entity instance with a specified ID.  Load updates to one or more database tables. This method enables the client to make changes to one
210    or two tables without reloading the whole database. For each table, there must be a corresponding
211    file in the data directory, either with the same name as the table, or with a C<.dtx> suffix. So,
212    for example, to make updates to the B<FeatureTranslation> relation, there must be a
213    C<FeatureTranslation.dtx> file in the data directory. Unlike a full load, files without an extension
214    are not examined. This allows update files to co-exist with files from an original load.
215    
216  =over 4  =over 4
217    
218  =item entityType  =item truncateFlag
219    
220  Entity type name.  TRUE if the tables should be rebuilt before loading, else FALSE. A value of TRUE therefore causes
221    current data and schema of the tables to be replaced, while a value of FALSE means the new data
222    is added to the existing data in the various relations.
223    
224  =item ID  =item tableList
225    
226  ID of the desired entity.  List of the tables to be updated.
227    
228  =item RETURN  =item RETURN
229    
230  Returns a B<DBObject> representing the desired entity instance, or an undefined value if no  Returns a statistical object containing the number of records read, the number of duplicates found,
231  instance is found with the specified key.  the number of errors encountered, and a list of error messages.
232    
233  =back  =back
234    
235  =cut  =cut
236    #: Return Type $%;
237  sub GetEntity {  sub LoadUpdate {
238          # Get the parameters.          # Get the parameters.
239          my $self = shift @_;      my ($self, $truncateFlag, $tableList) = @_;
240          my ($entityType, $ID) = @_;      # Declare the return value.
241          # Create a query.      my $retVal = Stats->new();
242          my $query = $self->Get([$entityType], "$entityType(id) = ?", [$ID]);      # Get the data directory.
243          # Get the first (and only) object.      my $optionTable = $self->{_options};
244          my $retVal = $query->Fetch();      my $dataDir = $optionTable->{dataDir};
245          # Return the result.      # Loop through the incoming table names.
246        for my $tableName (@{$tableList}) {
247            # Find the table's file.
248            my $fileName = LoadFileName($dataDir, $tableName);
249            if (! $fileName) {
250                Trace("No load file found for $tableName in $dataDir.") if T(0);
251            } else {
252                # Attempt to load this table.
253                my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);
254                # Accumulate the resulting statistics.
255                $retVal->Accumulate($result);
256            }
257        }
258        # Return the statistics.
259          return $retVal;          return $retVal;
260  }  }
261    
262  =head3 GetEntityValues  =head3 GenomeCounts
263    
264  C<< my @values = GetEntityValues($entityType, $ID, \@fields); >>  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>
265    
266  Return a list of values from a specified entity instance.  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
267    genomes will be included in the counts.
268    
269  =over 4  =over 4
270    
271  =item entityType  =item complete
   
 Entity type name.  
272    
273  =item ID  TRUE if only complete genomes are to be counted, FALSE if all genomes are to be
274    counted
 ID of the desired entity.  
   
 =item fields  
   
 List of field names, each of the form I<objectName>C<(>I<fieldName>C<)>.  
275    
276  =item RETURN  =item RETURN
277    
278  Returns a flattened list of the values of the specified fields for the specified entity.  A six-element list containing the number of genomes in each of six categories--
279    Archaea, Bacteria, Eukaryota, Viral, Environmental, and Unknown, respectively.
280    
281  =back  =back
282    
283  =cut  =cut
284    
285  sub GetEntityValues {  sub GenomeCounts {
286          # Get the parameters.          # Get the parameters.
287          my $self = shift @_;      my ($self, $complete) = @_;
288          my ($entityType, $ID, $fields) = @_;      # Set the filter based on the completeness flag.
289          # Get the specified entity.      my $filter = ($complete ? "Genome(complete) = 1" : "");
290          my $entity = $self->GetEntity($entityType, $ID);      # Get all the genomes and the related taxonomy information.
291          # Declare the return list.      my @genomes = $self->GetAll(['Genome'], $filter, [], ['Genome(id)', 'Genome(taxonomy)']);
292          my @retVal = ();      # Clear the counters.
293          # If we found the entity, push the values into the return list.      my ($arch, $bact, $euk, $vir, $env, $unk) = (0, 0, 0, 0, 0, 0);
294          if ($entity) {      # Loop through, counting the domains.
295                  push @retVal, $entity->Values($fields);      for my $genome (@genomes) {
296            if    ($genome->[1] =~ /^archaea/i)  { ++$arch }
297            elsif ($genome->[1] =~ /^bacter/i)   { ++$bact }
298            elsif ($genome->[1] =~ /^eukar/i)    { ++$euk }
299            elsif ($genome->[1] =~ /^vir/i)      { ++$vir }
300            elsif ($genome->[1] =~ /^env/i)      { ++$env }
301            else  { ++$unk }
302          }          }
303          # Return the result.      # Return the counts.
304          return @retVal;      return ($arch, $bact, $euk, $vir, $env, $unk);
 }  
   
 =head3 ShowMetaData  
   
 C<< $sprout->ShowMetaData($fileName); >>  
   
 This method outputs a description of the database to an HTML file in the data directory.  
   
 =over 4  
   
 =item fileName  
   
 Fully-qualified name to give to the output file.  
   
 =back  
   
 =cut  
   
 sub ShowMetaData {  
         # Get the parameters.  
         my $self = shift @_;  
         my ($fileName) = @_;  
         # Compute the file name.  
         my $options = $self->{_options};  
         # Call the show method on the underlying ERDB object.  
         $self->{_erdb}->ShowMetaData($fileName);  
305  }  }
306    
307  =head3 Load  =head3 ContigCount
   
 C<< $sprout->Load($rebuild); >>;  
   
 Load the database from files in the data directory, optionally re-creating the tables.  
308    
309  This method always deletes the data from the database before loading, even if the tables are not  C<< my $count = $sprout->ContigCount($genomeID); >>
 re-created. The data is loaded into the relations from files in the data directory either having the  
 same name as the target relation with no extension or with an extension of C<.dtx>. Files without an  
 extension are used in preference to the files with an extension.  
310    
311  The files are loaded based on the presumption that each line of the file is a record in the  Return the number of contigs for the specified genome ID.
 relation, and the individual fields are delimited by tabs. Tab and new-line characters inside  
 fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must  
 be presented in the order given in the relation tables produced by the L</ShowMetaData> method.  
312    
313  =over 4  =over 4
314    
315  =item rebuild  =item genomeID
316    
317  TRUE if the data tables need to be created or re-created, else FALSE  ID of the genome whose contig count is desired.
318    
319  =item RETURN  =item RETURN
320    
321  Returns a statistical object containing the number of records read, the number of duplicates found,  Returns the number of contigs for the specified genome.
 the number of errors, and a list of the error messages.  
322    
323  =back  =back
324    
325  =cut  =cut
326    
327  sub Load {  sub ContigCount {
328          # Get the parameters.          # Get the parameters.
329          my $self = shift @_;      my ($self, $genomeID) = @_;
330          my ($rebuild) = @_;      # Get the contig count.
331          # Get the database object.      my $retVal = $self->GetCount(['Contig', 'HasContig'], "HasContig(from-link) = ?", [$genomeID]);
332          my $erdb = $self->{_erdb};      # Return the result.
         # Load the tables from the data directory.  
         my $retVal = $erdb->LoadTables($self->{_options}->{dataDir}, $rebuild);  
         # Return the statistics.  
333          return $retVal;          return $retVal;
334  }  }
335    
336  =head3 LoadUpdate  =head3 GeneMenu
337    
338  C<< my %stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>
339    
340  Load updates to one or more database tables. This method enables the client to make changes to one  Return an HTML select menu of genomes. Each genome will be an option in the menu,
341  or two tables without reloading the whole database. For each table, there must be a corresponding  and will be displayed by name with the ID and a contig count attached. The selection
342  file in the data directory, either with the same name as the table, or with a C<.dtx> suffix. So,  value will be the genome ID. The genomes will be sorted by genus/species name.
 for example, to make updates to the B<FeatureTranslation> relation, there must be a  
 C<FeatureTranslation.dtx> file in the data directory. Unlike a full load, files without an extension  
 are not examined. This allows update files to co-exist with files from an original load.  
343    
344  =over 4  =over 4
345    
346  =item truncateFlag  =item attributes
347    
348  TRUE if the tables should be rebuilt before loading, else FALSE. A value of TRUE therefore causes  Reference to a hash mapping attributes to values for the SELECT tag generated.
 current data and schema of the tables to be replaced, while a value of FALSE means the new data  
 is added to the existing data in the various relations.  
349    
350  =item tableList  =item filterString
351    
352  List of the tables to be updated.  A filter string for use in selecting the genomes. The filter string must conform
353    to the rules for the C<< ERDB->Get >> method.
354    
355    =item params
356    
357    Reference to a list of values to be substituted in for the parameter marks in
358    the filter string.
359    
360  =item RETURN  =item RETURN
361    
362  Returns a statistical object containing the number of records read, the number of duplicates found,  Returns an HTML select menu with the specified genomes as selectable options.
 the number of errors encountered, and a list of error messages.  
363    
364  =back  =back
365    
366  =cut  =cut
367    
368  sub LoadUpdate {  sub GeneMenu {
369          # Get the parameters.          # Get the parameters.
370          my $self = shift @_;      my ($self, $attributes, $filterString, $params) = @_;
371          my ($truncateFlag, $tableList) = @_;      # Start the menu.
372          # Get the database object.      my $retVal = "<select " .
373          my $erdb = $self->{_erdb};          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
374          # Declare the return value.          ">\n";
375          my $retVal = Stats->new();      # Get the genomes.
376          # Get the data directory.      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',
377          my $optionTable = $self->{_options};                                                                       'Genome(genus)',
378          my $dataDir = $optionTable->{dataDir};                                                                       'Genome(species)']);
379          # Loop through the incoming table names.      # Sort them by name.
380          for my $tableName (@{$tableList}) {      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;
381                  # Find the table's file.      # Loop through the genomes, creating the option tags.
382                  my $fileName = "$dataDir/$tableName";      for my $genomeData (@sorted) {
383                  if (! -e $fileName) {          # Get the data for this genome.
384                          $fileName = "$fileName.dtx";          my ($genomeID, $genus, $species) = @{$genomeData};
385                  }          # Get the contig count.
386                  # Attempt to load this table.          my $count = $self->ContigCount($genomeID);
387                  my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);          my $counting = ($count == 1 ? "contig" : "contigs");
388                  # Accumulate the resulting statistics.          # Build the option tag.
389                  $retVal->Accumulate($result);          $retVal .= "<option value=\"$genomeID\">$genus $species ($genomeID) [$count $counting]</option>\n";
390          }          }
391          # Return the statistics.      # Close the SELECT tag.
392        $retVal .= "</select>\n";
393        # Return the result.
394          return $retVal;          return $retVal;
395  }  }
   
396  =head3 Build  =head3 Build
397    
398  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 459  Line 402 
402  changed.  changed.
403    
404  =cut  =cut
405    #: Return Type ;
406  sub Build {  sub Build {
407          # Get the parameters.          # Get the parameters.
408          my $self = shift @_;      my ($self) = @_;
409          # Create the tables.          # Create the tables.
410          $self->{_erdb}->CreateTables;      $self->CreateTables();
411  }  }
412    
413  =head3 Genomes  =head3 Genomes
# Line 474  Line 417 
417  Return a list of all the genome IDs.  Return a list of all the genome IDs.
418    
419  =cut  =cut
420    #: Return Type @;
421  sub Genomes {  sub Genomes {
422          # Get the parameters.          # Get the parameters.
423          my $self = shift @_;      my ($self) = @_;
424          # Get all the genomes.          # Get all the genomes.
425          my @retVal = $self->GetFlat(['Genome'], "", [], 'Genome(id)');          my @retVal = $self->GetFlat(['Genome'], "", [], 'Genome(id)');
426          # Return the list of IDs.          # Return the list of IDs.
# Line 504  Line 447 
447  =back  =back
448    
449  =cut  =cut
450    #: Return Type $;
451  sub GenusSpecies {  sub GenusSpecies {
452          # Get the parameters.          # Get the parameters.
453          my $self = shift @_;      my ($self, $genomeID) = @_;
         my ($genomeID) = @_;  
454          # Get the data for the specified genome.          # Get the data for the specified genome.
455          my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',          my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',
456                                                                                                                            'Genome(unique-characterization)']);                                                                                                                            'Genome(unique-characterization)']);
# Line 541  Line 483 
483  =back  =back
484    
485  =cut  =cut
486    #: Return Type @;
487  sub FeaturesOf {  sub FeaturesOf {
488          # Get the parameters.          # Get the parameters.
489          my $self = shift @_;      my ($self, $genomeID,$ftype) = @_;
         my ($genomeID,$ftype) = @_;  
490          # Get the features we want.          # Get the features we want.
491          my @features;          my @features;
492          if (!$ftype) {          if (!$ftype) {
# Line 589  Line 530 
530  =item RETURN  =item RETURN
531    
532  Returns a list of the feature's contig segments. The locations are returned as a list in a list  Returns a list of the feature's contig segments. The locations are returned as a list in a list
533  context and as a space-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context.
534    
535  =back  =back
536    
537  =cut  =cut
538    #: Return Type @;
539    #: Return Type $;
540  sub FeatureLocation {  sub FeatureLocation {
541          # Get the parameters.          # Get the parameters.
542          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
543          # Create a query for the feature locations.          # Create a query for the feature locations.
544          my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",          my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",
545                                                     [$featureID]);                                                     [$featureID]);
# Line 616  Line 557 
557                  if ($prevContig eq $contigID && $dir eq $prevDir) {                  if ($prevContig eq $contigID && $dir eq $prevDir) {
558                          # Here the new segment is in the same direction on the same contig. Insure the                          # Here the new segment is in the same direction on the same contig. Insure the
559                          # new segment's beginning is next to the old segment's end.                          # new segment's beginning is next to the old segment's end.
560                          if (($dir eq "-" && $beg == $prevBeg - $prevLen) ||              if ($dir eq "-" && $beg + $len == $prevBeg) {
561                                  ($dir eq "+" && $beg == $prevBeg + $prevLen)) {                  # Here we're merging two backward blocks, so we keep the new begin point
562                                  # Here we need to merge two segments. Adjust the beginning and length values                  # and adjust the length.
563                                  # to include both segments.                  $len += $prevLen;
564                    # Pop the old segment off. The new one will replace it later.
565                    pop @retVal;
566                } elsif ($dir eq "+" && $beg == $prevBeg + $prevLen) {
567                    # Here we need to merge two forward blocks. Adjust the beginning and
568                    # length values to include both segments.
569                                  $beg = $prevBeg;                                  $beg = $prevBeg;
570                                  $len += $prevLen;                                  $len += $prevLen;
571                                  # Pop the old segment off. The new one will replace it later.                                  # Pop the old segment off. The new one will replace it later.
# Line 628  Line 574 
574                  }                  }
575                  # Remember this specifier for the adjacent-segment test the next time through.                  # Remember this specifier for the adjacent-segment test the next time through.
576                  ($prevContig, $prevBeg, $prevDir, $prevLen) = ($contigID, $beg, $dir, $len);                  ($prevContig, $prevBeg, $prevDir, $prevLen) = ($contigID, $beg, $dir, $len);
577            # Compute the initial base pair.
578            my $start = ($dir eq "+" ? $beg : $beg + $len - 1);
579                  # Add the specifier to the list.                  # Add the specifier to the list.
580                  push @retVal, "${contigID}_$beg$dir$len";          push @retVal, "${contigID}_$start$dir$len";
581          }          }
582          # Return the list in the format indicated by the context.          # Return the list in the format indicated by the context.
583          return (wantarray ? @retVal : join(' ', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
584  }  }
585    
586  =head3 ParseLocation  =head3 ParseLocation
# Line 656  Line 604 
604  =back  =back
605    
606  =cut  =cut
607    #: Return Type @;
608  sub ParseLocation {  sub ParseLocation {
609          # Get the parameter.      # Get the parameter. Note that if we're called as an instance method, we ignore
610        # the first parameter.
611        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
612          my ($location) = @_;          my ($location) = @_;
613          # Parse it into segments.          # Parse it into segments.
614          $location =~ /^(.*)_(\d*)([+-_])(\d*)$/;      $location =~ /^(.+)_(\d+)([+\-_])(\d+)$/;
615          my ($contigID, $start, $dir, $len) = ($1, $2, $3, $4);          my ($contigID, $start, $dir, $len) = ($1, $2, $3, $4);
616          # If the direction is an underscore, convert it to a + or -.          # If the direction is an underscore, convert it to a + or -.
617          if ($dir eq "_") {          if ($dir eq "_") {
# Line 677  Line 627 
627          return ($contigID, $start, $dir, $len);          return ($contigID, $start, $dir, $len);
628  }  }
629    
630    =head3 PointLocation
631    
632    C<< my $found = Sprout::PointLocation($location, $point); >>
633    
634    Return the offset into the specified location of the specified point on the contig. If
635    the specified point is before the location, a negative value will be returned. If it is
636    beyond the location, an undefined value will be returned. It is assumed that the offset
637    is for the location's contig. The location can either be new-style (using a C<+> or C<->
638    and a length) or old-style (using C<_> and start and end positions.
639    
640    =over 4
641    
642    =item location
643    
644    A location specifier (see L</FeatureLocation> for a description).
645    
646    =item point
647    
648    The offset into the contig of the point in which we're interested.
649    
650    =item RETURN
651    
652    Returns the offset inside the specified location of the specified point, a negative
653    number if the point is before the location, or an undefined value if the point is past
654    the location. If the length of the location is 0, this method will B<always> denote
655    that it is outside the location. The offset will always be relative to the left-most
656    position in the location.
657    
658    =back
659    
660    =cut
661    #: Return Type $;
662    sub PointLocation {
663        # Get the parameter. Note that if we're called as an instance method, we ignore
664        # the first parameter.
665        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
666        my ($location, $point) = @_;
667        # Parse out the location elements. Note that this works on both old-style and new-style
668        # locations.
669        my ($contigID, $start, $dir, $len) = ParseLocation($location);
670        # Declare the return variable.
671        my $retVal;
672        # Compute the offset. The computation is dependent on the direction of the location.
673        my $offset = (($dir == '+') ? $point - $start : $point - ($start - $len + 1));
674        # Return the offset if it's valid.
675        if ($offset < $len) {
676            $retVal = $offset;
677        }
678        # Return the offset found.
679        return $retVal;
680    }
681    
682  =head3 DNASeq  =head3 DNASeq
683    
684  C<< my $sequence = $sprout->DNASeq(\@locationList); >>  C<< my $sequence = $sprout->DNASeq(\@locationList); >>
685    
686  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
687  should be of the form returned by L</feature_location> 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,
688  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.
689    
690    For example, the following would return the DNA sequence for contig C<83333.1:NC_000913>
691    between positions 1401 and 1532, inclusive.
692    
693        my $sequence = $sprout->DNASeq('83333.1:NC_000913_1401_1532');
694    
695  =over 4  =over 4
696    
697  =item locationList  =item locationList
698    
699  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<end> (see  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<len> or
700  L</FeatureLocation> for more about this format).  I<contigID>C<_>I<begin>C<_>I<end> (see L</FeatureLocation> for more about this format).
701    
702  =item RETURN  =item RETURN
703    
# Line 699  Line 706 
706  =back  =back
707    
708  =cut  =cut
709    #: Return Type $;
710  sub DNASeq {  sub DNASeq {
711          # Get the parameters.          # Get the parameters.
712          my $self = shift @_;      my ($self, $locationList) = @_;
         my ($locationList) = @_;  
713          # Create the return string.          # Create the return string.
714          my $retVal = "";          my $retVal = "";
715          # Loop through the locations.          # Loop through the locations.
# Line 718  Line 724 
724                  # the start point is the ending. Note that in the latter case we must reverse the DNA string                  # the start point is the ending. Note that in the latter case we must reverse the DNA string
725                  # before putting it in the return value.                  # before putting it in the return value.
726                  my ($start, $stop);                  my ($start, $stop);
727            Trace("Parse of \"$location\" is $beg$dir$len.") if T(SDNA => 4);
728                  if ($dir eq "+") {                  if ($dir eq "+") {
729                          $start = $beg;                          $start = $beg;
730                          $stop = $beg + $len - 1;                          $stop = $beg + $len - 1;
731                  } else {                  } else {
732                          $start = $beg + $len + 1;              $start = $beg - $len + 1;
733                          $stop = $beg;                          $stop = $beg;
734                  }                  }
735            Trace("Looking for sequences containing $start through $stop.") if T(SDNA => 4);
736                  my $query = $self->Get(['IsMadeUpOf','Sequence'],                  my $query = $self->Get(['IsMadeUpOf','Sequence'],
737                          "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .                          "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .
738                          " IsMadeUpOf(start-position) <= ? ORDER BY IsMadeUpOf(start-position)",                          " IsMadeUpOf(start-position) <= ? ORDER BY IsMadeUpOf(start-position)",
# Line 736  Line 744 
744                                  $sequence->Values(['IsMadeUpOf(start-position)', 'Sequence(sequence)',                                  $sequence->Values(['IsMadeUpOf(start-position)', 'Sequence(sequence)',
745                                                                     'IsMadeUpOf(len)']);                                                                     'IsMadeUpOf(len)']);
746                          my $stopPosition = $startPosition + $sequenceLength;                          my $stopPosition = $startPosition + $sequenceLength;
747                Trace("Sequence is from $startPosition to $stopPosition.") if T(SDNA => 4);
748                          # Figure out the start point and length of the relevant section.                          # Figure out the start point and length of the relevant section.
749                          my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);                          my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);
750                          my $len = ($stopPosition <= $stop ? $stopPosition : $stop) - $startPosition - $pos1;              my $len1 = ($stopPosition < $stop ? $stopPosition : $stop) + 1 - $startPosition - $pos1;
751                Trace("Position is $pos1 for length $len1.") if T(SDNA => 4);
752                          # Add the relevant data to the location data.                          # Add the relevant data to the location data.
753                          $locationDNA .= substr($sequenceData, $pos1, $len);              $locationDNA .= substr($sequenceData, $pos1, $len1);
754                  }                  }
755                  # Add this location's data to the return string. Note that we may need to reverse it.                  # Add this location's data to the return string. Note that we may need to reverse it.
756                  if ($dir eq '+') {                  if ($dir eq '+') {
757                          $retVal .= $locationDNA;                          $retVal .= $locationDNA;
758                  } else {                  } else {
759                          $locationDNA = join('', reverse split //, $locationDNA);              $retVal .= FIG::reverse_comp($locationDNA);
                         $retVal .= $locationDNA;  
760                  }                  }
761          }          }
762          # Return the result.          # Return the result.
# Line 773  Line 782 
782  =back  =back
783    
784  =cut  =cut
785    #: Return Type @;
786  sub AllContigs {  sub AllContigs {
787          # Get the parameters.          # Get the parameters.
788          my $self = shift @_;      my ($self, $genomeID) = @_;
         my ($genomeID) = @_;  
789          # Ask for the genome's Contigs.          # Ask for the genome's Contigs.
790          my @retVal = $self->GetFlat(['HasContig'], "HasContig(from-link) = ?", [$genomeID],          my @retVal = $self->GetFlat(['HasContig'], "HasContig(from-link) = ?", [$genomeID],
791                                                                  'HasContig(to-link)');                                                                  'HasContig(to-link)');
# Line 797  Line 805 
805    
806  ID of the contig whose length is desired.  ID of the contig whose length is desired.
807    
808    =item RETURN
809    
810    Returns the number of positions in the contig.
811    
812  =back  =back
813    
814  =cut  =cut
815    #: Return Type $;
816  sub ContigLength {  sub ContigLength {
817          # Get the parameters.          # Get the parameters.
818          my $self = shift @_;      my ($self, $contigID) = @_;
         my ($contigID) = @_;  
819          # Get the contig's last sequence.          # Get the contig's last sequence.
820          my $query = $self->Get(['IsMadeUpOf'],          my $query = $self->Get(['IsMadeUpOf'],
821                  "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",                  "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",
# Line 815  Line 826 
826          # Set it from the sequence data, if any.          # Set it from the sequence data, if any.
827          if ($sequence) {          if ($sequence) {
828                  my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);                  my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);
829                  $retVal = $start + $len;          $retVal = $start + $len - 1;
830        }
831        # Return the result.
832        return $retVal;
833    }
834    
835    =head3 ClusterPEGs
836    
837    C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>
838    
839    Cluster the PEGs in a list according to the cluster coding scheme of the specified
840    subsystem. In order for this to work properly, the subsystem object must have
841    been used recently to retrieve the PEGs using the B<get_pegs_from_cell> method.
842    This causes the cluster numbers to be pulled into the subsystem's color hash.
843    If a PEG is not found in the color hash, it will not appear in the output
844    sequence.
845    
846    =over 4
847    
848    =item sub
849    
850    Sprout subsystem object for the relevant subsystem, from the L</get_subsystem>
851    method.
852    
853    =item pegs
854    
855    Reference to the list of PEGs to be clustered.
856    
857    =item RETURN
858    
859    Returns a list of the PEGs, grouped into smaller lists by cluster number.
860    
861    =back
862    
863    =cut
864    #: Return Type $@@;
865    sub ClusterPEGs {
866        # Get the parameters.
867        my ($self, $sub, $pegs) = @_;
868        # Declare the return variable.
869        my $retVal = [];
870        # Loop through the PEGs, creating arrays for each cluster.
871        for my $pegID (@{$pegs}) {
872            my $clusterNumber = $sub->get_cluster_number($pegID);
873            # Only proceed if the PEG is in a cluster.
874            if ($clusterNumber >= 0) {
875                # Push this PEG onto the sub-list for the specified cluster number.
876                push @{$retVal->[$clusterNumber]}, $pegID;
877            }
878          }          }
879          # Return the result.          # Return the result.
880          return $retVal;          return $retVal;
# Line 846  Line 905 
905  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
906  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
907  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
908  the start and stop values.  the start and stop values. The first element (that is, the list of features) is sorted
909    roughly by location.
910    
911  =back  =back
912    
913  =cut  =cut
914    #: Return Type @@;
915  sub GenesInRegion {  sub GenesInRegion {
916          # Get the parameters.          # Get the parameters.
917          my $self = shift @_;      my ($self, $contigID, $start, $stop) = @_;
         my ($contigID, $start, $stop) = @_;  
918          # Get the maximum segment length.          # Get the maximum segment length.
919          my $maximumSegmentLength = $self->MaxSegment;          my $maximumSegmentLength = $self->MaxSegment;
920          # 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
921          # duplicates easily.      # duplicates easily. The hash key will be the feature ID. The value will be a two-element
922        # containing the minimum and maximum offsets. We will use the offsets to sort the results
923        # when we're building the result set.
924          my %featuresFound = ();          my %featuresFound = ();
925          # Prime the values we'll use for the returned beginning and end.          # Prime the values we'll use for the returned beginning and end.
926          my ($min, $max) = ($self->ContigLength($contigID), 0);      my @initialMinMax = ($self->ContigLength($contigID), 0);
927        my ($min, $max) = @initialMinMax;
928          # 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
929          # 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,
930          # 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 954 
954                                          $found = 1;                                          $found = 1;
955                                  }                                  }
956                          } elsif ($dir eq '-') {                          } elsif ($dir eq '-') {
957                                  $end = $beg - $len;                  # Note we switch things around so that the beginning is to the left of the
958                                  if ($end <= $stop) {                  # ending.
959                    ($beg, $end) = ($beg - $len, $beg);
960                    if ($beg <= $stop) {
961                                          # Denote we found a useful feature.                                          # Denote we found a useful feature.
962                                          $found = 1;                                          $found = 1;
963                                  }                                  }
964                          }                          }
965                          if ($found) {                          if ($found) {
966                                  # 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,
967                                  $featuresFound{$featureID} = 1;                  # get the current entry for the specified feature.
968                                  if ($beg < $min) { $min = $beg; }                  my ($loc1, $loc2) = (exists $featuresFound{$featureID} ? @{$featuresFound{$featureID}} :
969                                  if ($end < $min) { $min = $end; }                                       @initialMinMax);
970                                  if ($beg > $max) { $max = $beg; }                  # Merge the current segment's begin and end into the feature begin and end and the
971                                  if ($end > $max) { $max = $end; }                  # global min and max.
972                    if ($beg < $loc1) {
973                        $loc1 = $beg;
974                        $min = $beg if $beg < $min;
975                    }
976                    if ($end > $loc2) {
977                        $loc2 = $end;
978                        $max = $end if $end > $max;
979                    }
980                    # Store the entry back into the hash table.
981                    $featuresFound{$featureID} = [$loc1, $loc2];
982                          }                          }
983                  }                  }
984          }          }
985          # 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
986          my @list = (sort (keys %featuresFound));      # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
987        # but the result of the sort will be the same.)
988        my @list = map { [$featuresFound{$_}->[0] + $featuresFound{$_}->[1], $_] } keys %featuresFound;
989        # Now we sort by midpoint and yank out the feature IDs.
990        my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
991          # Return it along with the min and max.          # Return it along with the min and max.
992          return (\@list, $min, $max);      return (\@retVal, $min, $max);
993  }  }
994    
995  =head3 FType  =head3 FType
# Line 934  Line 1012 
1012  =back  =back
1013    
1014  =cut  =cut
1015    #: Return Type $;
1016  sub FType {  sub FType {
1017          # Get the parameters.          # Get the parameters.
1018          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1019          # Get the specified feature's type.          # Get the specified feature's type.
1020          my ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(feature-type)']);          my ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(feature-type)']);
1021          # Return the result.          # Return the result.
# Line 947  Line 1024 
1024    
1025  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1026    
1027  C<< my @descriptors = $sprout->FeatureAnnotations($featureID); >>  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>
1028    
1029  Return the annotations of a feature.  Return the annotations of a feature.
1030    
# Line 957  Line 1034 
1034    
1035  ID of the feature whose annotations are desired.  ID of the feature whose annotations are desired.
1036    
1037    =item rawFlag
1038    
1039    If TRUE, the annotation timestamps will be returned in raw form; otherwise, they
1040    will be returned in human-readable form.
1041    
1042  =item RETURN  =item RETURN
1043    
1044  Returns a list of annotation descriptors. Each descriptor is a hash with the following fields.  Returns a list of annotation descriptors. Each descriptor is a hash with the following fields.
# Line 972  Line 1054 
1054  =back  =back
1055    
1056  =cut  =cut
1057    #: Return Type @%;
1058  sub FeatureAnnotations {  sub FeatureAnnotations {
1059          # Get the parameters.          # Get the parameters.
1060          my $self = shift @_;      my ($self, $featureID, $rawFlag) = @_;
         my ($featureID) = @_;  
1061          # 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.
1062          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1063                                                     "IsTargetOfAnnotation(from-link) = ?", [$featureID]);                                                     "IsTargetOfAnnotation(from-link) = ?", [$featureID]);
# Line 989  Line 1070 
1070                          $annotation->Values(['IsTargetOfAnnotation(from-link)',                          $annotation->Values(['IsTargetOfAnnotation(from-link)',
1071                                                                   'Annotation(time)', 'MadeAnnotation(from-link)',                                                                   'Annotation(time)', 'MadeAnnotation(from-link)',
1072                                                                   'Annotation(annotation)']);                                                                   'Annotation(annotation)']);
1073            # Convert the time, if necessary.
1074            if (! $rawFlag) {
1075                $timeStamp = FriendlyTimestamp($timeStamp);
1076            }
1077                  # Assemble them into a hash.                  # Assemble them into a hash.
1078                  my $annotationHash = { featureID => $featureID, timeStamp => $timeStamp,          my $annotationHash = { featureID => $featureID,
1079                                   timeStamp => $timeStamp,
1080                                                             user => $user, text => $text };                                                             user => $user, text => $text };
1081                  # Add it to the return list.                  # Add it to the return list.
1082                  push @retVal, $annotationHash;                  push @retVal, $annotationHash;
# Line 1004  Line 1090 
1090  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>
1091    
1092  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
1093  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,
1094  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
1095  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,
1096  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.
1097  features only have a small number of annotations.  Finally, if a single user has multiple functional assignments, we will only keep the most
1098    recent one.
1099    
1100  =over 4  =over 4
1101    
# Line 1016  Line 1103 
1103    
1104  ID of the feature whose functional assignments are desired.  ID of the feature whose functional assignments are desired.
1105    
1106    =item RETURN
1107    
1108    Returns a hash mapping the user IDs to functional assignment IDs.
1109    
1110  =back  =back
1111    
1112  =cut  =cut
1113    #: Return Type %;
1114  sub AllFunctionsOf {  sub AllFunctionsOf {
1115          # Get the parameters.          # Get the parameters.
1116          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1117          # Get all of the feature's annotations.          # Get all of the feature's annotations.
1118          my @query = $self->GetFlat(['IsTargetOfAnnotation', 'Annotation'],      my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1119                                                      "IsTargetOfAnnotation(from-link) = ?",                                                      "IsTargetOfAnnotation(from-link) = ?",
1120                                                          [$featureID], 'Annotation(annotation)');                              [$featureID], ['Annotation(time)', 'Annotation(annotation)',
1121                                               'MadeAnnotation(from-link)']);
1122          # Declare the return hash.          # Declare the return hash.
1123          my %retVal;          my %retVal;
1124        # Now we sort the assignments by timestamp in reverse.
1125        my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query;
1126          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1127          for my $text (@query) {      for my $annotation (@sortedQuery) {
1128            # Get the annotation fields.
1129            my ($timeStamp, $text, $user) = @{$annotation};
1130                  # Check to see if this is a functional assignment.                  # Check to see if this is a functional assignment.
1131                  my ($user, $function) = ParseAssignment($text);          my ($actualUser, $function) = _ParseAssignment($user, $text);
1132                  if ($user) {          if ($actualUser && ! exists $retVal{$actualUser}) {
1133                          # Here it is, so stuff it in the return hash.              # Here it is a functional assignment and there has been no
1134                          $retVal{$function} = $user;              # previous assignment for this user, so we stuff it in the
1135                # return hash.
1136                $retVal{$actualUser} = $function;
1137                  }                  }
1138          }          }
1139          # Return the hash of assignments found.          # Return the hash of assignments found.
# Line 1047  Line 1144 
1144    
1145  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>
1146    
1147  Return the most recently-determined functional assignment of a particular feature. A functional  Return the most recently-determined functional assignment of a particular feature.
1148  assignment is a type of annotation. It has the format "XXXX\nset XXXX function to\nYYYYY". In this  
1149  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
1150  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
1151  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
1152    L</ParseAssignment>. Its worth noting that we cannot filter on the content of the
1153    annotation itself because it's a text field; however, this is not a big problem because
1154    most features only have a small number of annotations.
1155    
1156    Each user has an associated list of trusted users. The assignment returned will be the most
1157    recent one by at least one of the trusted users. If no trusted user list is available, then
1158    the specified user and FIG are considered trusted. If the user ID is omitted, only FIG
1159    is trusted.
1160    
1161    If the feature is B<not> identified by a FIG ID, then the functional assignment
1162    information is taken from the B<ExternalAliasFunc> table. If the table does
1163    not contain an entry for the feature, an undefined value is returned.
1164    
1165  =over 4  =over 4
1166    
# Line 1061  Line 1170 
1170    
1171  =item userID (optional)  =item userID (optional)
1172    
1173  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
1174    C<FIG> assignment will be returned.
1175    
1176  =item RETURN  =item RETURN
1177    
# Line 1070  Line 1180 
1180  =back  =back
1181    
1182  =cut  =cut
1183    #: Return Type $;
1184  sub FunctionOf {  sub FunctionOf {
1185          # Get the parameters.          # Get the parameters.
1186          my $self = shift @_;      my ($self, $featureID, $userID) = @_;
1187          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.  
1188          my $retVal;          my $retVal;
1189        # Determine the ID type.
1190        if ($featureID =~ m/^fig\|/) {
1191            # Here we have a FIG feature ID. We must build the list of trusted
1192            # users.
1193            my %trusteeTable = ();
1194            # Check the user ID.
1195            if (!$userID) {
1196                # No user ID, so only FIG is trusted.
1197                $trusteeTable{FIG} = 1;
1198            } else {
1199                # Add this user's ID.
1200                $trusteeTable{$userID} = 1;
1201                # Look for the trusted users in the database.
1202                my @trustees = $self->GetFlat(['IsTrustedBy'], 'IsTrustedBy(from-link) = ?', [$userID], 'IsTrustedBy(to-link)');
1203                if (! @trustees) {
1204                    # None were found, so build a default list.
1205                    $trusteeTable{FIG} = 1;
1206                } else {
1207                    # Otherwise, put all the trustees in.
1208                    for my $trustee (@trustees) {
1209                        $trusteeTable{$trustee} = 1;
1210                    }
1211                }
1212            }
1213            # Build a query for all of the feature's annotations, sorted by date.
1214            my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1215                                   "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1216                                   [$featureID]);
1217          my $timeSelected = 0;          my $timeSelected = 0;
1218          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1219          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1220                  # Get the annotation text.                  # Get the annotation text.
1221                  my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1222                  # Check to see if this is a functional assignment for the desired user.                                                       'Annotation(time)', 'MadeAnnotation(from-link)']);
1223                  my ($user, $type, $function) = split(/\n/, $text);              # Check to see if this is a functional assignment for a trusted user.
1224                  if ($type =~ m/^set $userID function to$/i) {              my ($actualUser, $function) = _ParseAssignment($user, $text);
1225                          # Here it is, so we check the time and save the assignment value.              Trace("Assignment user is $actualUser, text is $function.") if T(4);
1226                          if ($time > $timeSelected) {              if ($actualUser) {
1227                    # Here it is a functional assignment. Check the time and the user
1228                    # name. The time must be recent and the user must be trusted.
1229                    if ((exists $trusteeTable{$actualUser}) && ($time > $timeSelected)) {
1230                                  $retVal = $function;                                  $retVal = $function;
1231                                  $timeSelected = $time;                                  $timeSelected = $time;
1232                          }                          }
1233                  }                  }
1234          }          }
1235        } else {
1236            # Here we have a non-FIG feature ID. In this case the user ID does not
1237            # matter. We simply get the information from the External Alias Function
1238            # table.
1239            ($retVal) = $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);
1240        }
1241          # Return the assignment found.          # Return the assignment found.
1242          return $retVal;          return $retVal;
1243  }  }
1244    
1245  =head3 BBHList  =head3 FunctionsOf
   
 C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>  
1246    
1247  Return a hash mapping the features in a specified list to their bidirectional best hits  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>
 on a specified target genome.  
1248    
1249  =over 4  Return the functional assignments of a particular feature.
1250    
1251  =item genomeID  The functional assignment is handled differently depending on the type of feature. If
1252    the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional
1253    assignment is a type of annotation. The format of an assignment is described in
1254    L</ParseAssignment>. Its worth noting that we cannot filter on the content of the
1255    annotation itself because it's a text field; however, this is not a big problem because
1256    most features only have a small number of annotations.
1257    
1258    If the feature is B<not> identified by a FIG ID, then the functional assignment
1259    information is taken from the B<ExternalAliasFunc> table. If the table does
1260    not contain an entry for the feature, an empty list is returned.
1261    
1262  ID of the genome from which the best hits should be taken.  =over 4
1263    
1264  =item featureList  =item featureID
1265    
1266  List of the features whose best hits are desired.  ID of the feature whose functional assignments are desired.
1267    
1268  =item RETURN  =item RETURN
1269    
1270  Returns a reference to a hash that maps the IDs of the incoming features to the IDs of  Returns a list of 2-tuples, each consisting of a user ID and the text of an assignment by
1271  their best hits.  that user.
1272    
1273  =back  =back
1274    
1275  =cut  =cut
1276    #: Return Type @@;
1277    sub FunctionsOf {
1278        # Get the parameters.
1279        my ($self, $featureID) = @_;
1280        # Declare the return value.
1281        my @retVal = ();
1282        # Determine the ID type.
1283        if ($featureID =~ m/^fig\|/) {
1284            # Here we have a FIG feature ID. We must build the list of trusted
1285            # users.
1286            my %trusteeTable = ();
1287            # Build a query for all of the feature's annotations, sorted by date.
1288            my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1289                                   "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1290                                   [$featureID]);
1291            my $timeSelected = 0;
1292            # Loop until we run out of annotations.
1293            while (my $annotation = $query->Fetch()) {
1294                # Get the annotation text.
1295                my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1296                                                                'Annotation(time)',
1297                                                                'MadeAnnotation(user)']);
1298                # Check to see if this is a functional assignment for a trusted user.
1299                my ($actualUser, $function) = _ParseAssignment($user, $text);
1300                if ($actualUser) {
1301                    # Here it is a functional assignment.
1302                    push @retVal, [$actualUser, $function];
1303                }
1304            }
1305        } else {
1306            # Here we have a non-FIG feature ID. In this case the user ID does not
1307            # matter. We simply get the information from the External Alias Function
1308            # table.
1309            my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,
1310                                                     ['ExternalAliasFunc(func)']);
1311            push @retVal, map { ['master', $_] } @assignments;
1312        }
1313        # Return the assignments found.
1314        return @retVal;
1315    }
1316    
1317    =head3 BBHList
1318    
1319    C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>
1320    
1321    Return a hash mapping the features in a specified list to their bidirectional best hits
1322    on a specified target genome.
1323    
1324    =over 4
1325    
1326    =item genomeID
1327    
1328    ID of the genome from which the best hits should be taken.
1329    
1330    =item featureList
1331    
1332    List of the features whose best hits are desired.
1333    
1334    =item RETURN
1335    
1336    Returns a reference to a hash that maps the IDs of the incoming features to the best hits
1337    on the target genome.
1338    
1339    =back
1340    
1341    =cut
1342    #: Return Type %;
1343  sub BBHList {  sub BBHList {
1344          # Get the parameters.          # Get the parameters.
1345          my $self = shift @_;      my ($self, $genomeID, $featureList) = @_;
         my ($genomeID, $featureList) = @_;  
1346          # Create the return structure.          # Create the return structure.
1347          my %retVal = ();          my %retVal = ();
1348          # Loop through the incoming features.          # Loop through the incoming features.
# Line 1139  Line 1351 
1351                  my $query = $self->Get(['IsBidirectionalBestHitOf'],                  my $query = $self->Get(['IsBidirectionalBestHitOf'],
1352                                                             "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",                                                             "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",
1353                                                             [$featureID, $genomeID]);                                                             [$featureID, $genomeID]);
1354                  # Look for the best hit.          # Peel off the BBHs found.
1355                  my $bbh = $query->Fetch;          my @found = ();
1356                  if ($bbh) {          while (my $bbh = $query->Fetch) {
1357                          my ($targetFeature) = $bbh->Value('IsBidirectionalBestHitOf(to-link)');              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');
                         $retVal{$featureID} = $targetFeature;  
1358                  }                  }
1359            $retVal{$featureID} = \@found;
1360          }          }
1361          # Return the mapping.          # Return the mapping.
1362          return \%retVal;          return \%retVal;
1363  }  }
1364    
1365    =head3 SimList
1366    
1367    C<< my %similarities = $sprout->SimList($featureID, $count); >>
1368    
1369    Return a list of the similarities to the specified feature.
1370    
1371    Sprout does not support real similarities, so this method just returns the bidirectional
1372    best hits.
1373    
1374    =over 4
1375    
1376    =item featureID
1377    
1378    ID of the feature whose similarities are desired.
1379    
1380    =item count
1381    
1382    Maximum number of similar features to be returned, or C<0> to return them all.
1383    
1384    =back
1385    
1386    =cut
1387    #: Return Type %;
1388    sub SimList {
1389        # Get the parameters.
1390        my ($self, $featureID, $count) = @_;
1391        # Ask for the best hits.
1392        my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],
1393                                  "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",
1394                                  [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],
1395                                  $count);
1396        # Create the return value.
1397        my %retVal = ();
1398        for my $tuple (@lists) {
1399            $retVal{$tuple->[0]} = $tuple->[1];
1400        }
1401        # Return the result.
1402        return %retVal;
1403    }
1404    
1405    
1406    
1407    =head3 IsComplete
1408    
1409    C<< my $flag = $sprout->IsComplete($genomeID); >>
1410    
1411    Return TRUE if the specified genome is complete, else FALSE.
1412    
1413    =over 4
1414    
1415    =item genomeID
1416    
1417    ID of the genome whose completeness status is desired.
1418    
1419    =item RETURN
1420    
1421    Returns TRUE if the genome is complete, FALSE if it is incomplete, and C<undef> if it is
1422    not found.
1423    
1424    =back
1425    
1426    =cut
1427    #: Return Type $;
1428    sub IsComplete {
1429        # Get the parameters.
1430        my ($self, $genomeID) = @_;
1431        # Declare the return variable.
1432        my $retVal;
1433        # Get the genome's data.
1434        my $genomeData = $self->GetEntity('Genome', $genomeID);
1435        if ($genomeData) {
1436            # The genome exists, so get the completeness flag.
1437            ($retVal) = $genomeData->Value('Genome(complete)');
1438        }
1439        # Return the result.
1440        return $retVal;
1441    }
1442    
1443  =head3 FeatureAliases  =head3 FeatureAliases
1444    
1445  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>
# Line 1170  Line 1460 
1460  =back  =back
1461    
1462  =cut  =cut
1463    #: Return Type @;
1464  sub FeatureAliases {  sub FeatureAliases {
1465          # Get the parameters.          # Get the parameters.
1466          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
1467          # Get the desired feature's aliases          # Get the desired feature's aliases
1468          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);
1469          # Return the result.          # Return the result.
# Line 1185  Line 1474 
1474    
1475  C<< my $genomeID = $sprout->GenomeOf($featureID); >>  C<< my $genomeID = $sprout->GenomeOf($featureID); >>
1476    
1477  Return the genome that contains a specified feature.  Return the genome that contains a specified feature or contig.
1478    
1479  =over 4  =over 4
1480    
1481  =item featureID  =item featureID
1482    
1483  ID of the feature whose genome is desired.  ID of the feature or contig whose genome is desired.
1484    
1485  =item RETURN  =item RETURN
1486    
1487  Returns the ID of the genome for the specified feature. If the feature is not found, returns  Returns the ID of the genome for the specified feature or contig. If the feature or contig is not
1488  an undefined value.  found, returns an undefined value.
1489    
1490  =back  =back
1491    
1492  =cut  =cut
1493    #: Return Type $;
1494  sub GenomeOf {  sub GenomeOf {
1495          # Get the parameters.          # Get the parameters.
1496          my $self = shift @_;      my ($self, $featureID) = @_;
1497          my ($featureID) = @_;      # Create a query to find the genome associated with the incoming ID.
1498          # Create a query to find the genome associated with the feature.      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ? OR HasContig(to-link) = ?",
1499          my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);                             [$featureID, $featureID]);
1500          # Declare the return value.          # Declare the return value.
1501          my $retVal;          my $retVal;
1502          # Get the genome ID.          # Get the genome ID.
# Line 1238  Line 1527 
1527  =back  =back
1528    
1529  =cut  =cut
1530    #: Return Type %;
1531  sub CoupledFeatures {  sub CoupledFeatures {
1532          # Get the parameters.          # Get the parameters.
1533          my $self = shift @_;      my ($self, $featureID) = @_;
1534          my ($featureID) = @_;      # Create a query to retrieve the functionally-coupled features.
1535          # Create a query to retrieve the functionally-coupled features. Note that we depend on the      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1536          # 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]);  
1537          # 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.
1538          my $found = 0;          my $found = 0;
1539          # Create the return hash.          # Create the return hash.
1540          my %retVal = ();          my %retVal = ();
1541          # Retrieve the relationship records and store them in the hash.          # Retrieve the relationship records and store them in the hash.
1542          while (my $clustering = $query->Fetch()) {          while (my $clustering = $query->Fetch()) {
1543                  my ($otherFeatureID, $score) = $clustering->Values(['IsClusteredOnChromosomeWith(to-link)',          # Get the ID and score of the coupling.
1544                                                                      'IsClusteredOnChromosomeWith(score)']);          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1545                                                            'Coupling(score)']);
1546            # The coupling ID contains the two feature IDs separated by a space. We use
1547            # this information to find the ID of the other feature.
1548            my ($fid1, $fid2) = split / /, $couplingID;
1549            my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);
1550            # Attach the other feature's score to its ID.
1551                  $retVal{$otherFeatureID} = $score;                  $retVal{$otherFeatureID} = $score;
1552                  $found = 1;                  $found = 1;
1553          }          }
# Line 1268  Line 1560 
1560          return %retVal;          return %retVal;
1561  }  }
1562    
1563  =head3 GetEntityTypes  =head3 CouplingEvidence
1564    
1565    C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>
1566    
1567    Return the evidence for a functional coupling.
1568    
1569    A pair of features is considered evidence of a coupling between two other
1570    features if they occur close together on a contig and both are similar to
1571    the coupled features. So, if B<A1> and B<A2> are close together on a contig,
1572    B<B1> and B<B2> are considered evidence for the coupling if (1) B<B1> and
1573    B<B2> are close together, (2) B<B1> is similar to B<A1>, and (3) B<B2> is
1574    similar to B<A2>.
1575    
1576  C<< my @entityList = $sprout->GetEntityTypes(); >>  The score of a coupling is determined by the number of pieces of evidence
1577    that are considered I<representative>. If several evidence items belong to
1578    a group of genomes that are close to each other, only one of those items
1579    is considered representative. The other evidence items are presumed to be
1580    there because of the relationship between the genomes rather than because
1581    the two proteins generated by the features have a related functionality.
1582    
1583  Return the list of supported entity types.  Each evidence item is returned as a three-tuple in the form C<[>I<$peg1a>C<,>
1584    I<$peg2a>C<,> I<$rep>C<]>, where I<$peg1a> is similar to I<$peg1>, I<$peg2a>
1585    is similar to I<$peg2>, and I<$rep> is TRUE if the evidence is representative
1586    and FALSE otherwise.
1587    
1588    =over 4
1589    
1590    =item peg1
1591    
1592    ID of the feature of interest.
1593    
1594    =item peg2
1595    
1596    ID of a feature functionally coupled to the feature of interest.
1597    
1598    =item RETURN
1599    
1600    Returns a list of 3-tuples. Each tuple consists of a feature similar to the feature
1601    of interest, a feature similar to the functionally coupled feature, and a flag
1602    that is TRUE for a representative piece of evidence and FALSE otherwise.
1603    
1604    =back
1605    
1606  =cut  =cut
1607    #: Return Type @@;
1608    sub CouplingEvidence {
1609        # Get the parameters.
1610        my ($self, $peg1, $peg2) = @_;
1611        # Declare the return variable.
1612        my @retVal = ();
1613        # Our first task is to find out the nature of the coupling: whether or not
1614        # it exists, its score, and whether the features are stored in the same
1615        # order as the ones coming in.
1616        my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);
1617        # Only proceed if a coupling exists.
1618        if ($couplingID) {
1619            # Determine the ordering to place on the evidence items. If we're
1620            # inverted, we want to see feature 2 before feature 1 (descending); otherwise,
1621            # we want feature 1 before feature 2 (normal).
1622            Trace("Coupling evidence for ($peg1, $peg2) with inversion flag $inverted.") if T(Coupling => 4);
1623            my $ordering = ($inverted ? "DESC" : "");
1624            # Get the coupling evidence.
1625            my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
1626                                              "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",
1627                                              [$couplingID],
1628                                              ['PCH(used)', 'UsesAsEvidence(to-link)']);
1629            # Loop through the evidence items. Each piece of evidence is represented by two
1630            # positions in the evidence list, one for each feature on the other side of the
1631            # evidence link. If at some point we want to generalize to couplings with
1632            # more than two positions, this section of code will need to be re-done.
1633            while (@evidenceList > 0) {
1634                my $peg1Data = shift @evidenceList;
1635                my $peg2Data = shift @evidenceList;
1636                Trace("Peg 1 is " . $peg1Data->[1] . " and Peg 2 is " . $peg2Data->[1] . ".") if T(Coupling => 4);
1637                push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1638            }
1639            Trace("Last index in evidence result is is $#retVal.") if T(Coupling => 4);
1640        }
1641        # Return the result.
1642        return @retVal;
1643    }
1644    
1645    =head3 GetCoupling
1646    
1647    C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>
1648    
1649    Return the coupling (if any) for the specified pair of PEGs. If a coupling
1650    exists, we return the coupling ID along with an indicator of whether the
1651    coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.
1652    In the second case, we say the coupling is I<inverted>. The importance of an
1653    inverted coupling is that the PEGs in the evidence will appear in reverse order.
1654    
1655    =over 4
1656    
1657    =item peg1
1658    
1659  sub GetEntityTypes {  ID of the feature of interest.
1660    
1661    =item peg2
1662    
1663    ID of the potentially coupled feature.
1664    
1665    =item RETURN
1666    
1667    Returns a three-element list. The first element contains the database ID of
1668    the coupling. The second element is FALSE if the coupling is stored in the
1669    database in the caller specified order and TRUE if it is stored in the
1670    inverted order. The third element is the coupling's score. If the coupling
1671    does not exist, all three list elements will be C<undef>.
1672    
1673    =back
1674    
1675    =cut
1676    #: Return Type $%@;
1677    sub GetCoupling {
1678          # Get the parameters.          # Get the parameters.
1679          my $self = shift @_;      my ($self, $peg1, $peg2) = @_;
1680          # Get the underlying database object.      # Declare the return values. We'll start with the coupling ID and undefine the
1681          my $erdb = $self->{_erdb};      # flag and score until we have more information.
1682          # Get its entity type list.      my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);
1683          my @retVal = $erdb->GetEntityTypes();      # Find the coupling data.
1684        my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],
1685                                     "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",
1686                                     [$retVal], ["ParticipatesInCoupling(from-link)", "Coupling(score)"]);
1687        # Check to see if we found anything.
1688        if (!@pegs) {
1689            Trace("No coupling found.") if T(Coupling => 4);
1690            # No coupling, so undefine the return value.
1691            $retVal = undef;
1692        } else {
1693            # We have a coupling! Get the score and check for inversion.
1694            $score = $pegs[0]->[1];
1695            my $firstFound = $pegs[0]->[0];
1696            $inverted = ($firstFound ne $peg1);
1697            Trace("Coupling score is $score. First peg is $firstFound, peg 1 is $peg1.") if T(Coupling => 4);
1698        }
1699        # Return the result.
1700        return ($retVal, $inverted, $score);
1701    }
1702    
1703    =head3 CouplingID
1704    
1705    C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>
1706    
1707    Return the coupling ID for a pair of feature IDs.
1708    
1709    The coupling ID is currently computed by joining the feature IDs in
1710    sorted order with a space. Client modules (that is, modules which
1711    use Sprout) should not, however, count on this always being the
1712    case. This method provides a way for abstracting the concept of a
1713    coupling ID. All that we know for sure about it is that it can be
1714    generated easily from the feature IDs and the order of the IDs
1715    in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>
1716    will have the same value as C<CouplingID("b1", "a1")>.
1717    
1718    =over 4
1719    
1720    =item peg1
1721    
1722    First feature of interest.
1723    
1724    =item peg2
1725    
1726    Second feature of interest.
1727    
1728    =item RETURN
1729    
1730    Returns the ID that would be used to represent a functional coupling of
1731    the two specified PEGs.
1732    
1733    =back
1734    
1735    =cut
1736    #: Return Type $;
1737    sub CouplingID {
1738        return join " ", sort @_;
1739  }  }
1740    
1741  =head3 ReadFasta  =head3 ReadFasta
# Line 1310  Line 1763 
1763  =back  =back
1764    
1765  =cut  =cut
1766    #: Return Type %;
1767  sub ReadFasta {  sub ReadFasta {
1768          # Get the parameters.          # Get the parameters.
1769          my ($fileName, $prefix) = @_;          my ($fileName, $prefix) = @_;
# Line 1329  Line 1782 
1782                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {
1783                          # 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.
1784                          if ($id) {                          if ($id) {
1785                                  $retVal{$id} = $sequence;                  $retVal{$id} = lc $sequence;
1786                          }                          }
1787                          # Clear the sequence accumulator and save the new ID.                          # Clear the sequence accumulator and save the new ID.
1788                          ($id, $sequence) = ("$prefix$1", "");                          ($id, $sequence) = ("$prefix$1", "");
1789                  } else {                  } else {
1790                          # 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.
1791                          # First, we get the actual data out.              # First, we get the actual data out. Note that we normalize to lower
1792                # case.
1793                          $line =~ /^\s*(.*?)(\s|\n)/;                          $line =~ /^\s*(.*?)(\s|\n)/;
1794                          $sequence .= $1;                          $sequence .= $1;
1795                  }                  }
1796          }          }
1797          # Flush out the last sequence (if any).          # Flush out the last sequence (if any).
1798          if ($sequence) {          if ($sequence) {
1799                  $retVal {$id} = $sequence;          $retVal{$id} = lc $sequence;
1800          }          }
1801        # Close the file.
1802        close FASTAFILE;
1803          # Return the hash constructed from the file.          # Return the hash constructed from the file.
1804          return %retVal;          return %retVal;
1805  }  }
# Line 1354  Line 1810 
1810    
1811  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
1812  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
1813  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,
1814    it will not be changed; otherwise, it will be converted. This method can also be used to
1815    perform the reverse task-- insuring that all the locations are in the old format.
1816    
1817  =over 4  =over 4
1818    
# Line 1378  Line 1836 
1836  =back  =back
1837    
1838  =cut  =cut
1839    #: Return Type @;
1840  sub FormatLocations {  sub FormatLocations {
1841          # Get the parameters.          # Get the parameters.
1842          my $self = shift @_;      my ($self, $prefix, $locations, $oldFormat) = @_;
         my ($prefix, $locations, $oldFormat) = @_;  
1843          # Create the return list.          # Create the return list.
1844          my @retVal = ();          my @retVal = ();
1845          # Check to see if any locations were passed in.          # Check to see if any locations were passed in.
1846          if ($locations eq '') {          if ($locations eq '') {
1847              confess "No locations specified.";          Confess("No locations specified.");
1848          } else {          } else {
1849                  # Loop through the locations, converting them to the new format.                  # Loop through the locations, converting them to the new format.
1850                  for my $location (@{$locations}) {                  for my $location (@{$locations}) {
# Line 1422  Line 1879 
1879    
1880  sub DumpData {  sub DumpData {
1881          # Get the parameters.          # Get the parameters.
1882          my $self = shift @_;      my ($self) = @_;
1883          # Get the data directory name.          # Get the data directory name.
1884          my $outputDirectory = $self->{_options}->{dataDir};          my $outputDirectory = $self->{_options}->{dataDir};
1885          # Dump the relations.          # Dump the relations.
1886          $self->{_erdb}->DumpRelations($outputDirectory);      $self->DumpRelations($outputDirectory);
1887  }  }
1888    
1889  =head3 XMLFileName  =head3 XMLFileName
# Line 1436  Line 1893 
1893  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
1894    
1895  =cut  =cut
1896    #: Return Type $;
1897  sub XMLFileName {  sub XMLFileName {
1898          my $self = shift @_;      my ($self) = @_;
1899          return $self->{_xmlName};          return $self->{_xmlName};
1900  }  }
1901    
# Line 1458  Line 1915 
1915  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
1916  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>.
1917    
1918  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>
1919    
1920  =over 4  =over 4
1921    
# Line 1473  Line 1930 
1930  =back  =back
1931    
1932  =cut  =cut
1933    #: Return Type ;
1934  sub Insert {  sub Insert {
1935          # Get the parameters.          # Get the parameters.
1936          my $self = shift @_;      my ($self, $objectType, $fieldHash) = @_;
         my ($objectType, $fieldHash) = @_;  
1937          # Call the underlying method.          # Call the underlying method.
1938          $self->{_erdb}->InsertObject($objectType, $fieldHash);      $self->InsertObject($objectType, $fieldHash);
1939  }  }
1940    
1941  =head3 Annotate  =head3 Annotate
# Line 1515  Line 1971 
1971  =back  =back
1972    
1973  =cut  =cut
1974    #: Return Type $;
1975  sub Annotate {  sub Annotate {
1976          # Get the parameters.          # Get the parameters.
1977          my $self = shift @_;      my ($self, $fid, $timestamp, $user, $text) = @_;
         my ($fid, $timestamp, $user, $text) = @_;  
1978          # Create the annotation ID.          # Create the annotation ID.
1979          my $aid = "$fid:$timestamp";          my $aid = "$fid:$timestamp";
1980          # Insert the Annotation object.          # Insert the Annotation object.
# Line 1539  Line 1994 
1994    
1995  =head3 AssignFunction  =head3 AssignFunction
1996    
1997  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function); >>  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>
1998    
1999  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
2000  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.  
2001    
2002  =over 4  =over 4
2003    
# Line 1553  Line 2007 
2007    
2008  =item user  =item user
2009    
2010  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>.
2011    
2012  =item function  =item function
2013    
2014  Text of the function being assigned.  Text of the function being assigned.
2015    
2016    =item assigningUser (optional)
2017    
2018    Name of the individual user making the assignment. If omitted, defaults to the user group.
2019    
2020  =item RETURN  =item RETURN
2021    
2022  Returns 1 if successful, 0 if an error occurred.  Returns 1 if successful, 0 if an error occurred.
# Line 1566  Line 2024 
2024  =back  =back
2025    
2026  =cut  =cut
2027    #: Return Type $;
2028  sub AssignFunction {  sub AssignFunction {
2029          # Get the parameters.          # Get the parameters.
2030          my $self = shift @_;      my ($self, $featureID, $user, $function, $assigningUser) = @_;
2031          my ($featureID, $user, $function) = @_;      # Default the assigning user.
2032        if (! $assigningUser) {
2033            $assigningUser = $user;
2034        }
2035          # Create an annotation string from the parameters.          # Create an annotation string from the parameters.
2036          my $annotationText = "$user\nset $user function to\n$function";      my $annotationText = "$assigningUser\nset $user function to\n$function";
2037          # Get the current time.          # Get the current time.
2038          my $now = time;          my $now = time;
2039          # Declare the return variable.          # Declare the return variable.
# Line 1614  Line 2075 
2075  =back  =back
2076    
2077  =cut  =cut
2078    #: Return Type @;
2079  sub FeaturesByAlias {  sub FeaturesByAlias {
2080          # Get the parameters.          # Get the parameters.
2081          my $self = shift @_;      my ($self, $alias) = @_;
         my ($alias) = @_;  
2082          # Declare the return variable.          # Declare the return variable.
2083          my @retVal = ();          my @retVal = ();
2084          # Parse the alias.          # Parse the alias.
# Line 1657  Line 2117 
2117  =back  =back
2118    
2119  =cut  =cut
2120    #: Return Type $;
2121  sub Exists {  sub Exists {
2122          # Get the parameters.          # Get the parameters.
2123          my $self = shift @_;      my ($self, $entityName, $entityID) = @_;
         my ($entityName, $entityID) = @_;  
2124          # Check for the entity instance.          # Check for the entity instance.
2125        Trace("Checking existence of $entityName with ID=$entityID.") if T(4);
2126          my $testInstance = $self->GetEntity($entityName, $entityID);          my $testInstance = $self->GetEntity($entityName, $entityID);
2127          # Return an existence indicator.          # Return an existence indicator.
2128          my $retVal = ($testInstance ? 1 : 0);          my $retVal = ($testInstance ? 1 : 0);
# Line 1688  Line 2148 
2148  =back  =back
2149    
2150  =cut  =cut
2151    #: Return Type $;
2152  sub FeatureTranslation {  sub FeatureTranslation {
2153          # Get the parameters.          # Get the parameters.
2154          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2155          # Get the specified feature's translation.          # Get the specified feature's translation.
2156          my ($retVal) = $self->GetEntityValues("Feature", $featureID, ['Feature(translation)']);          my ($retVal) = $self->GetEntityValues("Feature", $featureID, ['Feature(translation)']);
2157          return $retVal;          return $retVal;
# Line 1721  Line 2180 
2180  =back  =back
2181    
2182  =cut  =cut
2183    #: Return Type @;
2184  sub Taxonomy {  sub Taxonomy {
2185          # Get the parameters.          # Get the parameters.
2186          my $self = shift @_;      my ($self, $genome) = @_;
         my ($genome) = @_;  
2187          # Find the specified genome's taxonomy string.          # Find the specified genome's taxonomy string.
2188          my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);          my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);
2189          # Declare the return variable.          # Declare the return variable.
# Line 1765  Line 2223 
2223  =back  =back
2224    
2225  =cut  =cut
2226    #: Return Type $;
2227  sub CrudeDistance {  sub CrudeDistance {
2228          # Get the parameters.          # Get the parameters.
2229          my $self = shift @_;      my ($self, $genome1, $genome2) = @_;
         my ($genome1, $genome2) = @_;  
2230          # Insure that the distance is commutative by sorting the genome IDs.          # Insure that the distance is commutative by sorting the genome IDs.
2231          my ($genomeA, $genomeB);          my ($genomeA, $genomeB);
2232          if ($genome2 < $genome2) {          if ($genome2 < $genome2) {
# Line 1813  Line 2270 
2270  =back  =back
2271    
2272  =cut  =cut
2273    #: Return Type $;
2274  sub RoleName {  sub RoleName {
2275          # Get the parameters.          # Get the parameters.
2276          my $self = shift @_;      my ($self, $roleID) = @_;
         my ($roleID) = @_;  
2277          # Get the specified role's name.          # Get the specified role's name.
2278          my ($retVal) = $self->GetEntityValues('Role', $roleID, ['Role(name)']);          my ($retVal) = $self->GetEntityValues('Role', $roleID, ['Role(name)']);
2279          # Use the ID if the role has no name.          # Use the ID if the role has no name.
# Line 1847  Line 2303 
2303  =back  =back
2304    
2305  =cut  =cut
2306    #: Return Type @;
2307  sub RoleDiagrams {  sub RoleDiagrams {
2308          # Get the parameters.          # Get the parameters.
2309          my $self = shift @_;      my ($self, $roleID) = @_;
         my ($roleID) = @_;  
2310          # Query for the diagrams.          # Query for the diagrams.
2311          my @retVal = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],          my @retVal = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],
2312                                                                  'RoleOccursIn(to-link)');                                                                  'RoleOccursIn(to-link)');
# Line 1859  Line 2314 
2314          return @retVal;          return @retVal;
2315  }  }
2316    
2317    =head3 GetProperties
2318    
2319    C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>
2320    
2321    Return a list of the properties with the specified characteristics.
2322    
2323    Properties are arbitrary key-value pairs associated with a feature. (At some point they
2324    will also be associated with genomes.) A property value is represented by a 4-tuple of
2325    the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter
2326    
2327    =over 4
2328    
2329    =item fid
2330    
2331    ID of the feature possessing the property.
2332    
2333    =item key
2334    
2335    Name or key of the property.
2336    
2337    =item value
2338    
2339    Value of the property.
2340    
2341    =item url
2342    
2343    URL of the document that indicated the property should have this particular value, or an
2344    empty string if no such document exists.
2345    
2346    =back
2347    
2348    The parameters act as a filter for the desired data. Any non-null parameter will
2349    automatically match all the tuples returned. So, specifying just the I<$fid> will
2350    return all the properties of the specified feature; similarly, specifying the I<$key>
2351    and I<$value> parameters will return all the features having the specified property
2352    value.
2353    
2354    A single property key can have many values, representing different ideas about the
2355    feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is
2356    virulent, and another may declare that it is not virulent. A query about the virulence of
2357    C<fig|83333.1.peg.10> would be coded as
2358    
2359        my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');
2360    
2361    Here the I<$value> and I<$url> fields are left blank, indicating that those fields are
2362    not to be filtered. The tuples returned would be
2363    
2364        ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')
2365        ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')
2366    
2367    =cut
2368    #: Return Type @@;
2369    sub GetProperties {
2370        # Get the parameters.
2371        my ($self, @parms) = @_;
2372        # Declare the return variable.
2373        my @retVal = ();
2374        # Now we need to create a WHERE clause that will get us the data we want. First,
2375        # we create a list of the columns containing the data for each parameter.
2376        my @colNames = ('HasProperty(from-link)', 'Property(property-name)',
2377                        'Property(property-value)', 'HasProperty(evidence)');
2378        # Now we build the WHERE clause and the list of parameter values.
2379        my @where = ();
2380        my @values = ();
2381        for (my $i = 0; $i <= $#colNames; $i++) {
2382            my $parm = $parms[$i];
2383            if (defined $parm && ($parm ne '')) {
2384                push @where, "$colNames[$i] = ?";
2385                push @values, $parm;
2386            }
2387        }
2388        # Format the WHERE clause.
2389        my $filter = (@values > 0 ? (join " AND ", @where) : undef);
2390        # Ask for all the propertie values with the desired characteristics.
2391        my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);
2392        while (my $valueObject = $query->Fetch()) {
2393            my @tuple = $valueObject->Values(\@colNames);
2394            push @retVal, \@tuple;
2395        }
2396        # Return the result.
2397        return @retVal;
2398    }
2399    
2400  =head3 FeatureProperties  =head3 FeatureProperties
2401    
2402  C<< my @properties = $sprout->FeatureProperties($featureID); >>  C<< my @properties = $sprout->FeatureProperties($featureID); >>
# Line 1885  Line 2423 
2423  =back  =back
2424    
2425  =cut  =cut
2426    #: Return Type @@;
2427  sub FeatureProperties {  sub FeatureProperties {
2428          # Get the parameters.          # Get the parameters.
2429          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2430          # Get the properties.          # Get the properties.
2431          my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],          my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],
2432                                                          ['Property(property-name)', 'Property(property-value)',                                                          ['Property(property-name)', 'Property(property-value)',
# Line 1917  Line 2454 
2454  =back  =back
2455    
2456  =cut  =cut
2457    #: Return Type $;
2458  sub DiagramName {  sub DiagramName {
2459          # Get the parameters.          # Get the parameters.
2460          my $self = shift @_;      my ($self, $diagramID) = @_;
         my ($diagramID) = @_;  
2461          # Get the specified diagram's name and return it.          # Get the specified diagram's name and return it.
2462          my ($retVal) = $self->GetEntityValues('Diagram', $diagramID, ['Diagram(name)']);          my ($retVal) = $self->GetEntityValues('Diagram', $diagramID, ['Diagram(name)']);
2463          return $retVal;          return $retVal;
# Line 1950  Line 2486 
2486  =back  =back
2487    
2488  =cut  =cut
2489    #: Return Type @;
2490  sub MergedAnnotations {  sub MergedAnnotations {
2491          # Get the parameters.          # Get the parameters.
2492          my $self = shift @_;      my ($self, $list) = @_;
         my ($list) = @_;  
2493          # Create a list to hold the annotation tuples found.          # Create a list to hold the annotation tuples found.
2494          my @tuples = ();          my @tuples = ();
2495          # Loop through the features in the input list.          # Loop through the features in the input list.
# Line 1969  Line 2504 
2504          }          }
2505          # Sort the result list by timestamp.          # Sort the result list by timestamp.
2506          my @retVal = sort { $a->[1] <=> $b->[1] } @tuples;          my @retVal = sort { $a->[1] <=> $b->[1] } @tuples;
2507        # Loop through and make the time stamps friendly.
2508        for my $tuple (@retVal) {
2509            $tuple->[1] = FriendlyTimestamp($tuple->[1]);
2510        }
2511          # Return the sorted list.          # Return the sorted list.
2512          return @retVal;          return @retVal;
2513  }  }
# Line 1995  Line 2534 
2534  =back  =back
2535    
2536  =cut  =cut
2537    #: Return Type @;
2538  sub RoleNeighbors {  sub RoleNeighbors {
2539          # Get the parameters.          # Get the parameters.
2540          my $self = shift @_;      my ($self, $roleID) = @_;
         my ($roleID) = @_;  
2541          # Get all the diagrams containing this role.          # Get all the diagrams containing this role.
2542          my @diagrams = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],          my @diagrams = $self->GetFlat(['RoleOccursIn'], "RoleOccursIn(from-link) = ?", [$roleID],
2543                                                                    'RoleOccursIn(to-link)');                                                                    'RoleOccursIn(to-link)');
# Line 2038  Line 2576 
2576  =back  =back
2577    
2578  =cut  =cut
2579    #: Return Type @;
2580  sub FeatureLinks {  sub FeatureLinks {
2581          # Get the parameters.          # Get the parameters.
2582          my $self = shift @_;      my ($self, $featureID) = @_;
         my ($featureID) = @_;  
2583          # Get the feature's links.          # Get the feature's links.
2584          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(link)']);          my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(link)']);
2585          # Return the feature's links.          # Return the feature's links.
# Line 2054  Line 2591 
2591  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>
2592    
2593  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
2594  to the role the feature performs.  to the roles the feature performs.
2595    
2596  =over 4  =over 4
2597    
# Line 2064  Line 2601 
2601    
2602  =item RETURN  =item RETURN
2603    
2604  Returns a hash mapping all the feature's subsystems to the feature's role.  Returns a hash mapping all the feature's subsystems to a list of the feature's roles.
2605    
2606  =back  =back
2607    
2608  =cut  =cut
2609    #: Return Type %@;
2610  sub SubsystemsOf {  sub SubsystemsOf {
2611          # Get the parameters.          # Get the parameters.
2612          my $self = shift @_;      my ($self, $featureID) = @_;
2613          my ($featureID) = @_;      # Get the subsystem list.
         # Use the SSCell to connect features to subsystems.  
2614          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],
2615                                                                          "ContainsFeature(to-link) = ?", [$featureID],                                                                          "ContainsFeature(to-link) = ?", [$featureID],
2616                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);
2617          # Create the return value.          # Create the return value.
2618          my %retVal = ();          my %retVal = ();
2619        # Build a hash to weed out duplicates. Sometimes the same PEG and role appears
2620        # in two spreadsheet cells.
2621        my %dupHash = ();
2622          # Loop through the results, adding them to the hash.          # Loop through the results, adding them to the hash.
2623          for my $record (@subsystems) {          for my $record (@subsystems) {
2624                  $retVal{$record->[0]} = $record->[1];          # Get this subsystem and role.
2625            my ($subsys, $role) = @{$record};
2626            # Insure it's the first time for both.
2627            my $dupKey = "$subsys\n$role";
2628            if (! exists $dupHash{"$subsys\n$role"}) {
2629                $dupHash{$dupKey} = 1;
2630                push @{$retVal{$subsys}}, $role;
2631            }
2632          }          }
2633          # Return the hash.          # Return the hash.
2634          return %retVal;          return %retVal;
2635  }  }
2636    
2637    =head3 SubsystemList
2638    
2639    C<< my @subsystems = $sprout->SubsystemList($featureID); >>
2640    
2641    Return a list containing the names of the subsystems in which the specified
2642    feature participates. Unlike L</SubsystemsOf>, this method only returns the
2643    subsystem names, not the roles.
2644    
2645    =over 4
2646    
2647    =item featureID
2648    
2649    ID of the feature whose subsystem names are desired.
2650    
2651    =item RETURN
2652    
2653    Returns a list of the names of the subsystems in which the feature participates.
2654    
2655    =back
2656    
2657    =cut
2658    #: Return Type @;
2659    sub SubsystemList {
2660        # Get the parameters.
2661        my ($self, $featureID) = @_;
2662        # Get the list of names.
2663        my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",
2664                                    [$featureID], 'HasSSCell(from-link)');
2665        # Return the result.
2666        return @retVal;
2667    }
2668    
2669    
2670    
2671  =head3 RelatedFeatures  =head3 RelatedFeatures
2672    
2673  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 2118  Line 2698 
2698  =back  =back
2699    
2700  =cut  =cut
2701    #: Return Type @;
2702  sub RelatedFeatures {  sub RelatedFeatures {
2703          # Get the parameters.          # Get the parameters.
2704          my $self = shift @_;      my ($self, $featureID, $function, $userID) = @_;
         my ($featureID, $function, $userID) = @_;  
2705          # 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.
2706          my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],          my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],
2707                                                                           "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],                                                                           "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],
# Line 2167  Line 2746 
2746  =back  =back
2747    
2748  =cut  =cut
2749    #: Return Type @;
2750  sub TaxonomySort {  sub TaxonomySort {
2751          # Get the parameters.          # Get the parameters.
2752          my $self = shift @_;      my ($self, $featureIDs) = @_;
         my ($featureIDs) = @_;  
2753          # Create the working hash table.          # Create the working hash table.
2754          my %hashBuffer = ();          my %hashBuffer = ();
2755          # Loop through the features.          # Loop through the features.
# Line 2180  Line 2758 
2758                  my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",                  my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
2759                                                                                  [$fid], 'Genome(taxonomy)');                                                                                  [$fid], 'Genome(taxonomy)');
2760                  # Add this feature to the hash buffer.                  # Add this feature to the hash buffer.
2761                  if (exists $hashBuffer{$taxonomy}) {          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);
                         push @{$hashBuffer{$taxonomy}}, $fid;  
                 } else {  
                         $hashBuffer{$taxonomy} = [$fid];  
                 }  
2762          }          }
2763          # Sort the keys and get the elements.          # Sort the keys and get the elements.
2764          my @retVal = ();          my @retVal = ();
# Line 2195  Line 2769 
2769          return @retVal;          return @retVal;
2770  }  }
2771    
 =head3 GetAll  
   
 C<< my @list = $sprout->GetAll(\@objectNames, $filterClause, \@parameters, \@fields, $count); >>  
   
 Return a list of values taken from the objects returned by a query. The first three  
 parameters correspond to the parameters of the L</Get> method. The final parameter is  
 a list of the fields desired from each record found by the query. The field name  
 syntax is the standard syntax used for fields in the B<ERDB> system--  
 B<I<objectName>(I<fieldName>)>-- where I<objectName> is the name of the relevant entity  
 or relationship and I<fieldName> is the name of the field.  
   
 The list returned will be a list of lists. Each element of the list will contain  
 the values returned for the fields specified in the fourth parameter. If one of the  
 fields specified returns multiple values, they are flattened in with the rest. For  
 example, the following call will return a list of the features in a particular  
 spreadsheet cell, and each feature will be represented by a list containing the  
 feature ID followed by all of its aliases.  
   
 C<< $query = $sprout->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(alias)']); >>  
   
 =over 4  
   
 =item objectNames  
   
 List containing the names of the entity and relationship objects to be retrieved.  
   
 =item filterClause  
   
 WHERE/ORDER BY clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can  
 be parameterized with parameter markers (C<?>). Each field used must be specified in the standard form  
 B<I<objectName>(I<fieldName>)>. Any parameters specified in the filter clause should be added to the  
 parameter list as additional parameters. The fields in a filter clause can come from primary  
 entity relations, relationship relations, or secondary entity relations; however, all of the  
 entities and relationships involved must be included in the list of object names.  
   
 =item parameterList  
   
 List of the parameters to be substituted in for the parameters marks in the filter clause.  
   
 =item fields  
   
 List of the fields to be returned in each element of the list returned.  
   
 =item count  
   
 Maximum number of records to return. If omitted or 0, all available records will be returned.  
   
 =item RETURN  
   
 Returns a list of list references. Each element of the return list contains the values for the  
 fields specified in the B<fields> parameter.  
   
 =back  
   
 =cut  
   
 sub GetAll {  
         # Get the parameters.  
         my $self = shift @_;  
         my ($objectNames, $filterClause, $parameterList, $fields, $count) = @_;  
         # Create the query.  
         my $query = $self->Get($objectNames, $filterClause, $parameterList);  
         # 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++;  
         }  
         # Return the resulting list.  
         return @retVal;  
 }  
   
 =head3 GetFlat  
   
 C<< my @list = $sprout->GetFlat(\@objectNames, $filterClause, $parameterList, $field); >>  
   
 This is a variation of L</GetAll> that asks for only a single field per record and  
 returns a single flattened list.  
   
 =over 4  
   
 =item objectNames  
   
 List containing the names of the entity and relationship objects to be retrieved.  
   
 =item filterClause  
   
 WHERE/ORDER BY clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can  
 be parameterized with parameter markers (C<?>). Each field used must be specified in the standard form  
 B<I<objectName>(I<fieldName>)>. Any parameters specified in the filter clause should be added to the  
 parameter list as additional parameters. The fields in a filter clause can come from primary  
 entity relations, relationship relations, or secondary entity relations; however, all of the  
 entities and relationships involved must be included in the list of object names.  
   
 =item parameterList  
   
 List of the parameters to be substituted in for the parameters marks in the filter clause.  
   
 =item field  
   
 Name of the field to be used to get the elements of the list returned.  
   
 =item RETURN  
   
 Returns a list of values.  
   
 =back  
   
 =cut  
   
 sub GetFlat {  
         # Get the parameters.  
         my $self = shift @_;  
         my ($objectNames, $filterClause, $parameterList, $field) = @_;  
         # Construct the query.  
         my $query = $self->Get($objectNames, $filterClause, $parameterList);  
         # Create the result list.  
         my @retVal = ();  
         # Loop through the records, adding the field values found to the result list.  
         while (my $row = $query->Fetch()) {  
                 push @retVal, $row->Value($field);  
         }  
         # Return the list created.  
         return @retVal;  
 }  
   
2772  =head3 Protein  =head3 Protein
2773    
2774  C<< my $protein = Sprout::Protein($sequence, $table); >>  C<< my $protein = Sprout::Protein($sequence, $table); >>
# Line 2423  Line 2863 
2863  to load the entire database.  to load the entire database.
2864    
2865  =cut  =cut
2866    #: Return Type @;
2867  sub LoadInfo {  sub LoadInfo {
2868          # Get the parameters.          # Get the parameters.
2869          my $self = shift @_;      my ($self) = @_;
2870          # 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.
2871          my @retVal = ($self->{_options}->{dataDir});          my @retVal = ($self->{_options}->{dataDir});
2872          # Concatenate the table names.          # Concatenate the table names.
2873          push @retVal, $self->{_erdb}->GetTableNames();      push @retVal, $self->GetTableNames();
2874          # Return the result.          # Return the result.
2875          return @retVal;          return @retVal;
2876  }  }
2877    
2878  =head3 LowBBHs  =head3 LowBBHs
2879    
2880  C<< my %bbhMap = $sprout->GoodBBHs($featureID, $cutoff); >>  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>
2881    
2882  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
2883  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 2460  Line 2900 
2900  =back  =back
2901    
2902  =cut  =cut
2903    #: Return Type %;
2904  sub LowBBHs {  sub LowBBHs {
2905          # Get the parsameters.          # Get the parsameters.
2906          my $self = shift @_;      my ($self, $featureID, $cutoff) = @_;
         my ($featureID, $cutoff) = @_;  
2907          # Create the return hash.          # Create the return hash.
2908          my %retVal = ();          my %retVal = ();
2909          # Create a query to get the desired BBHs.          # Create a query to get the desired BBHs.
# Line 2480  Line 2919 
2919          return %retVal;          return %retVal;
2920  }  }
2921    
2922    =head3 GetGroups
2923    
2924    C<< my %groups = $sprout->GetGroups(\@groupList); >>
2925    
2926    Return a hash mapping each group to the IDs of the genomes in the group.
2927    A list of groups may be specified, in which case only those groups will be
2928    shown. Alternatively, if no parameter is supplied, all groups will be
2929    included. Genomes that are not in any group are omitted.
2930    
2931    =cut
2932    #: Return Type %@;
2933    sub GetGroups {
2934        # Get the parameters.
2935        my ($self, $groupList) = @_;
2936        # Declare the return value.
2937        my %retVal = ();
2938        # Determine whether we are getting all the groups or just some.
2939        if (defined $groupList) {
2940            # Here we have a group list. Loop through them individually,
2941            # getting a list of the relevant genomes.
2942            for my $group (@{$groupList}) {
2943                my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",
2944                    [$group], "Genome(id)");
2945                $retVal{$group} = \@genomeIDs;
2946            }
2947        } else {
2948            # Here we need all of the groups. In this case, we run through all
2949            # of the genome records, putting each one found into the appropriate
2950            # group. Note that we use a filter clause to insure that only genomes
2951            # in groups are included in the return set.
2952            my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],
2953                                        ['Genome(id)', 'Genome(group-name)']);
2954            # Loop through the genomes found.
2955            for my $genome (@genomes) {
2956                # Pop this genome's ID off the current list.
2957                my @groups = @{$genome};
2958                my $genomeID = shift @groups;
2959                # Loop through the groups, adding the genome ID to each group's
2960                # list.
2961                for my $group (@groups) {
2962                    Tracer::AddToListMap(\%retVal, $group, $genomeID);
2963                }
2964            }
2965        }
2966        # Return the hash we just built.
2967        return %retVal;
2968    }
2969    
2970    =head3 MyGenomes
2971    
2972    C<< my @genomes = Sprout::MyGenomes($dataDir); >>
2973    
2974    Return a list of the genomes to be included in the Sprout.
2975    
2976    This method is provided for use during the Sprout load. It presumes the Genome load file has
2977    already been created. (It will be in the Sprout data directory and called either C<Genome>
2978    or C<Genome.dtx>.) Essentially, it reads in the Genome load file and strips out the genome
2979    IDs.
2980    
2981    =over 4
2982    
2983    =item dataDir
2984    
2985    Directory containing the Sprout load files.
2986    
2987    =back
2988    
2989    =cut
2990    #: Return Type @;
2991    sub MyGenomes {
2992        # Get the parameters.
2993        my ($dataDir) = @_;
2994        # Compute the genome file name.
2995        my $genomeFileName = LoadFileName($dataDir, "Genome");
2996        # Extract the genome IDs from the files.
2997        my @retVal = map { $_ =~ /^(\S+)/; $1 } Tracer::GetFile($genomeFileName);
2998        # Return the result.
2999        return @retVal;
3000    }
3001    
3002    =head3 LoadFileName
3003    
3004    C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>
3005    
3006    Return the name of the load file for the specified table in the specified data
3007    directory.
3008    
3009    =over 4
3010    
3011    =item dataDir
3012    
3013    Directory containing the Sprout load files.
3014    
3015    =item tableName
3016    
3017    Name of the table whose load file is desired.
3018    
3019    =item RETURN
3020    
3021    Returns the name of the file containing the load data for the specified table, or
3022    C<undef> if no load file is present.
3023    
3024    =back
3025    
3026    =cut
3027    #: Return Type $;
3028    sub LoadFileName {
3029        # Get the parameters.
3030        my ($dataDir, $tableName) = @_;
3031        # Declare the return variable.
3032        my $retVal;
3033        # Check for the various file names.
3034        if (-e "$dataDir/$tableName") {
3035            $retVal = "$dataDir/$tableName";
3036        } elsif (-e "$dataDir/$tableName.dtx") {
3037            $retVal = "$dataDir/$tableName.dtx";
3038        }
3039        # Return the result.
3040        return $retVal;
3041    }
3042    
3043    =head3 DeleteGenome
3044    
3045    C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>
3046    
3047    Delete a genome from the database.
3048    
3049    =over 4
3050    
3051    =item genomeID
3052    
3053    ID of the genome to delete
3054    
3055    =item testFlag
3056    
3057    If TRUE, then the DELETE statements will be traced, but no deletions will occur.
3058    
3059    =item RETURN
3060    
3061    Returns a statistics object describing the rows deleted.
3062    
3063    =back
3064    
3065    =cut
3066    #: Return Type $%;
3067    sub DeleteGenome {
3068        # Get the parameters.
3069        my ($self, $genomeID, $testFlag) = @_;
3070        # Perform the delete for the genome's features.
3071        my $retVal = $self->Delete('Feature', "fig|$genomeID.%", $testFlag);
3072        # Perform the delete for the primary genome data.
3073        my $stats = $self->Delete('Genome', $genomeID, $testFlag);
3074        $retVal->Accumulate($stats);
3075        # Return the result.
3076        return $retVal;
3077    }
3078    
3079  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3080    
3081  =head3 ParseAssignment  =head3 ParseAssignment
3082    
3083  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,
3084  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
3085  will be returned.  isn't, an empty list will be returned.
3086    
3087    A functional assignment is always of the form
3088    
3089        C<set >I<YYYY>C< function to\n>I<ZZZZZ>
3090    
3091    where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
3092    the user and the assigning user (from MadeAnnotation) will be the same, but that is
3093    not always the case.
3094    
3095    In addition, the functional role may contain extra data that is stripped, such as
3096    terminating spaces or a comment separated from the rest of the text by a tab.
3097    
3098  This is a static method.  This is a static method.
3099    
3100  =over 4  =over 4
3101    
3102    =item user
3103    
3104    Name of the assigning user.
3105    
3106  =item text  =item text
3107    
3108  Text of the annotation.  Text of the annotation.
# Line 2505  Line 3116 
3116    
3117  =cut  =cut
3118    
3119  sub ParseAssignment {  sub _ParseAssignment {
3120          # Get the parameters.          # Get the parameters.
3121          my ($text) = @_;      my ($user, $text) = @_;
3122          # Declare the return value.          # Declare the return value.
3123          my @retVal = ();          my @retVal = ();
3124          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
3125          my ($user, $type, $function) = split(/\n/, $text);      my ($type, $function) = split(/\n/, $text);
3126          if ($type =~ m/^set $user function to$/i) {      if ($type =~ m/^set function to$/i) {
3127                  # Here it is, so we return the user name and function text.          # Here we have an assignment without a user, so we use the incoming user ID.
3128                  @retVal = ($user, $function);                  @retVal = ($user, $function);
3129        } elsif ($type =~ m/^set (\S+) function to$/i) {
3130            # Here we have an assignment with a user that is passed back to the caller.
3131            @retVal = ($1, $function);
3132        }
3133        # If we have an assignment, we need to clean the function text. There may be
3134        # extra junk at the end added as a note from the user.
3135        if (@retVal) {
3136            $retVal[1] =~ s/(\t\S)?\s*$//;
3137          }          }
3138          # Return the result list.          # Return the result list.
3139          return @retVal;          return @retVal;
3140  }  }
3141    
3142    =head3 FriendlyTimestamp
3143    
3144    Convert a time number to a user-friendly time stamp for display.
3145    
3146    This is a static method.
3147    
3148    =over 4
3149    
3150    =item timeValue
3151    
3152    Numeric time value.
3153    
3154    =item RETURN
3155    
3156    Returns a string containing the same time in user-readable format.
3157    
3158    =back
3159    
3160    =cut
3161    
3162    sub FriendlyTimestamp {
3163        my ($timeValue) = @_;
3164        my $retVal = localtime($timeValue);
3165        return $retVal;
3166    }
3167    
3168    =head3 AddProperty
3169    
3170    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3171    
3172    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3173    be added to almost any object. In Sprout, they can only be added to features. In
3174    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3175    pair. If the particular key/value pair coming in is not already in the database, a new
3176    B<Property> record is created to hold it.
3177    
3178    =over 4
3179    
3180    =item peg
3181    
3182    ID of the feature to which the attribute is to be replied.
3183    
3184    =item key
3185    
3186    Name of the attribute (key).
3187    
3188    =item value
3189    
3190    Value of the attribute.
3191    
3192    =item url
3193    
3194    URL or text citation from which the property was obtained.
3195    
3196    =back
3197    
3198    =cut
3199    #: Return Type ;
3200    sub AddProperty {
3201        # Get the parameters.
3202        my ($self, $featureID, $key, $value, $url) = @_;
3203        # Declare the variable to hold the desired property ID.
3204        my $propID;
3205        # Attempt to find a property record for this key/value pair.
3206        my @properties = $self->GetFlat(['Property'],
3207                                       "Property(property-name) = ? AND Property(property-value) = ?",
3208                                       [$key, $value], 'Property(id)');
3209        if (@properties) {
3210            # Here the property is already in the database. We save its ID.
3211            $propID = $properties[0];
3212            # Here the property value does not exist. We need to generate an ID. It will be set
3213            # to a number one greater than the maximum value in the database. This call to
3214            # GetAll will stop after one record.
3215            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3216                                            1);
3217            $propID = $maxProperty[0]->[0] + 1;
3218            # Insert the new property value.
3219            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3220        }
3221        # Now we connect the incoming feature to the property.
3222        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3223    }
3224    
3225    
3226  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.59

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3