[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.47, Thu Oct 20 12:02:43 2005 UTC revision 1.57, Sat May 13 03:10:15 2006 UTC
# Line 62  Line 62 
62    
63  * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)  * B<xmlFileName> name of the XML file containing the database definition (default C<SproutDBD.xml>)
64    
65  * B<userData> user name and password, delimited by a slash (default C<root/>)  * B<userData> user name and password, delimited by a slash (default same as SEED)
66    
67  * B<port> connection port (default C<0>)  * B<port> connection port (default C<0>)
68    
69    * B<sock> connection socket (default same as SEED)
70    
71  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)  * B<maxSegmentLength> maximum number of residues per feature segment, (default C<4500>)
72    
73  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)
# Line 92  Line 94 
94                                                          # database type                                                          # database type
95                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
96                                                          # data file directory                                                          # data file directory
97                         xmlFileName  => "$FIG_Config::sproutData/SproutDBD.xml",                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",
98                                                          # database definition file name                                                          # database definition file name
99                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
100                                                          # user name and password                                                          # user name and password
101                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
102                                                          # database connection port                                                          # database connection port
103                           sock         => $FIG_Config::dbsock,
104                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
105                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
106                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 111  Line 114 
114      my $dbh;      my $dbh;
115      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
116          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
117                                  $password, $optionTable->{port});                                  $password, $optionTable->{port}, undef, $optionTable->{sock});
118      }      }
119      # Create the ERDB object.      # Create the ERDB object.
120      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
# Line 740  Line 743 
743  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,
744  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>.
745    
746    For example, the following would return the DNA sequence for contig C<83333.1:NC_000913>
747    between positions 1401 and 1532, inclusive.
748    
749        my $sequence = $sprout->DNASeq('83333.1:NC_000913_1401_1532');
750    
751  =over 4  =over 4
752    
753  =item locationList  =item locationList
754    
755  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
756  L</FeatureLocation> for more about this format).  I<contigID>C<_>I<begin>C<_>I<end> (see L</FeatureLocation> for more about this format).
757    
758  =item RETURN  =item RETURN
759    
# Line 1176  Line 1184 
1184          # Get the annotation fields.          # Get the annotation fields.
1185          my ($timeStamp, $text, $user) = @{$annotation};          my ($timeStamp, $text, $user) = @{$annotation};
1186          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
1187          my ($type, $function) = _ParseAssignment($text);          my ($actualUser, $function) = _ParseAssignment($user, $text);
1188          if ($type && ! exists $retVal{$user}) {          if ($actualUser && ! exists $retVal{$actualUser}) {
1189              # Here it is a functional assignment and there has been no              # Here it is a functional assignment and there has been no
1190              # previous assignment for this user, so we stuff it in the              # previous assignment for this user, so we stuff it in the
1191              # return hash.              # return hash.
1192              $retVal{$user} = $function;              $retVal{$actualUser} = $function;
1193          }          }
1194      }      }
1195      # Return the hash of assignments found.      # Return the hash of assignments found.
# Line 1259  Line 1267 
1267              }              }
1268          }          }
1269          # 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.
1270          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1271                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1272                                 [$featureID]);                                 [$featureID]);
1273          my $timeSelected = 0;          my $timeSelected = 0;
1274          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1275          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1276              # Get the annotation text.              # Get the annotation text.
1277              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1278                                                         'Annotation(time)', 'MadeAnnotation(from-link)']);
1279              # 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.
1280              my ($user, $function) = _ParseAssignment($text);              my ($actualUser, $function) = _ParseAssignment($user, $text);
1281              if ($user) {              Trace("Assignment user is $actualUser, text is $function.") if T(4);
1282                if ($actualUser) {
1283                  # Here it is a functional assignment. Check the time and the user                  # Here it is a functional assignment. Check the time and the user
1284                  # name. The time must be recent and the user must be trusted.                  # name. The time must be recent and the user must be trusted.
1285                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {                  if ((exists $trusteeTable{$actualUser}) && ($time > $timeSelected)) {
1286                      $retVal = $function;                      $retVal = $function;
1287                      $timeSelected = $time;                      $timeSelected = $time;
1288                  }                  }
# Line 1331  Line 1341 
1341          # users.          # users.
1342          my %trusteeTable = ();          my %trusteeTable = ();
1343          # 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.
1344          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1345                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1346                                 [$featureID]);                                 [$featureID]);
1347          my $timeSelected = 0;          my $timeSelected = 0;
1348          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1349          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
1350              # Get the annotation text.              # Get the annotation text.
1351              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time, $user) = $annotation->Values(['Annotation(annotation)',
1352                                                                'Annotation(time)',
1353                                                                'MadeAnnotation(user)']);
1354              # 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.
1355              my ($user, $function) = _ParseAssignment($text);              my ($actualUser, $function) = _ParseAssignment($user, $text);
1356              if ($user) {              if ($actualUser) {
1357                  # Here it is a functional assignment.                  # Here it is a functional assignment.
1358                  push @retVal, [$user, $function];                  push @retVal, [$actualUser, $function];
1359              }              }
1360          }          }
1361      } else {      } else {
1362          # 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
1363          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
1364          # table.          # table.
1365          push @retVal, $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);          my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,
1366                                                     ['ExternalAliasFunc(func)']);
1367            push @retVal, map { ['master', $_] } @assignments;
1368      }      }
1369      # Return the assignments found.      # Return the assignments found.
1370      return @retVal;      return @retVal;
# Line 1476  Line 1490 
1490      my $genomeData = $self->GetEntity('Genome', $genomeID);      my $genomeData = $self->GetEntity('Genome', $genomeID);
1491      if ($genomeData) {      if ($genomeData) {
1492          # The genome exists, so get the completeness flag.          # The genome exists, so get the completeness flag.
1493          ($retVal) = $genomeData->Value('complete');          ($retVal) = $genomeData->Value('Genome(complete)');
1494      }      }
1495      # Return the result.      # Return the result.
1496      return $retVal;      return $retVal;
# Line 1516  Line 1530 
1530    
1531  C<< my $genomeID = $sprout->GenomeOf($featureID); >>  C<< my $genomeID = $sprout->GenomeOf($featureID); >>
1532    
1533  Return the genome that contains a specified feature.  Return the genome that contains a specified feature or contig.
1534    
1535  =over 4  =over 4
1536    
1537  =item featureID  =item featureID
1538    
1539  ID of the feature whose genome is desired.  ID of the feature or contig whose genome is desired.
1540    
1541  =item RETURN  =item RETURN
1542    
1543  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
1544  an undefined value.  found, returns an undefined value.
1545    
1546  =back  =back
1547    
# Line 1536  Line 1550 
1550  sub GenomeOf {  sub GenomeOf {
1551      # Get the parameters.      # Get the parameters.
1552      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1553      # Create a query to find the genome associated with the feature.      # Create a query to find the genome associated with the incoming ID.
1554      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ?", [$featureID]);      my $query = $self->Get(['IsLocatedIn', 'HasContig'], "IsLocatedIn(from-link) = ? OR HasContig(to-link) = ?",
1555                               [$featureID, $featureID]);
1556      # Declare the return value.      # Declare the return value.
1557      my $retVal;      my $retVal;
1558      # Get the genome ID.      # Get the genome ID.
# Line 2724  Line 2739 
2739      return @retVal;      return @retVal;
2740  }  }
2741    
2742    
2743    
2744  =head3 RelatedFeatures  =head3 RelatedFeatures
2745    
2746  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 3215  Line 3232 
3232      return $retVal;      return $retVal;
3233  }  }
3234    
3235    =head3 DeleteGenome
3236    
3237    C<< my $stats = $sprout->DeleteGenome($genomeID, $testFlag); >>
3238    
3239    Delete a genome from the database.
3240    
3241    =over 4
3242    
3243    =item genomeID
3244    
3245    ID of the genome to delete
3246    
3247    =item testFlag
3248    
3249    If TRUE, then the DELETE statements will be traced, but no deletions will occur.
3250    
3251    =item RETURN
3252    
3253    Returns a statistics object describing the rows deleted.
3254    
3255    =back
3256    
3257    =cut
3258    #: Return Type $%;
3259    sub DeleteGenome {
3260        # Get the parameters.
3261        my ($self, $genomeID, $testFlag) = @_;
3262        # Perform the delete for the genome's features.
3263        my $retVal = $self->{_erdb}->Delete('Feature', "fig|$genomeID.%", $testFlag);
3264        # Perform the delete for the primary genome data.
3265        my $stats = $self->{_erdb}->Delete('Genome', $genomeID, $testFlag);
3266        $retVal->Accumulate($stats);
3267        # Return the result.
3268        return $retVal;
3269    }
3270    
3271  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3272    
3273  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3225  Line 3278 
3278    
3279  A functional assignment is always of the form  A functional assignment is always of the form
3280    
3281      I<XXXX>C<\nset >I<YYYY>C< function to\n>I<ZZZZZ>      C<set >I<YYYY>C< function to\n>I<ZZZZZ>
3282    
3283  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,
3284  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
3285  same, but that is not always the case.  not always the case.
3286    
3287    In addition, the functional role may contain extra data that is stripped, such as
3288    terminating spaces or a comment separated from the rest of the text by a tab.
3289    
3290  This is a static method.  This is a static method.
3291    
3292  =over 4  =over 4
3293    
3294    =item user
3295    
3296    Name of the assigning user.
3297    
3298  =item text  =item text
3299    
3300  Text of the annotation.  Text of the annotation.
# Line 3250  Line 3310 
3310    
3311  sub _ParseAssignment {  sub _ParseAssignment {
3312      # Get the parameters.      # Get the parameters.
3313      my ($text) = @_;      my ($user, $text) = @_;
3314      # Declare the return value.      # Declare the return value.
3315      my @retVal = ();      my @retVal = ();
3316      # Check to see if this is a functional assignment.      # Check to see if this is a functional assignment.
3317      my ($type, $function) = split(/\n/, $text);      my ($type, $function) = split(/\n/, $text);
3318      if ($type =~ m/^set ([^ ]+) function to$/i) {      if ($type =~ m/^set function to$/i) {
3319          # 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.
3320          # and the assigning user.          @retVal = ($user, $function);
3321        } elsif ($type =~ m/^set (\S+) function to$/i) {
3322            # Here we have an assignment with a user that is passed back to the caller.
3323          @retVal = ($1, $function);          @retVal = ($1, $function);
3324      }      }
3325        # If we have an assignment, we need to clean the function text. There may be
3326        # extra junk at the end added as a note from the user.
3327        if (@retVal) {
3328            $retVal[1] =~ s/(\t\S)?\s*$//;
3329        }
3330      # Return the result list.      # Return the result list.
3331      return @retVal;      return @retVal;
3332  }  }
# Line 3348  Line 3415 
3415  }  }
3416    
3417    
   
3418  1;  1;

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.57

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3