[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.119, Tue Sep 30 15:23:55 2008 UTC
# Line 15  Line 15 
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17      use CGI;      use CGI;
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 55  Line 57 
57    
58  =item dbName  =item dbName
59    
60  Name of the database.  Name of the database. If omitted, the default Sprout database name is used.
61    
62  =item options  =item options
63    
# Line 94  Line 96 
96  sub new {  sub new {
97      # Get the parameters.      # Get the parameters.
98      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
99        # Default the database name if it is missing.
100        if (! defined $dbName) {
101            $dbName = $FIG_Config::sproutDB;
102        } elsif (ref $dbName eq 'HASH') {
103            $options = $dbName;
104            $dbName = $FIG_Config::sproutDB;
105        }
106      # Compute the DBD directory.      # Compute the DBD directory.
107      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :      my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
108                                                    $FIG_Config::fig );                                                    $FIG_Config::fig );
# Line 106  Line 115 
115                                                          # data file directory                                                          # data file directory
116                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
117                                                          # database definition file name                                                          # database definition file name
118                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
119                                                          # user name and password                                                          # user name and password
120                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
121                                                          # database connection port                                                          # database connection port
122                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
123                         host         => $FIG_Config::sprout_host,                         host         => $FIG_Config::sprout_host,
124                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
125                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
# Line 138  Line 147 
147      $retVal->{groupHash} = undef;      $retVal->{groupHash} = undef;
148      # 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.
149      $retVal->{genomeHash} = undef;      $retVal->{genomeHash} = undef;
150        # Remember the data directory name.
151        $retVal->{dataDir} = $dataDir;
152      # Connect to the attributes.      # Connect to the attributes.
153      if ($FIG_Config::attrURL) {      if ($FIG_Config::attrURL) {
154          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);          Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
# Line 519  Line 530 
530  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
531  default is none.  default is none.
532    
533  =item inTable  =item class
534    
535  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.  
536    
537  =back  =back
538    
# Line 532  Line 542 
542      # Get the parameters.      # Get the parameters.
543      my ($self, %options) = @_;      my ($self, %options) = @_;
544      # Get the control's name and ID.      # Get the control's name and ID.
545      my $menuName = $options{name} || 'myGenomeControl';      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
546      my $menuID = $options{id} || $menuName;      my $menuID = $options{id} || $menuName;
547        Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
548      # Compute the IDs for the status display.      # Compute the IDs for the status display.
549      my $divID = "${menuID}_status";      my $divID = "${menuID}_status";
550      my $urlID = "${menuID}_url";      my $urlID = "${menuID}_url";
# Line 541  Line 552 
552      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
553      # Check for single-select or multi-select.      # Check for single-select or multi-select.
554      my $multiSelect = $options{multiSelect} || 0;      my $multiSelect = $options{multiSelect} || 0;
555        # Get the style data.
556        my $class = $options{class} || '';
557      # Get the list of pre-selected items.      # Get the list of pre-selected items.
558      my $selections = $options{selected} || [];      my $selections = $options{selected} || [];
559      if (ref $selections ne 'ARRAY') {      if (ref $selections ne 'ARRAY') {
560          $selections = [ split /\s*,\s*/, $selections ];          $selections = [ split /\s*,\s*/, $selections ];
561      }      }
562      my %selected = map { $_ => } @{$selections};      my %selected = map { $_ => 1 } @{$selections};
563      # 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
564      # string or a list reference.      # string or a list reference.
565      my $filterParms = $options{filter} || "";      my $filterParms = $options{filter} || "";
# Line 619  Line 632 
632      my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );      my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
633      # Set up the multiple-select flag.      # Set up the multiple-select flag.
634      my $multipleTag = ($multiSelect ? " multiple" : "" );      my $multipleTag = ($multiSelect ? " multiple" : "" );
635        # Set up the style class.
636        my $classTag = ($class ? " class=\"$class\"" : "" );
637      # Create the SELECT tag and stuff it into the output array.      # Create the SELECT tag and stuff it into the output array.
638      my @lines = ("<SELECT name=\"$menuID\" id=\"$menuID\" $onChangeTag$multipleTag size=\"$rows\" style=\"width: 100%\">");      my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
639      # Loop through the groups.      # Loop through the groups.
640      for my $group (@groups) {      for my $group (@groups) {
641          # Get the genomes in the group.          # Get the genomes in the group.
# Line 656  Line 671 
671          my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"          my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
672                                               : "Show genomes containing");                                               : "Show genomes containing");
673          push @lines, "<br />$searchThingLabel&nbsp;" .          push @lines, "<br />$searchThingLabel&nbsp;" .
674                       "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />";                       "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .
675                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
676          # 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.
677          if ($multiSelect) {          if ($multiSelect) {
678              push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";              push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";
# Line 664  Line 680 
680              push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";              push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";
681          }          }
682          # Add a hidden field we can use to generate organism page hyperlinks.          # Add a hidden field we can use to generate organism page hyperlinks.
683          push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/seedviewer.cgi?page=Organism;organism=\" />";          push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";
684          # 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.
685          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
686      }      }
687      # 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.
688      my $delim = ($options{inTable} ? "\\" : "" ) . "\n";      my $retVal = join("\n", @lines, "");
689      my $retVal = join($delim, @lines, "");      # Return the result.
690        return $retVal;
691    }
692    
693    
694    =head3 Stem
695    
696        my $stem = $sprout->Stem($word);
697    
698    Return the stem of the specified word, or C<undef> if the word is not
699    stemmable. Note that even if the word is stemmable, the stem may be
700    the same as the original word.
701    
702    =over 4
703    
704    =item word
705    
706    Word to convert into a stem.
707    
708    =item RETURN
709    
710    Returns a stem of the word (which may be the word itself), or C<undef> if
711    the word is not stemmable.
712    
713    =back
714    
715    =cut
716    
717    sub Stem {
718        # Get the parameters.
719        my ($self, $word) = @_;
720        # Get the stemmer object.
721        my $stemmer = $self->{stemmer};
722        if (! defined $stemmer) {
723            # We don't have one pre-built, so we build and save it now.
724            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
725                                     stops => "$FIG_Config::sproutData/StopWords.txt",
726                                     cache => 0);
727            $self->{stemmer} = $stemmer;
728        }
729        # Try to stem the word.
730        my $retVal = $stemmer->Process($word);
731      # Return the result.      # Return the result.
732      return $retVal;      return $retVal;
733  }  }
# Line 813  Line 870 
870  =item RETURN  =item RETURN
871    
872  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
873  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
874    wasn't found.
875    
876  =back  =back
877    
# Line 822  Line 880 
880  sub FeatureLocation {  sub FeatureLocation {
881      # Get the parameters.      # Get the parameters.
882      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
883        # Declare the return variable.
884        my @retVal = ();
885      # Get the feature record.      # Get the feature record.
886      my $object = $self->GetEntity('Feature', $featureID);      my $object = $self->GetEntity('Feature', $featureID);
887      Confess("Feature $featureID not found.") if ! defined($object);      # Only proceed if we found it.
888        if (defined $object) {
889      # Get the location string.      # Get the location string.
890      my $locString = $object->PrimaryValue('Feature(location-string)');      my $locString = $object->PrimaryValue('Feature(location-string)');
891      # Create the return list.      # Create the return list.
892      my @retVal = split /\s*,\s*/, $locString;          @retVal = split /\s*,\s*/, $locString;
893        }
894      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
895      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
896  }  }
# Line 1560  Line 1622 
1622  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
1623  is trusted.  is trusted.
1624    
1625  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.
1626  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.  
1627    
1628  =over 4  =over 4
1629    
# Line 1588  Line 1649 
1649      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1650      # Declare the return value.      # Declare the return value.
1651      my $retVal;      my $retVal;
1652      # Determine the ID type.      # Find a FIG ID for this feature.
1653      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1654        # Only proceed if we have an ID.
1655        if ($fid) {
1656          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1657          if (!$userID) {          if (!$userID) {
1658              # Use the primary assignment.              # Use the primary assignment.
1659              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1660          } else {          } else {
1661              # We must build the list of trusted users.              # We must build the list of trusted users.
1662              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1619  Line 1682 
1682              # 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.
1683              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1684                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1685                                     [$featureID]);                                     [$fid]);
1686              my $timeSelected = 0;              my $timeSelected = 0;
1687              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1688              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1639  Line 1702 
1702                  }                  }
1703              }              }
1704          }          }
     } 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)']);  
1705      }      }
1706      # Return the assignment found.      # Return the assignment found.
1707      return $retVal;      return $retVal;
# Line 1662  Line 1720 
1720  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
1721  most features only have a small number of annotations.  most features only have a small number of annotations.
1722    
 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.  
   
1723  =over 4  =over 4
1724    
1725  =item featureID  =item featureID
# Line 1686  Line 1740 
1740      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1741      # Declare the return value.      # Declare the return value.
1742      my @retVal = ();      my @retVal = ();
1743      # Determine the ID type.      # Convert to a FIG ID.
1744      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1745        # Only proceed if we found one.
1746        if ($fid) {
1747          # 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
1748          # users.          # users.
1749          my %trusteeTable = ();          my %trusteeTable = ();
1750          # 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.
1751          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1752                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1753                                 [$featureID]);                                 [$fid]);
1754          my $timeSelected = 0;          my $timeSelected = 0;
1755          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1756          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1709  Line 1765 
1765                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1766              }              }
1767          }          }
     } 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;  
1768      }      }
1769      # Return the assignments found.      # Return the assignments found.
1770      return @retVal;      return @retVal;
# Line 1903  Line 1952 
1952      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1953          $retVal = $1;          $retVal = $1;
1954      } else {      } else {
1955          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
1956            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1957            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1958                $retVal = $1;
1959            }
1960      }      }
1961      # Return the value found.      # Return the value found.
1962      return $retVal;      return $retVal;
# Line 2743  Line 2796 
2796      return @retVal;      return @retVal;
2797  }  }
2798    
 =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;  
 }  
   
2799  =head3 FeatureProperties  =head3 FeatureProperties
2800    
2801      my @properties = $sprout->FeatureProperties($featureID);      my @properties = $sprout->FeatureProperties($featureID);
# Line 3129  Line 3096 
3096  sub SubsystemList {  sub SubsystemList {
3097      # Get the parameters.      # Get the parameters.
3098      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3099      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3100      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3101        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3102                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3103      # Return the result, sorted.      # Return the result, sorted.
3104      return sort @retVal;      return sort @retVal;
# Line 3163  Line 3131 
3131      # Declare the return variable.      # Declare the return variable.
3132      my %retVal = ();      my %retVal = ();
3133      # 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
3134      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3135      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3136                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3137                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3138      # 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
3139      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3140      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3141      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3142      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3143                                   "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.  
3144      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3145          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3146          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3147          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3148          my $subsys = $subHash{$cellID};          # Check the subsystem;
3149          if ($subsys) {          if ($subs{$subsys}) {
3150                Trace("Subsystem found.") if T(4);
3151              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3152              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3153              # Merge in this new data.              # Merge in this new data.
# Line 4025  Line 3987 
3987  sub CleanKeywords {  sub CleanKeywords {
3988      # Get the parameters.      # Get the parameters.
3989      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
3990      # Perform the standard cleanup.      # Get the stemmer.
3991      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $stemmer = $self->GetStemmer();
3992      # Fix the periods in EC and TC numbers.      # Convert the search expression using the stemmer.
3993      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      my $retVal = $stemmer->PrepareSearchExpression($searchExpression);
3994      # 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;  
3995      # Return the result.      # Return the result.
3996      return $retVal;      return $retVal;
3997  }  }
3998    
3999    =head3 GetSourceObject
4000    
4001        my $source = $erdb->GetSourceObject();
4002    
4003    Return the object to be used in creating load files for this database.
4004    
4005    =cut
4006    
4007    sub GetSourceObject {
4008        # Get access to the FIG code.
4009        require FIG;
4010        # Return a FIG object.
4011        return FIG->new();
4012    }
4013    
4014    =head3 SectionList
4015    
4016        my @sections = $erdb->SectionList($source);
4017    
4018    Return a list of the names for the different data sections used when loading this database.
4019    The default is an empty string, in which case there is only one section representing the
4020    entire database.
4021    
4022    =over 4
4023    
4024    =item source
4025    
4026    Source object used to access the data from which the database is loaded. This is the
4027    same object returned by L</GetSourceObject>; however, we ask the caller to pass it
4028    in as a parameter so that we don't end up creating multiple copies of a potentially
4029    expensive data structure.
4030    
4031    =item RETURN
4032    
4033    Returns a list of section names.
4034    
4035    =back
4036    
4037    =cut
4038    
4039    sub SectionList {
4040        # Get the parameters.
4041        my ($self, $source) = @_;
4042        # Ask the BaseSproutLoader for a section list.
4043        require BaseSproutLoader;
4044        my @retVal = BaseSproutLoader::GetSectionList($self, $source);
4045        # Return the list.
4046        return @retVal;
4047    }
4048    
4049    =head3 Loader
4050    
4051        my $groupLoader = $erdb->Loader($groupName, $source, $options);
4052    
4053    Return an [[ERDBLoadGroupPm]] object for the specified load group. This method is used
4054    by [[ERDBGeneratorPl]] to create the load group objects. If you are not using
4055    [[ERDBGeneratorPl]], you don't need to override this method.
4056    
4057    =over 4
4058    
4059    =item groupName
4060    
4061    Name of the load group whose object is to be returned. The group name is
4062    guaranteed to be a single word with only the first letter capitalized.
4063    
4064    =item source
4065    
4066    The source object used to access the data from which the load file is derived. This
4067    is the same object returned by L</GetSourceObject>; however, we ask the caller to pass
4068    it in as a parameter so that we don't end up creating multiple copies of a potentially
4069    expensive data structure.
4070    
4071    =item options
4072    
4073    Reference to a hash of command-line options.
4074    
4075    =item RETURN
4076    
4077    Returns an [[ERDBLoadGroupPm]] object that can be used to process the specified load group
4078    for this database.
4079    
4080    =back
4081    
4082    =cut
4083    
4084    sub Loader {
4085        # Get the parameters.
4086        my ($self, $groupName, $source, $options) = @_;
4087        # Compute the loader name.
4088        my $loaderClass = "${groupName}SproutLoader";
4089        # Pull in its definition.
4090        require "$loaderClass.pm";
4091        # Create an object for it.
4092        my $retVal = eval("$loaderClass->new(\$self, \$source, \$options)");
4093        # Insure it worked.
4094        Confess("Could not create $loaderClass object: $@") if $@;
4095        # Return it to the caller.
4096        return $retVal;
4097    }
4098    
4099    =head3 LoadGroupList
4100    
4101        my @groups = $erdb->LoadGroupList();
4102    
4103    Returns a list of the names for this database's load groups. This method is used
4104    by [[ERDBGeneratorPl]] when the user wishes to load all table groups. The default
4105    is a single group called 'All' that loads everything.
4106    
4107    =cut
4108    
4109    sub LoadGroupList {
4110        # Return the list.
4111        return qw(Genome Subsystem Feature Annotation Property Source Reaction Synonym Drug);
4112    }
4113    
4114    =head3 LoadDirectory
4115    
4116        my $dirName = $erdb->LoadDirectory();
4117    
4118    Return the name of the directory in which load files are kept. The default is
4119    the FIG temporary directory, which is a really bad choice, but it's always there.
4120    
4121    =cut
4122    
4123    sub LoadDirectory {
4124        # Get the parameters.
4125        my ($self) = @_;
4126        # Return the directory name.
4127        return $self->{dataDir};
4128    }
4129    
4130  =head2 Internal Utility Methods  =head2 Internal Utility Methods
4131    
4132    =head3 GetStemmer
4133    
4134        my $stermmer = $sprout->GetStemmer();
4135    
4136    Return the stemmer object for this database.
4137    
4138    =cut
4139    
4140    sub GetStemmer {
4141        # Get the parameters.
4142        my ($self) = @_;
4143        # Declare the return variable.
4144        my $retVal = $self->{stemmer};
4145        if (! defined $retVal) {
4146            # We don't have one pre-built, so we build and save it now.
4147            $retVal = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
4148                                     stops => "$FIG_Config::sproutData/StopWords.txt",
4149                                     cache => 1);
4150            $self->{stemmer} = $retVal;
4151        }
4152        # Return the result.
4153        return $retVal;
4154    }
4155    
4156  =head3 ParseAssignment  =head3 ParseAssignment
4157    
4158  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 4164  Line 4276 
4276  }  }
4277    
4278    
4279    =head3 Hint
4280    
4281        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4282    
4283    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4284    This HTML can be put in forms to provide a useful hinting mechanism.
4285    
4286    =over 4
4287    
4288    =item wikiPage
4289    
4290    Name of the wiki page to be popped up when the hint mark is clicked.
4291    
4292    =item hintText
4293    
4294    Text to display for the hint. It is raw html, but may not contain any double quotes.
4295    
4296    =item RETURN
4297    
4298    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4299    uses the standard FIG popup technology.
4300    
4301    =back
4302    
4303    =cut
4304    
4305    sub Hint {
4306        # Get the parameters.
4307        my ($wikiPage, $hintText) = @_;
4308        # Escape the single quotes in the hint text.
4309        my $quotedText = $hintText;
4310        $quotedText =~ s/'/\\'/g;
4311        # Convert the wiki page name to a URL.
4312        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4313        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4314        # Compute the mouseover script.
4315        my $mouseOver = "doTooltip(this, '$quotedText')";
4316        # Create the html.
4317        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4318        # Return it.
4319        return $retVal;
4320    }
4321    
4322  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3