EnsEMBL/ArchiveStableId.pm untested

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