Mercurial > repos > mahtabm > ensemb_rep_gvl
comparison variant_effect_predictor/Bio/EnsEMBL/DensityFeatureSet.pm @ 0:2bc9b66ada89 draft default tip
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 06:29:17 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2bc9b66ada89 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 =head1 NAME | |
22 | |
23 Bio::EnsEMBL::DensityFeatureSet - | |
24 A feature representing a set of density features | |
25 | |
26 =head1 SYNOPSIS | |
27 | |
28 use Bio::EnsEMBL::DensityFeatureSet; | |
29 | |
30 my $densitySet = Bio::EnsEMBL::DensityFeatureSet->new( | |
31 -bin_array = \@out, | |
32 -stretch = 1, | |
33 ); | |
34 | |
35 =head1 DESCRIPTION | |
36 | |
37 A density feature set is a wrap around a array of density features with | |
38 additional information about the collective density feature set, such as | |
39 max_min_values and scale factors etc. a given region. | |
40 | |
41 This module is part of the Ensembl project http://www.ensembl.org | |
42 | |
43 =head1 METHODS | |
44 | |
45 =cut | |
46 | |
47 | |
48 package Bio::EnsEMBL::DensityFeatureSet; | |
49 | |
50 use strict; | |
51 use warnings; | |
52 | |
53 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
54 use Bio::EnsEMBL::Utils::Exception qw(throw); | |
55 | |
56 =head2 new | |
57 | |
58 Description: Creates a new density feature set. | |
59 Returntype : Bio::EnsEMBL::DensityFeatureSet | |
60 Exceptions : throw if invalid density value type is provided | |
61 Caller : general | |
62 Status : Stable | |
63 | |
64 =cut | |
65 | |
66 sub new { | |
67 my $class = shift; | |
68 | |
69 my $max_value = undef; | |
70 my $min_value = undef; | |
71 | |
72 my($dfeats, $stretch, $scale_to_fit) = | |
73 rearrange(['FEATURES', 'STRETCH', 'SCALE_TO_FIT'], @_); | |
74 foreach (@$dfeats){ | |
75 my $value = $_->density_value; | |
76 $max_value = $value if (!defined($max_value) || $value > $max_value); | |
77 $min_value = $value if (!defined($min_value) || $value < $min_value); | |
78 } | |
79 | |
80 return bless {'bin_array' => $dfeats, | |
81 'stretch' => $stretch, | |
82 'scale_to_fit' => $scale_to_fit, | |
83 'min_value' => $min_value, | |
84 'max_value' => $max_value}, $class; | |
85 } | |
86 | |
87 | |
88 =head2 stretch | |
89 | |
90 Title : stretch | |
91 Usage : $obj->stretch($newval) | |
92 Function: gets/sets a boolean for whether we should stretch the data over the | |
93 range (i.e. from min to max rather than absolute numbers). | |
94 Returns : value of _stretch | |
95 Args : newvalue (optional) | |
96 Status : Stable | |
97 | |
98 =cut | |
99 | |
100 sub stretch{ | |
101 my $self = shift; | |
102 $self->{'stretch'} = shift if(@_); | |
103 return $self->{'stretch'}; | |
104 } | |
105 | |
106 | |
107 =head2 scale_to_fit | |
108 | |
109 Title : scale_to_fit | |
110 Usage : $obj->scale_to_fit($newval) | |
111 Function: gets/sets the number that the BinValues are to be scaled against - | |
112 i.e. the greatest BinValue->value will be scaled to this number, and the rest | |
113 scaled in proportion. | |
114 Returns : scale_to_fit value | |
115 Args : newvalue (optional) | |
116 Status : Stable | |
117 | |
118 | |
119 =cut | |
120 | |
121 sub scale_to_fit{ | |
122 my $self = shift; | |
123 $self->{'scale_to_fit'} = shift if (@_); | |
124 return $self->{'scale_to_fit'}; | |
125 | |
126 } | |
127 | |
128 =head2 colour | |
129 | |
130 Title : colour | |
131 Usage : $obj->colour($newval) | |
132 Function: | |
133 Returns : value of colour | |
134 Args : newvalue (optional) | |
135 Status : Stable | |
136 | |
137 | |
138 =cut | |
139 | |
140 | |
141 sub colour{ | |
142 my $self = shift; | |
143 $self->{'color'} = shift if(@_); | |
144 return $self->{'color'}; | |
145 | |
146 } | |
147 | |
148 =head2 label | |
149 | |
150 Title : label | |
151 Usage : $obj->label($newval) | |
152 Function: | |
153 Returns : String containing label | |
154 Args : newvalue (optional) | |
155 Status : Stable | |
156 | |
157 | |
158 =cut | |
159 | |
160 sub label{ | |
161 my $self = shift; | |
162 $self->{'label'} = shift if (@_); | |
163 return $self->{'label'}; | |
164 | |
165 } | |
166 | |
167 | |
168 =head2 label2 | |
169 | |
170 Title : label2 | |
171 Usage : $obj->label2($newval) | |
172 Function: | |
173 Returns : String containing label2 | |
174 Args : newvalue (optional) | |
175 Status : Stable | |
176 | |
177 | |
178 =cut | |
179 | |
180 sub label2{ | |
181 my $self = shift; | |
182 $self->{'label2'} = shift if (@_); | |
183 return $self->{'label2'}; | |
184 } | |
185 | |
186 | |
187 | |
188 =head2 get_all_binvalues | |
189 | |
190 Arg [1] : none | |
191 Example : @binvalues = @{$dfs->get_all_binvalues}; | |
192 Description: Scales all of the contained DensityFeatures by $scalefactor | |
193 and returns them. | |
194 Returntype : reference to a list of DensityFeatures | |
195 Exceptions : none | |
196 Caller : general | |
197 Status : Stable | |
198 | |
199 =cut | |
200 | |
201 sub get_all_binvalues{ | |
202 my $self = shift; | |
203 my $max_value = $self->max_value(); | |
204 my $min_value = $self->min_value(); | |
205 | |
206 return [] if(!@{$self->{'bin_array'}}); | |
207 | |
208 my $width = $self->scale_to_fit(); | |
209 return [] unless defined($width); | |
210 # throw("Cannot scale values - scale_to_fit has not been set"); | |
211 | |
212 if ($self->stretch && ($max_value-$min_value) ){ | |
213 foreach my $bv (@{ $self->{'bin_array'}}){ | |
214 my $scaledval = (($bv->density_value - $min_value) / | |
215 ($max_value-$min_value) )* $width; | |
216 $bv->scaledvalue($scaledval); | |
217 } | |
218 } elsif($max_value) { | |
219 foreach my $bv (@{ $self->{'bin_array'}}){ | |
220 my $scaledval = ($bv->density_value / $max_value) * $width; | |
221 $bv->scaledvalue($scaledval); | |
222 } | |
223 } else { | |
224 foreach my $bv (@{ $self->{'bin_array'}}){ | |
225 $bv->scaledvalue(0); | |
226 } | |
227 } | |
228 | |
229 return $self->{'bin_array'}; | |
230 } | |
231 | |
232 | |
233 =head2 max_value | |
234 | |
235 Arg [1] : none | |
236 Example : my $max = $dfs->max_value(); | |
237 Description: Returns the maximum density feature value from the density | |
238 feature set | |
239 Returntype : int | |
240 Exceptions : none | |
241 Caller : general | |
242 Status : Stable | |
243 | |
244 =cut | |
245 | |
246 sub max_value{ $_[0]->{'max_value'};} | |
247 | |
248 | |
249 =head2 min_value | |
250 | |
251 Arg [1] : none | |
252 Example : my $min = $dfs->min_value(); | |
253 Description: Returns the minimum density feature value from the density | |
254 feature set. | |
255 Returntype : int | |
256 Exceptions : none | |
257 Caller : general | |
258 Status : Stable | |
259 | |
260 =cut | |
261 | |
262 sub min_value{ $_[0]->{'min_value'};} | |
263 | |
264 | |
265 | |
266 =head2 size | |
267 | |
268 Arg [1] : none | |
269 Example : my $num_features = $dfs->size(); | |
270 Description: Returns the number of density features in this density feature | |
271 set. | |
272 Returntype : int | |
273 Exceptions : none | |
274 Caller : general | |
275 Status : Stable | |
276 | |
277 =cut | |
278 | |
279 sub size { | |
280 my $self = shift; | |
281 return scalar @{$self->{'bin_array'}}; | |
282 } | |
283 | |
284 1; | |
285 | |
286 | |
287 |