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

Diff of /Sprout/SearchHelper.pm

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

revision 1.16, Wed Nov 15 12:02:46 2006 UTC revision 1.18, Sat Nov 18 20:36:49 2006 UTC
# Line 454  Line 454 
454      my ($self, $title) = @_;      my ($self, $title) = @_;
455      # Get the CGI object.      # Get the CGI object.
456      my $cgi = $self->Q();      my $cgi = $self->Q();
457      # Start the form.      # Start the form. Note we use the override option on the Class value, in
458        # case the Advanced button was used.
459      my $retVal = "<div class=\"search\">\n" .      my $retVal = "<div class=\"search\">\n" .
460                   $cgi->start_form(-method => 'POST',                   $cgi->start_form(-method => 'POST',
461                                    -action => $cgi->url(-relative => 1),                                    -action => $cgi->url(-relative => 1),
462                                    -name => $self->FormName()) .                                    -name => $self->FormName()) .
463                   $cgi->hidden(-name => 'Class',                   $cgi->hidden(-name => 'Class',
464                                -value => $self->{class}) .                                -value => $self->{class},
465                                  -override => 1) .
466                   $cgi->hidden(-name => 'SPROUT',                   $cgi->hidden(-name => 'SPROUT',
467                                -value => 1) .                                -value => 1) .
468                   $cgi->h3($title);                   $cgi->h3($title);
# Line 947  Line 949 
949    
950  =head3 ComputeFASTA  =head3 ComputeFASTA
951    
952  C<< my $fasta = $shelp->ComputeFASTA($incomingType, $desiredType, $sequence); >>  C<< my $fasta = $shelp->ComputeFASTA($desiredType, $sequence); >>
953    
954  Parse a sequence input and convert it into a FASTA string of the desired type. Note  Parse a sequence input and convert it into a FASTA string of the desired type.
 that it is possible to convert a DNA sequence into a protein sequence, but the reverse  
 is not possible.  
955    
956  =over 4  =over 4
957    
 =item incomingType  
   
 C<dna> if this is a DNA sequence, C<prot> if this is a protein sequence.  
   
958  =item desiredType  =item desiredType
959    
960  C<dna> to return a DNA sequence, C<prot> to return a protein sequence. If the  C<dna> to return a DNA sequence, C<prot> to return a protein sequence.
 I<$incomingType> is C<prot> and this value is C<dna>, an error will be thrown.  
961    
962  =item sequence  =item sequence
963    
# Line 991  Line 986 
986      my $okFlag = 1;      my $okFlag = 1;
987      # Create variables to hold the FASTA label and data.      # Create variables to hold the FASTA label and data.
988      my ($fastaLabel, $fastaData);      my ($fastaLabel, $fastaData);
989      Trace("FASTA incoming type is $incomingType, desired type is $desiredType.") if T(4);      Trace("FASTA desired type is $desiredType.") if T(4);
990      # Check for a feature specification.      # Check for a feature specification.
991      if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {      if ($sequence =~ /^\s*(\w+\|\S+)\s*$/) {
992          # Here we have a feature ID in $1. We'll need the Sprout object to process          # Here we have a feature ID in $1. We'll need the Sprout object to process
# Line 1004  Line 999 
999          # exist.          # exist.
1000          my ($figID) = $sprout->FeaturesByAlias($fid);          my ($figID) = $sprout->FeaturesByAlias($fid);
1001          if (! $figID) {          if (! $figID) {
1002              $self->SetMessage("No feature found with the ID \"$fid\".");              $self->SetMessage("No gene found with the ID \"$fid\".");
1003              $okFlag = 0;              $okFlag = 0;
1004          } else {          } else {
1005              # Set the FASTA label.              # Set the FASTA label.
# Line 1021  Line 1016 
1016                  Trace(length $fastaData . " characters returned for DNA of $fastaLabel.") if T(3);                  Trace(length $fastaData . " characters returned for DNA of $fastaLabel.") if T(3);
1017              }              }
1018          }          }
     } elsif ($incomingType eq 'prot' && $desiredType eq 'dna') {  
         # Here we're being asked to do an impossible conversion.  
         $self->SetMessage("Cannot convert a protein sequence to DNA.");  
         $okFlag = 0;  
1019      } else {      } else {
1020          Trace("Analyzing FASTA sequence.") if T(4);          Trace("Analyzing FASTA sequence.") if T(4);
1021          # Here we are expecting a FASTA. We need to see if there's a label.          # Here we are expecting a FASTA. We need to see if there's a label.
# Line 1037  Line 1028 
1028              Trace("No label found in match to sequence:\n$sequence") if T(4);              Trace("No label found in match to sequence:\n$sequence") if T(4);
1029              # Here we have no label, so we create one and use the entire sequence              # Here we have no label, so we create one and use the entire sequence
1030              # as data.              # as data.
1031              $fastaLabel = "User-specified $incomingType sequence";              $fastaLabel = "User-specified $desiredType sequence";
1032              $fastaData = $sequence;              $fastaData = $sequence;
1033          }          }
1034          # The next step is to clean the junk out of the sequence.          # The next step is to clean the junk out of the sequence.
1035          $fastaData =~ s/\n//g;          $fastaData =~ s/\n//g;
1036          $fastaData =~ s/\s+//g;          $fastaData =~ s/\s+//g;
1037          # Finally, if the user wants to convert to protein, we do it here. Note that          # Finally, verify that it's DNA if we're doing DNA stuff.
1038          # we've already prevented a conversion from protein to DNA.          if ($desiredType eq 'dna' && $fastaData =~ /[^agct]/i) {
         if ($incomingType ne $desiredType) {  
             $fastaData = Sprout::Protein($fastaData);  
             # Check for bad characters.  
             if ($fastaData =~ /X/) {  
                 $self->SetMessage("Invalid characters detected. Is the input really of type $incomingType?");  
                 $okFlag = 0;  
             }  
         } elsif ($desiredType eq 'dna' && $fastaData =~ /[^agct]/i) {  
1039              $self->SetMessage("Invaid characters detected. Is the input really a DNA sequence?");              $self->SetMessage("Invaid characters detected. Is the input really a DNA sequence?");
1040              $okFlag = 0;              $okFlag = 0;
1041          }          }
# Line 1367  Line 1350 
1350          # the search box. This allows the user to type text and have all genomes containing          # the search box. This allows the user to type text and have all genomes containing
1351          # the text selected automatically.          # the text selected automatically.
1352          my $searchThingName = "${menuName}_SearchThing";          my $searchThingName = "${menuName}_SearchThing";
1353          push @lines, "<br>Select genomes containing <INPUT type=\"text\" name=\"$searchThingName\" " .          push @lines, "<br />" .
1354                       "size=\"30\" onBlur=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />";                       "<INPUT type=\"button\" name=\"Search\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectViaSearch($menuName, $searchThingName); $showSelect\" />&nbsp;" .
1355                         "<INPUT type=\"text\" name=\"$searchThingName\" size=\"30\" />";
1356          # Next are the buttons to set and clear selections.          # Next are the buttons to set and clear selections.
1357          push @lines, "<br />";          push @lines, "<br />";
1358          push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";          push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll($menuName); $showSelect\" />";
# Line 1493  Line 1477 
1477    
1478  =head3 SubmitRow  =head3 SubmitRow
1479    
1480  C<< my $htmlText = $shelp->SubmitRow(); >>  C<< my $htmlText = $shelp->SubmitRow($caption); >>
1481    
1482  Returns the HTML text for the row containing the page size control  Returns the HTML text for the row containing the page size control
1483  and the submit button. All searches should have this row somewhere  and the submit button. All searches should have this row somewhere
1484  near the top of the form.  near the top of the form.
1485    
1486    =over 4
1487    
1488    =item caption (optional)
1489    
1490    Caption to be put on the search button. The default is C<Go>.
1491    
1492    =item RETURN
1493    
1494    Returns a table row containing the controls for submitting the search
1495    and tuning the results.
1496    
1497    =back
1498    
1499  =cut  =cut
1500    
1501  sub SubmitRow {  sub SubmitRow {
1502      # Get the parameters.      # Get the parameters.
1503      my ($self) = @_;      my ($self, $caption) = @_;
1504      my $cgi = $self->Q();      my $cgi = $self->Q();
1505        # Compute the button caption.
1506        my $realCaption = (defined $caption ? $caption : 'Go');
1507      # Get the current page size.      # Get the current page size.
1508      my $pageSize = $cgi->param('PageSize');      my $pageSize = $cgi->param('PageSize');
1509      # Get the incoming external-link flag.      # Get the incoming external-link flag.
# Line 1519  Line 1518 
1518                                                    -label => 'Show URL')),                                                    -label => 'Show URL')),
1519                            $cgi->td($cgi->submit(-class => 'goButton',                            $cgi->td($cgi->submit(-class => 'goButton',
1520                                                  -name => 'Search',                                                  -name => 'Search',
1521                                                  -value => 'Go')));                                                  -value => $realCaption)));
1522      # Return the result.      # Return the result.
1523      return $retVal;      return $retVal;
1524  }  }
# Line 1613  Line 1612 
1612          $seg_id =~ s/:/--/g;          $seg_id =~ s/:/--/g;
1613          Trace("Show limits are ($show_start,$show_stop) in genome $genomeID with ref $seg_id.") if T(3);          Trace("Show limits are ($show_start,$show_stop) in genome $genomeID with ref $seg_id.") if T(3);
1614          # Assemble all the pieces.          # Assemble all the pieces.
1615          $retVal = "gbrowse.cgi/GB_$genomeID?ref=$seg_id&start=$show_start&stop=$show_stop";          $retVal = "gbrowse.cgi/GB_$genomeID?ref=$seg_id;start=$show_start;stop=$show_stop";
1616      }      }
1617      # Return the result.      # Return the result.
1618      return $retVal;      return $retVal;
# Line 2273  Line 2272 
2272      } elsif ($colName =~ /^keyword:(.+)$/) {      } elsif ($colName =~ /^keyword:(.+)$/) {
2273          $retVal = ucfirst $1;          $retVal = ucfirst $1;
2274      } elsif ($colName eq 'orgName') {      } elsif ($colName eq 'orgName') {
2275          $retVal = "Feature Name";          $retVal = "Gene Name";
2276      } elsif ($colName eq 'protlink') {      } elsif ($colName eq 'protlink') {
2277          $retVal = "NMPDR Protein Page";          $retVal = "NMPDR Protein Page";
2278      } elsif ($colName eq 'subsystem') {      } elsif ($colName eq 'subsystem') {
# Line 2346  Line 2345 
2345          ($retVal) = $record->Value('Feature(assignment)');          ($retVal) = $record->Value('Feature(assignment)');
2346      } elsif ($colName eq 'gblink') {      } elsif ($colName eq 'gblink') {
2347          # Here we want a link to the GBrowse page using the official GBrowse button.          # Here we want a link to the GBrowse page using the official GBrowse button.
2348          my $gurl = "GetGBrowse.cgi?fid=$fid";          $retVal = Formlet('GBrowse', "GetGBrowse.cgi", undef,
2349          $retVal = $cgi->a({ href => $gurl, title => "GBrowse for $fid" },                            fid => $fid);
                           $cgi->img({ src => "../images/button-gbrowse.png",  
                                       border => 0 })  
                          );  
2350      } elsif ($colName eq 'group') {      } elsif ($colName eq 'group') {
2351          # Get the NMPDR group name.          # Get the NMPDR group name.
2352          my (undef, $group) = $self->OrganismData($fid);          my (undef, $group) = $self->OrganismData($fid);
# Line 2367  Line 2363 
2363          $retVal = $self->FeatureName($fid);          $retVal = $self->FeatureName($fid);
2364      } elsif ($colName eq 'protlink') {      } elsif ($colName eq 'protlink') {
2365          # Here we want a link to the protein page using the official NMPDR button.          # Here we want a link to the protein page using the official NMPDR button.
2366          my $hurl = HTML::fid_link($cgi, $fid, 0, 1);          $retVal = Formlet('NMPDR', "protein.cgi", undef,
2367          $retVal = $cgi->a({ href => $hurl, title => "Protein page for $fid" },                            prot => $fid, SPROUT => 1, new_framework => 0,
2368                            $cgi->img({ src => "../images/button-nmpdr.png",                            user => '');
                                      border => 0 })  
                          );  
2369      }elsif ($colName eq 'subsystem') {      }elsif ($colName eq 'subsystem') {
2370          # Another run-time column: subsystem list.          # Another run-time column: subsystem list.
2371          $retVal = "%%subsystem=$fid";          $retVal = "%%subsystem=$fid";
# Line 2573  Line 2567 
2567      return $retVal;      return $retVal;
2568  }  }
2569    
2570    =head3 Formlet
2571    
2572    C<< my $html = SearchHelper::Formlet($caption, $url, $target, %parms); >>
2573    
2574    Create a mini-form that posts to the specified URL with the specified parameters. The
2575    parameters will be stored in hidden fields, and the form's only visible control will
2576    be a submit button with the specified caption.
2577    
2578    Note that we don't use B<CGI.pm> services here because they generate forms with extra characters
2579    and tags that we don't want to deal with.
2580    
2581    =over 4
2582    
2583    =item caption
2584    
2585    Caption to be put on the form button.
2586    
2587    =item url
2588    
2589    URL to be put in the form's action parameter.
2590    
2591    =item target
2592    
2593    Frame or target in which the form results should appear. If C<undef> is specified,
2594    the default target will be used.
2595    
2596    =item parms
2597    
2598    Hash containing the parameter names as keys and the parameter values as values.
2599    
2600    =back
2601    
2602    =cut
2603    
2604    sub Formlet {
2605        # Get the parameters.
2606        my ($caption, $url, $target, %parms) = @_;
2607        # Compute the target HTML.
2608        my $targetHtml = ($target ? " target=\"$target\"" : "");
2609        # Start the form.
2610        my $retVal = "<form method=\"POST\" action=\"$url\"$target>";
2611        # Add the parameters.
2612        for my $parm (keys %parms) {
2613            $retVal .= "<input type=\"hidden\" name=\"$parm\" value=\"$parms{$parm}\" />";
2614        }
2615        # Put in the button.
2616        $retVal .= "<input type=\"submit\" name=\"submit\" value=\"$caption\" class=\"button\" />";
2617        # Close the form.
2618        $retVal .= "</form>";
2619        # Return the result.
2620        return $retVal;
2621    }
2622    
2623  =head2 Virtual Methods  =head2 Virtual Methods
2624    
2625  =head3 Form  =head3 Form

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.18

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3