[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.13, Thu May 5 03:14:03 2005 UTC revision 1.15, Wed Jun 22 21:30:45 2005 UTC
# Line 1230  Line 1230 
1230    
1231  =item RETURN  =item RETURN
1232    
1233  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
1234  their best hits.  on the target genome.
1235    
1236  =back  =back
1237    
# Line 1259  Line 1259 
1259          return \%retVal;          return \%retVal;
1260  }  }
1261    
1262    =head3 SimList
1263    
1264    C<< my %similarities = $sprout->SimList($featureID, $count); >>
1265    
1266    Return a list of the similarities to the specified feature.
1267    
1268    Sprout does not support real similarities, so this method just returns the bidirectional
1269    best hits.
1270    
1271    =over 4
1272    
1273    =item featureID
1274    
1275    ID of the feature whose similarities are desired.
1276    
1277    =item count
1278    
1279    Maximum number of similar features to be returned, or C<0> to return them all.
1280    
1281    =back
1282    
1283    =cut
1284    #: Return Type %;
1285    sub SimList {
1286        # Get the parameters.
1287        my ($self, $featureID, $count) = @_;
1288        # Ask for the best hits.
1289        my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],
1290                                  "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",
1291                                  [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],
1292                                  $count);
1293        # Create the return value.
1294        my %retVal = ();
1295        for my $tuple (@lists) {
1296            $retVal{$tuple->[0]} = $tuple->[1];
1297        }
1298        # Return the result.
1299        return %retVal;
1300    }
1301    
1302    
1303    
1304    =head3 IsComplete
1305    
1306    C<< my $flag = $sprout->IsComplete($genomeID); >>
1307    
1308    Return TRUE if the specified genome is complete, else FALSE.
1309    
1310    =over 4
1311    
1312    =item genomeID
1313    
1314    ID of the genome whose completeness status is desired.
1315    
1316    =item RETURN
1317    
1318    Returns TRUE if the genome is complete, FALSE if it is incomplete, and C<undef> if it is
1319    not found.
1320    
1321    =back
1322    
1323    =cut
1324    #: Return Type $;
1325    sub IsComplete {
1326        # Get the parameters.
1327        my ($self, $genomeID) = @_;
1328        # Declare the return variable.
1329        my $retVal;
1330        # Get the genome's data.
1331        my $genomeData = $self->GetEntity('Genome', $genomeID);
1332        if ($genomeData) {
1333            # The genome exists, so get the completeness flag.
1334            ($retVal) = $genomeData->Value('complete');
1335        }
1336        # Return the result.
1337        return $retVal;
1338    }
1339    
1340  =head3 FeatureAliases  =head3 FeatureAliases
1341    
1342  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>  C<< my @aliasList = $sprout->FeatureAliases($featureID); >>
# Line 1349  Line 1427 
1427  sub CoupledFeatures {  sub CoupledFeatures {
1428          # Get the parameters.          # Get the parameters.
1429          my ($self, $featureID) = @_;          my ($self, $featureID) = @_;
1430          # Create a query to retrieve the functionally-coupled features. Note that we depend on the      # Create a query to retrieve the functionally-coupled features.
1431          # fact that the functional coupling is physically paired. If (A,B) is in the database, then      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1432          # (B,A) will also be found.                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);
         my $query = $self->Get(['IsClusteredOnChromosomeWith'],  
                                                    "IsClusteredOnChromosomeWith(from-link) = ?", [$featureID]);  
1433          # 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.
1434          my $found = 0;          my $found = 0;
1435          # Create the return hash.          # Create the return hash.
1436          my %retVal = ();          my %retVal = ();
1437          # Retrieve the relationship records and store them in the hash.          # Retrieve the relationship records and store them in the hash.
1438          while (my $clustering = $query->Fetch()) {          while (my $clustering = $query->Fetch()) {
1439                  my ($otherFeatureID, $score) = $clustering->Values(['IsClusteredOnChromosomeWith(to-link)',          # Get the ID and score of the coupling.
1440                                                                      'IsClusteredOnChromosomeWith(score)']);          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1441                                                            'Coupling(score)']);
1442            # The coupling ID contains the two feature IDs separated by a space. We use
1443            # this information to find the ID of the other feature.
1444            my ($fid1, $fid2) = split / /, $couplingID;
1445            my $otherFeatureID = ($featureID eq $fid1 ? $fid2 : $fid1);
1446            # Attach the other feature's score to its ID.
1447                  $retVal{$otherFeatureID} = $score;                  $retVal{$otherFeatureID} = $score;
1448                  $found = 1;                  $found = 1;
1449          }          }
# Line 1374  Line 1456 
1456          return %retVal;          return %retVal;
1457  }  }
1458    
1459    =head3 CouplingEvidence
1460    
1461    C<< my @evidence = $sprout->CouplingEvidence($peg1, $peg2); >>
1462    
1463    Return the evidence for a functional coupling.
1464    
1465    A pair of features is considered evidence of a coupling between two other
1466    features if they occur close together on a contig and both are similar to
1467    the coupled features. So, if B<A1> and B<A2> are close together on a contig,
1468    B<B1> and B<B2> are considered evidence for the coupling if (1) B<B1> and
1469    B<B2> are close together, (2) B<B1> is similar to B<A1>, and (3) B<B2> is
1470    similar to B<A2>.
1471    
1472    The score of a coupling is determined by the number of pieces of evidence
1473    that are considered I<representative>. If several evidence items belong to
1474    a group of genomes that are close to each other, only one of those items
1475    is considered representative. The other evidence items are presumed to be
1476    there because of the relationship between the genomes rather than because
1477    the two proteins generated by the features have a related functionality.
1478    
1479    Each evidence item is returned as a three-tuple in the form C<[>I<$peg1a>C<,>
1480    I<$peg2a>C<,> I<$rep>C<]>, where I<$peg1a> is similar to I<$peg1>, I<$peg2a>
1481    is similar to I<$peg2>, and I<$rep> is TRUE if the evidence is representative
1482    and FALSE otherwise.
1483    
1484    =over 4
1485    
1486    =item peg1
1487    
1488    ID of the feature of interest.
1489    
1490    =item peg2
1491    
1492    ID of a feature functionally coupled to the feature of interest.
1493    
1494    =item RETURN
1495    
1496    Returns a list of 3-tuples. Each tuple consists of a feature similar to the feature
1497    of interest, a feature similar to the functionally coupled feature, and a flag
1498    that is TRUE for a representative piece of evidence and FALSE otherwise.
1499    
1500    =back
1501    
1502    =cut
1503    #: Return Type @@;
1504    sub CouplingEvidence {
1505        # Get the parameters.
1506        my ($self, $peg1, $peg2) = @_;
1507        # Declare the return variable.
1508        my @retVal = ();
1509        # Our first task is to find out the nature of the coupling.
1510        my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);
1511        # Only proceed if a coupling exists.
1512        if ($couplingID) {
1513            # Determine the ordering to place on the evidence items. If we're
1514            # inverted, we want to see feature 2 before feature 1; otherwise,
1515            # we want the reverse.
1516            my $ordering = ($inverted ? "DESC" : "");
1517            # Get the coupling evidence.
1518            my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
1519                                              "IsEvidencedBy(from-link) = ? ORDER BY PCH(id), UsesAsEvidence(pos) $ordering",
1520                                              [$couplingID],
1521                                              ['PCH(used)', 'UsesAsEvidence(pos)']);
1522            # Loop through the evidence items. Each piece of evidence is represented by two
1523            # positions in the evidence list, one for each feature on the other side of the
1524            # evidence link. If at some point we want to generalize to couplings with
1525            # more than two positions, this section of code will need to be re-done.
1526            while (@evidenceList > 0) {
1527                my $peg1Data = shift @evidenceList;
1528                my $peg2Data = shift @evidenceList;
1529                push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1530            }
1531        }
1532        # TODO: code
1533        # Return the result.
1534        return @retVal;
1535    }
1536    
1537    =head3 GetCoupling
1538    
1539    C<< my ($couplingID, $inverted, $score) = $sprout->GetCoupling($peg1, $peg2); >>
1540    
1541    Return the coupling (if any) for the specified pair of PEGs. If a coupling
1542    exists, we return the coupling ID along with an indicator of whether the
1543    coupling is stored as C<(>I<$peg1>C<, >I<$peg2>C<)> or C<(>I<$peg2>C<, >I<$peg1>C<)>.
1544    In the second case, we say the coupling is I<inverted>. The importance of an
1545    inverted coupling is that the PEGs in the evidence will appear in reverse order.
1546    
1547    =over 4
1548    
1549    =item peg1
1550    
1551    ID of the feature of interest.
1552    
1553    =item peg2
1554    
1555    ID of the potentially coupled feature.
1556    
1557    =item RETURN
1558    
1559    Returns a three-element list. The first element contains the database ID of
1560    the coupling. The second element is FALSE if the coupling is stored in the
1561    database in the caller specified order and TRUE if it is stored in the
1562    inverted order. The third element is the coupling's score. If the coupling
1563    does not exist, all three list elements will be C<undef>.
1564    
1565    =back
1566    
1567    =cut
1568    #: Return Type $%@;
1569    sub GetCoupling {
1570        # Get the parameters.
1571        my ($self, $peg1, $peg2) = @_;
1572        # Declare the return values. We'll start with the coupling ID and undefine the
1573        # flag and score until we have more information.
1574        my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef);
1575        # Find the coupling data.
1576        my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'],
1577                                     "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)",
1578                                     [$retVal], "ParticipatesInCoupling(from-link), Coupling(score)");
1579        # Check to see if we found anything.
1580        if (!@pegs) {
1581            # No coupling, so undefine the return value.
1582            $retVal = undef;
1583        } else {
1584            # We have a coupling! Get the score and check for inversion.
1585            $score = $pegs[0]->[1];
1586            $inverted = ($pegs[0]->[0] eq $peg1);
1587        }
1588        # Return the result.
1589        return ($retVal, $inverted, $score);
1590    }
1591    
1592    =head3 CouplingID
1593    
1594    C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >>
1595    
1596    Return the coupling ID for a pair of feature IDs.
1597    
1598    The coupling ID is currently computed by joining the feature IDs in
1599    sorted order with a space. Client modules (that is, modules which
1600    use Sprout) should not, however, count on this always being the
1601    case. This method provides a way for abstracting the concept of a
1602    coupling ID. All that we know for sure about it is that it can be
1603    generated easily from the feature IDs and the order of the IDs
1604    in the parameter list does not matter (i.e. C<CouplingID("a1", "b1")>
1605    will have the same value as C<CouplingID("b1", "a1")>.
1606    
1607    =over 4
1608    
1609    =item peg1
1610    
1611    First feature of interest.
1612    
1613    =item peg2
1614    
1615    Second feature of interest.
1616    
1617    =item RETURN
1618    
1619    Returns the ID that would be used to represent a functional coupling of
1620    the two specified PEGs.
1621    
1622    =back
1623    
1624    =cut
1625    #: Return Type $;
1626    sub CouplingID {
1627        return join " ", sort @_;
1628    }
1629    
1630  =head3 GetEntityTypes  =head3 GetEntityTypes
1631    
1632  C<< my @entityList = $sprout->GetEntityTypes(); >>  C<< my @entityList = $sprout->GetEntityTypes(); >>
# Line 1568  Line 1821 
1821  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
1822  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>.
1823    
1824  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'}); >>
1825    
1826  =over 4  =over 4
1827    
# Line 2686  Line 2939 
2939      return $retVal;      return $retVal;
2940  }  }
2941    
2942    =head3 AddProperty
2943    
2944    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
2945    
2946    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
2947    be added to almost any object. In Sprout, they can only be added to features. In
2948    Sprout, attributes are implemented using I<properties>. A property represents a key/value
2949    pair. If the particular key/value pair coming in is not already in the database, a new
2950    B<Property> record is created to hold it.
2951    
2952    =over 4
2953    
2954    =item peg
2955    
2956    ID of the feature to which the attribute is to be replied.
2957    
2958    =item key
2959    
2960    Name of the attribute (key).
2961    
2962    =item value
2963    
2964    Value of the attribute.
2965    
2966    =item url
2967    
2968    URL or text citation from which the property was obtained.
2969    
2970    =back
2971    
2972    =cut
2973    #: Return Type ;
2974    sub AddProperty {
2975        # Get the parameters.
2976        my ($self, $featureID, $key, $value, $url) = @_;
2977        # Declare the variable to hold the desired property ID.
2978        my $propID;
2979        # Attempt to find a property record for this key/value pair.
2980        my @properties = $self->GetFlat(['Property'],
2981                                       "Property(property-name) = ? AND Property(property-value) = ?",
2982                                       [$key, $value], 'Property(id)');
2983        if (@properties) {
2984            # Here the property is already in the database. We save its ID.
2985            $propID = $properties[0];
2986            # Here the property value does not exist. We need to generate an ID. It will be set
2987            # to a number one greater than the maximum value in the database. This call to
2988            # GetAll will stop after one record.
2989            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
2990                                            1);
2991            $propID = $maxProperty[0]->[0] + 1;
2992            # Insert the new property value.
2993            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
2994        }
2995        # Now we connect the incoming feature to the property.
2996        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
2997    }
2998    
2999  1;  1;

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3