Difference between revisions of "GBrowse/AJAXhandlerScript"

From GMOD
Jump to: navigation, search
(Changes To Configuration File)
(Changes To Configuration File)
Line 63: Line 63:
 
             $msg .= "<pre style='background:gainsboro;padding:10px'>";
 
             $msg .= "<pre style='background:gainsboro;padding:10px'>";
 
             for my $k (sort keys %$args) {
 
             for my $k (sort keys %$args) {
               $msg .= "$k => $$args{$k}\n";
+
               $msg .= "$k\t=>\t$$args{$k}\n";
 
             }
 
             }
 
             return $msg."</pre>";
 
             return $msg."</pre>";

Revision as of 17:33, 9 November 2007

Proposal to convert gbrowse_details to an AJAX request handler

A temporary page to describe a low-impact change to existing code to provide a built-in ajax handler for Gbrowse

Changes to gbrowse_details

  • A new CGI parameter to invoke the AJAX-handling behavior
my $rmt   = param('remote');


  • A response is triggered after the feature(s) are defined but before PrintTop is called.
if (defined $rmt) {
  print header,start_html;
  print remote_content($rmt,$features[0]);
  print end_html;
  exit 0;
}
  • The remote_content subroutine will get the text or coderef. It will return the text or execute the callback with user-defined arguments
# do something for popup balloons                                                                                                                                             
sub remote_content {
  my $key = shift; # the key for the text or code-ref in the gbrowse config file                                                                                              
  my $feat = shift;
  my $contents = $CONFIG->config->code_setting('TOOLTIPS',$key) or die "$key is empty";                                                                                                                 
  my $coderef = (ref $contents||'') eq 'CODE';
  return $contents unless $coderef;  
  # paranoia?                                                                                                                                                                 
  die "Error: $key is not a CODE-REF" if ref $contents && !$coderef;
  # args are user-defined                                                                                                                                                     
  my %args = (feature => $feat) if $feat;
  for my $arg (param()) {
    my @vals = param($arg);
    my $val  = @vals > 1 ? \@vals : $vals[0];
    $args{$arg} = $val;
  }
  return $contents->(\%args);
}

Changes To Configuration File

  • A new section [TOOLTIPS] that has all the the config options or callbacks you need to access through gbrowse_details


# callback to be run remotely by gbrowse_details for AJAX/iframe balloons
[TOOLTIPS]
default = sub {
                my $args  = shift;
                my $feat  = $args->{feature};
                my $name  = $feat->display_name;
                my $type  = $feat->primary_tag;
                my $class = $feat->class;
                my $extra = join(' ',$feat->each_tag_value('Note')) if $feat->has_tag('Note');
                my $n     = $name =~ /^[AEIOU]/ ? 'n' : '';
                my $msg   = "Hello, I am $name, a$n $type of class $class";
                $msg     .= "<br>I am described as a <b>$extra</b><br>" if $extra;
                my $seq   = substr $feat->seq->seq, 0, 400;
                $seq =~ s/(\S{40})/$1\n/g;
                return "<table><tr><th bgcolor='lightsteelblue'>$name</th><tr>" .
                       "<tr><td>$msg</td></tr><tr><td bgcolor='lightyellow'>".
                       "First 400 bp:<br><pre>>$name\n$seq</pre></td></tr></table>";
           }
params  = sub {
            my $args = shift;
            my $msg = "<h3>Arguments received<h3>";
            $msg .= "<pre style='background:gainsboro;padding:10px'>";
            for my $k (sort keys %$args) {
              $msg .= "$k\t=>\t$$args{$k}\n";
            }
            return $msg."</pre>";
         }

Changes to Bio::Graphics::Browser