[Bioperl-l] Can I get different Graphics::Panel colours fordifferent HSP frames within the same blast hit?

Aaron J. Mackey amackey at pcbi.upenn.edu
Thu Dec 9 11:20:23 EST 2004


There's another solution that shouldn't involve code patches: see the 
documentation in Panel (short answer: all_callbacks: 1)

When you install a callback for a feature that contains subparts, the
callback will be invoked first for the top-level feature, and then for
each of its subparts (recursively).  You should make sure to examine
the feature's type to determine whether the option is appropriate.

Some glyphs deliberately disable this recursive feature.  The "track",
"group", "transcript", "transcript2" and "segments" glyphs selectively
disable the -bump, -label and -description options.  This is to avoid,
for example, a label being attached to each exon in a transcript, or
the various segments of a gapped alignment bumping each other.  You
can override this behavior and force your callback to be invoked by
providing add_track() with a true -all_callbacks argument.  In this
case, you must be prepared to handle configuring options for the
"group" and "track" glyphs.

In particular, this means that in order to control the -bump option
with a callback, you should specify -all_callbacks=>1, and turn on
bumping when the callback is in the track or group glyphs.


On Dec 9, 2004, at 9:46 AM, Crabtree, Jonathan wrote:

>
> Hi Marcus-
>
> Looking at the source for Bio/Graphics/Glyph/graded_segments.pm, I'd 
> say that you're stuck with this behavior unless you either modify the 
> glyph or choose a different approach.  In terms of modifying the 
> glyph, a good long-term solution would be to add a "use_part_color" 
> option to graded_segments.pm; this option would conditionally enable 
> the code change I describe below.  If you're looking for a quick hack, 
> however, just make yourself a new glyph based on a copy of the old 
> one, something like this:
>
> 1. copy graded_segments.pm to graded_segments2.pm (ensuring that 
> graded_segments2.pm remains somewhere in your classpath under a 
> similar directory structure, namely Bio/Graphics/Glyph/)
>
> 2. make the following changes to graded_segments2.pm:
>  -globally replace "graded_segments" with "graded_segments2"
>  -find the section labeled "allocate colors", which looks like this:
>
>   # allocate colors
>   my $fill   = $self->bgcolor;
>   my ($red,$green,$blue) = $self->panel->rgb($fill);
>
>   foreach my $part (@parts) {
>
>  -change it to look like this (i.e. get $fill from the child feature, 
> not the parent):
>
>   # allocate colors
>
>   foreach my $part (@parts) {
>     my $fill   = $part->bgcolor;
>     my ($red,$green,$blue) = $self->panel->rgb($fill);
>
> Finally, change your original script to use glyph => 
> 'graded_segments2'.
>
> Jonathan
>
>
> -----Original Message-----
> From: bioperl-l-bounces at portal.open-bio.org on behalf of Marcus 
> Claesson
> Sent: Wed 12/8/2004 9:07 AM
> To: Bioperl list
> Subject: [Bioperl-l] Can I get different Graphics::Panel colours 
> fordifferent HSP frames within the same blast hit?
>
> Hi!
>
> In my Graphics::Panel overview of blastx results I would like to have
> different colours for hits in different frames. It works fine among 
> hits
> but not for HSPs within the same hit. It then uses the frame value for
> the first instance, and I only get one colour. Has anyone managed to
> side step that? Below is the code I've used so far.
>
> Many thanks!
> Marcus
>
>
> #!/usr/bin/perl -w
> use Bio::Graphics;
> use Bio::SearchIO;
> my $searchio = Bio::SearchIO->new(-file=>blastx_results.out
>                                   -format => 'blast');
> my $result = $searchio->next_result();
> my $panel = Bio::Graphics::Panel->new(-length=> $result->query_length,
>                                       -width=> 800);
> my $track = $panel->add_track(-glyph       => 'graded_segments',
>                               -label       => 1,
>                               -connector   => 'dashed',
>                               -bgcolor      => sub {
>                                   my $feature = shift;
>                                   my ($frame) = $feature->frame();
>                                   return "red" if ($frame =~ /0/);
>                                   return "green" if ($frame =~ /1/);
>                                   return "blue" if ($frame =~ /2/)},
>                               -strand_arrow  => 'tue');
> while( my $hit = $result->next_hit ) {
>     my $feature = 
> Bio::SeqFeature::Generic->new(-score=>$hit->raw_score,
>                                                 -frame=> $hit->frame);
>     while( my $hsp = $hit->next_hsp ) {
>         $feature->add_sub_SeqFeature($hsp,'EXPAND');
>    }
>     $track->add_feature($feature);
> }
> print $panel->png;
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
--
Aaron J. Mackey, Ph.D.
Dept. of Biology, Goddard 212
University of Pennsylvania       email:  amackey at pcbi.upenn.edu
415 S. University Avenue         office: 215-898-1205
Philadelphia, PA  19104-6017     fax:    215-746-6697



More information about the Bioperl-l mailing list