[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.10, Fri Feb 25 18:41:45 2005 UTC revision 1.14, Thu Jun 9 19:06:55 2005 UTC
# Line 269  Line 269 
269  sub GetEntity {  sub GetEntity {
270          # Get the parameters.          # Get the parameters.
271          my ($self, $entityType, $ID) = @_;          my ($self, $entityType, $ID) = @_;
272          # Create a query.          # Call the ERDB method.
273          my $query = $self->Get([$entityType], "$entityType(id) = ?", [$ID]);          return $self->{_erdb}->GetEntity($entityType, $ID);
         # Get the first (and only) object.  
         my $retVal = $query->Fetch();  
         # Return the result.  
         return $retVal;  
274  }  }
275    
276  =head3 GetEntityValues  =head3 GetEntityValues
# Line 308  Line 304 
304  sub GetEntityValues {  sub GetEntityValues {
305          # Get the parameters.          # Get the parameters.
306          my ($self, $entityType, $ID, $fields) = @_;          my ($self, $entityType, $ID, $fields) = @_;
307          # Get the specified entity.          # Call the ERDB method.
308          my $entity = $self->GetEntity($entityType, $ID);          return $self->{_erdb}->GetEntityValues($entityType, $ID, $fields);
         # Declare the return list.  
         my @retVal = ();  
         # If we found the entity, push the values into the return list.  
         if ($entity) {  
                 push @retVal, $entity->Values($fields);  
         }  
         # Return the result.  
         return @retVal;  
309  }  }
310    
311  =head3 ShowMetaData  =head3 ShowMetaData
# Line 1070  Line 1058 
1058  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>
1059    
1060  Return all of the functional assignments for a particular feature. The data is returned as a  Return all of the functional assignments for a particular feature. The data is returned as a
1061  hash of functional assignments to user IDs. A functional assignment is a type of annotation.  hash of functional assignments to user IDs. A functional assignment is a type of annotation,
1062  It has the format "XXXX\nset XXXX function to\nYYYYY". In this instance, XXXX is the user ID  Functional assignments are described in the L</ParseAssignment> function. Its worth noting that
1063  and YYYYY is the functional assignment text. Its worth noting that we cannot filter on the content  we cannot filter on the content of the annotation itself because it's a text field; however,
1064  of the annotation itself because it's a text field; however, this is not a big problem because most  this is not a big problem because most features only have a small number of annotations.
1065  features only have a small number of annotations. Finally, if a single user has multiple  Finally, if a single user has multiple functional assignments, we will only keep the most
1066  functional assignments, we will only keep the most recent one.  recent one.
1067    
1068  =over 4  =over 4
1069    
# Line 1109  Line 1097 
1097          # Get the annotation fields.          # Get the annotation fields.
1098          my ($timeStamp, $text) = @{$annotation};          my ($timeStamp, $text) = @{$annotation};
1099                  # Check to see if this is a functional assignment.                  # Check to see if this is a functional assignment.
1100                  my ($user, $function) = ParseAssignment($text);                  my ($user, $function) = _ParseAssignment($text);
1101          if ($user && ! exists $timeHash{$user}) {          if ($user && ! exists $timeHash{$user}) {
1102              # Here it is a functional assignment and there has been no              # Here it is a functional assignment and there has been no
1103              # previous assignment for this user, so we stuff it in the              # previous assignment for this user, so we stuff it in the
# Line 1131  Line 1119 
1119    
1120  The functional assignment is handled differently depending on the type of feature. If  The functional assignment is handled differently depending on the type of feature. If
1121  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional
1122  assignment is a type of annotation. It has the format "XXXX\nset XXXX function to\nYYYYY". In this  assignment is a type of annotation. The format of an assignment is described in
1123  instance, XXXX is the user ID and YYYYY is the functional assignment text. Its worth noting that  L</ParseLocation>. Its worth noting that we cannot filter on the content of the
1124  we cannot filter on the content of the annotation itself because it's a text field; however, this  annotation itself because it's a text field; however, this is not a big problem because
1125  is not a big problem because most features only have a small number of annotations.  most features only have a small number of annotations.
1126    
1127  Each user has an associated list of trusted users. The assignment returned will be the most  Each user has an associated list of trusted users. The assignment returned will be the most
1128  recent one by at least one of the trusted users. If no trusted user list is available, then  recent one by at least one of the trusted users. If no trusted user list is available, then
# Line 1203  Line 1191 
1191              # Get the annotation text.              # Get the annotation text.
1192              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);
1193              # Check to see if this is a functional assignment for a trusted user.              # Check to see if this is a functional assignment for a trusted user.
1194              my ($user, $type, $function) = split(/\n/, $text);              my ($user, $function) = _ParseAssignment($text);
1195              if ($type =~ m/^set $user function to$/i) {              if ($user) {
1196                  # Here it is a functional assignment. Check the time and the user                  # Here it is a functional assignment. Check the time and the user
1197                  # name. The time must be recent and the user must be trusted.                  # name. The time must be recent and the user must be trusted.
1198                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {
# Line 1361  Line 1349 
1349  sub CoupledFeatures {  sub CoupledFeatures {
1350          # Get the parameters.          # Get the parameters.
1351          my ($self, $featureID) = @_;          my ($self, $featureID) = @_;
1352          # Create a query to retrieve the functionally-coupled features. Note that we depend on the          # Create a query to retrieve the functionally-coupled features.
1353          # fact that the functional coupling is physically paired. If (A,B) is in the database, then          my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1354          # (B,A) will also be found.                                                     "ParticipatesInCoupling(from-link) = ?", [$featureID]);
         my $query = $self->Get(['IsClusteredOnChromosomeWith'],  
                                                    "IsClusteredOnChromosomeWith(from-link) = ?", [$featureID]);  
1355          # This value will be set to TRUE if we find at least one coupled feature.          # This value will be set to TRUE if we find at least one coupled feature.
1356          my $found = 0;          my $found = 0;
1357          # Create the return hash.          # Create the return hash.
1358          my %retVal = ();          my %retVal = ();
1359          # Retrieve the relationship records and store them in the hash.          # Retrieve the relationship records and store them in the hash.
1360          while (my $clustering = $query->Fetch()) {          while (my $clustering = $query->Fetch()) {
1361                  my ($otherFeatureID, $score) = $clustering->Values(['IsClusteredOnChromosomeWith(to-link)',                  # Get the ID and score of the coupling.
1362                                                                      'IsClusteredOnChromosomeWith(score)']);                  my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1363                                                                                    'Coupling(score)']);
1364                    # The coupling ID contains the two feature IDs separated by a space. We use
1365                    # this information to find the ID of the other feature.
1366                    my ($fid1, $fid2) = split / /, $couplingID;
1367                    my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);
1368                    # Attach the other feature's score to its ID.
1369                  $retVal{$otherFeatureID} = $score;                  $retVal{$otherFeatureID} = $score;
1370                  $found = 1;                  $found = 1;
1371          }          }
# Line 1447  Line 1439 
1439                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {
1440                          # Here we have a new header. Store the current sequence if we have one.                          # Here we have a new header. Store the current sequence if we have one.
1441                          if ($id) {                          if ($id) {
1442                                  $retVal{$id} = $sequence;                                  $retVal{$id} = uc $sequence;
1443                          }                          }
1444                          # Clear the sequence accumulator and save the new ID.                          # Clear the sequence accumulator and save the new ID.
1445                          ($id, $sequence) = ("$prefix$1", "");                          ($id, $sequence) = ("$prefix$1", "");
1446                  } else {                  } else {
1447                          # Here we have a data line, so we add it to the sequence accumulator.                          # Here we have a data line, so we add it to the sequence accumulator.
1448                          # First, we get the actual data out.                          # First, we get the actual data out. Note that we normalize to upper
1449                            # case.
1450                          $line =~ /^\s*(.*?)(\s|\n)/;                          $line =~ /^\s*(.*?)(\s|\n)/;
1451                          $sequence .= $1;                          $sequence .= $1;
1452                  }                  }
1453          }          }
1454          # Flush out the last sequence (if any).          # Flush out the last sequence (if any).
1455          if ($sequence) {          if ($sequence) {
1456                  $retVal {$id} = $sequence;                  $retVal{$id} = uc $sequence;
1457          }          }
1458            # Close the file.
1459            close FASTAFILE;
1460          # Return the hash constructed from the file.          # Return the hash constructed from the file.
1461          return %retVal;          return %retVal;
1462  }  }
# Line 1656  Line 1651 
1651    
1652  =head3 AssignFunction  =head3 AssignFunction
1653    
1654  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function); >>  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>
1655    
1656  This method assigns a function to a feature. Functions are a special type of annotation. The general  This method assigns a function to a feature. Functions are a special type of annotation. The general
1657  format is "XXXX\nset XXXX function to\nYYYYY" where XXXX is the feature type and YYYY is the functional  format is described in L</ParseAssignment>.
 assignment text.  
1658    
1659  =over 4  =over 4
1660    
# Line 1670  Line 1664 
1664    
1665  =item user  =item user
1666    
1667  Name of the user making the assignment. This is frequently a group name, like C<kegg> or C<fig>.  Name of the user group making the assignment, such as C<kegg> or C<fig>.
1668    
1669  =item function  =item function
1670    
1671  Text of the function being assigned.  Text of the function being assigned.
1672    
1673    =item assigningUser (optional)
1674    
1675    Name of the individual user making the assignment. If omitted, defaults to the user group.
1676    
1677  =item RETURN  =item RETURN
1678    
1679  Returns 1 if successful, 0 if an error occurred.  Returns 1 if successful, 0 if an error occurred.
# Line 1686  Line 1684 
1684  #: Return Type $;  #: Return Type $;
1685  sub AssignFunction {  sub AssignFunction {
1686          # Get the parameters.          # Get the parameters.
1687          my ($self, $featureID, $user, $function) = @_;          my ($self, $featureID, $user, $function, $assigningUser) = @_;
1688        # Default the assigning user.
1689        if (! $assigningUser) {
1690            $assigningUser = $user;
1691        }
1692          # Create an annotation string from the parameters.          # Create an annotation string from the parameters.
1693          my $annotationText = "$user\nset $user function to\n$function";          my $annotationText = "$assigningUser\nset $user function to\n$function";
1694          # Get the current time.          # Get the current time.
1695          my $now = time;          my $now = time;
1696          # Declare the return variable.          # Declare the return variable.
# Line 2355  Line 2357 
2357  sub GetAll {  sub GetAll {
2358          # Get the parameters.          # Get the parameters.
2359          my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;          my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;
2360          # Create the query.          # Call the ERDB method.
2361          my $query = $self->Get($objectNames, $filterClause, $parameterList);          my @retVal = $self->{_erdb}->GetAll($objectNames, $filterClause, $parameterList,
2362          # Set up a counter of the number of records read.                                                                                  $fields, $count);
         my $fetched = 0;  
         # Insure the counter has a value.  
         if (!defined $count) {  
                 $count = 0;  
         }  
         # Loop through the records returned, extracting the fields. Note that if the  
         # counter is non-zero, we stop when the number of records read hits the count.  
         my @retVal = ();  
         while (($count == 0 || $fetched < $count) && (my $row = $query->Fetch())) {  
                 my @rowData = $row->Values($fields);  
                 push @retVal, \@rowData;  
                 $fetched++;  
         }  
2363          # Return the resulting list.          # Return the resulting list.
2364          return @retVal;          return @retVal;
2365  }  }
# Line 2631  Line 2620 
2620  =head3 ParseAssignment  =head3 ParseAssignment
2621    
2622  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,
2623  the user and function text will be returned as a 2-element list. If it isn't, an empty list  the user, function text, and assigning user will be returned as a 3-element list. If it
2624  will be returned.  isn't, an empty list will be returned.
2625    
2626    A functional assignment is always of the form
2627    
2628        I<XXXX>C<\nset >I<YYYY>C< function to\n>I<ZZZZZ>
2629    
2630    where I<XXXX> is the B<assigning user>, I<YYYY> is the B<user>, and I<ZZZZ> is the
2631    actual functional role. In most cases, the user and the assigning user will be the
2632    same, but that is not always the case.
2633    
2634  This is a static method.  This is a static method.
2635    
# Line 2651  Line 2648 
2648    
2649  =cut  =cut
2650    
2651  sub ParseAssignment {  sub _ParseAssignment {
2652          # Get the parameters.          # Get the parameters.
2653          my ($text) = @_;          my ($text) = @_;
2654          # Declare the return value.          # Declare the return value.
2655          my @retVal = ();          my @retVal = ();
2656          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
2657          my ($user, $type, $function) = split(/\n/, $text);          my ($user, $type, $function) = split(/\n/, $text);
2658          if ($type =~ m/^set $user function to$/i) {          if ($type =~ m/^set ([^ ]+) function to$/i) {
2659                  # Here it is, so we return the user name and function text.                  # Here it is, so we return the user name (which is in $1), the functional role text,
2660                  @retVal = ($user, $function);          # and the assigning user.
2661                    @retVal = ($1, $function, $user);
2662          }          }
2663          # Return the result list.          # Return the result list.
2664          return @retVal;          return @retVal;

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.14

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3