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

Crabtree, Jonathan crabtree at tigr.org
Thu Dec 9 09:46:46 EST 2004


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



More information about the Bioperl-l mailing list