EnsEMBL/DensityFeature.pm untested

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