[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.18, Tue Jun 28 21:34:15 2005 UTC
# Line 86  Line 86 
86          # Compute the options. We do this by starting with a table of defaults and overwriting with          # Compute the options. We do this by starting with a table of defaults and overwriting with
87          # the incoming data.          # the incoming data.
88          my $optionTable = Tracer::GetOptions({          my $optionTable = Tracer::GetOptions({
89                                             dbType               => 'mysql',                     # database type                         dbType       => $FIG_Config::dbms,
90                                             dataDir              => 'Data',                      # data file directory                                                          # database type
91                                             xmlFileName  => 'SproutDBD.xml', # database definition file name                         dataDir      => $FIG_Config::sproutData,
92                                             userData             => 'root/',                     # user name and password                                                          # data file directory
93                                             port                 => 0,                           # database connection port                         xmlFileName  => "$FIG_Config::sproutData/SproutDBD.xml",
94                                                            # database definition file name
95                           userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
96                                                            # user name and password
97                           port         => $FIG_Config::dbport,
98                                                            # database connection port
99                                             maxSegmentLength => 4500,            # maximum feature segment length                                             maxSegmentLength => 4500,            # maximum feature segment length
100                                             maxSequenceLength => 8000,           # maximum contig sequence length                                             maxSequenceLength => 8000,           # maximum contig sequence length
101                                            }, $options);                                            }, $options);
# Line 269  Line 274 
274  sub GetEntity {  sub GetEntity {
275          # Get the parameters.          # Get the parameters.
276          my ($self, $entityType, $ID) = @_;          my ($self, $entityType, $ID) = @_;
277          # Create a query.      # Call the ERDB method.
278          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;  
279  }  }
280    
281  =head3 GetEntityValues  =head3 GetEntityValues
# Line 308  Line 309 
309  sub GetEntityValues {  sub GetEntityValues {
310          # Get the parameters.          # Get the parameters.
311          my ($self, $entityType, $ID, $fields) = @_;          my ($self, $entityType, $ID, $fields) = @_;
312          # Get the specified entity.      # Call the ERDB method.
313          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;  
314  }  }
315    
316  =head3 ShowMetaData  =head3 ShowMetaData
# Line 432  Line 425 
425          # Loop through the incoming table names.          # Loop through the incoming table names.
426          for my $tableName (@{$tableList}) {          for my $tableName (@{$tableList}) {
427                  # Find the table's file.                  # Find the table's file.
428                  my $fileName = "$dataDir/$tableName";          my $fileName = LoadFileName($dataDir, $tableName);
429                  if (! -e $fileName) {          if (! $fileName) {
430                          $fileName = "$fileName.dtx";              Trace("No load file found for $tableName in $dataDir.") if T(0);
431                  }          } else {
432                  # Attempt to load this table.                  # Attempt to load this table.
433                  my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);                  my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);
434                  # Accumulate the resulting statistics.                  # Accumulate the resulting statistics.
435                  $retVal->Accumulate($result);                  $retVal->Accumulate($result);
436          }          }
437        }
438          # Return the statistics.          # Return the statistics.
439          return $retVal;          return $retVal;
440  }  }
# Line 1070  Line 1064 
1064  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>  C<< my %functions = $sprout->AllFunctionsOf($featureID); >>
1065    
1066  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
1067  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,
1068  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
1069  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,
1070  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.
1071  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
1072  functional assignments, we will only keep the most recent one.  recent one.
1073    
1074  =over 4  =over 4
1075    
# Line 1109  Line 1103 
1103          # Get the annotation fields.          # Get the annotation fields.
1104          my ($timeStamp, $text) = @{$annotation};          my ($timeStamp, $text) = @{$annotation};
1105                  # Check to see if this is a functional assignment.                  # Check to see if this is a functional assignment.
1106                  my ($user, $function) = ParseAssignment($text);          my ($user, $function) = _ParseAssignment($text);
1107          if ($user && ! exists $timeHash{$user}) {          if ($user && ! exists $timeHash{$user}) {
1108              # Here it is a functional assignment and there has been no              # Here it is a functional assignment and there has been no
1109              # 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 1125 
1125    
1126  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
1127  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
1128  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
1129  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
1130  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
1131  is not a big problem because most features only have a small number of annotations.  most features only have a small number of annotations.
1132    
1133  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
1134  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 1197 
1197              # Get the annotation text.              # Get the annotation text.
1198              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);              my ($text, $time) = $annotation->Values(['Annotation(annotation)','Annotation(time)']);
1199              # 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.
1200              my ($user, $type, $function) = split(/\n/, $text);              my ($user, $function) = _ParseAssignment($text);
1201              if ($type =~ m/^set $user function to$/i) {              if ($user) {
1202                  # Here it is a functional assignment. Check the time and the user                  # Here it is a functional assignment. Check the time and the user
1203                  # name. The time must be recent and the user must be trusted.                  # name. The time must be recent and the user must be trusted.
1204                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {                  if ((exists $trusteeTable{$user}) && ($time > $timeSelected)) {
# Line 1242  Line 1236 
1236    
1237  =item RETURN  =item RETURN
1238    
1239  Returns a reference to a hash that maps the IDs of the incoming features to the IDs of  Returns a reference to a hash that maps the IDs of the incoming features to the best hits
1240  their best hits.  on the target genome.
1241    
1242  =back  =back
1243    
# Line 1271  Line 1265 
1265          return \%retVal;          return \%retVal;
1266  }  }
1267    
1268    =head3 SimList
1269    
1270    C<< my %similarities = $sprout->SimList($featureID, $count); >>
1271    
1272    Return a list of the similarities to the specified feature.
1273    
1274    Sprout does not support real similarities, so this method just returns the bidirectional
1275    best hits.
1276    
1277    =over 4
1278    
1279    =item featureID
1280    
1281    ID of the feature whose similarities are desired.
1282    
1283    =item count
1284    
1285    Maximum number of similar features to be returned, or C<0> to return them all.
1286    
1287    =back
1288    
1289    =cut
1290    #: Return Type %;
1291    sub SimList {
1292        # Get the parameters.
1293        my ($self, $featureID, $count) = @_;
1294        # Ask for the best hits.
1295        my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],
1296                                  "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",
1297                                  [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],
1298                                  $count);
1299        # Create the return value.
1300        my %retVal = ();
1301        for my $tuple (@lists) {
1302            $retVal{$tuple->[0]} = $tuple->[1];
1303        }
1304        # Return the result.
1305        return %retVal;
1306    }
1307    
1308    
1309    
1310    =head3 IsComplete
1311    
1312    C<< my $flag = $sprout->IsComplete($genomeID); >>
1313    
1314    Return TRUE if the specified genome is complete, else FALSE.
1315    
1316    =over 4
1317    
1318    =item genomeID
1319    
1320    ID of the genome whose completeness status is desired.
1321    
1322    =item RETURN
1323    
1324    Returns TRUE if the genome is complete, FALSE if it is incomplete, and C<undef> if it is
1325    not found.
1326    
1327    =back
1328    
1329    =cut
1330    #: Return Type $;
1331    sub IsComplete {
1332        # Get the parameters.
1333        my ($self, $genomeID) = @_;
1334        # Declare the return variable.
1335        my $retVal;
1336        # Get the genome's data.
1337        my $genomeData = $self->GetEntity('Genome', $genomeID);
1338        if ($genomeData) {
1339            # The genome exists, so get the completeness flag.
1340            ($retVal) = $genomeData->Value('complete');
1341        }
1342        # Return the result.
1343        return $retVal;
1344    }
1345    
1346  =head3 FeatureAliases  =head3 FeatureAliases
1347    
1348  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>
# Line 1361  Line 1433 
1433  sub CoupledFeatures {  sub CoupledFeatures {
1434          # Get the parameters.          # Get the parameters.
1435          my ($self, $featureID) = @_;          my ($self, $featureID) = @_;
1436          # Create a query to retrieve the functionally-coupled features. Note that we depend on the      # Create a query to retrieve the functionally-coupled features.
1437          # fact that the functional coupling is physically paired. If (A,B) is in the database, then      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1438          # (B,A) will also be found.                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);
         my $query = $self->Get(['IsClusteredOnChromosomeWith'],  
                                                    "IsClusteredOnChromosomeWith(from-link) = ?", [$featureID]);  
1439          # 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.
1440          my $found = 0;          my $found = 0;
1441          # Create the return hash.          # Create the return hash.
1442          my %retVal = ();          my %retVal = ();
1443          # Retrieve the relationship records and store them in the hash.          # Retrieve the relationship records and store them in the hash.
1444          while (my $clustering = $query->Fetch()) {          while (my $clustering = $query->Fetch()) {
1445                  my ($otherFeatureID, $score) = $clustering->Values(['IsClusteredOnChromosomeWith(to-link)',          # Get the ID and score of the coupling.
1446                                                                      'IsClusteredOnChromosomeWith(score)']);          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1447                                                            'Coupling(score)']);
1448            # The coupling ID contains the two feature IDs separated by a space. We use
1449            # this information to find the ID of the other feature.
1450            my ($fid1, $fid2) = split / /, $couplingID;
1451            my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);
1452            # Attach the other feature's score to its ID.
1453                  $retVal{$otherFeatureID} = $score;                  $retVal{$otherFeatureID} = $score;
1454                  $found = 1;                  $found = 1;
1455          }          }
# Line 1386  Line 1462 
1462          return %retVal;          return %retVal;
1463  }  }
1464    
1465    =head3 CouplingEvidence
1466    
1467    C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>
1468    
1469    Return the evidence for a functional coupling.
1470    
1471    A pair of features is considered evidence of a coupling between two other
1472    features if they occur close together on a contig and both are similar to
1473    the coupled features. So, if B<A1> and B<A2> are close together on a contig,
1474    B<B1> and B<B2> are considered evidence for the coupling if (1) B<B1> and
1475    B<B2> are close together, (2) B<B1> is similar to B<A1>, and (3) B<B2> is
1476    similar to B<A2>.
1477    
1478    The score of a coupling is determined by the number of pieces of evidence
1479    that are considered I<representative>. If several evidence items belong to
1480    a group of genomes that are close to each other, only one of those items
1481    is considered representative. The other evidence items are presumed to be
1482    there because of the relationship between the genomes rather than because
1483    the two proteins generated by the features have a related functionality.
1484    
1485    Each evidence item is returned as a three-tuple in the form C<[>I<$peg1a>C<,>
1486    I<$peg2a>C<,> I<$rep>C<]>, where I<$peg1a> is similar to I<$peg1>, I<$peg2a>
1487    is similar to I<$peg2>, and I<$rep> is TRUE if the evidence is representative
1488    and FALSE otherwise.
1489    
1490    =over 4
1491    
1492    =item peg1
1493    
1494    ID of the feature of interest.
1495    
1496    =item peg2
1497    
1498    ID of a feature functionally coupled to the feature of interest.
1499    
1500    =item RETURN
1501    
1502    Returns a list of 3-tuples. Each tuple consists of a feature similar to the feature
1503    of interest, a feature similar to the functionally coupled feature, and a flag
1504    that is TRUE for a representative piece of evidence and FALSE otherwise.
1505    
1506    =back
1507    
1508    =cut
1509    #: Return Type @@;
1510    sub CouplingEvidence {
1511        # Get the parameters.
1512        my ($self, $peg1, $peg2) = @_;
1513        # Declare the return variable.
1514        my @retVal = ();
1515        # Our first task is to find out the nature of the coupling: whether or not
1516        # it exists, its score, and whether the features are stored in the same
1517        # order as the ones coming in.
1518        my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);
1519        # Only proceed if a coupling exists.
1520        if ($couplingID) {
1521            # Determine the ordering to place on the evidence items. If we're
1522            # inverted, we want to see feature 2 before feature 1 (descending); otherwise,
1523            # we want feature 1 before feature 2 (normal).
1524            my $ordering = ($inverted ? "DESC" : "");
1525            # Get the coupling evidence.
1526            my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
1527                                              "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",
1528                                              [$couplingID],
1529                                              ['PCH(used)', 'UsesAsEvidence(to-link)']);
1530            # Loop through the evidence items. Each piece of evidence is represented by two
1531            # positions in the evidence list, one for each feature on the other side of the
1532            # evidence link. If at some point we want to generalize to couplings with
1533            # more than two positions, this section of code will need to be re-done.
1534            while (@evidenceList > 0) {
1535                my $peg1Data = shift @evidenceList;
1536                my $peg2Data = shift @evidenceList;
1537                push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1538            }
1539        }
1540        # Return the result.
1541        return @retVal;
1542    }
1543    
1544    =head3 GetCoupling
1545    
1546    C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>
1547    
1548    Return the coupling (if any) for the specified pair of PEGs. If a coupling
1549    exists, we return the coupling ID along with an indicator of whether the
1550    coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.
1551    In the second case, we say the coupling is I<inverted>. The importance of an
1552    inverted coupling is that the PEGs in the evidence will appear in reverse order.
1553    
1554    =over 4
1555    
1556    =item peg1
1557    
1558    ID of the feature of interest.
1559    
1560    =item peg2
1561    
1562    ID of the potentially coupled feature.
1563    
1564    =item RETURN
1565    
1566    Returns a three-element list. The first element contains the database ID of
1567    the coupling. The second element is FALSE if the coupling is stored in the
1568    database in the caller specified order and TRUE if it is stored in the
1569    inverted order. The third element is the coupling's score. If the coupling
1570    does not exist, all three list elements will be C<undef>.
1571    
1572    =back
1573    
1574    =cut
1575    #: Return Type $%@;
1576    sub GetCoupling {
1577        # Get the parameters.
1578        my ($self, $peg1, $peg2) = @_;
1579        # Declare the return values. We'll start with the coupling ID and undefine the
1580        # flag and score until we have more information.
1581        my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);
1582        # Find the coupling data.
1583        my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],
1584                                     "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",
1585                                     [$retVal], ["ParticipatesInCoupling(from-link)", "Coupling(score)"]);
1586        # Check to see if we found anything.
1587        if (!@pegs) {
1588            # No coupling, so undefine the return value.
1589            $retVal = undef;
1590        } else {
1591            # We have a coupling! Get the score and check for inversion.
1592            $score = $pegs[0]->[1];
1593            $inverted = ($pegs[0]->[0] eq $peg1);
1594        }
1595        # Return the result.
1596        return ($retVal, $inverted, $score);
1597    }
1598    
1599    =head3 CouplingID
1600    
1601    C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>
1602    
1603    Return the coupling ID for a pair of feature IDs.
1604    
1605    The coupling ID is currently computed by joining the feature IDs in
1606    sorted order with a space. Client modules (that is, modules which
1607    use Sprout) should not, however, count on this always being the
1608    case. This method provides a way for abstracting the concept of a
1609    coupling ID. All that we know for sure about it is that it can be
1610    generated easily from the feature IDs and the order of the IDs
1611    in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>
1612    will have the same value as C<CouplingID("b1", "a1")>.
1613    
1614    =over 4
1615    
1616    =item peg1
1617    
1618    First feature of interest.
1619    
1620    =item peg2
1621    
1622    Second feature of interest.
1623    
1624    =item RETURN
1625    
1626    Returns the ID that would be used to represent a functional coupling of
1627    the two specified PEGs.
1628    
1629    =back
1630    
1631    =cut
1632    #: Return Type $;
1633    sub CouplingID {
1634        return join " ", sort @_;
1635    }
1636    
1637  =head3 GetEntityTypes  =head3 GetEntityTypes
1638    
1639  C<< my @entityList = $sprout->GetEntityTypes(); >>  C<< my @entityList = $sprout->GetEntityTypes(); >>
# Line 1447  Line 1695 
1695                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {
1696                          # 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.
1697                          if ($id) {                          if ($id) {
1698                                  $retVal{$id} = $sequence;                  $retVal{$id} = uc $sequence;
1699                          }                          }
1700                          # Clear the sequence accumulator and save the new ID.                          # Clear the sequence accumulator and save the new ID.
1701                          ($id, $sequence) = ("$prefix$1", "");                          ($id, $sequence) = ("$prefix$1", "");
1702                  } else {                  } else {
1703                          # 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.
1704                          # First, we get the actual data out.              # First, we get the actual data out. Note that we normalize to upper
1705                # case.
1706                          $line =~ /^\s*(.*?)(\s|\n)/;                          $line =~ /^\s*(.*?)(\s|\n)/;
1707                          $sequence .= $1;                          $sequence .= $1;
1708                  }                  }
1709          }          }
1710          # Flush out the last sequence (if any).          # Flush out the last sequence (if any).
1711          if ($sequence) {          if ($sequence) {
1712                  $retVal {$id} = $sequence;          $retVal{$id} = uc $sequence;
1713          }          }
1714        # Close the file.
1715        close FASTAFILE;
1716          # Return the hash constructed from the file.          # Return the hash constructed from the file.
1717          return %retVal;          return %retVal;
1718  }  }
# Line 1577  Line 1828 
1828  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
1829  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
1830    
1831  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>  C<< $sprout->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>
1832    
1833  =over 4  =over 4
1834    
# Line 1656  Line 1907 
1907    
1908  =head3 AssignFunction  =head3 AssignFunction
1909    
1910  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function); >>  C<< my $ok = $sprout->AssignFunction($featureID, $user, $function, $assigningUser); >>
1911    
1912  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
1913  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.  
1914    
1915  =over 4  =over 4
1916    
# Line 1670  Line 1920 
1920    
1921  =item user  =item user
1922    
1923  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>.
1924    
1925  =item function  =item function
1926    
1927  Text of the function being assigned.  Text of the function being assigned.
1928    
1929    =item assigningUser (optional)
1930    
1931    Name of the individual user making the assignment. If omitted, defaults to the user group.
1932    
1933  =item RETURN  =item RETURN
1934    
1935  Returns 1 if successful, 0 if an error occurred.  Returns 1 if successful, 0 if an error occurred.
# Line 1686  Line 1940 
1940  #: Return Type $;  #: Return Type $;
1941  sub AssignFunction {  sub AssignFunction {
1942          # Get the parameters.          # Get the parameters.
1943          my ($self, $featureID, $user, $function) = @_;      my ($self, $featureID, $user, $function, $assigningUser) = @_;
1944        # Default the assigning user.
1945        if (! $assigningUser) {
1946            $assigningUser = $user;
1947        }
1948          # Create an annotation string from the parameters.          # Create an annotation string from the parameters.
1949          my $annotationText = "$user\nset $user function to\n$function";      my $annotationText = "$assigningUser\nset $user function to\n$function";
1950          # Get the current time.          # Get the current time.
1951          my $now = time;          my $now = time;
1952          # Declare the return variable.          # Declare the return variable.
# Line 2181  Line 2439 
2439  sub SubsystemsOf {  sub SubsystemsOf {
2440          # Get the parameters.          # Get the parameters.
2441          my ($self, $featureID) = @_;          my ($self, $featureID) = @_;
2442          # Use the SSCell to connect features to subsystems.      # Get the subsystem list.
2443          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],
2444                                                                          "ContainsFeature(to-link) = ?", [$featureID],                                                                          "ContainsFeature(to-link) = ?", [$featureID],
2445                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);
# Line 2195  Line 2453 
2453          return %retVal;          return %retVal;
2454  }  }
2455    
2456    =head3 SubsystemList
2457    
2458    C<< my @subsystems = $sprout->SubsystemList($featureID); >>
2459    
2460    Return a list containing the names of the subsystems in which the specified
2461    feature participates. Unlike L</SubsystemsOf>, this method only returns the
2462    subsystem names, not the roles.
2463    
2464    =over 4
2465    
2466    =item featureID
2467    
2468    ID of the feature whose subsystem names are desired.
2469    
2470    =item RETURN
2471    
2472    Returns a list of the names of the subsystems in which the feature participates.
2473    
2474    =back
2475    
2476    =cut
2477    #: Return Type @;
2478    sub SubsystemList {
2479        # Get the parameters.
2480        my ($self, $featureID) = @_;
2481        # Get the list of names.
2482        my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",
2483                                    [$featureID], 'HasSSCell(from-link)');
2484        # Return the result.
2485        return @retVal;
2486    }
2487    
2488  =head3 RelatedFeatures  =head3 RelatedFeatures
2489    
2490  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 2355  Line 2645 
2645  sub GetAll {  sub GetAll {
2646          # Get the parameters.          # Get the parameters.
2647          my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;          my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;
2648          # Create the query.      # Call the ERDB method.
2649          my $query = $self->Get($objectNames, $filterClause, $parameterList);      my @retVal = $self->{_erdb}->GetAll($objectNames, $filterClause, $parameterList,
2650          # 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++;  
         }  
2651          # Return the resulting list.          # Return the resulting list.
2652          return @retVal;          return @retVal;
2653  }  }
# Line 2626  Line 2903 
2903      return %retVal;      return %retVal;
2904  }  }
2905    
2906    =head3 MyGenomes
2907    
2908    C<< my @genomes = Sprout::MyGenomes($dataDir); >>
2909    
2910    Return a list of the genomes to be included in the Sprout.
2911    
2912    This method is provided for use during the Sprout load. It presumes the Genome load file has
2913    already been created. (It will be in the Sprout data directory and called either C<Genome>
2914    or C<Genome.dtx>.) Essentially, it reads in the Genome load file and strips out the genome
2915    IDs.
2916    
2917    =over 4
2918    
2919    =item dataDir
2920    
2921    Directory containing the Sprout load files.
2922    
2923    =back
2924    
2925    =cut
2926    #: Return Type @;
2927    sub MyGenomes {
2928        # Get the parameters.
2929        my ($dataDir) = @_;
2930        # Compute the genome file name.
2931        my $genomeFileName = LoadFileName($dataDir, "Genome");
2932        # Extract the genome IDs from the files.
2933        my @retVal = map { $_ =~ /^(\S+)/; $1 } Tracer::GetFile($genomeFileName);
2934        # Return the result.
2935        return @retVal;
2936    }
2937    
2938    =head3 LoadFileName
2939    
2940    C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>
2941    
2942    Return the name of the load file for the specified table in the specified data
2943    directory.
2944    
2945    =over 4
2946    
2947    =item dataDir
2948    
2949    Directory containing the Sprout load files.
2950    
2951    =item tableName
2952    
2953    Name of the table whose load file is desired.
2954    
2955    =item RETURN
2956    
2957    Returns the name of the file containing the load data for the specified table, or
2958    C<undef> if no load file is present.
2959    
2960    =back
2961    
2962    =cut
2963    #: Return Type $;
2964    sub LoadFileName {
2965        # Get the parameters.
2966        my ($dataDir, $tableName) = @_;
2967        # Declare the return variable.
2968        my $retVal;
2969        # Check for the various file names.
2970        if (-e "$dataDir/$tableName") {
2971            $retVal = "$dataDir/$tableName";
2972        } elsif (-e "$dataDir/$tableName.dtx") {
2973            $retVal = "$dataDir/$tableName.dtx";
2974        }
2975        # Return the result.
2976        return $retVal;
2977    }
2978    
2979  =head2 Internal Utility Methods  =head2 Internal Utility Methods
2980    
2981  =head3 ParseAssignment  =head3 ParseAssignment
2982    
2983  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,
2984  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
2985  will be returned.  isn't, an empty list will be returned.
2986    
2987    A functional assignment is always of the form
2988    
2989        I<XXXX>C<\nset >I<YYYY>C< function to\n>I<ZZZZZ>
2990    
2991    where I<XXXX> is the B<assigning user>, I<YYYY> is the B<user>, and I<ZZZZ> is the
2992    actual functional role. In most cases, the user and the assigning user will be the
2993    same, but that is not always the case.
2994    
2995  This is a static method.  This is a static method.
2996    
# Line 2651  Line 3009 
3009    
3010  =cut  =cut
3011    
3012  sub ParseAssignment {  sub _ParseAssignment {
3013          # Get the parameters.          # Get the parameters.
3014          my ($text) = @_;          my ($text) = @_;
3015          # Declare the return value.          # Declare the return value.
3016          my @retVal = ();          my @retVal = ();
3017          # Check to see if this is a functional assignment.          # Check to see if this is a functional assignment.
3018          my ($user, $type, $function) = split(/\n/, $text);          my ($user, $type, $function) = split(/\n/, $text);
3019          if ($type =~ m/^set $user function to$/i) {      if ($type =~ m/^set ([^ ]+) function to$/i) {
3020                  # 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,
3021                  @retVal = ($user, $function);          # and the assigning user.
3022            @retVal = ($1, $function, $user);
3023          }          }
3024          # Return the result list.          # Return the result list.
3025          return @retVal;          return @retVal;
# Line 2692  Line 3051 
3051      return $retVal;      return $retVal;
3052  }  }
3053    
3054    =head3 AddProperty
3055    
3056    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3057    
3058    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3059    be added to almost any object. In Sprout, they can only be added to features. In
3060    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3061    pair. If the particular key/value pair coming in is not already in the database, a new
3062    B<Property> record is created to hold it.
3063    
3064    =over 4
3065    
3066    =item peg
3067    
3068    ID of the feature to which the attribute is to be replied.
3069    
3070    =item key
3071    
3072    Name of the attribute (key).
3073    
3074    =item value
3075    
3076    Value of the attribute.
3077    
3078    =item url
3079    
3080    URL or text citation from which the property was obtained.
3081    
3082    =back
3083    
3084    =cut
3085    #: Return Type ;
3086    sub AddProperty {
3087        # Get the parameters.
3088        my ($self, $featureID, $key, $value, $url) = @_;
3089        # Declare the variable to hold the desired property ID.
3090        my $propID;
3091        # Attempt to find a property record for this key/value pair.
3092        my @properties = $self->GetFlat(['Property'],
3093                                       "Property(property-name) = ? AND Property(property-value) = ?",
3094                                       [$key, $value], 'Property(id)');
3095        if (@properties) {
3096            # Here the property is already in the database. We save its ID.
3097            $propID = $properties[0];
3098            # Here the property value does not exist. We need to generate an ID. It will be set
3099            # to a number one greater than the maximum value in the database. This call to
3100            # GetAll will stop after one record.
3101            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3102                                            1);
3103            $propID = $maxProperty[0]->[0] + 1;
3104            # Insert the new property value.
3105            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3106        }
3107        # Now we connect the incoming feature to the property.
3108        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3109    }
3110    
3111  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3