[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.45, Thu Oct 20 10:20:27 2005 UTC revision 1.56, Wed Apr 19 03:34:15 2006 UTC
# Line 92  Line 92 
92                                                          # database type                                                          # database type
93                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
94                                                          # data file directory                                                          # data file directory
95                         xmlFileName  => "$FIG_Config::sproutData/SproutDBD.xml",                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",
96                                                          # database definition file name                                                          # database definition file name
97                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
98                                                          # user name and password                                                          # user name and password
# Line 740  Line 740 
740  should be of the form returned by L</featureLocation> when in a list context. In other words,  should be of the form returned by L</featureLocation> when in a list context. In other words,
741  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.  each location is of the form I<contigID>C<_>I<begin>I<dir>I<end>.
742    
743    For example, the following would return the DNA sequence for contig C<83333.1:NC_000913>
744    between positions 1401 and 1532, inclusive.
745    
746        my $sequence = $sprout->DNASeq('83333.1:NC_000913_1401_1532');
747    
748  =over 4  =over 4
749    
750  =item locationList  =item locationList
751    
752  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<end> (see  List of location specifiers, each in the form I<contigID>C<_>I<begin>I<dir>I<len> or
753  L</FeatureLocation> for more about this format).  I<contigID>C<_>I<begin>C<_>I<end> (see L</FeatureLocation> for more about this format).
754    
755  =item RETURN  =item RETURN
756    
# Line 1153  Line 1158 
1158    
1159  =item RETURN  =item RETURN
1160    
1161  Returns a hash mapping the functional assignment IDs to user IDs.  Returns a hash mapping the user IDs to functional assignment IDs.
1162    
1163  =back  =back
1164    
# Line 1163  Line 1168 
1168      # Get the parameters.      # Get the parameters.
1169      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1170      # Get all of the feature's annotations.      # Get all of the feature's annotations.
1171      my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation'],      my @query = $self->GetAll(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1172                              "IsTargetOfAnnotation(from-link) = ?",                              "IsTargetOfAnnotation(from-link) = ?",
1173                              [$featureID], ['Annotation(time)', 'Annotation(annotation)']);                              [$featureID], ['Annotation(time)', 'Annotation(annotation)',
1174                                               'MadeAnnotation(from-link)']);
1175      # Declare the return hash.      # Declare the return hash.
1176      my %retVal;      my %retVal;
     # Declare a hash for insuring we only make one assignment per user.  
     my %timeHash = ();  
1177      # Now we sort the assignments by timestamp in reverse.      # Now we sort the assignments by timestamp in reverse.
1178      my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query;      my @sortedQuery = sort { -($a->[0] <=> $b->[0]) } @query;
1179      # Loop until we run out of annotations.      # Loop until we run out of annotations.
1180      for my $annotation (@sortedQuery) {      for my $annotation (@sortedQuery) {
1181          # Get the annotation fields.          # Get the annotation fields.
1182          my ($timeStamp, $text) = @{$annotation};          my ($timeStamp, $text, $user) = @{$annotation};
1183          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
1184          my ($user, $function) = _ParseAssignment($text);          my ($actualUser, $function) = _ParseAssignment($user, $text);
1185          if ($user && ! exists $timeHash{$user}) {          if ($actualUser && ! exists $retVal{$actualUser}) {
1186              # Here it is a functional assignment and there has been no              # Here it is a functional assignment and there has been no
1187              # previous assignment for this user, so we stuff it in the              # previous assignment for this user, so we stuff it in the
1188              # return hash.              # return hash.
1189              $retVal{$function} = $user;              $retVal{$actualUser} = $function;
             # Insure we don't assign to this user again.  
             $timeHash{$user} = 1;  
1190          }          }
1191      }      }
1192      # Return the hash of assignments found.      # Return the hash of assignments found.
# Line 1262  Line 1264 
1264              }              }
1265          }          }
1266          # 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.
1267          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1268                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1269                                 [$featureID]);                                 [$featureID]);
1270          my $timeSelected = 0;          my $timeSelected = 0;
1271          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1272          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1273              # Get the annotation text.              # Get the annotation text.
1274              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1275                                                         'Annotation(time)', 'MadeAnnotation(from-link)']);
1276              # 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.
1277              my ($user, $function) = _ParseAssignment($text);              my ($actualUser, $function) = _ParseAssignment($user, $text);
1278              if ($user) {              Trace("Assignment user is $actualUser, text is $function.") if T(4);
1279                if ($actualUser) {
1280                  # Here it is a functional assignment. Check the time and the user                  # Here it is a functional assignment. Check the time and the user
1281                  # name. The time must be recent and the user must be trusted.                  # name. The time must be recent and the user must be trusted.
1282                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {                  if ((exists $trusteeTable{$actualUser}) && ($time > $timeSelected)) {
1283                      $retVal = $function;                      $retVal = $function;
1284                      $timeSelected = $time;                      $timeSelected = $time;
1285                  }                  }
# Line 1334  Line 1338 
1338          # users.          # users.
1339          my %trusteeTable = ();          my %trusteeTable = ();
1340          # 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.
1341          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1342                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1343                                 [$featureID]);                                 [$featureID]);
1344          my $timeSelected = 0;          my $timeSelected = 0;
1345          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1346          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1347              # Get the annotation text.              # Get the annotation text.
1348              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1349                                                                'Annotation(time)',
1350                                                                'MadeAnnotation(user)']);
1351              # 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.
1352              my ($user, $function) = _ParseAssignment($text);              my ($actualUser, $function) = _ParseAssignment($user, $text);
1353              if ($user) {              if ($actualUser) {
1354                  # Here it is a functional assignment.                  # Here it is a functional assignment.
1355                  push @retVal, [$user, $function];                  push @retVal, [$actualUser, $function];
1356              }              }
1357          }          }
1358      } else {      } else {
1359          # Here we have a non-FIG feature ID. In this case the user ID does not          # Here we have a non-FIG feature ID. In this case the user ID does not
1360          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
1361          # table.          # table.
1362          push @retVal, $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);          my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,
1363                                                     ['ExternalAliasFunc(func)']);
1364            push @retVal, map { ['master', $_] } @assignments;
1365      }      }
1366      # Return the assignments found.      # Return the assignments found.
1367      return @retVal;      return @retVal;
# Line 1479  Line 1487 
1487      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1488      if ($genomeData) {      if ($genomeData) {
1489          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1490          ($retVal) = $genomeData->Value('complete');          ($retVal) = $genomeData->Value('Genome(complete)');
1491      }      }
1492      # Return the result.      # Return the result.
1493      return $retVal;      return $retVal;
# Line 1519  Line 1527 
1527    
1528  C<< my $genomeID = $sprout->GenomeOf($featureID); >>  C<< my $genomeID = $sprout->GenomeOf($featureID); >>
1529    
1530  Return the genome that contains a specified feature.  Return the genome that contains a specified feature or contig.
1531    
1532  =over 4  =over 4
1533    
1534  =item featureID  =item featureID
1535    
1536  ID of the feature whose genome is desired.  ID of the feature or contig whose genome is desired.
1537    
1538  =item RETURN  =item RETURN
1539    
1540  Returns the ID of the genome for the specified feature. If the feature is not found, returns  Returns the ID of the genome for the specified feature or contig. If the feature or contig is not
1541  an undefined value.  found, returns an undefined value.
1542    
1543  =back  =back
1544    
# Line 1539  Line 1547 
1547  sub GenomeOf {  sub GenomeOf {
1548      # Get the parameters.      # Get the parameters.
1549      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1550      # Create a query to find the genome associated with the feature.      # Create a query to find the genome associated with the incoming ID.
1551      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ? OR HasContig(to-link) = ?",
1552                               [$featureID, $featureID]);
1553      # Declare the return value.      # Declare the return value.
1554      my $retVal;      my $retVal;
1555      # Get the genome ID.      # Get the genome ID.
# Line 2727  Line 2736 
2736      return @retVal;      return @retVal;
2737  }  }
2738    
2739    
2740    
2741  =head3 RelatedFeatures  =head3 RelatedFeatures
2742    
2743  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 3218  Line 3229 
3229      return $retVal;      return $retVal;
3230  }  }
3231    
3232    =head3 DeleteGenome
3233    
3234    C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>
3235    
3236    Delete a genome from the database.
3237    
3238    =over 4
3239    
3240    =item genomeID
3241    
3242    ID of the genome to delete
3243    
3244    =item testFlag
3245    
3246    If TRUE, then the DELETE statements will be traced, but no deletions will occur.
3247    
3248    =item RETURN
3249    
3250    Returns a statistics object describing the rows deleted.
3251    
3252    =back
3253    
3254    =cut
3255    #: Return Type $%;
3256    sub DeleteGenome {
3257        # Get the parameters.
3258        my ($self, $genomeID, $testFlag) = @_;
3259        # Perform the delete for the genome's features.
3260        my $retVal = $self->{_erdb}->Delete('Feature', "fig|$genomeID.%", $testFlag);
3261        # Perform the delete for the primary genome data.
3262        my $stats = $self->{_erdb}->Delete('Genome', $genomeID, $testFlag);
3263        $retVal->Accumulate($stats);
3264        # Return the result.
3265        return $retVal;
3266    }
3267    
3268  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3269    
3270  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3228  Line 3275 
3275    
3276  A functional assignment is always of the form  A functional assignment is always of the form
3277    
3278      I<XXXX>C<\nset >I<YYYY>C< function to\n>I<ZZZZZ>      C<set >I<YYYY>C< function to\n>I<ZZZZZ>
3279    
3280  where I<XXXX> is the B<assigning user>, I<YYYY> is the B<user>, and I<ZZZZ> is the  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
3281  actual functional role. In most cases, the user and the assigning user will be the  the user and the assigning user (from MadeAnnotation) will be the same, but that is
3282  same, but that is not always the case.  not always the case.
3283    
3284    In addition, the functional role may contain extra data that is stripped, such as
3285    terminating spaces or a comment separated from the rest of the text by a tab.
3286    
3287  This is a static method.  This is a static method.
3288    
3289  =over 4  =over 4
3290    
3291    =item user
3292    
3293    Name of the assigning user.
3294    
3295  =item text  =item text
3296    
3297  Text of the annotation.  Text of the annotation.
# Line 3253  Line 3307 
3307    
3308  sub _ParseAssignment {  sub _ParseAssignment {
3309      # Get the parameters.      # Get the parameters.
3310      my ($text) = @_;      my ($user, $text) = @_;
3311      # Declare the return value.      # Declare the return value.
3312      my @retVal = ();      my @retVal = ();
3313      # Check to see if this is a functional assignment.      # Check to see if this is a functional assignment.
3314      my ($type, $function) = split(/\n/, $text);      my ($type, $function) = split(/\n/, $text);
3315      if ($type =~ m/^set ([^ ]+) function to$/i) {      if ($type =~ m/^set function to$/i) {
3316          # Here it is, so we return the user name (which is in $1), the functional role text,          # Here we have an assignment without a user, so we use the incoming user ID.
3317          # and the assigning user.          @retVal = ($user, $function);
3318        } elsif ($type =~ m/^set (\S+) function to$/i) {
3319            # Here we have an assignment with a user that is passed back to the caller.
3320          @retVal = ($1, $function);          @retVal = ($1, $function);
3321      }      }
3322        # If we have an assignment, we need to clean the function text. There may be
3323        # extra junk at the end added as a note from the user.
3324        if (@retVal) {
3325            $retVal[1] =~ s/(\t\S)?\s*$//;
3326        }
3327      # Return the result list.      # Return the result list.
3328      return @retVal;      return @retVal;
3329  }  }
# Line 3351  Line 3412 
3412  }  }
3413    
3414    
   
3415  1;  1;

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.56

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3