3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
34 A feature representing a set of density features
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.
51 This module is part of the Ensembl project http:
58 package Bio::EnsEMBL::DensityFeatureSet;
68 Description: Creates a
new density feature set.
70 Exceptions :
throw if invalid density value type is provided
79 my $max_value = undef;
80 my $min_value = undef;
82 my($dfeats, $stretch, $scale_to_fit) =
83 rearrange([
'FEATURES',
'STRETCH',
'SCALE_TO_FIT'], @_);
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);
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;
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)
112 $self->{
'stretch'} = shift
if(@_);
113 return $self->{
'stretch'};
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)
133 $self->{
'scale_to_fit'} = shift
if (@_);
134 return $self->{
'scale_to_fit'};
141 Usage : $obj->colour($newval)
143 Returns : value of colour
144 Args : newvalue (optional)
153 $self->{
'color'} = shift
if(@_);
154 return $self->{
'color'};
161 Usage : $obj->label($newval)
163 Returns : String containing label
164 Args : newvalue (optional)
172 $self->{
'label'} = shift
if (@_);
173 return $self->{
'label'};
181 Usage : $obj->label2($newval)
183 Returns : String containing label2
184 Args : newvalue (optional)
192 $self->{
'label2'} = shift
if (@_);
193 return $self->{
'label2'};
198 =head2 get_all_binvalues
201 Example : @binvalues = @{$dfs->get_all_binvalues};
202 Description: Scales all of the contained DensityFeatures by $scalefactor
204 Returntype : reference to a list of DensityFeatures
211 sub get_all_binvalues{
213 my $max_value = $self->max_value();
214 my $min_value = $self->min_value();
216 return []
if(!@{$self->{
'bin_array'}});
218 my $width = $self->scale_to_fit();
219 return [] unless defined($width);
220 # throw("Cannot scale values - scale_to_fit has not been set");
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);
228 } elsif($max_value) {
229 foreach my $bv (@{ $self->{
'bin_array'}}){
230 my $scaledval = ($bv->density_value / $max_value) * $width;
231 $bv->scaledvalue($scaledval);
234 foreach my $bv (@{ $self->{
'bin_array'}}){
239 return $self->{
'bin_array'};
246 Example : my $max = $dfs->max_value();
247 Description: Returns the maximum density feature value from the density
256 sub max_value{ $_[0]->{
'max_value'};}
262 Example : my $min = $dfs->min_value();
263 Description: Returns the minimum density feature value from the density
272 sub min_value{ $_[0]->{
'min_value'};}
279 Example : my $num_features = $dfs->size();
280 Description: Returns the number of density features in
this density feature
291 return scalar @{$self->{
'bin_array'}};