[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.54, Thu Feb 16 04:10:07 2006 UTC revision 1.84, Thu Sep 14 14:11:09 2006 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
3        require Exporter;
4        use ERDB;
5        @ISA = qw(Exporter ERDB);
6      use Data::Dumper;      use Data::Dumper;
7      use strict;      use strict;
8      use Carp;      use Carp;
# Line 7  Line 10 
10      use XML::Simple;      use XML::Simple;
11      use DBQuery;      use DBQuery;
12      use DBObject;      use DBObject;
     use ERDB;  
13      use Tracer;      use Tracer;
14      use FIGRules;      use FIGRules;
15        use FidCheck;
16      use Stats;      use Stats;
17      use POSIX qw(strftime);      use POSIX qw(strftime);
18        use BasicLocation;
19    
20  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
21    
# Line 32  Line 35 
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</dna_seq> 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    
42  #: Constructor SFXlate->new_sprout_only();  #: Constructor SFXlate->new_sprout_only();
# 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>)
# Line 85  Line 92 
92  sub new {  sub new {
93      # Get the parameters.      # Get the parameters.
94      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
95        # Compute the DBD directory.
96        my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
97                                                      $FIG_Config::fig );
98      # 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
99      # the incoming data.      # the incoming data.
100      my $optionTable = Tracer::GetOptions({      my $optionTable = Tracer::GetOptions({
# Line 92  Line 102 
102                                                          # database type                                                          # database type
103                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
104                                                          # data file directory                                                          # data file directory
105                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
106                                                          # database definition file name                                                          # database definition file name
107                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
108                                                          # user name and password                                                          # user name and password
109                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
110                                                          # database connection port                                                          # database connection port
111                           sock         => $FIG_Config::dbsock,
112                           host         => $FIG_Config::dbhost,
113                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
114                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
115                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 111  Line 123 
123      my $dbh;      my $dbh;
124      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
125          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
126                                  $password, $optionTable->{port});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
127      }      }
128      # Create the ERDB object.      # Create the ERDB object.
129      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
130      my $erdb = ERDB->new($dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName);
131      # Create this object.      # Add the option table and XML file name.
132      my $self = { _erdb => $erdb, _options => $optionTable, _xmlName => $xmlFileName };      $retVal->{_options} = $optionTable;
133      # Bless and return it.      $retVal->{_xmlName} = $xmlFileName;
134      bless $self;      # Return it.
135      return $self;      return $retVal;
136  }  }
137    
138  =head3 MaxSegment  =head3 MaxSegment
# Line 155  Line 167 
167      return $self->{_options}->{maxSequenceLength};      return $self->{_options}->{maxSequenceLength};
168  }  }
169    
 =head3 Get  
   
 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.  
   
 C<< $query = $sprout->Get(['Genome'], "ORDER BY Genome(genus), Genome(species)"); >>  
   
 Odd things may happen if one of the ORDER BY fields is in a secondary relation. So, for example, an  
 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.  
   
 =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 RETURN  
   
 Returns a B<DBQuery> that can be used to iterate through all of the results.  
   
 =back  
   
 =cut  
   
 sub Get {  
     # Get the parameters.  
     my ($self, $objectNames, $filterClause, $parameterList) = @_;  
     # We differ from the ERDB Get method in that the parameter list is passed in as a list reference  
     # rather than a list of parameters. The next step is to convert the parameters from a reference  
     # to a real list. We can only do this if the parameters have been specified.  
     my @parameters;  
     if ($parameterList) { @parameters = @{$parameterList}; }  
     return $self->{_erdb}->Get($objectNames, $filterClause, @parameters);  
 }  
   
 =head3 GetEntity  
   
 C<< my $entityObject = $sprout->GetEntity($entityType, $ID); >>  
   
 Return an object describing the entity instance with a specified ID.  
   
 =over 4  
   
 =item entityType  
   
 Entity type name.  
   
 =item ID  
   
 ID of the desired entity.  
   
 =item RETURN  
   
 Returns a B<DBObject> representing the desired entity instance, or an undefined value if no  
 instance is found with the specified key.  
   
 =back  
   
 =cut  
   
 sub GetEntity {  
     # Get the parameters.  
     my ($self, $entityType, $ID) = @_;  
     # Call the ERDB method.  
     return $self->{_erdb}->GetEntity($entityType, $ID);  
 }  
   
 =head3 GetEntityValues  
   
 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  
   
 Returns a flattened list of the values of the specified fields for the specified entity.  
   
 =back  
   
 =cut  
 #: Return Type @;  
 sub GetEntityValues {  
     # Get the parameters.  
     my ($self, $entityType, $ID, $fields) = @_;  
     # Call the ERDB method.  
     return $self->{_erdb}->GetEntityValues($entityType, $ID, $fields);  
 }  
   
 =head3 ShowMetaData  
   
 C<< $sprout->ShowMetaData($fileName); >>  
   
 This method outputs a description of the database to an HTML file in the data directory.  
   
 =over 4  
   
 =item fileName  
   
 Fully-qualified name to give to the output file.  
   
 =back  
   
 =cut  
   
 sub ShowMetaData {  
     # Get the parameters.  
     my ($self, $fileName) = @_;  
     # Compute the file name.  
     my $options = $self->{_options};  
     # Call the show method on the underlying ERDB object.  
     $self->{_erdb}->ShowMetaData($fileName);  
 }  
   
170  =head3 Load  =head3 Load
171    
172  C<< $sprout->Load($rebuild); >>;  C<< $sprout->Load($rebuild); >>;
# Line 379  Line 201 
201  sub Load {  sub Load {
202      # Get the parameters.      # Get the parameters.
203      my ($self, $rebuild) = @_;      my ($self, $rebuild) = @_;
     # Get the database object.  
     my $erdb = $self->{_erdb};  
204      # Load the tables from the data directory.      # Load the tables from the data directory.
205      my $retVal = $erdb->LoadTables($self->{_options}->{dataDir}, $rebuild);      my $retVal = $self->LoadTables($self->{_options}->{dataDir}, $rebuild);
206      # Return the statistics.      # Return the statistics.
207      return $retVal;      return $retVal;
208  }  }
# Line 422  Line 242 
242  sub LoadUpdate {  sub LoadUpdate {
243      # Get the parameters.      # Get the parameters.
244      my ($self, $truncateFlag, $tableList) = @_;      my ($self, $truncateFlag, $tableList) = @_;
     # Get the database object.  
     my $erdb = $self->{_erdb};  
245      # Declare the return value.      # Declare the return value.
246      my $retVal = Stats->new();      my $retVal = Stats->new();
247      # Get the data directory.      # Get the data directory.
# Line 437  Line 255 
255              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
256          } else {          } else {
257              # Attempt to load this table.              # Attempt to load this table.
258              my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);
259              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
260              $retVal->Accumulate($result);              $retVal->Accumulate($result);
261          }          }
# Line 446  Line 264 
264      return $retVal;      return $retVal;
265  }  }
266    
267    =head3 GenomeCounts
268    
269    C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>
270    
271    Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
272    genomes will be included in the counts.
273    
274    =over 4
275    
276    =item complete
277    
278    TRUE if only complete genomes are to be counted, FALSE if all genomes are to be
279    counted
280    
281    =item RETURN
282    
283    A six-element list containing the number of genomes in each of six categories--
284    Archaea, Bacteria, Eukaryota, Viral, Environmental, and Unknown, respectively.
285    
286    =back
287    
288    =cut
289    
290    sub GenomeCounts {
291        # Get the parameters.
292        my ($self, $complete) = @_;
293        # Set the filter based on the completeness flag.
294        my $filter = ($complete ? "Genome(complete) = 1" : "");
295        # Get all the genomes and the related taxonomy information.
296        my @genomes = $self->GetAll(['Genome'], $filter, [], ['Genome(id)', 'Genome(taxonomy)']);
297        # Clear the counters.
298        my ($arch, $bact, $euk, $vir, $env, $unk) = (0, 0, 0, 0, 0, 0);
299        # Loop through, counting the domains.
300        for my $genome (@genomes) {
301            if    ($genome->[1] =~ /^archaea/i)  { ++$arch }
302            elsif ($genome->[1] =~ /^bacter/i)   { ++$bact }
303            elsif ($genome->[1] =~ /^eukar/i)    { ++$euk }
304            elsif ($genome->[1] =~ /^vir/i)      { ++$vir }
305            elsif ($genome->[1] =~ /^env/i)      { ++$env }
306            else  { ++$unk }
307        }
308        # Return the counts.
309        return ($arch, $bact, $euk, $vir, $env, $unk);
310    }
311    
312    =head3 ContigCount
313    
314    C<< my $count = $sprout->ContigCount($genomeID); >>
315    
316    Return the number of contigs for the specified genome ID.
317    
318    =over 4
319    
320    =item genomeID
321    
322    ID of the genome whose contig count is desired.
323    
324    =item RETURN
325    
326    Returns the number of contigs for the specified genome.
327    
328    =back
329    
330    =cut
331    
332    sub ContigCount {
333        # Get the parameters.
334        my ($self, $genomeID) = @_;
335        # Get the contig count.
336        my $retVal = $self->GetCount(['Contig', 'HasContig'], "HasContig(from-link) = ?", [$genomeID]);
337        # Return the result.
338        return $retVal;
339    }
340    
341    =head3 GeneMenu
342    
343    C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>
344    
345    Return an HTML select menu of genomes. Each genome will be an option in the menu,
346    and will be displayed by name with the ID and a contig count attached. The selection
347    value will be the genome ID. The genomes will be sorted by genus/species name.
348    
349    =over 4
350    
351    =item attributes
352    
353    Reference to a hash mapping attributes to values for the SELECT tag generated.
354    
355    =item filterString
356    
357    A filter string for use in selecting the genomes. The filter string must conform
358    to the rules for the C<< ERDB->Get >> method.
359    
360    =item params
361    
362    Reference to a list of values to be substituted in for the parameter marks in
363    the filter string.
364    
365    =item RETURN
366    
367    Returns an HTML select menu with the specified genomes as selectable options.
368    
369    =back
370    
371    =cut
372    
373    sub GeneMenu {
374        # Get the parameters.
375        my ($self, $attributes, $filterString, $params) = @_;
376        # Start the menu.
377        my $retVal = "<select " .
378            join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
379            ">\n";
380        # Get the genomes.
381        my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',
382                                                                         'Genome(genus)',
383                                                                         'Genome(species)',
384                                                                         'Genome(unique-characterization)']);
385        # Sort them by name.
386        my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;
387        # Loop through the genomes, creating the option tags.
388        for my $genomeData (@sorted) {
389            # Get the data for this genome.
390            my ($genomeID, $genus, $species, $strain) = @{$genomeData};
391            # Get the contig count.
392            my $count = $self->ContigCount($genomeID);
393            my $counting = ($count == 1 ? "contig" : "contigs");
394            # Build the option tag.
395            $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";
396            Trace("Option tag built for $genomeID: $genus $species $strain.") if T(3);
397        }
398        # Close the SELECT tag.
399        $retVal .= "</select>\n";
400        # Return the result.
401        return $retVal;
402    }
403  =head3 Build  =head3 Build
404    
405  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 460  Line 414 
414      # Get the parameters.      # Get the parameters.
415      my ($self) = @_;      my ($self) = @_;
416      # Create the tables.      # Create the tables.
417      $self->{_erdb}->CreateTables;      $self->CreateTables();
418  }  }
419    
420  =head3 Genomes  =head3 Genomes
# Line 740  Line 694 
694  should be of the form returned by L</featureLocation> when in a list context. In other words,  should be of the form returned by L</featureLocation> when in a list context. In other words,
695  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.
696    
697    For example, the following would return the DNA sequence for contig C<83333.1:NC_000913>
698    between positions 1401 and 1532, inclusive.
699    
700        my $sequence = $sprout->DNASeq('83333.1:NC_000913_1401_1532');
701    
702  =over 4  =over 4
703    
704  =item locationList  =item locationList
705    
706  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<end> (see  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<len> or
707  L</FeatureLocation> for more about this format).  I<contigID>C<_>I<begin>C<_>I<end> (see L</FeatureLocation> for more about this format).
708    
709  =item RETURN  =item RETURN
710    
# Line 841  Line 800 
800      return @retVal;      return @retVal;
801  }  }
802    
803    =head3 GenomeLength
804    
805    C<< my $length = $sprout->GenomeLength($genomeID); >>
806    
807    Return the length of the specified genome in base pairs.
808    
809    =over 4
810    
811    =item genomeID
812    
813    ID of the genome whose base pair count is desired.
814    
815    =item RETURN
816    
817    Returns the number of base pairs in all the contigs of the specified
818    genome.
819    
820    =back
821    
822    =cut
823    
824    sub GenomeLength {
825        # Get the parameters.
826        my ($self, $genomeID) = @_;
827        # Declare the return variable.
828        my $retVal = 0;
829        # Get the genome's contig sequence lengths.
830        my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',
831                           [$genomeID], 'IsMadeUpOf(len)');
832        # Sum the lengths.
833        map { $retVal += $_ } @lens;
834        # Return the result.
835        return $retVal;
836    }
837    
838    =head3 FeatureCount
839    
840    C<< my $count = $sprout->FeatureCount($genomeID, $type); >>
841    
842    Return the number of features of the specified type in the specified genome.
843    
844    =over 4
845    
846    =item genomeID
847    
848    ID of the genome whose feature count is desired.
849    
850    =item type
851    
852    Type of feature to count (eg. C<peg>, C<rna>, etc.).
853    
854    =item RETURN
855    
856    Returns the number of features of the specified type for the specified genome.
857    
858    =back
859    
860    =cut
861    
862    sub FeatureCount {
863        # Get the parameters.
864        my ($self, $genomeID, $type) = @_;
865        # Compute the count.
866        my $retVal = $self->GetCount(['HasFeature', 'Feature'],
867                                    "HasFeature(from-link) = ? AND Feature(feature-type) = ?",
868                                    [$genomeID, $type]);
869        # Return the result.
870        return $retVal;
871    }
872    
873    =head3 GenomeAssignments
874    
875    C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>
876    
877    Return a list of a genome's assigned features. The return hash will contain each
878    assigned feature of the genome mapped to the text of its most recent functional
879    assignment.
880    
881    =over 4
882    
883    =item genomeID
884    
885    ID of the genome whose functional assignments are desired.
886    
887    =item RETURN
888    
889    Returns a reference to a hash which maps each feature to its most recent
890    functional assignment.
891    
892    =back
893    
894    =cut
895    
896    sub GenomeAssignments {
897        # Get the parameters.
898        my ($self, $genomeID) = @_;
899        # Declare the return variable.
900        my $retVal = {};
901        # Query the genome's features and annotations. We'll put the oldest annotations
902        # first so that the last assignment to go into the hash will be the correct one.
903        my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'],
904                               "HasFeature(from-link) = ? ORDER BY Annotation(time)",
905                               [$genomeID]);
906        # Loop through the annotations.
907        while (my $data = $query->Fetch) {
908            # Get the feature ID and annotation text.
909            my ($fid, $annotation) = $data->Values(['HasFeature(to-link)',
910                                                    'Annotation(annotation)']);
911            # Check to see if this is an assignment. Note that the user really
912            # doesn't matter to us, other than we use it to determine whether or
913            # not this is an assignment.
914            my ($user, $assignment) = _ParseAssignment('fig', $annotation);
915            if ($user) {
916                # Here it's an assignment. We put it in the return hash, overwriting
917                # any older assignment that might be present.
918                $retVal->{$fid} = $assignment;
919            }
920        }
921        # Return the result.
922        return $retVal;
923    }
924    
925  =head3 ContigLength  =head3 ContigLength
926    
927  C<< my $length = $sprout->ContigLength($contigID); >>  C<< my $length = $sprout->ContigLength($contigID); >>
# Line 1395  Line 1476 
1476      my %retVal = ();      my %retVal = ();
1477      # Loop through the incoming features.      # Loop through the incoming features.
1478      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1479          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1480          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1481          # Peel off the BBHs found.          # Peel off the BBHs found.
1482          my @found = ();          my @found = ();
1483          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1484              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              push @found, $bbh->[0];
1485          }          }
1486          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1487      }      }
# Line 1416  Line 1495 
1495    
1496  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1497    
1498  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.  
1499    
1500  =over 4  =over 4
1501    
# Line 1437  Line 1515 
1515      # Get the parameters.      # Get the parameters.
1516      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1517      # Ask for the best hits.      # Ask for the best hits.
1518      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);  
1519      # Create the return value.      # Create the return value.
1520      my %retVal = ();      my %retVal = ();
1521      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1450  Line 1525 
1525      return %retVal;      return %retVal;
1526  }  }
1527    
   
   
1528  =head3 IsComplete  =head3 IsComplete
1529    
1530  C<< my $flag = $sprout->IsComplete($genomeID); >>  C<< my $flag = $sprout->IsComplete($genomeID); >>
# Line 1522  Line 1595 
1595    
1596  C<< my $genomeID = $sprout->GenomeOf($featureID); >>  C<< my $genomeID = $sprout->GenomeOf($featureID); >>
1597    
1598  Return the genome that contains a specified feature.  Return the genome that contains a specified feature or contig.
1599    
1600  =over 4  =over 4
1601    
1602  =item featureID  =item featureID
1603    
1604  ID of the feature whose genome is desired.  ID of the feature or contig whose genome is desired.
1605    
1606  =item RETURN  =item RETURN
1607    
1608  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
1609  an undefined value.  found, returns an undefined value.
1610    
1611  =back  =back
1612    
# Line 1542  Line 1615 
1615  sub GenomeOf {  sub GenomeOf {
1616      # Get the parameters.      # Get the parameters.
1617      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1618      # Create a query to find the genome associated with the feature.      # Create a query to find the genome associated with the incoming ID.
1619      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ? OR HasContig(to-link) = ?",
1620                               [$featureID, $featureID]);
1621      # Declare the return value.      # Declare the return value.
1622      my $retVal;      my $retVal;
1623      # Get the genome ID.      # Get the genome ID.
# Line 1578  Line 1652 
1652  sub CoupledFeatures {  sub CoupledFeatures {
1653      # Get the parameters.      # Get the parameters.
1654      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1655        Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1656      # Create a query to retrieve the functionally-coupled features.      # Create a query to retrieve the functionally-coupled features.
1657      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1658                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);
# Line 1590  Line 1665 
1665          # Get the ID and score of the coupling.          # Get the ID and score of the coupling.
1666          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1667                                                          'Coupling(score)']);                                                          'Coupling(score)']);
1668          # The coupling ID contains the two feature IDs separated by a space. We use          Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);
1669          # this information to find the ID of the other feature.          # Get the other feature that participates in the coupling.
1670          my ($fid1, $fid2) = split / /, $couplingID;          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],
1671          my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",
1672                                               [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');
1673            Trace("$couplingID target feature is $otherFeatureID.") if T(coupling => 4);
1674          # Attach the other feature's score to its ID.          # Attach the other feature's score to its ID.
1675          $retVal{$otherFeatureID} = $score;          $retVal{$otherFeatureID} = $score;
1676          $found = 1;          $found = 1;
# Line 1726  Line 1803 
1803      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
1804      # Declare the return values. We'll start with the coupling ID and undefine the      # Declare the return values. We'll start with the coupling ID and undefine the
1805      # flag and score until we have more information.      # flag and score until we have more information.
1806      my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);      my ($retVal, $inverted, $score) = ($self->CouplingID($peg1, $peg2), undef, undef);
1807      # Find the coupling data.      # Find the coupling data.
1808      my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],      my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],
1809                                   "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",                                   "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",
# Line 1747  Line 1824 
1824      return ($retVal, $inverted, $score);      return ($retVal, $inverted, $score);
1825  }  }
1826    
1827    =head3 GetSynonymGroup
1828    
1829    C<< my $id = $sprout->GetSynonymGroup($fid); >>
1830    
1831    Return the synonym group name for the specified feature.
1832    
1833    =over 4
1834    
1835    =item fid
1836    
1837    ID of the feature whose synonym group is desired.
1838    
1839    =item RETURN
1840    
1841    The name of the synonym group to which the feature belongs. If the feature does
1842    not belong to a synonym group, the feature ID itself is returned.
1843    
1844    =back
1845    
1846    =cut
1847    
1848    sub GetSynonymGroup {
1849        # Get the parameters.
1850        my ($self, $fid) = @_;
1851        # Declare the return variable.
1852        my $retVal;
1853        # Find the synonym group.
1854        my @groups = $self->GetFlat(['IsSynonymGroupFor'], "IsSynonymGroupFor(to-link) = ?",
1855                                       [$fid], 'IsSynonymGroupFor(from-link)');
1856        # Check to see if we found anything.
1857        if (@groups) {
1858            $retVal = $groups[0];
1859        } else {
1860            $retVal = $fid;
1861        }
1862        # Return the result.
1863        return $retVal;
1864    }
1865    
1866    =head3 GetBoundaries
1867    
1868    C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>
1869    
1870    Determine the begin and end boundaries for the locations in a list. All of the
1871    locations must belong to the same contig and have mostly the same direction in
1872    order for this method to produce a meaningful result. The resulting
1873    begin/end pair will contain all of the bases in any of the locations.
1874    
1875    =over 4
1876    
1877    =item locList
1878    
1879    List of locations to process.
1880    
1881    =item RETURN
1882    
1883    Returns a 3-tuple consisting of the contig ID, the beginning boundary,
1884    and the ending boundary. The beginning boundary will be left of the
1885    end for mostly-forward locations and right of the end for mostly-backward
1886    locations.
1887    
1888    =back
1889    
1890    =cut
1891    
1892    sub GetBoundaries {
1893        # Get the parameters.
1894        my ($self, @locList) = @_;
1895        # Set up the counters used to determine the most popular direction.
1896        my %counts = ( '+' => 0, '-' => 0 );
1897        # Get the last location and parse it.
1898        my $locObject = BasicLocation->new(pop @locList);
1899        # Prime the loop with its data.
1900        my ($contig, $beg, $end) = ($locObject->Contig, $locObject->Left, $locObject->Right);
1901        # Count its direction.
1902        $counts{$locObject->Dir}++;
1903        # Loop through the remaining locations. Note that in most situations, this loop
1904        # will not iterate at all, because most of the time we will be dealing with a
1905        # singleton list.
1906        for my $loc (@locList) {
1907            # Create a location object.
1908            my $locObject = BasicLocation->new($loc);
1909            # Count the direction.
1910            $counts{$locObject->Dir}++;
1911            # Get the left end and the right end.
1912            my $left = $locObject->Left;
1913            my $right = $locObject->Right;
1914            # Merge them into the return variables.
1915            if ($left < $beg) {
1916                $beg = $left;
1917            }
1918            if ($right > $end) {
1919                $end = $right;
1920            }
1921        }
1922        # If the most common direction is reverse, flip the begin and end markers.
1923        if ($counts{'-'} > $counts{'+'}) {
1924            ($beg, $end) = ($end, $beg);
1925        }
1926        # Return the result.
1927        return ($contig, $beg, $end);
1928    }
1929    
1930  =head3 CouplingID  =head3 CouplingID
1931    
1932  C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>  C<< my $couplingID = $sprout->CouplingID($peg1, $peg2); >>
1933    
1934  Return the coupling ID for a pair of feature IDs.  Return the coupling ID for a pair of feature IDs.
1935    
# Line 1782  Line 1962 
1962  =cut  =cut
1963  #: Return Type $;  #: Return Type $;
1964  sub CouplingID {  sub CouplingID {
1965      return join " ", sort @_;      my ($self, @pegs) = @_;
1966  }      return $self->DigestKey(join " ", sort @pegs);
   
 =head3 GetEntityTypes  
   
 C<< my @entityList = $sprout->GetEntityTypes(); >>  
   
 Return the list of supported entity types.  
   
 =cut  
 #: Return Type @;  
 sub GetEntityTypes {  
     # Get the parameters.  
     my ($self) = @_;  
     # Get the underlying database object.  
     my $erdb = $self->{_erdb};  
     # Get its entity type list.  
     my @retVal = $erdb->GetEntityTypes();  
1967  }  }
1968    
1969  =head3 ReadFasta  =head3 ReadFasta
# Line 1947  Line 2111 
2111      # Get the data directory name.      # Get the data directory name.
2112      my $outputDirectory = $self->{_options}->{dataDir};      my $outputDirectory = $self->{_options}->{dataDir};
2113      # Dump the relations.      # Dump the relations.
2114      $self->{_erdb}->DumpRelations($outputDirectory);      $self->DumpRelations($outputDirectory);
2115  }  }
2116    
2117  =head3 XMLFileName  =head3 XMLFileName
# Line 1999  Line 2163 
2163      # Get the parameters.      # Get the parameters.
2164      my ($self, $objectType, $fieldHash) = @_;      my ($self, $objectType, $fieldHash) = @_;
2165      # Call the underlying method.      # Call the underlying method.
2166      $self->{_erdb}->InsertObject($objectType, $fieldHash);      $self->InsertObject($objectType, $fieldHash);
2167  }  }
2168    
2169  =head3 Annotate  =head3 Annotate
# Line 2158  Line 2322 
2322      return @retVal;      return @retVal;
2323  }  }
2324    
 =head3 Exists  
   
 C<< my $found = $sprout->Exists($entityName, $entityID); >>  
   
 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;  
 }  
   
2325  =head3 FeatureTranslation  =head3 FeatureTranslation
2326    
2327  C<< my $translation = $sprout->FeatureTranslation($featureID); >>  C<< my $translation = $sprout->FeatureTranslation($featureID); >>
# Line 2730  Line 2859 
2859      return @retVal;      return @retVal;
2860  }  }
2861    
2862    =head3 GenomeSubsystemData
2863    
2864    C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>
2865    
2866    Return a hash mapping genome features to their subsystem roles.
2867    
2868    =over 4
2869    
2870    =item genomeID
2871    
2872    ID of the genome whose subsystem feature map is desired.
2873    
2874    =item RETURN
2875    
2876    Returns a hash mapping each feature of the genome to a list of 2-tuples. Eacb
2877    2-tuple contains a subsystem name followed by a role ID.
2878    
2879    =back
2880    
2881    =cut
2882    
2883    sub GenomeSubsystemData {
2884        # Get the parameters.
2885        my ($self, $genomeID) = @_;
2886        # Declare the return variable.
2887        my %retVal = ();
2888        # Get a list of the genome features that participate in subsystems. For each
2889        # feature we get its spreadsheet cells and the corresponding roles.
2890        my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],
2891                                 "HasFeature(from-link) = ?", [$genomeID],
2892                                 ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);
2893        # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems
2894        # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the
2895        # list. We use it at the beginning to get all the spreadsheet cells for the genome and
2896        # again at the end to filter out participation in subsystems with a negative variant code.
2897        my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],
2898                                     "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",
2899                                     [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);
2900        # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.
2901        # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We
2902        # link these two lists together to create the result. First, we want a hash mapping
2903        # spreadsheet cells to subsystem names.
2904        my %subHash = map { $_->[0] => $_->[1] } @cellData;
2905        # We loop through @cellData to build the hash.
2906        for my $roleEntry (@roleData) {
2907            # Get the data for this feature and cell.
2908            my ($fid, $cellID, $role) = @{$roleEntry};
2909            # Check for a subsystem name.
2910            my $subsys = $subHash{$cellID};
2911            if ($subsys) {
2912                # Insure this feature has an entry in the return hash.
2913                if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
2914                # Merge in this new data.
2915                push @{$retVal{$fid}}, [$subsys, $role];
2916            }
2917        }
2918        # Return the result.
2919        return %retVal;
2920    }
2921    
2922  =head3 RelatedFeatures  =head3 RelatedFeatures
2923    
2924  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 2765  Line 2954 
2954      # Get the parameters.      # Get the parameters.
2955      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
2956      # 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.
2957      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
2958      # 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
2959      # functional assignment.      # functional assignment.
2960      my @retVal = ();      my @retVal = ();
# Line 2831  Line 3018 
3018      return @retVal;      return @retVal;
3019  }  }
3020    
 =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;  
 }  
   
3021  =head3 Protein  =head3 Protein
3022    
3023  C<< my $protein = Sprout::Protein($sequence, $table); >>  C<< my $protein = Sprout::Protein($sequence, $table); >>
# Line 3051  Line 3119 
3119      # 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.
3120      my @retVal = ($self->{_options}->{dataDir});      my @retVal = ($self->{_options}->{dataDir});
3121      # Concatenate the table names.      # Concatenate the table names.
3122      push @retVal, $self->{_erdb}->GetTableNames();      push @retVal, $self->GetTableNames();
3123      # Return the result.      # Return the result.
3124      return @retVal;      return @retVal;
3125  }  }
3126    
3127  =head3 LowBBHs  =head3 LowBBHs
3128    
3129  C<< my %bbhMap = $sprout->GoodBBHs($featureID, $cutoff); >>  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>
3130    
3131  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
3132  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 3087  Line 3155 
3155      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3156      # Create the return hash.      # Create the return hash.
3157      my %retVal = ();      my %retVal = ();
3158      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3159      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3160      # Form the results into the return hash.      # Form the results into the return hash.
3161      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3162          $retVal{$pair->[0]} = $pair->[1];          $retVal{$pair->[0]} = $pair->[1];
# Line 3100  Line 3165 
3165      return %retVal;      return %retVal;
3166  }  }
3167    
3168    =head3 Sims
3169    
3170    C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>
3171    
3172    Get a list of similarities for a specified feature. Similarity information is not kept in the
3173    Sprout database; rather, they are retrieved from a network server. The similarities are
3174    returned as B<Sim> objects. A Sim object is actually a list reference that has been blessed
3175    so that its elements can be accessed by name.
3176    
3177    Similarities can be either raw or expanded. The raw similarities are basic
3178    hits between features with similar DNA. Expanding a raw similarity drags in any
3179    features considered substantially identical. So, for example, if features B<A1>,
3180    B<A2>, and B<A3> are all substatially identical to B<A>, then a raw similarity
3181    B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.
3182    
3183    =over 4
3184    
3185    =item fid
3186    
3187    ID of the feature whose similarities are desired.
3188    
3189    =item maxN
3190    
3191    Maximum number of similarities to return.
3192    
3193    =item maxP
3194    
3195    Minumum allowable similarity score.
3196    
3197    =item select
3198    
3199    Selection criterion: C<raw> means only raw similarities are returned; C<fig>
3200    means only similarities to FIG features are returned; C<all> means all expanded
3201    similarities are returned; and C<figx> means similarities are expanded until the
3202    number of FIG features equals the maximum.
3203    
3204    =item max_expand
3205    
3206    The maximum number of features to expand.
3207    
3208    =item filters
3209    
3210    Reference to a hash containing filter information, or a subroutine that can be
3211    used to filter the sims.
3212    
3213    =item RETURN
3214    
3215    Returns a reference to a list of similarity objects, or C<undef> if an error
3216    occurred.
3217    
3218    =back
3219    
3220    =cut
3221    
3222    sub Sims {
3223        # Get the parameters.
3224        my ($self, $fid, $maxN, $maxP, $select, $max_expand, $filters) = @_;
3225        # Create the shim object to test for deleted FIDs.
3226        my $shim = FidCheck->new($self);
3227        # Ask the network for sims.
3228        my $retVal = FIGRules::GetNetworkSims($shim, $fid, {}, $maxN, $maxP, $select, $max_expand, $filters);
3229        # Return the result.
3230        return $retVal;
3231    }
3232    
3233  =head3 GetGroups  =head3 GetGroups
3234    
3235  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3249  Line 3379 
3379      # Get the parameters.      # Get the parameters.
3380      my ($self, $genomeID, $testFlag) = @_;      my ($self, $genomeID, $testFlag) = @_;
3381      # Perform the delete for the genome's features.      # Perform the delete for the genome's features.
3382      my $retVal = $self->{_erdb}->Delete('Feature', "fig|$genomeID.%", $testFlag);      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", $testFlag);
3383      # Perform the delete for the primary genome data.      # Perform the delete for the primary genome data.
3384      my $stats = $self->{_erdb}->Delete('Genome', $genomeID, $testFlag);      my $stats = $self->Delete('Genome', $genomeID, $testFlag);
3385      $retVal->Accumulate($stats);      $retVal->Accumulate($stats);
3386      # Return the result.      # Return the result.
3387      return $retVal;      return $retVal;
3388  }  }
3389    
3390    =head3 Fix
3391    
3392    C<< my %fixedHash = Sprout::Fix(%groupHash); >>
3393    
3394    Prepare a genome group hash (like that returned by L</GetGroups> for processing.
3395    Groups with the same primary name will be combined. The primary name is the
3396    first capitalized word in the group name.
3397    
3398    =over 4
3399    
3400    =item groupHash
3401    
3402    Hash to be fixed up.
3403    
3404    =item RETURN
3405    
3406    Returns a fixed-up version of the hash.
3407    
3408    =back
3409    
3410    =cut
3411    
3412    sub Fix {
3413        # Get the parameters.
3414        my (%groupHash) = @_;
3415        # Create the result hash.
3416        my %retVal = ();
3417        # Copy over the genomes.
3418        for my $groupID (keys %groupHash) {
3419            # Make a safety copy of the group ID.
3420            my $realGroupID = $groupID;
3421            # Yank the primary name.
3422            if ($groupID =~ /([A-Z]\w+)/) {
3423                $realGroupID = $1;
3424            }
3425            # Append this group's genomes into the result hash.
3426            Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});
3427        }
3428        # Return the result hash.
3429        return %retVal;
3430    }
3431    
3432    =head3 ReadGroupFile
3433    
3434    C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
3435    
3436    Read in the data from the specified group file. The group file contains information
3437    about each of the NMPDR groups.
3438    
3439    =over 4
3440    
3441    =item name
3442    
3443    Name of the group.
3444    
3445    =item page
3446    
3447    Name of the group's page on the web site (e.g. C<campy.php> for
3448    Campylobacter)
3449    
3450    =item genus
3451    
3452    Genus of the group
3453    
3454    =item species
3455    
3456    Species of the group, or an empty string if the group is for an entire
3457    genus. If the group contains more than one species, the species names
3458    should be separated by commas.
3459    
3460    =back
3461    
3462    The parameters to this method are as follows
3463    
3464    =over 4
3465    
3466    =item groupFile
3467    
3468    Name of the file containing the group data.
3469    
3470    =item RETURN
3471    
3472    Returns a hash keyed on group name. The value of each hash
3473    
3474    =back
3475    
3476    =cut
3477    
3478    sub ReadGroupFile {
3479        # Get the parameters.
3480        my ($groupFileName) = @_;
3481        # Declare the return variable.
3482        my %retVal;
3483        # Read the group file.
3484        my @groupLines = Tracer::GetFile($groupFileName);
3485        for my $groupLine (@groupLines) {
3486            my ($name, $page, $genus, $species) = split(/\t/, $groupLine);
3487            $retVal{$name} = [$page, $genus, $species];
3488        }
3489        # Return the result.
3490        return %retVal;
3491    }
3492    
3493  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3494    
3495  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3313  Line 3546 
3546      }      }
3547      # 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
3548      # extra junk at the end added as a note from the user.      # extra junk at the end added as a note from the user.
3549      if (@retVal) {      if (defined( $retVal[1] )) {
3550          $retVal[1] =~ s/(\t\S)?\s*$//;          $retVal[1] =~ s/(\t\S)?\s*$//;
3551      }      }
3552      # Return the result list.      # Return the result list.

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.84

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3