[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.14, Thu Jun 9 19:06:55 2005 UTC revision 1.29, Wed Sep 14 13:06:53 2005 UTC
# Line 70  Line 70 
70    
71  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)  * B<maxSequenceLength> maximum number of residues per sequence, (default C<8000>)
72    
73    * B<noDBOpen> suppresses the connection to the database if TRUE, else FALSE
74    
75  =back  =back
76    
77  For example, the following constructor call specifies a database named I<Sprout> and a user name of  For example, the following constructor call specifies a database named I<Sprout> and a user name of
# Line 86  Line 88 
88          # 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
89          # the incoming data.          # the incoming data.
90          my $optionTable = Tracer::GetOptions({          my $optionTable = Tracer::GetOptions({
91                                             dbType               => 'mysql',                     # database type                         dbType       => $FIG_Config::dbms,
92                                             dataDir              => 'Data',                      # data file directory                                                          # database type
93                                             xmlFileName  => 'SproutDBD.xml', # database definition file name                         dataDir      => $FIG_Config::sproutData,
94                                             userData             => 'root/',                     # user name and password                                                          # data file directory
95                                             port                 => 0,                           # database connection port                         xmlFileName  => "$FIG_Config::sproutData/SproutDBD.xml",
96                                                            # database definition file name
97                           userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
98                                                            # user name and password
99                           port         => $FIG_Config::dbport,
100                                                            # database connection port
101                                             maxSegmentLength => 4500,            # maximum feature segment length                                             maxSegmentLength => 4500,            # maximum feature segment length
102                                             maxSequenceLength => 8000,           # maximum contig sequence length                                             maxSequenceLength => 8000,           # maximum contig sequence length
103                           noDBOpen     => 0,               # 1 to suppress the database open
104                                            }, $options);                                            }, $options);
105          # Get the data directory.          # Get the data directory.
106          my $dataDir = $optionTable->{dataDir};          my $dataDir = $optionTable->{dataDir};
# Line 100  Line 108 
108          $optionTable->{userData} =~ m!([^/]*)/(.*)$!;          $optionTable->{userData} =~ m!([^/]*)/(.*)$!;
109          my ($userName, $password) = ($1, $2);          my ($userName, $password) = ($1, $2);
110          # Connect to the database.          # Connect to the database.
111          my $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName, $password, $optionTable->{port});      my $dbh;
112        if (! $optionTable->{noDBOpen}) {
113            $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
114                                    $password, $optionTable->{port});
115        }
116          # Create the ERDB object.          # Create the ERDB object.
117          my $xmlFileName = "$optionTable->{xmlFileName}";          my $xmlFileName = "$optionTable->{xmlFileName}";
118          my $erdb = ERDB->new($dbh, $xmlFileName);          my $erdb = ERDB->new($dbh, $xmlFileName);
# Line 420  Line 432 
432          # Loop through the incoming table names.          # Loop through the incoming table names.
433          for my $tableName (@{$tableList}) {          for my $tableName (@{$tableList}) {
434                  # Find the table's file.                  # Find the table's file.
435                  my $fileName = "$dataDir/$tableName";          my $fileName = LoadFileName($dataDir, $tableName);
436                  if (! -e $fileName) {          if (! $fileName) {
437                          $fileName = "$fileName.dtx";              Trace("No load file found for $tableName in $dataDir.") if T(0);
438                  }          } else {
439                  # Attempt to load this table.                  # Attempt to load this table.
440                  my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);                  my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);
441                  # Accumulate the resulting statistics.                  # Accumulate the resulting statistics.
442                  $retVal->Accumulate($result);                  $retVal->Accumulate($result);
443          }          }
444        }
445          # Return the statistics.          # Return the statistics.
446          return $retVal;          return $retVal;
447  }  }
# Line 570  Line 583 
583  =item RETURN  =item RETURN
584    
585  Returns a list of the feature's contig segments. The locations are returned as a list in a list  Returns a list of the feature's contig segments. The locations are returned as a list in a list
586  context and as a space-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context.
587    
588  =back  =back
589    
# Line 613  Line 626 
626                  push @retVal, "${contigID}_$beg$dir$len";                  push @retVal, "${contigID}_$beg$dir$len";
627          }          }
628          # Return the list in the format indicated by the context.          # Return the list in the format indicated by the context.
629          return (wantarray ? @retVal : join(' ', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
630  }  }
631    
632  =head3 ParseLocation  =head3 ParseLocation
# Line 756  Line 769 
769                          $start = $beg;                          $start = $beg;
770                          $stop = $beg + $len - 1;                          $stop = $beg + $len - 1;
771                  } else {                  } else {
772                          $start = $beg + $len + 1;              $start = $beg - $len + 1;
773                          $stop = $beg;                          $stop = $beg;
774                  }                  }
775            Trace("Looking for sequences containing $start through $stop.") if T(SDNA => 4);
776                  my $query = $self->Get(['IsMadeUpOf','Sequence'],                  my $query = $self->Get(['IsMadeUpOf','Sequence'],
777                          "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .                          "IsMadeUpOf(from-link) = ? AND IsMadeUpOf(start-position) + IsMadeUpOf(len) > ? AND " .
778                          " IsMadeUpOf(start-position) <= ? ORDER BY IsMadeUpOf(start-position)",                          " IsMadeUpOf(start-position) <= ? ORDER BY IsMadeUpOf(start-position)",
# Line 770  Line 784 
784                                  $sequence->Values(['IsMadeUpOf(start-position)', 'Sequence(sequence)',                                  $sequence->Values(['IsMadeUpOf(start-position)', 'Sequence(sequence)',
785                                                                     'IsMadeUpOf(len)']);                                                                     'IsMadeUpOf(len)']);
786                          my $stopPosition = $startPosition + $sequenceLength;                          my $stopPosition = $startPosition + $sequenceLength;
787                Trace("Sequence is from $startPosition to $stopPosition.") if T(SDNA => 4);
788                          # Figure out the start point and length of the relevant section.                          # Figure out the start point and length of the relevant section.
789                          my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);                          my $pos1 = ($start < $startPosition ? 0 : $start - $startPosition);
790                          my $len = ($stopPosition <= $stop ? $stopPosition : $stop) - $startPosition - $pos1;              my $len1 = ($stopPosition <= $stop ? $stopPosition : $stop) - $startPosition - $pos1;
791                Trace("Position is $pos1 for length $len1.") if T(SDNA => 4);
792                          # Add the relevant data to the location data.                          # Add the relevant data to the location data.
793                          $locationDNA .= substr($sequenceData, $pos1, $len);              $locationDNA .= substr($sequenceData, $pos1, $len1);
794                  }                  }
795                  # Add this location's data to the return string. Note that we may need to reverse it.                  # Add this location's data to the return string. Note that we may need to reverse it.
796                  if ($dir eq '+') {                  if ($dir eq '+') {
797                          $retVal .= $locationDNA;                          $retVal .= $locationDNA;
798                  } else {                  } else {
799                          $locationDNA = join('', reverse split //, $locationDNA);              $retVal .= FIG::reverse_comp($locationDNA);
                         $retVal .= $locationDNA;  
800                  }                  }
801          }          }
802          # Return the result.          # Return the result.
# Line 1230  Line 1245 
1245    
1246  =item RETURN  =item RETURN
1247    
1248  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
1249  their best hits.  on the target genome.
1250    
1251  =back  =back
1252    
# Line 1259  Line 1274 
1274          return \%retVal;          return \%retVal;
1275  }  }
1276    
1277    =head3 SimList
1278    
1279    C<< my %similarities = $sprout->SimList($featureID, $count); >>
1280    
1281    Return a list of the similarities to the specified feature.
1282    
1283    Sprout does not support real similarities, so this method just returns the bidirectional
1284    best hits.
1285    
1286    =over 4
1287    
1288    =item featureID
1289    
1290    ID of the feature whose similarities are desired.
1291    
1292    =item count
1293    
1294    Maximum number of similar features to be returned, or C<0> to return them all.
1295    
1296    =back
1297    
1298    =cut
1299    #: Return Type %;
1300    sub SimList {
1301        # Get the parameters.
1302        my ($self, $featureID, $count) = @_;
1303        # Ask for the best hits.
1304        my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],
1305                                  "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",
1306                                  [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],
1307                                  $count);
1308        # Create the return value.
1309        my %retVal = ();
1310        for my $tuple (@lists) {
1311            $retVal{$tuple->[0]} = $tuple->[1];
1312        }
1313        # Return the result.
1314        return %retVal;
1315    }
1316    
1317    
1318    
1319    =head3 IsComplete
1320    
1321    C<< my $flag = $sprout->IsComplete($genomeID); >>
1322    
1323    Return TRUE if the specified genome is complete, else FALSE.
1324    
1325    =over 4
1326    
1327    =item genomeID
1328    
1329    ID of the genome whose completeness status is desired.
1330    
1331    =item RETURN
1332    
1333    Returns TRUE if the genome is complete, FALSE if it is incomplete, and C<undef> if it is
1334    not found.
1335    
1336    =back
1337    
1338    =cut
1339    #: Return Type $;
1340    sub IsComplete {
1341        # Get the parameters.
1342        my ($self, $genomeID) = @_;
1343        # Declare the return variable.
1344        my $retVal;
1345        # Get the genome's data.
1346        my $genomeData = $self->GetEntity('Genome', $genomeID);
1347        if ($genomeData) {
1348            # The genome exists, so get the completeness flag.
1349            ($retVal) = $genomeData->Value('complete');
1350        }
1351        # Return the result.
1352        return $retVal;
1353    }
1354    
1355  =head3 FeatureAliases  =head3 FeatureAliases
1356    
1357  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>
# Line 1378  Line 1471 
1471          return %retVal;          return %retVal;
1472  }  }
1473    
1474    =head3 CouplingEvidence
1475    
1476    C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>
1477    
1478    Return the evidence for a functional coupling.
1479    
1480    A pair of features is considered evidence of a coupling between two other
1481    features if they occur close together on a contig and both are similar to
1482    the coupled features. So, if B<A1> and B<A2> are close together on a contig,
1483    B<B1> and B<B2> are considered evidence for the coupling if (1) B<B1> and
1484    B<B2> are close together, (2) B<B1> is similar to B<A1>, and (3) B<B2> is
1485    similar to B<A2>.
1486    
1487    The score of a coupling is determined by the number of pieces of evidence
1488    that are considered I<representative>. If several evidence items belong to
1489    a group of genomes that are close to each other, only one of those items
1490    is considered representative. The other evidence items are presumed to be
1491    there because of the relationship between the genomes rather than because
1492    the two proteins generated by the features have a related functionality.
1493    
1494    Each evidence item is returned as a three-tuple in the form C<[>I<$peg1a>C<,>
1495    I<$peg2a>C<,> I<$rep>C<]>, where I<$peg1a> is similar to I<$peg1>, I<$peg2a>
1496    is similar to I<$peg2>, and I<$rep> is TRUE if the evidence is representative
1497    and FALSE otherwise.
1498    
1499    =over 4
1500    
1501    =item peg1
1502    
1503    ID of the feature of interest.
1504    
1505    =item peg2
1506    
1507    ID of a feature functionally coupled to the feature of interest.
1508    
1509    =item RETURN
1510    
1511    Returns a list of 3-tuples. Each tuple consists of a feature similar to the feature
1512    of interest, a feature similar to the functionally coupled feature, and a flag
1513    that is TRUE for a representative piece of evidence and FALSE otherwise.
1514    
1515    =back
1516    
1517    =cut
1518    #: Return Type @@;
1519    sub CouplingEvidence {
1520        # Get the parameters.
1521        my ($self, $peg1, $peg2) = @_;
1522        # Declare the return variable.
1523        my @retVal = ();
1524        # Our first task is to find out the nature of the coupling: whether or not
1525        # it exists, its score, and whether the features are stored in the same
1526        # order as the ones coming in.
1527        my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);
1528        # Only proceed if a coupling exists.
1529        if ($couplingID) {
1530            # Determine the ordering to place on the evidence items. If we're
1531            # inverted, we want to see feature 2 before feature 1 (descending); otherwise,
1532            # we want feature 1 before feature 2 (normal).
1533            Trace("Coupling evidence for ($peg1, $peg2) with inversion flag $inverted.") if T(Coupling => 4);
1534            my $ordering = ($inverted ? "DESC" : "");
1535            # Get the coupling evidence.
1536            my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
1537                                              "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",
1538                                              [$couplingID],
1539                                              ['PCH(used)', 'UsesAsEvidence(to-link)']);
1540            # Loop through the evidence items. Each piece of evidence is represented by two
1541            # positions in the evidence list, one for each feature on the other side of the
1542            # evidence link. If at some point we want to generalize to couplings with
1543            # more than two positions, this section of code will need to be re-done.
1544            while (@evidenceList > 0) {
1545                my $peg1Data = shift @evidenceList;
1546                my $peg2Data = shift @evidenceList;
1547                Trace("Peg 1 is " . $peg1Data->[1] . " and Peg 2 is " . $peg2Data->[1] . ".") if T(Coupling => 4);
1548                push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1549            }
1550            Trace("Last index in evidence result is is $#retVal.") if T(Coupling => 4);
1551        }
1552        # Return the result.
1553        return @retVal;
1554    }
1555    
1556    =head3 GetCoupling
1557    
1558    C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>
1559    
1560    Return the coupling (if any) for the specified pair of PEGs. If a coupling
1561    exists, we return the coupling ID along with an indicator of whether the
1562    coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.
1563    In the second case, we say the coupling is I<inverted>. The importance of an
1564    inverted coupling is that the PEGs in the evidence will appear in reverse order.
1565    
1566    =over 4
1567    
1568    =item peg1
1569    
1570    ID of the feature of interest.
1571    
1572    =item peg2
1573    
1574    ID of the potentially coupled feature.
1575    
1576    =item RETURN
1577    
1578    Returns a three-element list. The first element contains the database ID of
1579    the coupling. The second element is FALSE if the coupling is stored in the
1580    database in the caller specified order and TRUE if it is stored in the
1581    inverted order. The third element is the coupling's score. If the coupling
1582    does not exist, all three list elements will be C<undef>.
1583    
1584    =back
1585    
1586    =cut
1587    #: Return Type $%@;
1588    sub GetCoupling {
1589        # Get the parameters.
1590        my ($self, $peg1, $peg2) = @_;
1591        # Declare the return values. We'll start with the coupling ID and undefine the
1592        # flag and score until we have more information.
1593        my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);
1594        # Find the coupling data.
1595        my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],
1596                                     "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",
1597                                     [$retVal], ["ParticipatesInCoupling(from-link)", "Coupling(score)"]);
1598        # Check to see if we found anything.
1599        if (!@pegs) {
1600            Trace("No coupling found.") if T(Coupling => 4);
1601            # No coupling, so undefine the return value.
1602            $retVal = undef;
1603        } else {
1604            # We have a coupling! Get the score and check for inversion.
1605            $score = $pegs[0]->[1];
1606            my $firstFound = $pegs[0]->[0];
1607            $inverted = ($firstFound ne $peg1);
1608            Trace("Coupling score is $score. First peg is $firstFound, peg 1 is $peg1.") if T(Coupling => 4);
1609        }
1610        # Return the result.
1611        return ($retVal, $inverted, $score);
1612    }
1613    
1614    =head3 CouplingID
1615    
1616    C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>
1617    
1618    Return the coupling ID for a pair of feature IDs.
1619    
1620    The coupling ID is currently computed by joining the feature IDs in
1621    sorted order with a space. Client modules (that is, modules which
1622    use Sprout) should not, however, count on this always being the
1623    case. This method provides a way for abstracting the concept of a
1624    coupling ID. All that we know for sure about it is that it can be
1625    generated easily from the feature IDs and the order of the IDs
1626    in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>
1627    will have the same value as C<CouplingID("b1", "a1")>.
1628    
1629    =over 4
1630    
1631    =item peg1
1632    
1633    First feature of interest.
1634    
1635    =item peg2
1636    
1637    Second feature of interest.
1638    
1639    =item RETURN
1640    
1641    Returns the ID that would be used to represent a functional coupling of
1642    the two specified PEGs.
1643    
1644    =back
1645    
1646    =cut
1647    #: Return Type $;
1648    sub CouplingID {
1649        return join " ", sort @_;
1650    }
1651    
1652  =head3 GetEntityTypes  =head3 GetEntityTypes
1653    
1654  C<< my @entityList = $sprout->GetEntityTypes(); >>  C<< my @entityList = $sprout->GetEntityTypes(); >>
# Line 1439  Line 1710 
1710                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {                  if ($line =~ m/^>\s*(.+?)(\s|\n)/) {
1711                          # 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.
1712                          if ($id) {                          if ($id) {
1713                                  $retVal{$id} = uc $sequence;                  $retVal{$id} = lc $sequence;
1714                          }                          }
1715                          # Clear the sequence accumulator and save the new ID.                          # Clear the sequence accumulator and save the new ID.
1716                          ($id, $sequence) = ("$prefix$1", "");                          ($id, $sequence) = ("$prefix$1", "");
1717                  } else {                  } else {
1718                          # 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.
1719                          # First, we get the actual data out. Note that we normalize to upper              # First, we get the actual data out. Note that we normalize to lower
1720                          # case.                          # case.
1721                          $line =~ /^\s*(.*?)(\s|\n)/;                          $line =~ /^\s*(.*?)(\s|\n)/;
1722                          $sequence .= $1;                          $sequence .= $1;
# Line 1453  Line 1724 
1724          }          }
1725          # Flush out the last sequence (if any).          # Flush out the last sequence (if any).
1726          if ($sequence) {          if ($sequence) {
1727                  $retVal{$id} = uc $sequence;          $retVal{$id} = lc $sequence;
1728          }          }
1729          # Close the file.          # Close the file.
1730          close FASTAFILE;          close FASTAFILE;
# Line 1572  Line 1843 
1843  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
1844  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>.
1845    
1846  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'}); >>
1847    
1848  =over 4  =over 4
1849    
# Line 1779  Line 2050 
2050          # Get the parameters.          # Get the parameters.
2051          my ($self, $entityName, $entityID) = @_;          my ($self, $entityName, $entityID) = @_;
2052          # Check for the entity instance.          # Check for the entity instance.
2053        Trace("Checking existence of $entityName with ID=$entityID.") if T(4);
2054          my $testInstance = $self->GetEntity($entityName, $entityID);          my $testInstance = $self->GetEntity($entityName, $entityID);
2055          # Return an existence indicator.          # Return an existence indicator.
2056          my $retVal = ($testInstance ? 1 : 0);          my $retVal = ($testInstance ? 1 : 0);
# Line 1970  Line 2242 
2242          return @retVal;          return @retVal;
2243  }  }
2244    
2245    =head3 GetProperties
2246    
2247    C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>
2248    
2249    Return a list of the properties with the specified characteristics.
2250    
2251    Properties are arbitrary key-value pairs associated with a feature. (At some point they
2252    will also be associated with genomes.) A property value is represented by a 4-tuple of
2253    the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter
2254    
2255    =over 4
2256    
2257    =item fid
2258    
2259    ID of the feature possessing the property.
2260    
2261    =item key
2262    
2263    Name or key of the property.
2264    
2265    =item value
2266    
2267    Value of the property.
2268    
2269    =item url
2270    
2271    URL of the document that indicated the property should have this particular value, or an
2272    empty string if no such document exists.
2273    
2274    =back
2275    
2276    The parameters act as a filter for the desired data. Any non-null parameter will
2277    automatically match all the tuples returned. So, specifying just the I<$fid> will
2278    return all the properties of the specified feature; similarly, specifying the I<$key>
2279    and I<$value> parameters will return all the features having the specified property
2280    value.
2281    
2282    A single property key can have many values, representing different ideas about the
2283    feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is
2284    virulent, and another may declare that it is not virulent. A query about the virulence of
2285    C<fig|83333.1.peg.10> would be coded as
2286    
2287        my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');
2288    
2289    Here the I<$value> and I<$url> fields are left blank, indicating that those fields are
2290    not to be filtered. The tuples returned would be
2291    
2292        ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')
2293        ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')
2294    
2295    =cut
2296    #: Return Type @@;
2297    sub GetProperties {
2298        # Get the parameters.
2299        my ($self, @parms) = @_;
2300        # Declare the return variable.
2301        my @retVal = ();
2302        # Now we need to create a WHERE clause that will get us the data we want. First,
2303        # we create a list of the columns containing the data for each parameter.
2304        my @colNames = ('HasProperty(from-link)', 'Property(property-name)',
2305                        'Property(property-value)', 'HasProperty(evidence)');
2306        # Now we build the WHERE clause and the list of parameter values.
2307        my @where = ();
2308        my @values = ();
2309        for (my $i = 0; $i <= $#colNames; $i++) {
2310            my $parm = $parms[$i];
2311            if (defined $parm && ($parm ne '')) {
2312                push @where, "$colNames[$i] = ?";
2313                push @values, $parm;
2314            }
2315        }
2316        # Format the WHERE clause.
2317        my $filter = (@values > 0 ? (join " AND ", @where) : undef);
2318        # Ask for all the propertie values with the desired characteristics.
2319        my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);
2320        while (my $valueObject = $query->Fetch()) {
2321            my @tuple = $valueObject->Values(\@colNames);
2322            push @retVal, \@tuple;
2323        }
2324        # Return the result.
2325        return @retVal;
2326    }
2327    
2328  =head3 FeatureProperties  =head3 FeatureProperties
2329    
2330  C<< my @properties = $sprout->FeatureProperties($featureID); >>  C<< my @properties = $sprout->FeatureProperties($featureID); >>
# Line 2164  Line 2519 
2519  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>
2520    
2521  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped
2522  to the role the feature performs.  to the roles the feature performs.
2523    
2524  =over 4  =over 4
2525    
# Line 2174  Line 2529 
2529    
2530  =item RETURN  =item RETURN
2531    
2532  Returns a hash mapping all the feature's subsystems to the feature's role.  Returns a hash mapping all the feature's subsystems to a list of the feature's roles.
2533    
2534  =back  =back
2535    
2536  =cut  =cut
2537  #: Return Type %;  #: Return Type %@;
2538  sub SubsystemsOf {  sub SubsystemsOf {
2539          # Get the parameters.          # Get the parameters.
2540          my ($self, $featureID) = @_;          my ($self, $featureID) = @_;
2541          # Use the SSCell to connect features to subsystems.      # Get the subsystem list.
2542          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],          my @subsystems = $self->GetAll(['ContainsFeature', 'HasSSCell', 'IsRoleOf'],
2543                                                                          "ContainsFeature(to-link) = ?", [$featureID],                                                                          "ContainsFeature(to-link) = ?", [$featureID],
2544                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);                                                                          ['HasSSCell(from-link)', 'IsRoleOf(from-link)']);
# Line 2191  Line 2546 
2546          my %retVal = ();          my %retVal = ();
2547          # Loop through the results, adding them to the hash.          # Loop through the results, adding them to the hash.
2548          for my $record (@subsystems) {          for my $record (@subsystems) {
2549                  $retVal{$record->[0]} = $record->[1];          my ($subsys, $role) = @{$record};
2550            if (exists $retVal{$subsys}) {
2551                push @{$retVal{$subsys}}, $role;
2552            } else {
2553                $retVal{$subsys} = [$role];
2554            }
2555          }          }
2556          # Return the hash.          # Return the hash.
2557          return %retVal;          return %retVal;
2558  }  }
2559    
2560    =head3 SubsystemList
2561    
2562    C<< my @subsystems = $sprout->SubsystemList($featureID); >>
2563    
2564    Return a list containing the names of the subsystems in which the specified
2565    feature participates. Unlike L</SubsystemsOf>, this method only returns the
2566    subsystem names, not the roles.
2567    
2568    =over 4
2569    
2570    =item featureID
2571    
2572    ID of the feature whose subsystem names are desired.
2573    
2574    =item RETURN
2575    
2576    Returns a list of the names of the subsystems in which the feature participates.
2577    
2578    =back
2579    
2580    =cut
2581    #: Return Type @;
2582    sub SubsystemList {
2583        # Get the parameters.
2584        my ($self, $featureID) = @_;
2585        # Get the list of names.
2586        my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",
2587                                    [$featureID], 'HasSSCell(from-link)');
2588        # Return the result.
2589        return @retVal;
2590    }
2591    
2592  =head3 RelatedFeatures  =head3 RelatedFeatures
2593    
2594  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 2615  Line 3007 
3007      return %retVal;      return %retVal;
3008  }  }
3009    
3010    =head3 MyGenomes
3011    
3012    C<< my @genomes = Sprout::MyGenomes($dataDir); >>
3013    
3014    Return a list of the genomes to be included in the Sprout.
3015    
3016    This method is provided for use during the Sprout load. It presumes the Genome load file has
3017    already been created. (It will be in the Sprout data directory and called either C<Genome>
3018    or C<Genome.dtx>.) Essentially, it reads in the Genome load file and strips out the genome
3019    IDs.
3020    
3021    =over 4
3022    
3023    =item dataDir
3024    
3025    Directory containing the Sprout load files.
3026    
3027    =back
3028    
3029    =cut
3030    #: Return Type @;
3031    sub MyGenomes {
3032        # Get the parameters.
3033        my ($dataDir) = @_;
3034        # Compute the genome file name.
3035        my $genomeFileName = LoadFileName($dataDir, "Genome");
3036        # Extract the genome IDs from the files.
3037        my @retVal = map { $_ =~ /^(\S+)/; $1 } Tracer::GetFile($genomeFileName);
3038        # Return the result.
3039        return @retVal;
3040    }
3041    
3042    =head3 LoadFileName
3043    
3044    C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>
3045    
3046    Return the name of the load file for the specified table in the specified data
3047    directory.
3048    
3049    =over 4
3050    
3051    =item dataDir
3052    
3053    Directory containing the Sprout load files.
3054    
3055    =item tableName
3056    
3057    Name of the table whose load file is desired.
3058    
3059    =item RETURN
3060    
3061    Returns the name of the file containing the load data for the specified table, or
3062    C<undef> if no load file is present.
3063    
3064    =back
3065    
3066    =cut
3067    #: Return Type $;
3068    sub LoadFileName {
3069        # Get the parameters.
3070        my ($dataDir, $tableName) = @_;
3071        # Declare the return variable.
3072        my $retVal;
3073        # Check for the various file names.
3074        if (-e "$dataDir/$tableName") {
3075            $retVal = "$dataDir/$tableName";
3076        } elsif (-e "$dataDir/$tableName.dtx") {
3077            $retVal = "$dataDir/$tableName.dtx";
3078        }
3079        # Return the result.
3080        return $retVal;
3081    }
3082    
3083  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3084    
3085  =head3 ParseAssignment  =head3 ParseAssignment
# Line 2690  Line 3155 
3155      return $retVal;      return $retVal;
3156  }  }
3157    
3158    =head3 AddProperty
3159    
3160    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3161    
3162    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3163    be added to almost any object. In Sprout, they can only be added to features. In
3164    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3165    pair. If the particular key/value pair coming in is not already in the database, a new
3166    B<Property> record is created to hold it.
3167    
3168    =over 4
3169    
3170    =item peg
3171    
3172    ID of the feature to which the attribute is to be replied.
3173    
3174    =item key
3175    
3176    Name of the attribute (key).
3177    
3178    =item value
3179    
3180    Value of the attribute.
3181    
3182    =item url
3183    
3184    URL or text citation from which the property was obtained.
3185    
3186    =back
3187    
3188    =cut
3189    #: Return Type ;
3190    sub AddProperty {
3191        # Get the parameters.
3192        my ($self, $featureID, $key, $value, $url) = @_;
3193        # Declare the variable to hold the desired property ID.
3194        my $propID;
3195        # Attempt to find a property record for this key/value pair.
3196        my @properties = $self->GetFlat(['Property'],
3197                                       "Property(property-name) = ? AND Property(property-value) = ?",
3198                                       [$key, $value], 'Property(id)');
3199        if (@properties) {
3200            # Here the property is already in the database. We save its ID.
3201            $propID = $properties[0];
3202            # Here the property value does not exist. We need to generate an ID. It will be set
3203            # to a number one greater than the maximum value in the database. This call to
3204            # GetAll will stop after one record.
3205            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3206                                            1);
3207            $propID = $maxProperty[0]->[0] + 1;
3208            # Insert the new property value.
3209            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3210        }
3211        # Now we connect the incoming feature to the property.
3212        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3213    }
3214    
3215    
3216    
3217  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3