Skip to content

Commit

Permalink
added track filtering functionality as well as ability to select trac…
Browse files Browse the repository at this point in the history
…ks by their source
  • Loading branch information
lstein committed May 20, 2009
1 parent f6c4672 commit 1369b5b
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 30 deletions.
6 changes: 6 additions & 0 deletions conf/languages/POSIX.pm
Expand Up @@ -141,6 +141,10 @@ END

TRACKS => 'Tracks',

TRACK_SELECT => 'Search for Specific Tracks',

TRACK_NAME => 'Track name',

EXTERNAL_TRACKS => '<i>External tracks italicized</i>',

OVERVIEW_TRACKS => '<sup>*</sup>Overview track',
Expand Down Expand Up @@ -193,6 +197,8 @@ END

CLEAR_HIGHLIGHTING => 'Clear highlighting',

CLEAR => 'Clear',

UPDATE => 'Update',

UPDATE_TRACKS => 'Update Tracks',
Expand Down
99 changes: 99 additions & 0 deletions conf/plugins/SimpleTrackFinder.pm
@@ -0,0 +1,99 @@
package Bio::Graphics::Browser::Plugin::SimpleTrackFinder;
# $Id: SimpleTrackFinder.pm,v 1.1 2009-05-20 20:36:20 lstein Exp $
use strict;
use CGI qw(:standard *table);
use base 'Bio::Graphics::Browser::Plugin';
our $VERSION = '0.25';

sub name { "Simple Track Finder" }

sub description {
return p("The simple track finder filters the track table by the name of the track.");
}

sub type { 'trackfilter' }

sub init { }

sub config_defaults {
my $self = shift;
return {
track_name => undef,
};
}

sub reconfigure {
my $self = shift;
my $current_config = $self->configuration;
$current_config->{track_name} = $self->config_param('track_name');
}

sub configure_form {
my $self = shift;
my $current_config = $self->configuration;
my $name = $current_config->{track_name};
return
b('Partial or full track name:').
textfield(-id => 'track_name_filter',
-name => $self->config_name('track_name'),
-default => $name,
-override => 1,
-onKeyDown=>'if (event.keyCode==13) doPluginUpdate()',
).
button(-value => 'Clear',
-onClick => "\$('track_name_filter').clear(); doPluginUpdate()");
}

sub filter_tracks {
my $self = shift;
my $tracks = shift;
my $source = shift;

my $config = $self->configuration;
my $name = $config->{track_name} or return @$tracks;

my @filtered = grep {
my $key = $source->setting($_=>'key') || $_;
$key =~ m/$name/i
} @$tracks;
warn "name = $name, filtered = @filtered";
return @filtered;
}

1;

__END__
=head1 NAME
Bio::Graphics::Browser::Plugin::SimpleTrackFinder - Limit list of tracks to those that match a name pattern
=head1 SYNOPSIS
In the appropriate gbrowse configuration file:
track filter = SimpleTrackFinder
=head1 DESCRIPTION
=head1 OPTIONS
=head1 BUGS
None known yet.
=head1 SEE ALSO
L<Bio::Graphics::Browser::Plugin>
=head1 AUTHOR
Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
Copyright (c) 2009 Ontario Institute for Cancer Research
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
136 changes: 136 additions & 0 deletions conf/plugins/SourceTrackFinder.pm
@@ -0,0 +1,136 @@
package Bio::Graphics::Browser::Plugin::SourceTrackFinder;
# $Id: SourceTrackFinder.pm,v 1.1 2009-05-20 20:36:20 lstein Exp $
use strict;
use CGI qw(:standard *table);
use base 'Bio::Graphics::Browser::Plugin';
use Bio::Graphics::Browser::Util 'shellwords';
our $VERSION = '0.25';

sub name { "Source Track Finder" }

sub description {
return p("The source track finder filters the track table by the data and config source the track.");
}

sub type { 'trackfilter' }

sub init { }

sub config_defaults {
my $self = shift;

# this line gets all the options defined in the "[SourceTrackFinder: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;

for my $f ($self->get_fields) {
$current_config->{lc $f} = $self->config_param($f);
}
}

sub configure_form {
my $self = shift;
my $current_config = $self->configuration;
my $source = $self->browser_config;

my @fields = $self->get_fields;
my @elements;

for my $f (@fields) {
my @options = ('',shellwords($source->plugin_setting($f)));
push @elements,b(ucfirst $f.':');
push @elements,
popup_menu(
-id => "plugin_$f",
-class => "SourceTrackFinderPopup",
-name => $self->config_name($f),
-values => \@options,
-default => $current_config->{$f},
-override => 1,
-onChange => 'doPluginUpdate()',
)
}
push @elements,
button(-value => 'Clear',
-onClick => q($$('.SourceTrackFinderPopup').each(function(m) {m.selectedIndex=0}); doPluginUpdate();)
);
return join '&nbsp;',@elements;


}

sub filter_tracks {
my $self = shift;
my $track_labels = shift;
my $source = shift;

my $config = $self->configuration;
my @fields = $self->get_fields;
my %filters = map {lc $_ => $config->{lc $_}} @fields;

my @result;

LABEL:
for my $l (@$track_labels) {
do {push @result,$l; next LABEL} if $l =~ /^(plugin|file|http|das)/;

for my $f (keys %filters) {
my %values = map {lc $_=>1} shellwords $source->fallback_setting($l=>$f);
next LABEL if length $filters{$f} && !$values{lc $filters{$f}};
}

push @result,$l;
}
return @result;
}

1;

__END__
=head1 NAME
Bio::Graphics::Browser::Plugin::SimpleTrackFinder - Limit list of tracks to those that match a name pattern
=head1 SYNOPSIS
In the appropriate gbrowse configuration file:
track filter = SimpleTrackFinder
=head1 DESCRIPTION
=head1 OPTIONS
=head1 BUGS
None known yet.
=head1 SEE ALSO
L<Bio::Graphics::Browser::Plugin>
=head1 AUTHOR
Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
Copyright (c) 2009 Ontario Institute for Cancer Research
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
22 changes: 18 additions & 4 deletions htdocs/js/controller.js
Expand Up @@ -3,7 +3,7 @@
Lincoln Stein <lincoln.stein@gmail.com>
Ben Faga <ben.faga@gmail.com>
$Id: controller.js,v 1.91 2009-05-15 03:23:19 lstein Exp $
$Id: controller.js,v 1.92 2009-05-20 20:36:20 lstein Exp $
Indentation courtesy of Emacs javascript-mode
(http://mihai.bazon.net/projects/emacs-javascript-mode/javascript.el)
Expand Down Expand Up @@ -236,6 +236,7 @@ var GBrowseController = Class.create({

var request_str = "update_sections=1" + param_str;
for (var i = 0; i < section_names.length; i++) {
$(section_names[i]).innerHTML="<img src='/gbrowse2/images/spinner.gif' alt='loading...' />";
request_str += "&section_names="+section_names[i];
}

Expand Down Expand Up @@ -636,14 +637,24 @@ var GBrowseController = Class.create({
filter_track: track_id,
}).toQueryString(),
onSuccess: function(transport) {
var track_div_id = Controller.gbtracks.get(track_id).track_div_id;
Balloon.prototype.hideTooltip(1);
Controller.rerender_track(track_id,true);
} // end onSuccess
});

},

restrict_tracks:
function(restriction_data) {
new Ajax.Request(document.URL,{
method: 'post',
parameters:
restriction_data + '&' +
$H({restrict_tracks: 1}).toQueryString(),
onSuccess: function(transport) {
Controller.update_sections(new Array(track_listing_id),'',1);
}
});
},

// Plugin Methods *************************************************

Expand All @@ -669,7 +680,7 @@ var GBrowseController = Class.create({
}).toQueryString(),

onSuccess: function(transport) {
Controller.wipe_div(pc_div_id);
if (pc_div_id != null) Controller.wipe_div(pc_div_id);

if (plugin_type == 'annotator'){
Controller.each_track(plugin_track_id,function(gbtrack) {
Expand All @@ -679,6 +690,9 @@ var GBrowseController = Class.create({
else if (plugin_type == 'filter'){
Controller.update_coordinates("reload segment");
}
else if (plugin_type == 'trackfilter') {
Controller.update_sections(new Array(track_listing_id),'',1);
}
} // end onSuccess
});
},
Expand Down
60 changes: 59 additions & 1 deletion lib/Bio/Graphics/Browser/DataSource.pm
Expand Up @@ -342,7 +342,8 @@ sub plugin_setting {
my $caller_package = caller();
my ($last_name) = $caller_package =~ /(\w+)$/;
my $option_name = "${last_name}:plugin";
$self->setting($option_name => @_);
return $self->label_options($option_name) unless @_;
return $self->setting($option_name => @_);
}

sub karyotype_setting {
Expand Down Expand Up @@ -792,5 +793,62 @@ sub add_dbid_to_feature {
}


=head2 @labels = $source->data_source_to_label(@data_sources)
Search through all stanzas for those with a matching "data source"
option. Data sources look like this:
[stanzaLabel1]
data source = FlyBase
[stanzaLabel2]
data source = FlyBase
Now searching for $source->data_source_to_label('FlyBase') will return
"stanzaLabel1" and "stanzaLabel2" along with others that match. A
track may have several data sources, separated by spaces.
=cut


sub data_source_to_label {
my $self = shift;
return $self->_secondary_key_to_label('data source',@_);
}

=head2 @labels = $source->track_source_to_label(@track_sources)
Search through all stanzas for those with a matching "track source"
option. Track sources look like this:
[stanzaLabel]
track source = UCSC EBI NCBI
Now searching for $source->track_source_to_label('UCSC','EBI') will
return "stanzaLabel" along with others that match. A track may have
several space-delimited track sources.
=cut
sub track_source_to_label {
my $self = shift;
return $self->_secondary_key_to_label('track source',@_);
}

sub _secondary_key_to_label {
my $self = shift;
my $field = shift;
my $index = $self->{'.secondary_key'};
if (!exists $index->{$field}) {
for my $label ($self->labels) {
my @sources = shellwords $self->setting($label=>$field) or next;
push @{$index->{$field}{lc $_}},$label foreach @sources;
}
}

my %seenit;
return grep {!$seenit{$_}++}
map {exists $index->{$field}{lc $_} ? @{$index->{$field}{lc $_}} : () } @_;
}

1;

0 comments on commit 1369b5b

Please sign in to comment.