| 1 | package Bio::Graphics::Browser2::Plugin::SourceTrackFinder; | ||
| 2 | # $Id: SourceTrackFinder.pm,v 1.2 2009-05-20 21:29:40 lstein Exp $ | ||
| 3 | use strict; | ||
| 4 | use CGI qw(:standard *table); | ||
| 5 | use base 'Bio::Graphics::Browser2::Plugin'; | ||
| 6 | use Bio::Graphics::Browser2::Util 'shellwords'; | ||
| 7 | our $VERSION = '0.25'; | ||
| 8 | |||
| 9 | sub name { "Source Track Finder" } | ||
| 10 | |||
| 11 | sub description { | ||
| 12 | return p("The source track finder filters the track table by the data and config source the track."); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub type { 'trackfilter' } | ||
| 16 | |||
| 17 | sub init { } | ||
| 18 | |||
| 19 | sub config_defaults { | ||
| 20 | my $self = shift; | ||
| 21 | |||
| 22 | # this line gets all the options defined in the "[SourceTrackFinder:plugin]" stanza | ||
| 23 | my %fields = map {$_=>undef} $self->get_fields; | ||
| 24 | |||
| 25 | return \%fields; | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | # this method gets all the options defined in the "[SourceTrackFinder:plugin]" stanza | ||
| 30 | sub get_fields { | ||
| 31 | my $self = shift; | ||
| 32 | return $self->browser_config->plugin_setting; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub reconfigure { | ||
| 36 | my $self = shift; | ||
| 37 | my $current_config = $self->configuration; | ||
| 38 | |||
| 39 | for my $f ($self->get_fields) { | ||
| 40 | $current_config->{lc $f} = $self->config_param($f); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | sub configure_form { | ||
| 45 | my $self = shift; | ||
| 46 | my $current_config = $self->configuration; | ||
| 47 | my $source = $self->browser_config; | ||
| 48 | |||
| 49 | my @fields = $self->get_fields; | ||
| 50 | my @elements; | ||
| 51 | |||
| 52 | for my $f (@fields) { | ||
| 53 | my @options = ('',shellwords($source->plugin_setting($f))); | ||
| 54 | push @elements,b(ucfirst $f.':'); | ||
| 55 | push @elements, | ||
| 56 | popup_menu( | ||
| 57 | -id => "plugin_$f", | ||
| 58 | -class => "SourceTrackFinderPopup", | ||
| 59 | -name => $self->config_name($f), | ||
| 60 | -values => \@options, | ||
| 61 | -default => $current_config->{$f}, | ||
| 62 | -override => 1, | ||
| 63 | -onChange => 'doPluginUpdate()', | ||
| 64 | ) | ||
| 65 | } | ||
| 66 | push @elements, | ||
| 67 | button(-value => 'Clear', | ||
| 68 | -onClick => q($$('.SourceTrackFinderPopup').each(function(m) {m.selectedIndex=0}); doPluginUpdate();) | ||
| 69 | ); | ||
| 70 | return join ' ',@elements; | ||
| 71 | |||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | sub filter_tracks { | ||
| 76 | my $self = shift; | ||
| 77 | my $track_labels = shift; | ||
| 78 | my $source = shift; | ||
| 79 | |||
| 80 | my $config = $self->configuration; | ||
| 81 | my @fields = $self->get_fields; | ||
| 82 | my %filters = map {lc $_ => $config->{lc $_}} @fields; | ||
| 83 | |||
| 84 | my @result; | ||
| 85 | |||
| 86 | LABEL: | ||
| 87 | for my $l (@$track_labels) { | ||
| 88 | do {push @result,$l; next LABEL} if $l =~ /^(plugin|file|http|das)/; | ||
| 89 | |||
| 90 | for my $f (keys %filters) { | ||
| 91 | my %values = map {lc $_=>1} shellwords $source->fallback_setting($l=>$f); | ||
| 92 | next LABEL if length $filters{$f} && !$values{lc $filters{$f}}; | ||
| 93 | } | ||
| 94 | |||
| 95 | push @result,$l; | ||
| 96 | } | ||
| 97 | return @result; | ||
| 98 | } | ||
| 99 | |||
| 100 | 1; | ||
| 101 | |||
| 102 | __END__ |