[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.109, Sun Mar 23 16:32:05 2008 UTC revision 1.128, Tue Jun 30 19:53:01 2009 UTC
# Line 4  Line 4 
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 14  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17      use CGI;      use CGI qw(-nosticky);
18        use WikiTools;
19        use BioWords;
20      use base qw(ERDB);      use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 39  Line 41 
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      my $sprout = Sprout->new($dbName, \%options);      my $sprout = Sprout->new(%parms)
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 incoming parameter hash has the following permissible
52  database.  members (others will be ignored without error.
53    
54  =over 4  =over 4
55    
56    =item DBD
57    
58    Name of the XML file containing the database definition (default C<SproutDBD.xml> in
59    the DBD directory).
60    
61  =item dbName  =item dbName
62    
63  Name of the database.  Name of the database. If omitted, the default Sprout database name is used.
64    
65  =item options  =item options
66    
67  Table of options.  Sub-hash of special options.
68    
69  * B<dbType> type of database (currently C<mysql> for MySQL and C<pg> for PostgreSQL) (default C<mysql>)  * B<dbType> type of database (currently C<mysql> for MySQL and C<pg> for PostgreSQL) (default C<mysql>)
70    
71  * B<dataDir> directory containing the database definition file and the flat files used to load the data (default C<Data>)  * B<dataDir> directory containing the database definition file and the flat files used to load the data (default C<Data>)
72    
 * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)  
   
73  * B<userData> user name and password, delimited by a slash (default same as SEED)  * B<userData> user name and password, delimited by a slash (default same as SEED)
74    
75  * B<port> connection port (default C<0>)  * B<port> connection port (default C<0>)
# Line 87  Line 90 
90  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
91  F</usr/fig/SproutData>.  F</usr/fig/SproutData>.
92    
93      my $sprout = Sprout->new('Sprout', { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });      my $sprout = Sprout->new(dbName => 'Sprout', options => { userData => 'fig/admin', dataDir => '/usr/fig/SproutData' });
94    
95    The odd constructor signature is a result of Sprout's status as the first ERDB database,
96    and the need to make it compatible with the needs of its younger siblings.
97    
98  =cut  =cut
99    
100  sub new {  sub new {
101      # Get the parameters.      # Get the parameters.
102      my ($class, $dbName, $options) = @_;      my ($class, %parms) = @_;
103        # Look for an options hash.
104        my $options = $parms{options} || {};
105        # Plug in the DBD and name parameters.
106        if ($parms{DBD}) {
107            $options->{xmlFileName} = $parms{DBD};
108        }
109        my $dbName = $parms{dbName} || $FIG_Config::sproutDB;
110      # Compute the DBD directory.      # Compute the DBD directory.
111      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
112                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 106  Line 119 
119                                                          # data file directory                                                          # data file directory
120                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
121                                                          # database definition file name                                                          # database definition file name
122                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
123                                                          # user name and password                                                          # user name and password
124                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
125                                                          # database connection port                                                          # database connection port
126                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
127                         host         => $FIG_Config::sprout_host,                         host         => $FIG_Config::sprout_host,
128                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
129                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
130                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
131                           demandDriven => 0,               # 1 for forward-only queries
132                        }, $options);                        }, $options);
133      # Get the data directory.      # Get the data directory.
134      my $dataDir = $optionTable->{dataDir};      my $dataDir = $optionTable->{dataDir};
# Line 130  Line 144 
144      }      }
145      # Create the ERDB object.      # Create the ERDB object.
146      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
147      my $retVal = ERDB::new($class, $dbh, $xmlFileName);      my $retVal = ERDB::new($class, $dbh, $xmlFileName, %$optionTable);
148      # Add the option table and XML file name.      # Add the option table and XML file name.
149      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
150      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
151      # Set up space for the group file data.      # Set up space for the group file data.
152      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
153      # 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
154      $retVal->{genomeHash} = undef;      # and remember genome data.
155      # Connect to the attributes.      $retVal->{genomeHash} = {};
156        $retVal->{genomeHashFilled} = 0;
157        # Remember the data directory name.
158        $retVal->{dataDir} = $dataDir;
159        # Return it.
160        return $retVal;
161    }
162    
163    =head3 ca
164    
165        my $ca = $sprout->ca():;
166    
167    Return the [[CustomAttributesPm]] object for retrieving object
168    properties.
169    
170    =cut
171    
172    sub ca {
173        # Get the parameters.
174        my ($self) = @_;
175        # Do we already have an attribute object?
176        my $retVal = $self->{_ca};
177        if (! defined $retVal) {
178            # No, create one. How we do it depends on the configuration.
179      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
180          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
181          $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);              $retVal = RemoteCustomAttributes->new($FIG_Config::attrURL);
182      } elsif ($FIG_Config::attrDbName) {      } elsif ($FIG_Config::attrDbName) {
183          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);          Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
184          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
185          $retVal->{_ca} = CustomAttributes->new(user => $user);              $retVal = CustomAttributes->new(user => $user);
186      }      }
187      # Return it.          # Save it for next time.
188            $self->{_ca} = $retVal;
189        }
190        # Return the result.
191      return $retVal;      return $retVal;
192  }  }
193    
# Line 254  Line 294 
294                  $retVal = $superGroup;                  $retVal = $superGroup;
295              }              }
296          }          }
         # Make sure we found something.  
         if (! $retVal) {  
             Confess("No super-group found for \"$groupName\".");  
         }  
297      }      }
298      # Return the result.      # Return the result.
299      return $retVal;      return $retVal;
# Line 309  Line 345 
345  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
346  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
347  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
348  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.
349    
350  =over 4  =over 4
351    
# Line 498  Line 534 
534  =item filter  =item filter
535    
536  If specified, a filter for the list of genomes to display. The filter should be in the form of a  If specified, a filter for the list of genomes to display. The filter should be in the form of a
537  list reference. The first element of the list should be the filter string, and the remaining elements  list reference, a string, or a hash reference. If it is a list reference, the first element
538  the filter parameters.  of the list should be the filter string, and the remaining elements the filter parameters. If it is a
539    string, it will be split into a list at each included tab. If it is a hash reference, it should be
540    a hash that maps genomes which should be included to a TRUE value.
541    
542  =item multiSelect  =item multiSelect
543    
# Line 519  Line 557 
557  A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The  A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
558  default is none.  default is none.
559    
560  =item inTable  =item class
561    
562  If TRUE, then backslashes will be included at the end of each line in the resulting HTML. This enables the control  If specified, a style class to assign to the genome control.
 to be used in TWiki tables.  
563    
564  =back  =back
565    
# Line 532  Line 569 
569      # Get the parameters.      # Get the parameters.
570      my ($self, %options) = @_;      my ($self, %options) = @_;
571      # Get the control's name and ID.      # Get the control's name and ID.
572      my $menuName = $options{name} || 'myGenomeControl';      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
573      my $menuID = $options{id} || $menuName;      my $menuID = $options{id} || $menuName;
574        Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
575      # Compute the IDs for the status display.      # Compute the IDs for the status display.
576      my $divID = "${menuID}_status";      my $divID = "${menuID}_status";
577      my $urlID = "${menuID}_url";      my $urlID = "${menuID}_url";
578      # Compute the code to show selected genomes in the status area.      # Compute the code to show selected genomes in the status area.
579      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', $FIG_Config::genome_control_cap)";
580      # Check for single-select or multi-select.      # Check for single-select or multi-select.
581      my $multiSelect = $options{multiSelect} || 0;      my $multiSelect = $options{multiSelect} || 0;
582        # Get the style data.
583        my $class = $options{class} || '';
584      # Get the list of pre-selected items.      # Get the list of pre-selected items.
585      my $selections = $options{selected} || [];      my $selections = $options{selected} || [];
586      if (ref $selections ne 'ARRAY') {      if (ref $selections ne 'ARRAY') {
587          $selections = [ split /\s*,\s*/, $selections ];          $selections = [ split /\s*,\s*/, $selections ];
588      }      }
589      my %selected = map { $_ => } @{$selections};      my %selected = map { $_ => 1 } @{$selections};
590      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
591      # string or a list reference.      # string, a hash reference, or a list reference.
592        my ($filterHash, $filterString);
593      my $filterParms = $options{filter} || "";      my $filterParms = $options{filter} || "";
594        if (ref $filterParms eq 'HASH') {
595            $filterHash = $filterParms;
596            $filterParms = [];
597            $filterString = "";
598        } else {
599      if (! ref $filterParms) {      if (! ref $filterParms) {
600          $filterParms = [split /\t|\\t/, $filterParms];          $filterParms = [split /\t|\\t/, $filterParms];
601      }      }
602      my $filterString = shift @{$filterParms};          $filterString = shift @{$filterParms};
603        }
604        # Check for possible subsystem filtering. If there is one, we will tack the
605        # relationship onto the object name list.
606        my @objectNames = qw(Genome);
607        if ($filterString =~ /ParticipatesIn\(/) {
608            push @objectNames, 'ParticipatesIn';
609        }
610      # Get a list of all the genomes in group order. In fact, we only need them ordered      # Get a list of all the genomes in group order. In fact, we only need them ordered
611      # by name (genus,species,strain), but putting primary-group in front enables us to      # by name (genus,species,strain), but putting primary-group in front enables us to
612      # take advantage of an existing index.      # take advantage of an existing index.
613      my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",      my @genomeList = $self->GetAll(\@objectNames, "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
614                                     $filterParms,                                     $filterParms,
615                                     [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);                                     [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
616        # Apply the hash filter (if any).
617        if (defined $filterHash) {
618            @genomeList = grep { $filterHash->{$_->[1]} } @genomeList;
619        }
620      # Create a hash to organize the genomes by group. Each group will contain a list of      # Create a hash to organize the genomes by group. Each group will contain a list of
621      # 2-tuples, the first element being the genome ID and the second being the genome      # 2-tuples, the first element being the genome ID and the second being the genome
622      # name.      # name.
# Line 589  Line 646 
646      my @groups = map { $sortGroups{$_} } sort keys %sortGroups;      my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
647      # Remember the number of NMPDR groups.      # Remember the number of NMPDR groups.
648      my $nmpdrGroupCount = scalar @groups;      my $nmpdrGroupCount = scalar @groups;
649        # Are there any supporting genomes?
650        if (exists $gHash{$FIG_Config::otherGroup}) {
651      # Loop through the supporting genomes, classifying them by domain. We'll also keep a list      # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
652      # of the domains found.      # of the domains found.
653      my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};      my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
# Line 607  Line 666 
666      push @groups, sort @domains;      push @groups, sort @domains;
667      # Delete the supporting group.      # Delete the supporting group.
668      delete $gHash{$FIG_Config::otherGroup};      delete $gHash{$FIG_Config::otherGroup};
669        }
670      # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage      # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
671      # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes      # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
672      # and use that to make the selections.      # and use that to make the selections.
# Line 619  Line 679 
679      my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );      my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
680      # Set up the multiple-select flag.      # Set up the multiple-select flag.
681      my $multipleTag = ($multiSelect ? " multiple" : "" );      my $multipleTag = ($multiSelect ? " multiple" : "" );
682        # Set up the style class.
683        my $classTag = ($class ? " $class" : "" );
684      # Create the SELECT tag and stuff it into the output array.      # Create the SELECT tag and stuff it into the output array.
685      my @lines = ("<SELECT name=\"$menuID\" id=\"$menuID\" $onChangeTag$multipleTag size=\"$rows\" style=\"width: 100%\">");      my @lines = qq(<SELECT name="$menuName" id="$menuID" class="genomeSelect $class" $onChangeTag$multipleTag$classTag size="$rows">);
686      # Loop through the groups.      # Loop through the groups.
687      for my $group (@groups) {      for my $group (@groups) {
688          # Get the genomes in the group.          # Get the genomes in the group.
# Line 653  Line 715 
715          # displayed. For multiple-select mode, we include a button that selects the displayed          # displayed. For multiple-select mode, we include a button that selects the displayed
716          # genes. For single-select mode, we use a plain label instead.          # genes. For single-select mode, we use a plain label instead.
717          my $searchThingName = "${menuID}_SearchThing";          my $searchThingName = "${menuID}_SearchThing";
718          my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"          my $searchThingLabel = "Type to narrow selection";
719                                               : "Show genomes containing");          my $searchThingButton = "";
720            if ($multiSelect) {
721                $searchThingButton = qq(<INPUT type="button" name="MacroSearch" class="button" value="Go" onClick="selectShowing('$menuID', '$searchThingName'); $showSelect;" />);
722            }
723          push @lines, "<br />$searchThingLabel&nbsp;" .          push @lines, "<br />$searchThingLabel&nbsp;" .
724                       "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />";                       qq(<INPUT type="text" id="$searchThingName" name="$searchThingName" class="genomeSearchThing" onKeyup="showTyped('$menuID', '$searchThingName');" />) .
725                         $searchThingButton .
726                         Hint("GenomeControl", 28) . "<br />";
727          # For multi-select mode, we also have buttons to set and clear selections.          # For multi-select mode, we also have buttons to set and clear selections.
728          if ($multiSelect) {          if ($multiSelect) {
729              push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";              push @lines, qq(<INPUT type="button" name="ClearAll" class="bigButton genomeButton" value="Clear All" onClick="clearAll(getElementById('$menuID')); $showSelect" />);
730              push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";              push @lines, qq(<INPUT type="button" name="SelectAll" class="bigButton genomeButton" value="Select All" onClick="selectAll(getElementById('$menuID')); $showSelect" />);
731              push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";              push @lines, qq(<INPUT type="button" name="NMPDROnly" class="bigButton genomeButton" value="Select NMPDR" onClick="selectSome(getElementById('$menuID'), $nmpdrCount, true); $showSelect;" />);
732          }          }
733          # Add a hidden field we can use to generate organism page hyperlinks.          # Add a hidden field we can use to generate organism page hyperlinks.
734          push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/seedviewer.cgi?page=Organism;organism=\" />";          push @lines, qq(<INPUT type="hidden" id="$urlID" value="$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=" />);
735          # Add the status display. This tells the user what's selected no matter where the list is scrolled.          # Add the status display. This tells the user what's selected no matter where the list is scrolled.
736          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";          push @lines, qq(<DIV id="$divID" class="Panel"></DIV>);
737      }      }
738      # Assemble all the lines into a string. This is where we do the "inTable" thing to insure we don't mess up TWiki tables.      # Assemble all the lines into a string.
739      my $delim = ($options{inTable} ? "\\" : "" ) . "\n";      my $retVal = join("\n", @lines, "");
740      my $retVal = join($delim, @lines, "");      # Return the result.
741        return $retVal;
742    }
743    
744    =head3 Cleanup
745    
746        $sprout->Cleanup();
747    
748    Release the internal cache structures to free up memory.
749    
750    =cut
751    
752    sub Cleanup {
753        # Get the parameters.
754        my ($self) = @_;
755        # Delete the stemmer.
756        delete $self->{stemmer};
757        # Delete the attribute database.
758        delete $self->{_ca};
759        # Delete the group hash.
760        delete $self->{groupHash};
761        # Is there a FIG object?
762        if (defined $self->{fig}) {
763            # Yes, clear its subsystem cache.
764            $self->{fig}->clear_subsystem_cache();
765        }
766    }
767    
768    
769    =head3 Stem
770    
771        my $stem = $sprout->Stem($word);
772    
773    Return the stem of the specified word, or C<undef> if the word is not
774    stemmable. Note that even if the word is stemmable, the stem may be
775    the same as the original word.
776    
777    =over 4
778    
779    =item word
780    
781    Word to convert into a stem.
782    
783    =item RETURN
784    
785    Returns a stem of the word (which may be the word itself), or C<undef> if
786    the word is not stemmable.
787    
788    =back
789    
790    =cut
791    
792    sub Stem {
793        # Get the parameters.
794        my ($self, $word) = @_;
795        # Get the stemmer object.
796        my $stemmer = $self->{stemmer};
797        if (! defined $stemmer) {
798            # We don't have one pre-built, so we build and save it now.
799            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
800                                     stops => "$FIG_Config::sproutData/StopWords.txt",
801                                     cache => 0);
802            $self->{stemmer} = $stemmer;
803        }
804        # Try to stem the word.
805        my $retVal = $stemmer->Process($word);
806      # Return the result.      # Return the result.
807      return $retVal;      return $retVal;
808  }  }
# Line 734  Line 866 
866  sub GenusSpecies {  sub GenusSpecies {
867      # Get the parameters.      # Get the parameters.
868      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
869      # Get the data for the specified genome.      # Declare the return value.
870      my @values = $self->GetEntityValues('Genome', $genomeID, ['Genome(genus)', 'Genome(species)',      my $retVal;
871                                                                'Genome(unique-characterization)']);      # Get the genome data.
872      # Format the result and return it.      my $genomeData = $self->_GenomeData($genomeID);
873      my $retVal = join(' ', @values);      # Only proceed if we found the genome.
874        if (defined $genomeData) {
875            $retVal = $genomeData->PrimaryValue('Genome(scientific-name)');
876        }
877        # Return it.
878      return $retVal;      return $retVal;
879  }  }
880    
# Line 813  Line 949 
949  =item RETURN  =item RETURN
950    
951  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
952  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
953    wasn't found.
954    
955  =back  =back
956    
# Line 822  Line 959 
959  sub FeatureLocation {  sub FeatureLocation {
960      # Get the parameters.      # Get the parameters.
961      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
962        # Declare the return variable.
963        my @retVal = ();
964      # Get the feature record.      # Get the feature record.
965      my $object = $self->GetEntity('Feature', $featureID);      my $object = $self->GetEntity('Feature', $featureID);
966      Confess("Feature $featureID not found.") if ! defined($object);      # Only proceed if we found it.
967        if (defined $object) {
968      # Get the location string.      # Get the location string.
969      my $locString = $object->PrimaryValue('Feature(location-string)');      my $locString = $object->PrimaryValue('Feature(location-string)');
970      # Create the return list.      # Create the return list.
971      my @retVal = split /\s*,\s*/, $locString;          @retVal = split /\s*,\s*/, $locString;
972        }
973      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
974      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
975  }  }
# Line 878  Line 1019 
1019  }  }
1020    
1021    
   
1022  =head3 PointLocation  =head3 PointLocation
1023    
1024      my $found = Sprout::PointLocation($location, $point);      my $found = Sprout::PointLocation($location, $point);
# Line 1071  Line 1211 
1211      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
1212      # Declare the return variable.      # Declare the return variable.
1213      my $retVal = 0;      my $retVal = 0;
1214      # Get the genome's contig sequence lengths.      # Get the genome data.
1215      my @lens = $self->GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?',      my $genomeData = $self->_GenomeData($genomeID);
1216                         [$genomeID], 'IsMadeUpOf(len)');      # Only proceed if it exists.
1217      # Sum the lengths.      if (defined $genomeData) {
1218      map { $retVal += $_ } @lens;          $retVal = $genomeData->PrimaryValue('Genome(dna-size)');
1219        }
1220      # Return the result.      # Return the result.
1221      return $retVal;      return $retVal;
1222  }  }
# Line 1560  Line 1701 
1701  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
1702  is trusted.  is trusted.
1703    
1704  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.
1705  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.  
1706    
1707  =over 4  =over 4
1708    
# Line 1588  Line 1728 
1728      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1729      # Declare the return value.      # Declare the return value.
1730      my $retVal;      my $retVal;
1731      # Determine the ID type.      # Find a FIG ID for this feature.
1732      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1733        # Only proceed if we have an ID.
1734        if ($fid) {
1735          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1736          if (!$userID) {          if (!$userID) {
1737              # Use the primary assignment.              # Use the primary assignment.
1738              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1739          } else {          } else {
1740              # We must build the list of trusted users.              # We must build the list of trusted users.
1741              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1619  Line 1761 
1761              # 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.
1762              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1763                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1764                                     [$featureID]);                                     [$fid]);
1765              my $timeSelected = 0;              my $timeSelected = 0;
1766              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1767              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1639  Line 1781 
1781                  }                  }
1782              }              }
1783          }          }
     } 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)']);  
1784      }      }
1785      # Return the assignment found.      # Return the assignment found.
1786      return $retVal;      return $retVal;
# Line 1662  Line 1799 
1799  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
1800  most features only have a small number of annotations.  most features only have a small number of annotations.
1801    
 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.  
   
1802  =over 4  =over 4
1803    
1804  =item featureID  =item featureID
# Line 1686  Line 1819 
1819      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1820      # Declare the return value.      # Declare the return value.
1821      my @retVal = ();      my @retVal = ();
1822      # Determine the ID type.      # Convert to a FIG ID.
1823      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1824        # Only proceed if we found one.
1825        if ($fid) {
1826          # 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
1827          # users.          # users.
1828          my %trusteeTable = ();          my %trusteeTable = ();
1829          # 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.
1830          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1831                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1832                                 [$featureID]);                                 [$fid]);
1833          my $timeSelected = 0;          my $timeSelected = 0;
1834          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1835          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1709  Line 1844 
1844                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1845              }              }
1846          }          }
     } 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;  
1847      }      }
1848      # Return the assignments found.      # Return the assignments found.
1849      return @retVal;      return @retVal;
# Line 1755  Line 1883 
1883      # Loop through the incoming features.      # Loop through the incoming features.
1884      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1885          # Ask the server for the feature's best hit.          # Ask the server for the feature's best hit.
1886          my @bbhData = FIGRules::BBHData($featureID);          my $bbhData = FIGRules::BBHData($featureID);
1887          # Peel off the BBHs found.          # Peel off the BBHs found.
1888          my @found = ();          my @found = ();
1889          for my $bbh (@bbhData) {          for my $bbh (@$bbhData) {
1890              my $fid = $bbh->[0];              my $fid = $bbh->[0];
1891              my $bbGenome = $self->GenomeOf($fid);              my $bbGenome = $self->GenomeOf($fid);
1892              if ($bbGenome eq $genomeID) {              if ($bbGenome eq $genomeID) {
# Line 1797  Line 1925 
1925      # Get the parameters.      # Get the parameters.
1926      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1927      # Ask for the best hits.      # Ask for the best hits.
1928      my @lists = FIGRules::BBHData($featureID);      my $lists = FIGRules::BBHData($featureID);
1929      # Create the return value.      # Create the return value.
1930      my %retVal = ();      my %retVal = ();
1931      for my $tuple (@lists) {      for my $tuple (@$lists) {
1932          $retVal{$tuple->[0]} = $tuple->[1];          $retVal{$tuple->[0]} = $tuple->[1];
1933      }      }
1934      # Return the result.      # Return the result.
# Line 1834  Line 1962 
1962      # Declare the return variable.      # Declare the return variable.
1963      my $retVal;      my $retVal;
1964      # Get the genome's data.      # Get the genome's data.
1965      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->_GenomeData($genomeID);
1966      if ($genomeData) {      # Only proceed if it exists.
1967        if (defined $genomeData) {
1968          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1969          $retVal = $genomeData->PrimaryValue('Genome(complete)');          $retVal = $genomeData->PrimaryValue('Genome(complete)');
1970      }      }
# Line 1903  Line 2032 
2032      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
2033          $retVal = $1;          $retVal = $1;
2034      } else {      } else {
2035          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
2036            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
2037            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
2038                $retVal = $1;
2039            }
2040      }      }
2041      # Return the value found.      # Return the value found.
2042      return $retVal;      return $retVal;
# Line 1947  Line 2080 
2080              $retVal{$featureID2} = $score;              $retVal{$featureID2} = $score;
2081          }          }
2082      }      }
     # 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;  
     }  
2083      # Return the hash.      # Return the hash.
2084      return %retVal;      return %retVal;
2085  }  }
# Line 2308  Line 2436 
2436  sub GetGenomeNameData {  sub GetGenomeNameData {
2437      # Get the parameters.      # Get the parameters.
2438      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
2439        # Declare the return variables.
2440        my ($genus, $species, $strain);
2441        # Get the genome's data.
2442        my $genomeData = $self->_GenomeData($genomeID);
2443        # Only proceed if the genome exists.
2444        if (defined $genomeData) {
2445      # Get the desired values.      # Get the desired values.
2446      my ($genus, $species, $strain) = $self->GetEntityValues('Genome', $genomeID =>          ($genus, $species, $strain) = $genomeData->Values(['Genome(genus)',
2447                                                              [qw(Genome(genus) Genome(species) Genome(unique-characterization))]);                                                             'Genome(species)',
2448      # Throw an error if they were not found.                                                             'Genome(unique-characterization)']);
2449      if (! defined $genus) {      } else {
2450            # Throw an error because they were not found.
2451          Confess("Genome $genomeID not found in database.");          Confess("Genome $genomeID not found in database.");
2452      }      }
2453      # Return the results.      # Return the results.
# Line 2613  Line 2748 
2748  sub Taxonomy {  sub Taxonomy {
2749      # Get the parameters.      # Get the parameters.
2750      my ($self, $genome) = @_;      my ($self, $genome) = @_;
     # Find the specified genome's taxonomy string.  
     my ($list) = $self->GetEntityValues('Genome', $genome, ['Genome(taxonomy)']);  
2751      # Declare the return variable.      # Declare the return variable.
2752      my @retVal = ();      my @retVal = ();
2753      # If we found the genome, return its taxonomy string.      # Get the genome data.
2754      if ($list) {      my $genomeData = $self->_GenomeData($genome);
2755          @retVal = split /\s*;\s*/, $list;      # Only proceed if it exists.
2756        if (defined $genomeData) {
2757            # Create the taxonomy from the taxonomy string.
2758            @retVal = split /\s*;\s*/, $genomeData->PrimaryValue('Genome(taxonomy)');
2759      } else {      } else {
2760            # Genome doesn't exist, so emit a warning.
2761          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);
2762      }      }
2763      # Return the value found.      # Return the value found.
# Line 2665  Line 2802 
2802      }      }
2803      my @taxA = $self->Taxonomy($genomeA);      my @taxA = $self->Taxonomy($genomeA);
2804      my @taxB = $self->Taxonomy($genomeB);      my @taxB = $self->Taxonomy($genomeB);
2805      # Initialize the distance to 1. We'll reduce it each time we find a match between the      # Compute the distance.
2806      # 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;  
     }  
2807      return $retVal;      return $retVal;
2808  }  }
2809    
# Line 2743  Line 2871 
2871      return @retVal;      return @retVal;
2872  }  }
2873    
 =head3 GetProperties  
   
     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;  
 }  
   
2874  =head3 FeatureProperties  =head3 FeatureProperties
2875    
2876      my @properties = $sprout->FeatureProperties($featureID);      my @properties = $sprout->FeatureProperties($featureID);
# Line 2857  Line 2899 
2899      # Get the parameters.      # Get the parameters.
2900      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2901      # Get the properties.      # Get the properties.
2902      my @attributes = $self->{_ca}->GetAttributes($featureID);      my @attributes = $self->ca->GetAttributes($featureID);
2903      # Strip the feature ID off each tuple.      # Strip the feature ID off each tuple.
2904      my @retVal = ();      my @retVal = ();
2905      for my $attributeRow (@attributes) {      for my $attributeRow (@attributes) {
# Line 3129  Line 3171 
3171  sub SubsystemList {  sub SubsystemList {
3172      # Get the parameters.      # Get the parameters.
3173      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3174      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3175      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3176        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3177                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3178      # Return the result, sorted.      # Return the result, sorted.
3179      return sort @retVal;      return sort @retVal;
# Line 3163  Line 3206 
3206      # Declare the return variable.      # Declare the return variable.
3207      my %retVal = ();      my %retVal = ();
3208      # 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
3209      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3210      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3211                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3212                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3213      # 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
3214      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3215      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3216      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3217      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3218                                   "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.  
3219      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3220          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3221          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3222          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3223          my $subsys = $subHash{$cellID};          # Check the subsystem;
3224          if ($subsys) {          if ($subs{$subsys}) {
3225                Trace("Subsystem found.") if T(4);
3226              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3227              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3228              # Merge in this new data.              # Merge in this new data.
# Line 3231  Line 3268 
3268      # Get the parameters.      # Get the parameters.
3269      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3270      # 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.
3271      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);      my $bbhData = FIGRules::BBHData($featureID);
3272        my @bbhFeatures = map { $_->[0] } @$bbhData;
3273      # 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
3274      # functional assignment.      # functional assignment.
3275      my @retVal = ();      my @retVal = ();
# Line 3404  Line 3442 
3442    
3443  =head3 BBHMatrix  =head3 BBHMatrix
3444    
3445      my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);      my $bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets);
3446    
3447  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
3448  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 3428  Line 3466 
3466    
3467  =item RETURN  =item RETURN
3468    
3469  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
3470  BBH pegs in the target genomes to their scores.  to a sub-hash mapping its BBH pegs in the target genomes to their scores.
3471    
3472  =back  =back
3473    
# Line 3442  Line 3480 
3480      my %retVal = ();      my %retVal = ();
3481      # Ask for the BBHs.      # Ask for the BBHs.
3482      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);      my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3483        Trace("Retrieved " . scalar(@bbhList) . " BBH results.") if T(3);
3484      # 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.
3485      for my $bbhData (@bbhList) {      for my $bbhData (@bbhList) {
3486          my ($peg1, $peg2, $score) = @{$bbhData};          my ($peg1, $peg2, $score) = @{$bbhData};
# Line 3452  Line 3491 
3491          }          }
3492      }      }
3493      # Return the result.      # Return the result.
3494      return %retVal;      return \%retVal;
3495  }  }
3496    
3497    
# Line 3558  Line 3597 
3597      # Create the return hash.      # Create the return hash.
3598      my %retVal = ();      my %retVal = ();
3599      # Query for the desired BBHs.      # Query for the desired BBHs.
3600      my @bbhList = FIGRules::BBHData($featureID, $cutoff);      my $bbhList = FIGRules::BBHData($featureID, $cutoff);
3601      # Form the results into the return hash.      # Form the results into the return hash.
3602      for my $pair (@bbhList) {      for my $pair (@$bbhList) {
3603          my $fid = $pair->[0];          my $fid = $pair->[0];
3604          if ($self->Exists('Feature', $fid)) {          if ($self->Exists('Feature', $fid)) {
3605              $retVal{$fid} = $pair->[1];              $retVal{$fid} = $pair->[1];
# Line 3938  Line 3977 
3977      # Get the parameters.      # Get the parameters.
3978      my ($self, $featureID, $key, @values) = @_;      my ($self, $featureID, $key, @values) = @_;
3979      # Add the property using the attached attributes object.      # Add the property using the attached attributes object.
3980      $self->{_ca}->AddAttribute($featureID, $key, @values);      $self->ca->AddAttribute($featureID, $key, @values);
3981  }  }
3982    
3983  =head3 CheckGroupFile  =head3 CheckGroupFile
# Line 3958  Line 3997 
3997    
3998  =over 4  =over 4
3999    
4000  =item page  =item specials
4001    
4002  The super-group's web page in the NMPDR.  Reference to a hash whose keys are the names of special species.
4003    
4004  =item contents  =item contents
4005    
# Line 3983  Line 4022 
4022          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");          my @groupLines = Tracer::GetFile("$FIG_Config::sproutData/groups.tbl");
4023          # Loop through the list of sort-of groups.          # Loop through the list of sort-of groups.
4024          for my $groupLine (@groupLines) {          for my $groupLine (@groupLines) {
4025              my ($name, $page, @contents) = split /\t/, $groupLine;              my ($name, $specials, @contents) = split /\t/, $groupLine;
4026              $groupHash{$name} = { page => $page,              $groupHash{$name} = { specials => { map { $_ => 1 } split /\s*,\s*/, $specials },
4027                                    contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]                                    contents => [ map { [ split /\s*,\s*/, $_ ] } @contents ]
4028                                  };                                  };
4029          }          }
# Line 4025  Line 4064 
4064  sub CleanKeywords {  sub CleanKeywords {
4065      # Get the parameters.      # Get the parameters.
4066      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
4067      # Perform the standard cleanup.      # Get the stemmer.
4068      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $stemmer = $self->GetStemmer();
4069      # Fix the periods in EC and TC numbers.      # Convert the search expression using the stemmer.
4070      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
4071      # Fix non-trailing periods.      Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
     $retVal =~ s/\.(\w)/_$1/g;  
     # Fix non-leading minus signs.  
     $retVal =~ s/(\w)[\-]/$1_/g;  
     # Fix the vertical bars and colons  
     $retVal =~ s/(\w)[|:](\w)/$1'$2/g;  
4072      # Return the result.      # Return the result.
4073      return $retVal;      return $retVal;
4074  }  }
4075    
4076    =head3 GetSourceObject
4077    
4078        my $source = $erdb->GetSourceObject();
4079    
4080    Return the object to be used in creating load files for this database.
4081    
4082    =cut
4083    
4084    sub GetSourceObject {
4085        # Get the parameters.
4086        my ($self) = @_;
4087        # Do we already have one?
4088        my $retVal = $self->{fig};
4089        if (! defined $retVal) {
4090            # Create the object.
4091            require FIG;
4092            $retVal = FIG->new();
4093            Trace("FIG source object created for process $$.") if T(ERDBLoadGroup => 3);
4094            # Set up retries to prevent the lost-connection error when harvesting
4095            # the feature data.
4096            my $dbh = $retVal->db_handle();
4097            $dbh->set_retries(5);
4098            # Save it for other times.
4099            $self->{fig} = $retVal;
4100        }
4101        # Return the object.
4102        return $retVal;
4103    }
4104    
4105    =head3 SectionList
4106    
4107        my @sections = $erdb->SectionList($fig);
4108    
4109    Return a list of the names for the different data sections used when loading this database.
4110    The default is a single string, in which case there is only one section representing the
4111    entire database.
4112    
4113    =cut
4114    
4115    sub SectionList {
4116        # Get the parameters.
4117        my ($self, $source) = @_;
4118        # Ask the BaseSproutLoader for a section list.
4119        require BaseSproutLoader;
4120        my @retVal = BaseSproutLoader::GetSectionList($self, $source);
4121        # Return the list.
4122        return @retVal;
4123    }
4124    
4125    =head3 Loader
4126    
4127        my $groupLoader = $erdb->Loader($groupName, $options);
4128    
4129    Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4130    by L<ERDBGenerator.pl> to create the load group objects. If you are not using
4131    L<ERDBGenerator.pl>, you don't need to override this method.
4132    
4133    =over 4
4134    
4135    =item groupName
4136    
4137    Name of the load group whose object is to be returned. The group name is
4138    guaranteed to be a single word with only the first letter capitalized.
4139    
4140    =item options
4141    
4142    Reference to a hash of command-line options.
4143    
4144    =item RETURN
4145    
4146    Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4147    for this database.
4148    
4149    =back
4150    
4151    =cut
4152    
4153    sub Loader {
4154        # Get the parameters.
4155        my ($self, $groupName, $options) = @_;
4156        # Compute the loader name.
4157        my $loaderClass = "${groupName}SproutLoader";
4158        # Pull in its definition.
4159        require "$loaderClass.pm";
4160        # Create an object for it.
4161        my $retVal = eval("$loaderClass->new(\$self, \$options)");
4162        # Insure it worked.
4163        Confess("Could not create $loaderClass object: $@") if $@;
4164        # Return it to the caller.
4165        return $retVal;
4166    }
4167    
4168    
4169    =head3 LoadGroupList
4170    
4171        my @groups = $erdb->LoadGroupList();
4172    
4173    Returns a list of the names for this database's load groups. This method is used
4174    by L<ERDBGenerator.pl> when the user wishes to load all table groups. The default
4175    is a single group called 'All' that loads everything.
4176    
4177    =cut
4178    
4179    sub LoadGroupList {
4180        # Return the list.
4181        return qw(Feature Subsystem Genome Annotation Property Source Reaction Synonym Drug);
4182    }
4183    
4184    =head3 LoadDirectory
4185    
4186        my $dirName = $erdb->LoadDirectory();
4187    
4188    Return the name of the directory in which load files are kept. The default is
4189    the FIG temporary directory, which is a really bad choice, but it's always there.
4190    
4191    =cut
4192    
4193    sub LoadDirectory {
4194        # Get the parameters.
4195        my ($self) = @_;
4196        # Return the directory name.
4197        return $self->{dataDir};
4198    }
4199    
4200  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4201    
4202    =head3 GetStemmer
4203    
4204        my $stermmer = $sprout->GetStemmer();
4205    
4206    Return the stemmer object for this database.
4207    
4208    =cut
4209    
4210    sub GetStemmer {
4211        # Get the parameters.
4212        my ($self) = @_;
4213        # Declare the return variable.
4214        my $retVal = $self->{stemmer};
4215        if (! defined $retVal) {
4216            # We don't have one pre-built, so we build and save it now.
4217            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4218                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4219                                     cache => 0);
4220            $self->{stemmer} = $retVal;
4221        }
4222        # Return the result.
4223        return $retVal;
4224    }
4225    
4226  =head3 ParseAssignment  =head3 ParseAssignment
4227    
4228  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 4127  Line 4309 
4309      # Get the parameters.      # Get the parameters.
4310      my ($self, $fid) = @_;      my ($self, $fid) = @_;
4311      # Insure we have a genome hash.      # Insure we have a genome hash.
4312      if (! defined $self->{genomeHash}) {      my $genomes = $self->_GenomeHash();
         my %genomeHash = map { $_ => 1 } $self->GetFlat(['Genome'], "", [], 'Genome(id)');  
         $self->{genomeHash} = \%genomeHash;  
     }  
4313      # Get the feature's genome ID.      # Get the feature's genome ID.
4314      my ($genomeID) = FIGRules::ParseFeatureID($fid);      my ($genomeID) = FIGRules::ParseFeatureID($fid);
4315      # 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 4164  Line 4343 
4343  }  }
4344    
4345    
4346    =head3 Hint
4347    
4348        my $htmlText = Sprout::Hint($wikiPage, $hintID);
4349    
4350    Return the HTML for a help link that displays the specified hint text when it is clicked.
4351    This HTML can be put in forms to provide a useful hinting mechanism.
4352    
4353    =over 4
4354    
4355    =item wikiPage
4356    
4357    Name of the wiki page to be popped up when the hint mark is clicked.
4358    
4359    =item hintID
4360    
4361    ID of the text to display for the hint. This should correspond to a tip number
4362    in the Wiki.
4363    
4364    =item RETURN
4365    
4366    Returns the html for the hint facility. The resulting html shows the word "help" and
4367    uses the standard FIG popup technology.
4368    
4369    =back
4370    
4371    =cut
4372    
4373    sub Hint {
4374        # Get the parameters.
4375        my ($wikiPage, $hintID) = @_;
4376        # Declare the return variable.
4377        my $retVal;
4378        # Convert the wiki page name to a URL.
4379        my $wikiURL;
4380        if ($wikiPage =~ m#/#) {
4381            # Here it's a URL of some sort.
4382            $wikiURL = $wikiPage;
4383        } else {
4384            # Here it's a wiki page.
4385            my $page = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4386            if ($page =~ /^(.+?)\.(.+)$/) {
4387                $page = "$1/$2";
4388            } else {
4389                $page = "FIG/$page";
4390            }
4391            $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/$page";
4392        }
4393        # Is there hint text?
4394        if (! $hintID) {
4395            # No. Create a new-page hint.
4396            $retVal = qq(&nbsp;<a class="hint" onclick="doPagePopup(this, '$wikiURL')">(help)</a>);
4397        } else {
4398            # With hint text, we create a popup window hint. We need to compute the hint URL.
4399            my $tipURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/TWikiCustomTip" .
4400                Tracer::Pad($hintID, 3, 1, "0");
4401            # Create a hint pop-up link.
4402            $retVal = qq(&nbsp;<a class="hint" onclick="doHintPopup(this, '$wikiURL', '$tipURL')">(help)</a>);
4403        }
4404        # Return the HTML.
4405        return $retVal;
4406    }
4407    
4408    =head3 _GenomeHash
4409    
4410        my $gHash = $sprout->_GenomeHash();
4411    
4412    Return a hash mapping all NMPDR genome IDs to [[ERDBObjectPm]] genome objects.
4413    
4414    =cut
4415    
4416    sub _GenomeHash {
4417        # Get the parameters.
4418        my ($self) = @_;
4419        # Do we already have a filled hash?
4420        if (! $self->{genomeHashFilled}) {
4421            # No, create it.
4422            my %gHash = map { $_->PrimaryValue('id') => $_ } $self->GetList("Genome", "", []);
4423            $self->{genomeHash} = \%gHash;
4424            # Denote we have it.
4425            $self->{genomeHashFilled} = 1;
4426        }
4427        # Return the hash.
4428        return $self->{genomeHash};
4429    }
4430    
4431    =head3 _GenomeData
4432    
4433        my $genomeData = $sprout->_GenomeData($genomeID);
4434    
4435    Return an [[ERDBObjectPm]] object for the specified genome, or an undefined
4436    value if the genome does not exist.
4437    
4438    =over 4
4439    
4440    =item genomeID
4441    
4442    ID of the desired genome.
4443    
4444    =item RETURN
4445    
4446    Returns either an [[ERDBObjectPm]] containing the genome, or an undefined value.
4447    If the genome exists, it will have been read into the genome cache.
4448    
4449    =back
4450    
4451    =cut
4452    
4453    sub _GenomeData {
4454        # Get the parameters.
4455        my ($self, $genomeID) = @_;
4456        # Are we in the genome hash?
4457        if (! exists $self->{genomeHash}->{$genomeID} && ! $self->{genomeHashFilled}) {
4458            # The genome isn't in the hash, and the hash is not complete, so we try to
4459            # read it.
4460            $self->{genomeHash}->{$genomeID} = $self->GetEntity(Genome => $genomeID);
4461        }
4462        # Return the result.
4463        return $self->{genomeHash}->{$genomeID};
4464    }
4465    
4466    =head3 _CacheGenome
4467    
4468        $sprout->_CacheGenome($genomeID, $genomeData);
4469    
4470    Store the specified genome object in the genome cache if it is already there.
4471    
4472    =over 4
4473    
4474    =item genomeID
4475    
4476    ID of the genome to store in the cache.
4477    
4478    =item genomeData
4479    
4480    An [[ERDBObjectPm]] containing at least the data for the specified genome.
4481    Note that the Genome may not be the primary object in it, so a fully-qualified
4482    field name has to be used to retrieve data from it.
4483    
4484    =back
4485    
4486    =cut
4487    
4488    sub _CacheGenome {
4489        # Get the parameters.
4490        my ($self, $genomeID, $genomeData) = @_;
4491        # Only proceed if we don't already have the genome.
4492        if (! exists $self->{genomeHash}->{$genomeID}) {
4493            $self->{genomeHash}->{$genomeID} = $genomeData;
4494        }
4495    }
4496    
4497  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3