[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.101, Mon Aug 20 23:29:24 2007 UTC revision 1.122, Mon Jan 19 21:46:21 2009 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
     require Exporter;  
     use ERDB;  
     @ISA = qw(Exporter ERDB);  
3      use Data::Dumper;      use Data::Dumper;
4      use strict;      use strict;
5      use DBKernel;      use DBKernel;
6      use XML::Simple;      use XML::Simple;
7      use DBQuery;      use ERDBQuery;
8      use ERDBObject;      use ERDBObject;
9      use Tracer;      use Tracer;
10      use FIGRules;      use FIGRules;
# Line 17  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17        use CGI qw(-nosticky);
18        use WikiTools;
19        use BioWords;
20        use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
23    
# Line 29  Line 30 
30  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>
31  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>.
32    
33  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' });
34    
35  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
36  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
37  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
38  L</dna_seq> returns the DNA sequence for a specified genome location.  L</DNASeq> returns the DNA sequence for a specified genome location.
39    
40  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.
41    
42  =cut  =cut
43    
 #: Constructor SFXlate->new_sprout_only();  
   
44  =head2 Public Methods  =head2 Public Methods
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 56  Line 55 
55    
56  =item dbName  =item dbName
57    
58  Name of the database.  Name of the database. If omitted, the default Sprout database name is used.
59    
60  =item options  =item options
61    
# Line 80  Line 79 
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    In order to work properly with [[ERDBGeneratorPl]], the constructor has an alternate
93    form.
94    
95        my $sprout = Sprout->new(dbd => $filename);
96    
97    Where I<$fileName> is the name of the DBD file. This enables us to specify an alternate
98    DBD for the loader, which is important when the database format changes.
99    
100  =cut  =cut
101    
102  sub new {  sub new {
103      # Get the parameters.      # Get the parameters.
104      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
105        # Check for the alternate signature, and default the database name if it is missing.
106        if ($dbName eq 'dbd') {
107            $dbName = $FIG_Config::sproutDB;
108            $options = { xmlFileName => $options };
109        } elsif (! defined $dbName) {
110            $dbName = $FIG_Config::sproutDB;
111        } elsif (ref $dbName eq 'HASH') {
112            $options = $dbName;
113            $dbName = $FIG_Config::sproutDB;
114        }
115      # Compute the DBD directory.      # Compute the DBD directory.
116      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
117                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 105  Line 124 
124                                                          # data file directory                                                          # data file directory
125                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
126                                                          # database definition file name                                                          # database definition file name
127                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
128                                                          # user name and password                                                          # user name and password
129                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
130                                                          # database connection port                                                          # database connection port
131                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
132                         host         => $FIG_Config::dbhost,                         host         => $FIG_Config::sprout_host,
133                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
134                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
135                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 123  Line 142 
142      # Connect to the database.      # Connect to the database.
143      my $dbh;      my $dbh;
144      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
145            Trace("Connect data: host = $optionTable->{host}, port = $optionTable->{port}.") if T(3);
146          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
147                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
148      }      }
# Line 134  Line 154 
154      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
155      # Set up space for the group file data.      # Set up space for the group file data.
156      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
157      # Set up space for the genome hash. We use this to identify NMPDR genomes.      # Set up space for the genome hash. We use this to identify NMPDR genomes
158      $retVal->{genomeHash} = undef;      # and remember genome data.
159      # Connect to the attributes.      $retVal->{genomeHash} = {};
160        $retVal->{genomeHashFilled} = 0;
161        # Remember the data directory name.
162        $retVal->{dataDir} = $dataDir;
163        # Return it.
164        return $retVal;
165    }
166    
167    =head3 ca
168    
169        my $ca = $sprout->ca():;
170    
171    Return the [[CustomAttributesPm]] object for retrieving object
172    properties.
173    
174    =cut
175    
176    sub ca {
177        # Get the parameters.
178        my ($self) = @_;
179        # Do we already have an attribute object?
180        my $retVal = $self->{_ca};
181        if (! defined $retVal) {
182            # No, create one. How we do it depends on the configuration.
183      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
184          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
185          $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);              $retVal = RemoteCustomAttributes->new($FIG_Config::attrURL);
186      } elsif ($FIG_Config::attrDbName) {      } elsif ($FIG_Config::attrDbName) {
187          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
188          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
189          $retVal->{_ca} = CustomAttributes->new(user => $user);              $retVal = CustomAttributes->new(user => $user);
190      }      }
191      # Return it.          # Save it for next time.
192            $self->{_ca} = $retVal;
193        }
194        # Return the result.
195        return $retVal;
196    }
197    
198    =head3 CoreGenomes
199    
200        my @genomes = $sprout->CoreGenomes($scope);
201    
202    Return the IDs of NMPDR genomes in the specified scope.
203    
204    =over 4
205    
206    =item scope
207    
208    Scope of the desired genomes. C<core> covers the original core genomes,
209    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
210    genomes in the system.
211    
212    =item RETURN
213    
214    Returns a list of the IDs for the genomes in the specified scope.
215    
216    =back
217    
218    =cut
219    
220    sub CoreGenomes {
221        # Get the parameters.
222        my ($self, $scope) = @_;
223        # Declare the return variable.
224        my @retVal = ();
225        # If we want all genomes, then this is easy.
226        if ($scope eq 'all') {
227            @retVal = $self->Genomes();
228        } else {
229            # Here we're dealing with groups. Get the hash of all the
230            # genome groups.
231            my %groups = $self->GetGroups();
232            # Loop through the groups, keeping the ones that we want.
233            for my $group (keys %groups) {
234                # Decide if we want to keep this group.
235                my $keepGroup = 0;
236                if ($scope eq 'nmpdr') {
237                    # NMPDR mode: keep all groups.
238                    $keepGroup = 1;
239                } elsif ($scope eq 'core') {
240                    # CORE mode. Only keep real core groups.
241                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
242                        $keepGroup = 1;
243                    }
244                }
245                # Add this group if we're keeping it.
246                if ($keepGroup) {
247                    push @retVal, @{$groups{$group}};
248                }
249            }
250        }
251        # Return the result.
252        return @retVal;
253    }
254    
255    =head3 SuperGroup
256    
257        my $superGroup = $sprout->SuperGroup($groupName);
258    
259    Return the name of the super-group containing the specified NMPDR genome
260    group. If no appropriate super-group can be found, an error will be
261    thrown.
262    
263    =over 4
264    
265    =item groupName
266    
267    Name of the group whose super-group is desired.
268    
269    =item RETURN
270    
271    Returns the name of the super-group containing the incoming group.
272    
273    =back
274    
275    =cut
276    
277    sub SuperGroup {
278        # Get the parameters.
279        my ($self, $groupName) = @_;
280        # Declare the return variable.
281        my $retVal;
282        # Get the group hash.
283        my %groupHash = $self->CheckGroupFile();
284        # Find the super-group genus.
285        $groupName =~ /([A-Z]\w+)/;
286        my $nameThing = $1;
287        # See if it's directly in the group hash.
288        if (exists $groupHash{$nameThing}) {
289            # Yes, then it's our result.
290            $retVal = $nameThing;
291        } else {
292            # No, so we have to search.
293            for my $superGroup (keys %groupHash) {
294                # Get this super-group's item list.
295                my $list = $groupHash{$superGroup}->{contents};
296                # Search it.
297                if (grep { $_->[0] eq $nameThing } @{$list}) {
298                    $retVal = $superGroup;
299                }
300            }
301            # Make sure we found something.
302            if (! $retVal) {
303                Confess("No super-group found for \"$groupName\".");
304            }
305        }
306        # Return the result.
307      return $retVal;      return $retVal;
308  }  }
309    
310  =head3 MaxSegment  =head3 MaxSegment
311    
312  C<< my $length = $sprout->MaxSegment(); >>      my $length = $sprout->MaxSegment();
313    
314  This method returns the maximum permissible length of a feature segment. The length is important  This method returns the maximum permissible length of a feature segment. The length is important
315  because it enables us to make reasonable guesses at how to find features inside a particular  because it enables us to make reasonable guesses at how to find features inside a particular
# Line 168  Line 326 
326    
327  =head3 MaxSequence  =head3 MaxSequence
328    
329  C<< my $length = $sprout->MaxSequence(); >>      my $length = $sprout->MaxSequence();
330    
331  This method returns the maximum permissible length of a contig sequence. A contig is broken  This method returns the maximum permissible length of a contig sequence. A contig is broken
332  into sequences in order to save memory resources. In particular, when manipulating features,  into sequences in order to save memory resources. In particular, when manipulating features,
# Line 183  Line 341 
341    
342  =head3 Load  =head3 Load
343    
344  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
345    
346  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.
347    
# Line 195  Line 353 
353  The files are loaded based on the presumption that each line of the file is a record in the  The files are loaded based on the presumption that each line of the file is a record in the
354  relation, and the individual fields are delimited by tabs. Tab and new-line characters inside  relation, and the individual fields are delimited by tabs. Tab and new-line characters inside
355  fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must  fields must be represented by the escape sequences C<\t> and C<\n>, respectively. The fields must
356  be presented in the order given in the relation tables produced by the L</ShowMetaData> method.  be presented in the order given in the relation tables produced by the database documentation.
357    
358  =over 4  =over 4
359    
# Line 223  Line 381 
381    
382  =head3 LoadUpdate  =head3 LoadUpdate
383    
384  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
385    
386  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
387  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 269  Line 427 
427              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
428          } else {          } else {
429              # Attempt to load this table.              # Attempt to load this table.
430              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
431              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
432              $retVal->Accumulate($result);              $retVal->Accumulate($result);
433          }          }
# Line 280  Line 438 
438    
439  =head3 GenomeCounts  =head3 GenomeCounts
440    
441  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>      my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
442    
443  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
444  genomes will be included in the counts.  genomes will be included in the counts.
# Line 325  Line 483 
483    
484  =head3 ContigCount  =head3 ContigCount
485    
486  C<< my $count = $sprout->ContigCount($genomeID); >>      my $count = $sprout->ContigCount($genomeID);
487    
488  Return the number of contigs for the specified genome ID.  Return the number of contigs for the specified genome ID.
489    
# Line 352  Line 510 
510      return $retVal;      return $retVal;
511  }  }
512    
513  =head3 GeneMenu  =head3 GenomeMenu
514    
515  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>      my $html = $sprout->GenomeMenu(%options);
516    
517  Return an HTML select menu of genomes. Each genome will be an option in the menu,  Generate a genome selection control with the specified name and options.
518  and will be displayed by name with the ID and a contig count attached. The selection  This control is almost but not quite the same as the genome control in the
519  value will be the genome ID. The genomes will be sorted by genus/species name.  B<SearchHelper> class. Eventually, the two will be combined.
520    
521  =over 4  =over 4
522    
523  =item attributes  =item options
524    
525  Reference to a hash mapping attributes to values for the SELECT tag generated.  Optional parameters for the control (see below).
526    
527  =item filterString  =item RETURN
528    
529  A filter string for use in selecting the genomes. The filter string must conform  Returns the HTML for a genome selection control on a form (sometimes called a popup menu).
 to the rules for the C<< ERDB->Get >> method.  
530    
531  =item params  =back
532    
533  Reference to a list of values to be substituted in for the parameter marks in  The valid options are as follows.
 the filter string.  
534    
535  =item selected (optional)  =over 4
536    
537  ID of the genome to be initially selected.  =item name
538    
539  =item fast (optional)  Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
540    Terrible things will happen if you have two controls with the same name on the same page.
541    
542  If specified and TRUE, the contig counts will be omitted to improve performance.  =item filter
543    
544  =item RETURN  If specified, a filter for the list of genomes to display. The filter should be in the form of a
545    list reference, a string, or a hash reference. If it is a list reference, the first element
546    of the list should be the filter string, and the remaining elements the filter parameters. If it is a
547    string, it will be split into a list at each included tab. If it is a hash reference, it should be
548    a hash that maps genomes which should be included to a TRUE value.
549    
550    =item multiSelect
551    
552    If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
553    
554    =item size
555    
556    Number of rows to display in the control. The default is C<10>
557    
558  Returns an HTML select menu with the specified genomes as selectable options.  =item id
559    
560    ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
561    unless this ID is unique.
562    
563    =item selected
564    
565    A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
566    default is none.
567    
568    =item class
569    
570    If specified, a style class to assign to the genome control.
571    
572  =back  =back
573    
574  =cut  =cut
575    
576  sub GeneMenu {  sub GenomeMenu {
577      # Get the parameters.      # Get the parameters.
578      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;      my ($self, %options) = @_;
579      my $slowMode = ! $fast;      # Get the control's name and ID.
580      # Default to nothing selected. This prevents an execution warning if "$selected"      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
581      # is undefined.      my $menuID = $options{id} || $menuName;
582      $selected = "" unless defined $selected;      Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
583      Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);      # Compute the IDs for the status display.
584      # Start the menu.      my $divID = "${menuID}_status";
585      my $retVal = "<select " .      my $urlID = "${menuID}_url";
586          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .      # Compute the code to show selected genomes in the status area.
587          ">\n";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', $FIG_Config::genome_control_cap)";
588      # Get the genomes.      # Check for single-select or multi-select.
589      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',      my $multiSelect = $options{multiSelect} || 0;
590                                                                       'Genome(genus)',      # Get the style data.
591                                                                       'Genome(species)',      my $class = $options{class} || '';
592                                                                       'Genome(unique-characterization)']);      # Get the list of pre-selected items.
593      # Sort them by name.      my $selections = $options{selected} || [];
594      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;      if (ref $selections ne 'ARRAY') {
595      # Loop through the genomes, creating the option tags.          $selections = [ split /\s*,\s*/, $selections ];
596      for my $genomeData (@sorted) {      }
597          # Get the data for this genome.      my %selected = map { $_ => 1 } @{$selections};
598          my ($genomeID, $genus, $species, $strain) = @{$genomeData};      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
599          # Get the contig count.      # string, a hash reference, or a list reference.
600          my $contigInfo = "";      my ($filterHash, $filterString);
601          if ($slowMode) {      my $filterParms = $options{filter} || "";
602              my $count = $self->ContigCount($genomeID);      if (ref $filterParms eq 'HASH') {
603              my $counting = ($count == 1 ? "contig" : "contigs");          $filterHash = $filterParms;
604              $contigInfo = "[$count $counting]";          $filterParms = [];
605          }          $filterString = "";
606          # Find out if we're selected.      } else {
607          my $selectOption = ($selected eq $genomeID ? " selected" : "");          if (! ref $filterParms) {
608          # Build the option tag.              $filterParms = [split /\t|\\t/, $filterParms];
609          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";          }
610            $filterString = shift @{$filterParms};
611        }
612        # Check for possible subsystem filtering. If there is one, we will tack the
613        # relationship onto the object name list.
614        my @objectNames = qw(Genome);
615        if ($filterString =~ /ParticipatesIn\(/) {
616            push @objectNames, 'ParticipatesIn';
617        }
618        # Get a list of all the genomes in group order. In fact, we only need them ordered
619        # by name (genus,species,strain), but putting primary-group in front enables us to
620        # take advantage of an existing index.
621        my @genomeList = $self->GetAll(\@objectNames, "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
622                                       $filterParms,
623                                       [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
624        # Apply the hash filter (if any).
625        if (defined $filterHash) {
626            @genomeList = grep { $filterHash->{$_->[1]} } @genomeList;
627        }
628        # Create a hash to organize the genomes by group. Each group will contain a list of
629        # 2-tuples, the first element being the genome ID and the second being the genome
630        # name.
631        my %gHash = ();
632        for my $genome (@genomeList) {
633            # Get the genome data.
634            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
635            # Compute its name. This is the genus, species, strain (if any), and the contig count.
636            my $name = "$genus $species ";
637            $name .= "$strain " if $strain;
638            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
639            # Now we get the domain. The domain tells us the display style of the organism.
640            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
641            # Now compute the display group. This is normally the primary group, but if the
642            # organism is supporting, we blank it out.
643            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
644            # Push the genome into the group's list. Note that we use the real group
645            # name for the hash key here, not the display group name.
646            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
647        }
648        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
649        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
650        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
651        # that aren't "other". At some point, we will want to make this less complicated.
652        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
653                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
654        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
655        # Remember the number of NMPDR groups.
656        my $nmpdrGroupCount = scalar @groups;
657        # Are there any supporting genomes?
658        if (exists $gHash{$FIG_Config::otherGroup}) {
659            # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
660            # of the domains found.
661            my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
662            my @domains = ();
663            for my $genomeData (@otherGenomes) {
664                my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
665                if (exists $gHash{$domain}) {
666                    push @{$gHash{$domain}}, $genomeData;
667                } else {
668                    $gHash{$domain} = [$genomeData];
669                    push @domains, $domain;
670                }
671            }
672            # Add the domain groups at the end of the main group list. The main group list will now
673            # contain all the categories we need to display the genomes.
674            push @groups, sort @domains;
675            # Delete the supporting group.
676            delete $gHash{$FIG_Config::otherGroup};
677        }
678        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
679        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
680        # and use that to make the selections.
681        my $nmpdrCount = 0;
682        # Create the type counters.
683        my $groupCount = 1;
684        # Get the number of rows to display.
685        my $rows = $options{size} || 10;
686        # If we're multi-row, create an onChange event.
687        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
688        # Set up the multiple-select flag.
689        my $multipleTag = ($multiSelect ? " multiple" : "" );
690        # Set up the style class.
691        my $classTag = ($class ? " class=\"$class\"" : "" );
692        # Create the SELECT tag and stuff it into the output array.
693        my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
694        # Loop through the groups.
695        for my $group (@groups) {
696            # Get the genomes in the group.
697            for my $genome (@{$gHash{$group}}) {
698                # If this is an NMPDR organism, we add an extra style and count it.
699                my $nmpdrStyle = "";
700                if ($nmpdrGroupCount > 0) {
701                    $nmpdrCount++;
702                    $nmpdrStyle = " Core";
703                }
704                # Get the organism ID, name, contig count, and domain.
705                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
706                # See if we're pre-selected.
707                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
708                # Compute the display name.
709                my $nameString = "$name ($genomeID$contigCount)";
710                # Generate the option tag.
711                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
712                push @lines, "    $optionTag";
713            }
714            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
715            # groups.
716            $nmpdrGroupCount--;
717      }      }
718      # Close the SELECT tag.      # Close the SELECT tag.
719      $retVal .= "</select>\n";      push @lines, "</SELECT>";
720        if ($rows > 1) {
721            # We're in a non-compact mode, so we need to add some selection helpers. First is
722            # the search box. This allows the user to type text and change which genomes are
723            # displayed. For multiple-select mode, we include a button that selects the displayed
724            # genes. For single-select mode, we use a plain label instead.
725            my $searchThingName = "${menuID}_SearchThing";
726            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
727                                                 : "Show genomes containing");
728            push @lines, "<br />$searchThingLabel&nbsp;" .
729                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .
730                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
731            # For multi-select mode, we also have buttons to set and clear selections.
732            if ($multiSelect) {
733                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll(getElementById('$menuID')); $showSelect\" />";
734                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll(getElementById('$menuID')); $showSelect\" />";
735                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome(getElementById('$menuID'), $nmpdrCount, true); $showSelect;\" />";
736            }
737            # Add a hidden field we can use to generate organism page hyperlinks.
738            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";
739            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
740            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
741        }
742        # Assemble all the lines into a string.
743        my $retVal = join("\n", @lines, "");
744        # Return the result.
745        return $retVal;
746    }
747    
748    
749    =head3 Stem
750    
751        my $stem = $sprout->Stem($word);
752    
753    Return the stem of the specified word, or C<undef> if the word is not
754    stemmable. Note that even if the word is stemmable, the stem may be
755    the same as the original word.
756    
757    =over 4
758    
759    =item word
760    
761    Word to convert into a stem.
762    
763    =item RETURN
764    
765    Returns a stem of the word (which may be the word itself), or C<undef> if
766    the word is not stemmable.
767    
768    =back
769    
770    =cut
771    
772    sub Stem {
773        # Get the parameters.
774        my ($self, $word) = @_;
775        # Get the stemmer object.
776        my $stemmer = $self->{stemmer};
777        if (! defined $stemmer) {
778            # We don't have one pre-built, so we build and save it now.
779            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
780                                     stops => "$FIG_Config::sproutData/StopWords.txt",
781                                     cache => 0);
782            $self->{stemmer} = $stemmer;
783        }
784        # Try to stem the word.
785        my $retVal = $stemmer->Process($word);
786      # Return the result.      # Return the result.
787      return $retVal;      return $retVal;
788  }  }
789    
790    
791  =head3 Build  =head3 Build
792    
793  C<< $sprout->Build(); >>      $sprout->Build();
794    
795  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.
796  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 452  Line 807 
807    
808  =head3 Genomes  =head3 Genomes
809    
810  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
811    
812  Return a list of all the genome IDs.  Return a list of all the genome IDs.
813    
# Line 469  Line 824 
824    
825  =head3 GenusSpecies  =head3 GenusSpecies
826    
827  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
828    
829  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
830    
# Line 491  Line 846 
846  sub GenusSpecies {  sub GenusSpecies {
847      # Get the parameters.      # Get the parameters.
848      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
849      # Get the data for the specified genome.      # Declare the return value.
850      my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',      my $retVal;
851                                                                'Genome(unique-characterization)']);      # Get the genome data.
852      # Format the result and return it.      my $genomeData = $self->_GenomeData($genomeID);
853      my $retVal = join(' ', @values);      # Only proceed if we found the genome.
854        if (defined $genomeData) {
855            $retVal = $genomeData->PrimaryValue('Genome(scientific-name)');
856        }
857        # Return it.
858      return $retVal;      return $retVal;
859  }  }
860    
861  =head3 FeaturesOf  =head3 FeaturesOf
862    
863  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
864    
865  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
866    
# Line 546  Line 905 
905    
906  =head3 FeatureLocation  =head3 FeatureLocation
907    
908  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
909    
910  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
911  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 570  Line 929 
929  =item RETURN  =item RETURN
930    
931  Returns a list of the feature's contig segments. The locations are returned as a list in a list  Returns a list of the feature's contig segments. The locations are returned as a list in a list
932  context and as a comma-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context. An empty list means the feature
933    wasn't found.
934    
935  =back  =back
936    
# Line 579  Line 939 
939  sub FeatureLocation {  sub FeatureLocation {
940      # Get the parameters.      # Get the parameters.
941      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
942        # Declare the return variable.
943        my @retVal = ();
944      # Get the feature record.      # Get the feature record.
945      my $object = $self->GetEntity('Feature', $featureID);      my $object = $self->GetEntity('Feature', $featureID);
946      Confess("Feature $featureID not found.") if ! defined($object);      # Only proceed if we found it.
947        if (defined $object) {
948      # Get the location string.      # Get the location string.
949      my $locString = $object->PrimaryValue('Feature(location-string)');      my $locString = $object->PrimaryValue('Feature(location-string)');
950      # Create the return list.      # Create the return list.
951      my @retVal = split /\s*,\s*/, $locString;          @retVal = split /\s*,\s*/, $locString;
952        }
953      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
954      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
955  }  }
956    
957  =head3 ParseLocation  =head3 ParseLocation
958    
959  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
960    
961  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
962  length.  length.
# Line 638  Line 1002 
1002    
1003  =head3 PointLocation  =head3 PointLocation
1004    
1005  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
1006    
1007  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
1008  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 690  Line 1054 
1054    
1055  =head3 DNASeq  =head3 DNASeq
1056    
1057  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
1058    
1059  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
1060  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 774  Line 1138 
1138    
1139  =head3 AllContigs  =head3 AllContigs
1140    
1141  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
1142    
1143  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
1144    
# Line 804  Line 1168 
1168    
1169  =head3 GenomeLength  =head3 GenomeLength
1170    
1171  C<< my $length = $sprout->GenomeLength($genomeID); >>      my $length = $sprout->GenomeLength($genomeID);
1172    
1173  Return the length of the specified genome in base pairs.  Return the length of the specified genome in base pairs.
1174    
# Line 828  Line 1192 
1192      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
1193      # Declare the return variable.      # Declare the return variable.
1194      my $retVal = 0;      my $retVal = 0;
1195      # Get the genome's contig sequence lengths.      # Get the genome data.
1196      my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',      my $genomeData = $self->_GenomeData($genomeID);
1197                         [$genomeID], 'IsMadeUpOf(len)');      # Only proceed if it exists.
1198      # Sum the lengths.      if (defined $genomeData) {
1199      map { $retVal += $_ } @lens;          $retVal = $genomeData->PrimaryValue('Genome(dna-size)');
1200        }
1201      # Return the result.      # Return the result.
1202      return $retVal;      return $retVal;
1203  }  }
1204    
1205  =head3 FeatureCount  =head3 FeatureCount
1206    
1207  C<< my $count = $sprout->FeatureCount($genomeID, $type); >>      my $count = $sprout->FeatureCount($genomeID, $type);
1208    
1209  Return the number of features of the specified type in the specified genome.  Return the number of features of the specified type in the specified genome.
1210    
# Line 874  Line 1239 
1239    
1240  =head3 GenomeAssignments  =head3 GenomeAssignments
1241    
1242  C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>      my $fidHash = $sprout->GenomeAssignments($genomeID);
1243    
1244  Return a list of a genome's assigned features. The return hash will contain each  Return a list of a genome's assigned features. The return hash will contain each
1245  assigned feature of the genome mapped to the text of its most recent functional  assigned feature of the genome mapped to the text of its most recent functional
# Line 917  Line 1282 
1282    
1283  =head3 ContigLength  =head3 ContigLength
1284    
1285  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->ContigLength($contigID);
1286    
1287  Compute the length of a contig.  Compute the length of a contig.
1288    
# Line 956  Line 1321 
1321    
1322  =head3 ClusterPEGs  =head3 ClusterPEGs
1323    
1324  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
1325    
1326  Cluster the PEGs in a list according to the cluster coding scheme of the specified  Cluster the PEGs in a list according to the cluster coding scheme of the specified
1327  subsystem. In order for this to work properly, the subsystem object must have  subsystem. In order for this to work properly, the subsystem object must have
1328  been used recently to retrieve the PEGs using the B<get_pegs_from_cell> method.  been used recently to retrieve the PEGs using the B<get_pegs_from_cell> or
1329  This causes the cluster numbers to be pulled into the subsystem's color hash.  B<get_row> methods. This causes the cluster numbers to be pulled into the
1330  If a PEG is not found in the color hash, it will not appear in the output  subsystem's color hash. If a PEG is not found in the color hash, it will not
1331  sequence.  appear in the output sequence.
1332    
1333  =over 4  =over 4
1334    
# Line 1004  Line 1369 
1369    
1370  =head3 GenesInRegion  =head3 GenesInRegion
1371    
1372  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1373    
1374  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1375    
# Line 1085  Line 1450 
1450    
1451  =head3 GeneDataInRegion  =head3 GeneDataInRegion
1452    
1453  C<< my @featureList = $sprout->GenesInRegion($contigID, $start, $stop); >>      my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1454    
1455  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1456    
# Line 1156  Line 1521 
1521    
1522  =head3 FType  =head3 FType
1523    
1524  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1525    
1526  Return the type of a feature.  Return the type of a feature.
1527    
# Line 1186  Line 1551 
1551    
1552  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1553    
1554  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1555    
1556  Return the annotations of a feature.  Return the annotations of a feature.
1557    
# Line 1249  Line 1614 
1614    
1615  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1616    
1617  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1618    
1619  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
1620  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 1304  Line 1669 
1669    
1670  =head3 FunctionOf  =head3 FunctionOf
1671    
1672  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1673    
1674  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1675    
# Line 1317  Line 1682 
1682  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG
1683  is trusted.  is trusted.
1684    
1685  If the feature is B<not> identified by a FIG ID, then the functional assignment  If the feature is B<not> identified by a FIG ID, then we search the aliases for it.
1686  information is taken from the B<ExternalAliasFunc> table. If the table does  If no matching alias is found, we return an undefined value.
 not contain an entry for the feature, an undefined value is returned.  
1687    
1688  =over 4  =over 4
1689    
# Line 1345  Line 1709 
1709      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1710      # Declare the return value.      # Declare the return value.
1711      my $retVal;      my $retVal;
1712      # Determine the ID type.      # Find a FIG ID for this feature.
1713      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1714        # Only proceed if we have an ID.
1715        if ($fid) {
1716          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1717          if (!$userID) {          if (!$userID) {
1718              # Use the primary assignment.              # Use the primary assignment.
1719              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1720          } else {          } else {
1721              # We must build the list of trusted users.              # We must build the list of trusted users.
1722              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1376  Line 1742 
1742              # Build a query for all of the feature's annotations, sorted by date.              # Build a query for all of the feature's annotations, sorted by date.
1743              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1744                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1745                                     [$featureID]);                                     [$fid]);
1746              my $timeSelected = 0;              my $timeSelected = 0;
1747              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1748              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1396  Line 1762 
1762                  }                  }
1763              }              }
1764          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         ($retVal) = $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);  
1765      }      }
1766      # Return the assignment found.      # Return the assignment found.
1767      return $retVal;      return $retVal;
# Line 1408  Line 1769 
1769    
1770  =head3 FunctionsOf  =head3 FunctionsOf
1771    
1772  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1773    
1774  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1775    
# Line 1419  Line 1780 
1780  annotation itself because it's a text field; however, this is not a big problem because  annotation itself because it's a text field; however, this is not a big problem because
1781  most features only have a small number of annotations.  most features only have a small number of annotations.
1782    
 If the feature is B<not> identified by a FIG ID, then the functional assignment  
 information is taken from the B<ExternalAliasFunc> table. If the table does  
 not contain an entry for the feature, an empty list is returned.  
   
1783  =over 4  =over 4
1784    
1785  =item featureID  =item featureID
# Line 1443  Line 1800 
1800      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1801      # Declare the return value.      # Declare the return value.
1802      my @retVal = ();      my @retVal = ();
1803      # Determine the ID type.      # Convert to a FIG ID.
1804      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1805        # Only proceed if we found one.
1806        if ($fid) {
1807          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID. We must build the list of trusted
1808          # users.          # users.
1809          my %trusteeTable = ();          my %trusteeTable = ();
1810          # Build a query for all of the feature's annotations, sorted by date.          # Build a query for all of the feature's annotations, sorted by date.
1811          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1812                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1813                                 [$featureID]);                                 [$fid]);
1814          my $timeSelected = 0;          my $timeSelected = 0;
1815          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1816          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1466  Line 1825 
1825                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1826              }              }
1827          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,  
                                                  ['ExternalAliasFunc(func)']);  
         push @retVal, map { ['master', $_] } @assignments;  
1828      }      }
1829      # Return the assignments found.      # Return the assignments found.
1830      return @retVal;      return @retVal;
# Line 1480  Line 1832 
1832    
1833  =head3 BBHList  =head3 BBHList
1834    
1835  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1836    
1837  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
1838  on a specified target genome.  on a specified target genome.
# Line 1512  Line 1864 
1864      # Loop through the incoming features.      # Loop through the incoming features.
1865      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1866          # Ask the server for the feature's best hit.          # Ask the server for the feature's best hit.
1867          my @bbhData = FIGRules::BBHData($featureID);          my $bbhData = FIGRules::BBHData($featureID);
1868          # Peel off the BBHs found.          # Peel off the BBHs found.
1869          my @found = ();          my @found = ();
1870          for my $bbh (@bbhData) {          for my $bbh (@$bbhData) {
1871              my $fid = $bbh->[0];              my $fid = $bbh->[0];
1872              my $bbGenome = $self->GenomeOf($fid);              my $bbGenome = $self->GenomeOf($fid);
1873              if ($bbGenome eq $genomeID) {              if ($bbGenome eq $genomeID) {
# Line 1530  Line 1882 
1882    
1883  =head3 SimList  =head3 SimList
1884    
1885  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1886    
1887  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1888    
# Line 1554  Line 1906 
1906      # Get the parameters.      # Get the parameters.
1907      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1908      # Ask for the best hits.      # Ask for the best hits.
1909      my @lists = FIGRules::BBHData($featureID);      my $lists = FIGRules::BBHData($featureID);
1910      # Create the return value.      # Create the return value.
1911      my %retVal = ();      my %retVal = ();
1912      for my $tuple (@lists) {      for my $tuple (@$lists) {
1913          $retVal{$tuple->[0]} = $tuple->[1];          $retVal{$tuple->[0]} = $tuple->[1];
1914      }      }
1915      # Return the result.      # Return the result.
# Line 1566  Line 1918 
1918    
1919  =head3 IsComplete  =head3 IsComplete
1920    
1921  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1922    
1923  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1924    
# Line 1591  Line 1943 
1943      # Declare the return variable.      # Declare the return variable.
1944      my $retVal;      my $retVal;
1945      # Get the genome's data.      # Get the genome's data.
1946      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->_GenomeData($genomeID);
1947      if ($genomeData) {      # Only proceed if it exists.
1948        if (defined $genomeData) {
1949          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1950          $retVal = $genomeData->PrimaryValue('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1951      }      }
# Line 1602  Line 1955 
1955    
1956  =head3 FeatureAliases  =head3 FeatureAliases
1957    
1958  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1959    
1960  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1961    
# Line 1632  Line 1985 
1985    
1986  =head3 GenomeOf  =head3 GenomeOf
1987    
1988  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1989    
1990  Return the genome that contains a specified feature or contig.  Return the genome that contains a specified feature or contig.
1991    
# Line 1660  Line 2013 
2013      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
2014          $retVal = $1;          $retVal = $1;
2015      } else {      } else {
2016          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
2017            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
2018            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
2019                $retVal = $1;
2020            }
2021      }      }
2022      # Return the value found.      # Return the value found.
2023      return $retVal;      return $retVal;
# Line 1668  Line 2025 
2025    
2026  =head3 CoupledFeatures  =head3 CoupledFeatures
2027    
2028  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
2029    
2030  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
2031  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 1704  Line 2061 
2061              $retVal{$featureID2} = $score;              $retVal{$featureID2} = $score;
2062          }          }
2063      }      }
     # Functional coupling is reflexive. If we found at least one coupled feature, we must add  
     # the incoming feature as well.  
     if (keys %retVal) {  
         $retVal{$featureID} = 9999;  
     }  
2064      # Return the hash.      # Return the hash.
2065      return %retVal;      return %retVal;
2066  }  }
2067    
2068  =head3 CouplingEvidence  =head3 CouplingEvidence
2069    
2070  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
2071    
2072  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
2073    
# Line 1777  Line 2129 
2129    
2130  =head3 GetSynonymGroup  =head3 GetSynonymGroup
2131    
2132  C<< my $id = $sprout->GetSynonymGroup($fid); >>      my $id = $sprout->GetSynonymGroup($fid);
2133    
2134  Return the synonym group name for the specified feature.  Return the synonym group name for the specified feature.
2135    
# Line 1816  Line 2168 
2168    
2169  =head3 GetBoundaries  =head3 GetBoundaries
2170    
2171  C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
2172    
2173  Determine the begin and end boundaries for the locations in a list. All of the  Determine the begin and end boundaries for the locations in a list. All of the
2174  locations must belong to the same contig and have mostly the same direction in  locations must belong to the same contig and have mostly the same direction in
# Line 1880  Line 2232 
2232    
2233  =head3 ReadFasta  =head3 ReadFasta
2234    
2235  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
2236    
2237  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
2238  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 1946  Line 2298 
2298    
2299  =head3 FormatLocations  =head3 FormatLocations
2300    
2301  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
2302    
2303  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
2304  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 2011  Line 2363 
2363    
2364  =head3 DumpData  =head3 DumpData
2365    
2366  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2367    
2368  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.
2369    
# Line 2028  Line 2380 
2380    
2381  =head3 XMLFileName  =head3 XMLFileName
2382    
2383  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2384    
2385  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2386    
# Line 2039  Line 2391 
2391      return $self->{_xmlName};      return $self->{_xmlName};
2392  }  }
2393    
2394    =head3 GetGenomeNameData
2395    
2396        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2397    
2398    Return the genus, species, and unique characterization for a genome. This
2399    is similar to L</GenusSpecies>, with the exception that it returns the
2400    values in three seperate fields.
2401    
2402    =over 4
2403    
2404    =item genomeID
2405    
2406    ID of the genome whose name data is desired.
2407    
2408    =item RETURN
2409    
2410    Returns a three-element list, consisting of the genus, species, and strain
2411    of the specified genome. If the genome is not found, an error occurs.
2412    
2413    =back
2414    
2415    =cut
2416    
2417    sub GetGenomeNameData {
2418        # Get the parameters.
2419        my ($self, $genomeID) = @_;
2420        # Declare the return variables.
2421        my ($genus, $species, $strain);
2422        # Get the genome's data.
2423        my $genomeData = $self->_GenomeData($genomeID);
2424        # Only proceed if the genome exists.
2425        if (defined $genomeData) {
2426            # Get the desired values.
2427            ($genus, $species, $strain) = $genomeData->Values(['Genome(genus)',
2428                                                               'Genome(species)',
2429                                                               'Genome(unique-characterization)']);
2430        } else {
2431            # Throw an error because they were not found.
2432            Confess("Genome $genomeID not found in database.");
2433        }
2434        # Return the results.
2435        return ($genus, $species, $strain);
2436    }
2437    
2438    =head3 GetGenomeByNameData
2439    
2440        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2441    
2442    Return a list of the IDs of the genomes with the specified genus,
2443    species, and strain. In almost every case, there will be either zero or
2444    one IDs returned; however, two or more IDs could be returned if there are
2445    multiple versions of the genome in the database.
2446    
2447    =over 4
2448    
2449    =item genus
2450    
2451    Genus of the desired genome.
2452    
2453    =item species
2454    
2455    Species of the desired genome.
2456    
2457    =item strain
2458    
2459    Strain (unique characterization) of the desired genome. This may be an empty
2460    string, in which case it is presumed that the desired genome has no strain
2461    specified.
2462    
2463    =item RETURN
2464    
2465    Returns a list of the IDs of the genomes having the specified genus, species, and
2466    strain.
2467    
2468    =back
2469    
2470    =cut
2471    
2472    sub GetGenomeByNameData {
2473        # Get the parameters.
2474        my ($self, $genus, $species, $strain) = @_;
2475        # Try to find the genomes.
2476        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2477                                    [$genus, $species, $strain], 'Genome(id)');
2478        # Return the result.
2479        return @retVal;
2480    }
2481    
2482  =head3 Insert  =head3 Insert
2483    
2484  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2485    
2486  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
2487  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 2050  Line 2490 
2490  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
2491  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>.
2492    
2493  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']});
2494    
2495  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
2496  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>.
2497    
2498  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'});
2499    
2500  =over 4  =over 4
2501    
# Line 2080  Line 2520 
2520    
2521  =head3 Annotate  =head3 Annotate
2522    
2523  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2524    
2525  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
2526  specified feature and user.  specified feature and user.
# Line 2134  Line 2574 
2574    
2575  =head3 AssignFunction  =head3 AssignFunction
2576    
2577  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2578    
2579  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
2580  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2194  Line 2634 
2634    
2635  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2636    
2637  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2638    
2639  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
2640  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 2236  Line 2676 
2676    
2677  =head3 FeatureTranslation  =head3 FeatureTranslation
2678    
2679  C<< my $translation = $sprout->FeatureTranslation($featureID); >>      my $translation = $sprout->FeatureTranslation($featureID);
2680    
2681  Return the translation of a feature.  Return the translation of a feature.
2682    
# Line 2264  Line 2704 
2704    
2705  =head3 Taxonomy  =head3 Taxonomy
2706    
2707  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2708    
2709  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
2710  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>,
2711  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2712    
2713  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2714    
2715  =over 4  =over 4
2716    
# Line 2289  Line 2729 
2729  sub Taxonomy {  sub Taxonomy {
2730      # Get the parameters.      # Get the parameters.
2731      my ($self, $genome) = @_;      my ($self, $genome) = @_;
     # Find the specified genome's taxonomy string.  
     my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);  
2732      # Declare the return variable.      # Declare the return variable.
2733      my @retVal = ();      my @retVal = ();
2734      # If we found the genome, return its taxonomy string.      # Get the genome data.
2735      if ($list) {      my $genomeData = $self->_GenomeData($genome);
2736          @retVal = split /\s*;\s*/, $list;      # Only proceed if it exists.
2737        if (defined $genomeData) {
2738            # Create the taxonomy from the taxonomy string.
2739            @retVal = split /\s*;\s*/, $genomeData->PrimaryValue('Genome(taxonomy)');
2740      } else {      } else {
2741            # Genome doesn't exist, so emit a warning.
2742          Trace("Genome \"$genome\" does not have a taxonomy in the database.\n") if T(0);          Trace("Genome \"$genome\" does not have a taxonomy in the database.\n") if T(0);
2743      }      }
2744      # Return the value found.      # Return the value found.
# Line 2305  Line 2747 
2747    
2748  =head3 CrudeDistance  =head3 CrudeDistance
2749    
2750  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2751    
2752  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
2753  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 2341  Line 2783 
2783      }      }
2784      my @taxA = $self->Taxonomy($genomeA);      my @taxA = $self->Taxonomy($genomeA);
2785      my @taxB = $self->Taxonomy($genomeB);      my @taxB = $self->Taxonomy($genomeB);
2786      # Initialize the distance to 1. We'll reduce it each time we find a match between the      # Compute the distance.
2787      # taxonomies.      my $retVal = FIGRules::CrudeDistanceFormula(\@taxA, \@taxB);
     my $retVal = 1.0;  
     # Initialize the subtraction amount. This amount determines the distance reduction caused  
     # by a mismatch at the current level.  
     my $v = 0.5;  
     # Loop through the taxonomies.  
     for (my $i = 0; ($i < @taxA) && ($i < @taxB) && ($taxA[$i] eq $taxB[$i]); $i++) {  
         $retVal -= $v;  
         $v /= 2;  
     }  
2788      return $retVal;      return $retVal;
2789  }  }
2790    
2791  =head3 RoleName  =head3 RoleName
2792    
2793  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2794    
2795  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
2796  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 2391  Line 2824 
2824    
2825  =head3 RoleDiagrams  =head3 RoleDiagrams
2826    
2827  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2828    
2829  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2830    
# Line 2419  Line 2852 
2852      return @retVal;      return @retVal;
2853  }  }
2854    
 =head3 GetProperties  
   
 C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>  
   
 Return a list of the properties with the specified characteristics.  
   
 Properties are the Sprout analog of the FIG attributes. The call is  
 passed directly to the CustomAttributes or RemoteCustomAttributes object  
 contained in this object.  
   
 This method returns a series of tuples that match the specified criteria. Each tuple  
 will contain an object ID, a key, and one or more values. The parameters to this  
 method therefore correspond structurally to the values expected in each tuple. In  
 addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any  
 of the parameters. So, for example,  
   
     my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);  
   
 would return something like  
   
     ['fig}100226.1.peg.1004', 'structure', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure1', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure2', 1, 2]  
     ['fig}100226.1.peg.1004', 'structureA', 1, 2]  
   
 Use of C<undef> in any position acts as a wild card (all values). You can also specify  
 a list reference in the ID column. Thus,  
   
     my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');  
   
 would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its  
 features.  
   
 In addition to values in multiple sections, a single attribute key can have multiple  
 values, so even  
   
     my @attributeList = $sprout->GetProperties($peg, 'virulent');  
   
 which has no wildcard in the key or the object ID, may return multiple tuples.  
   
 =over 4  
   
 =item objectID  
   
 ID of object whose attributes are desired. If the attributes are desired for multiple  
 objects, this parameter can be specified as a list reference. If the attributes are  
 desired for all objects, specify C<undef> or an empty string. Finally, you can specify  
 attributes for a range of object IDs by putting a percent sign (C<%>) at the end.  
   
 =item key  
   
 Attribute key name. A value of C<undef> or an empty string will match all  
 attribute keys. If the values are desired for multiple keys, this parameter can be  
 specified as a list reference. Finally, you can specify attributes for a range of  
 keys by putting a percent sign (C<%>) at the end.  
   
 =item values  
   
 List of the desired attribute values, section by section. If C<undef>  
 or an empty string is specified, all values in that section will match. A  
 generic match can be requested by placing a percent sign (C<%>) at the end.  
 In that case, all values that match up to and not including the percent sign  
 will match. You may also specify a regular expression enclosed  
 in slashes. All values that match the regular expression will be returned. For  
 performance reasons, only values have this extra capability.  
   
 =item RETURN  
   
 Returns a list of tuples. The first element in the tuple is an object ID, the  
 second is an attribute key, and the remaining elements are the sections of  
 the attribute value. All of the tuples will match the criteria set forth in  
 the parameter list.  
   
 =back  
   
 =cut  
   
 sub GetProperties {  
     # Get the parameters.  
     my ($self, @parms) = @_;  
     # Declare the return variable.  
     my @retVal = $self->{_ca}->GetAttributes(@parms);  
     # Return the result.  
     return @retVal;  
 }  
   
2855  =head3 FeatureProperties  =head3 FeatureProperties
2856    
2857  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2858    
2859  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
2860  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
# Line 2533  Line 2880 
2880      # Get the parameters.      # Get the parameters.
2881      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2882      # Get the properties.      # Get the properties.
2883      my @attributes = $self->{_ca}->GetAttributes($featureID);      my @attributes = $self->ca->GetAttributes($featureID);
2884      # Strip the feature ID off each tuple.      # Strip the feature ID off each tuple.
2885      my @retVal = ();      my @retVal = ();
2886      for my $attributeRow (@attributes) {      for my $attributeRow (@attributes) {
# Line 2546  Line 2893 
2893    
2894  =head3 DiagramName  =head3 DiagramName
2895    
2896  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2897    
2898  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2899    
# Line 2574  Line 2921 
2921    
2922  =head3 PropertyID  =head3 PropertyID
2923    
2924  C<< my $id = $sprout->PropertyID($propName, $propValue); >>      my $id = $sprout->PropertyID($propName, $propValue);
2925    
2926  Return the ID of the specified property name and value pair, if the  Return the ID of the specified property name and value pair, if the
2927  pair exists. Only a small subset of the FIG attributes are stored as  pair exists. Only a small subset of the FIG attributes are stored as
# Line 2611  Line 2958 
2958    
2959  =head3 MergedAnnotations  =head3 MergedAnnotations
2960    
2961  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2962    
2963  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
2964  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 2660  Line 3007 
3007    
3008  =head3 RoleNeighbors  =head3 RoleNeighbors
3009    
3010  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
3011    
3012  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
3013  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 2703  Line 3050 
3050    
3051  =head3 FeatureLinks  =head3 FeatureLinks
3052    
3053  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
3054    
3055  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
3056  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 2734  Line 3081 
3081    
3082  =head3 SubsystemsOf  =head3 SubsystemsOf
3083    
3084  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
3085    
3086  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
3087  to the roles the feature performs.  to the roles the feature performs.
# Line 2782  Line 3129 
3129    
3130  =head3 SubsystemList  =head3 SubsystemList
3131    
3132  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
3133    
3134  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
3135  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2805  Line 3152 
3152  sub SubsystemList {  sub SubsystemList {
3153      # Get the parameters.      # Get the parameters.
3154      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3155      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3156      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3157        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3158                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3159      # Return the result, sorted.      # Return the result, sorted.
3160      return sort @retVal;      return sort @retVal;
# Line 2814  Line 3162 
3162    
3163  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
3164    
3165  C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>      my %featureData = $sprout->GenomeSubsystemData($genomeID);
3166    
3167  Return a hash mapping genome features to their subsystem roles.  Return a hash mapping genome features to their subsystem roles.
3168    
# Line 2839  Line 3187 
3187      # Declare the return variable.      # Declare the return variable.
3188      my %retVal = ();      my %retVal = ();
3189      # Get a list of the genome features that participate in subsystems. For each      # Get a list of the genome features that participate in subsystems. For each
3190      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3191      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3192                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3193                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3194      # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems      # Now we get a list of valid subsystems. These are the subsystems connected to the genome with
3195      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3196      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3197      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3198      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3199                                   "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",      # We loop through @roleData to build the hash.
                                  [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);  
     # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.  
     # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We  
     # link these two lists together to create the result. First, we want a hash mapping  
     # spreadsheet cells to subsystem names.  
     my %subHash = map { $_->[0] => $_->[1] } @cellData;  
     # We loop through @cellData to build the hash.  
3200      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3201          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3202          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3203          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3204          my $subsys = $subHash{$cellID};          # Check the subsystem;
3205          if ($subsys) {          if ($subs{$subsys}) {
3206                Trace("Subsystem found.") if T(4);
3207              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3208              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3209              # Merge in this new data.              # Merge in this new data.
# Line 2874  Line 3216 
3216    
3217  =head3 RelatedFeatures  =head3 RelatedFeatures
3218    
3219  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
3220    
3221  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
3222  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 2907  Line 3249 
3249      # Get the parameters.      # Get the parameters.
3250      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3251      # 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.
3252      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);      my $bbhData = FIGRules::BBHData($featureID);
3253        my @bbhFeatures = map { $_->[0] } @$bbhData;
3254      # 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
3255      # functional assignment.      # functional assignment.
3256      my @retVal = ();      my @retVal = ();
# Line 2925  Line 3268 
3268    
3269  =head3 TaxonomySort  =head3 TaxonomySort
3270    
3271  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3272    
3273  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
3274  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 2960  Line 3303 
3303          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3304                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3305          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3306          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3307      }      }
3308      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3309      my @retVal = ();      my @retVal = ();
# Line 2973  Line 3316 
3316    
3317  =head3 Protein  =head3 Protein
3318    
3319  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3320    
3321  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3322    
# Line 3059  Line 3402 
3402    
3403  =head3 LoadInfo  =head3 LoadInfo
3404    
3405  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3406    
3407  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
3408  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 3080  Line 3423 
3423    
3424  =head3 BBHMatrix  =head3 BBHMatrix
3425    
3426  C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>      my $bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3427    
3428  Find all the bidirectional best hits for the features of a genome in a  Find all the bidirectional best hits for the features of a genome in a
3429  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3104  Line 3447 
3447    
3448  =item RETURN  =item RETURN
3449    
3450  Returns a hash mapping each feature in the original genome to a hash mapping its  Returns a reference to a hash mapping each feature in the original genome
3451  BBH pegs in the target genomes to their scores.  to a sub-hash mapping its BBH pegs in the target genomes to their scores.
3452    
3453  =back  =back
3454    
# Line 3118  Line 3461 
3461      my %retVal = ();      my %retVal = ();
3462      # Ask for the BBHs.      # Ask for the BBHs.
3463      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3464        Trace("Retrieved " . scalar(@bbhList) . " BBH results.") if T(3);
3465      # We now have a set of 4-tuples that we need to convert into a hash of hashes.      # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3466      for my $bbhData (@bbhList) {      for my $bbhData (@bbhList) {
3467          my ($peg1, $peg2, $score) = @{$bbhData};          my ($peg1, $peg2, $score) = @{$bbhData};
# Line 3128  Line 3472 
3472          }          }
3473      }      }
3474      # Return the result.      # Return the result.
3475      return %retVal;      return \%retVal;
3476  }  }
3477    
3478    
3479  =head3 SimMatrix  =head3 SimMatrix
3480    
3481  C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>      my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3482    
3483  Find all the similarities for the features of a genome in a  Find all the similarities for the features of a genome in a
3484  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3204  Line 3548 
3548    
3549  =head3 LowBBHs  =head3 LowBBHs
3550    
3551  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3552    
3553  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
3554  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 3234  Line 3578 
3578      # Create the return hash.      # Create the return hash.
3579      my %retVal = ();      my %retVal = ();
3580      # Query for the desired BBHs.      # Query for the desired BBHs.
3581      my @bbhList = FIGRules::BBHData($featureID, $cutoff);      my $bbhList = FIGRules::BBHData($featureID, $cutoff);
3582      # Form the results into the return hash.      # Form the results into the return hash.
3583      for my $pair (@bbhList) {      for my $pair (@$bbhList) {
3584          my $fid = $pair->[0];          my $fid = $pair->[0];
3585          if ($self->Exists('Feature', $fid)) {          if ($self->Exists('Feature', $fid)) {
3586              $retVal{$fid} = $pair->[1];              $retVal{$fid} = $pair->[1];
# Line 3248  Line 3592 
3592    
3593  =head3 Sims  =head3 Sims
3594    
3595  C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>      my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3596    
3597  Get a list of similarities for a specified feature. Similarity information is not kept in the  Get a list of similarities for a specified feature. Similarity information is not kept in the
3598  Sprout database; rather, they are retrieved from a network server. The similarities are  Sprout database; rather, they are retrieved from a network server. The similarities are
# Line 3314  Line 3658 
3658    
3659  =head3 IsAllGenomes  =head3 IsAllGenomes
3660    
3661  C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>      my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3662    
3663  Return TRUE if all genomes in the second list are represented in the first list at  Return TRUE if all genomes in the second list are represented in the first list at
3664  least one. Otherwise, return FALSE. If the second list is omitted, the first list is  least one. Otherwise, return FALSE. If the second list is omitted, the first list is
# Line 3363  Line 3707 
3707    
3708  =head3 GetGroups  =head3 GetGroups
3709    
3710  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3711    
3712  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.
3713  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 3395  Line 3739 
3739                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3740          # Loop through the genomes found.          # Loop through the genomes found.
3741          for my $genome (@genomes) {          for my $genome (@genomes) {
3742              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3743              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3744              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);  
             }  
3745          }          }
3746      }      }
3747      # Return the hash we just built.      # Return the hash we just built.
# Line 3411  Line 3750 
3750    
3751  =head3 MyGenomes  =head3 MyGenomes
3752    
3753  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3754    
3755  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3756    
# Line 3443  Line 3782 
3782    
3783  =head3 LoadFileName  =head3 LoadFileName
3784    
3785  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3786    
3787  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
3788  directory.  directory.
# Line 3484  Line 3823 
3823    
3824  =head3 DeleteGenome  =head3 DeleteGenome
3825    
3826  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3827    
3828  Delete a genome from the database.  Delete a genome from the database.
3829    
# Line 3520  Line 3859 
3859    
3860  =head3 Fix  =head3 Fix
3861    
3862  C<< my %fixedHash = Sprout::Fix(%groupHash); >>      my %fixedHash = $sprout->Fix(%groupHash);
3863    
3864  Prepare a genome group hash (like that returned by L</GetGroups>) for processing.  Prepare a genome group hash (like that returned by L</GetGroups>) for processing.
3865  Groups with the same primary name will be combined. The primary name is the  The groups will be combined into the appropriate super-groups.
 first capitalized word in the group name.  
3866    
3867  =over 4  =over 4
3868    
# Line 3542  Line 3880 
3880    
3881  sub Fix {  sub Fix {
3882      # Get the parameters.      # Get the parameters.
3883      my (%groupHash) = @_;      my ($self, %groupHash) = @_;
3884      # Create the result hash.      # Create the result hash.
3885      my %retVal = ();      my %retVal = ();
3886      # Copy over the genomes.      # Copy over the genomes.
3887      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3888          # Make a safety copy of the group ID.          # Get the super-group name.
3889          my $realGroupID = $groupID;          my $realGroupID = $self->SuperGroup($groupID);
3890          # Yank the primary name.          # Append this group's genomes into the result hash
3891          if ($groupID =~ /([A-Z]\w+)/) {          # using the super-group name.
3892              $realGroupID = $1;          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
         }  
         # Append this group's genomes into the result hash.  
         Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});  
3893      }      }
3894      # Return the result hash.      # Return the result hash.
3895      return %retVal;      return %retVal;
# Line 3562  Line 3897 
3897    
3898  =head3 GroupPageName  =head3 GroupPageName
3899    
3900  C<< my $name = $sprout->GroupPageName($group); >>      my $name = $sprout->GroupPageName($group);
3901    
3902  Return the name of the page for the specified NMPDR group.  Return the name of the page for the specified NMPDR group.
3903    
# Line 3584  Line 3919 
3919  sub GroupPageName {  sub GroupPageName {
3920      # Get the parameters.      # Get the parameters.
3921      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3922      # Check for the group file data.      # Check for the group file data.
3923      if (! defined $self->{groupHash}) {      my %superTable = $self->CheckGroupFile();
         # Read the group file.  
         my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");  
         # Store it in our object.  
         $self->{groupHash} = \%groupData;  
     }  
3924      # Compute the real group name.      # Compute the real group name.
3925      my $realGroup = $group;      my $realGroup = $self->SuperGroup($group);
3926      if ($group =~ /([A-Z]\w+)/) {      # Get the associated page name.
3927          $realGroup = $1;      my $retVal = "../content/$superTable{$realGroup}->{page}";
     }  
     # Return the page name.  
     $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];  
3928      # Return the result.      # Return the result.
3929      return $retVal;      return $retVal;
3930  }  }
3931    
 =head3 ReadGroupFile  
3932    
3933  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  =head3 AddProperty
3934    
3935  Read in the data from the specified group file. The group file contains information      $sprout->AddProperty($featureID, $key, @values);
3936  about each of the NMPDR groups.  
3937    Add a new attribute value (Property) to a feature.
3938    
3939  =over 4  =over 4
3940    
3941  =item name  =item peg
3942    
3943  Name of the group.  ID of the feature to which the attribute is to be added.
3944    
3945  =item page  =item key
3946    
3947  Name of the group's page on the web site (e.g. C<campy.php> for  Name of the attribute (key).
 Campylobacter)  
3948    
3949  =item genus  =item values
3950    
3951  Genus of the group  Values of the attribute.
3952    
3953  =item species  =back
3954    
3955    =cut
3956    #: Return Type ;
3957    sub AddProperty {
3958        # Get the parameters.
3959        my ($self, $featureID, $key, @values) = @_;
3960        # Add the property using the attached attributes object.
3961        $self->ca->AddAttribute($featureID, $key, @values);
3962    }
3963    
3964  Species of the group, or an empty string if the group is for an entire  =head3 CheckGroupFile
 genus. If the group contains more than one species, the species names  
 should be separated by commas.  
3965    
3966  =back      my %groupData = $sprout->CheckGroupFile();
3967    
3968    Get the group file hash. The group file hash describes the relationship
3969    between a group and the super-group to which it belongs for purposes of
3970    display. The super-group name is computed from the first capitalized word
3971    in the actual group name. For each super-group, the group file contains
3972    the page name and a list of the species expected to be in the group.
3973    Each species is specified by a genus and a species name. A species name
3974    of C<0> implies an entire genus.
3975    
3976  The parameters to this method are as follows  This method returns a hash from super-group names to a hash reference. Each
3977    resulting hash reference contains the following fields.
3978    
3979  =over 4  =over 4
3980    
3981  =item groupFile  =item page
3982    
3983  Name of the file containing the group data.  The super-group's web page in the NMPDR.
3984    
3985  =item RETURN  =item contents
3986    
3987  Returns a hash keyed on group name. The value of each hash  A list of 2-tuples, each containing a genus name followed by a species name
3988    (or 0, indicating all species). This list indicates which organisms belong
3989    in the super-group.
3990    
3991  =back  =back
3992    
3993  =cut  =cut
3994    
3995  sub ReadGroupFile {  sub CheckGroupFile {
3996      # Get the parameters.      # Get the parameters.
3997      my ($groupFileName) = @_;      my ($self) = @_;
3998      # Declare the return variable.      # Check to see if we already have this hash.
3999      my %retVal;      if (! defined $self->{groupHash}) {
4000            # We don't, so we need to read it in.
4001            my %groupHash;
4002      # Read the group file.      # Read the group file.
4003      my @groupLines = Tracer::GetFile($groupFileName);          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
4004            # Loop through the list of sort-of groups.
4005      for my $groupLine (@groupLines) {      for my $groupLine (@groupLines) {
4006          my ($name, $page, $genus, $species) = split(/\t/, $groupLine);              my ($name, $page, @contents) = split /\t/, $groupLine;
4007          $retVal{$name} = [$page, $genus, $species];              $groupHash{$name} = { page => $page,
4008                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
4009                                    };
4010            }
4011            # Save the hash.
4012            $self->{groupHash} = \%groupHash;
4013      }      }
4014      # Return the result.      # Return the result.
4015      return %retVal;      return %{$self->{groupHash}};
4016  }  }
4017    
4018  =head3 AddProperty  =head2 Virtual Methods
4019    
4020  C<< my  = $sprout->AddProperty($featureID, $key, @values); >>  =head3 CleanKeywords
4021    
4022  Add a new attribute value (Property) to a feature.      my $cleanedString = $sprout->CleanKeywords($searchExpression);
4023    
4024    Clean up a search expression or keyword list. This involves converting the periods
4025    in EC numbers to underscores, converting non-leading minus signs to underscores,
4026    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
4027    characters. In addition, any extra spaces are removed.
4028    
4029  =over 4  =over 4
4030    
4031  =item peg  =item searchExpression
4032    
4033  ID of the feature to which the attribute is to be added.  Search expression or keyword list to clean. Note that a search expression may
4034    contain boolean operators which need to be preserved. This includes leading
4035    minus signs.
4036    
4037  =item key  =item RETURN
4038    
4039  Name of the attribute (key).  Cleaned expression or keyword list.
4040    
4041  =item values  =back
4042    
4043  Values of the attribute.  =cut
4044    
4045  =back  sub CleanKeywords {
4046        # Get the parameters.
4047        my ($self, $searchExpression) = @_;
4048        # Get the stemmer.
4049        my $stemmer = $self->GetStemmer();
4050        # Convert the search expression using the stemmer.
4051        my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
4052        Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
4053        # Return the result.
4054        return $retVal;
4055    }
4056    
4057    =head3 GetSourceObject
4058    
4059        my $source = $erdb->GetSourceObject();
4060    
4061    Return the object to be used in creating load files for this database.
4062    
4063  =cut  =cut
4064  #: Return Type ;  
4065  sub AddProperty {  sub GetSourceObject {
4066      # Get the parameters.      # Get the parameters.
4067      my ($self, $featureID, $key, @values) = @_;      my ($self) = @_;
4068      # Add the property using the attached attributes object.      # Check to see if we already have a source object.
4069      $self->{_ca}->AddAttribute($featureID, $key, @values);      my $retVal = $self->{_fig};
4070        if (! defined $retVal) {
4071            # No, so create one.
4072            require FIG;
4073            $retVal = FIG->new();
4074        }
4075        # Return the object.
4076        return $retVal;
4077  }  }
4078    
4079  =head2 Virtual Methods  =head3 SectionList
4080    
4081  =head3 CleanKeywords      my @sections = $erdb->SectionList();
4082    
4083  C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>  Return a list of the names for the different data sections used when loading this database.
4084    The default is a single string, in which case there is only one section representing the
4085    entire database.
4086    
4087  Clean up a search expression or keyword list. This involves converting the periods  =cut
4088  in EC numbers to underscores, converting non-leading minus signs to underscores,  
4089  a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic  sub SectionList {
4090  characters. In addition, any extra spaces are removed.      # Get the parameters.
4091        my ($self, $source) = @_;
4092        # Ask the BaseSproutLoader for a section list.
4093        require BaseSproutLoader;
4094        my @retVal = BaseSproutLoader::GetSectionList($self);
4095        # Return the list.
4096        return @retVal;
4097    }
4098    
4099    =head3 Loader
4100    
4101        my $groupLoader = $erdb->Loader($groupName, $options);
4102    
4103    Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4104    by [[ERDBGeneratorPl]] to create the load group objects. If you are not using
4105    [[ERDBGeneratorPl]], you don't need to override this method.
4106    
4107  =over 4  =over 4
4108    
4109  =item searchExpression  =item groupName
4110    
4111  Search expression or keyword list to clean. Note that a search expression may  Name of the load group whose object is to be returned. The group name is
4112  contain boolean operators which need to be preserved. This includes leading  guaranteed to be a single word with only the first letter capitalized.
4113  minus signs.  
4114    =item options
4115    
4116    Reference to a hash of command-line options.
4117    
4118  =item RETURN  =item RETURN
4119    
4120  Cleaned expression or keyword list.  Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4121    for this database.
4122    
4123  =back  =back
4124    
4125  =cut  =cut
4126    
4127  sub CleanKeywords {  sub Loader {
4128      # Get the parameters.      # Get the parameters.
4129      my ($self, $searchExpression) = @_;      my ($self, $groupName, $options) = @_;
4130      # Perform the standard cleanup.      # Compute the loader name.
4131      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $loaderClass = "${groupName}SproutLoader";
4132      # Fix the periods in EC and TC numbers.      # Pull in its definition.
4133      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      require "$loaderClass.pm";
4134      # Fix non-trailing periods.      # Create an object for it.
4135      $retVal =~ s/\.(\w)/_$1/g;      my $retVal = eval("$loaderClass->new(\$self, \$options)");
4136      # Fix non-leading minus signs.      # Insure it worked.
4137      $retVal =~ s/(\w)[\-]/$1_/g;      Confess("Could not create $loaderClass object: $@") if $@;
4138      # Fix the vertical bars and colons      # Return it to the caller.
     $retVal =~ s/(\w)[|:](\w)/$1'$2/g;  
     # Return the result.  
4139      return $retVal;      return $retVal;
4140  }  }
4141    
4142    
4143    =head3 LoadGroupList
4144    
4145        my @groups = $erdb->LoadGroupList();
4146    
4147    Returns a list of the names for this database's load groups. This method is used
4148    by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default
4149    is a single group called 'All' that loads everything.
4150    
4151    =cut
4152    
4153    sub LoadGroupList {
4154        # Return the list.
4155        return qw(Genome Subsystem Annotation Property Source Reaction Synonym Feature Drug);
4156    }
4157    
4158    =head3 LoadDirectory
4159    
4160        my $dirName = $erdb->LoadDirectory();
4161    
4162    Return the name of the directory in which load files are kept. The default is
4163    the FIG temporary directory, which is a really bad choice, but it's always there.
4164    
4165    =cut
4166    
4167    sub LoadDirectory {
4168        # Get the parameters.
4169        my ($self) = @_;
4170        # Return the directory name.
4171        return $self->{dataDir};
4172    }
4173    
4174  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4175    
4176    =head3 GetStemmer
4177    
4178        my $stermmer = $sprout->GetStemmer();
4179    
4180    Return the stemmer object for this database.
4181    
4182    =cut
4183    
4184    sub GetStemmer {
4185        # Get the parameters.
4186        my ($self) = @_;
4187        # Declare the return variable.
4188        my $retVal = $self->{stemmer};
4189        if (! defined $retVal) {
4190            # We don't have one pre-built, so we build and save it now.
4191            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4192                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4193                                     cache => 0);
4194            $self->{stemmer} = $retVal;
4195        }
4196        # Return the result.
4197        return $retVal;
4198    }
4199    
4200  =head3 ParseAssignment  =head3 ParseAssignment
4201    
4202  Parse annotation text to determine whether or not it is a functional assignment. If it is,  Parse annotation text to determine whether or not it is a functional assignment. If it is,
# Line 3750  Line 4205 
4205    
4206  A functional assignment is always of the form  A functional assignment is always of the form
4207    
4208      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
4209        ZZZZ
4210    
4211  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,
4212  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 3805  Line 4261 
4261    
4262  =head3 _CheckFeature  =head3 _CheckFeature
4263    
4264  C<< my $flag = $sprout->_CheckFeature($fid); >>      my $flag = $sprout->_CheckFeature($fid);
4265    
4266  Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.  Return TRUE if the specified FID is probably an NMPDR feature ID, else FALSE.
4267    
# Line 3827  Line 4283 
4283      # Get the parameters.      # Get the parameters.
4284      my ($self, $fid) = @_;      my ($self, $fid) = @_;
4285      # Insure we have a genome hash.      # Insure we have a genome hash.
4286      if (! defined $self->{genomeHash}) {      my $genomes = $self->_GenomeHash();
         my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');  
         $self->{genomeHash} = \%genomeHash;  
     }  
4287      # Get the feature's genome ID.      # Get the feature's genome ID.
4288      my ($genomeID) = FIGRules::ParseFeatureID($fid);      my ($genomeID) = FIGRules::ParseFeatureID($fid);
4289      # Return an indicator of whether or not the genome ID is in the hash.      # Return an indicator of whether or not the genome ID is in the hash.
# Line 3864  Line 4317 
4317  }  }
4318    
4319    
4320    =head3 Hint
4321    
4322        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4323    
4324    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4325    This HTML can be put in forms to provide a useful hinting mechanism.
4326    
4327    =over 4
4328    
4329    =item wikiPage
4330    
4331    Name of the wiki page to be popped up when the hint mark is clicked.
4332    
4333    =item hintText
4334    
4335    Text to display for the hint. It is raw html, but may not contain any double quotes.
4336    
4337    =item RETURN
4338    
4339    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4340    uses the standard FIG popup technology.
4341    
4342    =back
4343    
4344    =cut
4345    
4346    sub Hint {
4347        # Get the parameters.
4348        my ($wikiPage, $hintText) = @_;
4349        # Escape the single quotes in the hint text.
4350        my $quotedText = $hintText;
4351        $quotedText =~ s/'/\\'/g;
4352        # Convert the wiki page name to a URL.
4353        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4354        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4355        # Compute the mouseover script.
4356        my $mouseOver = "doTooltip(this, '$quotedText')";
4357        # Create the html.
4358        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4359        # Return it.
4360        return $retVal;
4361    }
4362    
4363    =head3 _GenomeHash
4364    
4365        my $gHash = $sprout->_GenomeHash();
4366    
4367    Return a hash mapping all NMPDR genome IDs to [[ERDBObjectPm]] genome objects.
4368    
4369    =cut
4370    
4371    sub _GenomeHash {
4372        # Get the parameters.
4373        my ($self) = @_;
4374        # Do we already have a filled hash?
4375        if (! $self->{genomeHashFilled}) {
4376            # No, create it.
4377            my %gHash = map { $_->PrimaryValue('id') => $_ } $self->GetList("Genome", "", []);
4378            $self->{genomeHash} = \%gHash;
4379            # Denote we have it.
4380            $self->{genomeHashFilled} = 1;
4381        }
4382        # Return the hash.
4383        return $self->{genomeHash};
4384    }
4385    
4386    =head3 _GenomeData
4387    
4388        my $genomeData = $sprout->_GenomeData($genomeID);
4389    
4390    Return an [[ERDBObjectPm]] object for the specified genome, or an undefined
4391    value if the genome does not exist.
4392    
4393    =over 4
4394    
4395    =item genomeID
4396    
4397    ID of the desired genome.
4398    
4399    =item RETURN
4400    
4401    Returns either an [[ERDBObjectPm]] containing the genome, or an undefined value.
4402    If the genome exists, it will have been read into the genome cache.
4403    
4404    =back
4405    
4406    =cut
4407    
4408    sub _GenomeData {
4409        # Get the parameters.
4410        my ($self, $genomeID) = @_;
4411        # Are we in the genome hash?
4412        if (! exists $self->{genomeHash}->{$genomeID} && ! $self->{genomeHashFilled}) {
4413            # The genome isn't in the hash, and the hash is not complete, so we try to
4414            # read it.
4415            $self->{genomeHash}->{$genomeID} = $self->GetEntity(Genome => $genomeID);
4416        }
4417        # Return the result.
4418        return $self->{genomeHash}->{$genomeID};
4419    }
4420    
4421    =head3 _CacheGenome
4422    
4423        $sprout->_CacheGenome($genomeID, $genomeData);
4424    
4425    Store the specified genome object in the genome cache if it is already there.
4426    
4427    =over 4
4428    
4429    =item genomeID
4430    
4431    ID of the genome to store in the cache.
4432    
4433    =item genomeData
4434    
4435    An [[ERDBObjectPm]] containing at least the data for the specified genome.
4436    Note that the Genome may not be the primary object in it, so a fully-qualified
4437    field name has to be used to retrieve data from it.
4438    
4439    =back
4440    
4441    =cut
4442    
4443    sub _CacheGenome {
4444        # Get the parameters.
4445        my ($self, $genomeID, $genomeData) = @_;
4446        # Only proceed if we don't already have the genome.
4447        if (! exists $self->{genomeHash}->{$genomeID}) {
4448            $self->{genomeHash}->{$genomeID} = $genomeData;
4449        }
4450    }
4451    
4452  1;  1;

Legend:
Removed from v.1.101  
changed lines
  Added in v.1.122

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3