[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.7, Wed Nov 15 12:13:40 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 87  Line 88 
88      my $commonality = $cgi->param('commonality') || "0.8";      my $commonality = $cgi->param('commonality') || "0.8";
89      my $cutoff = $cgi->param('cutoff') || "1e-10";      my $cutoff = $cgi->param('cutoff') || "1e-10";
90      my $statistical = $cgi->param('statistical') || 1;      my $statistical = $cgi->param('statistical') || 1;
91      # Now we build the table rows. The top contains the two numeric parameters and      # Now we build the table rows.
     # the submit button.  
92      my @rows = ();      my @rows = ();
93        # First we have the given genome.
94        push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Reference Genome"),
95                             $cgi->td({colspan => 2}, $givenMenu));
96        # Now show the target and exclusion menus.
97        push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Inclusion Genomes (Set 1)"),
98                             $cgi->td({colspan => 2}, $targetMenu));
99        push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Exclusion Genomes (Set 2)"),
100                             $cgi->td({colspan => 2}, $excludeMenu));
101        # Next, the numeric parameters.
102      push @rows, $cgi->Tr($cgi->td("Commonality"),      push @rows, $cgi->Tr($cgi->td("Commonality"),
103                           $cgi->td($cgi->textfield(-name => 'commonality',                           $cgi->td($cgi->textfield(-name => 'commonality',
104                                                    -value => $commonality,                                                    -value => $commonality,
105                                                    -size => 5) . " " .                                                    -size => 5))),
106                    $cgi->Tr($cgi->td(), $cgi->td(
107                                    $cgi->checkbox(-name => 'statistical',                                    $cgi->checkbox(-name => 'statistical',
108                                                   -checked => $statistical,                                                   -checked => $statistical,
109                                                   -value => 1,                                                   -value => 1,
# Line 102  Line 112 
112                           $cgi->td($cgi->textfield(-name => 'cutoff',                           $cgi->td($cgi->textfield(-name => 'cutoff',
113                                                    -value => $cutoff,                                                    -value => $cutoff,
114                                                    -size => 5)));                                                    -size => 5)));
115      push @rows, $self->SubmitRow();      # Next, the feature filter rows.
     # The next rows have the given genome and a feature filter.  
     push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Given Genome"),  
                          $cgi->td({colspan => 2}, $givenMenu));  
116      push @rows, $self->FeatureFilterRows();      push @rows, $self->FeatureFilterRows();
117      # Now show the target and exclusion menus.      # Finally, the submit button.
118      push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Target Genomes (Set 1)"),      push @rows, $self->SubmitRow();
                          $cgi->td({colspan => 2}, $targetMenu));  
     push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Exclusion Genomes (Set 2)"),  
                          $cgi->td({colspan => 2}, $excludeMenu));  
119      # Create the table.      # Create the table.
120      $retVal .= $self->MakeTable(\@rows);      $retVal .= $self->MakeTable(\@rows);
121      # Close the form.      # Close the form.
# Line 140  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 167  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 227  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  }  }
# Line 253  Line 292 
292      # Get the parameters.      # Get the parameters.
293      my ($self) = @_;      my ($self) = @_;
294      # Return the result.      # Return the result.
295      return "Search for features that are common to a group of organisms or that discriminate between two groups of organisms.";      return "Search for genes that are common to a group of organisms or that discriminate between two groups of organisms.";
296  }  }
297    
298  =head2 Internal Utilities  =head2 Internal Utilities

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3