[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.80, Thu Aug 10 07:34:37 2006 UTC revision 1.84, Thu Sep 14 14:11:09 2006 UTC
# Line 1476  Line 1476 
1476      my %retVal = ();      my %retVal = ();
1477      # Loop through the incoming features.      # Loop through the incoming features.
1478      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1479          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1480          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1481          # Peel off the BBHs found.          # Peel off the BBHs found.
1482          my @found = ();          my @found = ();
1483          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1484              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              push @found, $bbh->[0];
1485          }          }
1486          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1487      }      }
# Line 1497  Line 1495 
1495    
1496  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1497    
1498  Sprout does not support real similarities, so this method just returns the bidirectional  This method just returns the bidirectional best hits for performance reasons.
 best hits.  
1499    
1500  =over 4  =over 4
1501    
# Line 1518  Line 1515 
1515      # Get the parameters.      # Get the parameters.
1516      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1517      # Ask for the best hits.      # Ask for the best hits.
1518      my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],      my @lists = FIGRules::BBHData($featureID);
                               "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",  
                               [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],  
                               $count);  
1519      # Create the return value.      # Create the return value.
1520      my %retVal = ();      my %retVal = ();
1521      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1531  Line 1525 
1525      return %retVal;      return %retVal;
1526  }  }
1527    
   
   
1528  =head3 IsComplete  =head3 IsComplete
1529    
1530  C<< my $flag = $sprout->IsComplete($genomeID); >>  C<< my $flag = $sprout->IsComplete($genomeID); >>
# Line 2962  Line 2954 
2954      # Get the parameters.      # Get the parameters.
2955      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
2956      # Get a list of the features that are BBHs of the incoming feature.      # Get a list of the features that are BBHs of the incoming feature.
2957      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
2958      # Now we loop through the features, pulling out the ones that have the correct      # Now we loop through the features, pulling out the ones that have the correct
2959      # functional assignment.      # functional assignment.
2960      my @retVal = ();      my @retVal = ();
# Line 3165  Line 3155 
3155      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3156      # Create the return hash.      # Create the return hash.
3157      my %retVal = ();      my %retVal = ();
3158      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3159      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3160      # Form the results into the return hash.      # Form the results into the return hash.
3161      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3162          $retVal{$pair->[0]} = $pair->[1];          $retVal{$pair->[0]} = $pair->[1];
# Line 3400  Line 3387 
3387      return $retVal;      return $retVal;
3388  }  }
3389    
3390    =head3 Fix
3391    
3392    C<< my %fixedHash = Sprout::Fix(%groupHash); >>
3393    
3394    Prepare a genome group hash (like that returned by L</GetGroups> for processing.
3395    Groups with the same primary name will be combined. The primary name is the
3396    first capitalized word in the group name.
3397    
3398    =over 4
3399    
3400    =item groupHash
3401    
3402    Hash to be fixed up.
3403    
3404    =item RETURN
3405    
3406    Returns a fixed-up version of the hash.
3407    
3408    =back
3409    
3410    =cut
3411    
3412    sub Fix {
3413        # Get the parameters.
3414        my (%groupHash) = @_;
3415        # Create the result hash.
3416        my %retVal = ();
3417        # Copy over the genomes.
3418        for my $groupID (keys %groupHash) {
3419            # Make a safety copy of the group ID.
3420            my $realGroupID = $groupID;
3421            # Yank the primary name.
3422            if ($groupID =~ /([A-Z]\w+)/) {
3423                $realGroupID = $1;
3424            }
3425            # Append this group's genomes into the result hash.
3426            Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});
3427        }
3428        # Return the result hash.
3429        return %retVal;
3430    }
3431    
3432    =head3 ReadGroupFile
3433    
3434    C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
3435    
3436    Read in the data from the specified group file. The group file contains information
3437    about each of the NMPDR groups.
3438    
3439    =over 4
3440    
3441    =item name
3442    
3443    Name of the group.
3444    
3445    =item page
3446    
3447    Name of the group's page on the web site (e.g. C<campy.php> for
3448    Campylobacter)
3449    
3450    =item genus
3451    
3452    Genus of the group
3453    
3454    =item species
3455    
3456    Species of the group, or an empty string if the group is for an entire
3457    genus. If the group contains more than one species, the species names
3458    should be separated by commas.
3459    
3460    =back
3461    
3462    The parameters to this method are as follows
3463    
3464    =over 4
3465    
3466    =item groupFile
3467    
3468    Name of the file containing the group data.
3469    
3470    =item RETURN
3471    
3472    Returns a hash keyed on group name. The value of each hash
3473    
3474    =back
3475    
3476    =cut
3477    
3478    sub ReadGroupFile {
3479        # Get the parameters.
3480        my ($groupFileName) = @_;
3481        # Declare the return variable.
3482        my %retVal;
3483        # Read the group file.
3484        my @groupLines = Tracer::GetFile($groupFileName);
3485        for my $groupLine (@groupLines) {
3486            my ($name, $page, $genus, $species) = split(/\t/, $groupLine);
3487            $retVal{$name} = [$page, $genus, $species];
3488        }
3489        # Return the result.
3490        return %retVal;
3491    }
3492    
3493  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3494    
3495  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3456  Line 3546 
3546      }      }
3547      # If we have an assignment, we need to clean the function text. There may be      # If we have an assignment, we need to clean the function text. There may be
3548      # extra junk at the end added as a note from the user.      # extra junk at the end added as a note from the user.
3549      if (@retVal > 1) {      if (defined( $retVal[1] )) {
3550          $retVal[1] =~ s/(\t\S)?\s*$//;          $retVal[1] =~ s/(\t\S)?\s*$//;
3551      }      }
3552      # Return the result list.      # Return the result list.

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.84

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3