EnsEMBL/DensityPlot/BinValueSet.pm untested

filter: Statementstmt 0.0% 0 / 92 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 188 CC 14 SCAR 20.4
CC
14
Cov
0%
get_binvalues
20.0
_store_smallest
12.0
position
6.0
CRAP 7.7
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31  
32 =head1 NAME
33  
34 Bio::EnsEMBL::DensityPlot::BinValueSet
35  
36 =head1 SYNOPSIS
37  
38 =head1 DESCRIPTION
39  
40 =head1 METHODS
41  
42 =cut
43  
44 package Bio::EnsEMBL::DensityPlot::BinValueSet;
45 $Bio::EnsEMBL::DensityPlot::BinValueSet::VERSION = '114.0.0';
46 use vars qw($AUTOLOAD @ISA);
47 use strict;
48 use Bio::EnsEMBL::DensityPlot::BinValue;
49  
50 # Object preamble - inheriets from Bio::Root::Object
51  
52 @ISA = qw(Exporter);
53 #@EXPORT_OK = qw();
54 # new() is inherited from Bio::Root::Object
55  
56 # _initialize is where the heavy stuff will happen when new is called
57  
58 sub new {
59 my ($class,@args) = @_;
60
61 my $self = {};
62 bless $self,$class;
63 $self->{'_bin_array'} = [];
64 return $self;
65 }
66  
67  
68  
69 =head2 add_binvalue
70  
71 Title : add_binValue
72 Usage :
73 Function:
74 Example :
75 Returns :
76 Args :
77  
78  
79 =cut
80  
81 sub add_binvalue{
82 my ($self,$value) = @_;
83  
84 defined ($value->chromosomestart) || $self->throw( "Bin Value object does not contain a ChromosomeStart method" );
85 defined ($value->chromosomeend) || $self->throw( "Bin Value object does not contain a ChromosomeEnd method" );
86 defined ($value->value) || $self->throw( "Bin Value object does not contain a Value method" );
87 $self->_store_biggest($value->value);
88 $self->_store_smallest($value->value);
89  
90 push(@{$self->{'_bin_array'}},$value);
91 }
92  
93 =head2 get_binvalues
94  
95 Title : get_binvalues
96 Usage : my @binvalue_objects = $BVSet->get_binvalues
97 Function: scales all the binvalues by the scale_factor and returns them.
98 Example :
99 Returns : array of BinValue objects
100 Args : none
101  
102  
103 =cut
104  
105 sub get_binvalues{
106 my $self = shift;
107 my $biggest_value = $self->{'_biggest_value'} || 0;
108 my $smallest_value = $self->{'_smallest_value'} || 0;
109
110 if (!defined ($biggest_value)||!defined($smallest_value)){
111 $self->throw("Cannot scale - no values to scale against");
112 }
113  
114 my $width = $self->scale_to_fit();
115  
116 if ($self->stretch && ($biggest_value-$smallest_value) ){
117 foreach my $bv (@{ $self->{'_bin_array'}}){
118 my $scaledval = (($bv->value - $smallest_value) / ($biggest_value-$smallest_value) )* $width;
119 $bv->scaledvalue($scaledval);
120 }
121 } elsif($biggest_value) {
122 foreach my $bv (@{ $self->{'_bin_array'}}){
123 my $scaledval = ($bv->value / $biggest_value) * $width;
124 $bv->scaledvalue($scaledval);
125 }
126 } else {
127 foreach my $bv (@{ $self->{'_bin_array'}}){
128 $bv->scaledvalue(0);
129 }
130 }
131  
132 return ( @{ $self->{'_bin_array'}} );
133  
134 }
135  
136 sub size {
137 my $self = shift;
138 return scalar @{$self->{'_bin_array'}};
139 }
140  
141 =head2 position
142  
143 Title : position
144 Usage : $obj->position($newval)
145 Function:
146 Returns : value of position
147 Args : newvalue (optional)
148  
149  
150 =cut
151  
152 sub position{
153 my $self = shift;
154 if( @_ ) {
155 my $value = shift;
156 $self->{'position'} = $value;
157 }
158 return $self->{'position'};
159  
160 }
161  
162  
163 =head2 label
164  
165 Title : label
166 Usage : $obj->label($newval)
167 Function:
168 Returns : value of label
169 Args : newvalue (optional)
170  
171  
172 =cut
173  
174 sub label{
175 my $self = shift;
176 if( @_ ) {
177 my $value = shift;
178 $self->{'label'} = $value;
179 }
180 return $self->{'label'};
181  
182 }
183  
184  
185 =head2 label2
186  
187 Title : label2
188 Usage : $obj->label2($newval)
189 Function:
190 Returns : value of label2
191 Args : newvalue (optional)
192  
193  
194 =cut
195  
196 sub label2{
197 my $self = shift;
198 if( @_ ) {
199 my $value = shift;
200 $self->{'label2'} = $value;
201 }
202 return $self->{'label2'};
203  
204 }
205  
206  
207  
208 =head2 color
209  
210 Title : color
211 Usage : $obj->color($newval)
212 Function:
213 Returns : value of color
214 Args : newvalue (optional)
215  
216  
217 =cut
218  
219 sub color{
220 my $self = shift;
221  
222  
223 if( @_ ) {
224 my $value = shift;
225 $self->{'color'} = $value;
226 }
227 return $self->{'color'};
228  
229 }
230  
231 =head2 shape
232  
233 Title : shape
234 Usage : $obj->shape($newval)
235 Function:
236 Returns : value of shape
237 Args : newvalue (optional)
238  
239  
240 =cut
241  
242 sub shape{
243 my $self = shift;
244 if( @_ ) {
245 my $value = shift;
246 $self->{'shape'} = $value;
247 }
248 return $self->{'shape'};
249  
250 }
251  
252  
253  
254 =head2 stretch
255  
256 Title : stretch
257 Usage : $obj->stretch($newval)
258 Function: gets/sets a boolean for whether we should stretch the data over the
259 range (i.e. from min to max rather than absolute numbers).
260 Returns : value of _stretch
261 Args : newvalue (optional)
262  
263  
264 =cut
265  
266 sub stretch{
267 my ($self,$value) = @_;
268 if( defined $value ) {
269 $self->{'_stretch'} = $value;
270 }
271 return $self->{'_stretch'};
272 }
273  
274  
275 =head2 scale_to_fit
276  
277 Title : scale_to_fit
278 Usage : $obj->scale_to_fit($newval)
279 Function: gets/sets the number that the BinValues are to be scaled against -
280 i.e. the greatest BinValue->value will be scaled to this number, and the rest
281 scaled in proportion.
282 Returns : scale_to_fit value
283 Args : newvalue (optional)
284  
285  
286 =cut
287  
288 sub scale_to_fit{
289 my $self = shift;
290 if( @_ ) {
291 my $value = shift;
292 $self->{'_scale_to_fit'} = $value;
293 }
294 return $self->{'_scale_to_fit'};
295  
296 }
297  
298  
299 =head2 _store_biggest
300  
301 Title : _store_biggest
302 Usage : $self->_store_biggest($newval)
303 Function: internal method for storing the largest BinValue->value in this set.
304 Returns : biggest value seen so far
305 Args : value
306  
307  
308 =cut
309  
310 sub _store_biggest {
311 my ($self,$val) = @_;
312
313 if (!defined $self->{'_biggest_value'} ||
314 $val > $self->{'_biggest_value'}){
315 $self->{'_biggest_value'}=$val;
316 }
317  
318 return $self->{'_biggest_value'};
319 }
320  
321  
322  
323 =head2 _store_smallest
324  
325 Title : _store_smallest
326 Usage : $self->_store_smallest($newval)
327 Function: internal method for storing the smallest BinValue->value in this set.
328 Returns : smallest value seen so far
329 Args : value
330  
331 =cut
332  
333 sub _store_smallest {
334 my ($self,$val) = @_;
335
336 if (!defined($self->{'_smallest_value'})){
337 $self->{'_smallest_value'}=$val;
338 }
339  
340 if (!defined($self->{'_smallest_value'}) ||
341 $val < $self->{'_smallest_value'}){
342 $self->{'_smallest_value'}=$val;
343 }
344 return $self->{'_smallest_value'};
345 }
346  
347  
348  
349 1;