[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.55, Mon Apr 3 18:33:58 2006 UTC revision 1.109, Sun Mar 23 16:32:05 2008 UTC
# Line 2  Line 2 
2    
3      use Data::Dumper;      use Data::Dumper;
4      use strict;      use strict;
     use Carp;  
5      use DBKernel;      use DBKernel;
6      use XML::Simple;      use XML::Simple;
7      use DBQuery;      use DBQuery;
8      use DBObject;      use ERDBObject;
     use ERDB;  
9      use Tracer;      use Tracer;
10      use FIGRules;      use FIGRules;
11        use FidCheck;
12      use Stats;      use Stats;
13      use POSIX qw(strftime);      use POSIX qw(strftime);
14        use BasicLocation;
15        use CustomAttributes;
16        use RemoteCustomAttributes;
17        use CGI;
18        use base qw(ERDB);
19    
20  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
21    
# Line 25  Line 28 
28  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>
29  whose definition and data files are in a co-directory named F<Data>.  whose definition and data files are in a co-directory named F<Data>.
30    
31  C<< my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' }); >>      my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' });
32    
33  Once you have a sprout object, you may use it to re-create the database, load the tables from  Once you have a sprout object, you may use it to re-create the database, load the tables from
34  tab-delimited flat files and perform queries. Several special methods are provided for common  tab-delimited flat files and perform queries. Several special methods are provided for common
35  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
36  L</dna_seq> returns the DNA sequence for a specified genome location.  L</DNASeq> returns the DNA sequence for a specified genome location.
37    
38    The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.
39    
40  =cut  =cut
41    
# Line 40  Line 45 
45    
46  =head3 new  =head3 new
47    
48  C<< my $sprout = Sprout->new($dbName, \%options); >>      my $sprout = Sprout->new($dbName, \%options);
49    
50  This is the constructor for a sprout object. It connects to the database and loads the  This is the constructor for a sprout object. It connects to the database and loads the
51  database definition into memory. The positional first parameter specifies the name of the  database definition into memory. The positional first parameter specifies the name of the
# Line 62  Line 67 
67    
68  * 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>)
69    
70  * 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)
71    
72  * B<port> connection port (default C<0>)  * B<port> connection port (default C<0>)
73    
74    * B<sock> connection socket (default same as SEED)
75    
76  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)
77    
78  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)
79    
80  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE  * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE
81    
82    * B<host> name of the database host
83    
84  =back  =back
85    
86  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
87  I<fig> with a password of I<admin>. The database load files are in the directory  I<fig> with a password of I<admin>. The database load files are in the directory
88  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
89    
90  C<< my $sprout = Sprout->new('Sprout', { userData =>; 'fig/admin', dataDir => '/usr/fig/SproutData' }); >>      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });
91    
92  =cut  =cut
93    
94  sub new {  sub new {
95      # Get the parameters.      # Get the parameters.
96      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
97        # Compute the DBD directory.
98        my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
99                                                      $FIG_Config::fig );
100      # 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
101      # the incoming data.      # the incoming data.
102      my $optionTable = Tracer::GetOptions({      my $optionTable = Tracer::GetOptions({
# Line 92  Line 104 
104                                                          # database type                                                          # database type
105                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
106                                                          # data file directory                                                          # data file directory
107                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
108                                                          # database definition file name                                                          # database definition file name
109                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
110                                                          # user name and password                                                          # user name and password
111                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
112                                                          # database connection port                                                          # database connection port
113                           sock         => $FIG_Config::dbsock,
114                           host         => $FIG_Config::sprout_host,
115                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
116                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
117                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 110  Line 124 
124      # Connect to the database.      # Connect to the database.
125      my $dbh;      my $dbh;
126      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
127            Trace("Connect data: host = $optionTable->{host}, port = $optionTable->{port}.") if T(3);
128          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
129                                  $password, $optionTable->{port});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
130      }      }
131      # Create the ERDB object.      # Create the ERDB object.
132      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
133      my $erdb = ERDB->new($dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName);
134      # Create this object.      # Add the option table and XML file name.
135      my $self = { _erdb => $erdb, _options => $optionTable, _xmlName => $xmlFileName };      $retVal->{_options} = $optionTable;
136      # Bless and return it.      $retVal->{_xmlName} = $xmlFileName;
137      bless $self;      # Set up space for the group file data.
138      return $self;      $retVal->{groupHash} = undef;
139  }      # Set up space for the genome hash. We use this to identify NMPDR genomes.
140        $retVal->{genomeHash} = undef;
141  =head3 MaxSegment      # Connect to the attributes.
142        if ($FIG_Config::attrURL) {
143  C<< my $length = $sprout->MaxSegment(); >>          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
144            $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);
145  This method returns the maximum permissible length of a feature segment. The length is important      } elsif ($FIG_Config::attrDbName) {
146  because it enables us to make reasonable guesses at how to find features inside a particular          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
147  contig region. For example, if the maximum length is 4000 and we're looking for a feature that          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
148  overlaps the region from 6000 to 7000 we know that the starting position must be between 2001          $retVal->{_ca} = CustomAttributes->new(user => $user);
 and 10999.  
   
 =cut  
 #: Return Type $;  
 sub MaxSegment {  
     my ($self) = @_;  
     return $self->{_options}->{maxSegmentLength};  
149  }  }
150        # Return it.
151  =head3 MaxSequence      return $retVal;
   
 C<< my $length = $sprout->MaxSequence(); >>  
   
 This method returns the maximum permissible length of a contig sequence. A contig is broken  
 into sequences in order to save memory resources. In particular, when manipulating features,  
 we generally only need a few sequences in memory rather than the entire contig.  
   
 =cut  
 #: Return Type $;  
 sub MaxSequence {  
     my ($self) = @_;  
     return $self->{_options}->{maxSequenceLength};  
152  }  }
153    
154  =head3 Get  =head3 CoreGenomes
   
 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]); >>  
   
 It is also permissible to specify I<only> an ORDER BY clause. For example, the following invocation gets  
 all genomes ordered by genus and species.  
155    
156  C<< $query = $sprout->Get(['Genome'], "ORDER BY Genome(genus), Genome(species)"); >>      my @genomes = $sprout->CoreGenomes($scope);
157    
158  Odd things may happen if one of the ORDER BY fields is in a secondary relation. So, for example, an  Return the IDs of NMPDR genomes in the specified scope.
 attempt to order B<Feature>s by alias may (depending on the underlying database engine used) cause  
 a single feature to appear more than once.  
   
 If multiple names are specified, then the query processor will automatically determine a  
 join path between the entities and relationships. The algorithm used is very simplistic.  
 In particular, you can't specify any entity or relationship more than once, and if a  
 relationship is recursive, the path is determined by the order in which the entity  
 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.  
159    
160  =over 4  =over 4
161    
162  =item objectNames  =item scope
   
 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.  
163    
164  =item parameterList  Scope of the desired genomes. C<core> covers the original core genomes,
165    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
166  List of the parameters to be substituted in for the parameters marks in the filter clause.  genomes in the system.
167    
168  =item RETURN  =item RETURN
169    
170  Returns a B<DBQuery> that can be used to iterate through all of the results.  Returns a list of the IDs for the genomes in the specified scope.
171    
172  =back  =back
173    
174  =cut  =cut
175    
176  sub Get {  sub CoreGenomes {
177      # Get the parameters.      # Get the parameters.
178      my ($self, $objectNames, $filterClause, $parameterList) = @_;      my ($self, $scope) = @_;
179      # We differ from the ERDB Get method in that the parameter list is passed in as a list reference      # Declare the return variable.
180      # rather than a list of parameters. The next step is to convert the parameters from a reference      my @retVal = ();
181      # to a real list. We can only do this if the parameters have been specified.      # If we want all genomes, then this is easy.
182      my @parameters;      if ($scope eq 'all') {
183      if ($parameterList) { @parameters = @{$parameterList}; }          @retVal = $self->Genomes();
184      return $self->{_erdb}->Get($objectNames, $filterClause, @parameters);      } else {
185            # Here we're dealing with groups. Get the hash of all the
186            # genome groups.
187            my %groups = $self->GetGroups();
188            # Loop through the groups, keeping the ones that we want.
189            for my $group (keys %groups) {
190                # Decide if we want to keep this group.
191                my $keepGroup = 0;
192                if ($scope eq 'nmpdr') {
193                    # NMPDR mode: keep all groups.
194                    $keepGroup = 1;
195                } elsif ($scope eq 'core') {
196                    # CORE mode. Only keep real core groups.
197                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
198                        $keepGroup = 1;
199                    }
200                }
201                # Add this group if we're keeping it.
202                if ($keepGroup) {
203                    push @retVal, @{$groups{$group}};
204                }
205            }
206        }
207        # Return the result.
208        return @retVal;
209  }  }
210    
211  =head3 GetEntity  =head3 SuperGroup
212    
213  C<< my $entityObject = $sprout->GetEntity($entityType, $ID); >>      my $superGroup = $sprout->SuperGroup($groupName);
214    
215  Return an object describing the entity instance with a specified ID.  Return the name of the super-group containing the specified NMPDR genome
216    group. If no appropriate super-group can be found, an error will be
217    thrown.
218    
219  =over 4  =over 4
220    
221  =item entityType  =item groupName
   
 Entity type name.  
222    
223  =item ID  Name of the group whose super-group is desired.
   
 ID of the desired entity.  
224    
225  =item RETURN  =item RETURN
226    
227  Returns a B<DBObject> representing the desired entity instance, or an undefined value if no  Returns the name of the super-group containing the incoming group.
 instance is found with the specified key.  
228    
229  =back  =back
230    
231  =cut  =cut
232    
233  sub GetEntity {  sub SuperGroup {
234      # Get the parameters.      # Get the parameters.
235      my ($self, $entityType, $ID) = @_;      my ($self, $groupName) = @_;
236      # Call the ERDB method.      # Declare the return variable.
237      return $self->{_erdb}->GetEntity($entityType, $ID);      my $retVal;
238        # Get the group hash.
239        my %groupHash = $self->CheckGroupFile();
240        # Find the super-group genus.
241        $groupName =~ /([A-Z]\w+)/;
242        my $nameThing = $1;
243        # See if it's directly in the group hash.
244        if (exists $groupHash{$nameThing}) {
245            # Yes, then it's our result.
246            $retVal = $nameThing;
247        } else {
248            # No, so we have to search.
249            for my $superGroup (keys %groupHash) {
250                # Get this super-group's item list.
251                my $list = $groupHash{$superGroup}->{contents};
252                # Search it.
253                if (grep { $_->[0] eq $nameThing } @{$list}) {
254                    $retVal = $superGroup;
255                }
256            }
257            # Make sure we found something.
258            if (! $retVal) {
259                Confess("No super-group found for \"$groupName\".");
260            }
261        }
262        # Return the result.
263        return $retVal;
264  }  }
265    
266  =head3 GetEntityValues  =head3 MaxSegment
   
 C<< my @values = GetEntityValues($entityType, $ID, \@fields); >>  
   
 Return a list of values from a specified entity instance.  
   
 =over 4  
   
 =item entityType  
   
 Entity type name.  
   
 =item ID  
   
 ID of the desired entity.  
   
 =item fields  
   
 List of field names, each of the form I<objectName>C<(>I<fieldName>C<)>.  
   
 =item RETURN  
267    
268  Returns a flattened list of the values of the specified fields for the specified entity.      my $length = $sprout->MaxSegment();
269    
270  =back  This method returns the maximum permissible length of a feature segment. The length is important
271    because it enables us to make reasonable guesses at how to find features inside a particular
272    contig region. For example, if the maximum length is 4000 and we're looking for a feature that
273    overlaps the region from 6000 to 7000 we know that the starting position must be between 2001
274    and 10999.
275    
276  =cut  =cut
277  #: Return Type @;  #: Return Type $;
278  sub GetEntityValues {  sub MaxSegment {
279      # Get the parameters.      my ($self) = @_;
280      my ($self, $entityType, $ID, $fields) = @_;      return $self->{_options}->{maxSegmentLength};
     # Call the ERDB method.  
     return $self->{_erdb}->GetEntityValues($entityType, $ID, $fields);  
281  }  }
282    
283  =head3 ShowMetaData  =head3 MaxSequence
   
 C<< $sprout->ShowMetaData($fileName); >>  
   
 This method outputs a description of the database to an HTML file in the data directory.  
   
 =over 4  
   
 =item fileName  
284    
285  Fully-qualified name to give to the output file.      my $length = $sprout->MaxSequence();
286    
287  =back  This method returns the maximum permissible length of a contig sequence. A contig is broken
288    into sequences in order to save memory resources. In particular, when manipulating features,
289    we generally only need a few sequences in memory rather than the entire contig.
290    
291  =cut  =cut
292    #: Return Type $;
293  sub ShowMetaData {  sub MaxSequence {
294      # Get the parameters.      my ($self) = @_;
295      my ($self, $fileName) = @_;      return $self->{_options}->{maxSequenceLength};
     # Compute the file name.  
     my $options = $self->{_options};  
     # Call the show method on the underlying ERDB object.  
     $self->{_erdb}->ShowMetaData($fileName);  
296  }  }
297    
298  =head3 Load  =head3 Load
299    
300  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
301    
302  Load the database from files in the data directory, optionally re-creating the tables.  Load the database from files in the data directory, optionally re-creating the tables.
303    
# Line 379  Line 329 
329  sub Load {  sub Load {
330      # Get the parameters.      # Get the parameters.
331      my ($self, $rebuild) = @_;      my ($self, $rebuild) = @_;
     # Get the database object.  
     my $erdb = $self->{_erdb};  
332      # Load the tables from the data directory.      # Load the tables from the data directory.
333      my $retVal = $erdb->LoadTables($self->{_options}->{dataDir}, $rebuild);      my $retVal = $self->LoadTables($self->{_options}->{dataDir}, $rebuild);
334      # Return the statistics.      # Return the statistics.
335      return $retVal;      return $retVal;
336  }  }
337    
338  =head3 LoadUpdate  =head3 LoadUpdate
339    
340  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
341    
342  Load updates to one or more database tables. This method enables the client to make changes to one  Load updates to one or more database tables. This method enables the client to make changes to one
343  or two tables without reloading the whole database. For each table, there must be a corresponding  or two tables without reloading the whole database. For each table, there must be a corresponding
# Line 422  Line 370 
370  sub LoadUpdate {  sub LoadUpdate {
371      # Get the parameters.      # Get the parameters.
372      my ($self, $truncateFlag, $tableList) = @_;      my ($self, $truncateFlag, $tableList) = @_;
     # Get the database object.  
     my $erdb = $self->{_erdb};  
373      # Declare the return value.      # Declare the return value.
374      my $retVal = Stats->new();      my $retVal = Stats->new();
375      # Get the data directory.      # Get the data directory.
# Line 437  Line 383 
383              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
384          } else {          } else {
385              # Attempt to load this table.              # Attempt to load this table.
386              my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
387              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
388              $retVal->Accumulate($result);              $retVal->Accumulate($result);
389          }          }
# Line 446  Line 392 
392      return $retVal;      return $retVal;
393  }  }
394    
395    =head3 GenomeCounts
396    
397        my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
398    
399    Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
400    genomes will be included in the counts.
401    
402    =over 4
403    
404    =item complete
405    
406    TRUE if only complete genomes are to be counted, FALSE if all genomes are to be
407    counted
408    
409    =item RETURN
410    
411    A six-element list containing the number of genomes in each of six categories--
412    Archaea, Bacteria, Eukaryota, Viral, Environmental, and Unknown, respectively.
413    
414    =back
415    
416    =cut
417    
418    sub GenomeCounts {
419        # Get the parameters.
420        my ($self, $complete) = @_;
421        # Set the filter based on the completeness flag.
422        my $filter = ($complete ? "Genome(complete) = 1" : "");
423        # Get all the genomes and the related taxonomy information.
424        my @genomes = $self->GetAll(['Genome'], $filter, [], ['Genome(id)', 'Genome(taxonomy)']);
425        # Clear the counters.
426        my ($arch, $bact, $euk, $vir, $env, $unk) = (0, 0, 0, 0, 0, 0);
427        # Loop through, counting the domains.
428        for my $genome (@genomes) {
429            if    ($genome->[1] =~ /^archaea/i)  { ++$arch }
430            elsif ($genome->[1] =~ /^bacter/i)   { ++$bact }
431            elsif ($genome->[1] =~ /^eukar/i)    { ++$euk }
432            elsif ($genome->[1] =~ /^vir/i)      { ++$vir }
433            elsif ($genome->[1] =~ /^env/i)      { ++$env }
434            else  { ++$unk }
435        }
436        # Return the counts.
437        return ($arch, $bact, $euk, $vir, $env, $unk);
438    }
439    
440    =head3 ContigCount
441    
442        my $count = $sprout->ContigCount($genomeID);
443    
444    Return the number of contigs for the specified genome ID.
445    
446    =over 4
447    
448    =item genomeID
449    
450    ID of the genome whose contig count is desired.
451    
452    =item RETURN
453    
454    Returns the number of contigs for the specified genome.
455    
456    =back
457    
458    =cut
459    
460    sub ContigCount {
461        # Get the parameters.
462        my ($self, $genomeID) = @_;
463        # Get the contig count.
464        my $retVal = $self->GetCount(['Contig', 'HasContig'], "HasContig(from-link) = ?", [$genomeID]);
465        # Return the result.
466        return $retVal;
467    }
468    
469    =head3 GenomeMenu
470    
471        my $html = $sprout->GenomeMenu(%options);
472    
473    Generate a genome selection control with the specified name and options.
474    This control is almost but not quite the same as the genome control in the
475    B<SearchHelper> class. Eventually, the two will be combined.
476    
477    =over 4
478    
479    =item options
480    
481    Optional parameters for the control (see below).
482    
483    =item RETURN
484    
485    Returns the HTML for a genome selection control on a form (sometimes called a popup menu).
486    
487    =back
488    
489    The valid options are as follows.
490    
491    =over 4
492    
493    =item name
494    
495    Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
496    Terrible things will happen if you have two controls with the same name on the same page.
497    
498    =item filter
499    
500    If specified, a filter for the list of genomes to display. The filter should be in the form of a
501    list reference. The first element of the list should be the filter string, and the remaining elements
502    the filter parameters.
503    
504    =item multiSelect
505    
506    If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
507    
508    =item size
509    
510    Number of rows to display in the control. The default is C<10>
511    
512    =item id
513    
514    ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
515    unless this ID is unique.
516    
517    =item selected
518    
519    A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
520    default is none.
521    
522    =item inTable
523    
524    If TRUE, then backslashes will be included at the end of each line in the resulting HTML. This enables the control
525    to be used in TWiki tables.
526    
527    =back
528    
529    =cut
530    
531    sub GenomeMenu {
532        # Get the parameters.
533        my ($self, %options) = @_;
534        # Get the control's name and ID.
535        my $menuName = $options{name} || 'myGenomeControl';
536        my $menuID = $options{id} || $menuName;
537        # Compute the IDs for the status display.
538        my $divID = "${menuID}_status";
539        my $urlID = "${menuID}_url";
540        # Compute the code to show selected genomes in the status area.
541        my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
542        # Check for single-select or multi-select.
543        my $multiSelect = $options{multiSelect} || 0;
544        # Get the list of pre-selected items.
545        my $selections = $options{selected} || [];
546        if (ref $selections ne 'ARRAY') {
547            $selections = [ split /\s*,\s*/, $selections ];
548        }
549        my %selected = map { $_ => } @{$selections};
550        # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
551        # string or a list reference.
552        my $filterParms = $options{filter} || "";
553        if (! ref $filterParms) {
554            $filterParms = [split /\t|\\t/, $filterParms];
555        }
556        my $filterString = shift @{$filterParms};
557        # Get a list of all the genomes in group order. In fact, we only need them ordered
558        # by name (genus,species,strain), but putting primary-group in front enables us to
559        # take advantage of an existing index.
560        my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
561                                       $filterParms,
562                                       [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
563        # Create a hash to organize the genomes by group. Each group will contain a list of
564        # 2-tuples, the first element being the genome ID and the second being the genome
565        # name.
566        my %gHash = ();
567        for my $genome (@genomeList) {
568            # Get the genome data.
569            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
570            # Compute its name. This is the genus, species, strain (if any), and the contig count.
571            my $name = "$genus $species ";
572            $name .= "$strain " if $strain;
573            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
574            # Now we get the domain. The domain tells us the display style of the organism.
575            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
576            # Now compute the display group. This is normally the primary group, but if the
577            # organism is supporting, we blank it out.
578            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
579            # Push the genome into the group's list. Note that we use the real group
580            # name for the hash key here, not the display group name.
581            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
582        }
583        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
584        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
585        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
586        # that aren't "other". At some point, we will want to make this less complicated.
587        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
588                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
589        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
590        # Remember the number of NMPDR groups.
591        my $nmpdrGroupCount = scalar @groups;
592        # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
593        # of the domains found.
594        my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
595        my @domains = ();
596        for my $genomeData (@otherGenomes) {
597            my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
598            if (exists $gHash{$domain}) {
599                push @{$gHash{$domain}}, $genomeData;
600            } else {
601                $gHash{$domain} = [$genomeData];
602                push @domains, $domain;
603            }
604        }
605        # Add the domain groups at the end of the main group list. The main group list will now
606        # contain all the categories we need to display the genomes.
607        push @groups, sort @domains;
608        # Delete the supporting group.
609        delete $gHash{$FIG_Config::otherGroup};
610        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
611        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
612        # and use that to make the selections.
613        my $nmpdrCount = 0;
614        # Create the type counters.
615        my $groupCount = 1;
616        # Get the number of rows to display.
617        my $rows = $options{size} || 10;
618        # If we're multi-row, create an onChange event.
619        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
620        # Set up the multiple-select flag.
621        my $multipleTag = ($multiSelect ? " multiple" : "" );
622        # Create the SELECT tag and stuff it into the output array.
623        my @lines = ("<SELECT name=\"$menuID\" id=\"$menuID\" $onChangeTag$multipleTag size=\"$rows\" style=\"width: 100%\">");
624        # Loop through the groups.
625        for my $group (@groups) {
626            # Get the genomes in the group.
627            for my $genome (@{$gHash{$group}}) {
628                # If this is an NMPDR organism, we add an extra style and count it.
629                my $nmpdrStyle = "";
630                if ($nmpdrGroupCount > 0) {
631                    $nmpdrCount++;
632                    $nmpdrStyle = " Core";
633                }
634                # Get the organism ID, name, contig count, and domain.
635                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
636                # See if we're pre-selected.
637                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
638                # Compute the display name.
639                my $nameString = "$name ($genomeID$contigCount)";
640                # Generate the option tag.
641                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
642                push @lines, "    $optionTag";
643            }
644            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
645            # groups.
646            $nmpdrGroupCount--;
647        }
648        # Close the SELECT tag.
649        push @lines, "</SELECT>";
650        if ($rows > 1) {
651            # We're in a non-compact mode, so we need to add some selection helpers. First is
652            # the search box. This allows the user to type text and change which genomes are
653            # displayed. For multiple-select mode, we include a button that selects the displayed
654            # genes. For single-select mode, we use a plain label instead.
655            my $searchThingName = "${menuID}_SearchThing";
656            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
657                                                 : "Show genomes containing");
658            push @lines, "<br />$searchThingLabel&nbsp;" .
659                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />";
660            # For multi-select mode, we also have buttons to set and clear selections.
661            if ($multiSelect) {
662                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";
663                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";
664                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";
665            }
666            # Add a hidden field we can use to generate organism page hyperlinks.
667            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/seedviewer.cgi?page=Organism;organism=\" />";
668            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
669            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
670        }
671        # Assemble all the lines into a string. This is where we do the "inTable" thing to insure we don't mess up TWiki tables.
672        my $delim = ($options{inTable} ? "\\" : "" ) . "\n";
673        my $retVal = join($delim, @lines, "");
674        # Return the result.
675        return $retVal;
676    }
677    
678    
679  =head3 Build  =head3 Build
680    
681  C<< $sprout->Build(); >>      $sprout->Build();
682    
683  Build the database. The database will be cleared and the tables re-created from the metadata.  Build the database. The database will be cleared and the tables re-created from the metadata.
684  This method is useful when a database is brand new or when the database definition has  This method is useful when a database is brand new or when the database definition has
# Line 460  Line 690 
690      # Get the parameters.      # Get the parameters.
691      my ($self) = @_;      my ($self) = @_;
692      # Create the tables.      # Create the tables.
693      $self->{_erdb}->CreateTables;      $self->CreateTables();
694  }  }
695    
696  =head3 Genomes  =head3 Genomes
697    
698  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
699    
700  Return a list of all the genome IDs.  Return a list of all the genome IDs.
701    
# Line 482  Line 712 
712    
713  =head3 GenusSpecies  =head3 GenusSpecies
714    
715  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
716    
717  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
718    
# Line 514  Line 744 
744    
745  =head3 FeaturesOf  =head3 FeaturesOf
746    
747  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
748    
749  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
750    
# Line 559  Line 789 
789    
790  =head3 FeatureLocation  =head3 FeatureLocation
791    
792  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
793    
794  Return the location of a feature in its genome's contig segments. In a list context, this method  Return the location of a feature in its genome's contig segments. In a list context, this method
795  will return a list of the locations. In a scalar context, it will return the locations as a space-  will return a list of the locations. In a scalar context, it will return the locations as a space-
# Line 588  Line 818 
818  =back  =back
819    
820  =cut  =cut
821  #: Return Type @;  
 #: Return Type $;  
822  sub FeatureLocation {  sub FeatureLocation {
823      # Get the parameters.      # Get the parameters.
824      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
825      # Create a query for the feature locations.      # Get the feature record.
826      my $query = $self->Get(['IsLocatedIn'], "IsLocatedIn(from-link) = ? ORDER BY IsLocatedIn(locN)",      my $object = $self->GetEntity('Feature', $featureID);
827                             [$featureID]);      Confess("Feature $featureID not found.") if ! defined($object);
828        # Get the location string.
829        my $locString = $object->PrimaryValue('Feature(location-string)');
830      # Create the return list.      # Create the return list.
831      my @retVal = ();      my @retVal = split /\s*,\s*/, $locString;
     # Set up the variables used to determine if we have adjacent segments. This initial setup will  
     # not match anything.  
     my ($prevContig, $prevBeg, $prevDir, $prevLen) = ("", 0, "0", 0);  
     # Loop through the query results, creating location specifiers.  
     while (my $location = $query->Fetch()) {  
         # Get the location parameters.  
         my ($contigID, $beg, $dir, $len) = $location->Values(['IsLocatedIn(to-link)',  
             'IsLocatedIn(beg)', 'IsLocatedIn(dir)', 'IsLocatedIn(len)']);  
         # Check to see if we are adjacent to the previous segment.  
         if ($prevContig eq $contigID && $dir eq $prevDir) {  
             # Here the new segment is in the same direction on the same contig. Insure the  
             # new segment's beginning is next to the old segment's end.  
             if ($dir eq "-" && $beg + $len == $prevBeg) {  
                 # Here we're merging two backward blocks, so we keep the new begin point  
                 # and adjust the length.  
                 $len += $prevLen;  
                 # Pop the old segment off. The new one will replace it later.  
                 pop @retVal;  
             } elsif ($dir eq "+" && $beg == $prevBeg + $prevLen) {  
                 # Here we need to merge two forward blocks. Adjust the beginning and  
                 # length values to include both segments.  
                 $beg = $prevBeg;  
                 $len += $prevLen;  
                 # Pop the old segment off. The new one will replace it later.  
                 pop @retVal;  
             }  
         }  
         # Remember this specifier for the adjacent-segment test the next time through.  
         ($prevContig, $prevBeg, $prevDir, $prevLen) = ($contigID, $beg, $dir, $len);  
         # Compute the initial base pair.  
         my $start = ($dir eq "+" ? $beg : $beg + $len - 1);  
         # Add the specifier to the list.  
         push @retVal, "${contigID}_$start$dir$len";  
     }  
832      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
833      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
834  }  }
835    
836  =head3 ParseLocation  =head3 ParseLocation
837    
838  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
839    
840  Split a location specifier into the contig ID, the starting point, the direction, and the  Split a location specifier into the contig ID, the starting point, the direction, and the
841  length.  length.
# Line 657  Line 854 
854  =back  =back
855    
856  =cut  =cut
857  #: Return Type @;  
858  sub ParseLocation {  sub ParseLocation {
859      # Get the parameter. Note that if we're called as an instance method, we ignore      # Get the parameter. Note that if we're called as an instance method, we ignore
860      # the first parameter.      # the first parameter.
# Line 680  Line 877 
877      return ($contigID, $start, $dir, $len);      return ($contigID, $start, $dir, $len);
878  }  }
879    
880    
881    
882  =head3 PointLocation  =head3 PointLocation
883    
884  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
885    
886  Return the offset into the specified location of the specified point on the contig. If  Return the offset into the specified location of the specified point on the contig. If
887  the specified point is before the location, a negative value will be returned. If it is  the specified point is before the location, a negative value will be returned. If it is
# Line 711  Line 910 
910  =back  =back
911    
912  =cut  =cut
913  #: Return Type $;  
914  sub PointLocation {  sub PointLocation {
915      # Get the parameter. Note that if we're called as an instance method, we ignore      # Get the parameter. Note that if we're called as an instance method, we ignore
916      # the first parameter.      # the first parameter.
# Line 734  Line 933 
933    
934  =head3 DNASeq  =head3 DNASeq
935    
936  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
937    
938  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
939  should be of the form returned by L</featureLocation> when in a list context. In other words,  should be of the form returned by L</featureLocation> when in a list context. In other words,
# Line 818  Line 1017 
1017    
1018  =head3 AllContigs  =head3 AllContigs
1019    
1020  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
1021    
1022  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
1023    
# Line 846  Line 1045 
1045      return @retVal;      return @retVal;
1046  }  }
1047    
1048  =head3 ContigLength  =head3 GenomeLength
1049    
1050  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->GenomeLength($genomeID);
1051    
1052  Compute the length of a contig.  Return the length of the specified genome in base pairs.
1053    
1054  =over 4  =over 4
1055    
1056  =item contigID  =item genomeID
1057    
1058  ID of the contig whose length is desired.  ID of the genome whose base pair count is desired.
1059    
1060  =item RETURN  =item RETURN
1061    
1062  Returns the number of positions in the contig.  Returns the number of base pairs in all the contigs of the specified
1063    genome.
1064    
1065  =back  =back
1066    
1067  =cut  =cut
1068  #: Return Type $;  
1069  sub ContigLength {  sub GenomeLength {
1070      # Get the parameters.      # Get the parameters.
1071      my ($self, $contigID) = @_;      my ($self, $genomeID) = @_;
1072      # Get the contig's last sequence.      # Declare the return variable.
     my $query = $self->Get(['IsMadeUpOf'],  
         "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",  
         [$contigID]);  
     my $sequence = $query->Fetch();  
     # Declare the return value.  
1073      my $retVal = 0;      my $retVal = 0;
1074      # Set it from the sequence data, if any.      # Get the genome's contig sequence lengths.
1075      if ($sequence) {      my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',
1076          my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);                         [$genomeID], 'IsMadeUpOf(len)');
1077          $retVal = $start + $len - 1;      # Sum the lengths.
1078      }      map { $retVal += $_ } @lens;
1079      # Return the result.      # Return the result.
1080      return $retVal;      return $retVal;
1081  }  }
1082    
1083  =head3 ClusterPEGs  =head3 FeatureCount
1084    
1085  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $count = $sprout->FeatureCount($genomeID, $type);
1086    
1087  Cluster the PEGs in a list according to the cluster coding scheme of the specified  Return the number of features of the specified type in the specified genome.
 subsystem. In order for this to work properly, the subsystem object must have  
 been used recently to retrieve the PEGs using the B<get_pegs_from_cell> method.  
 This causes the cluster numbers to be pulled into the subsystem's color hash.  
 If a PEG is not found in the color hash, it will not appear in the output  
 sequence.  
1088    
1089  =over 4  =over 4
1090    
1091  =item sub  =item genomeID
1092    
1093  Sprout subsystem object for the relevant subsystem, from the L</get_subsystem>  ID of the genome whose feature count is desired.
 method.  
1094    
1095  =item pegs  =item type
1096    
1097  Reference to the list of PEGs to be clustered.  Type of feature to count (eg. C<peg>, C<rna>, etc.).
1098    
1099  =item RETURN  =item RETURN
1100    
1101  Returns a list of the PEGs, grouped into smaller lists by cluster number.  Returns the number of features of the specified type for the specified genome.
1102    
1103  =back  =back
1104    
1105  =cut  =cut
1106  #: Return Type $@@;  
1107  sub ClusterPEGs {  sub FeatureCount {
1108      # Get the parameters.      # Get the parameters.
1109      my ($self, $sub, $pegs) = @_;      my ($self, $genomeID, $type) = @_;
1110      # Declare the return variable.      # Compute the count.
1111      my $retVal = [];      my $retVal = $self->GetCount(['HasFeature', 'Feature'],
1112      # Loop through the PEGs, creating arrays for each cluster.                                  "HasFeature(from-link) = ? AND Feature(feature-type) = ?",
1113      for my $pegID (@{$pegs}) {                                  [$genomeID, $type]);
1114          my $clusterNumber = $sub->get_cluster_number($pegID);      # Return the result.
1115        return $retVal;
1116    }
1117    
1118    =head3 GenomeAssignments
1119    
1120        my $fidHash = $sprout->GenomeAssignments($genomeID);
1121    
1122    Return a list of a genome's assigned features. The return hash will contain each
1123    assigned feature of the genome mapped to the text of its most recent functional
1124    assignment.
1125    
1126    =over 4
1127    
1128    =item genomeID
1129    
1130    ID of the genome whose functional assignments are desired.
1131    
1132    =item RETURN
1133    
1134    Returns a reference to a hash which maps each feature to its most recent
1135    functional assignment.
1136    
1137    =back
1138    
1139    =cut
1140    
1141    sub GenomeAssignments {
1142        # Get the parameters.
1143        my ($self, $genomeID) = @_;
1144        # Declare the return variable.
1145        my $retVal = {};
1146        # Query the genome's features.
1147        my $query = $self->Get(['HasFeature', 'Feature'], "HasFeature(from-link) = ?",
1148                               [$genomeID]);
1149        # Loop through the features.
1150        while (my $data = $query->Fetch) {
1151            # Get the feature ID and assignment.
1152            my ($fid, $assignment) = $data->Values(['Feature(id)', 'Feature(assignment)']);
1153            if ($assignment) {
1154                $retVal->{$fid} = $assignment;
1155            }
1156        }
1157        # Return the result.
1158        return $retVal;
1159    }
1160    
1161    =head3 ContigLength
1162    
1163        my $length = $sprout->ContigLength($contigID);
1164    
1165    Compute the length of a contig.
1166    
1167    =over 4
1168    
1169    =item contigID
1170    
1171    ID of the contig whose length is desired.
1172    
1173    =item RETURN
1174    
1175    Returns the number of positions in the contig.
1176    
1177    =back
1178    
1179    =cut
1180    #: Return Type $;
1181    sub ContigLength {
1182        # Get the parameters.
1183        my ($self, $contigID) = @_;
1184        # Get the contig's last sequence.
1185        my $query = $self->Get(['IsMadeUpOf'],
1186            "IsMadeUpOf(from-link) = ? ORDER BY IsMadeUpOf(start-position) DESC",
1187            [$contigID]);
1188        my $sequence = $query->Fetch();
1189        # Declare the return value.
1190        my $retVal = 0;
1191        # Set it from the sequence data, if any.
1192        if ($sequence) {
1193            my ($start, $len) = $sequence->Values(['IsMadeUpOf(start-position)', 'IsMadeUpOf(len)']);
1194            $retVal = $start + $len - 1;
1195        }
1196        # Return the result.
1197        return $retVal;
1198    }
1199    
1200    =head3 ClusterPEGs
1201    
1202        my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
1203    
1204    Cluster the PEGs in a list according to the cluster coding scheme of the specified
1205    subsystem. In order for this to work properly, the subsystem object must have
1206    been used recently to retrieve the PEGs using the B<get_pegs_from_cell> or
1207    B<get_row> methods. This causes the cluster numbers to be pulled into the
1208    subsystem's color hash. If a PEG is not found in the color hash, it will not
1209    appear in the output sequence.
1210    
1211    =over 4
1212    
1213    =item sub
1214    
1215    Sprout subsystem object for the relevant subsystem, from the L</get_subsystem>
1216    method.
1217    
1218    =item pegs
1219    
1220    Reference to the list of PEGs to be clustered.
1221    
1222    =item RETURN
1223    
1224    Returns a list of the PEGs, grouped into smaller lists by cluster number.
1225    
1226    =back
1227    
1228    =cut
1229    #: Return Type $@@;
1230    sub ClusterPEGs {
1231        # Get the parameters.
1232        my ($self, $sub, $pegs) = @_;
1233        # Declare the return variable.
1234        my $retVal = [];
1235        # Loop through the PEGs, creating arrays for each cluster.
1236        for my $pegID (@{$pegs}) {
1237            my $clusterNumber = $sub->get_cluster_number($pegID);
1238          # Only proceed if the PEG is in a cluster.          # Only proceed if the PEG is in a cluster.
1239          if ($clusterNumber >= 0) {          if ($clusterNumber >= 0) {
1240              # Push this PEG onto the sub-list for the specified cluster number.              # Push this PEG onto the sub-list for the specified cluster number.
# Line 935  Line 1247 
1247    
1248  =head3 GenesInRegion  =head3 GenesInRegion
1249    
1250  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1251    
1252  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1253    
# Line 964  Line 1276 
1276  =back  =back
1277    
1278  =cut  =cut
1279  #: Return Type @@;  
1280  sub GenesInRegion {  sub GenesInRegion {
1281      # Get the parameters.      # Get the parameters.
1282      my ($self, $contigID, $start, $stop) = @_;      my ($self, $contigID, $start, $stop) = @_;
1283      # Get the maximum segment length.      # Get the maximum segment length.
1284      my $maximumSegmentLength = $self->MaxSegment;      my $maximumSegmentLength = $self->MaxSegment;
     # Create a hash to receive the feature list. We use a hash so that we can eliminate  
     # duplicates easily. The hash key will be the feature ID. The value will be a two-element  
     # containing the minimum and maximum offsets. We will use the offsets to sort the results  
     # when we're building the result set.  
     my %featuresFound = ();  
1285      # Prime the values we'll use for the returned beginning and end.      # Prime the values we'll use for the returned beginning and end.
1286      my @initialMinMax = ($self->ContigLength($contigID), 0);      my @initialMinMax = ($self->ContigLength($contigID), 0);
1287      my ($min, $max) = @initialMinMax;      my ($min, $max) = @initialMinMax;
1288      # Create a table of parameters for each query. Each query looks for features travelling in      # Get the overlapping features.
1289        my @featureObjects = $self->GeneDataInRegion($contigID, $start, $stop);
1290        # We'l use this hash to help us track the feature IDs and sort them. The key is the
1291        # feature ID and the value is a [$left,$right] pair indicating the maximum extent
1292        # of the feature's locations.
1293        my %featureMap = ();
1294        # Loop through them to do the begin/end analysis.
1295        for my $featureObject (@featureObjects) {
1296            # Get the feature's location string. This may contain multiple actual locations.
1297            my ($locations, $fid) = $featureObject->Values([qw(Feature(location-string) Feature(id))]);
1298            my @locationSegments = split /\s*,\s*/, $locations;
1299            # Loop through the locations.
1300            for my $locationSegment (@locationSegments) {
1301                # Construct an object for the location.
1302                my $locationObject = BasicLocation->new($locationSegment);
1303                # Merge the current segment's begin and end into the min and max.
1304                my ($left, $right) = ($locationObject->Left, $locationObject->Right);
1305                my ($beg, $end);
1306                if (exists $featureMap{$fid}) {
1307                    ($beg, $end) = @{$featureMap{$fid}};
1308                    $beg = $left if $left < $beg;
1309                    $end = $right if $right > $end;
1310                } else {
1311                    ($beg, $end) = ($left, $right);
1312                }
1313                $min = $beg if $beg < $min;
1314                $max = $end if $end > $max;
1315                # Store the feature's new extent back into the hash table.
1316                $featureMap{$fid} = [$beg, $end];
1317            }
1318        }
1319        # Now we must compute the list of the IDs for the features found. We start with a list
1320        # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,
1321        # but the result of the sort will be the same.)
1322        my @list = map { [$featureMap{$_}->[0] + $featureMap{$_}->[1], $_] } keys %featureMap;
1323        # Now we sort by midpoint and yank out the feature IDs.
1324        my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;
1325        # Return it along with the min and max.
1326        return (\@retVal, $min, $max);
1327    }
1328    
1329    =head3 GeneDataInRegion
1330    
1331        my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1332    
1333    List the features which overlap a specified region in a contig.
1334    
1335    =over 4
1336    
1337    =item contigID
1338    
1339    ID of the contig containing the region of interest.
1340    
1341    =item start
1342    
1343    Offset of the first residue in the region of interest.
1344    
1345    =item stop
1346    
1347    Offset of the last residue in the region of interest.
1348    
1349    =item RETURN
1350    
1351    Returns a list of B<ERDBObjects> for the desired features. Each object will
1352    contain a B<Feature> record.
1353    
1354    =back
1355    
1356    =cut
1357    
1358    sub GeneDataInRegion {
1359        # Get the parameters.
1360        my ($self, $contigID, $start, $stop) = @_;
1361        # Get the maximum segment length.
1362        my $maximumSegmentLength = $self->MaxSegment;
1363        # Create a hash to receive the feature list. We use a hash so that we can eliminate
1364        # duplicates easily. The hash key will be the feature ID. The value will be the feature's
1365        # ERDBObject from the query.
1366        my %featuresFound = ();
1367        # Create a table of parameters for the queries. Each query looks for features travelling in
1368      # 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,
1369      # 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
1370      # because each feature segment length must be no greater than the maximum segment length.      # because each feature segment length must be no greater than the maximum segment length.
# Line 987  Line 1373 
1373      # Loop through the query parameters.      # Loop through the query parameters.
1374      for my $parms (values %queryParms) {      for my $parms (values %queryParms) {
1375          # Create the query.          # Create the query.
1376          my $query = $self->Get(['IsLocatedIn'],          my $query = $self->Get([qw(Feature IsLocatedIn)],
1377              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",              "IsLocatedIn(to-link)= ? AND IsLocatedIn(dir) = ? AND IsLocatedIn(beg) >= ? AND IsLocatedIn(beg) <= ?",
1378              $parms);              $parms);
1379          # Loop through the feature segments found.          # Loop through the feature segments found.
1380          while (my $segment = $query->Fetch) {          while (my $segment = $query->Fetch) {
1381              # Get the data about this segment.              # Get the data about this segment.
1382              my ($featureID, $dir, $beg, $len) = $segment->Values(['IsLocatedIn(from-link)',              my ($featureID, $contig, $dir, $beg, $len) = $segment->Values([qw(IsLocatedIn(from-link)
1383                  'IsLocatedIn(dir)', 'IsLocatedIn(beg)', 'IsLocatedIn(len)']);                  IsLocatedIn(to-link) IsLocatedIn(dir) IsLocatedIn(beg) IsLocatedIn(len))]);
1384              # Determine if this feature actually overlaps the region. The query insures that              # Determine if this feature segment actually overlaps the region. The query insures that
1385              # this will be the case if the segment is the maximum length, so to fine-tune              # this will be the case if the segment is the maximum length, so to fine-tune
1386              # the results we insure that the inequality from the query holds using the actual              # the results we insure that the inequality from the query holds using the actual
1387              # length.              # length.
1388              my ($found, $end) = (0, 0);              my $loc = BasicLocation->new($contig, $beg, $dir, $len);
1389              if ($dir eq '+') {              my $found = $loc->Overlap($start, $stop);
                 $end = $beg + $len;  
                 if ($end >= $start) {  
                     # Denote we found a useful feature.  
                     $found = 1;  
                 }  
             } elsif ($dir eq '-') {  
                 # Note we switch things around so that the beginning is to the left of the  
                 # ending.  
                 ($beg, $end) = ($beg - $len, $beg);  
                 if ($beg <= $stop) {  
                     # Denote we found a useful feature.  
                     $found = 1;  
                 }  
             }  
1390              if ($found) {              if ($found) {
1391                  # Here we need to record the feature and update the minima and maxima. First,                  # Save this feature in the result list.
1392                  # get the current entry for the specified feature.                  $featuresFound{$featureID} = $segment;
                 my ($loc1, $loc2) = (exists $featuresFound{$featureID} ? @{$featuresFound{$featureID}} :  
                                      @initialMinMax);  
                 # Merge the current segment's begin and end into the feature begin and end and the  
                 # global min and max.  
                 if ($beg < $loc1) {  
                     $loc1 = $beg;  
                     $min = $beg if $beg < $min;  
                 }  
                 if ($end > $loc2) {  
                     $loc2 = $end;  
                     $max = $end if $end > $max;  
                 }  
                 # Store the entry back into the hash table.  
                 $featuresFound{$featureID} = [$loc1, $loc2];  
1393              }              }
1394          }          }
1395      }      }
1396      # Now we must compute the list of the IDs for the features found. We start with a list      # Return the ERDB objects for the features found.
1397      # of midpoints / feature ID pairs. (It's not really a midpoint, it's twice the midpoint,      return values %featuresFound;
     # but the result of the sort will be the same.)  
     my @list = map { [$featuresFound{$_}->[0] + $featuresFound{$_}->[1], $_] } keys %featuresFound;  
     # Now we sort by midpoint and yank out the feature IDs.  
     my @retVal = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @list;  
     # Return it along with the min and max.  
     return (\@retVal, $min, $max);  
1398  }  }
1399    
1400  =head3 FType  =head3 FType
1401    
1402  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1403    
1404  Return the type of a feature.  Return the type of a feature.
1405    
# Line 1077  Line 1429 
1429    
1430  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1431    
1432  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1433    
1434  Return the annotations of a feature.  Return the annotations of a feature.
1435    
# Line 1140  Line 1492 
1492    
1493  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1494    
1495  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1496    
1497  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
1498  hash of functional assignments to user IDs. A functional assignment is a type of annotation,  hash of functional assignments to user IDs. A functional assignment is a type of annotation,
# Line 1195  Line 1547 
1547    
1548  =head3 FunctionOf  =head3 FunctionOf
1549    
1550  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1551    
1552  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1553    
1554  The functional assignment is handled differently depending on the type of feature. If  The functional assignment is handled differently depending on the type of feature. If
1555  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional  the feature is identified by a FIG ID (begins with the string C<fig|>), then the functional
1556  assignment is a type of annotation. The format of an assignment is described in  assignment is taken from the B<Feature> or C<Annotation> table, depending.
 L</ParseAssignment>. Its worth noting that we cannot filter on the content of the  
 annotation itself because it's a text field; however, this is not a big problem because  
 most features only have a small number of annotations.  
1557    
1558  Each user has an associated list of trusted users. The assignment returned will be the most  Each user has an associated list of trusted users. The assignment returned will be the most
1559  recent one by at least one of the trusted users. If no trusted user list is available, then  recent one by at least one of the trusted users. If no trusted user list is available, then
# Line 1223  Line 1572 
1572    
1573  =item userID (optional)  =item userID (optional)
1574    
1575  ID of the user whose function determination is desired. If omitted, only the latest  ID of the user whose function determination is desired. If omitted, the primary
1576  C<FIG> assignment will be returned.  functional assignment in the B<Feature> table will be returned.
1577    
1578  =item RETURN  =item RETURN
1579    
# Line 1241  Line 1590 
1590      my $retVal;      my $retVal;
1591      # Determine the ID type.      # Determine the ID type.
1592      if ($featureID =~ m/^fig\|/) {      if ($featureID =~ m/^fig\|/) {
1593          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID.
1594          # users.          if (!$userID) {
1595                # Use the primary assignment.
1596                ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);
1597            } else {
1598                # We must build the list of trusted users.
1599          my %trusteeTable = ();          my %trusteeTable = ();
1600          # Check the user ID.          # Check the user ID.
1601          if (!$userID) {          if (!$userID) {
# Line 1285  Line 1638 
1638                  }                  }
1639              }              }
1640          }          }
1641            }
1642      } else {      } else {
1643          # Here we have a non-FIG feature ID. In this case the user ID does not          # Here we have a non-FIG feature ID. In this case the user ID does not
1644          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
# Line 1297  Line 1651 
1651    
1652  =head3 FunctionsOf  =head3 FunctionsOf
1653    
1654  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1655    
1656  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1657    
# Line 1369  Line 1723 
1723    
1724  =head3 BBHList  =head3 BBHList
1725    
1726  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1727    
1728  Return a hash mapping the features in a specified list to their bidirectional best hits  Return a hash mapping the features in a specified list to their bidirectional best hits
1729  on a specified target genome.  on a specified target genome.
# Line 1400  Line 1754 
1754      my %retVal = ();      my %retVal = ();
1755      # Loop through the incoming features.      # Loop through the incoming features.
1756      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1757          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1758          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1759          # Peel off the BBHs found.          # Peel off the BBHs found.
1760          my @found = ();          my @found = ();
1761          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1762              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              my $fid = $bbh->[0];
1763                my $bbGenome = $self->GenomeOf($fid);
1764                if ($bbGenome eq $genomeID) {
1765                    push @found, $fid;
1766                }
1767          }          }
1768          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1769      }      }
# Line 1417  Line 1773 
1773    
1774  =head3 SimList  =head3 SimList
1775    
1776  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1777    
1778  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1779    
1780  Sprout does not support real similarities, so this method just returns the bidirectional  This method just returns the bidirectional best hits for performance reasons.
 best hits.  
1781    
1782  =over 4  =over 4
1783    
# Line 1442  Line 1797 
1797      # Get the parameters.      # Get the parameters.
1798      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1799      # Ask for the best hits.      # Ask for the best hits.
1800      my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],      my @lists = FIGRules::BBHData($featureID);
                               "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",  
                               [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],  
                               $count);  
1801      # Create the return value.      # Create the return value.
1802      my %retVal = ();      my %retVal = ();
1803      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1455  Line 1807 
1807      return %retVal;      return %retVal;
1808  }  }
1809    
   
   
1810  =head3 IsComplete  =head3 IsComplete
1811    
1812  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1813    
1814  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1815    
# Line 1487  Line 1837 
1837      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1838      if ($genomeData) {      if ($genomeData) {
1839          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1840          ($retVal) = $genomeData->Value('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1841      }      }
1842      # Return the result.      # Return the result.
1843      return $retVal;      return $retVal;
# Line 1495  Line 1845 
1845    
1846  =head3 FeatureAliases  =head3 FeatureAliases
1847    
1848  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1849    
1850  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1851    
# Line 1518  Line 1868 
1868      # Get the parameters.      # Get the parameters.
1869      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1870      # Get the desired feature's aliases      # Get the desired feature's aliases
1871      my @retVal = $self->GetEntityValues('Feature', $featureID, ['Feature(alias)']);      my @retVal = $self->GetFlat(['IsAliasOf'], "IsAliasOf(to-link) = ?", [$featureID], 'IsAliasOf(from-link)');
1872      # Return the result.      # Return the result.
1873      return @retVal;      return @retVal;
1874  }  }
1875    
1876  =head3 GenomeOf  =head3 GenomeOf
1877    
1878  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1879    
1880  Return the genome that contains a specified feature.  Return the genome that contains a specified feature or contig.
1881    
1882  =over 4  =over 4
1883    
1884  =item featureID  =item featureID
1885    
1886  ID of the feature whose genome is desired.  ID of the feature or contig whose genome is desired.
1887    
1888  =item RETURN  =item RETURN
1889    
1890  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
1891  an undefined value.  found, returns an undefined value.
1892    
1893  =back  =back
1894    
# Line 1547  Line 1897 
1897  sub GenomeOf {  sub GenomeOf {
1898      # Get the parameters.      # Get the parameters.
1899      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
     # Create a query to find the genome associated with the feature.  
     my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);  
1900      # Declare the return value.      # Declare the return value.
1901      my $retVal;      my $retVal;
1902      # Get the genome ID.      # Parse the genome ID from the feature ID.
1903      if (my $relationship = $query->Fetch()) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1904          ($retVal) = $relationship->Value('HasContig(from-link)');          $retVal = $1;
1905        } else {
1906            Confess("Invalid feature ID $featureID.");
1907      }      }
1908      # Return the value found.      # Return the value found.
1909      return $retVal;      return $retVal;
# Line 1561  Line 1911 
1911    
1912  =head3 CoupledFeatures  =head3 CoupledFeatures
1913    
1914  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
1915    
1916  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
1917  functionally coupled if they tend to be clustered on the same chromosome.  functionally coupled if they tend to be clustered on the same chromosome.
# Line 1583  Line 1933 
1933  sub CoupledFeatures {  sub CoupledFeatures {
1934      # Get the parameters.      # Get the parameters.
1935      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1936      # Create a query to retrieve the functionally-coupled features.      # Ask the coupling server for the data.
1937      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1938                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);      my @rawPairs = FIGRules::NetCouplingData('coupled_to', id1 => $featureID);
1939      # This value will be set to TRUE if we find at least one coupled feature.      Trace(scalar(@rawPairs) . " couplings returned.") if T(coupling => 3);
1940      my $found = 0;      # Form them into a hash.
     # Create the return hash.  
1941      my %retVal = ();      my %retVal = ();
1942      # Retrieve the relationship records and store them in the hash.      for my $pair (@rawPairs) {
1943      while (my $clustering = $query->Fetch()) {          # Get the feature ID and score.
1944          # Get the ID and score of the coupling.          my ($featureID2, $score) = @{$pair};
1945          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          # Only proceed if the feature is in NMPDR.
1946                                                          'Coupling(score)']);          if ($self->_CheckFeature($featureID2)) {
1947          # The coupling ID contains the two feature IDs separated by a space. We use              $retVal{$featureID2} = $score;
1948          # this information to find the ID of the other feature.          }
         my ($fid1, $fid2) = split / /, $couplingID;  
         my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);  
         # Attach the other feature's score to its ID.  
         $retVal{$otherFeatureID} = $score;  
         $found = 1;  
1949      }      }
1950      # Functional coupling is reflexive. If we found at least one coupled feature, we must add      # Functional coupling is reflexive. If we found at least one coupled feature, we must add
1951      # the incoming feature as well.      # the incoming feature as well.
1952      if ($found) {      if (keys %retVal) {
1953          $retVal{$featureID} = 9999;          $retVal{$featureID} = 9999;
1954      }      }
1955      # Return the hash.      # Return the hash.
# Line 1614  Line 1958 
1958    
1959  =head3 CouplingEvidence  =head3 CouplingEvidence
1960    
1961  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
1962    
1963  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
1964    
# Line 1662  Line 2006 
2006      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
2007      # Declare the return variable.      # Declare the return variable.
2008      my @retVal = ();      my @retVal = ();
2009      # Our first task is to find out the nature of the coupling: whether or not      # Get the coupling and evidence data.
2010      # it exists, its score, and whether the features are stored in the same      my @rawData = FIGRules::NetCouplingData('coupling_evidence', id1 => $peg1, id2 => $peg2);
2011      # order as the ones coming in.      # Loop through the raw data, saving the ones that are in NMPDR genomes.
2012      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);      for my $rawTuple (@rawData) {
2013      # Only proceed if a coupling exists.          if ($self->_CheckFeature($rawTuple->[0]) && $self->_CheckFeature($rawTuple->[1])) {
2014      if ($couplingID) {              push @retVal, $rawTuple;
2015          # Determine the ordering to place on the evidence items. If we're          }
         # inverted, we want to see feature 2 before feature 1 (descending); otherwise,  
         # we want feature 1 before feature 2 (normal).  
         Trace("Coupling evidence for ($peg1, $peg2) with inversion flag $inverted.") if T(Coupling => 4);  
         my $ordering = ($inverted ? "DESC" : "");  
         # Get the coupling evidence.  
         my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],  
                                           "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",  
                                           [$couplingID],  
                                           ['PCH(used)', 'UsesAsEvidence(to-link)']);  
         # Loop through the evidence items. Each piece of evidence is represented by two  
         # positions in the evidence list, one for each feature on the other side of the  
         # evidence link. If at some point we want to generalize to couplings with  
         # more than two positions, this section of code will need to be re-done.  
         while (@evidenceList > 0) {  
             my $peg1Data = shift @evidenceList;  
             my $peg2Data = shift @evidenceList;  
             Trace("Peg 1 is " . $peg1Data->[1] . " and Peg 2 is " . $peg2Data->[1] . ".") if T(Coupling => 4);  
             push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];  
         }  
         Trace("Last index in evidence result is is $#retVal.") if T(Coupling => 4);  
2016      }      }
2017      # Return the result.      # Return the result.
2018      return @retVal;      return @retVal;
2019  }  }
2020    
2021  =head3 GetCoupling  =head3 GetSynonymGroup
   
 C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>  
   
 Return the coupling (if any) for the specified pair of PEGs. If a coupling  
 exists, we return the coupling ID along with an indicator of whether the  
 coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.  
 In the second case, we say the coupling is I<inverted>. The importance of an  
 inverted coupling is that the PEGs in the evidence will appear in reverse order.  
2022    
2023  =over 4      my $id = $sprout->GetSynonymGroup($fid);
2024    
2025  =item peg1  Return the synonym group name for the specified feature.
2026    
2027  ID of the feature of interest.  =over 4
2028    
2029  =item peg2  =item fid
2030    
2031  ID of the potentially coupled feature.  ID of the feature whose synonym group is desired.
2032    
2033  =item RETURN  =item RETURN
2034    
2035  Returns a three-element list. The first element contains the database ID of  The name of the synonym group to which the feature belongs. If the feature does
2036  the coupling. The second element is FALSE if the coupling is stored in the  not belong to a synonym group, the feature ID itself is returned.
 database in the caller specified order and TRUE if it is stored in the  
 inverted order. The third element is the coupling's score. If the coupling  
 does not exist, all three list elements will be C<undef>.  
2037    
2038  =back  =back
2039    
2040  =cut  =cut
2041  #: Return Type $%@;  
2042  sub GetCoupling {  sub GetSynonymGroup {
2043      # Get the parameters.      # Get the parameters.
2044      my ($self, $peg1, $peg2) = @_;      my ($self, $fid) = @_;
2045      # Declare the return values. We'll start with the coupling ID and undefine the      # Declare the return variable.
2046      # flag and score until we have more information.      my $retVal;
2047      my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);      # Find the synonym group.
2048      # Find the coupling data.      my @groups = $self->GetFlat(['IsSynonymGroupFor'], "IsSynonymGroupFor(to-link) = ?",
2049      my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],                                     [$fid], 'IsSynonymGroupFor(from-link)');
                                  "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",  
                                  [$retVal], ["ParticipatesInCoupling(from-link)", "Coupling(score)"]);  
2050      # Check to see if we found anything.      # Check to see if we found anything.
2051      if (!@pegs) {      if (@groups) {
2052          Trace("No coupling found.") if T(Coupling => 4);          $retVal = $groups[0];
         # No coupling, so undefine the return value.  
         $retVal = undef;  
2053      } else {      } else {
2054          # We have a coupling! Get the score and check for inversion.          $retVal = $fid;
         $score = $pegs[0]->[1];  
         my $firstFound = $pegs[0]->[0];  
         $inverted = ($firstFound ne $peg1);  
         Trace("Coupling score is $score. First peg is $firstFound, peg 1 is $peg1.") if T(Coupling => 4);  
2055      }      }
2056      # Return the result.      # Return the result.
2057      return ($retVal, $inverted, $score);      return $retVal;
2058  }  }
2059    
2060  =head3 CouplingID  =head3 GetBoundaries
2061    
2062  C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
2063    
2064  Return the coupling ID for a pair of feature IDs.  Determine the begin and end boundaries for the locations in a list. All of the
2065    locations must belong to the same contig and have mostly the same direction in
2066  The coupling ID is currently computed by joining the feature IDs in  order for this method to produce a meaningful result. The resulting
2067  sorted order with a space. Client modules (that is, modules which  begin/end pair will contain all of the bases in any of the locations.
 use Sprout) should not, however, count on this always being the  
 case. This method provides a way for abstracting the concept of a  
 coupling ID. All that we know for sure about it is that it can be  
 generated easily from the feature IDs and the order of the IDs  
 in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>  
 will have the same value as C<CouplingID("b1", "a1")>.  
2068    
2069  =over 4  =over 4
2070    
2071  =item peg1  =item locList
   
 First feature of interest.  
   
 =item peg2  
2072    
2073  Second feature of interest.  List of locations to process.
2074    
2075  =item RETURN  =item RETURN
2076    
2077  Returns the ID that would be used to represent a functional coupling of  Returns a 3-tuple consisting of the contig ID, the beginning boundary,
2078  the two specified PEGs.  and the ending boundary. The beginning boundary will be left of the
2079    end for mostly-forward locations and right of the end for mostly-backward
2080    locations.
2081    
2082  =back  =back
2083    
2084  =cut  =cut
 #: Return Type $;  
 sub CouplingID {  
     return join " ", sort @_;  
 }  
   
 =head3 GetEntityTypes  
   
 C<< my @entityList = $sprout->GetEntityTypes(); >>  
   
 Return the list of supported entity types.  
2085    
2086  =cut  sub GetBoundaries {
 #: Return Type @;  
 sub GetEntityTypes {  
2087      # Get the parameters.      # Get the parameters.
2088      my ($self) = @_;      my ($self, @locList) = @_;
2089      # Get the underlying database object.      # Set up the counters used to determine the most popular direction.
2090      my $erdb = $self->{_erdb};      my %counts = ( '+' => 0, '-' => 0 );
2091      # Get its entity type list.      # Get the last location and parse it.
2092      my @retVal = $erdb->GetEntityTypes();      my $locObject = BasicLocation->new(pop @locList);
2093        # Prime the loop with its data.
2094        my ($contig, $beg, $end) = ($locObject->Contig, $locObject->Left, $locObject->Right);
2095        # Count its direction.
2096        $counts{$locObject->Dir}++;
2097        # Loop through the remaining locations. Note that in most situations, this loop
2098        # will not iterate at all, because most of the time we will be dealing with a
2099        # singleton list.
2100        for my $loc (@locList) {
2101            # Create a location object.
2102            my $locObject = BasicLocation->new($loc);
2103            # Count the direction.
2104            $counts{$locObject->Dir}++;
2105            # Get the left end and the right end.
2106            my $left = $locObject->Left;
2107            my $right = $locObject->Right;
2108            # Merge them into the return variables.
2109            if ($left < $beg) {
2110                $beg = $left;
2111            }
2112            if ($right > $end) {
2113                $end = $right;
2114            }
2115        }
2116        # If the most common direction is reverse, flip the begin and end markers.
2117        if ($counts{'-'} > $counts{'+'}) {
2118            ($beg, $end) = ($end, $beg);
2119        }
2120        # Return the result.
2121        return ($contig, $beg, $end);
2122  }  }
2123    
2124  =head3 ReadFasta  =head3 ReadFasta
2125    
2126  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
2127    
2128  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by
2129  one or more lines of data. The first line begins with a > character and contains an ID.  one or more lines of data. The first line begins with a > character and contains an ID.
# Line 1875  Line 2189 
2189    
2190  =head3 FormatLocations  =head3 FormatLocations
2191    
2192  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
2193    
2194  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
2195  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward
# Line 1940  Line 2254 
2254    
2255  =head3 DumpData  =head3 DumpData
2256    
2257  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2258    
2259  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.
2260    
# Line 1952  Line 2266 
2266      # Get the data directory name.      # Get the data directory name.
2267      my $outputDirectory = $self->{_options}->{dataDir};      my $outputDirectory = $self->{_options}->{dataDir};
2268      # Dump the relations.      # Dump the relations.
2269      $self->{_erdb}->DumpRelations($outputDirectory);      $self->DumpRelations($outputDirectory);
2270  }  }
2271    
2272  =head3 XMLFileName  =head3 XMLFileName
2273    
2274  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2275    
2276  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2277    
# Line 1968  Line 2282 
2282      return $self->{_xmlName};      return $self->{_xmlName};
2283  }  }
2284    
2285    =head3 GetGenomeNameData
2286    
2287        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2288    
2289    Return the genus, species, and unique characterization for a genome. This
2290    is similar to L</GenusSpecies>, with the exception that it returns the
2291    values in three seperate fields.
2292    
2293    =over 4
2294    
2295    =item genomeID
2296    
2297    ID of the genome whose name data is desired.
2298    
2299    =item RETURN
2300    
2301    Returns a three-element list, consisting of the genus, species, and strain
2302    of the specified genome. If the genome is not found, an error occurs.
2303    
2304    =back
2305    
2306    =cut
2307    
2308    sub GetGenomeNameData {
2309        # Get the parameters.
2310        my ($self, $genomeID) = @_;
2311        # Get the desired values.
2312        my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>
2313                                                                [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);
2314        # Throw an error if they were not found.
2315        if (! defined $genus) {
2316            Confess("Genome $genomeID not found in database.");
2317        }
2318        # Return the results.
2319        return ($genus, $species, $strain);
2320    }
2321    
2322    =head3 GetGenomeByNameData
2323    
2324        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2325    
2326    Return a list of the IDs of the genomes with the specified genus,
2327    species, and strain. In almost every case, there will be either zero or
2328    one IDs returned; however, two or more IDs could be returned if there are
2329    multiple versions of the genome in the database.
2330    
2331    =over 4
2332    
2333    =item genus
2334    
2335    Genus of the desired genome.
2336    
2337    =item species
2338    
2339    Species of the desired genome.
2340    
2341    =item strain
2342    
2343    Strain (unique characterization) of the desired genome. This may be an empty
2344    string, in which case it is presumed that the desired genome has no strain
2345    specified.
2346    
2347    =item RETURN
2348    
2349    Returns a list of the IDs of the genomes having the specified genus, species, and
2350    strain.
2351    
2352    =back
2353    
2354    =cut
2355    
2356    sub GetGenomeByNameData {
2357        # Get the parameters.
2358        my ($self, $genus, $species, $strain) = @_;
2359        # Try to find the genomes.
2360        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2361                                    [$genus, $species, $strain], 'Genome(id)');
2362        # Return the result.
2363        return @retVal;
2364    }
2365    
2366  =head3 Insert  =head3 Insert
2367    
2368  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2369    
2370  Insert an entity or relationship instance into the database. The entity or relationship of interest  Insert an entity or relationship instance into the database. The entity or relationship of interest
2371  is defined by a type name and then a hash of field names to values. Field values in the primary  is defined by a type name and then a hash of field names to values. Field values in the primary
# Line 1979  Line 2374 
2374  list references. For example, the following line inserts an inactive PEG feature named  list references. For example, the following line inserts an inactive PEG feature named
2375  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.
2376    
2377  C<< $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>      $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']});
2378    
2379  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
2380  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>.
2381    
2382  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>      $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'});
2383    
2384  =over 4  =over 4
2385    
# Line 2004  Line 2399 
2399      # Get the parameters.      # Get the parameters.
2400      my ($self, $objectType, $fieldHash) = @_;      my ($self, $objectType, $fieldHash) = @_;
2401      # Call the underlying method.      # Call the underlying method.
2402      $self->{_erdb}->InsertObject($objectType, $fieldHash);      $self->InsertObject($objectType, $fieldHash);
2403  }  }
2404    
2405  =head3 Annotate  =head3 Annotate
2406    
2407  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2408    
2409  Annotate a feature. This inserts an Annotation record into the database and links it to the  Annotate a feature. This inserts an Annotation record into the database and links it to the
2410  specified feature and user.  specified feature and user.
# Line 2063  Line 2458 
2458    
2459  =head3 AssignFunction  =head3 AssignFunction
2460    
2461  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2462    
2463  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
2464  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2123  Line 2518 
2518    
2519  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2520    
2521  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2522    
2523  Returns a list of features with the specified alias. The alias is parsed to determine  Returns a list of features with the specified alias. The alias is parsed to determine
2524  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6
# Line 2157  Line 2552 
2552          push @retVal, $mappedAlias;          push @retVal, $mappedAlias;
2553      } else {      } else {
2554          # Here we have a non-FIG alias. Get the features with the normalized alias.          # Here we have a non-FIG alias. Get the features with the normalized alias.
2555          @retVal = $self->GetFlat(['Feature'], 'Feature(alias) = ?', [$mappedAlias], 'Feature(id)');          @retVal = $self->GetFlat(['IsAliasOf'], 'IsAliasOf(from-link) = ?', [$mappedAlias], 'IsAliasOf(to-link)');
2556      }      }
2557      # Return the result.      # Return the result.
2558      return @retVal;      return @retVal;
2559  }  }
2560    
2561  =head3 Exists  =head3 FeatureTranslation
2562    
2563  C<< my $found = $sprout->Exists($entityName, $entityID); >>      my $translation = $sprout->FeatureTranslation($featureID);
   
 Return TRUE if an entity exists, else FALSE.  
   
 =over 4  
   
 =item entityName  
   
 Name of the entity type (e.g. C<Feature>) relevant to the existence check.  
   
 =item entityID  
   
 ID of the entity instance whose existence is to be checked.  
   
 =item RETURN  
   
 Returns TRUE if the entity instance exists, else FALSE.  
   
 =back  
   
 =cut  
 #: Return Type $;  
 sub Exists {  
     # Get the parameters.  
     my ($self, $entityName, $entityID) = @_;  
     # Check for the entity instance.  
     Trace("Checking existence of $entityName with ID=$entityID.") if T(4);  
     my $testInstance = $self->GetEntity($entityName, $entityID);  
     # Return an existence indicator.  
     my $retVal = ($testInstance ? 1 : 0);  
     return $retVal;  
 }  
   
 =head3 FeatureTranslation  
   
 C<< my $translation = $sprout->FeatureTranslation($featureID); >>  
2564    
2565  Return the translation of a feature.  Return the translation of a feature.
2566    
# Line 2228  Line 2588 
2588    
2589  =head3 Taxonomy  =head3 Taxonomy
2590    
2591  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2592    
2593  Return the taxonomy of the specified genome. This will be in the form of a list  Return the taxonomy of the specified genome. This will be in the form of a list
2594  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,
2595  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2596    
2597  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2598    
2599  =over 4  =over 4
2600    
# Line 2269  Line 2629 
2629    
2630  =head3 CrudeDistance  =head3 CrudeDistance
2631    
2632  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2633    
2634  Returns a crude estimate of the distance between two genomes. The distance is construed so  Returns a crude estimate of the distance between two genomes. The distance is construed so
2635  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.
# Line 2321  Line 2681 
2681    
2682  =head3 RoleName  =head3 RoleName
2683    
2684  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2685    
2686  Return the descriptive name of the role with the specified ID. In general, a role  Return the descriptive name of the role with the specified ID. In general, a role
2687  will only have a descriptive name if it is coded as an EC number.  will only have a descriptive name if it is coded as an EC number.
# Line 2355  Line 2715 
2715    
2716  =head3 RoleDiagrams  =head3 RoleDiagrams
2717    
2718  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2719    
2720  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2721    
# Line 2385  Line 2745 
2745    
2746  =head3 GetProperties  =head3 GetProperties
2747    
2748  C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>      my @list = $sprout->GetProperties($fid, $key, $value, $url);
2749    
2750  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2751    
2752  Properties are arbitrary key-value pairs associated with a feature. (At some point they  Properties are the Sprout analog of the FIG attributes. The call is
2753  will also be associated with genomes.) A property value is represented by a 4-tuple of  passed directly to the CustomAttributes or RemoteCustomAttributes object
2754  the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter  contained in this object.
2755    
2756  =over 4  This method returns a series of tuples that match the specified criteria. Each tuple
2757    will contain an object ID, a key, and one or more values. The parameters to this
2758    method therefore correspond structurally to the values expected in each tuple. In
2759    addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any
2760    of the parameters. So, for example,
2761    
2762  =item fid      my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);
2763    
2764  ID of the feature possessing the property.  would return something like
2765    
2766  =item key      ['fig}100226.1.peg.1004', 'structure', 1, 2]
2767        ['fig}100226.1.peg.1004', 'structure1', 1, 2]
2768        ['fig}100226.1.peg.1004', 'structure2', 1, 2]
2769        ['fig}100226.1.peg.1004', 'structureA', 1, 2]
2770    
2771  Name or key of the property.  Use of C<undef> in any position acts as a wild card (all values). You can also specify
2772    a list reference in the ID column. Thus,
2773    
2774  =item value      my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');
2775    
2776  Value of the property.  would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its
2777    features.
2778    
2779  =item url  In addition to values in multiple sections, a single attribute key can have multiple
2780    values, so even
2781    
2782  URL of the document that indicated the property should have this particular value, or an      my @attributeList = $sprout->GetProperties($peg, 'virulent');
 empty string if no such document exists.  
2783    
2784  =back  which has no wildcard in the key or the object ID, may return multiple tuples.
2785    
2786  The parameters act as a filter for the desired data. Any non-null parameter will  =over 4
 automatically match all the tuples returned. So, specifying just the I<$fid> will  
 return all the properties of the specified feature; similarly, specifying the I<$key>  
 and I<$value> parameters will return all the features having the specified property  
 value.  
2787    
2788  A single property key can have many values, representing different ideas about the  =item objectID
 feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is  
 virulent, and another may declare that it is not virulent. A query about the virulence of  
 C<fig|83333.1.peg.10> would be coded as  
2789    
2790      my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');  ID of object whose attributes are desired. If the attributes are desired for multiple
2791    objects, this parameter can be specified as a list reference. If the attributes are
2792    desired for all objects, specify C<undef> or an empty string. Finally, you can specify
2793    attributes for a range of object IDs by putting a percent sign (C<%>) at the end.
2794    
2795  Here the I<$value> and I<$url> fields are left blank, indicating that those fields are  =item key
2796  not to be filtered. The tuples returned would be  
2797    Attribute key name. A value of C<undef> or an empty string will match all
2798    attribute keys. If the values are desired for multiple keys, this parameter can be
2799    specified as a list reference. Finally, you can specify attributes for a range of
2800    keys by putting a percent sign (C<%>) at the end.
2801    
2802    =item values
2803    
2804    List of the desired attribute values, section by section. If C<undef>
2805    or an empty string is specified, all values in that section will match. A
2806    generic match can be requested by placing a percent sign (C<%>) at the end.
2807    In that case, all values that match up to and not including the percent sign
2808    will match. You may also specify a regular expression enclosed
2809    in slashes. All values that match the regular expression will be returned. For
2810    performance reasons, only values have this extra capability.
2811    
2812    =item RETURN
2813    
2814      ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')  Returns a list of tuples. The first element in the tuple is an object ID, the
2815      ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')  second is an attribute key, and the remaining elements are the sections of
2816    the attribute value. All of the tuples will match the criteria set forth in
2817    the parameter list.
2818    
2819    =back
2820    
2821  =cut  =cut
2822  #: Return Type @@;  
2823  sub GetProperties {  sub GetProperties {
2824      # Get the parameters.      # Get the parameters.
2825      my ($self, @parms) = @_;      my ($self, @parms) = @_;
2826      # Declare the return variable.      # Declare the return variable.
2827      my @retVal = ();      my @retVal = $self->{_ca}->GetAttributes(@parms);
     # Now we need to create a WHERE clause that will get us the data we want. First,  
     # we create a list of the columns containing the data for each parameter.  
     my @colNames = ('HasProperty(from-link)', 'Property(property-name)',  
                     'Property(property-value)', 'HasProperty(evidence)');  
     # Now we build the WHERE clause and the list of parameter values.  
     my @where = ();  
     my @values = ();  
     for (my $i = 0; $i <= $#colNames; $i++) {  
         my $parm = $parms[$i];  
         if (defined $parm && ($parm ne '')) {  
             push @where, "$colNames[$i] = ?";  
             push @values, $parm;  
         }  
     }  
     # Format the WHERE clause.  
     my $filter = (@values > 0 ? (join " AND ", @where) : undef);  
     # Ask for all the propertie values with the desired characteristics.  
     my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);  
     while (my $valueObject = $query->Fetch()) {  
         my @tuple = $valueObject->Values(\@colNames);  
         push @retVal, \@tuple;  
     }  
2828      # Return the result.      # Return the result.
2829      return @retVal;      return @retVal;
2830  }  }
2831    
2832  =head3 FeatureProperties  =head3 FeatureProperties
2833    
2834  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2835    
2836  Return a list of the properties for the specified feature. Properties are key-value pairs  Return a list of the properties for the specified feature. Properties are key-value pairs
2837  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
2838  that a feature is essential to the survival of the organism or that it has benign influence  that a feature is essential to the survival of the organism or that it has benign influence
2839  on the activities of a pathogen. Each property is returned as a triple of the form  on the activities of a pathogen. Each property is returned as a triple of the form
2840  C<($key,$value,$url)>, where C<$key> is the property name, C<$value> is its value (commonly  C<($key,@values)>, where C<$key> is the property name and  C<@values> are its values.
 a 1 or a 0, but possibly a string or a floating-point value), and C<$url> is a string describing  
 the web address or citation in which the property's value for the feature was identified.  
2841    
2842  =over 4  =over 4
2843    
# Line 2486  Line 2847 
2847    
2848  =item RETURN  =item RETURN
2849    
2850  Returns a list of triples, each triple containing the property name, its value, and a URL or  Returns a list of tuples, each tuple containing the property name and its values.
 citation.  
2851    
2852  =back  =back
2853    
# Line 2497  Line 2857 
2857      # Get the parameters.      # Get the parameters.
2858      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2859      # Get the properties.      # Get the properties.
2860      my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],      my @attributes = $self->{_ca}->GetAttributes($featureID);
2861                              ['Property(property-name)', 'Property(property-value)',      # Strip the feature ID off each tuple.
2862                               'HasProperty(evidence)']);      my @retVal = ();
2863        for my $attributeRow (@attributes) {
2864            shift @{$attributeRow};
2865            push @retVal, $attributeRow;
2866        }
2867      # Return the resulting list.      # Return the resulting list.
2868      return @retVal;      return @retVal;
2869  }  }
2870    
2871  =head3 DiagramName  =head3 DiagramName
2872    
2873  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2874    
2875  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2876    
# Line 2532  Line 2896 
2896      return $retVal;      return $retVal;
2897  }  }
2898    
2899    =head3 PropertyID
2900    
2901        my $id = $sprout->PropertyID($propName, $propValue);
2902    
2903    Return the ID of the specified property name and value pair, if the
2904    pair exists. Only a small subset of the FIG attributes are stored as
2905    Sprout properties, mostly for use in search optimization.
2906    
2907    =over 4
2908    
2909    =item propName
2910    
2911    Name of the desired property.
2912    
2913    =item propValue
2914    
2915    Value expected for the desired property.
2916    
2917    =item RETURN
2918    
2919    Returns the ID of the name/value pair, or C<undef> if the pair does not exist.
2920    
2921    =back
2922    
2923    =cut
2924    
2925    sub PropertyID {
2926        # Get the parameters.
2927        my ($self, $propName, $propValue) = @_;
2928        # Try to find the ID.
2929        my ($retVal) = $self->GetFlat(['Property'],
2930                                      "Property(property-name) = ? AND Property(property-value) = ?",
2931                                      [$propName, $propValue], 'Property(id)');
2932        # Return the result.
2933        return $retVal;
2934    }
2935    
2936  =head3 MergedAnnotations  =head3 MergedAnnotations
2937    
2938  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2939    
2940  Returns a merged list of the annotations for the features in a list. Each annotation is  Returns a merged list of the annotations for the features in a list. Each annotation is
2941  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where
# Line 2583  Line 2984 
2984    
2985  =head3 RoleNeighbors  =head3 RoleNeighbors
2986    
2987  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
2988    
2989  Returns a list of the roles that occur in the same diagram as the specified role. Because  Returns a list of the roles that occur in the same diagram as the specified role. Because
2990  diagrams and roles are in a many-to-many relationship with each other, the list is  diagrams and roles are in a many-to-many relationship with each other, the list is
# Line 2626  Line 3027 
3027    
3028  =head3 FeatureLinks  =head3 FeatureLinks
3029    
3030  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
3031    
3032  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are
3033  to external websites describing either the feature itself or the organism containing it  to external websites describing either the feature itself or the organism containing it
# Line 2657  Line 3058 
3058    
3059  =head3 SubsystemsOf  =head3 SubsystemsOf
3060    
3061  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
3062    
3063  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
3064  to the roles the feature performs.  to the roles the feature performs.
# Line 2705  Line 3106 
3106    
3107  =head3 SubsystemList  =head3 SubsystemList
3108    
3109  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
3110    
3111  Return a list containing the names of the subsystems in which the specified  Return a list containing the names of the subsystems in which the specified
3112  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2729  Line 3130 
3130      # Get the parameters.      # Get the parameters.
3131      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3132      # Get the list of names.      # Get the list of names.
3133      my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
3134                                  [$featureID], 'HasSSCell(from-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3135        # Return the result, sorted.
3136        return sort @retVal;
3137    }
3138    
3139    =head3 GenomeSubsystemData
3140    
3141        my %featureData = $sprout->GenomeSubsystemData($genomeID);
3142    
3143    Return a hash mapping genome features to their subsystem roles.
3144    
3145    =over 4
3146    
3147    =item genomeID
3148    
3149    ID of the genome whose subsystem feature map is desired.
3150    
3151    =item RETURN
3152    
3153    Returns a hash mapping each feature of the genome to a list of 2-tuples. Eacb
3154    2-tuple contains a subsystem name followed by a role ID.
3155    
3156    =back
3157    
3158    =cut
3159    
3160    sub GenomeSubsystemData {
3161        # Get the parameters.
3162        my ($self, $genomeID) = @_;
3163        # Declare the return variable.
3164        my %retVal = ();
3165        # Get a list of the genome features that participate in subsystems. For each
3166        # feature we get its spreadsheet cells and the corresponding roles.
3167        my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],
3168                                 "HasFeature(from-link) = ?", [$genomeID],
3169                                 ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);
3170        # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems
3171        # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the
3172        # list. We use it at the beginning to get all the spreadsheet cells for the genome and
3173        # again at the end to filter out participation in subsystems with a negative variant code.
3174        my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],
3175                                     "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",
3176                                     [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);
3177        # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.
3178        # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We
3179        # link these two lists together to create the result. First, we want a hash mapping
3180        # spreadsheet cells to subsystem names.
3181        my %subHash = map { $_->[0] => $_->[1] } @cellData;
3182        # We loop through @cellData to build the hash.
3183        for my $roleEntry (@roleData) {
3184            # Get the data for this feature and cell.
3185            my ($fid, $cellID, $role) = @{$roleEntry};
3186            # Check for a subsystem name.
3187            my $subsys = $subHash{$cellID};
3188            if ($subsys) {
3189                # Insure this feature has an entry in the return hash.
3190                if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3191                # Merge in this new data.
3192                push @{$retVal{$fid}}, [$subsys, $role];
3193            }
3194        }
3195      # Return the result.      # Return the result.
3196      return @retVal;      return %retVal;
3197  }  }
3198    
3199  =head3 RelatedFeatures  =head3 RelatedFeatures
3200    
3201  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
3202    
3203  Return a list of the features which are bi-directional best hits of the specified feature and  Return a list of the features which are bi-directional best hits of the specified feature and
3204  have been assigned the specified function by the specified user. If no such features exists,  have been assigned the specified function by the specified user. If no such features exists,
# Line 2770  Line 3231 
3231      # Get the parameters.      # Get the parameters.
3232      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3233      # 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.
3234      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
3235      # Now we loop through the features, pulling out the ones that have the correct      # Now we loop through the features, pulling out the ones that have the correct
3236      # functional assignment.      # functional assignment.
3237      my @retVal = ();      my @retVal = ();
# Line 2790  Line 3249 
3249    
3250  =head3 TaxonomySort  =head3 TaxonomySort
3251    
3252  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3253    
3254  Return a list formed by sorting the specified features by the taxonomy of the containing  Return a list formed by sorting the specified features by the taxonomy of the containing
3255  genome. This will cause genomes from similar organisms to float close to each other.  genome. This will cause genomes from similar organisms to float close to each other.
# Line 2825  Line 3284 
3284          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3285                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3286          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3287          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3288      }      }
3289      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3290      my @retVal = ();      my @retVal = ();
# Line 2836  Line 3295 
3295      return @retVal;      return @retVal;
3296  }  }
3297    
 =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  
 #: Return Type @@;  
 sub GetAll {  
     # Get the parameters.  
     my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;  
     # Call the ERDB method.  
     my @retVal = $self->{_erdb}->GetAll($objectNames, $filterClause, $parameterList,  
                                         $fields, $count);  
     # 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  
 #: Return Type @;  
 sub GetFlat {  
     # Get the parameters.  
     my ($self, $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;  
 }  
   
3298  =head3 Protein  =head3 Protein
3299    
3300  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3301    
3302  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3303    
# Line 3027  Line 3367 
3367      # Loop through the input triples.      # Loop through the input triples.
3368      my $n = length $sequence;      my $n = length $sequence;
3369      for (my $i = 0; $i < $n; $i += 3) {      for (my $i = 0; $i < $n; $i += 3) {
3370          # Get the current triple from the sequence.          # Get the current triple from the sequence. Note we convert to
3371          my $triple = substr($sequence, $i, 3);          # upper case to insure a match.
3372            my $triple = uc substr($sequence, $i, 3);
3373          # Translate it using the table.          # Translate it using the table.
3374          my $protein = "X";          my $protein = "X";
3375          if (exists $table->{$triple}) { $protein = $table->{$triple}; }          if (exists $table->{$triple}) { $protein = $table->{$triple}; }
# Line 3042  Line 3383 
3383    
3384  =head3 LoadInfo  =head3 LoadInfo
3385    
3386  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3387    
3388  Return the name of the directory from which data is to be loaded and a list of the relation  Return the name of the directory from which data is to be loaded and a list of the relation
3389  names. This information is useful when trying to analyze what needs to be put where in order  names. This information is useful when trying to analyze what needs to be put where in order
# Line 3056  Line 3397 
3397      # 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.
3398      my @retVal = ($self->{_options}->{dataDir});      my @retVal = ($self->{_options}->{dataDir});
3399      # Concatenate the table names.      # Concatenate the table names.
3400      push @retVal, $self->{_erdb}->GetTableNames();      push @retVal, $self->GetTableNames();
3401      # Return the result.      # Return the result.
3402      return @retVal;      return @retVal;
3403  }  }
3404    
3405    =head3 BBHMatrix
3406    
3407        my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3408    
3409    Find all the bidirectional best hits for the features of a genome in a
3410    specified list of target genomes. The return value will be a hash mapping
3411    features in the original genome to their bidirectional best hits in the
3412    target genomes.
3413    
3414    =over 4
3415    
3416    =item genomeID
3417    
3418    ID of the genome whose features are to be examined for bidirectional best hits.
3419    
3420    =item cutoff
3421    
3422    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3423    
3424    =item targets
3425    
3426    List of target genomes. Only pairs originating in the original
3427    genome and landing in one of the target genomes will be returned.
3428    
3429    =item RETURN
3430    
3431    Returns a hash mapping each feature in the original genome to a hash mapping its
3432    BBH pegs in the target genomes to their scores.
3433    
3434    =back
3435    
3436    =cut
3437    
3438    sub BBHMatrix {
3439        # Get the parameters.
3440        my ($self, $genomeID, $cutoff, @targets) = @_;
3441        # Declare the return variable.
3442        my %retVal = ();
3443        # Ask for the BBHs.
3444        my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3445        # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3446        for my $bbhData (@bbhList) {
3447            my ($peg1, $peg2, $score) = @{$bbhData};
3448            if (! exists $retVal{$peg1}) {
3449                $retVal{$peg1} = { $peg2 => $score };
3450            } else {
3451                $retVal{$peg1}->{$peg2} = $score;
3452            }
3453        }
3454        # Return the result.
3455        return %retVal;
3456    }
3457    
3458    
3459    =head3 SimMatrix
3460    
3461        my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3462    
3463    Find all the similarities for the features of a genome in a
3464    specified list of target genomes. The return value will be a hash mapping
3465    features in the original genome to their similarites in the
3466    target genomes.
3467    
3468    =over 4
3469    
3470    =item genomeID
3471    
3472    ID of the genome whose features are to be examined for similarities.
3473    
3474    =item cutoff
3475    
3476    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3477    
3478    =item targets
3479    
3480    List of target genomes. Only pairs originating in the original
3481    genome and landing in one of the target genomes will be returned.
3482    
3483    =item RETURN
3484    
3485    Returns a hash mapping each feature in the original genome to a hash mapping its
3486    similar pegs in the target genomes to their scores.
3487    
3488    =back
3489    
3490    =cut
3491    
3492    sub SimMatrix {
3493        # Get the parameters.
3494        my ($self, $genomeID, $cutoff, @targets) = @_;
3495        # Declare the return variable.
3496        my %retVal = ();
3497        # Get the list of features in the source organism.
3498        my @fids = $self->FeaturesOf($genomeID);
3499        # Ask for the sims. We only want similarities to fig features.
3500        my $simList = FIGRules::GetNetworkSims($self, \@fids, {}, 1000, $cutoff, "fig");
3501        if (! defined $simList) {
3502            Confess("Unable to retrieve similarities from server.");
3503        } else {
3504            Trace("Processing sims.") if T(3);
3505            # We now have a set of sims that we need to convert into a hash of hashes. First, we
3506            # Create a hash for the target genomes.
3507            my %targetHash = map { $_ => 1 } @targets;
3508            for my $simData (@{$simList}) {
3509                # Get the PEGs and the score.
3510                my ($peg1, $peg2, $score) = ($simData->id1, $simData->id2, $simData->psc);
3511                # Insure the second ID is in the target list.
3512                my ($genome2) = FIGRules::ParseFeatureID($peg2);
3513                if (exists $targetHash{$genome2}) {
3514                    # Here it is. Now we need to add it to the return hash. How we do that depends
3515                    # on whether or not $peg1 is new to us.
3516                    if (! exists $retVal{$peg1}) {
3517                        $retVal{$peg1} = { $peg2 => $score };
3518                    } else {
3519                        $retVal{$peg1}->{$peg2} = $score;
3520                    }
3521                }
3522            }
3523        }
3524        # Return the result.
3525        return %retVal;
3526    }
3527    
3528    
3529  =head3 LowBBHs  =head3 LowBBHs
3530    
3531  C<< my %bbhMap = $sprout->GoodBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3532    
3533  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
3534  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 3092  Line 3557 
3557      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3558      # Create the return hash.      # Create the return hash.
3559      my %retVal = ();      my %retVal = ();
3560      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3561      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3562      # Form the results into the return hash.      # Form the results into the return hash.
3563      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3564          $retVal{$pair->[0]} = $pair->[1];          my $fid = $pair->[0];
3565            if ($self->Exists('Feature', $fid)) {
3566                $retVal{$fid} = $pair->[1];
3567            }
3568      }      }
3569      # Return the result.      # Return the result.
3570      return %retVal;      return %retVal;
3571  }  }
3572    
3573    =head3 Sims
3574    
3575        my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3576    
3577    Get a list of similarities for a specified feature. Similarity information is not kept in the
3578    Sprout database; rather, they are retrieved from a network server. The similarities are
3579    returned as B<Sim> objects. A Sim object is actually a list reference that has been blessed
3580    so that its elements can be accessed by name.
3581    
3582    Similarities can be either raw or expanded. The raw similarities are basic
3583    hits between features with similar DNA. Expanding a raw similarity drags in any
3584    features considered substantially identical. So, for example, if features B<A1>,
3585    B<A2>, and B<A3> are all substantially identical to B<A>, then a raw similarity
3586    B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.
3587    
3588    =over 4
3589    
3590    =item fid
3591    
3592    ID of the feature whose similarities are desired, or reference to a list of IDs
3593    of features whose similarities are desired.
3594    
3595    =item maxN
3596    
3597    Maximum number of similarities to return.
3598    
3599    =item maxP
3600    
3601    Minumum allowable similarity score.
3602    
3603    =item select
3604    
3605    Selection criterion: C<raw> means only raw similarities are returned; C<fig>
3606    means only similarities to FIG features are returned; C<all> means all expanded
3607    similarities are returned; and C<figx> means similarities are expanded until the
3608    number of FIG features equals the maximum.
3609    
3610    =item max_expand
3611    
3612    The maximum number of features to expand.
3613    
3614    =item filters
3615    
3616    Reference to a hash containing filter information, or a subroutine that can be
3617    used to filter the sims.
3618    
3619    =item RETURN
3620    
3621    Returns a reference to a list of similarity objects, or C<undef> if an error
3622    occurred.
3623    
3624    =back
3625    
3626    =cut
3627    
3628    sub Sims {
3629        # Get the parameters.
3630        my ($self, $fid, $maxN, $maxP, $select, $max_expand, $filters) = @_;
3631        # Create the shim object to test for deleted FIDs.
3632        my $shim = FidCheck->new($self);
3633        # Ask the network for sims.
3634        my $retVal = FIGRules::GetNetworkSims($shim, $fid, {}, $maxN, $maxP, $select, $max_expand, $filters);
3635        # Return the result.
3636        return $retVal;
3637    }
3638    
3639    =head3 IsAllGenomes
3640    
3641        my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3642    
3643    Return TRUE if all genomes in the second list are represented in the first list at
3644    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3645    compared to a list of all the genomes.
3646    
3647    =over 4
3648    
3649    =item list
3650    
3651    Reference to the list to be compared to the second list.
3652    
3653    =item checkList (optional)
3654    
3655    Reference to the comparison target list. Every genome ID in this list must occur at
3656    least once in the first list. If this parameter is omitted, a list of all the genomes
3657    is used.
3658    
3659    =item RETURN
3660    
3661    Returns TRUE if every item in the second list appears at least once in the
3662    first list, else FALSE.
3663    
3664    =back
3665    
3666    =cut
3667    
3668    sub IsAllGenomes {
3669        # Get the parameters.
3670        my ($self, $list, $checkList) = @_;
3671        # Supply the checklist if it was omitted.
3672        $checkList = [$self->Genomes()] if ! defined($checkList);
3673        # Create a hash of the original list.
3674        my %testList = map { $_ => 1 } @{$list};
3675        # Declare the return variable. We assume that the representation
3676        # is complete and stop at the first failure.
3677        my $retVal = 1;
3678        my $n = scalar @{$checkList};
3679        for (my $i = 0; $retVal && $i < $n; $i++) {
3680            if (! $testList{$checkList->[$i]}) {
3681                $retVal = 0;
3682            }
3683        }
3684        # Return the result.
3685        return $retVal;
3686    }
3687    
3688  =head3 GetGroups  =head3 GetGroups
3689    
3690  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3691    
3692  Return a hash mapping each group to the IDs of the genomes in the group.  Return a hash mapping each group to the IDs of the genomes in the group.
3693  A list of groups may be specified, in which case only those groups will be  A list of groups may be specified, in which case only those groups will be
# Line 3126  Line 3706 
3706          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3707          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3708          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3709              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3710                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3711              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3712          }          }
# Line 3134  Line 3714 
3714          # Here we need all of the groups. In this case, we run through all          # Here we need all of the groups. In this case, we run through all
3715          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3716          # group. Note that we use a filter clause to insure that only genomes          # group. Note that we use a filter clause to insure that only genomes
3717          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3718          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3719                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3720          # Loop through the genomes found.          # Loop through the genomes found.
3721          for my $genome (@genomes) {          for my $genome (@genomes) {
3722              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3723              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3724              my $genomeID = shift @groups;              push @{$retVal{$group}}, $genomeID;
             # Loop through the groups, adding the genome ID to each group's  
             # list.  
             for my $group (@groups) {  
                 Tracer::AddToListMap(\%retVal, $group, $genomeID);  
             }  
3725          }          }
3726      }      }
3727      # Return the hash we just built.      # Return the hash we just built.
# Line 3155  Line 3730 
3730    
3731  =head3 MyGenomes  =head3 MyGenomes
3732    
3733  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3734    
3735  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3736    
# Line 3187  Line 3762 
3762    
3763  =head3 LoadFileName  =head3 LoadFileName
3764    
3765  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3766    
3767  Return the name of the load file for the specified table in the specified data  Return the name of the load file for the specified table in the specified data
3768  directory.  directory.
# Line 3228  Line 3803 
3803    
3804  =head3 DeleteGenome  =head3 DeleteGenome
3805    
3806  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3807    
3808  Delete a genome from the database.  Delete a genome from the database.
3809    
# Line 3254  Line 3829 
3829      # Get the parameters.      # Get the parameters.
3830      my ($self, $genomeID, $testFlag) = @_;      my ($self, $genomeID, $testFlag) = @_;
3831      # Perform the delete for the genome's features.      # Perform the delete for the genome's features.
3832      my $retVal = $self->{_erdb}->Delete('Feature', "fig|$genomeID.%", $testFlag);      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", testMode => $testFlag);
3833      # Perform the delete for the primary genome data.      # Perform the delete for the primary genome data.
3834      my $stats = $self->{_erdb}->Delete('Genome', $genomeID, $testFlag);      my $stats = $self->Delete('Genome', $genomeID, testMode => $testFlag);
3835      $retVal->Accumulate($stats);      $retVal->Accumulate($stats);
3836      # Return the result.      # Return the result.
3837      return $retVal;      return $retVal;
3838  }  }
3839    
3840    =head3 Fix
3841    
3842        my %fixedHash = $sprout->Fix(%groupHash);
3843    
3844    Prepare a genome group hash (like that returned by L</GetGroups>) for processing.
3845    The groups will be combined into the appropriate super-groups.
3846    
3847    =over 4
3848    
3849    =item groupHash
3850    
3851    Hash to be fixed up.
3852    
3853    =item RETURN
3854    
3855    Returns a fixed-up version of the hash.
3856    
3857    =back
3858    
3859    =cut
3860    
3861    sub Fix {
3862        # Get the parameters.
3863        my ($self, %groupHash) = @_;
3864        # Create the result hash.
3865        my %retVal = ();
3866        # Copy over the genomes.
3867        for my $groupID (keys %groupHash) {
3868            # Get the super-group name.
3869            my $realGroupID = $self->SuperGroup($groupID);
3870            # Append this group's genomes into the result hash
3871            # using the super-group name.
3872            push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
3873        }
3874        # Return the result hash.
3875        return %retVal;
3876    }
3877    
3878    =head3 GroupPageName
3879    
3880        my $name = $sprout->GroupPageName($group);
3881    
3882    Return the name of the page for the specified NMPDR group.
3883    
3884    =over 4
3885    
3886    =item group
3887    
3888    Name of the relevant group.
3889    
3890    =item RETURN
3891    
3892    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3893    memory it will be read in.
3894    
3895    =back
3896    
3897    =cut
3898    
3899    sub GroupPageName {
3900        # Get the parameters.
3901        my ($self, $group) = @_;
3902        # Check for the group file data.
3903        my %superTable = $self->CheckGroupFile();
3904        # Compute the real group name.
3905        my $realGroup = $self->SuperGroup($group);
3906        # Get the associated page name.
3907        my $retVal = "../content/$superTable{$realGroup}->{page}";
3908        # Return the result.
3909        return $retVal;
3910    }
3911    
3912    
3913    =head3 AddProperty
3914    
3915        $sprout->AddProperty($featureID, $key, @values);
3916    
3917    Add a new attribute value (Property) to a feature.
3918    
3919    =over 4
3920    
3921    =item peg
3922    
3923    ID of the feature to which the attribute is to be added.
3924    
3925    =item key
3926    
3927    Name of the attribute (key).
3928    
3929    =item values
3930    
3931    Values of the attribute.
3932    
3933    =back
3934    
3935    =cut
3936    #: Return Type ;
3937    sub AddProperty {
3938        # Get the parameters.
3939        my ($self, $featureID, $key, @values) = @_;
3940        # Add the property using the attached attributes object.
3941        $self->{_ca}->AddAttribute($featureID, $key, @values);
3942    }
3943    
3944    =head3 CheckGroupFile
3945    
3946        my %groupData = $sprout->CheckGroupFile();
3947    
3948    Get the group file hash. The group file hash describes the relationship
3949    between a group and the super-group to which it belongs for purposes of
3950    display. The super-group name is computed from the first capitalized word
3951    in the actual group name. For each super-group, the group file contains
3952    the page name and a list of the species expected to be in the group.
3953    Each species is specified by a genus and a species name. A species name
3954    of C<0> implies an entire genus.
3955    
3956    This method returns a hash from super-group names to a hash reference. Each
3957    resulting hash reference contains the following fields.
3958    
3959    =over 4
3960    
3961    =item page
3962    
3963    The super-group's web page in the NMPDR.
3964    
3965    =item contents
3966    
3967    A list of 2-tuples, each containing a genus name followed by a species name
3968    (or 0, indicating all species). This list indicates which organisms belong
3969    in the super-group.
3970    
3971    =back
3972    
3973    =cut
3974    
3975    sub CheckGroupFile {
3976        # Get the parameters.
3977        my ($self) = @_;
3978        # Check to see if we already have this hash.
3979        if (! defined $self->{groupHash}) {
3980            # We don't, so we need to read it in.
3981            my %groupHash;
3982            # Read the group file.
3983            my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3984            # Loop through the list of sort-of groups.
3985            for my $groupLine (@groupLines) {
3986                my ($name, $page, @contents) = split /\t/, $groupLine;
3987                $groupHash{$name} = { page => $page,
3988                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3989                                    };
3990            }
3991            # Save the hash.
3992            $self->{groupHash} = \%groupHash;
3993        }
3994        # Return the result.
3995        return %{$self->{groupHash}};
3996    }
3997    
3998    =head2 Virtual Methods
3999    
4000    =head3 CleanKeywords
4001    
4002        my $cleanedString = $sprout->CleanKeywords($searchExpression);
4003    
4004    Clean up a search expression or keyword list. This involves converting the periods
4005    in EC numbers to underscores, converting non-leading minus signs to underscores,
4006    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
4007    characters. In addition, any extra spaces are removed.
4008    
4009    =over 4
4010    
4011    =item searchExpression
4012    
4013    Search expression or keyword list to clean. Note that a search expression may
4014    contain boolean operators which need to be preserved. This includes leading
4015    minus signs.
4016    
4017    =item RETURN
4018    
4019    Cleaned expression or keyword list.
4020    
4021    =back
4022    
4023    =cut
4024    
4025    sub CleanKeywords {
4026        # Get the parameters.
4027        my ($self, $searchExpression) = @_;
4028        # Perform the standard cleanup.
4029        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
4030        # Fix the periods in EC and TC numbers.
4031        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
4032        # Fix non-trailing periods.
4033        $retVal =~ s/\.(\w)/_$1/g;
4034        # Fix non-leading minus signs.
4035        $retVal =~ s/(\w)[\-]/$1_/g;
4036        # Fix the vertical bars and colons
4037        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
4038        # Return the result.
4039        return $retVal;
4040    }
4041    
4042  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4043    
4044  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3272  Line 4049 
4049    
4050  A functional assignment is always of the form  A functional assignment is always of the form
4051    
4052      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
4053        ZZZZ
4054    
4055  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
4056  the user and the assigning user (from MadeAnnotation) will be the same, but that is  the user and the assigning user (from MadeAnnotation) will be the same, but that is
# Line 3318  Line 4096 
4096      }      }
4097      # If we have an assignment, we need to clean the function text. There may be      # If we have an assignment, we need to clean the function text. There may be
4098      # extra junk at the end added as a note from the user.      # extra junk at the end added as a note from the user.
4099      if (@retVal) {      if (defined( $retVal[1] )) {
4100          $retVal[1] =~ s/(\t\S)?\s*$//;          $retVal[1] =~ s/(\t\S)?\s*$//;
4101      }      }
4102      # Return the result list.      # Return the result list.
4103      return @retVal;      return @retVal;
4104  }  }
4105    
4106  =head3 FriendlyTimestamp  =head3 _CheckFeature
4107    
4108  Convert a time number to a user-friendly time stamp for display.      my $flag = $sprout->_CheckFeature($fid);
4109    
4110  This is a static method.  Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.
4111    
4112  =over 4  =over 4
4113    
4114  =item timeValue  =item fid
4115    
4116  Numeric time value.  Feature ID to check.
4117    
4118  =item RETURN  =item RETURN
4119    
4120  Returns a string containing the same time in user-readable format.  Returns TRUE if the FID is for one of the NMPDR genomes, else FALSE.
4121    
4122  =back  =back
4123    
4124  =cut  =cut
4125    
4126  sub FriendlyTimestamp {  sub _CheckFeature {
4127      my ($timeValue) = @_;      # Get the parameters.
4128      my $retVal = localtime($timeValue);      my ($self, $fid) = @_;
4129      return $retVal;      # Insure we have a genome hash.
4130        if (! defined $self->{genomeHash}) {
4131            my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');
4132            $self->{genomeHash} = \%genomeHash;
4133        }
4134        # Get the feature's genome ID.
4135        my ($genomeID) = FIGRules::ParseFeatureID($fid);
4136        # Return an indicator of whether or not the genome ID is in the hash.
4137        return ($self->{genomeHash}->{$genomeID} ? 1 : 0);
4138  }  }
4139    
4140  =head3 AddProperty  =head3 FriendlyTimestamp
4141    
4142  C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>  Convert a time number to a user-friendly time stamp for display.
4143    
4144  Add a new attribute value (Property) to a feature. In the SEED system, attributes can  This is a static method.
 be added to almost any object. In Sprout, they can only be added to features. In  
 Sprout, attributes are implemented using I<properties>. A property represents a key/value  
 pair. If the particular key/value pair coming in is not already in the database, a new  
 B<Property> record is created to hold it.  
4145    
4146  =over 4  =over 4
4147    
4148  =item peg  =item timeValue
   
 ID of the feature to which the attribute is to be replied.  
   
 =item key  
   
 Name of the attribute (key).  
   
 =item value  
4149    
4150  Value of the attribute.  Numeric time value.
4151    
4152  =item url  =item RETURN
4153    
4154  URL or text citation from which the property was obtained.  Returns a string containing the same time in user-readable format.
4155    
4156  =back  =back
4157    
4158  =cut  =cut
4159  #: Return Type ;  
4160  sub AddProperty {  sub FriendlyTimestamp {
4161      # Get the parameters.      my ($timeValue) = @_;
4162      my ($self, $featureID, $key, $value, $url) = @_;      my $retVal = localtime($timeValue);
4163      # Declare the variable to hold the desired property ID.      return $retVal;
     my $propID;  
     # Attempt to find a property record for this key/value pair.  
     my @properties = $self->GetFlat(['Property'],  
                                    "Property(property-name) = ? AND Property(property-value) = ?",  
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
         # Here the property value does not exist. We need to generate an ID. It will be set  
         # to a number one greater than the maximum value in the database. This call to  
         # GetAll will stop after one record.  
         my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],  
                                         1);  
         $propID = $maxProperty[0]->[0] + 1;  
         # Insert the new property value.  
         $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });  
     }  
     # Now we connect the incoming feature to the property.  
     $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });  
4164  }  }
4165    
4166    

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.109

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3