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
44 package Bio::EnsEMBL::DensityPlot::BinValueSet;
46 use vars qw($AUTOLOAD @ISA);
50 # Object preamble - inheriets from Bio::Root::Object
54 # new() is inherited from Bio::Root::Object
56 # _initialize is where the heavy stuff will happen when new is called
59 my ($class,@args) = @_;
63 $self->{
'_bin_array'} = [];
82 my ($self,$value) = @_;
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);
90 push(@{$self->{
'_bin_array'}},$value);
96 Usage : my @binvalue_objects = $BVSet->get_binvalues
97 Function: scales all the binvalues by the scale_factor and returns them.
99 Returns : array of BinValue objects
107 my $biggest_value = $self->{
'_biggest_value'} || 0;
108 my $smallest_value = $self->{
'_smallest_value'} || 0;
110 if (!defined ($biggest_value)||!defined($smallest_value)){
111 $self->throw(
"Cannot scale - no values to scale against");
114 my $width = $self->scale_to_fit();
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);
121 } elsif($biggest_value) {
122 foreach my $bv (@{ $self->{
'_bin_array'}}){
123 my $scaledval = ($bv->value / $biggest_value) * $width;
124 $bv->scaledvalue($scaledval);
127 foreach my $bv (@{ $self->{
'_bin_array'}}){
132 return ( @{ $self->{
'_bin_array'}} );
138 return scalar @{$self->{
'_bin_array'}};
144 Usage : $obj->position($newval)
146 Returns : value of position
147 Args : newvalue (optional)
156 $self->{
'position'} = $value;
158 return $self->{
'position'};
166 Usage : $obj->label($newval)
168 Returns : value of label
169 Args : newvalue (optional)
178 $self->{
'label'} = $value;
180 return $self->{
'label'};
188 Usage : $obj->label2($newval)
190 Returns : value of label2
191 Args : newvalue (optional)
200 $self->{
'label2'} = $value;
202 return $self->{
'label2'};
211 Usage : $obj->color($newval)
213 Returns : value of color
214 Args : newvalue (optional)
225 $self->{
'color'} = $value;
227 return $self->{
'color'};
234 Usage : $obj->shape($newval)
236 Returns : value of shape
237 Args : newvalue (optional)
246 $self->{
'shape'} = $value;
248 return $self->{
'shape'};
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)
267 my ($self,$value) = @_;
268 if( defined $value ) {
269 $self->{
'_stretch'} = $value;
271 return $self->{
'_stretch'};
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)
292 $self->{
'_scale_to_fit'} = $value;
294 return $self->{
'_scale_to_fit'};
299 =head2 _store_biggest
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
311 my ($self,$val) = @_;
313 if (!defined $self->{
'_biggest_value'} ||
314 $val > $self->{
'_biggest_value'}){
315 $self->{
'_biggest_value'}=$val;
318 return $self->{
'_biggest_value'};
323 =head2 _store_smallest
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
333 sub _store_smallest {
334 my ($self,$val) = @_;
336 if (!defined($self->{
'_smallest_value'})){
337 $self->{
'_smallest_value'}=$val;
340 if (!defined($self->{
'_smallest_value'}) ||
341 $val < $self->{
'_smallest_value'}){
342 $self->{
'_smallest_value'}=$val;
344 return $self->{
'_smallest_value'};