EnsEMBL/StableIdEvent.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 136 CC 14 SCAR 25.6
CC
14
Cov
0%
old_ArchiveStableId
20.0
new_ArchiveStableId
20.0
get_attribute
20.0
CRAP 12.9
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::StableIdEvent- object representing a stable ID mapping event
34  
35 =head1 SYNOPSIS
36  
37 my $old_id = Bio::EnsEMBL::ArchiveStableId->new(
38 -stable_id => 'ENSG001',
39 -version => 1,
40 -type => 'Gene',
41 );
42  
43 my $new_id = Bio::EnsEMBL::ArchiveStableId->new(
44 -stable_id => 'ENSG001',
45 -version => 2,
46 -type => 'Gene',
47 );
48  
49 my $event = Bio::EnsEMBL::StableIdEvent->new(
50 -old_id => $old_id,
51 -new_id => $new_id,
52 -score => 0.997
53 );
54  
55 # directly access attributes in old and new ArchiveStableId
56 my $old_stable_id = $event->get_attribute( 'old', 'stable_id' );
57  
58 =head1 DESCRIPTION
59  
60 This object represents a stable ID mapping event. Such an event links two
61 ArchiveStableIds with a mapping score.
62  
63 =head1 METHODS
64  
65 new
66 old_ArchiveStableId
67 new_ArchiveStableId
68 score
69 get_attribute
70 ident_string
71  
72 =head1 RELATED MODULES
73  
74 Bio::EnsEMBL::ArchiveStableId
75 Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor
76 Bio::EnsEMBL::StableIdHistoryTree
77  
78 =cut
79  
80 package Bio::EnsEMBL::StableIdEvent;
81 $Bio::EnsEMBL::StableIdEvent::VERSION = '114.0.0';
82 use strict;
83 use warnings;
84 no warnings 'uninitialized';
85  
86 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
87 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
88  
89  
90 =head2 new
91  
92 Arg[1] : Bio::EnsEMBL::ArchiveStableId $old_id
93 The old ArchiveStableId in the mapping event
94 Arg[2] : Bio::EnsEMBL::ArchiveStableId $new_id
95 The new ArchiveStableId in the mapping event
96 Arg[3] : (optional) float $score - score of this mapping event
97 Example : my $event = Bio::EnsEMBL::StableIdEvent->new(
98 $arch_id1, $arch_id2, 0.977);
99 Description : object constructor
100 Return type : Bio::EnsEMBL::StableIdEvent
101 Exceptions : thrown on wrong argument types
102 Caller : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor::fetch_history_tree_by_stable_id, general
103 Status : At Risk
104 : under development
105  
106 =cut
107  
108 sub new {
109 my $caller = shift;
110 my $class = ref($caller) || $caller;
111  
112 my ($old_id, $new_id, $score) = rearrange([qw(OLD_ID NEW_ID SCORE)], @_);
113  
114 throw("Need old or new Bio::EnsEMBL::ArchiveStableId to create StableIdEvent")
115 unless ($old_id || $new_id);
116  
117 my $self = {};
118 bless $self, $class;
119  
120 # initialise object
121 $self->old_ArchiveStableId($old_id);
122 $self->new_ArchiveStableId($new_id);
123 $self->score($score);
124
125 return $self;
126 }
127  
128  
129 =head2 old_ArchiveStableId
130  
131 Arg[1] : (optional) Bio::EnsEMBL::ArchiveStableId $archive_id, or undef
132 The old ArchiveStableId to set for this mapping event
133 Example : # getter
134 my $archive_id = $event->old_ArchiveStableId;
135
136 # setter
137 $event->old_ArchiveStableId($archive_id);
138 Description : Getter/setter for old ArchiveStableId in this mapping event.
139 Return type : Bio::EnsEMBL::ArchiveStableId
140 Exceptions : thrown on wrong argument type
141 Caller : general
142 Status : At Risk
143 : under development
144  
145 =cut
146  
147 sub old_ArchiveStableId {
148 my $self = shift;
149
150 # setter
151 if (@_) {
152 my $archive_id = shift;
153  
154 # if argument is defined, check type. undef is also legal as an argument.
155 if (defined($archive_id)) {
156 throw("Need a Bio::EnsEMBL::ArchiveStableId.") unless
157 (ref($archive_id) && $archive_id->isa('Bio::EnsEMBL::ArchiveStableId'));
158 }
159  
160 $self->{'old_id'} = $archive_id;
161 }
162  
163 # getter
164 return $self->{'old_id'};
165 }
166  
167  
168 =head2 new_ArchiveStableId
169  
170 Arg[1] : (optional) Bio::EnsEMBL::ArchiveStableId $archive_id, or undef
171 The new ArchiveStableId to set for this mapping event
172 Example : # getter
173 my $archive_id = $event->new_ArchiveStableId;
174
175 # setter
176 $event->new_ArchiveStableId($archive_id);
177 Description : Getter/setter for new ArchiveStableId in this mapping event.
178 Return type : Bio::EnsEMBL::ArchiveStableId
179 Exceptions : thrown on wrong argument type
180 Caller : general
181 Status : At Risk
182 : under development
183  
184 =cut
185  
186 sub new_ArchiveStableId {
187 my $self = shift;
188
189 # setter
190 if (@_) {
191 my $archive_id = shift;
192  
193 # if argument is defined, check type. undef is also legal as an argument.
194 if (defined($archive_id)) {
195 throw("Need a Bio::EnsEMBL::ArchiveStableId.") unless
196 (ref($archive_id) && $archive_id->isa('Bio::EnsEMBL::ArchiveStableId'));
197 }
198  
199 $self->{'new_id'} = $archive_id;
200 }
201  
202 # getter
203 return $self->{'new_id'};
204 }
205  
206  
207 =head2 score
208  
209 Arg[1] : (optional) float $score - the score to set
210 Example : my $score = $event->score;
211 Description : Getter/setter for mapping event score.
212 Return type : float or undef
213 Exceptions : none
214 Caller : general
215 Status : At Risk
216 : under development
217  
218 =cut
219  
220 sub score {
221 my $self = shift;
222 $self->{'score'} = shift if (@_);
223 return $self->{'score'};
224 }
225  
226  
227 =head2 get_attribute
228  
229 Arg[1] : String $type - determines whether to get attribute from 'old'
230 or 'new' ArchiveStableId
231 Arg[2] : String $attr - ArchiveStableId attribute to fetch
232 Example : my $old_stable_id = $event->get_attribute('old', 'stable_id');
233 Description : Accessor to attributes of the ArchiveStableIds attached to this
234 event. Convenience method that does the check for undef old
235 and/or new ArchiveStableId for you.
236 Return type : same as respective method in Bio::EnsEMBL::ArchiveStableId, or
237 undef
238 Exceptions : thrown on wrong arguments
239 Caller : general
240 Status : At Risk
241 : under development
242  
243 =cut
244  
245 sub get_attribute {
246 my ($self, $type, $attr) = @_;
247  
248 throw("First argument passed to this function has to be 'old' or 'new'.")
249 unless ($type eq 'old' or $type eq 'new');
250  
251 my %allowed_attribs = map { $_ => 1 }
252 qw(stable_id version db_name release assembly);
253  
254 throw("Attribute $attr not allowed.") unless $allowed_attribs{$attr};
255  
256 my $call = $type.'_ArchiveStableId';
257  
258 if (my $id = $self->$call) {
259 return $id->$attr;
260 } else {
261 return undef;
262 }
263 }
264  
265  
266 =head2 ident_string
267  
268 Example : print $event->ident_string, "\n";
269 Description : Returns a string that can be used to identify your StableIdEvent.
270 Useful in debug warnings.
271 Return type : String
272 Exceptions : none
273 Caller : general
274 Status : At Risk
275 : under development
276  
277 =cut
278  
279 sub ident_string {
280 my $self = shift;
281  
282 my $old_id = $self->old_ArchiveStableId;
283 my $new_id = $self->new_ArchiveStableId;
284  
285 my $str;
286  
287 if ($old_id) {
288 $str = $old_id->stable_id.'.'.$old_id->version.' ('.
289 $old_id->release.')';
290 } else {
291 $str = 'null';
292 }
293  
294 $str .= ' -> ';
295  
296 if ($new_id) {
297 $str .= $new_id->stable_id.'.'.$new_id->version.' ('.
298 $new_id->release.')';
299 } else {
300 $str .= 'null';
301 }
302  
303 $str .= ' ['.$self->score.']';
304
305 return $str;
306 }
307  
308  
309 1;
310