3 # PROGRAM : hitdisplay.pl
4 # PURPOSE : Demonstrate Bio::Tk::HitDisplay
5 # AUTHOR : Keith James kdj@sanger.ac.uk
8 # Requires Bio::Tk::HitDisplay
10 # To use, just pipe Blast output into this script. Try clicking on
11 # the blue Subject ids with the left button to activate a callback
12 # or with the right button to show text describing the hit.
16 use Text
::Wrap
qw(wrap $columns);
17 use Bio::Tools::BPlite;
19 print STDERR "This example uses deprecated BioPerl code; feel free to refactor as needed\n";
23 require 'Bio/Tk/HitDisplay.pm';
26 print STDERR "Must have bioperl-gui and Tk installed to run this test, see bioperl website www.bioperl.org for instructions on how to installed bioperl-gui modules\n";
34 my $report = Bio::Tools::BPlite->new(-fh => \*STDIN);
36 # Normally the code ref below is in a separate package and I do
39 # my $adapter = Bio::PSU::IO::Blast::HitAdapter->new;
41 # while (my $hit = $result->next_hit)
44 # my $callback = sub { ... };
45 # push(@hits, $adapter->($sbjct, $text, $callback));
48 # It's easy to roll your own for Fasta, or whatever.
52 my ($sbjct, $text, $callback) = @_;
54 my (@data, $expect, $percent, $length);
55 my ($q_id, $s_id, $q_len, $s_len);
57 while (my $hsp = $sbjct->nextHSP)
59 $q_id ||= $hsp->query->seqname;
60 $s_id ||= $hsp->subject->seqname;
62 $q_len ||= $hsp->query->seqlength;
63 $s_len ||= $hsp->subject->seqlength;
65 my $q_x1 = $hsp->query->start;
66 my $q_x2 = $hsp->query->end;
68 my $s_x1 = $hsp->subject->start;
69 my $s_x2 = $hsp->subject->end;
71 push(@data, [$q_x1, $q_x2,
76 if ($hsp->P < $expect)
79 $percent = $hsp->percent;
80 $length = $hsp->length;
86 $percent = $hsp->percent;
87 $length = $hsp->length;
91 return { q_id => $q_id,
100 callback => $callback }
106 while (my $sbjct = $report->nextSbjct)
108 # Make some text to show when the left button is clicked
109 my $text = wrap("", "", "Blast hit to: ", $sbjct->name, "\n");
111 # Make a callback to actiavte when the right button is clicked
112 my $callback = sub { print "Blast hit to ", $sbjct->name, "\n" };
114 # Convert Subjct, text and callback into hash
115 push(@hits, $adapter->($sbjct, $text, $callback));
118 # Create the main window and HitDisplay
119 my $mw = MainWindow->new;
120 my $hds = $mw->Scrolled('HitDisplay',
122 -scrollbars => 'ose',
125 -background => 'white',
137 $hds->pack(-side => 'top', -fill => 'both', -expand => 1);
138 $hds->waitVisibility;
139 $hds->configure(-height => 900);
140 $hds->configure(-scrollregion => [$hds->bbox("all")]);