Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interval_method option for statistical summaries #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Changes
@@ -1,7 +1,11 @@
Revision history for Perl extension Bio::Graphics.

2.31 Tue Sep 25 22:39:43 EDT 2012
- Fix infinite loop when drawing wiggle_xyplots with z-score scaling
over regions that do not vary much.

2.30
- Added the glyph for FlyBase's "stacked wiggle" plot (fb_shmiggle.pl) as well as a utility script for preparing the data (index_cov_files.pl).
- Added the glyph for FlyBase's "stacked wiggle" plot (fb_shmiggle.pm) as well as a utility script for preparing the data (index_cov_files.pl).

2.29
- Fixes for Bio::Graphics::Wiggle to prevent crash when the "bottom" keystyle selected.
Expand Down
6 changes: 0 additions & 6 deletions MANIFEST
Expand Up @@ -127,8 +127,6 @@ scripts/render_msa.pl
scripts/search_overview.pl
t/BioGraphics.t
t/data/feature_data.txt
t/data/t1.gif
t/data/t1.png
t/data/t1/version1.gif
t/data/t1/version1.png
t/data/t1/version10.png
Expand All @@ -149,8 +147,6 @@ t/data/t1/version7.png
t/data/t1/version8.png
t/data/t1/version9.gif
t/data/t1/version9.png
t/data/t2.gif
t/data/t2.png
t/data/t2/version1.gif
t/data/t2/version1.png
t/data/t2/version10.png
Expand Down Expand Up @@ -178,8 +174,6 @@ t/data/t2/version6.png
t/data/t2/version7.png
t/data/t2/version8.png
t/data/t2/version9.png
t/data/t3.gif
t/data/t3.png
t/data/t3/version1.gif
t/data/t3/version1.png
t/data/t3/version10.gif
Expand Down
2 changes: 1 addition & 1 deletion lib/Bio/Graphics.pm
Expand Up @@ -2,7 +2,7 @@ package Bio::Graphics;

use strict;
use Bio::Graphics::Panel;
our $VERSION = '2.29';
our $VERSION = '2.31';

1;

Expand Down
24 changes: 21 additions & 3 deletions lib/Bio/Graphics/Glyph/hybrid_plot.pm
Expand Up @@ -70,7 +70,7 @@ sub draw {
my ($left,$top,$right,$bottom) = $self->calculate_boundaries($dx,$dy);
my $height = $bottom - $top;
my $feature = $self->feature;
my $set_flip = $self->option('flip_sign') | 0;
my $set_flip = $self->option('flip_sign') || 0;

#Draw individual features for reads (unlike wiggle features reads will have scores)
my $t_id = $feature->method;
Expand Down Expand Up @@ -106,7 +106,23 @@ sub draw {
-end => $self->panel->end,
-type => 'summary');
my $stats = $summary->statistical_summary($self->width);
my @vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount}*$flip:0} @$stats;
my $interval_method = $self->option('interval_method') || 'mean';
my @vals;
if ($interval_method eq 'mean') {
@vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount} * $flip : undef} @$stats;
}
elsif ($interval_method eq 'sum') {
@vals = map {$_->{validCount} ? $_->{sumData} * $flip : undef} @$stats;
}
elsif ($interval_method eq 'min') {
@vals = map {$_->{validCount} ? $_->{minVal} * $flip : undef} @$stats;
}
elsif ($interval_method eq 'max') {
@vals = map {$_->{validCount} ? $_->{maxVal} * $flip : undef} @$stats;
}
else {
warn "unrecognized interval method $interval_method!";
}
$self->_draw_coverage($summary,\@vals,@_);
}
}
Expand All @@ -129,6 +145,7 @@ sub minmax {
my $parts = shift;

my $autoscale = $self->option('autoscale') || 'local';
my $set_flip = $self->option('flip_sign') || 0;

my $min_score = $self->min_score unless $autoscale eq 'z_score';
my $max_score = $self->max_score unless $autoscale eq 'z_score';
Expand Down Expand Up @@ -160,7 +177,8 @@ sub minmax {
$stdev += $d**2;
}
$stdev = sqrt($stdev);

$min = $max * -1 if ($set_flip);

$min_score = $min if $do_min;
$max_score = $max if $do_max;
return $self->sanity_check($min_score,$max_score,$mean,$stdev);
Expand Down
18 changes: 17 additions & 1 deletion lib/Bio/Graphics/Glyph/vista_plot.pm
Expand Up @@ -203,7 +203,23 @@ sub draw_signal {
$self->Bio::Graphics::Glyph::wiggle_whiskers::draw(@_);
} else {
my $stats = $summary->statistical_summary($self->width);
my @vals = map {$_->{validCount} ? Bio::DB::BigWig::binMean($_) : 0} @$stats;
my $interval_method = $self->option('interval_method') || 'mean';
my @vals;
if ($interval_method eq 'mean') {
@vals = map {$_->{validCount} ? Bio::DB::BigWig::binMean($_) : undef} @$stats;
}
elsif ($interval_method eq 'sum') {
@vals = map {$_->{validCount} ? $_->{sumData} : undef} @$stats;
}
elsif ($interval_method eq 'min') {
@vals = map {$_->{validCount} ? $_->{minVal} : undef} @$stats;
}
elsif ($interval_method eq 'max') {
@vals = map {$_->{validCount} ? $_->{maxVal} : undef} @$stats;
}
else {
warn "unrecognized interval method $interval_method!";
}
$self->bigwig_summary($summary);
if ($signal_type eq 'density') {
$self->Bio::Graphics::Glyph::wiggle_density::_draw_coverage($summary,\@vals,@_);
Expand Down
37 changes: 35 additions & 2 deletions lib/Bio/Graphics/Glyph/wiggle_data.pm
Expand Up @@ -241,7 +241,23 @@ sub create_parts_from_summary {
my $self = shift;
my ($stats,$start,$end) = @_;
$stats ||= [];
my @vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount}:0} @$stats;
my $interval_method = $self->option('interval_method') || 'mean';
my @vals;
if ($interval_method eq 'mean') {
@vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount} : undef} @$stats;
}
elsif ($interval_method eq 'sum') {
@vals = map {$_->{validCount} ? $_->{sumData} : undef} @$stats;
}
elsif ($interval_method eq 'min') {
@vals = map {$_->{validCount} ? $_->{minVal} : undef} @$stats;
}
elsif ($interval_method eq 'max') {
@vals = map {$_->{validCount} ? $_->{maxVal} : undef} @$stats;
}
else {
warn "unrecognized interval method $interval_method!";
}
return \@vals;
}

Expand Down Expand Up @@ -395,7 +411,23 @@ sub draw_statistical_summary {
my $feature = shift;
my $stats = $feature->statistical_summary($self->width);
$stats ||= [];
my @vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount}:0} @$stats;
my $interval_method = $self->option('interval_method') || 'mean';
my @vals;
if ($interval_method eq 'mean') {
@vals = map {$_->{validCount} ? $_->{sumData}/$_->{validCount} : undef} @$stats;
}
elsif ($interval_method eq 'sum') {
@vals = map {$_->{validCount} ? $_->{sumData} : undef} @$stats;
}
elsif ($interval_method eq 'min') {
@vals = map {$_->{validCount} ? $_->{minVal} : undef} @$stats;
}
elsif ($interval_method eq 'max') {
@vals = map {$_->{validCount} ? $_->{maxVal} : undef} @$stats;
}
else {
warn "unrecognized interval method $interval_method!";
}
return $self->_draw_coverage($feature,\@vals,@_);
}

Expand All @@ -416,6 +448,7 @@ sub _draw_coverage {
my $s = $start + $offset;
my $e = $s+1; # fill in gaps
my $v = $array->[$offset/$bases_per_bin];
next unless defined $v; # skip missing values
push @parts,[$s,$s,$v];
}
$self->draw_plot(\@parts,@_);
Expand Down
1 change: 1 addition & 0 deletions lib/Bio/Graphics/Glyph/wiggle_density.pm
Expand Up @@ -401,6 +401,7 @@ sub _draw_coverage {
my $s = $start + $offset;
my $e = $s+1; # fill in gaps
my $v = $array->[$offset/$bases_per_bin];
$v = 0 unless defined $v; # don't want undefined values
push @parts,[$s,$s,$v];
}
$self->Bio::Graphics::Glyph::wiggle_density::draw_plot(\@parts,@_);
Expand Down
35 changes: 29 additions & 6 deletions lib/Bio/Graphics/Glyph/wiggle_xyplot.pm
Expand Up @@ -11,10 +11,12 @@ sub my_description {
return <<END;
This glyph draws quantitative data as an xyplot. It is designed to be
used in conjunction with features in "wiggle" format as generated by
Bio::Graphics::Wiggle, or base pair coverage data generated by the
Bio::DB::Sam module.
Bio::Graphics::Wiggle, base pair coverage data generated by the
Bio::DB::Sam module, or interval statistical_summaries generated by
the Bio::DB::BigWig module.

For this glyph to work, the feature must define one of the following tags:
For this glyph to work, the feature must define one of the following tags
or methods:

wigfile -- a path to a Bio::Graphics::Wiggle file

Expand All @@ -23,7 +25,9 @@ For this glyph to work, the feature must define one of the following tags:

coverage-- a simple comma-delimited string containing the quantitative values,
assumed to be one value per pixel.


statistical_summary() -- a method for generating statistical information
including validCount, maxVal, minVal, sumData, and sumSquares.
END
}

Expand Down Expand Up @@ -64,6 +68,13 @@ sub my_options {
'scaled to the minimum and maximum values of the region currently on display.',
'min_score and max_score override autoscaling if one or both are defined'
],
interval_method => [
['mean', 'sum', 'min', 'max'],
'mean',
'When working with features that offer a statistical_summary() method,',
'such as those from Bio::DB::BigWig, define the method for reporting',
'scores within each interval.',
],
};
}

Expand Down Expand Up @@ -147,8 +158,8 @@ sub draw_plot {
$scaled_min = int(($min_score-$mean)/$stdev + 0.5);
$scaled_max = int(($max_score-$mean)/$stdev + 0.5);
my $bound = $self->z_score_bound;
$scaled_max = $bound if $scaled_max > 0;
$scaled_min = -$bound if $scaled_min < 0;
$scaled_max = $bound if $scaled_max >= 0;
$scaled_min = -$bound if $scaled_min <= 0;
}
elsif ($side) {
$scaled_min = int($min_score - 0.5);
Expand Down Expand Up @@ -396,6 +407,12 @@ the "wigdata" attribute. This can be an arrayref of quantitative data
starting at feature start and ending at feature end, or the
data string returned by Bio::Graphics::Wiggle->export_to_wif64($start,$end).

The glyph also supports features which offer a statistical_summary()
method, such as those from Bio::DB::BigWig. This method returns a hash
of values, including validCount, maxVal, minVal, sumData, and sumSquares.
For each interval, a statistical score is generated from these values.
The mean, minimum, maximum, or sum of the values may be reported.

=head2 OPTIONS

In addition to all the xyplot glyph options, the following options are
Expand Down Expand Up @@ -439,6 +456,12 @@ recognized:
neg_color color When drawing bicolor plots, the fill color to use for values
that are below the pivot point.

interval_method method When working with bigWig features that use the
statistical_summary() method, define the method
for reporting one or more scores within each
interval. Options include "mean", "sum", "min",
or "max". Default is "mean".

=head2 SPECIAL FEATURE TAGS

The glyph expects one or more of the following tags (attributes) in
Expand Down