[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.113, Tue Aug 12 06:01:49 2008 UTC revision 1.118, Sat Sep 20 14:32:34 2008 UTC
# Line 16  Line 16 
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17      use CGI;      use CGI;
18      use WikiTools;      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 107  Line 108 
108                                                          # data file directory                                                          # data file directory
109                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
110                                                          # database definition file name                                                          # database definition file name
111                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
112                                                          # user name and password                                                          # user name and password
113                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
114                                                          # database connection port                                                          # database connection port
115                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
116                         host         => $FIG_Config::sprout_host,                         host         => $FIG_Config::sprout_host,
117                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
118                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
# Line 148  Line 149 
149          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));          my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
150          $retVal->{_ca} = CustomAttributes->new(user => $user);          $retVal->{_ca} = CustomAttributes->new(user => $user);
151      }      }
     # Insure we have access to the stem module.  
     WikiUse('Lingua::Stem');  
     $retVal->{stemmer} = Lingua::Stem->new();  
     $retVal->{stemmer}->stem_caching({ -level => 2 });  
152      # Return it.      # Return it.
153      return $retVal;      return $retVal;
154  }  }
# Line 536  Line 533 
533      # Get the parameters.      # Get the parameters.
534      my ($self, %options) = @_;      my ($self, %options) = @_;
535      # Get the control's name and ID.      # Get the control's name and ID.
536      my $menuName = $options{name} || 'myGenomeControl';      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
537      my $menuID = $options{id} || $menuName;      my $menuID = $options{id} || $menuName;
538        Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
539      # Compute the IDs for the status display.      # Compute the IDs for the status display.
540      my $divID = "${menuID}_status";      my $divID = "${menuID}_status";
541      my $urlID = "${menuID}_url";      my $urlID = "${menuID}_url";
# Line 628  Line 626 
626      # Set up the style class.      # Set up the style class.
627      my $classTag = ($class ? " class=\"$class\"" : "" );      my $classTag = ($class ? " class=\"$class\"" : "" );
628      # Create the SELECT tag and stuff it into the output array.      # Create the SELECT tag and stuff it into the output array.
629      my @lines = ("<SELECT name=\"$menuID\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");      my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
630      # Loop through the groups.      # Loop through the groups.
631      for my $group (@groups) {      for my $group (@groups) {
632          # Get the genomes in the group.          # Get the genomes in the group.
# Line 664  Line 662 
662          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;\" />"
663                                               : "Show genomes containing");                                               : "Show genomes containing");
664          push @lines, "<br />$searchThingLabel&nbsp;" .          push @lines, "<br />$searchThingLabel&nbsp;" .
665                       "<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');\" />" .
666                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
667          # 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.
668          if ($multiSelect) {          if ($multiSelect) {
669              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 672  Line 671 
671              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;\" />";
672          }          }
673          # Add a hidden field we can use to generate organism page hyperlinks.          # Add a hidden field we can use to generate organism page hyperlinks.
674          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=\" />";
675          # 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.
676          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";          push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
677      }      }
# Line 709  Line 708 
708  sub Stem {  sub Stem {
709      # Get the parameters.      # Get the parameters.
710      my ($self, $word) = @_;      my ($self, $word) = @_;
711      # Declare the return variable.      # Get the stemmer object.
712      my $retVal;      my $stemmer = $self->{stemmer};
713      # See if it's stemmable.      if (! defined $stemmer) {
714      if ($word =~ /^[A-Za-z]+$/) {          # We don't have one pre-built, so we build and save it now.
715          # Compute the stem.          $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
716          my $stemList = $self->{stemmer}->stem($word);                                   stops => "$FIG_Config::sproutData/StopWords.txt",
717          my $stem = $stemList->[0];                                   cache => 1);
718          # Check to see if it's long enough.          $self->{stemmer} = $stemmer;
         if (length $stem >= 3) {  
             # Yes, keep it.  
             $retVal = $stem;  
         } else {  
             # No, use the original word.  
             $retVal = $word;  
         }  
719      }      }
720        # Try to stem the word.
721        my $retVal = $stemmer->Process($word);
722      # Return the result.      # Return the result.
723      return $retVal;      return $retVal;
724  }  }
# Line 1619  Line 1613 
1613  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
1614  is trusted.  is trusted.
1615    
1616  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.
1617  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.  
1618    
1619  =over 4  =over 4
1620    
# Line 1647  Line 1640 
1640      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1641      # Declare the return value.      # Declare the return value.
1642      my $retVal;      my $retVal;
1643      # Determine the ID type.      # Find a FIG ID for this feature.
1644      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1645        # Only proceed if we have an ID.
1646        if ($fid) {
1647          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1648          if (!$userID) {          if (!$userID) {
1649              # Use the primary assignment.              # Use the primary assignment.
1650              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1651          } else {          } else {
1652              # We must build the list of trusted users.              # We must build the list of trusted users.
1653              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1678  Line 1673 
1673              # 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.
1674              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1675                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1676                                     [$featureID]);                                     [$fid]);
1677              my $timeSelected = 0;              my $timeSelected = 0;
1678              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1679              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1698  Line 1693 
1693                  }                  }
1694              }              }
1695          }          }
     } 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)']);  
1696      }      }
1697      # Return the assignment found.      # Return the assignment found.
1698      return $retVal;      return $retVal;
# Line 1721  Line 1711 
1711  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
1712  most features only have a small number of annotations.  most features only have a small number of annotations.
1713    
 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.  
   
1714  =over 4  =over 4
1715    
1716  =item featureID  =item featureID
# Line 1745  Line 1731 
1731      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1732      # Declare the return value.      # Declare the return value.
1733      my @retVal = ();      my @retVal = ();
1734      # Determine the ID type.      # Convert to a FIG ID.
1735      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1736        # Only proceed if we found one.
1737        if ($fid) {
1738          # 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
1739          # users.          # users.
1740          my %trusteeTable = ();          my %trusteeTable = ();
1741          # 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.
1742          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1743                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1744                                 [$featureID]);                                 [$fid]);
1745          my $timeSelected = 0;          my $timeSelected = 0;
1746          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1747          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1768  Line 1756 
1756                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1757              }              }
1758          }          }
     } 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;  
1759      }      }
1760      # Return the assignments found.      # Return the assignments found.
1761      return @retVal;      return @retVal;
# Line 1966  Line 1947 
1947          my ($realFeatureID) = $self->FeaturesByAlias($featureID);          my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1948          if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {          if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1949              $retVal = $1;              $retVal = $1;
         } else {  
             # Use the external table.  
             my ($org) = $self->GetFlat(['ExternalAliasOrg'], "ExternalAliasOrg(id) = ?",  
                                        [$featureID], "ExternalAliasOrg(org)");  
             if ($org) {  
                 $retVal = $org;  
             } else {  
                 Confess("Invalid feature ID $featureID.");  
             }  
1950          }          }
1951      }      }
1952      # Return the value found.      # Return the value found.
# Line 2815  Line 2787 
2787      return @retVal;      return @retVal;
2788  }  }
2789    
 =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;  
 }  
   
2790  =head3 FeatureProperties  =head3 FeatureProperties
2791    
2792      my @properties = $sprout->FeatureProperties($featureID);      my @properties = $sprout->FeatureProperties($featureID);
# Line 3201  Line 3087 
3087  sub SubsystemList {  sub SubsystemList {
3088      # Get the parameters.      # Get the parameters.
3089      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3090      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3091      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3092        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3093                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3094      # Return the result, sorted.      # Return the result, sorted.
3095      return sort @retVal;      return sort @retVal;
# Line 3235  Line 3122 
3122      # Declare the return variable.      # Declare the return variable.
3123      my %retVal = ();      my %retVal = ();
3124      # 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
3125      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3126      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3127                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3128                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3129      # 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
3130      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3131      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3132      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3133      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3134                                   "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.  
3135      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3136          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3137          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3138          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3139          my $subsys = $subHash{$cellID};          # Check the subsystem;
3140          if ($subsys) {          if ($subs{$subsys}) {
3141                Trace("Subsystem found.") if T(4);
3142              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3143              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3144              # Merge in this new data.              # Merge in this new data.
# Line 4250  Line 4131 
4131  }  }
4132    
4133    
4134    =head3 Hint
4135    
4136        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4137    
4138    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4139    This HTML can be put in forms to provide a useful hinting mechanism.
4140    
4141    =over 4
4142    
4143    =item wikiPage
4144    
4145    Name of the wiki page to be popped up when the hint mark is clicked.
4146    
4147    =item hintText
4148    
4149    Text to display for the hint. It is raw html, but may not contain any double quotes.
4150    
4151    =item RETURN
4152    
4153    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4154    uses the standard FIG popup technology.
4155    
4156    =back
4157    
4158    =cut
4159    
4160    sub Hint {
4161        # Get the parameters.
4162        my ($wikiPage, $hintText) = @_;
4163        # Escape the single quotes in the hint text.
4164        my $quotedText = $hintText;
4165        $quotedText =~ s/'/\\'/g;
4166        # Convert the wiki page name to a URL.
4167        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4168        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4169        # Compute the mouseover script.
4170        my $mouseOver = "doTooltip(this, '$quotedText')";
4171        # Create the html.
4172        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4173        # Return it.
4174        return $retVal;
4175    }
4176    
4177  1;  1;

Legend:
Removed from v.1.113  
changed lines
  Added in v.1.118

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3