--- Sprout.pm 2006/06/14 19:47:19 1.60 +++ Sprout.pm 2006/06/18 05:38:12 1.62 @@ -793,6 +793,128 @@ return @retVal; } +=head3 GenomeLength + +C<< my $length = $sprout->GenomeLength($genomeID); >> + +Return the length of the specified genome in base pairs. + +=over 4 + +=item genomeID + +ID of the genome whose base pair count is desired. + +=item RETURN + +Returns the number of base pairs in all the contigs of the specified +genome. + +=back + +=cut + +sub GenomeLength { + # Get the parameters. + my ($self, $genomeID) = @_; + # Declare the return variable. + my $retVal = 0; + # Get the genome's contig sequence lengths. + my @lens = GetFlat(['HasContig', 'IsMadeUpOf'], 'HasContig(from-link) = ?', + [$genomeID], 'IsMadeUpOf(len)'); + # Sum the lengths. + map { $retVal += $_ } @lens; + # Return the result. + return $retVal; +} + +=head3 FeatureCount + +C<< my $count = $sprout->FeatureCount($genomeID, $type); >> + +Return the number of features of the specified type in the specified genome. + +=over 4 + +=genomeID + +ID of the genome whose feature count is desired. + +=item type + +Type of feature to count (eg. C, C, etc.). + +=item RETURN + +Returns the number of features of the specified type for the specified genome. + +=back + +=cut + +sub FeatureCount { + # Get the parameters. + my ($self, $genomeID, $type) = @_; + # Compute the count. + my $retVal = $self->GetCount(['HasFeature', 'Feature'], + "HasFeature(from-link) = ? AND Feature(type) = ?", + [$genomeID, $type]); + # Return the result. + return $retVal; +} + +=head3 GenomeAssignments + +C<< my $fidHash = $sprout->GenomeAssignments($genomeID); >> + +Return a list of a genome's assigned features. The return hash will contain each +assigned feature of the genome mapped to the text of its most recent functional +assignment. + +=over 4 + +=item genomeID + +ID of the genome whose functional assignments are desired. + +=item RETURN + +Returns a reference to a hash which maps each feature to its most recent +functional assignment. + +=back + +=cut + +sub GenomeAssignments { + # Get the parameters. + my ($self, $genomeID) = @_; + # Declare the return variable. + my $retVal = {}; + # Query the genome's features and annotations. We'll put the oldest annotations + # first so that the last assignment to go into the hash will be the correct one. + my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'], + "HasFeature(from-link) = ? ORDER BY Annotation(time)", + [$genomeID]); + # Loop through the annotations. + while (my $data = $query->Fetch) { + # Get the feature ID and annotation text. + my ($fid, $annotation) = $data->Values(['HasFeature(from-link)', + 'Annotation(text)']); + # Check to see if this is an assignment. Note that the user really + # doesn't matter to us, other than we use it to determine whether or + # not this is an assignment. + my ($user, $assignment) = $self->_ParseAssignment('fig', $annotation); + if ($user) { + # Here it's an assignment. We put it in the return hash, overwriting + # any older assignment that might be present. + $retVal->{$fid} = $assignment; + } + } + # Return the result. + return $retVal; +} + =head3 ContigLength C<< my $length = $sprout->ContigLength($contigID); >> @@ -1546,7 +1668,7 @@ # Get the other feature that participates in the coupling. my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'], "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?", - [$couplingID, $featureID], 'ParticipatesInCoupling(to-link)'); + [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)'); # Attach the other feature's score to its ID. $retVal{$otherFeatureID} = $score; $found = 1;