EnsEMBL/DensityFeatureSet.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 127 CC 12 SCAR 23.4
CC
12
Cov
0%
get_all_binvalues
30.0
new
12.0
stretch
6.0
CRAP 10.4
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 =head1 NAME
32  
33 Bio::EnsEMBL::DensityFeatureSet -
34 A feature representing a set of density features
35  
36 =head1 SYNOPSIS
37  
38 use Bio::EnsEMBL::DensityFeatureSet;
39  
40 my $densitySet = Bio::EnsEMBL::DensityFeatureSet->new(
41 -bin_array = \@out,
42 -stretch = 1,
43 );
44  
45 =head1 DESCRIPTION
46  
47 A density feature set is a wrap around a array of density features with
48 additional information about the collective density feature set, such as
49 max_min_values and scale factors etc. a given region.
50  
51 This module is part of the Ensembl project http://www.ensembl.org
52  
53 =head1 METHODS
54  
55 =cut
56  
57  
58 package Bio::EnsEMBL::DensityFeatureSet;
59 $Bio::EnsEMBL::DensityFeatureSet::VERSION = '114.0.0';
60 use strict;
61 use warnings;
62  
63 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
64 use Bio::EnsEMBL::Utils::Exception qw(throw);
65  
66 =head2 new
67  
68 Description: Creates a new density feature set.
69 Returntype : Bio::EnsEMBL::DensityFeatureSet
70 Exceptions : throw if invalid density value type is provided
71 Caller : general
72 Status : Stable
73  
74 =cut
75  
76 sub new {
77 my $class = shift;
78  
79 my $max_value = undef;
80 my $min_value = undef;
81  
82 my($dfeats, $stretch, $scale_to_fit) =
83 rearrange(['FEATURES', 'STRETCH', 'SCALE_TO_FIT'], @_);
84 foreach (@$dfeats){
85 my $value = $_->density_value;
86 $max_value = $value if (!defined($max_value) || $value > $max_value);
87 $min_value = $value if (!defined($min_value) || $value < $min_value);
88 }
89  
90 return bless {'bin_array' => $dfeats,
91 'stretch' => $stretch,
92 'scale_to_fit' => $scale_to_fit,
93 'min_value' => $min_value,
94 'max_value' => $max_value}, $class;
95 }
96  
97  
98 =head2 stretch
99  
100 Title : stretch
101 Usage : $obj->stretch($newval)
102 Function: gets/sets a boolean for whether we should stretch the data over the
103 range (i.e. from min to max rather than absolute numbers).
104 Returns : value of _stretch
105 Args : newvalue (optional)
106 Status : Stable
107  
108 =cut
109  
110 sub stretch{
111 my $self = shift;
112 $self->{'stretch'} = shift if(@_);
113 return $self->{'stretch'};
114 }
115  
116  
117 =head2 scale_to_fit
118  
119 Title : scale_to_fit
120 Usage : $obj->scale_to_fit($newval)
121 Function: gets/sets the number that the BinValues are to be scaled against -
122 i.e. the greatest BinValue->value will be scaled to this number, and the rest
123 scaled in proportion.
124 Returns : scale_to_fit value
125 Args : newvalue (optional)
126 Status : Stable
127  
128  
129 =cut
130  
131 sub scale_to_fit{
132 my $self = shift;
133 $self->{'scale_to_fit'} = shift if (@_);
134 return $self->{'scale_to_fit'};
135  
136 }
137  
138 =head2 colour
139  
140 Title : colour
141 Usage : $obj->colour($newval)
142 Function:
143 Returns : value of colour
144 Args : newvalue (optional)
145 Status : Stable
146  
147  
148 =cut
149  
150  
151 sub colour{
152 my $self = shift;
153 $self->{'color'} = shift if(@_);
154 return $self->{'color'};
155  
156 }
157  
158 =head2 label
159  
160 Title : label
161 Usage : $obj->label($newval)
162 Function:
163 Returns : String containing label
164 Args : newvalue (optional)
165 Status : Stable
166  
167  
168 =cut
169  
170 sub label{
171 my $self = shift;
172 $self->{'label'} = shift if (@_);
173 return $self->{'label'};
174  
175 }
176  
177  
178 =head2 label2
179  
180 Title : label2
181 Usage : $obj->label2($newval)
182 Function:
183 Returns : String containing label2
184 Args : newvalue (optional)
185 Status : Stable
186  
187  
188 =cut
189  
190 sub label2{
191 my $self = shift;
192 $self->{'label2'} = shift if (@_);
193 return $self->{'label2'};
194 }
195  
196  
197  
198 =head2 get_all_binvalues
199  
200 Arg [1] : none
201 Example : @binvalues = @{$dfs->get_all_binvalues};
202 Description: Scales all of the contained DensityFeatures by $scalefactor
203 and returns them.
204 Returntype : reference to a list of DensityFeatures
205 Exceptions : none
206 Caller : general
207 Status : Stable
208  
209 =cut
210  
211 sub get_all_binvalues{
212 my $self = shift;
213 my $max_value = $self->max_value();
214 my $min_value = $self->min_value();
215  
216 return [] if(!@{$self->{'bin_array'}});
217  
218 my $width = $self->scale_to_fit();
219 return [] unless defined($width);
220 # throw("Cannot scale values - scale_to_fit has not been set");
221  
222 if ($self->stretch && ($max_value-$min_value) ){
223 foreach my $bv (@{ $self->{'bin_array'}}){
224 my $scaledval = (($bv->density_value - $min_value) /
225 ($max_value-$min_value) )* $width;
226 $bv->scaledvalue($scaledval);
227 }
228 } elsif($max_value) {
229 foreach my $bv (@{ $self->{'bin_array'}}){
230 my $scaledval = ($bv->density_value / $max_value) * $width;
231 $bv->scaledvalue($scaledval);
232 }
233 } else {
234 foreach my $bv (@{ $self->{'bin_array'}}){
235 $bv->scaledvalue(0);
236 }
237 }
238  
239 return $self->{'bin_array'};
240 }
241  
242  
243 =head2 max_value
244  
245 Arg [1] : none
246 Example : my $max = $dfs->max_value();
247 Description: Returns the maximum density feature value from the density
248 feature set
249 Returntype : int
250 Exceptions : none
251 Caller : general
252 Status : Stable
253  
254 =cut
255  
256 sub max_value{ $_[0]->{'max_value'};}
257  
258  
259 =head2 min_value
260  
261 Arg [1] : none
262 Example : my $min = $dfs->min_value();
263 Description: Returns the minimum density feature value from the density
264 feature set.
265 Returntype : int
266 Exceptions : none
267 Caller : general
268 Status : Stable
269  
270 =cut
271  
272 sub min_value{ $_[0]->{'min_value'};}
273  
274  
275  
276 =head2 size
277  
278 Arg [1] : none
279 Example : my $num_features = $dfs->size();
280 Description: Returns the number of density features in this density feature
281 set.
282 Returntype : int
283 Exceptions : none
284 Caller : general
285 Status : Stable
286  
287 =cut
288  
289 sub size {
290 my $self = shift;
291 return scalar @{$self->{'bin_array'}};
292 }
293  
294 1;
295  
296  
297