[Bioperl-l] Bio::Graphics::Panel->add_track problem

Crabtree, Jonathan crabtree at tigr.org
Wed Aug 4 17:03:49 EDT 2004


Mark-

The -bgcolor option of add_track will accept a coderef instead of a
scalar.  This is covered in the documentation (see 'perldoc
Bio::Graphics::Panel').  Here's the relevant part:

=head2 Options and Callbacks

Instead of providing a constant value to an option, you may subsitute
a code reference.  This code reference will be called every time the
panel needs to configure a glyph.  The callback will be called with
three arguments like this:

   sub callback {
      my ($feature,$option_name,$part_no,$total_parts,$glyph) = @_;
      # do something which results in $option_value being set
      return $option_value;
   }

The five arguments are C<$feature>, a reference to the IO::SeqFeatureI
object, C<$option_name>, the name of the option to configure,
C<$part_no>, an integer index indicating which subpart of the feature
is being drawn, C<$total_parts>, an integer indicating the total
number of subfeatures in the feature, and finally C<$glyph>, the Glyph
object itself.  The latter fields are useful in the case of treating
the first or last subfeature differently, such as using a different
color for the terminal exon of a gene.  Usually you will only need to
examine the first argument.  This example shows a callback examining
the score() attribute of a feature (possibly a BLAST hit) and return
the color "red" for high-scoring features, and "green" for low-scoring
features:

  sub callback {
     my $feature = shift;
     if ($feature->score > 90) {
       return 'red';
     else {
       return 'green';
    }
  }

The callback should return a string indicating the desired value of
the option.  To tell the panel to use the default value for this
option, return the string "*default*".

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 B<-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=E<gt>1, and turn on
bumping when the callback is in the track or group glyphs.


> -----Original Message-----
> From: bioperl-l-bounces at portal.open-bio.org 
> [mailto:bioperl-l-bounces at portal.open-bio.org] On Behalf Of mql201
> Sent: Wednesday, August 04, 2004 4:25 PM
> To: bioperl-l at portal.open-bio.org
> Subject: [Bioperl-l] Bio::Graphics::Panel->add_track problem
> 
> 
> Hello
> 
> I want to print out a number of glyphs of different colours 
> on the same track, 
> but with this code there doesn't seem to be a way round 
> having more than 1 
> colour per track:
> 
> ## start with an array of colours
> #
> @colours = qw(white red green blue black yellow ...);   # 190 
> colours in all
> 
> ## specify new panel once, background white
> #
> $panel = Bio::Graphics::Panel->new(-length => 700,      # 
> length of panel in 
> nt
>                                    -width  => 700,  # 
> physical width of img
>                                    -pad_top => 10,     # padding
>                                    -pad_bottom => 10,
>                                    -pad_left => 10,
>                                    -pad_right => 10,
>                                    -bgcolor => 'white',    # 
> colour of panel
>                                    -key_color => 'white',
>                                    -key_style => 'bottom');
> 
> ## the following code should create a 28 track panel (down)  
> with 6 glyphs on 
> ## each track (across), with each glyph a different colour 
> got out of the 
> array
> ## @colours.
> # 
> my($start) = 10;
> my($end) = 60;
> for($x = 0; $x <=28; $x++) {       # 28 tracks to make
>   ## define glyph track
>   #
>   $track = $panel->add_track(-glyph => 'graded_segments',
>                              -linewidth => 2,
>                              -height => 8,
>                              -fontcolor => '#1d4305',
>                             # -bgcolor => 'some color',
>                              -label  => 1,
>                              -bump => 1,
>                              -description => 1);
> 
>   ## but instead i want to use -bgcolor in the for loop below
>   #
>   for ($i = 0; $i <= 6; $i++) {
>     my($feature) = Bio::SeqFeature::Generic->new(-display_name=>$key,
>                                                  -score=>2000,
>                                                  -start=>$start,
>    ERROR, THIS SHOULD BE IN ADD_TRACK ABOVE ->   -bgcolor => 
> shift(@colours),
>    ALTHOUGH I WANT IT IN HERE               ->   -end=>$end);
> 
>     $track->add_feature($feature);
>     $start += 90;
>     $end += 90;
>   }
> $start = 10;
> $end = 60;
> }
> 
> 
> As you can see, its a std way of adding tracks, and glyphs to 
> tracks, except i 
> can't work out how to add glyphs without them having the same 
> colour as the 
> glyphs on the same track because i'd have specified the 
> colour of the glyphs 
> on that track, rather than the colour of the individual glyph.
> 
> i've a feeling its a simple solution.  Anybody have any idea?
> 
> Many ta IA
> Mark
> 
> _______________________________________________
> 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