[Bioperl-l] background layer is not supported in Bioperl 1.6 for Bio::Graphics::Glyph
Scott Cain
scott at scottcain.net
Sat Jun 13 01:29:09 UTC 2009
Hello Xianjun,
I don't think that approach will work. What you almost certainly need
to do is a postgrid callback that does the drawing of the highlighted
region. For example code of how to do this, take a look at the
make_postgrid_callback subroutine in GBrowse 1.69. The option
-postgrid is a method of Bio::Graphics::Panel.
Scott
On Fri, Jun 12, 2009 at 4:38 PM, Xianjun Dong<Xianjun.Dong at bccs.uib.no> wrote:
> HI,
>
> I am not sure this is the right place I can get help.
>
> I've suffered by a problem for several days: I want to highlight parts of
> regions in my track, using a different background color. To do that, I
> defined a glyph named "background", based on the
> 'Bio::Graphics::Glyph::generic' module. I override the draw_component()
> method, by adding code like below:
>
> $gd->filledRectangle($left,0,$right,$gd->height,
> $self->factory->translate_color($color));
>
> # the script is pasted at the end
>
> This will draw a rectangle with top=0, bottom=$gd->height. I made the
> highlight regions into a list of features, and add_track with
> -glyph=>'background'. (see the following script, test.pl) This really works
> as I expect, which will add a colored block at background of all tracks in a
> panel (including the ruler arrow). You can see the output image in attached
> file "test.bioperl1.2.3.png"
>
> Now, the problem comes: when I switch to Bioperl 1.5 (or 1.6), it does not
> work. Well, it works, but the highlight part only shrink to a low height,
> instead of covering all tracks in the panel. I also attached the output
> here, see the file "test.bioperl1.6.png".
>
> I tried to think about the reason, the 'background' module is based on the
> generic module. What can cause the difference? Is it because $gd->height is
> different, or the tracks followed with 'background' track can not draw from
> the first position?
>
> Well. I can stick to use Bioperl 1.2.3 to avoid the problem. ("Smart person
> solve problem, wise person avoid problem"...) But another problem is coming:
> Bio::Graphics in Bioperl 1.2.3 does not support $panel->create_web_map()
> function, which means I have to use some higher version if I want to create
> web map for my graphics, but then I have to give up using highlight
> background.
>
> OK. It's long enough for my first-time submission here. Hope someone can
> throw me some clue.
>
> Thanks ahead!!
>
> Xianjun
>
>
> ==================== test.pl =======================
> #!/usr/bin/perl
>
> use strict;
> use lib "$ENV{HOME}/lib";
>
> use Bio::Graphics;
> use Bio::Graphics::Feature;
> my $ftr= 'Bio::Graphics::Feature';
>
> # processed_transcript
> my $trans1 =
> $ftr->new(-start=>50,-end=>10,-name=>'ZK154.1',-type=>"3'-UTR");
> my $trans2 = $ftr->new(-start=>100,-end=>50,-name=>'ZK154.2',-type=>'CDS');
> my $trans3 = $ftr->new(-start=>350,-end=>225,-name=>'ZK154.3',-type=>'CDS',
> -source=>'a');
> my $trans4 = $ftr->new(-start=>650,-end=>500,-name=>'ZK154.3',-type=>'CDS',
> -source=>'a');
> my $trans5 =
> $ftr->new(-start=>700,-end=>650,-name=>'ZK154.3',-type=>"5'-UTR");
> my $trans =
> $ftr->new(-segments=>[$trans1,$trans2,$trans3,$trans4,$trans5]);
>
> # hightlight
> my $trans31 =
> $ftr->new(-start=>240,-end=>450,-name=>'hightlight1',-type=>'background',
> -source=>'a');
> my $trans41 =
> $ftr->new(-start=>650,-end=>600,-name=>'hightlight2',-type=>'multihourglass',
> -source=>'b');
>
> my $panel= Bio::Graphics::Panel->new(-width=>1200,
> -length=>1050,
> -start =>0,
> -pad_left=>12,
> -pad_right=>12);
>
> # the following track works as I expected in bioperl 1.2.3, but not in 1.5
> and 1.6
> $panel->add_track([$trans41,$trans31],
> -glyph => 'background',
> -block_bgcolor => sub{return (shift->source eq
> 'a')?'#cccccc':'#fffc22'},
> );
>
> $panel->add_track($ftr->new(-start=>100,-end=>1000),
> -glyph=>'arrow',
> -double=>1,
> -tick=>2);
>
> $panel->add_track($trans,
> -glyph => 'transcript2', # 'transcript2', #process_5utr',
> -fgcolor => 'darkred',
> -bgcolor => 'darkred',
> -title => '$source',
> -link =>
> 'http://www.ensembl.org/Homo_sapiens/transview?transcript=$name', #EnsEMBL
> );
> print $panel->png;
>
> # the following part works in bioperl 1.5 and 1.6, but not work in Bioperl
> 1.2.3
> my $map = $panel->create_web_map("image");
> $panel->finished();
>
> 1;
>
> ==================== background.pm =======================
> package Bio::Graphics::Glyph::background;
>
> use strict;
> use base 'Bio::Graphics::Glyph::generic';
> sub pad_top{
> return 0;
> }
>
> sub draw_component {
> my $self = shift;
> #$self->SUPER::draw_component(@_);
> my ($gd,$dx,$dy) = @_;
> my ($left,$top,$right,$bottom) = $self->bounds($dx,$dy);
>
> # draw an arrow to indicate the direction of transcript
> my $color = $self->option('block_bgcolor') || '#cccccc';
> $gd->filledRectangle($left,0,$right,$gd->height,
> $self->factory->translate_color($color));
> }
>
> 1;
>
> --
> ==========================================
> Xianjun Dong
> PhD student, Lenhard group
> Computational Biology Unit
> Bergen Center for Computational Science
> University of Bergen
> Hoyteknologisenteret, Thormohlensgate 55
> N-5008 Bergen, Norway
> E-mail: xianjun.dong at bccs.uib.no
> Tel.: +47 555 84022
> Fax : +47 555 84295
> ==========================================
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
--
------------------------------------------------------------------------
Scott Cain, Ph. D. scott at scottcain dot net
GMOD Coordinator (http://gmod.org/) 216-392-3087
Ontario Institute for Cancer Research
More information about the Bioperl-l
mailing list