[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.110, Tue Apr 29 20:54:51 2008 UTC revision 1.117, Tue Sep 16 18:57:59 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 106  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 531  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 547  Line 550 
550      if (ref $selections ne 'ARRAY') {      if (ref $selections ne 'ARRAY') {
551          $selections = [ split /\s*,\s*/, $selections ];          $selections = [ split /\s*,\s*/, $selections ];
552      }      }
553      my %selected = map { $_ => } @{$selections};      my %selected = map { $_ => 1 } @{$selections};
554      # 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
555      # string or a list reference.      # string or a list reference.
556      my $filterParms = $options{filter} || "";      my $filterParms = $options{filter} || "";
# Line 623  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 659  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 667  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 678  Line 682 
682  }  }
683    
684    
685    =head3 Stem
686    
687        my $stem = $sprout->Stem($word);
688    
689    Return the stem of the specified word, or C<undef> if the word is not
690    stemmable. Note that even if the word is stemmable, the stem may be
691    the same as the original word.
692    
693    =over 4
694    
695    =item word
696    
697    Word to convert into a stem.
698    
699    =item RETURN
700    
701    Returns a stem of the word (which may be the word itself), or C<undef> if
702    the word is not stemmable.
703    
704    =back
705    
706    =cut
707    
708    sub Stem {
709        # Get the parameters.
710        my ($self, $word) = @_;
711        # Get the stemmer object.
712        my $stemmer = $self->{stemmer};
713        if (! defined $stemmer) {
714            # We don't have one pre-built, so we build and save it now.
715            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
716                                     stops => "$FIG_Config::sproutData/StopWords.txt",
717                                     cache => 1);
718            $self->{stemmer} = $stemmer;
719        }
720        # Try to stem the word.
721        my $retVal = $stemmer->Process($word);
722        # Return the result.
723        return $retVal;
724    }
725    
726    
727  =head3 Build  =head3 Build
728    
729      $sprout->Build();      $sprout->Build();
# Line 1567  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 1595  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 1626  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 1646  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 1669  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 1693  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 1716  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 1910  Line 1943 
1943      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1944          $retVal = $1;          $retVal = $1;
1945      } else {      } else {
1946          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
1947            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1948            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1949                $retVal = $1;
1950            }
1951      }      }
1952      # Return the value found.      # Return the value found.
1953      return $retVal;      return $retVal;
# Line 2750  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 3136  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 4033  Line 3985 
3985      # Get the parameters.      # Get the parameters.
3986      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
3987      # Perform the standard cleanup.      # Perform the standard cleanup.
3988      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $words = $self->ERDB::CleanKeywords($searchExpression);
3989      # Fix the periods in EC and TC numbers.      # Fix the periods in EC and TC numbers.
3990      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      $words =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3991      # Fix non-trailing periods.      # Fix non-trailing periods.
3992      $retVal =~ s/\.(\w)/_$1/g;      $words =~ s/\.(\w)/_$1/g;
3993      # Fix non-leading minus signs.      # Fix non-leading minus signs.
3994      $retVal =~ s/(\w)[\-]/$1_/g;      $words =~ s/(\w)[\-]/$1_/g;
3995      # Fix the vertical bars and colons      # Fix the vertical bars and colons
3996      $retVal =~ s/(\w)[|:](\w)/$1'$2/g;      $words =~ s/(\w)[|:](\w)/$1'$2/g;
3997        # Now split up the list so that each keyword is in its own string. We keep the delimiters
3998        # because they may contain boolean expression data.
3999        my @words = split /([^A-Za-z'0-9_]+)/, $words;
4000        # We'll convert the stemmable words into stems and re-assemble the result.
4001        my $retVal = "";
4002        for my $word (@words) {
4003            my $stem = $self->Stem($word);
4004            if (defined $stem) {
4005                $retVal .= $stem;
4006            } else {
4007                $retVal .= $word;
4008            }
4009        }
4010        Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
4011      # Return the result.      # Return the result.
4012      return $retVal;      return $retVal;
4013  }  }
# Line 4171  Line 4137 
4137  }  }
4138    
4139    
4140    =head3 Hint
4141    
4142        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4143    
4144    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4145    This HTML can be put in forms to provide a useful hinting mechanism.
4146    
4147    =over 4
4148    
4149    =item wikiPage
4150    
4151    Name of the wiki page to be popped up when the hint mark is clicked.
4152    
4153    =item hintText
4154    
4155    Text to display for the hint. It is raw html, but may not contain any double quotes.
4156    
4157    =item RETURN
4158    
4159    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4160    uses the standard FIG popup technology.
4161    
4162    =back
4163    
4164    =cut
4165    
4166    sub Hint {
4167        # Get the parameters.
4168        my ($wikiPage, $hintText) = @_;
4169        # Escape the single quotes in the hint text.
4170        my $quotedText = $hintText;
4171        $quotedText =~ s/'/\\'/g;
4172        # Convert the wiki page name to a URL.
4173        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4174        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4175        # Compute the mouseover script.
4176        my $mouseOver = "doTooltip(this, '$quotedText')";
4177        # Create the html.
4178        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4179        # Return it.
4180        return $retVal;
4181    }
4182    
4183  1;  1;

Legend:
Removed from v.1.110  
changed lines
  Added in v.1.117

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3