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