Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/ArchiveStableId.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::ArchiveStableId | |
24 | |
25 =head1 DESCRIPTION | |
26 | |
27 ArchiveStableId objects are the main workunit for retrieving stable id | |
28 archived information from EnsEMBL core database. | |
29 | |
30 Attributes: | |
31 type: Gene, Transcript, Translation, Exon, other, undef | |
32 stable_id: eg. ENSG00000000001 | |
33 version: e.g. 1 | |
34 db_name: eg. homo_sapiens_core_12_31 | |
35 release: e.g. 35 | |
36 assembly: e.g. NCBI35 | |
37 successors: listref of Bio::EnsEMBL::ArchiveStableIds | |
38 adaptor: Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | |
39 | |
40 Status: At Risk. This module is in development. | |
41 | |
42 =head1 SEE ALSO | |
43 | |
44 Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | |
45 Bio::EnsEMBL::StableIdEvent | |
46 Bio::EnsEMBL::StableIdHistoryTree | |
47 | |
48 =cut | |
49 | |
50 package Bio::EnsEMBL::ArchiveStableId; | |
51 | |
52 use strict; | |
53 use warnings; | |
54 no warnings qw(uninitialized); | |
55 | |
56 use Bio::EnsEMBL::Root; | |
57 our @ISA = qw(Bio::EnsEMBL::Root); | |
58 | |
59 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
60 use Scalar::Util qw(weaken isweak); | |
61 | |
62 =head2 new | |
63 | |
64 Arg [STABLE_ID] : String $stable_id | |
65 Arg [VERSION] : Int $version | |
66 Arg [CURRENT_VERSION]: Int $current_version | |
67 Arg [DB_NAME] : String $db_name | |
68 Arg [RELEASE] : String $release | |
69 Arg [ASSEMBLY_NAME] : String $assembly | |
70 Arg [TYPE] : String $type - "Gene", "Transcript", "Translation", "Exon" | |
71 Arg [ADAPTOR] : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor $adaptor | |
72 Description : standard constructor with named arguments to create | |
73 ArchiveStableId | |
74 Returntype : Bio::EnsEMBL::ArchiveStableId | |
75 Exceptions : none | |
76 Caller : general, Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | |
77 Status : At Risk | |
78 : under development | |
79 | |
80 =cut | |
81 | |
82 sub new { | |
83 my $class = shift; | |
84 $class = ref( $class ) || $class; | |
85 | |
86 my $self = bless {}, $class; | |
87 | |
88 my ($stable_id, $version, $current_version, $db_name, $release, $assembly, | |
89 $type, $adaptor) = rearrange([qw( STABLE_ID VERSION CURRENT_VERSION DB_NAME | |
90 RELEASE ASSEMBLY TYPE ADAPTOR)], @_ ); | |
91 | |
92 $self->{'stable_id'} = $stable_id; | |
93 $self->{'version'} = $version; | |
94 $self->{'current_version'} = $current_version; | |
95 $self->{'db_name'} = $db_name; | |
96 $self->{'release'} = $release; | |
97 $self->{'assembly'} = $assembly; | |
98 $self->{'type'} = $type; | |
99 $self->adaptor($adaptor); | |
100 | |
101 return $self; | |
102 } | |
103 | |
104 | |
105 =head2 new_fast | |
106 | |
107 Arg [1] : String $stable_id | |
108 Arg [2] : Int $version | |
109 Arg [3] : String $db_name | |
110 Arg [4] : String $release | |
111 Arg [5] : String $assembly | |
112 Arg [6] : String $type - "Gene", "Transcript", "Translation", "Exon" | |
113 Arg [7] : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor $adaptor | |
114 Arg [8] : Int $current_version | |
115 Description : faster version of above constructor | |
116 Returntype : Bio::EnsEMBL::ArchiveStableId | |
117 Exceptions : none | |
118 Caller : general, Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor | |
119 Status : At Risk | |
120 : under development | |
121 | |
122 =cut | |
123 | |
124 sub new_fast { | |
125 my $class = shift; | |
126 | |
127 $class = ref ($class) || $class; | |
128 | |
129 my $self = bless { | |
130 'stable_id' => $_[0], | |
131 'version' => $_[1], | |
132 'db_name' => $_[2], | |
133 'release' => $_[3], | |
134 'assembly' => $_[4], | |
135 'type' => $_[5], | |
136 'adaptor' => $_[6], | |
137 'current_version' => $_[7], | |
138 }, $class; | |
139 | |
140 weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) ); | |
141 | |
142 return $self; | |
143 } | |
144 | |
145 | |
146 =head2 get_history_tree | |
147 | |
148 Arg[1] : (optional) Int $num_high_scorers | |
149 number of mappings per stable ID allowed when filtering | |
150 Arg[2] : (optional) Int $max_rows | |
151 maximum number of stable IDs in history tree (used for | |
152 filtering) | |
153 Example : my $history_tree = $archive_id->get_history_tree; | |
154 Description : Returns the history tree of this ArchiveStableId | |
155 Return type : Bio::EnsEMBL::StableIdHistoryTree | |
156 Exceptions : none | |
157 Caller : general | |
158 Status : At Risk | |
159 : under development | |
160 | |
161 =cut | |
162 | |
163 sub get_history_tree { | |
164 my ($self, $num_high_scorers, $max_rows) = @_; | |
165 | |
166 unless ($self->{'history'}) { | |
167 $self->{'history'} = $self->adaptor->fetch_history_tree_by_stable_id( | |
168 $self->stable_id, $num_high_scorers, $max_rows); | |
169 } | |
170 | |
171 return $self->{'history'}; | |
172 } | |
173 | |
174 | |
175 =head2 get_all_predecessors | |
176 | |
177 Args : none | |
178 Description : Retrieve a list of ArchiveStableIds that were mapped to this | |
179 one. | |
180 Returntype : listref of Bio::EnsEMBL::ArchiveStableId | |
181 Exceptions : none | |
182 Caller : general | |
183 Status : At Risk | |
184 : under development | |
185 | |
186 =cut | |
187 | |
188 sub get_all_predecessors { | |
189 my $self = shift; | |
190 | |
191 my $predecessors = $self->adaptor->fetch_predecessors_by_archive_id($self); | |
192 | |
193 foreach my $pre (@$predecessors) { | |
194 $pre->successors($self); | |
195 } | |
196 | |
197 return $predecessors; | |
198 } | |
199 | |
200 | |
201 =head2 get_all_successors | |
202 | |
203 Args : none | |
204 Description : Retrieve a list of ArchiveStableIds that this one was mapped to. | |
205 Returntype : listref Bio::EnsEMBL::ArchiveStableId | |
206 Exceptions : none | |
207 Caller : general | |
208 Status : At Risk | |
209 : under development | |
210 | |
211 =cut | |
212 | |
213 sub get_all_successors { | |
214 my $self = shift; | |
215 | |
216 if ($self->{'successors'}) { | |
217 return $self->{'successors'}; | |
218 } else { | |
219 my $successors = $self->adaptor->fetch_successors_by_archive_id($self); | |
220 return $self->successors(@$successors); | |
221 } | |
222 } | |
223 | |
224 | |
225 =head2 get_peptide | |
226 | |
227 Description : Retrieves the peptide string for this ArchiveStableId. | |
228 Returntype : String, or undef if this is not a Translation or cant be found | |
229 in the database. | |
230 Exceptions : none | |
231 Caller : general | |
232 Status : At Risk | |
233 : under development | |
234 | |
235 =cut | |
236 | |
237 sub get_peptide { | |
238 my $self = shift; | |
239 | |
240 if ( lc( $self->type() ) eq 'translation' ) { | |
241 return $self->adaptor->get_peptide($self); | |
242 } else { | |
243 return undef; | |
244 } | |
245 } | |
246 | |
247 | |
248 =head2 get_all_associated_archived | |
249 | |
250 Example : my ($arch_gene, $arch_tr, $arch_tl, $pep_seq) = | |
251 @{ $arch_id->get_all_associated_archived }; | |
252 Description : Fetches associated archived stable IDs from the db for this | |
253 ArchiveStableId (version is taken into account). | |
254 Return type : Listref of | |
255 ArchiveStableId archived gene | |
256 ArchiveStableId archived transcript | |
257 (optional) ArchiveStableId archived translation | |
258 (optional) peptide sequence | |
259 Caller : webcode, general | |
260 Status : At Risk | |
261 : under development | |
262 | |
263 =cut | |
264 | |
265 sub get_all_associated_archived { | |
266 my $self = shift; | |
267 return $self->adaptor->fetch_associated_archived($self); | |
268 } | |
269 | |
270 | |
271 =head2 get_all_gene_archive_ids | |
272 | |
273 Example : my @archived_genes = @{ $arch_id->get_all_gene_archive_ids }; | |
274 Description : Returns gene ArchiveStableIds associated with this | |
275 ArchiveStableId. If this is a gene, it returns itself. | |
276 Returntype : listref of Bio::EnsEMBL::ArchiveStableId | |
277 Exceptions : none | |
278 Caller : general | |
279 Status : At Risk | |
280 : under development | |
281 | |
282 =cut | |
283 | |
284 sub get_all_gene_archive_ids { | |
285 my $self = shift; | |
286 | |
287 if ($self->type eq "Gene") { | |
288 return [$self]; | |
289 } else { | |
290 return $self->adaptor->fetch_all_by_archive_id($self, 'Gene'); | |
291 } | |
292 } | |
293 | |
294 | |
295 =head2 get_all_transcript_archive_ids | |
296 | |
297 Example : my @archived_transcripts = | |
298 @{ $arch_id->get_all_transcript_archive_ids }; | |
299 Description : Returns transcript ArchiveStableIds associated with this | |
300 ArchiveStableId. If this is a transcript, it returns itself. | |
301 Returntype : listref of Bio::EnsEMBL::ArchiveStableId | |
302 Exceptions : none | |
303 Caller : general | |
304 Status : At Risk | |
305 : under development | |
306 | |
307 =cut | |
308 | |
309 sub get_all_transcript_archive_ids { | |
310 my $self = shift; | |
311 | |
312 if ($self->type eq "Transcript") { | |
313 return [$self]; | |
314 } else { | |
315 return $self->adaptor->fetch_all_by_archive_id($self, 'Transcript'); | |
316 } | |
317 } | |
318 | |
319 | |
320 =head2 get_all_translation_archive_ids | |
321 | |
322 Example : my @archived_peptides = | |
323 @{ $arch_id->get_all_translation_archive_ids }; | |
324 Description : Returns translation ArchiveStableIds associated with this | |
325 ArchiveStableId. If this is a translation, it returns itself. | |
326 Returntype : listref of Bio::EnsEMBL::ArchiveStableId | |
327 Exceptions : none | |
328 Caller : general | |
329 Status : At Risk | |
330 : under development | |
331 | |
332 =cut | |
333 | |
334 sub get_all_translation_archive_ids { | |
335 my $self = shift; | |
336 | |
337 if ($self->type eq "Translation") { | |
338 return [$self]; | |
339 } else { | |
340 return $self->adaptor->fetch_all_by_archive_id($self, 'Translation'); | |
341 } | |
342 } | |
343 | |
344 | |
345 =head2 current_version | |
346 | |
347 Example : if (my $v = $arch_id->current_version) { | |
348 print "Current version of this stable ID ", $v, "\n"; | |
349 } else { | |
350 print "This stable ID is not in the current db.\n"; | |
351 } | |
352 Description : Lazy-loads the current version of stable ID | |
353 Return type : Boolean (TRUE is current version found, else FALSE) | |
354 Exceptions : none | |
355 Caller : general | |
356 Status : At Risk | |
357 : under development | |
358 | |
359 =cut | |
360 | |
361 sub current_version { | |
362 my $self = shift; | |
363 | |
364 if (@_) { | |
365 $self->{'current_version'} = shift; | |
366 } elsif (! defined $self->{'current_version'}) { | |
367 if (defined $self->adaptor()) { | |
368 # lazy load | |
369 $self->adaptor()->lookup_current($self); | |
370 } | |
371 } | |
372 | |
373 return $self->{'current_version'}; | |
374 } | |
375 | |
376 | |
377 =head2 is_current | |
378 | |
379 Example : if ($arch_id->is_current) { | |
380 print $arch_id->version, " is the current version of this | |
381 stable ID.\n"; | |
382 } | |
383 Description : Determines if the version of this object is the current version | |
384 of this stable ID. Note that this method doesn't lazy-load the | |
385 current version of an ArchiveStableId; if you want to be sure, | |
386 use current_version() instead. | |
387 Return type : Boolean (TRUE if it is current, else FALSE) | |
388 Exceptions : none | |
389 Caller : general | |
390 Status : At Risk | |
391 : under development | |
392 | |
393 =cut | |
394 | |
395 sub is_current { | |
396 my $self = shift; | |
397 return ($self->{'version'} == $self->{'current_version'}); | |
398 } | |
399 | |
400 | |
401 =head2 get_latest_incarnation | |
402 | |
403 Example : my $latest = $arch_id->get_latest_incarnation; | |
404 print "Latest version of ".$arch_id->stable_id." is ". | |
405 $latest->version."\n"; | |
406 Description : Returns the ArchiveStableId representing the latest version | |
407 of this stable ID. Returns itself if this already is the latest | |
408 version, otherwise fetches it from the db. | |
409 Return type : Bio::EnsEMBL::ArchiveStableId | |
410 Exceptions : none | |
411 Caller : general | |
412 Status : At Risk | |
413 : under development | |
414 | |
415 =cut | |
416 | |
417 sub get_latest_incarnation { | |
418 my $self = shift; | |
419 | |
420 return $self if ($self->is_latest); | |
421 | |
422 my $latest = $self->adaptor->fetch_by_stable_id($self->stable_id); | |
423 return $latest; | |
424 } | |
425 | |
426 | |
427 =head2 is_latest | |
428 | |
429 Arg[1] : (optional) Boolean $is_latest | |
430 Example : if ($arch_id->is_latest) { | |
431 print "Version ".$arch_id->version." is the latest version | |
432 of ".$arch_id->stable_id."\n"; | |
433 } | |
434 Description : Indicates whether this is the latest version of this stable ID. | |
435 Can also be used as a setter if we know this is the latest | |
436 version. | |
437 Return type : Boolean (TRUE if yes, FALSE if no) | |
438 Exceptions : none | |
439 Caller : Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor->fetch_by_stable_id, general | |
440 Status : At Risk | |
441 : under development | |
442 | |
443 =cut | |
444 | |
445 sub is_latest { | |
446 my $self = shift; | |
447 $self->{'is_latest'} = shift if (@_); | |
448 return ($self->{'is_latest'} || $self->is_current); | |
449 } | |
450 | |
451 | |
452 # | |
453 # getter/setters for attributes | |
454 # | |
455 | |
456 sub stable_id { | |
457 my $self = shift; | |
458 $self->{'stable_id'} = shift if (@_); | |
459 return $self->{'stable_id'}; | |
460 } | |
461 | |
462 sub version { | |
463 my $self = shift; | |
464 $self->{'version'} = shift if (@_); | |
465 return $self->{'version'}; | |
466 } | |
467 | |
468 sub db_name { | |
469 my $self = shift; | |
470 $self->{'db_name'} = shift if (@_); | |
471 return $self->{'db_name'}; | |
472 } | |
473 | |
474 sub release { | |
475 my $self = shift; | |
476 $self->{'release'} = shift if (@_); | |
477 return $self->{'release'}; | |
478 } | |
479 | |
480 sub assembly { | |
481 my $self = shift; | |
482 $self->{'assembly'} = shift if (@_); | |
483 return $self->{'assembly'}; | |
484 } | |
485 | |
486 sub type { | |
487 my $self = shift; | |
488 $self->{'type'} = shift if (@_); | |
489 return $self->{'type'}; | |
490 } | |
491 | |
492 sub adaptor { | |
493 my $self = shift; | |
494 weaken($self->{'adaptor'} = shift) if (@_); | |
495 return $self->{'adaptor'}; | |
496 } | |
497 | |
498 sub successors { | |
499 my $self = shift; | |
500 $self->{'successors'} = \@_; | |
501 return $self->{'successors'}; | |
502 } | |
503 | |
504 | |
505 1; | |
506 |