EnsEMBL/DensityFeature.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 116 CC 11 SCAR 19.6
CC
11
Cov
0%
new
12.0
density_value
12.0
density_type
12.0
CRAP 7.1
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::DensityFeature - A feature representing a density, or
34 precentage coverage etc. in a given region.
35  
36 =head1 SYNOPSIS
37  
38 use Bio::EnsEMBL::DensityFeature;
39  
40 $feature = Bio::EnsEMBL::DensityFeature->new(
41 -seq_region => $region,
42 -start => 1,
43 -end => 1e6,
44 -density_type => $dt,
45 -density_value => 98.5
46 );
47  
48 =head1 DESCRIPTION
49  
50 A density feature represents a count, density, or percentage coverage,
51 etc. for a given region.
52  
53 This module is part of the Ensembl project http://www.ensembl.org
54  
55 =head1 METHODS
56  
57 =cut
58  
59  
60 use strict;
61 use warnings;
62  
63 package Bio::EnsEMBL::DensityFeature;
64 $Bio::EnsEMBL::DensityFeature::VERSION = '114.0.0_50'; # TRIAL
65 $Bio::EnsEMBL::DensityFeature::VERSION = '114.0.050';
66 use Bio::EnsEMBL::Feature;
67 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
68 use Bio::EnsEMBL::Utils::Exception qw(throw);
69 use Bio::EnsEMBL::DensityType;
70  
71 use vars qw(@ISA);
72  
73 @ISA = qw(Bio::EnsEMBL::Feature);
74  
75  
76 =head2 new
77  
78 Arg [SEQ_REGION] : the sequence over which the density was calculated.
79  
80 Arg [START] : start point on the seq at which density was calulated.
81  
82 Arg [END] : end point on the seq at which density was calulated.
83  
84 Arg [DENSITY_TYPE] : the type of density calculated.
85  
86 Arg [DENSITY_VALUE] : the density.
87  
88 Arg [...] : Named arguments passed to superclass
89 Example : $feature = Bio::EnsEMBL::DensityFeature->new
90 (-seq_region => $region,
91 -start => 1,
92 -end => 1e6,
93 -density_type => $dt,
94 -density_value => 98.5)
95  
96 Description: Creates a new density feature.
97 Returntype : Bio::EnsEMBL::DensityFeature
98 Exceptions : throw if invalid density value type is provided
99 Caller : general
100 Status : Stable
101  
102 =cut
103  
104 sub new {
105 my $caller = shift;
106  
107 #allow constructor to be called as class or object method
108 my $class = ref($caller) || $caller;
109  
110 my $self = $class->SUPER::new(@_);
111  
112 my($seq_region, $start, $end, $dt, $dv) =
113 rearrange(['SEQ_REGION', 'START', 'END', 'DENSITY_TYPE', 'DENSITY_VALUE'],
114 @_);
115  
116 throw("Density value must be >= 0.") if($dv < 0);
117  
118 if(!defined($dt)){
119 throw("Density Type is NOT optional.");
120 }
121  
122 $self->{'density_type'} = $dt;
123 $self->{'density_value'} = $dv;
124  
125 $self->{'slice'} = $seq_region;
126 $self->{'start'} = $start;
127 $self->{'end'} = $end;
128
129  
130 return $self;
131 }
132  
133  
134  
135 =head2 strand
136  
137 Arg [1] : none
138 Example : $strand = $df->strand();
139 Description: Getter fot the strand attribute. Density features always have
140 strand 0 and this attribute is not settable.
141 Returntype : int (always 0)
142 Exceptions : warning if an attempt is made to set the strand
143 Caller : general
144 Status : Stable
145  
146 =cut
147  
148 sub strand {
149 my $self = shift;
150 warning("DensityFeature strand is not settable") if(@_);
151 return 0;
152 }
153  
154  
155  
156 =head2 density_value
157  
158 Arg [1] : (optional) float $density_value
159 Example : $dv = $density_feature->density_value();
160 Description: Getter/Setter for the density value of this DensityFeature.
161 The density value may be a count, a percentage, or a coverage
162 of a feature type in the area defined by this feature.
163 Returntype : float
164 Exceptions : throw if a negative density value is provided
165 Caller : general
166 Status : Stable
167  
168 =cut
169  
170 sub density_value {
171 my $self = shift;
172  
173 if(@_) {
174 my $density_value = shift;
175 throw("Density value must be >= 0.") if($density_value < 0);
176 $self->{'density_value'} = $density_value;
177 }
178  
179 return $self->{'density_value'};
180 }
181  
182  
183  
184 =head2 analysis
185  
186 Arg [1] : (optional) Bio::EnsEMBL::Analysis $analysis
187 New value for the analysis of the attached DensityType
188 Example : print $df->analysis()->logic_name();
189 Description: Overridden superclass analysis method, to chain to analysis
190 method on attached DensityType.
191 Returntype : Bio::EnsEMBL::Analysis
192 Exceptions : none
193 Caller : general
194 Status : Stable
195  
196 =cut
197  
198 sub analysis {
199 my $self = shift;
200  
201 my $dt = $self->density_type();
202  
203 return undef if(!$dt);
204  
205 return $dt->analysis(@_);
206 }
207  
208  
209  
210 =head2 density_type
211  
212 Arg [1] : string $newval (optional)
213 The new value to set the density_value_type attribute to
214 Example : $density_value_type = $obj->density_value_type()
215 Description: Getter/Setter for the density_value_type attribute
216 Returntype : Bio::EnsEMBL::DensityType
217 Exceptions : if object passed is not of type DensityType
218 Caller : general
219 Status : Stable
220  
221 =cut
222  
223 sub density_type{
224 my $self = shift;
225 if(@_) {
226 my $type = shift;
227 if( !ref $type || !$type->isa("Bio::EnsEMBL::DensityType")){
228 throw("object passed must be an ensembl DensityType ".
229 "not a [".ref($type)."]");
230 }
231 else{
232 $self->{'density_type'}=$type;
233 }
234 }
235 return $self->{'density_type'};
236 }
237  
238  
239 ###BG########
240  
241 =head2 scaledvalue
242  
243 Title : scaledvalue
244 Usage : $obj->scaledvalue($newval)
245 Function:
246 Returns : scalar - object's scaled value
247 Args : newvalue (optional)
248 Status : Stable
249  
250 =cut
251  
252 sub scaledvalue{
253 my $obj = shift;
254 if( @_ ) {
255 my $scaledvalue = shift;
256 $obj->{'scaledvalue'} = $scaledvalue;
257 }
258 return $obj->{'scaledvalue'};
259 }
260  
261  
262  
263 =head2 url
264  
265 Title : url
266 Usage : $obj->url($newval)
267 Function:
268 Returns : String containing this object's url
269 Args : newvalue (optional)
270 Status : Stable
271  
272  
273 =cut
274  
275 sub url{
276 my $obj = shift;
277 if( @_ ) {
278 my $url = shift;
279 $obj->{'url'} = $url;
280 }
281 return $obj->{'url'};
282  
283 }
284  
285  
286 1;
287  
288  
289