[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.109, Sun Mar 23 16:32:05 2008 UTC
# Line 1  Line 1 
1  package Sprout;  package Sprout;
2    
     require Exporter;  
     use ERDB;  
     @ISA = qw(Exporter ERDB);  
3      use Data::Dumper;      use Data::Dumper;
4      use strict;      use strict;
5      use DBKernel;      use DBKernel;
# Line 17  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17        use CGI;
18        use base qw(ERDB);
19    
20  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
21    
# Line 29  Line 28 
28  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>  on the constructor. For example, the following invocation specifies a PostgreSQL database named I<GenDB>
29  whose definition and data files are in a co-directory named F<Data>.  whose definition and data files are in a co-directory named F<Data>.
30    
31  C<< my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' }); >>      my $sprout = Sprout->new('GenDB', { dbType => 'pg', dataDir => '../Data', xmlFileName => '../Data/SproutDBD.xml' });
32    
33  Once you have a sprout object, you may use it to re-create the database, load the tables from  Once you have a sprout object, you may use it to re-create the database, load the tables from
34  tab-delimited flat files and perform queries. Several special methods are provided for common  tab-delimited flat files and perform queries. Several special methods are provided for common
35  query tasks. For example, L</genomes> lists the IDs of all the genomes in the database and  query tasks. For example, L</Genomes> lists the IDs of all the genomes in the database and
36  L</dna_seq> returns the DNA sequence for a specified genome location.  L</DNASeq> returns the DNA sequence for a specified genome location.
37    
38  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.  The Sprout object is a subclass of the ERDB object and inherits all its properties and methods.
39    
# Line 46  Line 45 
45    
46  =head3 new  =head3 new
47    
48  C<< my $sprout = Sprout->new($dbName, \%options); >>      my $sprout = Sprout->new($dbName, \%options);
49    
50  This is the constructor for a sprout object. It connects to the database and loads the  This is the constructor for a sprout object. It connects to the database and loads the
51  database definition into memory. The positional first parameter specifies the name of the  database definition into memory. The positional first parameter specifies the name of the
# Line 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  =cut  =cut
93    
# Line 110  Line 111 
111                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
112                                                          # database connection port                                                          # database connection port
113                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::dbsock,
114                         host         => $FIG_Config::dbhost,                         host         => $FIG_Config::sprout_host,
115                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
116                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
117                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 123  Line 124 
124      # Connect to the database.      # Connect to the database.
125      my $dbh;      my $dbh;
126      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
127            Trace("Connect data: host = $optionTable->{host}, port = $optionTable->{port}.") if T(3);
128          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
129                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
130      }      }
# Line 149  Line 151 
151      return $retVal;      return $retVal;
152  }  }
153    
154    =head3 CoreGenomes
155    
156        my @genomes = $sprout->CoreGenomes($scope);
157    
158    Return the IDs of NMPDR genomes in the specified scope.
159    
160    =over 4
161    
162    =item scope
163    
164    Scope of the desired genomes. C<core> covers the original core genomes,
165    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
166    genomes in the system.
167    
168    =item RETURN
169    
170    Returns a list of the IDs for the genomes in the specified scope.
171    
172    =back
173    
174    =cut
175    
176    sub CoreGenomes {
177        # Get the parameters.
178        my ($self, $scope) = @_;
179        # Declare the return variable.
180        my @retVal = ();
181        # If we want all genomes, then this is easy.
182        if ($scope eq 'all') {
183            @retVal = $self->Genomes();
184        } else {
185            # Here we're dealing with groups. Get the hash of all the
186            # genome groups.
187            my %groups = $self->GetGroups();
188            # Loop through the groups, keeping the ones that we want.
189            for my $group (keys %groups) {
190                # Decide if we want to keep this group.
191                my $keepGroup = 0;
192                if ($scope eq 'nmpdr') {
193                    # NMPDR mode: keep all groups.
194                    $keepGroup = 1;
195                } elsif ($scope eq 'core') {
196                    # CORE mode. Only keep real core groups.
197                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
198                        $keepGroup = 1;
199                    }
200                }
201                # Add this group if we're keeping it.
202                if ($keepGroup) {
203                    push @retVal, @{$groups{$group}};
204                }
205            }
206        }
207        # Return the result.
208        return @retVal;
209    }
210    
211    =head3 SuperGroup
212    
213        my $superGroup = $sprout->SuperGroup($groupName);
214    
215    Return the name of the super-group containing the specified NMPDR genome
216    group. If no appropriate super-group can be found, an error will be
217    thrown.
218    
219    =over 4
220    
221    =item groupName
222    
223    Name of the group whose super-group is desired.
224    
225    =item RETURN
226    
227    Returns the name of the super-group containing the incoming group.
228    
229    =back
230    
231    =cut
232    
233    sub SuperGroup {
234        # Get the parameters.
235        my ($self, $groupName) = @_;
236        # Declare the return variable.
237        my $retVal;
238        # Get the group hash.
239        my %groupHash = $self->CheckGroupFile();
240        # Find the super-group genus.
241        $groupName =~ /([A-Z]\w+)/;
242        my $nameThing = $1;
243        # See if it's directly in the group hash.
244        if (exists $groupHash{$nameThing}) {
245            # Yes, then it's our result.
246            $retVal = $nameThing;
247        } else {
248            # No, so we have to search.
249            for my $superGroup (keys %groupHash) {
250                # Get this super-group's item list.
251                my $list = $groupHash{$superGroup}->{contents};
252                # Search it.
253                if (grep { $_->[0] eq $nameThing } @{$list}) {
254                    $retVal = $superGroup;
255                }
256            }
257            # Make sure we found something.
258            if (! $retVal) {
259                Confess("No super-group found for \"$groupName\".");
260            }
261        }
262        # Return the result.
263        return $retVal;
264    }
265    
266  =head3 MaxSegment  =head3 MaxSegment
267    
268  C<< my $length = $sprout->MaxSegment(); >>      my $length = $sprout->MaxSegment();
269    
270  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
271  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 282 
282    
283  =head3 MaxSequence  =head3 MaxSequence
284    
285  C<< my $length = $sprout->MaxSequence(); >>      my $length = $sprout->MaxSequence();
286    
287  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
288  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 297 
297    
298  =head3 Load  =head3 Load
299    
300  C<< $sprout->Load($rebuild); >>;      $sprout->Load($rebuild);;
301    
302  Load the database from files in the data directory, optionally re-creating the tables.  Load the database from files in the data directory, optionally re-creating the tables.
303    
# Line 223  Line 337 
337    
338  =head3 LoadUpdate  =head3 LoadUpdate
339    
340  C<< my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList); >>      my $stats = $sprout->LoadUpdate($truncateFlag, \@tableList);
341    
342  Load updates to one or more database tables. This method enables the client to make changes to one  Load updates to one or more database tables. This method enables the client to make changes to one
343  or two tables without reloading the whole database. For each table, there must be a corresponding  or two tables without reloading the whole database. For each table, there must be a corresponding
# Line 269  Line 383 
383              Trace("No load file found for $tableName in $dataDir.") if T(0);              Trace("No load file found for $tableName in $dataDir.") if T(0);
384          } else {          } else {
385              # Attempt to load this table.              # Attempt to load this table.
386              my $result = $self->LoadTable($fileName, $tableName, $truncateFlag);              my $result = $self->LoadTable($fileName, $tableName, truncate => $truncateFlag);
387              # Accumulate the resulting statistics.              # Accumulate the resulting statistics.
388              $retVal->Accumulate($result);              $retVal->Accumulate($result);
389          }          }
# Line 280  Line 394 
394    
395  =head3 GenomeCounts  =head3 GenomeCounts
396    
397  C<< my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete); >>      my ($arch, $bact, $euk, $vir, $env, $unk) = $sprout->GenomeCounts($complete);
398    
399  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete  Count the number of genomes in each domain. If I<$complete> is TRUE, only complete
400  genomes will be included in the counts.  genomes will be included in the counts.
# Line 325  Line 439 
439    
440  =head3 ContigCount  =head3 ContigCount
441    
442  C<< my $count = $sprout->ContigCount($genomeID); >>      my $count = $sprout->ContigCount($genomeID);
443    
444  Return the number of contigs for the specified genome ID.  Return the number of contigs for the specified genome ID.
445    
# Line 352  Line 466 
466      return $retVal;      return $retVal;
467  }  }
468    
469  =head3 GeneMenu  =head3 GenomeMenu
470    
471  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>      my $html = $sprout->GenomeMenu(%options);
472    
473  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.
474  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
475  value will be the genome ID. The genomes will be sorted by genus/species name.  B<SearchHelper> class. Eventually, the two will be combined.
476    
477  =over 4  =over 4
478    
479  =item attributes  =item options
480    
481  Reference to a hash mapping attributes to values for the SELECT tag generated.  Optional parameters for the control (see below).
482    
483  =item filterString  =item RETURN
484    
485  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.  
486    
487  =item params  =back
488    
489  Reference to a list of values to be substituted in for the parameter marks in  The valid options are as follows.
 the filter string.  
490    
491  =item selected (optional)  =over 4
492    
493  ID of the genome to be initially selected.  =item name
494    
495  =item fast (optional)  Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
496    Terrible things will happen if you have two controls with the same name on the same page.
497    
498  If specified and TRUE, the contig counts will be omitted to improve performance.  =item filter
499    
500  =item RETURN  If specified, a filter for the list of genomes to display. The filter should be in the form of a
501    list reference. The first element of the list should be the filter string, and the remaining elements
502  Returns an HTML select menu with the specified genomes as selectable options.  the filter parameters.
503    
504    =item multiSelect
505    
506    If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
507    
508    =item size
509    
510    Number of rows to display in the control. The default is C<10>
511    
512    =item id
513    
514    ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
515    unless this ID is unique.
516    
517    =item selected
518    
519    A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
520    default is none.
521    
522    =item inTable
523    
524    If TRUE, then backslashes will be included at the end of each line in the resulting HTML. This enables the control
525    to be used in TWiki tables.
526    
527  =back  =back
528    
529  =cut  =cut
530    
531  sub GeneMenu {  sub GenomeMenu {
532      # Get the parameters.      # Get the parameters.
533      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;      my ($self, %options) = @_;
534      my $slowMode = ! $fast;      # Get the control's name and ID.
535      # Default to nothing selected. This prevents an execution warning if "$selected"      my $menuName = $options{name} || 'myGenomeControl';
536      # is undefined.      my $menuID = $options{id} || $menuName;
537      $selected = "" unless defined $selected;      # Compute the IDs for the status display.
538      Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);      my $divID = "${menuID}_status";
539      # Start the menu.      my $urlID = "${menuID}_url";
540      my $retVal = "<select " .      # Compute the code to show selected genomes in the status area.
541          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
542          ">\n";      # Check for single-select or multi-select.
543      # Get the genomes.      my $multiSelect = $options{multiSelect} || 0;
544      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',      # Get the list of pre-selected items.
545                                                                       'Genome(genus)',      my $selections = $options{selected} || [];
546                                                                       'Genome(species)',      if (ref $selections ne 'ARRAY') {
547                                                                       'Genome(unique-characterization)']);          $selections = [ split /\s*,\s*/, $selections ];
548      # Sort them by name.      }
549      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;      my %selected = map { $_ => } @{$selections};
550      # Loop through the genomes, creating the option tags.      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
551      for my $genomeData (@sorted) {      # string or a list reference.
552          # Get the data for this genome.      my $filterParms = $options{filter} || "";
553          my ($genomeID, $genus, $species, $strain) = @{$genomeData};      if (! ref $filterParms) {
554          # Get the contig count.          $filterParms = [split /\t|\\t/, $filterParms];
555          my $contigInfo = "";      }
556          if ($slowMode) {      my $filterString = shift @{$filterParms};
557              my $count = $self->ContigCount($genomeID);      # Get a list of all the genomes in group order. In fact, we only need them ordered
558              my $counting = ($count == 1 ? "contig" : "contigs");      # by name (genus,species,strain), but putting primary-group in front enables us to
559              $contigInfo = "[$count $counting]";      # take advantage of an existing index.
560          }      my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
561          # Find out if we're selected.                                     $filterParms,
562          my $selectOption = ($selected eq $genomeID ? " selected" : "");                                     [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
563          # Build the option tag.      # Create a hash to organize the genomes by group. Each group will contain a list of
564          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";      # 2-tuples, the first element being the genome ID and the second being the genome
565        # name.
566        my %gHash = ();
567        for my $genome (@genomeList) {
568            # Get the genome data.
569            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
570            # Compute its name. This is the genus, species, strain (if any), and the contig count.
571            my $name = "$genus $species ";
572            $name .= "$strain " if $strain;
573            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
574            # Now we get the domain. The domain tells us the display style of the organism.
575            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
576            # Now compute the display group. This is normally the primary group, but if the
577            # organism is supporting, we blank it out.
578            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
579            # Push the genome into the group's list. Note that we use the real group
580            # name for the hash key here, not the display group name.
581            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
582        }
583        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
584        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
585        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
586        # that aren't "other". At some point, we will want to make this less complicated.
587        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
588                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
589        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
590        # Remember the number of NMPDR groups.
591        my $nmpdrGroupCount = scalar @groups;
592        # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
593        # of the domains found.
594        my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
595        my @domains = ();
596        for my $genomeData (@otherGenomes) {
597            my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
598            if (exists $gHash{$domain}) {
599                push @{$gHash{$domain}}, $genomeData;
600            } else {
601                $gHash{$domain} = [$genomeData];
602                push @domains, $domain;
603            }
604        }
605        # Add the domain groups at the end of the main group list. The main group list will now
606        # contain all the categories we need to display the genomes.
607        push @groups, sort @domains;
608        # Delete the supporting group.
609        delete $gHash{$FIG_Config::otherGroup};
610        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
611        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
612        # and use that to make the selections.
613        my $nmpdrCount = 0;
614        # Create the type counters.
615        my $groupCount = 1;
616        # Get the number of rows to display.
617        my $rows = $options{size} || 10;
618        # If we're multi-row, create an onChange event.
619        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
620        # Set up the multiple-select flag.
621        my $multipleTag = ($multiSelect ? " multiple" : "" );
622        # Create the SELECT tag and stuff it into the output array.
623        my @lines = ("<SELECT name=\"$menuID\" id=\"$menuID\" $onChangeTag$multipleTag size=\"$rows\" style=\"width: 100%\">");
624        # Loop through the groups.
625        for my $group (@groups) {
626            # Get the genomes in the group.
627            for my $genome (@{$gHash{$group}}) {
628                # If this is an NMPDR organism, we add an extra style and count it.
629                my $nmpdrStyle = "";
630                if ($nmpdrGroupCount > 0) {
631                    $nmpdrCount++;
632                    $nmpdrStyle = " Core";
633                }
634                # Get the organism ID, name, contig count, and domain.
635                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
636                # See if we're pre-selected.
637                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
638                # Compute the display name.
639                my $nameString = "$name ($genomeID$contigCount)";
640                # Generate the option tag.
641                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
642                push @lines, "    $optionTag";
643            }
644            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
645            # groups.
646            $nmpdrGroupCount--;
647      }      }
648      # Close the SELECT tag.      # Close the SELECT tag.
649      $retVal .= "</select>\n";      push @lines, "</SELECT>";
650        if ($rows > 1) {
651            # We're in a non-compact mode, so we need to add some selection helpers. First is
652            # the search box. This allows the user to type text and change which genomes are
653            # displayed. For multiple-select mode, we include a button that selects the displayed
654            # genes. For single-select mode, we use a plain label instead.
655            my $searchThingName = "${menuID}_SearchThing";
656            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
657                                                 : "Show genomes containing");
658            push @lines, "<br />$searchThingLabel&nbsp;" .
659                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />";
660            # For multi-select mode, we also have buttons to set and clear selections.
661            if ($multiSelect) {
662                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";
663                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";
664                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";
665            }
666            # Add a hidden field we can use to generate organism page hyperlinks.
667            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/seedviewer.cgi?page=Organism;organism=\" />";
668            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
669            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
670        }
671        # Assemble all the lines into a string. This is where we do the "inTable" thing to insure we don't mess up TWiki tables.
672        my $delim = ($options{inTable} ? "\\" : "" ) . "\n";
673        my $retVal = join($delim, @lines, "");
674      # Return the result.      # Return the result.
675      return $retVal;      return $retVal;
676  }  }
677    
678    
679  =head3 Build  =head3 Build
680    
681  C<< $sprout->Build(); >>      $sprout->Build();
682    
683  Build the database. The database will be cleared and the tables re-created from the metadata.  Build the database. The database will be cleared and the tables re-created from the metadata.
684  This method is useful when a database is brand new or when the database definition has  This method is useful when a database is brand new or when the database definition has
# Line 452  Line 695 
695    
696  =head3 Genomes  =head3 Genomes
697    
698  C<< my @genomes = $sprout->Genomes(); >>      my @genomes = $sprout->Genomes();
699    
700  Return a list of all the genome IDs.  Return a list of all the genome IDs.
701    
# Line 469  Line 712 
712    
713  =head3 GenusSpecies  =head3 GenusSpecies
714    
715  C<< my $infoString = $sprout->GenusSpecies($genomeID); >>      my $infoString = $sprout->GenusSpecies($genomeID);
716    
717  Return the genus, species, and unique characterization for a genome.  Return the genus, species, and unique characterization for a genome.
718    
# Line 501  Line 744 
744    
745  =head3 FeaturesOf  =head3 FeaturesOf
746    
747  C<< my @features = $sprout->FeaturesOf($genomeID, $ftype); >>      my @features = $sprout->FeaturesOf($genomeID, $ftype);
748    
749  Return a list of the features relevant to a specified genome.  Return a list of the features relevant to a specified genome.
750    
# Line 546  Line 789 
789    
790  =head3 FeatureLocation  =head3 FeatureLocation
791    
792  C<< my @locations = $sprout->FeatureLocation($featureID); >>      my @locations = $sprout->FeatureLocation($featureID);
793    
794  Return the location of a feature in its genome's contig segments. In a list context, this method  Return the location of a feature in its genome's contig segments. In a list context, this method
795  will return a list of the locations. In a scalar context, it will return the locations as a space-  will return a list of the locations. In a scalar context, it will return the locations as a space-
# Line 592  Line 835 
835    
836  =head3 ParseLocation  =head3 ParseLocation
837    
838  C<< my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location); >>      my ($contigID, $start, $dir, $len) = Sprout::ParseLocation($location);
839    
840  Split a location specifier into the contig ID, the starting point, the direction, and the  Split a location specifier into the contig ID, the starting point, the direction, and the
841  length.  length.
# Line 638  Line 881 
881    
882  =head3 PointLocation  =head3 PointLocation
883    
884  C<< my $found = Sprout::PointLocation($location, $point); >>      my $found = Sprout::PointLocation($location, $point);
885    
886  Return the offset into the specified location of the specified point on the contig. If  Return the offset into the specified location of the specified point on the contig. If
887  the specified point is before the location, a negative value will be returned. If it is  the specified point is before the location, a negative value will be returned. If it is
# Line 690  Line 933 
933    
934  =head3 DNASeq  =head3 DNASeq
935    
936  C<< my $sequence = $sprout->DNASeq(\@locationList); >>      my $sequence = $sprout->DNASeq(\@locationList);
937    
938  This method returns the DNA sequence represented by a list of locations. The list of locations  This method returns the DNA sequence represented by a list of locations. The list of locations
939  should be of the form returned by L</featureLocation> when in a list context. In other words,  should be of the form returned by L</featureLocation> when in a list context. In other words,
# Line 774  Line 1017 
1017    
1018  =head3 AllContigs  =head3 AllContigs
1019    
1020  C<< my @idList = $sprout->AllContigs($genomeID); >>      my @idList = $sprout->AllContigs($genomeID);
1021    
1022  Return a list of all the contigs for a genome.  Return a list of all the contigs for a genome.
1023    
# Line 804  Line 1047 
1047    
1048  =head3 GenomeLength  =head3 GenomeLength
1049    
1050  C<< my $length = $sprout->GenomeLength($genomeID); >>      my $length = $sprout->GenomeLength($genomeID);
1051    
1052  Return the length of the specified genome in base pairs.  Return the length of the specified genome in base pairs.
1053    
# Line 839  Line 1082 
1082    
1083  =head3 FeatureCount  =head3 FeatureCount
1084    
1085  C<< my $count = $sprout->FeatureCount($genomeID, $type); >>      my $count = $sprout->FeatureCount($genomeID, $type);
1086    
1087  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.
1088    
# Line 874  Line 1117 
1117    
1118  =head3 GenomeAssignments  =head3 GenomeAssignments
1119    
1120  C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >>      my $fidHash = $sprout->GenomeAssignments($genomeID);
1121    
1122  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
1123  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 1160 
1160    
1161  =head3 ContigLength  =head3 ContigLength
1162    
1163  C<< my $length = $sprout->ContigLength($contigID); >>      my $length = $sprout->ContigLength($contigID);
1164    
1165  Compute the length of a contig.  Compute the length of a contig.
1166    
# Line 956  Line 1199 
1199    
1200  =head3 ClusterPEGs  =head3 ClusterPEGs
1201    
1202  C<< my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs); >>      my $clusteredList = $sprout->ClusterPEGs($sub, \@pegs);
1203    
1204  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
1205  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
1206  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
1207  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
1208  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
1209  sequence.  appear in the output sequence.
1210    
1211  =over 4  =over 4
1212    
# Line 1004  Line 1247 
1247    
1248  =head3 GenesInRegion  =head3 GenesInRegion
1249    
1250  C<< my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop); >>      my (\@featureIDList, $beg, $end) = $sprout->GenesInRegion($contigID, $start, $stop);
1251    
1252  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1253    
# Line 1085  Line 1328 
1328    
1329  =head3 GeneDataInRegion  =head3 GeneDataInRegion
1330    
1331  C<< my @featureList = $sprout->GenesInRegion($contigID, $start, $stop); >>      my @featureList = $sprout->GenesInRegion($contigID, $start, $stop);
1332    
1333  List the features which overlap a specified region in a contig.  List the features which overlap a specified region in a contig.
1334    
# Line 1156  Line 1399 
1399    
1400  =head3 FType  =head3 FType
1401    
1402  C<< my $ftype = $sprout->FType($featureID); >>      my $ftype = $sprout->FType($featureID);
1403    
1404  Return the type of a feature.  Return the type of a feature.
1405    
# Line 1186  Line 1429 
1429    
1430  =head3 FeatureAnnotations  =head3 FeatureAnnotations
1431    
1432  C<< my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag); >>      my @descriptors = $sprout->FeatureAnnotations($featureID, $rawFlag);
1433    
1434  Return the annotations of a feature.  Return the annotations of a feature.
1435    
# Line 1249  Line 1492 
1492    
1493  =head3 AllFunctionsOf  =head3 AllFunctionsOf
1494    
1495  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>      my %functions = $sprout->AllFunctionsOf($featureID);
1496    
1497  Return all of the functional assignments for a particular feature. The data is returned as a  Return all of the functional assignments for a particular feature. The data is returned as a
1498  hash of functional assignments to user IDs. A functional assignment is a type of annotation,  hash of functional assignments to user IDs. A functional assignment is a type of annotation,
# Line 1304  Line 1547 
1547    
1548  =head3 FunctionOf  =head3 FunctionOf
1549    
1550  C<< my $functionText = $sprout->FunctionOf($featureID, $userID); >>      my $functionText = $sprout->FunctionOf($featureID, $userID);
1551    
1552  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1553    
# Line 1408  Line 1651 
1651    
1652  =head3 FunctionsOf  =head3 FunctionsOf
1653    
1654  C<< my @functionList = $sprout->FunctionOf($featureID, $userID); >>      my @functionList = $sprout->FunctionOf($featureID, $userID);
1655    
1656  Return the functional assignments of a particular feature.  Return the functional assignments of a particular feature.
1657    
# Line 1480  Line 1723 
1723    
1724  =head3 BBHList  =head3 BBHList
1725    
1726  C<< my $bbhHash = $sprout->BBHList($genomeID, \@featureList); >>      my $bbhHash = $sprout->BBHList($genomeID, \@featureList);
1727    
1728  Return a hash mapping the features in a specified list to their bidirectional best hits  Return a hash mapping the features in a specified list to their bidirectional best hits
1729  on a specified target genome.  on a specified target genome.
# Line 1530  Line 1773 
1773    
1774  =head3 SimList  =head3 SimList
1775    
1776  C<< my %similarities = $sprout->SimList($featureID, $count); >>      my %similarities = $sprout->SimList($featureID, $count);
1777    
1778  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1779    
# Line 1566  Line 1809 
1809    
1810  =head3 IsComplete  =head3 IsComplete
1811    
1812  C<< my $flag = $sprout->IsComplete($genomeID); >>      my $flag = $sprout->IsComplete($genomeID);
1813    
1814  Return TRUE if the specified genome is complete, else FALSE.  Return TRUE if the specified genome is complete, else FALSE.
1815    
# Line 1602  Line 1845 
1845    
1846  =head3 FeatureAliases  =head3 FeatureAliases
1847    
1848  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>      my @aliasList = $sprout->FeatureAliases($featureID);
1849    
1850  Return a list of the aliases for a specified feature.  Return a list of the aliases for a specified feature.
1851    
# Line 1632  Line 1875 
1875    
1876  =head3 GenomeOf  =head3 GenomeOf
1877    
1878  C<< my $genomeID = $sprout->GenomeOf($featureID); >>      my $genomeID = $sprout->GenomeOf($featureID);
1879    
1880  Return the genome that contains a specified feature or contig.  Return the genome that contains a specified feature or contig.
1881    
# Line 1668  Line 1911 
1911    
1912  =head3 CoupledFeatures  =head3 CoupledFeatures
1913    
1914  C<< my %coupleHash = $sprout->CoupledFeatures($featureID); >>      my %coupleHash = $sprout->CoupledFeatures($featureID);
1915    
1916  Return the features functionally coupled with a specified feature. Features are considered  Return the features functionally coupled with a specified feature. Features are considered
1917  functionally coupled if they tend to be clustered on the same chromosome.  functionally coupled if they tend to be clustered on the same chromosome.
# Line 1715  Line 1958 
1958    
1959  =head3 CouplingEvidence  =head3 CouplingEvidence
1960    
1961  C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>      my @evidence = $sprout->CouplingEvidence($peg1, $peg2);
1962    
1963  Return the evidence for a functional coupling.  Return the evidence for a functional coupling.
1964    
# Line 1777  Line 2020 
2020    
2021  =head3 GetSynonymGroup  =head3 GetSynonymGroup
2022    
2023  C<< my $id = $sprout->GetSynonymGroup($fid); >>      my $id = $sprout->GetSynonymGroup($fid);
2024    
2025  Return the synonym group name for the specified feature.  Return the synonym group name for the specified feature.
2026    
# Line 1816  Line 2059 
2059    
2060  =head3 GetBoundaries  =head3 GetBoundaries
2061    
2062  C<< my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList); >>      my ($contig, $beg, $end) = $sprout->GetBoundaries(@locList);
2063    
2064  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
2065  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 2123 
2123    
2124  =head3 ReadFasta  =head3 ReadFasta
2125    
2126  C<< my %sequenceData = Sprout::ReadFasta($fileName, $prefix); >>      my %sequenceData = Sprout::ReadFasta($fileName, $prefix);
2127    
2128  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by  Read sequence data from a FASTA-format file. Each sequence in a FASTA file is represented by
2129  one or more lines of data. The first line begins with a > character and contains an ID.  one or more lines of data. The first line begins with a > character and contains an ID.
# Line 1946  Line 2189 
2189    
2190  =head3 FormatLocations  =head3 FormatLocations
2191    
2192  C<< my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat); >>      my @locations = $sprout->FormatLocations($prefix, \@locations, $oldFormat);
2193    
2194  Insure that a list of feature locations is in the Sprout format. The Sprout feature location  Insure that a list of feature locations is in the Sprout format. The Sprout feature location
2195  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward  format is I<contig>_I<beg*len> where I<*> is C<+> for a forward gene and C<-> for a backward
# Line 2011  Line 2254 
2254    
2255  =head3 DumpData  =head3 DumpData
2256    
2257  C<< $sprout->DumpData(); >>      $sprout->DumpData();
2258    
2259  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.  Dump all the tables to tab-delimited DTX files. The files will be stored in the data directory.
2260    
# Line 2028  Line 2271 
2271    
2272  =head3 XMLFileName  =head3 XMLFileName
2273    
2274  C<< my $fileName = $sprout->XMLFileName(); >>      my $fileName = $sprout->XMLFileName();
2275    
2276  Return the name of this database's XML definition file.  Return the name of this database's XML definition file.
2277    
# Line 2039  Line 2282 
2282      return $self->{_xmlName};      return $self->{_xmlName};
2283  }  }
2284    
2285    =head3 GetGenomeNameData
2286    
2287        my ($genus, $species, $strain) = $sprout->GenomeNameData($genomeID);
2288    
2289    Return the genus, species, and unique characterization for a genome. This
2290    is similar to L</GenusSpecies>, with the exception that it returns the
2291    values in three seperate fields.
2292    
2293    =over 4
2294    
2295    =item genomeID
2296    
2297    ID of the genome whose name data is desired.
2298    
2299    =item RETURN
2300    
2301    Returns a three-element list, consisting of the genus, species, and strain
2302    of the specified genome. If the genome is not found, an error occurs.
2303    
2304    =back
2305    
2306    =cut
2307    
2308    sub GetGenomeNameData {
2309        # Get the parameters.
2310        my ($self, $genomeID) = @_;
2311        # Get the desired values.
2312        my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>
2313                                                                [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);
2314        # Throw an error if they were not found.
2315        if (! defined $genus) {
2316            Confess("Genome $genomeID not found in database.");
2317        }
2318        # Return the results.
2319        return ($genus, $species, $strain);
2320    }
2321    
2322    =head3 GetGenomeByNameData
2323    
2324        my @genomes = $sprout->GetGenomeByNameData($genus, $species, $strain);
2325    
2326    Return a list of the IDs of the genomes with the specified genus,
2327    species, and strain. In almost every case, there will be either zero or
2328    one IDs returned; however, two or more IDs could be returned if there are
2329    multiple versions of the genome in the database.
2330    
2331    =over 4
2332    
2333    =item genus
2334    
2335    Genus of the desired genome.
2336    
2337    =item species
2338    
2339    Species of the desired genome.
2340    
2341    =item strain
2342    
2343    Strain (unique characterization) of the desired genome. This may be an empty
2344    string, in which case it is presumed that the desired genome has no strain
2345    specified.
2346    
2347    =item RETURN
2348    
2349    Returns a list of the IDs of the genomes having the specified genus, species, and
2350    strain.
2351    
2352    =back
2353    
2354    =cut
2355    
2356    sub GetGenomeByNameData {
2357        # Get the parameters.
2358        my ($self, $genus, $species, $strain) = @_;
2359        # Try to find the genomes.
2360        my @retVal = $self->GetFlat(['Genome'], "Genome(genus) = ? AND Genome(species) = ? AND Genome(unique-characterization) = ?",
2361                                    [$genus, $species, $strain], 'Genome(id)');
2362        # Return the result.
2363        return @retVal;
2364    }
2365    
2366  =head3 Insert  =head3 Insert
2367    
2368  C<< $sprout->Insert($objectType, \%fieldHash); >>      $sprout->Insert($objectType, \%fieldHash);
2369    
2370  Insert an entity or relationship instance into the database. The entity or relationship of interest  Insert an entity or relationship instance into the database. The entity or relationship of interest
2371  is defined by a type name and then a hash of field names to values. Field values in the primary  is defined by a type name and then a hash of field names to values. Field values in the primary
# Line 2050  Line 2374 
2374  list references. For example, the following line inserts an inactive PEG feature named  list references. For example, the following line inserts an inactive PEG feature named
2375  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.  C<fig|188.1.peg.1> with aliases C<ZP_00210270.1> and C<gi|46206278>.
2376    
2377  C<< $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>      $sprout->Insert('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']});
2378    
2379  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
2380  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
2381    
2382  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>      $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'});
2383    
2384  =over 4  =over 4
2385    
# Line 2080  Line 2404 
2404    
2405  =head3 Annotate  =head3 Annotate
2406    
2407  C<< my $ok = $sprout->Annotate($fid, $timestamp, $user, $text); >>      my $ok = $sprout->Annotate($fid, $timestamp, $user, $text);
2408    
2409  Annotate a feature. This inserts an Annotation record into the database and links it to the  Annotate a feature. This inserts an Annotation record into the database and links it to the
2410  specified feature and user.  specified feature and user.
# Line 2134  Line 2458 
2458    
2459  =head3 AssignFunction  =head3 AssignFunction
2460    
2461  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>      my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser);
2462    
2463  This method assigns a function to a feature. Functions are a special type of annotation. The general  This method assigns a function to a feature. Functions are a special type of annotation. The general
2464  format is described in L</ParseAssignment>.  format is described in L</ParseAssignment>.
# Line 2194  Line 2518 
2518    
2519  =head3 FeaturesByAlias  =head3 FeaturesByAlias
2520    
2521  C<< my @features = $sprout->FeaturesByAlias($alias); >>      my @features = $sprout->FeaturesByAlias($alias);
2522    
2523  Returns a list of features with the specified alias. The alias is parsed to determine  Returns a list of features with the specified alias. The alias is parsed to determine
2524  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6  the type of the alias. A string of digits is a GenBack ID and a string of exactly 6
# Line 2236  Line 2560 
2560    
2561  =head3 FeatureTranslation  =head3 FeatureTranslation
2562    
2563  C<< my $translation = $sprout->FeatureTranslation($featureID); >>      my $translation = $sprout->FeatureTranslation($featureID);
2564    
2565  Return the translation of a feature.  Return the translation of a feature.
2566    
# Line 2264  Line 2588 
2588    
2589  =head3 Taxonomy  =head3 Taxonomy
2590    
2591  C<< my @taxonomyList = $sprout->Taxonomy($genome); >>      my @taxonomyList = $sprout->Taxonomy($genome);
2592    
2593  Return the taxonomy of the specified genome. This will be in the form of a list  Return the taxonomy of the specified genome. This will be in the form of a list
2594  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,  containing the various classifications in order from domain (eg. C<Bacteria>, C<Archaea>,
2595  or C<Eukaryote>) to sub-species. For example,  or C<Eukaryote>) to sub-species. For example,
2596    
2597  C<< (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12) >>      (Bacteria, Proteobacteria, Gammaproteobacteria, Enterobacteriales, Enterobacteriaceae, Escherichia, Escherichia coli, Escherichia coli K12)
2598    
2599  =over 4  =over 4
2600    
# Line 2305  Line 2629 
2629    
2630  =head3 CrudeDistance  =head3 CrudeDistance
2631    
2632  C<< my $distance = $sprout->CrudeDistance($genome1, $genome2); >>      my $distance = $sprout->CrudeDistance($genome1, $genome2);
2633    
2634  Returns a crude estimate of the distance between two genomes. The distance is construed so  Returns a crude estimate of the distance between two genomes. The distance is construed so
2635  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.  that it will be 0 for genomes with identical taxonomies and 1 for genomes from different domains.
# Line 2357  Line 2681 
2681    
2682  =head3 RoleName  =head3 RoleName
2683    
2684  C<< my $roleName = $sprout->RoleName($roleID); >>      my $roleName = $sprout->RoleName($roleID);
2685    
2686  Return the descriptive name of the role with the specified ID. In general, a role  Return the descriptive name of the role with the specified ID. In general, a role
2687  will only have a descriptive name if it is coded as an EC number.  will only have a descriptive name if it is coded as an EC number.
# Line 2391  Line 2715 
2715    
2716  =head3 RoleDiagrams  =head3 RoleDiagrams
2717    
2718  C<< my @diagrams = $sprout->RoleDiagrams($roleID); >>      my @diagrams = $sprout->RoleDiagrams($roleID);
2719    
2720  Return a list of the diagrams containing a specified functional role.  Return a list of the diagrams containing a specified functional role.
2721    
# Line 2421  Line 2745 
2745    
2746  =head3 GetProperties  =head3 GetProperties
2747    
2748  C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>      my @list = $sprout->GetProperties($fid, $key, $value, $url);
2749    
2750  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2751    
# Line 2507  Line 2831 
2831    
2832  =head3 FeatureProperties  =head3 FeatureProperties
2833    
2834  C<< my @properties = $sprout->FeatureProperties($featureID); >>      my @properties = $sprout->FeatureProperties($featureID);
2835    
2836  Return a list of the properties for the specified feature. Properties are key-value pairs  Return a list of the properties for the specified feature. Properties are key-value pairs
2837  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
# Line 2546  Line 2870 
2870    
2871  =head3 DiagramName  =head3 DiagramName
2872    
2873  C<< my $diagramName = $sprout->DiagramName($diagramID); >>      my $diagramName = $sprout->DiagramName($diagramID);
2874    
2875  Return the descriptive name of a diagram.  Return the descriptive name of a diagram.
2876    
# Line 2574  Line 2898 
2898    
2899  =head3 PropertyID  =head3 PropertyID
2900    
2901  C<< my $id = $sprout->PropertyID($propName, $propValue); >>      my $id = $sprout->PropertyID($propName, $propValue);
2902    
2903  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
2904  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 2935 
2935    
2936  =head3 MergedAnnotations  =head3 MergedAnnotations
2937    
2938  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>      my @annotationList = $sprout->MergedAnnotations(\@list);
2939    
2940  Returns a merged list of the annotations for the features in a list. Each annotation is  Returns a merged list of the annotations for the features in a list. Each annotation is
2941  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where  represented by a 4-tuple of the form C<($fid, $timestamp, $userID, $annotation)>, where
# Line 2660  Line 2984 
2984    
2985  =head3 RoleNeighbors  =head3 RoleNeighbors
2986    
2987  C<< my @roleList = $sprout->RoleNeighbors($roleID); >>      my @roleList = $sprout->RoleNeighbors($roleID);
2988    
2989  Returns a list of the roles that occur in the same diagram as the specified role. Because  Returns a list of the roles that occur in the same diagram as the specified role. Because
2990  diagrams and roles are in a many-to-many relationship with each other, the list is  diagrams and roles are in a many-to-many relationship with each other, the list is
# Line 2703  Line 3027 
3027    
3028  =head3 FeatureLinks  =head3 FeatureLinks
3029    
3030  C<< my @links = $sprout->FeatureLinks($featureID); >>      my @links = $sprout->FeatureLinks($featureID);
3031    
3032  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are  Return a list of the web hyperlinks associated with a feature. The web hyperlinks are
3033  to external websites describing either the feature itself or the organism containing it  to external websites describing either the feature itself or the organism containing it
# Line 2734  Line 3058 
3058    
3059  =head3 SubsystemsOf  =head3 SubsystemsOf
3060    
3061  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>      my %subsystems = $sprout->SubsystemsOf($featureID);
3062    
3063  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped
3064  to the roles the feature performs.  to the roles the feature performs.
# Line 2782  Line 3106 
3106    
3107  =head3 SubsystemList  =head3 SubsystemList
3108    
3109  C<< my @subsystems = $sprout->SubsystemList($featureID); >>      my @subsystems = $sprout->SubsystemList($featureID);
3110    
3111  Return a list containing the names of the subsystems in which the specified  Return a list containing the names of the subsystems in which the specified
3112  feature participates. Unlike L</SubsystemsOf>, this method only returns the  feature participates. Unlike L</SubsystemsOf>, this method only returns the
# Line 2814  Line 3138 
3138    
3139  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
3140    
3141  C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>      my %featureData = $sprout->GenomeSubsystemData($genomeID);
3142    
3143  Return a hash mapping genome features to their subsystem roles.  Return a hash mapping genome features to their subsystem roles.
3144    
# Line 2874  Line 3198 
3198    
3199  =head3 RelatedFeatures  =head3 RelatedFeatures
3200    
3201  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>      my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID);
3202    
3203  Return a list of the features which are bi-directional best hits of the specified feature and  Return a list of the features which are bi-directional best hits of the specified feature and
3204  have been assigned the specified function by the specified user. If no such features exists,  have been assigned the specified function by the specified user. If no such features exists,
# Line 2925  Line 3249 
3249    
3250  =head3 TaxonomySort  =head3 TaxonomySort
3251    
3252  C<< my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs); >>      my @sortedFeatureIDs = $sprout->TaxonomySort(\@featureIDs);
3253    
3254  Return a list formed by sorting the specified features by the taxonomy of the containing  Return a list formed by sorting the specified features by the taxonomy of the containing
3255  genome. This will cause genomes from similar organisms to float close to each other.  genome. This will cause genomes from similar organisms to float close to each other.
# Line 2960  Line 3284 
3284          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",          my ($taxonomy) = $self->GetFlat(['IsLocatedIn', 'HasContig', 'Genome'], "IsLocatedIn(from-link) = ?",
3285                                          [$fid], 'Genome(taxonomy)');                                          [$fid], 'Genome(taxonomy)');
3286          # Add this feature to the hash buffer.          # Add this feature to the hash buffer.
3287          Tracer::AddToListMap(\%hashBuffer, $taxonomy, $fid);          push @{$hashBuffer{$taxonomy}}, $fid;
3288      }      }
3289      # Sort the keys and get the elements.      # Sort the keys and get the elements.
3290      my @retVal = ();      my @retVal = ();
# Line 2973  Line 3297 
3297    
3298  =head3 Protein  =head3 Protein
3299    
3300  C<< my $protein = Sprout::Protein($sequence, $table); >>      my $protein = Sprout::Protein($sequence, $table);
3301    
3302  Translate a DNA sequence into a protein sequence.  Translate a DNA sequence into a protein sequence.
3303    
# Line 3059  Line 3383 
3383    
3384  =head3 LoadInfo  =head3 LoadInfo
3385    
3386  C<< my ($dirName, @relNames) = $sprout->LoadInfo(); >>      my ($dirName, @relNames) = $sprout->LoadInfo();
3387    
3388  Return the name of the directory from which data is to be loaded and a list of the relation  Return the name of the directory from which data is to be loaded and a list of the relation
3389  names. This information is useful when trying to analyze what needs to be put where in order  names. This information is useful when trying to analyze what needs to be put where in order
# Line 3080  Line 3404 
3404    
3405  =head3 BBHMatrix  =head3 BBHMatrix
3406    
3407  C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>      my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3408    
3409  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
3410  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 3134  Line 3458 
3458    
3459  =head3 SimMatrix  =head3 SimMatrix
3460    
3461  C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>      my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets);
3462    
3463  Find all the similarities for the features of a genome in a  Find all the similarities for the features of a genome in a
3464  specified list of target genomes. The return value will be a hash mapping  specified list of target genomes. The return value will be a hash mapping
# Line 3204  Line 3528 
3528    
3529  =head3 LowBBHs  =head3 LowBBHs
3530    
3531  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>      my %bbhMap = $sprout->LowBBHs($featureID, $cutoff);
3532    
3533  Return the bidirectional best hits of a feature whose score is no greater than a  Return the bidirectional best hits of a feature whose score is no greater than a
3534  specified cutoff value. A higher cutoff value will allow inclusion of hits with  specified cutoff value. A higher cutoff value will allow inclusion of hits with
# Line 3248  Line 3572 
3572    
3573  =head3 Sims  =head3 Sims
3574    
3575  C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >>      my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters);
3576    
3577  Get a list of similarities for a specified feature. Similarity information is not kept in the  Get a list of similarities for a specified feature. Similarity information is not kept in the
3578  Sprout database; rather, they are retrieved from a network server. The similarities are  Sprout database; rather, they are retrieved from a network server. The similarities are
# Line 3314  Line 3638 
3638    
3639  =head3 IsAllGenomes  =head3 IsAllGenomes
3640    
3641  C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>      my $flag = $sprout->IsAllGenomes(\@list, \@checkList);
3642    
3643  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
3644  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 3687 
3687    
3688  =head3 GetGroups  =head3 GetGroups
3689    
3690  C<< my %groups = $sprout->GetGroups(\@groupList); >>      my %groups = $sprout->GetGroups(\@groupList);
3691    
3692  Return a hash mapping each group to the IDs of the genomes in the group.  Return a hash mapping each group to the IDs of the genomes in the group.
3693  A list of groups may be specified, in which case only those groups will be  A list of groups may be specified, in which case only those groups will be
# Line 3395  Line 3719 
3719                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3720          # Loop through the genomes found.          # Loop through the genomes found.
3721          for my $genome (@genomes) {          for my $genome (@genomes) {
3722              # Pop this genome's ID off the current list.              # Get the genome ID and group, and add this genome to the group's list.
3723              my @groups = @{$genome};              my ($genomeID, $group) = @{$genome};
3724              my $genomeID = shift @groups;              push @{$retVal{$group}}, $genomeID;
             # Loop through the groups, adding the genome ID to each group's  
             # list.  
             for my $group (@groups) {  
                 Tracer::AddToListMap(\%retVal, $group, $genomeID);  
             }  
3725          }          }
3726      }      }
3727      # Return the hash we just built.      # Return the hash we just built.
# Line 3411  Line 3730 
3730    
3731  =head3 MyGenomes  =head3 MyGenomes
3732    
3733  C<< my @genomes = Sprout::MyGenomes($dataDir); >>      my @genomes = Sprout::MyGenomes($dataDir);
3734    
3735  Return a list of the genomes to be included in the Sprout.  Return a list of the genomes to be included in the Sprout.
3736    
# Line 3443  Line 3762 
3762    
3763  =head3 LoadFileName  =head3 LoadFileName
3764    
3765  C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>      my $fileName = Sprout::LoadFileName($dataDir, $tableName);
3766    
3767  Return the name of the load file for the specified table in the specified data  Return the name of the load file for the specified table in the specified data
3768  directory.  directory.
# Line 3484  Line 3803 
3803    
3804  =head3 DeleteGenome  =head3 DeleteGenome
3805    
3806  C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>      my $stats = $sprout->DeleteGenome($genomeID, $testFlag);
3807    
3808  Delete a genome from the database.  Delete a genome from the database.
3809    
# Line 3520  Line 3839 
3839    
3840  =head3 Fix  =head3 Fix
3841    
3842  C<< my %fixedHash = Sprout::Fix(%groupHash); >>      my %fixedHash = $sprout->Fix(%groupHash);
3843    
3844  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.
3845  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.  
3846    
3847  =over 4  =over 4
3848    
# Line 3542  Line 3860 
3860    
3861  sub Fix {  sub Fix {
3862      # Get the parameters.      # Get the parameters.
3863      my (%groupHash) = @_;      my ($self, %groupHash) = @_;
3864      # Create the result hash.      # Create the result hash.
3865      my %retVal = ();      my %retVal = ();
3866      # Copy over the genomes.      # Copy over the genomes.
3867      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3868          # Make a safety copy of the group ID.          # Get the super-group name.
3869          my $realGroupID = $groupID;          my $realGroupID = $self->SuperGroup($groupID);
3870          # Yank the primary name.          # Append this group's genomes into the result hash
3871          if ($groupID =~ /([A-Z]\w+)/) {          # using the super-group name.
3872              $realGroupID = $1;          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
         }  
         # Append this group's genomes into the result hash.  
         Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});  
3873      }      }
3874      # Return the result hash.      # Return the result hash.
3875      return %retVal;      return %retVal;
# Line 3562  Line 3877 
3877    
3878  =head3 GroupPageName  =head3 GroupPageName
3879    
3880  C<< my $name = $sprout->GroupPageName($group); >>      my $name = $sprout->GroupPageName($group);
3881    
3882  Return the name of the page for the specified NMPDR group.  Return the name of the page for the specified NMPDR group.
3883    
# Line 3584  Line 3899 
3899  sub GroupPageName {  sub GroupPageName {
3900      # Get the parameters.      # Get the parameters.
3901      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3902      # Check for the group file data.      # Check for the group file data.
3903      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;  
     }  
3904      # Compute the real group name.      # Compute the real group name.
3905      my $realGroup = $group;      my $realGroup = $self->SuperGroup($group);
3906      if ($group =~ /([A-Z]\w+)/) {      # Get the associated page name.
3907          $realGroup = $1;      my $retVal = "../content/$superTable{$realGroup}->{page}";
     }  
     # Return the page name.  
     $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];  
3908      # Return the result.      # Return the result.
3909      return $retVal;      return $retVal;
3910  }  }
3911    
 =head3 ReadGroupFile  
   
 C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  
   
 Read in the data from the specified group file. The group file contains information  
 about each of the NMPDR groups.  
   
 =over 4  
   
 =item name  
   
 Name of the group.  
3912    
3913  =item page  =head3 AddProperty
   
 Name of the group's page on the web site (e.g. C<campy.php> for  
 Campylobacter)  
   
 =item genus  
3914    
3915  Genus of the group      $sprout->AddProperty($featureID, $key, @values);
3916    
3917  =item species  Add a new attribute value (Property) to a feature.
   
 Species of the group, or an empty string if the group is for an entire  
 genus. If the group contains more than one species, the species names  
 should be separated by commas.  
3918    
3919  =back  =over 4
3920    
3921  The parameters to this method are as follows  =item peg
3922    
3923  =over 4  ID of the feature to which the attribute is to be added.
3924    
3925  =item groupFile  =item key
3926    
3927  Name of the file containing the group data.  Name of the attribute (key).
3928    
3929  =item RETURN  =item values
3930    
3931  Returns a hash keyed on group name. The value of each hash  Values of the attribute.
3932    
3933  =back  =back
3934    
3935  =cut  =cut
3936    #: Return Type ;
3937  sub ReadGroupFile {  sub AddProperty {
3938      # Get the parameters.      # Get the parameters.
3939      my ($groupFileName) = @_;      my ($self, $featureID, $key, @values) = @_;
3940      # Declare the return variable.      # Add the property using the attached attributes object.
3941      my %retVal;      $self->{_ca}->AddAttribute($featureID, $key, @values);
     # Read the group file.  
     my @groupLines = Tracer::GetFile($groupFileName);  
     for my $groupLine (@groupLines) {  
         my ($name, $page, $genus, $species) = split(/\t/, $groupLine);  
         $retVal{$name} = [$page, $genus, $species];  
     }  
     # Return the result.  
     return %retVal;  
3942  }  }
3943    
3944  =head3 AddProperty  =head3 CheckGroupFile
3945    
3946  C<< my  = $sprout->AddProperty($featureID, $key, @values); >>      my %groupData = $sprout->CheckGroupFile();
   
 Add a new attribute value (Property) to a feature.  
3947    
3948  =over 4  Get the group file hash. The group file hash describes the relationship
3949    between a group and the super-group to which it belongs for purposes of
3950    display. The super-group name is computed from the first capitalized word
3951    in the actual group name. For each super-group, the group file contains
3952    the page name and a list of the species expected to be in the group.
3953    Each species is specified by a genus and a species name. A species name
3954    of C<0> implies an entire genus.
3955    
3956  =item peg  This method returns a hash from super-group names to a hash reference. Each
3957    resulting hash reference contains the following fields.
3958    
3959  ID of the feature to which the attribute is to be added.  =over 4
3960    
3961  =item key  =item page
3962    
3963  Name of the attribute (key).  The super-group's web page in the NMPDR.
3964    
3965  =item values  =item contents
3966    
3967  Values of the attribute.  A list of 2-tuples, each containing a genus name followed by a species name
3968    (or 0, indicating all species). This list indicates which organisms belong
3969    in the super-group.
3970    
3971  =back  =back
3972    
3973  =cut  =cut
3974  #: Return Type ;  
3975  sub AddProperty {  sub CheckGroupFile {
3976      # Get the parameters.      # Get the parameters.
3977      my ($self, $featureID, $key, @values) = @_;      my ($self) = @_;
3978      # Add the property using the attached attributes object.      # Check to see if we already have this hash.
3979      $self->{_ca}->AddAttribute($featureID, $key, @values);      if (! defined $self->{groupHash}) {
3980            # We don't, so we need to read it in.
3981            my %groupHash;
3982            # Read the group file.
3983            my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
3984            # Loop through the list of sort-of groups.
3985            for my $groupLine (@groupLines) {
3986                my ($name, $page, @contents) = split /\t/, $groupLine;
3987                $groupHash{$name} = { page => $page,
3988                                      contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
3989                                    };
3990            }
3991            # Save the hash.
3992            $self->{groupHash} = \%groupHash;
3993        }
3994        # Return the result.
3995        return %{$self->{groupHash}};
3996  }  }
3997    
3998  =head2 Virtual Methods  =head2 Virtual Methods
3999    
4000  =head3 CleanKeywords  =head3 CleanKeywords
4001    
4002  C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>      my $cleanedString = $sprout->CleanKeywords($searchExpression);
4003    
4004  Clean up a search expression or keyword list. This involves converting the periods  Clean up a search expression or keyword list. This involves converting the periods
4005  in EC numbers to underscores, converting non-leading minus signs to underscores,  in EC numbers to underscores, converting non-leading minus signs to underscores,
# Line 3750  Line 4049 
4049    
4050  A functional assignment is always of the form  A functional assignment is always of the form
4051    
4052      C<set >I<YYYY>C< function to\n>I<ZZZZZ>      set YYYY function to
4053        ZZZZ
4054    
4055  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
4056  the user and the assigning user (from MadeAnnotation) will be the same, but that is  the user and the assigning user (from MadeAnnotation) will be the same, but that is
# Line 3805  Line 4105 
4105    
4106  =head3 _CheckFeature  =head3 _CheckFeature
4107    
4108  C<< my $flag = $sprout->_CheckFeature($fid); >>      my $flag = $sprout->_CheckFeature($fid);
4109    
4110  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.
4111    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3