blib/lib/Bio/Graphics/Glyph/smoothing.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 58 CC 4 SCAR 17.0
CC
4
Cov
0%
smooth_window
12.0
get_smoothing
6.0
my_options
2.0
CRAP 5.5
1 package Bio::Graphics::Glyph::smoothing;
2 use base 'Bio::Graphics::Glyph';
3  
4 use strict;
5  
6 use constant SMOOTHING => 'mean';
7  
8 sub my_options {
9 {
10 smoothing => [
11 ['none','mean','max','min'],
12 'none',
13 'Whether to smooth data values across a defined window.',
14 'Mean smoothing will run a rolling mean across the window.',
15 'Max smoothing will take the maximum value across the window,',
16 'and min smoothing will take the minimum value.'
17 ],
18 smoothing_window => [
19 'integer',
20 undef,
21 'Size of the smoothing window. If not specified, the window',
22 'will be taken to be 10% of the region under display.'
23 ],
24 };
25 }
26  
27  
28 sub get_smoothing {
29 my $self = shift;
30 return 'none' if $self->smooth_window == 1;
31 return $self->option('smoothing') or SMOOTHING;
32 }
33  
34 sub smooth_window {
35 my $self = shift;
36  
37 my $smooth_window = $self->option('smoothing_window')
38 || $self->option('smoothing window'); # drat!
39 return $smooth_window if defined $smooth_window;
40  
41 my $start = $self->smooth_start;
42 my $end = $self->smooth_end;
43  
44 $smooth_window = int (($end - $start)/(10*$self->width));
45 $smooth_window = 1 unless $smooth_window > 2;
46 return $smooth_window;
47 }
48  
49 sub smooth_start {
50 my $self = shift;
51 my ($start) = sort {$b<=>$a} ($self->feature->start,$self->panel->start);
52 return $start;
53 }
54  
55 sub smooth_end {
56 my $self = shift;
57 my ($end) = sort {$a<=>$b} ($self->feature->end,$self->panel->end);
58 return $end;
59 }
60  
61 1;
62