| 1 | package Bio::Graphics::Glyph::whiskerplot; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(Bio::Graphics::Glyph::xyplot); | ||
| 5 | |||
| 6 | sub lookup_draw_method { | ||
| 7 | my $self = shift; | ||
| 8 | return 'draw_whiskerplot'; | ||
| 9 | } | ||
| 10 | |||
| 11 | sub draw_whiskerplot { | ||
| 12 | my $self = shift; | ||
| 13 | my ($gd,$left,$top) = @_; | ||
| 14 | my @parts = $self->parts; | ||
| 15 | my $fgcolor = $self->fgcolor; | ||
| 16 | |||
| 17 | for my $part (@parts) { | ||
| 18 | my ($x1,$y1,$x2,$y2) = $part->calculate_boundaries($left,$top); | ||
| 19 | |||
| 20 | my $y = $part->{_y_position}; | ||
| 21 | |||
| 22 | # get the range and tendency | ||
| 23 | if (my $range = $part->get_range) { | ||
| 24 | |||
| 25 | unshift @$range,undef if @$range == 4; # backward compatibility | ||
| 26 | |||
| 27 | my ($median,$range_low,$range_high,$lower_quartile,$higher_quartile) = @$range; | ||
| 28 | $y = $part->{_y_position} = $self->score2position($median) if defined $median; | ||
| 29 | |||
| 30 | # draw the quartile box | ||
| 31 | my ($box_top,$box_bottom) = ($y,$y); | ||
| 32 | if (defined $lower_quartile && defined $higher_quartile) { | ||
| 33 | $box_top = $self->score2position($higher_quartile); | ||
| 34 | $box_bottom = $self->score2position($lower_quartile); | ||
| 35 | $self->filled_box($gd,$x1,$box_top,$x2,$box_bottom); | ||
| 36 | } | ||
| 37 | |||
| 38 | # calculate positions of the range whiskers | ||
| 39 | if (defined $range_low && defined $range_high) { | ||
| 40 | my $range_top = $self->score2position($range_high); | ||
| 41 | my $range_bottom = $self->score2position($range_low); | ||
| 42 | my $center = ($x1+$x2)/2; | ||
| 43 | my $whisker_left = $center-5; | ||
| 44 | my $whisker_right = $center+5; | ||
| 45 | $whisker_left = $x1 if $whisker_left < $x1; | ||
| 46 | $whisker_right = $x2 if $whisker_right > $x2; | ||
| 47 | |||
| 48 | # top whisker | ||
| 49 | $gd->line($center,$box_top,$center,$range_top,$fgcolor); | ||
| 50 | $gd->line($whisker_left,$range_top,$whisker_right,$range_top,$fgcolor); | ||
| 51 | |||
| 52 | # bottom whisker | ||
| 53 | $gd->line($center,$box_bottom,$center,$range_bottom,$fgcolor); | ||
| 54 | $gd->line($whisker_left,$range_bottom,$whisker_right,$range_bottom,$fgcolor); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | # draw the median | ||
| 59 | $gd->line($x1,$y,$x2,$y,$fgcolor); | ||
| 60 | |||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | sub get_range { | ||
| 65 | my $self = shift; | ||
| 66 | my $range = $self->option('range'); | ||
| 67 | return $range if defined $range; | ||
| 68 | # otherwise get it from the feature | ||
| 69 | return [$self->feature->get_tag_values('range')]; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | __END__ |