[Bioperl-l] Re: patch xyplot.pm negative values Bio::Graphics/GMOD

Lincoln Stein lstein at cshl.edu
Tue Jun 14 14:00:36 EDT 2005


Hi Albert,

Much obliged to you on this. Unfortunately the patch got wordwrapped in 
transit.  Could you send the patch as an attachment? Sometimes you need to 
gzip the attachment first.

Lincoln

On Saturday 11 June 2005 03:18 pm, Albert Vilella wrote:
> Hi all,
>
> xyplot negative values:
>
> Lincoln and Guenther: this are very hacky modifications (I still haven't
> completely familiarized myself with Bio::Graphics)
>
> I took a look at the code in xyplot.pm, and tested it on a local png
> file (I don't have a GBrowse setup to test). Please check if what
> has been done is correct.
>
> It seems to me that _draw_boxes needs to be modified, so that the
> boxes aren't wrongly plotted, but _draw_histogram, _draw_line and
> _draw_points don't need anything special, a part from the existence of
> the scale.
>
> In _draw_boxes, negative boxes need to be plotted from the middle of
> the track down to their score, so I modified it in a similar fashion
> as it is done in _draw_scale
>
> --- xyplot.pm.~1.15.~   2005-06-11 08:03:02.000000000 +0200
> +++ xyplot.pm   2005-06-11 21:04:37.895586696 +0200
> @@ -64,7 +64,8 @@
>
>    my $type = $self->option('graph_type') || $self->option('graphtype')
>
> || 'boxes';
>
>    $self->_draw_histogram($gd,$x,$y)  if $type eq 'histogram';
> -  $self->_draw_boxes($gd,$x,$y)      if $type eq 'boxes';
> +  #we need $dx and $dy for calculating $half for negative boxes
> +  $self->_draw_boxes($gd,$x,$y,$dx,$dy)      if $type eq 'boxes';
>    $self->_draw_line ($gd,$x,$y)      if $type eq 'line'
>                                         or $type eq 'linepoints';
>    $self->_draw_points($gd,$x,$y)     if $type eq 'points'
> @@ -141,7 +142,7 @@
>
>  sub _draw_boxes {
>    my $self = shift;
> -  my ($gd,$left,$top) = @_;
> +  my ($gd,$left,$top,$dx,$dy) = @_;
>
>    my @parts  = $self->parts;
>    my $fgcolor = $self->fgcolor;
> @@ -152,8 +153,17 @@
>    for (my $i = 0; $i < @parts; $i++) {
>      my $part = $parts[$i];
>      my $next = $parts[$i+1];
> +    my ($dummy1,$dummy2,$dummy3,$zero) =
> $part->calculate_boundaries($left,0);
>      my ($x1,$y1,$x2,$y2) = $part->calculate_boundaries($left,$top);
> -    $self->filled_box($gd,$x1,$part->{_y_position},$x2,$y2,$bgcolor,
> $fgcolor);
> +    # If negative box
> +    if ($zero < ($part->{_y_position})) {
> +        my ($dummyx1,$ny1,$dummyx2,$ny2) =
> $self->calculate_boundaries($dx,$dy);
> +        my $half = ($ny1+$ny2)/2;
> +        $self->filled_box($gd,$x1,$part->{_y_position},$x2,$half,
> $bgcolor,$fgcolor);
> +    # Normal positive box
> +    } else {
> +        $self->filled_box($gd,$x1,$part->{_y_position},$x2,$y2,
> $bgcolor,$fgcolor);
> +    }
>      next unless $next;
>      my ($x3,$y3,$x4,$y4) = $next->calculate_boundaries($left,$top);
>      $gd->line($x2,$y2,$x3,$y4,$fgcolor) if $x2 < $x3;
>
> This results in boxes being plot upward if positive and downward if
> negative from the middle of the track, (midpoint between $min_score
> and $max_score). I don't know if it is the best thing to do, but it
> makes sense to me.
>
> Also, negative boxes will have a different color than positive boxes. It
> also makes sense to me.
>
> If you can check if it is ok and test it in a running GBrowse server,
> that would be great.
>
> Bests,
>
>     Albert.
>
> PD: I haven't done anything about the log coordinates.

-- 
Lincoln D. Stein
Cold Spring Harbor Laboratory
1 Bungtown Road
Cold Spring Harbor, NY 11724


More information about the Bioperl-l mailing list