[Bio] / Sprout / SHSigGenes.pm Repository:
ViewVC logotype

Diff of /Sprout/SHSigGenes.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9, Sat Dec 2 09:46:01 2006 UTC revision 1.10, Wed Dec 6 03:36:04 2006 UTC
# Line 8  Line 8 
8      use CGI;      use CGI;
9      use HTML;      use HTML;
10      use Sprout;      use Sprout;
11        use Time::HiRes;
12    
13      our @ISA = qw(SearchHelper);      our @ISA = qw(SearchHelper);
14    
# Line 143  Line 144 
144      # Declare the return variable. If it remains undefined, the caller will      # Declare the return variable. If it remains undefined, the caller will
145      # assume there was an error.      # assume there was an error.
146      my $retVal;      my $retVal;
147        # Create the timers.
148        my ($saveTime, $loopCounter, $bbhTimer, $putTimer, $queryTimer) = (0, 0, 0, 0, 0);
149      # Validate the numeric parameters.      # Validate the numeric parameters.
150      my $commonality = $cgi->param('commonality');      my $commonality = $cgi->param('commonality');
151      my $cutoff = $cgi->param('cutoff');      my $cutoff = $cgi->param('cutoff');
# Line 170  Line 173 
173          my $statistical = $cgi->param('statistical') || 0;          my $statistical = $cgi->param('statistical') || 0;
174          # Denote we have not yet found any genomes.          # Denote we have not yet found any genomes.
175          $retVal = 0;          $retVal = 0;
176            # Compute the list of genomes of interest.
177            my @allGenomes = (keys %exclusionGenomes, keys %targetGenomes);
178            # Get the BBH matrix.
179            $saveTime = time();
180            my %bbhMatrix = $sprout->BBHMatrix($givenGenomeID, $cutoff, @allGenomes);
181            $bbhTimer += time() - $saveTime;
182          # Create a feature query object to loop through the chosen features of the given          # Create a feature query object to loop through the chosen features of the given
183          # genome.          # genome.
184            Trace("Creating feature query.") if T(3);
185            $saveTime = time();
186          my $fquery = FeatureQuery->new($self, $givenGenomeID);          my $fquery = FeatureQuery->new($self, $givenGenomeID);
187            $queryTimer += time() - $saveTime;
188          # Get the sizes of the two sets. This information is useful in computing commonality.          # Get the sizes of the two sets. This information is useful in computing commonality.
189          my $targetSetSize = scalar keys %targetGenomes;          my $targetSetSize = scalar keys %targetGenomes;
190          my $exclusionSetSize = scalar keys %exclusionGenomes;          my $exclusionSetSize = scalar keys %exclusionGenomes;
191          # Loop through the features.          # Loop through the features.
192          while (my $record = $fquery->Fetch()) {          my $done = 0;
193            while (! $done) {
194                # Get the next feature.
195                $saveTime = time();
196                my $record = $fquery->Fetch();
197                $queryTimer += time() - $saveTime;
198                if (! $record) {
199                    $done = 1;
200                } else {
201              # Get the feature's ID.              # Get the feature's ID.
202              my $fid = $fquery->FID();              my $fid = $fquery->FID();
203              # Request its list of BBHs. The list is actually a hash mapping each BBH to its                  Trace("Processing feature $fid.") if T(4);
204                    # Get its list of BBHs. The list is actually a hash mapping each BBH to its
205              # score. All we care about, however, are the BBHs themselves.              # score. All we care about, however, are the BBHs themselves.
206              my %bbhList = $sprout->LowBBHs($fid, $cutoff);                  my $bbhList = $bbhMatrix{$fid};
207              # We next wish to loop through the BBH IDs, counting how many are in each of the              # We next wish to loop through the BBH IDs, counting how many are in each of the
208              # sets. If a genome occurs twice, we only want to count the first occurrence, so              # sets. If a genome occurs twice, we only want to count the first occurrence, so
209              # we have a hash of genomes we've already seen.              # we have a hash of genomes we've already seen.
210              my %alreadySeen = ();              my %alreadySeen = ();
211              # Clear the counts.                  # Clear the exclusion count.
212              my ($targetCount, $exclusionCount) = (0, 0);                  my $exclusionCount = 0;
213                    # Denote that we're in our own genome.
214                    $alreadySeen{$givenGenomeID} = 1;
215                    my $targetCount = 1;
216              # Loop through the BBHs.              # Loop through the BBHs.
217              for my $bbhPeg (keys %bbhList) {                  for my $bbhPeg (keys %{$bbhList}) {
218                  # Get the genome ID. We want to find out if this genome is new.                  # Get the genome ID. We want to find out if this genome is new.
219                  my ($genomeID) = FIGRules::ParseFeatureID($bbhPeg);                  my ($genomeID) = FIGRules::ParseFeatureID($bbhPeg);
220                  if (! $alreadySeen{$genomeID}) {                  if (! $alreadySeen{$genomeID}) {
# Line 230  Line 254 
254              }              }
255              if ($okFlag) {              if ($okFlag) {
256                  # Put this feature to the output.                  # Put this feature to the output.
257                        $saveTime = time();
258                  $self->PutFeature($fquery);                  $self->PutFeature($fquery);
259                        $putTimer += time() - $saveTime;
260                  # Increase the result count.                  # Increase the result count.
261                  $retVal++;                  $retVal++;
262              }              }
263                    # Check for a timer trace. We trace every 500 features.
264                    $loopCounter++;
265                    if (T(3) && $loopCounter % 500 == 0) {
266                        Trace("Time spent for $loopCounter features: Put = $putTimer, Query = $queryTimer, BBH = $bbhTimer.");
267                    }
268                }
269          }          }
270          # Close the session file.          # Close the session file.
271            $saveTime = time();
272          $self->CloseSession();          $self->CloseSession();
273            $putTimer += time() - $saveTime;
274      }      }
275        # Trace the timers.
276        Trace("Time spent: Put = $putTimer, Query = $queryTimer, BBH = $bbhTimer.") if T(3);
277      # Return the result count.      # Return the result count.
278      return $retVal;      return $retVal;
279  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3