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

Diff of /Sprout/SHPropSearch.pm

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

revision 1.3, Wed Nov 15 12:13:05 2006 UTC revision 1.8, Mon Jan 19 21:56:19 2009 UTC
# Line 4  Line 4 
4    
5      use strict;      use strict;
6      use Tracer;      use Tracer;
7      use SearchHelper;      use CGI qw(-nosticky);
     use CGI;  
8      use HTML;      use HTML;
9      use Sprout;      use Sprout;
10      use FeatureData;      use RHFeatures;
11      use FeatureQuery;      use base 'SearchHelper';
   
     our @ISA = qw(SearchHelper);  
12    
13  =head1 Property Search Feature Search Helper  =head1 Property Search Feature Search Helper
14    
# Line 43  Line 40 
40    
41  =head3 Form  =head3 Form
42    
43  C<< my $html = $shelp->Form(); >>      my $html = $shelp->Form();
44    
45  Generate the HTML for a form to request a new search.  Generate the HTML for a form to request a new search.
46    
# Line 60  Line 57 
57      my @rows = ();      my @rows = ();
58      # First, we generate the genome menu.      # First, we generate the genome menu.
59      my $genomeMenu = $self->NmpdrGenomeMenu('genome', 0, [$cgi->param('genome')]);      my $genomeMenu = $self->NmpdrGenomeMenu('genome', 0, [$cgi->param('genome')]);
60      push @rows, $cgi->Tr($cgi->td({valign => "top"}, "Genome"),      push @rows, CGI::Tr(CGI::td({valign => "top"}, "Genome"),
61                           $cgi->td({colspan => 2}, $genomeMenu));                           CGI::td({colspan => 2}, $genomeMenu));
62      # Now add the property rows.      # Now add the property rows.
63      my @pairs = grep { $_ } $cgi->param('propertyPair');      my @pairs = grep { $_ } $cgi->param('propertyPair');
64      Trace(scalar(@pairs) . " property pairs read from CGI.") if T(3);      Trace(scalar(@pairs) . " property pairs read from CGI.") if T(3);
65      for (my $i = 1; $i <= $FIG_Config::prop_search_limit; $i++) {      for (my $i = 1; $i <= $FIG_Config::prop_search_limit; $i++) {
66          my $thisPair = shift @pairs;          my $thisPair = shift @pairs;
67          Trace("\"$thisPair\" popped from pairs array. " . scalar(@pairs) . " entries left.") if T(3);          Trace("\"$thisPair\" popped from pairs array. " . scalar(@pairs) . " entries left.") if T(3);
68          push @rows, $cgi->Tr($cgi->td("Name=Value ($i)"),          push @rows, CGI::Tr(CGI::td("Name=Value ($i)"),
69                               $cgi->td({colspan => 2}, $cgi->textfield(-name => 'propertyPair',                               CGI::td({colspan => 2}, CGI::textfield(-name => 'propertyPair',
70                                                                        -value => $thisPair,                                                                        -value => $thisPair,
                                                                       -override => 1,  
71                                                                        -size => 40)));                                                                        -size => 40)));
72      }      }
73      # Finally, the submit row.      # Finally, the submit row.
# Line 86  Line 82 
82    
83  =head3 Find  =head3 Find
84    
85  C<< my $resultCount = $shelp->Find(); >>      my $resultCount = $shelp->Find();
86    
87  Conduct a search based on the current CGI query parameters. The search results will  Conduct a search based on the current CGI query parameters. The search results will
88  be written to the session cache file and the number of results will be  be written to the session cache file and the number of results will be
# Line 143  Line 139 
139          } else {          } else {
140              # If we are here, then we have a genome ($genomeID) and a list              # If we are here, then we have a genome ($genomeID) and a list
141              # of desired property IDs (@propIDs). That means we can search.              # of desired property IDs (@propIDs). That means we can search.
142                # Create the result helper.
143                my $rhelp = RHFeatures->new($self);
144                # Set the default columns.
145                $self->DefaultColumns($rhelp);
146                # Add the value columm at the front.
147                $rhelp->AddExtraColumn(values => 0, title => 'Values', download => 'list',
148                                       style => 'leftAlign');
149              # Initialize the session file.              # Initialize the session file.
150              $self->OpenSession();              $self->OpenSession($rhelp);
151              # Initialize the result counter.              # Initialize the result counter.
152              $retVal = 0;              $retVal = 0;
             # Create a feature data object for tracking the results.  
             my $fd = FeatureData->new($self);  
153              # Create a variable to store the property value HTML.              # Create a variable to store the property value HTML.
154              my @extraCols = ();              my @extraCols = ();
155              # Denote that we currently don't have a feature.              # Denote that we currently don't have a feature.
# Line 160  Line 161 
161                                       [$genomeID]);                                       [$genomeID]);
162              # Loop through the query results. The same feature may appear multiple times,              # Loop through the query results. The same feature may appear multiple times,
163              # but all the multiples will be grouped together.              # but all the multiples will be grouped together.
164                my $savedRow;
165              while (my $row = $query->Fetch()) {              while (my $row = $query->Fetch()) {
166                  # Get the feature ID;                  # Get the feature ID;
167                  my ($newFid) = $row->Value('Feature(id)');                  my $newFid = $row->PrimaryValue('Feature(id)');
168                  # Check to see if we have a new feature coming in. Note we check for undef                  # Check to see if we have a new feature coming in. Note we check for undef
169                  # to avoid a run-time warning.                  # to avoid a run-time warning.
170                  if (! defined($fid) || $newFid ne $fid) {                  if (! defined($fid) || $newFid ne $fid) {
171                      if (defined($fid)) {                      if (defined($fid)) {
172                          # Here we have an old feature to output.                          # Here we have an old feature to output.
173                          $self->DumpFeature($fd, \@extraCols);                          $self->DumpFeature($rhelp, $savedRow, \@extraCols);
174                          $retVal++;                          $retVal++;
175                      }                      }
176                      # Now we can store the new feature.                      # Clear the property value list.
                     $fd->Store($row);  
177                      @extraCols = ();                      @extraCols = ();
178                        # Save this as the currently-active feature.
179                        $savedRow = $row;
180                      $fid = $newFid;                      $fid = $newFid;
181                  }                  }
182                  # Get this row's property data for the extra column.                  # Get this row's property data for the extra column.
# Line 182  Line 185 
185                                                           'HasProperty(evidence)']);                                                           'HasProperty(evidence)']);
186                  # If the evidence is a URL, format it as a link; otherwise, ignore it.                  # If the evidence is a URL, format it as a link; otherwise, ignore it.
187                  if ($url =~ m!http://!) {                  if ($url =~ m!http://!) {
188                      push @extraCols, $cgi->a({href => $url}, $value);                      push @extraCols, CGI::a({href => $url}, $value);
189                  } else {                  } else {
190                      push @extraCols, $value;                      push @extraCols, $value;
191                  }                  }
192              }              }
193              # If there's a feature still in the buffer, write it here.              # If there's a feature still in the buffer, write it here.
194              if (defined $fid) {              if (defined $fid) {
195                  $self->DumpFeature($fd, \@extraCols);                  $self->DumpFeature($rhelp, $savedRow, \@extraCols);
196                  $retVal++;                  $retVal++;
197              }              }
198              # Close the session file.              # Close the session file.
# Line 202  Line 205 
205    
206  =head3 DumpFeature  =head3 DumpFeature
207    
208  C<< $shelp->DumpFeature($fd, \@extraCols); >>      $shelp->DumpFeature($rhelp, $record, \@extraCols);
209    
210  Write the data for the current feature to the output.  Write the data for the current feature to the output.
211    
212  =over 4  =over 4
213    
214  =item fd  =item rhelp
215    
216    Feature result helper.
217    
218    =item record
219    
220  B<FeatureData> object for the feature.  B<ERDBObject> containing the feature.
221    
222  =item extraCols  =item extraCols
223    
# Line 222  Line 229 
229    
230  sub DumpFeature {  sub DumpFeature {
231      # Get the parameters.      # Get the parameters.
232      my ($self, $fd, $extraCols) = @_;      my ($self, $rhelp, $record, $extraCols) = @_;
233      # Format the extra column data.      # Format the extra column data.
234      my $extraColumn = join(", ", @{$extraCols});      my $extraColumn = join(", ", @{$extraCols});
235      # Add the extra column data.      # Add the extra column data.
236      $fd->AddExtraColumns(values => $extraColumn);      $rhelp->PutExtraColumns(values => $extraColumn);
237        # Compute the sort key and the feature ID.
238        my $sortKey = $rhelp->SortKey($record);
239        my $fid = $record->PrimaryValue('Feature(id)');
240      # Put everything to the output.      # Put everything to the output.
241      $self->PutFeature($fd);      $rhelp->PutData($sortKey, $fid, $record);
242  }  }
243    
244  =head3 Description  =head3 Description
245    
246  C<< my $htmlText = $shelp->Description(); >>      my $htmlText = $shelp->Description();
247    
248  Return a description of this search. The description is used for the table of contents  Return a description of this search. The description is used for the table of contents
249  on the main search tools page. It may contain HTML, but it should be character-level,  on the main search tools page. It may contain HTML, but it should be character-level,
# Line 245  Line 255 
255      # Get the parameters.      # Get the parameters.
256      my ($self) = @_;      my ($self) = @_;
257      # Return the result.      # Return the result.
258      return "Search for features in a specific genome with specified property values.";      return "Search for genes in a specific genome with specified property values.";
259  }  }
260    
261  1;  1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3