Permalink
Browse files

syntax enhancements to prepare for faceted searching

  • Loading branch information...
lstein committed May 27, 2011
1 parent d2c58ef commit f508224dd9f9913624b1f92bd0d8d9c159cf03a0
Showing with 71 additions and 31 deletions.
  1. +10 −0 Changes
  2. +1 −0 lib/Bio/Graphics/Browser2/RenderPanels.pm
  3. +60 −31 lib/Bio/Graphics/Browser2/SubtrackTable.pm
View
10 Changes
@@ -1,3 +1,13 @@
+2.35
+ * Preparations for faceted track searching
+ * deprecate "subtrack select" and "subtrack table" options in favor of "subtrack facets",
+ which introspects values from database (will require updates to Bio::DB::SeqFeature and friends)
+ * add "facet labels" and "facet values" options
+ * allow options to be tagged with "ex:option_name" to identify facets
+ * Fix subtracks to prevent features from appearing in the subtrack manager that won't be
+ displayed in the track panel because the feature type doesn't match the configured "feature"
+ option.
+
2.34
* Fixed broken https:// links in karyotype summary table; patch courtesy Dan Bolser
* Fixed behavior of "q" parameter to match the documented behavior.
@@ -1701,6 +1701,7 @@ sub add_features_to_track {
}
if (!$is_summary && $stt && (defined (my $id = $stt->feature_to_id_sub->($feature)))) {
+ warn "ID = $id";
$groups{$l}{$id} ||= Bio::Graphics::Feature->new(-type => 'group',
-primary_id => $id,
-name => $stt->id2label($id),
@@ -92,7 +92,6 @@ sub counts {
return ($selected,$total);
}
-
sub set_selected {
my $self = shift;
my $selected = shift;
@@ -316,10 +315,13 @@ sub feature_to_id_sub {
my $bang = $val ? '' : '!';
$sub .= "\$found &&= $bang\$f->has_tag('$operand');\n";
} else {
- my $operation = $val =~ /^~(.+)/ ? "=~ m[$1]i"
+ my $operation = $val eq '' ? undef
+ : $val =~ /^~(.+)/ ? "=~ m[$1]i"
: $val =~ /^[+-]?\d*(\.\d+)?([eE]-?\d+)?$/ ? "== $val"
: "eq '$val'";
- if ($op eq 'tag_value') {
+ if (!defined $operation) {
+ $sub .= "\$found &&= length((\$f->get_tag_values('$operand'))[0])==0;\n";
+ } elsif ($op eq 'tag_value') {
$sub .= "\$found &&= \$f->has_tag('$operand');\n";
$sub .= "\$found &&= (\$f->get_tag_values('$operand'))[0] $operation;\n";
} else {
@@ -381,16 +383,22 @@ sub infer_settings_from_source {
my (@dimensions,@rows);
TRY: {
+ if (my @facets = shellwords $source->setting($label=>'subtrack facets')) {
+ @dimensions = map {[$_,'tag_value',$_]} @facets;
+ @rows = $package->get_facet_values($source,$label,@facets);
+ last TRY;
+ }
+
if ((my $d = $source->setting($label => 'subtrack select')) &&
(my $r = $source->setting($label => 'subtrack table'))) {
@dimensions = map {[shellwords($_)]} split ';',$d;
@rows = map {[shellwords($_)]} split ';',$r;
last TRY;
}
-
+
if (my $s = $source->setting($label=>'select')) {
my %defaults = map {$_=>1} shellwords($source->setting($label=>'select default'));
-
+
if ($s =~ /;/) { # new syntax
my @lines = split ';',$s;
my ($method) = shellwords (shift @lines);
@@ -412,48 +420,69 @@ sub infer_settings_from_source {
last TRY;
}
- my (undef,$adaptor) = $source->db_settings($label);
- last TRY unless $adaptor =~ /BigWigSet/;
-
- my $db = $source->open_database($label) or last TRY;
- my $meta = eval {$db->metadata} or last TRY;
+ my (undef,$adaptor) = $source->db_settings($label);
+ last TRY unless $adaptor =~ /BigWigSet/;
- # get all the tags that are consistently used
- my %tags;
- my @keys = map {keys %$_} values %$meta;
- for my $k (@keys) {
- $tags{$k}++;
- }
- my $count = keys %$meta;
+ my $db = $source->open_database($label) or last TRY;
+ my $meta = eval {$db->metadata} or last TRY;
- my @tags = sort grep {defined $_ && $_ ne 'dbid' && $tags{$_}==$count} keys %tags;
- @dimensions = map {[ucfirst($_),'tag_value',$_]} @tags;
+ # get all the tags that are consistently used
+ my %tags;
+ my @keys = map {keys %$_} values %$meta;
+ for my $k (@keys) {
+ $tags{$k}++;
+ }
+ my $count = keys %$meta;
+
+ my @tags = sort grep {defined $_ && $_ ne 'dbid' && $tags{$_}==$count} keys %tags;
+ @dimensions = map {[ucfirst($_),'tag_value',$_]} @tags;
+ @rows = $package->get_facet_values($source,$label,@tags);
- # translate these into rows
- for my $id (sort {$a<=>$b} keys %$meta) {
- my @vals = map {$_||0} @{$meta->{$id}}{@tags};
- push @vals,"=$id";
- push @rows,\@vals;
- }
- push @{$rows[0]},'*';
}
return unless @dimensions && @rows;
-
- # apply "facet dimensions" setting on top of dimensions
- if (my %facet_dimensions = shellwords($source->setting(general=>'facet dimensions'))) {
+
+ # apply "facet labels" setting on top of dimensions
+ if (my %facet_dimensions = shellwords($source->setting(general=>'facet labels'))) {
for my $d (@dimensions) {
$d->[0] = $facet_dimensions{$d->[0]} || $d->[0];
}
}
-
+
my %facet_values = shellwords($source->setting(general=>'facet values'));
my $aliases = $source->setting($label=>'subtrack select labels')
- ||$source->setting($label=>'subtrack labels') ; # deprecated API
+ ||$source->setting($label=>'subtrack labels') ; # deprecated API
my %aliases = map {shellwords($_)} split ';',$aliases if $aliases;
%aliases = (%facet_values,%aliases);
return (\@dimensions,\@rows,\%aliases);
}
+sub get_facet_values {
+ my $self = shift;
+ my ($source,$label,@facets) = @_;
+
+ my @types = shellwords $source->setting($label=>'feature');
+ my $match = join '|',map {$_="$_:?" unless /:/} @types;
+
+ my @rows;
+ my (undef,$adaptor) = $source->db_settings($label);
+ my $db = $source->open_database($label) or return;
+ my $meta = eval {$db->metadata} or return;
+
+ for my $id (sort {$a<=>$b} keys %$meta) {
+ my $method = $meta->{$id}{method} || eval {$db->feature_type} || 'feature';
+ my $source = $meta->{$id}{source} || '';
+ my $type = $meta->{$id}{type} || "$method:$source";
+
+ next unless $type =~ /$match/;
+ my @vals = map {$_||''} @{$meta->{$id}}{@facets};
+ push @vals,"=$id";
+ push @rows,\@vals;
+ }
+
+ push @{$rows[0]},'*';
+ return @rows;
+}
+
1;

0 comments on commit f508224

Please sign in to comment.