EnsEMBL/SimpleFeature.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 74 CC 5 SCAR 16.2
CC
5
Cov
0%
summary_as_hash
12.0
display_label
6.0
score
6.0
CRAP 5.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::SimpleFeature - A simple feature with a location and label
34  
35 =head1 SYNOPSIS
36  
37 use Bio::EnsEMBL::SimpleFeature;
38  
39 $feature = Bio::EnsEMBL::SimpleFeature->new(
40 -start => 100,
41 -end => 220,
42 -strand => -1,
43 -slice => $slice,
44 -analysis => $analysis,
45 -score => 58,
46 -display_label => 'EponineTSS',
47 -dbID => 1230,
48 -adaptor => $adaptor
49 );
50  
51 =head1 DESCRIPTION
52  
53 This is a simple feature which extends the Feature class to add
54 display_label and score attributes.
55  
56 =head1 METHODS
57  
58 =cut
59  
60 use strict;
61  
62 package Bio::EnsEMBL::SimpleFeature;
63 $Bio::EnsEMBL::SimpleFeature::VERSION = '114.0.0_50'; # TRIAL
64 $Bio::EnsEMBL::SimpleFeature::VERSION = '114.0.050';
65 use vars qw(@ISA);
66  
67 use Bio::EnsEMBL::Feature;
68 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
69 use Scalar::Util qw(weaken isweak);
70  
71 @ISA = qw(Bio::EnsEMBL::Feature);
72  
73 use constant SEQUENCE_ONTOLOGY => {
74 acc => 'SO:0001411',
75 term => 'biological_region',
76 };
77  
78 =head2 new
79  
80 Arg [DISPLAY_LABEL]: The label assigned to this simple feature
81 Arg [...] : Named arguments passed to superclass
82 Example : $feature = Bio::EnsEMBL::SimpleFeature->new
83 (-start => 1,
84 -end => 100,
85 -strand => 1,
86 -slice => $slice,
87 -analysis => $analysis,
88 -adaptor => $adaptor,
89 -dbID => 10,
90 -display_label => 'EponineTSS',
91 -score => 100);
92 Description: Constructs a new Bio::EnsEMBL::Feature. Generally subclasses
93 of this method are instantiated, rather than this class itself.
94 Returntype : Bio::EnsEMBL::Feature
95 Exceptions : Thrown on invalid -SLICE, -ANALYSIS, -STRAND arguments
96 Caller : general, subclass constructors
97 Status : Stable
98  
99 =cut
100  
101 sub new {
102 my $caller = shift;
103  
104 #allow this to be called as class or object method
105 my $class = ref($caller) || $caller;
106 my $self = $class->SUPER::new(@_);
107  
108 my ($display_label, $score) = rearrange(['DISPLAY_LABEL','SCORE'],@_);
109  
110 $self->{'display_label'} = $display_label;
111 $self->{'score'} = $score;
112  
113 return $self;
114 }
115  
116  
117 =head2 display_label
118  
119 Arg [1] : (optional) string $value
120 Example : $label = $simple_feature->display_label();
121 Description: Getter/Setter for the display label associated with this
122 feature.
123 Returntype : string
124 Exceptions : none
125 Caller : general
126 Status : Stable
127  
128 =cut
129  
130 sub display_label{
131 my $self = shift;
132  
133 $self->{'display_label'} = shift if(@_);
134  
135 return $self->{'display_label'};
136 }
137  
138  
139 =head2 display_id
140  
141 Arg [1] : none
142 Example : print $rf->display_id();
143 Description: This method returns a string that is considered to be
144 the 'display' identifier. For simple features this is the
145 display_label if it is available otherwise it is an empty
146 string.
147 Returntype : string
148 Exceptions : none
149 Caller : web drawing code
150 Status : Stable
151  
152 =cut
153  
154 sub display_id {
155 my $self = shift;
156 return $self->{'display_label'} || '';
157 }
158  
159  
160  
161 =head2 score
162  
163 Arg [1] : (optional) string $value
164 Example : $score = $simple_feature->score();
165 Description: Getter/Setter for the score associated with this
166 feature.
167 Returntype : string
168 Exceptions : none
169 Caller : general
170 Status : Stable
171  
172 =cut
173  
174 sub score {
175 my $self = shift;
176 $self->{'score'} = shift if(@_);
177 return $self->{'score'};
178 }
179  
180  
181 =head2 summary_as_hash
182  
183 Example : my $hash = $simple_feature->summary_as_hash();
184 Description: Generates a HashRef compatible with GFFSerializer. Adds
185 score, external_name and logic_name to the basic Feature
186 hash
187 Returntype : Hash
188 Exceptions : none
189 Caller : general
190 Status : Stable
191  
192 =cut
193  
194 sub summary_as_hash {
195 my ($self) = @_;
196 my $hash = $self->SUPER::summary_as_hash();
197 $hash->{score} = $self->score() if $self->score();
198 $hash->{'external_name'} = $self->display_label() if $self->display_label();
199 $hash->{'logic_name'} = $self->analysis->logic_name();
200 delete $hash->{id};
201 return $hash;
202 }
203  
204  
205 1;