Skip to content

Commit

Permalink
fixed a bug which prevented link and title callbacks from being evalu…
Browse files Browse the repository at this point in the history
…ated within the feature files returned by Annotator plugins
  • Loading branch information
lstein committed Jul 19, 2005
1 parent ba22d1c commit 989d60e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 42 deletions.
4 changes: 2 additions & 2 deletions conf/plugins/RandomGene.pm
@@ -1,13 +1,13 @@
package Bio::Graphics::Browser::Plugin::RandomGene;
# $Id: RandomGene.pm,v 1.1.6.1 2005-07-18 23:03:42 lstein Exp $
# $Id: RandomGene.pm,v 1.1.6.2 2005-07-19 21:41:39 lstein Exp $
# test plugin
use strict;
use Bio::Graphics::Browser::Plugin;
use Bio::SeqFeature::Generic;
use CGI qw(:standard *table);

use vars '$VERSION','@ISA';
$VERSION = '0.1';
$VERSION = '0.2';

@ISA = qw(Bio::Graphics::Browser::Plugin);

Expand Down
50 changes: 38 additions & 12 deletions extras/BioPerl/Bio/Graphics/FeatureFile.pm
@@ -1,6 +1,6 @@
package Bio::Graphics::FeatureFile;

# $Id: FeatureFile.pm,v 1.1.2.6 2005-07-18 20:46:37 lstein Exp $
# $Id: FeatureFile.pm,v 1.1.2.7 2005-07-19 21:41:40 lstein Exp $
# This package parses and renders a simple tab-delimited format for features.
# It is simpler than GFF, but still has a lot of expressive power.
# See __END__ for the file format
Expand Down Expand Up @@ -233,15 +233,34 @@ sub new {

=over 4
=item ($rendered,$panel) = $features-E<gt>render([$panel])
=item ($rendered,$panel) = $features-E<gt>render([$panel, $position_to_insert, $options, $max_bump, $max_label, $selector])
Render features in the data set onto the indicated
Bio::Graphics::Panel. If no panel is specified, creates one.
All arguments are optional.
$panel is a Bio::Graphics::Panel that has previously been created and
configured.
$position_to_insert indicates the position at which to start inserting
new tracks. The last current track on the panel is assumed.
$options is a scalar used to control automatic expansion of the
tracks. 0=auto, 1=compact, 2=expanded, 3=expand and label,
4=hyperexpand, 5=hyperexpand and label.
$max_bump and $max_label indicate the maximum number of features
before bumping and labeling are turned off.
$selector is a code ref that can be used to filter which features to
render. It receives a feature and should return true to include the
feature and false to exclude it.
In a scalar context returns the number of tracks rendered. In a list
context, returns a two-element list containing the number of features
rendered and the panel. Use this form if you want the panel created
for you.
context, returns a three-element list containing the number of
features rendered, the created panel, and a list of all the track
objects created.
=back
Expand All @@ -257,7 +276,7 @@ sub render {
$panel ||= $self->new_panel;

# count up number of tracks inserted
my $tracks = 0;
my @tracks;
my $color;
my %types = map {$_=>1} $self->configured_types;

Expand Down Expand Up @@ -306,13 +325,12 @@ sub render {
@override,
);
if (defined($position_to_insert)) {
$panel->insert_track($position_to_insert++,$features,@config);
push @tracks,$panel->insert_track($position_to_insert++,$features,@config);
} else {
$panel->add_track($features,@config);
push @tracks,$panel->add_track($features,@config);
}
$tracks++;
}
return wantarray ? ($tracks,$panel) : $tracks;
return wantarray ? (scalar(@tracks),$panel,\@tracks) : scalar @tracks;
}

sub _stat {
Expand Down Expand Up @@ -1303,7 +1321,7 @@ interface) or its primary_tag() method otherwise.
sub feature2label {
my $self = shift;
my $feature = shift;
my $type = eval {$feature->type} || $feature->primary_tag or return;
my $type = $feature->primary_tag or return;
(my $basetype = $type) =~ s/:.+$//;
my @labels = $self->type2label($type);
@labels = $self->type2label($basetype) unless @labels;
Expand Down Expand Up @@ -1373,7 +1391,15 @@ sub make_link {
sub make_title {
my $self = shift;
my $feature = shift;
my $method = $feature->method;

for my $label ($self->feature2label($feature)) {
my $linkrule = $self->setting($label,'title');
$linkrule ||= $self->setting(general=>'title');
next unless $linkrule;
return $self->link_pattern($linkrule,$feature);
}

my $method = eval {$feature->method} || $feature->primary_tag;
my $seqid = $feature->can('seq_id') ? $feature->seq_id : $feature->location->seq_id;
my $title = eval {
if ($feature->can('target') && (my $target = $feature->target)) {
Expand Down
73 changes: 45 additions & 28 deletions lib/Bio/Graphics/Browser.pm
@@ -1,5 +1,5 @@
package Bio::Graphics::Browser;
# $Id: Browser.pm,v 1.167.4.22 2005-07-18 20:46:37 lstein Exp $
# $Id: Browser.pm,v 1.167.4.23 2005-07-19 21:41:40 lstein Exp $
# This package provides methods that support the Generic Genome Browser.
# Its main utility for plugin writers is to access the configuration file information

Expand Down Expand Up @@ -650,8 +650,8 @@ the feature.

sub make_link {
my $self = shift;
my ($feature,$panel,$label) = @_;
my @results = $self->config->make_link($feature,$panel,$label);
my ($feature,$panel,$label,$src) = @_;
my @results = $self->config->make_link($feature,$panel,$label,$self->source);
return wantarray ? @results : $results[0];
}

Expand Down Expand Up @@ -888,8 +888,7 @@ sub tmpdir {

sub make_map {
my $self = shift;
my ($boxes,$centering_map,$panel,$tracks) = @_;
my %track2label = reverse %$tracks;
my ($boxes,$centering_map,$panel,$track2label) = @_;
my $map = qq(<map name="hmap" id="hmap">\n);

my $flip = $panel->flip;
Expand All @@ -909,7 +908,7 @@ sub make_map {
next;
}

my $label = $_->[5] ? $track2label{$_->[5]} : '';
my $label = $_->[5] ? $track2label->{$_->[5]} : '';

my $href = $self->make_href($_->[0],$panel,$label) or next;
my $alt = unescape($self->make_title($_->[0],$panel,$label));
Expand Down Expand Up @@ -961,7 +960,7 @@ sub make_centering_map {
sub make_href {
my $self = shift;
my ($feature,$panel,$label) = @_;
return $self->make_link($feature,$panel,$label);
return $self->make_link($feature,$panel,$label,$self->source);
}

sub make_title {
Expand All @@ -971,7 +970,8 @@ sub make_title {
return $self->config->make_title($feature,$panel,$label);
}

# Generate the image and the box list, and return as a two-element list.
# Generate the image and the box list, and return the GD object, the boxes() list, the panel object and
# a hashref that maps track objects to track labels or feature files.
# arguments: a key=>value list
# 'segment' A feature iterator that responds to next_seq() methods
# 'feature_files' A hash of Bio::Graphics::FeatureFile objects containing 3d party features
Expand Down Expand Up @@ -1063,7 +1063,7 @@ sub image_and_map {
-unit_divider => $conf->setting(general=>'unit_divider') || 1,
) unless $suppress_scale;

my (%tracks,@blank_tracks);
my (%track2label,%tracks,@blank_tracks);

for (my $i= 0; $i < @$tracks; $i++) {

Expand All @@ -1088,7 +1088,8 @@ sub image_and_map {
my @settings = ($conf->default_style,$conf->i18n_style($label,$lang,$length));
push @settings,(-hilite => $hilite_callback) if $hilite_callback;
my $track = $panel->add_track(-glyph => 'generic',@settings);
$tracks{$label} = $track;
$track2label{$track} = $label;
$tracks{$label} = $track;
}

}
Expand Down Expand Up @@ -1181,10 +1182,12 @@ sub image_and_map {
$track += $offset + 1;
my $name = $file->name || '';
$options->{$name} ||= 0;
my $inserted = $file->render($panel,$track,$options->{$name},
$max_bump,$max_labels,
$select
);
my ($inserted,undef,$new_tracks)
= $file->render($panel,$track,$options->{$name},
$max_bump,$max_labels,
$select
);
foreach (@$new_tracks) { $track2label{$_} = $file }
$offset += $inserted;
}

Expand All @@ -1198,7 +1201,7 @@ sub image_and_map {

my $boxes = $panel->boxes;

return ($gd,$boxes,$panel,\%tracks);
return ($gd,$boxes,$panel,\%track2label);
}

=head2 overview()
Expand Down Expand Up @@ -2174,6 +2177,7 @@ sub feature2label {
my ($feature,$length) = @_;
my $type = eval {$feature->type}
|| eval{$feature->source_tag} || eval{$feature->primary_tag} or return;

(my $basetype = $type) =~ s/:.+$//;
my @label = $self->type2label($type,$length);

Expand Down Expand Up @@ -2227,7 +2231,11 @@ sub summary_mode {
# override make_link to allow for code references
sub make_link {
my $self = shift;
my ($feature,$panel,$label) = @_;
my ($feature,$panel,$label,$data_source) = @_;

if ($label->isa('Bio::Graphics::FeatureFile')) {
return $label->make_link($feature);
}

$panel ||= 'Bio::Graphics::Panel';
$label ||= $self->feature2label($feature);
Expand All @@ -2253,7 +2261,7 @@ sub make_link {
my $start = CGI::escape($feature->start);
my $end = CGI::escape($feature->end);
my $src = CGI::escape(eval{$feature->source} || '');
return "../../gbrowse_details/$src?name=$name;class=$class;ref=$ref;start=$start;end=$end";
return "../../gbrowse_details/$data_source?name=$name;class=$class;ref=$ref;start=$start;end=$end";
}
return $self->link_pattern($link,$feature,$panel);
}
Expand All @@ -2265,19 +2273,28 @@ sub make_title {
local $^W = 0; # tired of uninitialized variable warnings

my ($title,$key) = ('','');

TRY: {
$label ||= $self->feature2label($feature) or last TRY;
$key = $self->setting($label,'key') || $label;
$key =~ s/s$//;
my $link = $self->code_setting($label,'title')
|| $self->code_setting('TRACK DEFAULTS'=>'title')
|| $self->code_setting(general=>'title');
if (defined $link && ref($link) eq 'CODE') {
$title = eval {$link->($feature,$panel)};
$self->_callback_complain($label=>'title') if $@;
return $title if defined $title;
if ($label->isa('Bio::Graphics::FeatureFile')) {
$key = $label->name;
$title = $label->make_title($feature) or last TRY;
return $title;
}

else {
$label ||= $self->feature2label($feature) or last TRY;
$key ||= $self->setting($label,'key') || $label;
$key =~ s/s$//;
my $link = $self->code_setting($label,'title')
|| $self->code_setting('TRACK DEFAULTS'=>'title')
|| $self->code_setting(general=>'title');
if (defined $link && ref($link) eq 'CODE') {
$title = eval {$link->($feature,$panel)};
$self->_callback_complain($label=>'title') if $@;
return $title if defined $title;
}
return $self->link_pattern($link,$feature) if $link && $link ne 'AUTO';
}
return $self->link_pattern($link,$feature) if $link && $link ne 'AUTO';
}

# otherwise, try it ourselves
Expand Down

0 comments on commit 989d60e

Please sign in to comment.