GBrowse
view release on metacpan or search on metacpan
conf/plugins/TrackFinder.pm view on Meta::CPAN
package Bio::Graphics::Browser2::Plugin::TrackFinder;
# $Id: SourceTrackFinder.pm,v 1.2 2009-05-20 21:29:40 lstein Exp $
use strict;
use CGI qw(:standard *table);
use base 'Bio::Graphics::Browser2::Plugin';
use Bio::Graphics::Browser2::Util 'shellwords';
our $VERSION = '0.25';
sub name { "Track Finder" }
sub description {
return p("The track finder filters the track table by the contents of its key, comments and select fields.");
}
sub type { 'trackfilter' }
sub init { }
sub config_defaults {
my $self = shift;
# this line gets all the options defined in the "[TrackFinder:plugin]" stanza
my %fields = map {$_=>undef} $self->get_fields;
return \%fields;
}
# this method gets all the options defined in the "[SourceTrackFinder:plugin]" stanza
sub get_fields {
my $self = shift;
return $self->browser_config->plugin_setting;
}
sub reconfigure {
my $self = shift;
my $current_config = $self->configuration;
$current_config->{keywords} = $self->config_param('keywords');
}
sub configure_form {
my $self = shift;
my $current_config = $self->configuration;
my $source = $self->browser_config;
my $html = '';
$html .= div({-class=>'searchbody'},
b('Search: ').textfield(-id => 'plugin_TrackFinderKeywords',
-name => $self->config_name('keywords'),
-onKeyDown => "Controller.busy();if (typeof(timeOutID) != 'undefined') clearTimeout(timeOutID);timeOutID= setTimeout('Controller.idle();doPluginUpdate()',500)",
-override => 1,
-value => $current_config->{keywords},
-onBlur => 'clearTimeout(timeOutID)',
),
input({-type => 'checkbox',
-id => 'stickySearch',
-value => 'Stick to top when scrolled'
}
),
label({-for => 'stickySearch'}, 'Stick to top when scrolled')
);
$html .= button(-value => 'Clear',
-onClick => "\$('plugin_TrackFinderKeywords').clear();doPluginUpdate()",
);
return $html;
}
sub filter_tracks {
my $self = shift;
my $track_labels = shift;
my $source = shift;
my $config = $self->configuration;
my @keywords = map {quotemeta($_)} shellwords $config->{keywords};
my @searches = get_fields($self);
my @result;
LABEL:
for my $l (@$track_labels) {
do {push @result,$l; next LABEL} if $l =~ /^(plugin|file|http|das)/;
my @searched_fields = @searches ? @searches :(qw(key keywords select),"subtrack select labels");
my $aggregate_text = join ' ',map {$source->code_setting($l=>$_)} @searched_fields;
$aggregate_text ||= $l;
my $labels = $source->subtrack_scan_list($l);
$aggregate_text .= " @$labels" if $labels && @$labels;
for my $k (@keywords) {
next LABEL unless $aggregate_text =~ /$k/i;
}
push @result,$l;
}
return @result;
}
sub hilite_terms {
my $self = shift;
my $config = $self->configuration;
my @keywords = map {quotemeta($_)} shellwords $config->{keywords};
return @keywords;
}
# Scripts required by the plugin.
sub scripts {
return qw(scrollfix.js);
}
# Functions to run once the content has been loaded.
sub onLoads {
my %loads = (track_page => "scrollfix.setup();");
( run in 0.770 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )