--- Sprout.pm 2006/06/18 07:20:33 1.65 +++ Sprout.pm 2006/06/25 02:44:43 1.73 @@ -12,6 +12,7 @@ use DBObject; use Tracer; use FIGRules; + use FidCheck; use Stats; use POSIX qw(strftime); @@ -104,7 +105,7 @@ # user name and password port => $FIG_Config::dbport, # database connection port - sock => $FIG_Config::dbsock, + sock => $FIG_Config::dbsock, maxSegmentLength => 4500, # maximum feature segment length maxSequenceLength => 8000, # maximum contig sequence length noDBOpen => 0, # 1 to suppress the database open @@ -375,18 +376,20 @@ # Get the genomes. my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)', 'Genome(genus)', - 'Genome(species)']); + 'Genome(species)', + 'Genome(unique-characterization)']); # Sort them by name. my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes; # Loop through the genomes, creating the option tags. for my $genomeData (@sorted) { # Get the data for this genome. - my ($genomeID, $genus, $species) = @{$genomeData}; + my ($genomeID, $genus, $species, $strain) = @{$genomeData}; # Get the contig count. my $count = $self->ContigCount($genomeID); my $counting = ($count == 1 ? "contig" : "contigs"); # Build the option tag. - $retVal .= "\n"; + $retVal .= "\n"; + Trace("Option tag built for $genomeID: $genus $species $strain.") if T(3); } # Close the SELECT tag. $retVal .= "\n"; @@ -836,7 +839,7 @@ =over 4 -=genomeID +=item genomeID ID of the genome whose feature count is desired. @@ -899,12 +902,12 @@ # Loop through the annotations. while (my $data = $query->Fetch) { # Get the feature ID and annotation text. - my ($fid, $annotation) = $data->Values(['HasFeature(from-link)', + my ($fid, $annotation) = $data->Values(['HasFeature(to-link)', 'Annotation(annotation)']); # 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); + my ($user, $assignment) = _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. @@ -1801,7 +1804,7 @@ my ($self, $peg1, $peg2) = @_; # Declare the return values. We'll start with the coupling ID and undefine the # flag and score until we have more information. - my ($retVal, $inverted, $score) = (CouplingID($peg1, $peg2), undef, undef); + my ($retVal, $inverted, $score) = ($self->CouplingID($peg1, $peg2), undef, undef); # Find the coupling data. my @pegs = $self->GetAll(['Coupling', 'ParticipatesInCoupling'], "Coupling(id) = ? ORDER BY ParticipatesInCoupling(pos)", @@ -1824,7 +1827,7 @@ =head3 CouplingID -C<< my $couplingID = Sprout::CouplingID($peg1, $peg2); >> +C<< my $couplingID = $sprout->CouplingID($peg1, $peg2); >> Return the coupling ID for a pair of feature IDs. @@ -1857,7 +1860,8 @@ =cut #: Return Type $; sub CouplingID { - return join " ", sort @_; + my ($self, @pegs) = @_; + return $self->DigestKey(join " ", sort @pegs); } =head3 ReadFasta @@ -2216,41 +2220,6 @@ return @retVal; } -=head3 Exists - -C<< my $found = $sprout->Exists($entityName, $entityID); >> - -Return TRUE if an entity exists, else FALSE. - -=over 4 - -=item entityName - -Name of the entity type (e.g. C) relevant to the existence check. - -=item entityID - -ID of the entity instance whose existence is to be checked. - -=item RETURN - -Returns TRUE if the entity instance exists, else FALSE. - -=back - -=cut -#: Return Type $; -sub Exists { - # Get the parameters. - my ($self, $entityName, $entityID) = @_; - # Check for the entity instance. - Trace("Checking existence of $entityName with ID=$entityID.") if T(4); - my $testInstance = $self->GetEntity($entityName, $entityID); - # Return an existence indicator. - my $retVal = ($testInstance ? 1 : 0); - return $retVal; -} - =head3 FeatureTranslation C<< my $translation = $sprout->FeatureTranslation($featureID); >> @@ -2788,8 +2757,6 @@ return @retVal; } - - =head3 RelatedFeatures C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >> @@ -3041,6 +3008,71 @@ return %retVal; } +=head3 Sims + +C<< my $simList = $sprout->Sims($fid, $maxN, $maxP, $select, $max_expand, $filters); >> + +Get a list of similarities for a specified feature. Similarity information is not kept in the +Sprout database; rather, they are retrieved from a network server. The similarities are +returned as B objects. A Sim object is actually a list reference that has been blessed +so that its elements can be accessed by name. + +Similarities can be either raw or expanded. The raw similarities are basic +hits between features with similar DNA. Expanding a raw similarity drags in any +features considered substantially identical. So, for example, if features B, +B, and B are all substatially identical to B, then a raw similarity +B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>. + +=over 4 + +=item fid + +ID of the feature whose similarities are desired. + +=item maxN + +Maximum number of similarities to return. + +=item maxP + +Minumum allowable similarity score. + +=item select + +Selection criterion: C means only raw similarities are returned; C +means only similarities to FIG features are returned; C means all expanded +similarities are returned; and C means similarities are expanded until the +number of FIG features equals the maximum. + +=item max_expand + +The maximum number of features to expand. + +=item filters + +Reference to a hash containing filter information, or a subroutine that can be +used to filter the sims. + +=item RETURN + +Returns a reference to a list of similarity objects, or C if an error +occurred. + +=back + +=cut + +sub Sims { + # Get the parameters. + my ($self, $fid, $maxN, $maxP, $select, $max_expand, $filters) = @_; + # Create the shim object to test for deleted FIDs. + my $shim = FidCheck->new($self); + # Ask the network for sims. + my $retVal = FIGRules::GetNetworkSims($shim, $fid, {}, $maxN, $maxP, $select, $max_expand, $filters); + # Return the result. + return $retVal; +} + =head3 GetGroups C<< my %groups = $sprout->GetGroups(\@groupList); >>