Mercurial > repos > mahtabm > ensemb_rep_gvl
comparison variant_effect_predictor/Bio/EnsEMBL/Translation.pm @ 0:2bc9b66ada89 draft default tip
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 06:29:17 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2bc9b66ada89 |
---|---|
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::Translation - A class representing the translation of a | |
24 transcript | |
25 | |
26 =head1 SYNOPSIS | |
27 | |
28 my $translation = Bio::EnsEMBL::Translation->new( | |
29 -START_EXON => $exon1, | |
30 -END_EXON => $exon2, | |
31 -SEQ_START => 98, | |
32 -SEQ_END => 39 | |
33 ); | |
34 | |
35 # stable ID setter | |
36 $translation->stable_id('ENSP00053458'); | |
37 | |
38 # get start and end position in start/end exons | |
39 my $start = $translation->start; | |
40 my $end = $translation->end; | |
41 | |
42 =head1 DESCRIPTION | |
43 | |
44 A Translation object defines the CDS and UTR regions of a Transcript | |
45 through the use of start_Exon/end_Exon, and start/end attributes. | |
46 | |
47 =cut | |
48 | |
49 | |
50 package Bio::EnsEMBL::Translation; | |
51 | |
52 use vars qw($AUTOLOAD @ISA); | |
53 use strict; | |
54 | |
55 use Scalar::Util qw(weaken isweak); | |
56 | |
57 use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning ); | |
58 use Bio::EnsEMBL::Utils::Argument qw( rearrange ); | |
59 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref ); | |
60 | |
61 use Bio::EnsEMBL::Storable; | |
62 | |
63 @ISA = qw(Bio::EnsEMBL::Storable); | |
64 | |
65 | |
66 =head2 new | |
67 | |
68 Arg [-START_EXON] : The Exon object in which the translation (CDS) starts | |
69 Arg [-END_EXON] : The Exon object in which the translation (CDS) ends | |
70 Arg [-SEQ_START] : The offset in the start_Exon indicating the start | |
71 position of the CDS. | |
72 Arg [-SEQ_END] : The offset in the end_Exon indicating the end | |
73 position of the CDS. | |
74 Arg [-STABLE_ID] : The stable identifier for this Translation | |
75 Arg [-VERSION] : The version of the stable identifier | |
76 Arg [-DBID] : The internal identifier of this Translation | |
77 Arg [-ADAPTOR] : The TranslationAdaptor for this Translation | |
78 Arg [-SEQ] : Manually sets the peptide sequence of this translation. | |
79 May be useful if this translation is not stored in | |
80 a database. | |
81 Arg [-CREATED_DATE]: the date the translation was created | |
82 Arg [-MODIFIED_DATE]: the date the translation was modified | |
83 Example : my $tl = Bio::EnsEMBL::Translation->new | |
84 (-START_EXON => $ex1, | |
85 -END_EXON => $ex2, | |
86 -SEQ_START => 98, | |
87 -SEQ_END => 39); | |
88 Description: Constructor. Creates a new Translation object | |
89 Returntype : Bio::EnsEMBL::Translation | |
90 Exceptions : none | |
91 Caller : general | |
92 Status : Stable | |
93 | |
94 =cut | |
95 | |
96 sub new { | |
97 my $caller = shift; | |
98 | |
99 my $class = ref($caller) || $caller; | |
100 | |
101 my ( $start_exon, $end_exon, $seq_start, $seq_end, | |
102 $stable_id, $version, $dbID, $adaptor, $seq, | |
103 $created_date, $modified_date ) = | |
104 rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END", | |
105 "STABLE_ID", "VERSION", "DBID", "ADAPTOR", | |
106 "SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ ); | |
107 | |
108 my $self = bless { | |
109 'start_exon' => $start_exon, | |
110 'end_exon' => $end_exon, | |
111 'dbID' => $dbID, | |
112 'start' => $seq_start, | |
113 'end' => $seq_end, | |
114 'stable_id' => $stable_id, | |
115 'version' => $version, | |
116 'created_date' => $created_date, | |
117 'modified_date' => $modified_date, | |
118 'seq' => $seq | |
119 }, $class; | |
120 | |
121 $self->adaptor($adaptor); | |
122 | |
123 return $self; | |
124 } | |
125 | |
126 =head2 new_fast | |
127 | |
128 Arg [1] : hashref to be blessed | |
129 Description: Construct a new Bio::EnsEMBL::Translation using the hashref. | |
130 Exceptions : none | |
131 Returntype : Bio::EnsEMBL::Translation | |
132 Caller : general, subclass constructors | |
133 Status : Stable | |
134 | |
135 =cut | |
136 | |
137 | |
138 sub new_fast { | |
139 my $class = shift; | |
140 my $hashref = shift; | |
141 my $self = bless $hashref, $class; | |
142 weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) ); | |
143 return $self; | |
144 } | |
145 | |
146 =head2 transcript | |
147 | |
148 Arg [1] : Transcript object (optional) | |
149 Description : Sets or retrieves the transcript object associated | |
150 with this translation object. | |
151 Exceptions : Throws if there is no adaptor or no dbID defined for | |
152 the translation object. | |
153 Returntype : Bio::EnsEMBL::Transcript | |
154 =cut | |
155 | |
156 sub transcript { | |
157 my ( $self, $transcript ) = @_; | |
158 | |
159 if ( defined($transcript) ) { | |
160 assert_ref( $transcript, 'Bio::EnsEMBL::Transcript' ); | |
161 | |
162 $self->{'transcript'} = $transcript; | |
163 | |
164 weaken( $self->{'transcript'} ); # Avoid circular references. | |
165 | |
166 } elsif ( @_ > 1 ) { | |
167 # Break connection to transcript. | |
168 delete( $self->{'transcript'} ); | |
169 } elsif ( !defined( $self->{'transcript'} ) ) { | |
170 my $adaptor = $self->adaptor; | |
171 if ( !defined($adaptor) ) { | |
172 throw( "Adaptor is not set for translation, " | |
173 . "can not fetch its transcript." ); | |
174 } | |
175 | |
176 my $dbID = $self->{'dbID'}; | |
177 if ( !defined($dbID) ) { | |
178 throw( "dbID is not set for translation, " | |
179 . " can not fetch its transcript." ); | |
180 } | |
181 | |
182 $self->{'transcript'} = | |
183 $adaptor->db()->get_TranscriptAdaptor() | |
184 ->fetch_by_translation_id($dbID); | |
185 | |
186 # Do not weaken the reference if we had to get the transcript from the | |
187 # database. The user is probably working on translations directly, | |
188 # not going through transcripts. | |
189 #weaken( $self->{'transcript'} ); # Avoid circular references. | |
190 } | |
191 | |
192 return $self->{'transcript'}; | |
193 } ## end sub transcript | |
194 | |
195 | |
196 =head2 start | |
197 | |
198 Arg [1] : (optional) int $start - start position to set | |
199 Example : $translation->start(17); | |
200 Description: Getter/setter for the value of start, which is a position within | |
201 the exon given by start_Exon. | |
202 | |
203 If you need genomic coordinates, use the genomic_start() | |
204 method. | |
205 Returntype : int | |
206 Exceptions : none | |
207 Caller : general | |
208 Status : Stable | |
209 | |
210 =cut | |
211 | |
212 sub start{ | |
213 my $obj = shift; | |
214 if( @_ ) { | |
215 my $value = shift; | |
216 | |
217 $obj->{'start'} = $value; | |
218 } | |
219 return $obj->{'start'}; | |
220 | |
221 } | |
222 | |
223 | |
224 =head2 end | |
225 | |
226 Arg [1] : (optional) int $end - end position to set | |
227 Example : $translation->end(8); | |
228 Description: Getter/setter for the value of end, which is a position within | |
229 the exon given by end_Exon. | |
230 | |
231 If you need genomic coordinates, use the genomic_end() | |
232 method. | |
233 Returntype : int | |
234 Exceptions : none | |
235 Caller : general | |
236 Status : Stable | |
237 | |
238 =cut | |
239 | |
240 sub end { | |
241 my $self = shift; | |
242 if( @_ ) { | |
243 my $value = shift; | |
244 | |
245 $self->{'end'} = $value; | |
246 } | |
247 return $self->{'end'}; | |
248 | |
249 } | |
250 | |
251 | |
252 =head2 start_Exon | |
253 | |
254 Arg [1] : (optional) Bio::EnsEMBL::Exon - start exon to assign | |
255 Example : $translation->start_Exon($exon1); | |
256 Description: Getter/setter for the value of start_Exon, which denotes the | |
257 exon at which translation starts (and within this exon, at the | |
258 position indicated by start, see above). | |
259 Returntype : Bio::EnsEMBL::Exon | |
260 Exceptions : thrown on wrong argument type | |
261 Caller : general | |
262 Status : Stable | |
263 | |
264 =cut | |
265 | |
266 sub start_Exon { | |
267 my $self = shift; | |
268 | |
269 if( @_ ) { | |
270 my $value = shift; | |
271 if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) { | |
272 throw("Got to have an Exon object, not a $value"); | |
273 } | |
274 $self->{'start_exon'} = $value; | |
275 } | |
276 return $self->{'start_exon'}; | |
277 } | |
278 | |
279 | |
280 =head2 end_Exon | |
281 | |
282 Arg [1] : (optional) Bio::EnsEMBL::Exon - start exon to assign | |
283 Example : $translation->start_Exon($exon1); | |
284 Description: Getter/setter for the value of end_Exon, which denotes the | |
285 exon at which translation ends (and within this exon, at the | |
286 position indicated by end, see above). | |
287 Returntype : Bio::EnsEMBL::Exon | |
288 Exceptions : thrown on wrong argument type | |
289 Caller : general | |
290 Status : Stable | |
291 | |
292 =cut | |
293 | |
294 sub end_Exon { | |
295 my $self = shift; | |
296 if( @_ ) { | |
297 my $value = shift; | |
298 if( !ref $value || !$value->isa('Bio::EnsEMBL::Exon') ) { | |
299 throw("Got to have an Exon object, not a $value"); | |
300 } | |
301 $self->{'end_exon'} = $value; | |
302 } | |
303 | |
304 return $self->{'end_exon'}; | |
305 } | |
306 | |
307 =head2 cdna_start | |
308 | |
309 Arg [1] : (optional) Bio::EnsEMBL::Transcript $transcript | |
310 The transcript which this is a translation of. | |
311 Example : $translation_cdna_start = $translation->cdna_start(); | |
312 Description : Returns the start position of the translation in cDNA | |
313 coordinates. | |
314 If no transcript is given, the method will use | |
315 TranscriptAdaptor->fetch_by_translation_id() to locate | |
316 the correct transcript. | |
317 Return type : Integer | |
318 Exceptions : Throws if the given (optional) argument is not a | |
319 transcript. | |
320 Caller : General | |
321 Status : At Risk (Under Development) | |
322 | |
323 =cut | |
324 | |
325 sub cdna_start { | |
326 my ( $self, $transcript ) = @_; | |
327 | |
328 if ( defined($transcript) | |
329 && ( !ref($transcript) | |
330 || !$transcript->isa('Bio::EnsEMBL::Transcript') ) ) | |
331 { | |
332 throw("Argument is not a transcript"); | |
333 } | |
334 | |
335 if ( !exists( $self->{'cdna_start'} ) ) { | |
336 if ( !defined($transcript) ) { | |
337 # We were not given a transcript, get the transcript out of | |
338 # the database. | |
339 $transcript = $self->transcript(); | |
340 } | |
341 | |
342 $self->{'cdna_start'} = | |
343 $self->start_Exon()->cdna_coding_start($transcript); | |
344 } | |
345 | |
346 return $self->{'cdna_start'}; | |
347 } | |
348 | |
349 =head2 cdna_end | |
350 | |
351 Arg [1] : (optional) Bio::EnsEMBL::Transcript $transcript | |
352 The transcript which this is a translation of. | |
353 Example : $translation_cdna_end = $translation->cdna_end(); | |
354 Description : Returns the end position of the translation in cDNA | |
355 coordinates. | |
356 If no transcript is given, the method will use | |
357 TranscriptAdaptor->fetch_by_translation_id() to locate | |
358 the correct transcript. | |
359 Return type : Integer | |
360 Exceptions : Throws if the given (optional) argument is not a | |
361 transcript. | |
362 Caller : General | |
363 Status : At Risk (Under Development) | |
364 | |
365 =cut | |
366 | |
367 sub cdna_end { | |
368 my ( $self, $transcript ) = @_; | |
369 | |
370 if ( defined($transcript) | |
371 && ( !ref($transcript) | |
372 || !$transcript->isa('Bio::EnsEMBL::Transcript') ) ) | |
373 { | |
374 throw("Argument is not a transcript"); | |
375 } | |
376 | |
377 if ( !exists( $self->{'cdna_end'} ) ) { | |
378 if ( !defined($transcript) ) { | |
379 # We were not given a transcript, get the transcript out of | |
380 # the database. | |
381 $transcript = $self->transcript(); | |
382 } | |
383 | |
384 $self->{'cdna_end'} = | |
385 $self->end_Exon()->cdna_coding_end($transcript); | |
386 } | |
387 | |
388 return $self->{'cdna_end'}; | |
389 } | |
390 | |
391 =head2 genomic_start | |
392 | |
393 Args : None | |
394 Example : $translation_genomic_start = | |
395 $translation->genomic_start(); | |
396 Description : Returns the start position of the translation in | |
397 genomic coordinates on the forward strand. | |
398 Return type : Integer | |
399 Exceptions : None | |
400 Caller : General | |
401 Status : At Risk (Under Development) | |
402 | |
403 =cut | |
404 | |
405 sub genomic_start { | |
406 my $self = shift; | |
407 | |
408 if ( !exists $self->{'genomic_start'} ) { | |
409 if ( $self->start_Exon()->strand() >= 0 ) { | |
410 $self->{'genomic_start'} = | |
411 $self->start_Exon()->start() + ( $self->start() - 1 ); | |
412 } else { | |
413 $self->{'genomic_start'} = | |
414 $self->end_Exon()->end() - ( $self->end() - 1 ); | |
415 } | |
416 } | |
417 | |
418 return $self->{'genomic_start'}; | |
419 } | |
420 | |
421 =head2 genomic_end | |
422 | |
423 Args : None | |
424 Example : $translation_genomic_end = $translation->genomic_end(); | |
425 Description : Returns the end position of the translation in genomic | |
426 coordinates on the forward strand. | |
427 Return type : Integer | |
428 Exceptions : None | |
429 Caller : General | |
430 Status : At Risk (Under Development) | |
431 | |
432 =cut | |
433 | |
434 sub genomic_end { | |
435 my $self = shift; | |
436 | |
437 if ( !exists $self->{'genomic_end'} ) { | |
438 if ( $self->end_Exon()->strand() >= 0 ) { | |
439 $self->{'genomic_end'} = | |
440 $self->end_Exon()->start() + ( $self->end() - 1 ); | |
441 } else { | |
442 $self->{'genomic_end'} = | |
443 $self->start_Exon()->end() - ( $self->start() - 1 ); | |
444 } | |
445 } | |
446 | |
447 return $self->{'genomic_end'}; | |
448 } | |
449 | |
450 =head2 version | |
451 | |
452 Arg [1] : (optional) string $version - version to set | |
453 Example : $translation->version(2); | |
454 Description: Getter/setter for attribute version | |
455 Returntype : string | |
456 Exceptions : none | |
457 Caller : general | |
458 Status : Stable | |
459 | |
460 =cut | |
461 | |
462 sub version { | |
463 my $self = shift; | |
464 $self->{'version'} = shift if( @_ ); | |
465 return $self->{'version'}; | |
466 } | |
467 | |
468 | |
469 =head2 stable_id | |
470 | |
471 Arg [1] : (optional) string $stable_id - stable ID to set | |
472 Example : $translation->stable_id('ENSP0059890'); | |
473 Description: Getter/setter for attribute stable_id | |
474 Returntype : string | |
475 Exceptions : none | |
476 Caller : general | |
477 Status : Stable | |
478 | |
479 =cut | |
480 | |
481 sub stable_id { | |
482 my $self = shift; | |
483 $self->{'stable_id'} = shift if( @_ ); | |
484 return $self->{'stable_id'}; | |
485 } | |
486 | |
487 =head2 created_date | |
488 | |
489 Arg [1] : (optional) string $created_date - created date to set | |
490 Example : $translation->created_date('2007-01-10 20:52:00'); | |
491 Description: Getter/setter for attribute created date | |
492 Returntype : string | |
493 Exceptions : none | |
494 Caller : general | |
495 Status : Stable | |
496 | |
497 =cut | |
498 | |
499 sub created_date { | |
500 my $self = shift; | |
501 $self->{'created_date'} = shift if ( @_ ); | |
502 return $self->{'created_date'}; | |
503 } | |
504 | |
505 | |
506 =head2 modified_date | |
507 | |
508 Arg [1] : (optional) string $modified_date - modification date to set | |
509 Example : $translation->modified_date('2007-01-10 20:52:00'); | |
510 Description: Getter/setter for attribute modified date | |
511 Returntype : string | |
512 Exceptions : none | |
513 Caller : general | |
514 Status : Stable | |
515 | |
516 =cut | |
517 | |
518 sub modified_date { | |
519 my $self = shift; | |
520 $self->{'modified_date'} = shift if ( @_ ); | |
521 return $self->{'modified_date'}; | |
522 } | |
523 | |
524 | |
525 | |
526 =head2 transform | |
527 | |
528 Arg [1] : hashref $old_new_exon_map | |
529 a hash that maps old to new exons for a whole gene | |
530 Description: maps start end end exon according to mapping table. | |
531 If an exon is not mapped, just keep the old one. | |
532 Returntype : none | |
533 Exceptions : none | |
534 Caller : Transcript->transform() | |
535 Status : Stable | |
536 | |
537 =cut | |
538 | |
539 sub transform { | |
540 my $self = shift; | |
541 my $href_exons = shift; | |
542 | |
543 my $start_exon = $self->start_Exon(); | |
544 my $end_exon = $self->end_Exon(); | |
545 | |
546 if ( exists $href_exons->{$start_exon} ) { | |
547 $self->start_Exon($href_exons->{$start_exon}); | |
548 } else { | |
549 # do nothing, the start exon wasnt mapped | |
550 } | |
551 | |
552 if ( exists $href_exons->{$end_exon} ) { | |
553 $self->end_Exon($href_exons->{$end_exon}); | |
554 } else { | |
555 # do nothing, the end exon wasnt mapped | |
556 } | |
557 } | |
558 | |
559 | |
560 =head2 get_all_DBEntries | |
561 | |
562 Arg [1] : (optional) String, external database name | |
563 | |
564 Arg [2] : (optional) String, external_db type | |
565 | |
566 Example : @dbentries = @{ $translation->get_all_DBEntries() }; | |
567 | |
568 Description: Retrieves DBEntries (xrefs) for this translation. | |
569 | |
570 This method will attempt to lazy-load DBEntries | |
571 from a database if an adaptor is available and no | |
572 DBEntries are present on the translation (i.e. they | |
573 have not already been added or loaded). | |
574 | |
575 Returntype : Listref to Bio::EnsEMBL::DBEntry objects | |
576 Exceptions : none | |
577 Caller : TranslationAdaptor::store | |
578 Status : Stable | |
579 | |
580 =cut | |
581 | |
582 sub get_all_DBEntries { | |
583 my ( $self, $ex_db_exp, $ex_db_type ) = @_; | |
584 | |
585 my $cache_name = 'dbentries'; | |
586 | |
587 if ( defined($ex_db_exp) ) { | |
588 $cache_name .= $ex_db_exp; | |
589 } | |
590 | |
591 if ( defined($ex_db_type) ) { | |
592 $cache_name .= $ex_db_type; | |
593 } | |
594 | |
595 # if not cached, retrieve all of the xrefs for this translation | |
596 if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) ) | |
597 { | |
598 $self->{$cache_name} = | |
599 $self->adaptor()->db()->get_DBEntryAdaptor() | |
600 ->fetch_all_by_Translation( $self, $ex_db_exp, $ex_db_type ); | |
601 } | |
602 | |
603 $self->{$cache_name} ||= []; | |
604 | |
605 return $self->{$cache_name}; | |
606 } ## end sub get_all_DBEntries | |
607 | |
608 =head2 get_all_object_xrefs | |
609 | |
610 Arg [1] : (optional) String, external database name | |
611 | |
612 Arg [2] : (optional) String, external_db type | |
613 | |
614 Example : @oxrefs = @{ $translation->get_all_object_xrefs() }; | |
615 | |
616 Description: Retrieves xrefs for this translation. | |
617 | |
618 This method will attempt to lazy-load xrefs from a | |
619 database if an adaptor is available and no xrefs | |
620 are present on the translation (i.e. they have not | |
621 already been added or loaded). | |
622 | |
623 NB: This method is an alias for the | |
624 get_all_DBentries() method. | |
625 | |
626 Return type: Listref of Bio::EnsEMBL::DBEntry objects | |
627 | |
628 Status : Stable | |
629 | |
630 =cut | |
631 | |
632 sub get_all_object_xrefs { | |
633 my $self = shift; | |
634 return $self->get_all_DBEntries(@_); | |
635 } | |
636 | |
637 =head2 add_DBEntry | |
638 | |
639 Arg [1] : Bio::EnsEMBL::DBEntry $dbe | |
640 The dbEntry to be added | |
641 Example : $translation->add_DBEntry($xref); | |
642 Description: Associates a DBEntry with this translation. Note that adding | |
643 DBEntries will prevent future lazy-loading of DBEntries for this | |
644 translation (see get_all_DBEntries). | |
645 Returntype : none | |
646 Exceptions : thrown on incorrect argument type | |
647 Caller : general | |
648 Status : Stable | |
649 | |
650 =cut | |
651 | |
652 sub add_DBEntry { | |
653 my $self = shift; | |
654 my $dbe = shift; | |
655 | |
656 unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) { | |
657 throw('Expected DBEntry argument'); | |
658 } | |
659 | |
660 $self->{'dbentries'} ||= []; | |
661 push @{$self->{'dbentries'}}, $dbe; | |
662 } | |
663 | |
664 | |
665 =head2 get_all_DBLinks | |
666 | |
667 Arg [1] : String database name (optional) | |
668 SQL wildcard characters (_ and %) can be used to | |
669 specify patterns. | |
670 | |
671 Example : my @dblinks = @{ $translation->get_all_DBLinks() }; | |
672 my @dblinks = @{ $translation->get_all_DBLinks('Uniprot%') }; | |
673 | |
674 Description: This is here for consistancy with the Transcript | |
675 and Gene classes. It is a synonym for the | |
676 get_all_DBEntries() method. | |
677 | |
678 Return type: Listref to Bio::EnsEMBL::DBEntry objects | |
679 Exceptions : none | |
680 Caller : general | |
681 Status : Stable | |
682 | |
683 =cut | |
684 | |
685 sub get_all_DBLinks { | |
686 my $self = shift; | |
687 return $self->get_all_DBEntries(@_); | |
688 } | |
689 | |
690 =head2 get_all_xrefs | |
691 | |
692 Arg [1] : String database name (optional) | |
693 SQL wildcard characters (_ and %) can be used to | |
694 specify patterns. | |
695 | |
696 Example : @xrefs = @{ $translation->get_all_xrefs() }; | |
697 @xrefs = @{ $translation->get_all_xrefs('Uniprot%') }; | |
698 | |
699 Description: This method is here for consistancy with the Gene | |
700 and Transcript classes. It is an alias for the | |
701 get_all_DBLinks() method, which in turn directly | |
702 calls get_all_DBEntries(). | |
703 | |
704 Return type: Listref of Bio::EnsEMBL::DBEntry objects | |
705 | |
706 Status : Stable | |
707 | |
708 =cut | |
709 | |
710 sub get_all_xrefs { | |
711 my $self = shift; | |
712 return $self->get_all_DBLinks(@_); | |
713 } | |
714 | |
715 =head2 get_all_ProteinFeatures | |
716 | |
717 Arg [1] : (optional) string $logic_name | |
718 The analysis logic_name of the features to retrieve. If not | |
719 specified, all features are retrieved instead. | |
720 Example : $features = $self->get_all_ProteinFeatures('PFam'); | |
721 Description: Retrieves all ProteinFeatures associated with this | |
722 Translation. If a logic_name is specified, only features with | |
723 that logic_name are returned. If no logic_name is provided all | |
724 associated protein_features are returned. | |
725 | |
726 ProteinFeatures are lazy-loaded from the database unless they | |
727 added manually to the Translation or had already been loaded. | |
728 Returntype : Bio::EnsEMBL::ProteinFeature | |
729 Exceptions : none | |
730 Caller : general | |
731 Status : Stable | |
732 | |
733 =cut | |
734 | |
735 sub get_all_ProteinFeatures { | |
736 my $self = shift; | |
737 my $logic_name = shift; | |
738 | |
739 if(!$self->{'protein_features'}) { | |
740 my $adaptor = $self->adaptor(); | |
741 my $dbID = $self->dbID(); | |
742 | |
743 return [] if (!$adaptor || !$dbID); | |
744 | |
745 my %hash; | |
746 $self->{'protein_features'} = \%hash; | |
747 | |
748 my $pfa = $adaptor->db()->get_ProteinFeatureAdaptor(); | |
749 my $name; | |
750 foreach my $f (@{$pfa->fetch_all_by_translation_id($dbID)}) { | |
751 my $analysis = $f->analysis(); | |
752 if($analysis) { | |
753 $name = lc($f->analysis->logic_name()); | |
754 } else { | |
755 warning("ProteinFeature has no attached analysis\n"); | |
756 $name = ''; | |
757 } | |
758 $hash{$name} ||= []; | |
759 push @{$hash{$name}}, $f; | |
760 } | |
761 } | |
762 | |
763 # a specific type of protein feature was requested | |
764 if(defined($logic_name)) { | |
765 $logic_name = lc($logic_name); | |
766 return $self->{'protein_features'}->{$logic_name} || []; | |
767 } | |
768 | |
769 my @features = (); | |
770 | |
771 # all protein features were requested | |
772 foreach my $type (keys %{$self->{'protein_features'}}) { | |
773 push @features, @{$self->{'protein_features'}->{$type}}; | |
774 } | |
775 | |
776 return \@features; | |
777 } | |
778 | |
779 | |
780 =head2 get_all_DomainFeatures | |
781 | |
782 Example : @domain_feats = @{$translation->get_all_DomainFeatures}; | |
783 Description: A convenience method which retrieves all protein features | |
784 that are considered to be 'Domain' features. Features which | |
785 are 'domain' features are those with analysis logic names: | |
786 'pfscan', 'scanprosite', 'superfamily', 'pfam', 'prints', | |
787 'smart', 'pirsf', 'tigrfam'. | |
788 Returntype : listref of Bio::EnsEMBL::ProteinFeatures | |
789 Exceptions : none | |
790 Caller : webcode (protview) | |
791 Status : Stable | |
792 | |
793 =cut | |
794 | |
795 sub get_all_DomainFeatures{ | |
796 my ($self) = @_; | |
797 | |
798 my @features; | |
799 | |
800 my @types = ('pfscan', #profile (prosite or pfam motifs) | |
801 'scanprosite', #prosite | |
802 'superfamily', | |
803 'pfam', | |
804 'smart', | |
805 'tigrfam', | |
806 'pirsf', | |
807 'prints'); | |
808 | |
809 foreach my $type (@types) { | |
810 push @features, @{$self->get_all_ProteinFeatures($type)}; | |
811 } | |
812 | |
813 return \@features; | |
814 } | |
815 | |
816 | |
817 =head2 add_ProteinFeature | |
818 | |
819 Arg [1] : Bio::EnsEMBL::ProteinFeature $pf | |
820 The ProteinFeature to be added | |
821 Example : $translation->add_ProteinFeature($pf); | |
822 Description: Associates a ProteinFeature with this translation. Note that | |
823 adding ProteinFeatures will prevent future lazy-loading of | |
824 ProteinFeatures for this translation (see | |
825 get_all_ProteinFeatures). | |
826 Returntype : none | |
827 Exceptions : thrown on incorrect argument type | |
828 Caller : general | |
829 Status : Stable | |
830 | |
831 =cut | |
832 | |
833 sub add_ProteinFeature { | |
834 my $self = shift; | |
835 my $pf = shift; | |
836 | |
837 unless ($pf && ref($pf) && $pf->isa('Bio::EnsEMBL::ProteinFeature')) { | |
838 throw('Expected ProteinFeature argument'); | |
839 } | |
840 | |
841 my $analysis = $pf->analysis; | |
842 throw("ProteinFeature has no attached Analysis.") unless $analysis; | |
843 | |
844 push @{ $self->{'protein_features'}->{$analysis->logic_name} }, $pf; | |
845 } | |
846 | |
847 | |
848 =head2 display_id | |
849 | |
850 Example : print $translation->display_id(); | |
851 Description: This method returns a string that is considered to be | |
852 the 'display' identifier. For translations this is (depending on | |
853 availability and in this order) the stable Id, the dbID or an | |
854 empty string. | |
855 Returntype : string | |
856 Exceptions : none | |
857 Caller : web drawing code | |
858 Status : Stable | |
859 | |
860 =cut | |
861 | |
862 sub display_id { | |
863 my $self = shift; | |
864 return $self->{'stable_id'} || $self->dbID || ''; | |
865 } | |
866 | |
867 | |
868 =head2 length | |
869 | |
870 Example : print "Peptide length =", $translation->length(); | |
871 Description: Retrieves the length of the peptide sequence (i.e. number of | |
872 amino acids) represented by this Translation object. | |
873 Returntype : int | |
874 Exceptions : none | |
875 Caller : webcode (protview etc.) | |
876 Status : Stable | |
877 | |
878 =cut | |
879 | |
880 sub length { | |
881 my $self = shift; | |
882 my $seq = $self->seq(); | |
883 | |
884 return ($seq) ? CORE::length($seq) : 0; | |
885 } | |
886 | |
887 | |
888 =head2 seq | |
889 | |
890 Example : print $translation->seq(); | |
891 Description: Retrieves a string representation of the peptide sequence | |
892 of this Translation. This retrieves the transcript from the | |
893 database and gets its sequence, or retrieves the sequence which | |
894 was set via the constructor. | |
895 Returntype : string | |
896 Exceptions : warning if the sequence is not set and cannot be retrieved from | |
897 the database. | |
898 Caller : webcode (protview etc.) | |
899 Status : Stable | |
900 | |
901 =cut | |
902 | |
903 sub seq { | |
904 my ( $self, $sequence ) = @_; | |
905 | |
906 if ( defined($sequence) ) { | |
907 | |
908 $self->{'seq'} = $sequence; | |
909 | |
910 } elsif ( !defined( $self->{'seq'} ) ) { | |
911 | |
912 my $transcript = $self->transcript(); | |
913 | |
914 my $canonical_translation = $transcript->translation(); | |
915 my $is_alternative; | |
916 if(!$canonical_translation) { | |
917 throw "Transcript does not have a canonical translation"; | |
918 } | |
919 if ( defined( $canonical_translation->stable_id() ) | |
920 && defined( $self->stable_id() ) ) | |
921 { | |
922 # Try stable ID. | |
923 $is_alternative = | |
924 ( $canonical_translation->stable_id() ne $self->stable_id() ); | |
925 } elsif ( defined( $canonical_translation->dbID() ) | |
926 && defined( $self->dbID() ) ) | |
927 { | |
928 # Try dbID. | |
929 $is_alternative = | |
930 ( $canonical_translation->dbID() != $self->dbID() ); | |
931 } else { | |
932 # Resort to using geomic start/end coordinates. | |
933 $is_alternative = ( ($canonical_translation->genomic_start() != | |
934 $self->genomic_start() ) | |
935 || ( $canonical_translation->genomic_end() != | |
936 $self->genomic_end() ) ); | |
937 } | |
938 | |
939 if ($is_alternative) { | |
940 # To deal with non-canonical (alternative) translations, subsitute | |
941 # the canonical translation in the transcript with $self for a | |
942 # while. | |
943 | |
944 $transcript->translation($self); | |
945 } | |
946 | |
947 my $seq = $transcript->translate(); | |
948 if ( defined($seq) ) { | |
949 $self->{'seq'} = $seq->seq(); | |
950 } | |
951 | |
952 if ($is_alternative) { | |
953 # Reinstate the real canonical translation. | |
954 | |
955 $transcript->translation($canonical_translation); | |
956 } | |
957 | |
958 } ## end elsif ( !defined( $self->...)) | |
959 | |
960 if ( !defined( $self->{'seq'} ) ) { | |
961 return ''; # Empty string | |
962 } | |
963 | |
964 return $self->{'seq'}; | |
965 | |
966 } ## end sub seq | |
967 | |
968 | |
969 =head2 get_all_Attributes | |
970 | |
971 Arg [1] : optional string $attrib_code | |
972 The code of the attribute type to retrieve values for. | |
973 Example : ($sc_attr) = @{$tl->get_all_Attributes('_selenocysteine')}; | |
974 @tl_attributes = @{$translation->get_all_Attributes()}; | |
975 Description: Gets a list of Attributes of this translation. | |
976 Optionally just get Attrubutes for given code. | |
977 Recognized attribute "_selenocysteine" | |
978 Returntype : listref Bio::EnsEMBL::Attribute | |
979 Exceptions : warning if translation does not have attached adaptor and | |
980 attempts lazy load. | |
981 Caller : general, modify_translation | |
982 Status : Stable | |
983 | |
984 =cut | |
985 | |
986 sub get_all_Attributes { | |
987 my $self = shift; | |
988 my $attrib_code = shift; | |
989 | |
990 if( ! exists $self->{'attributes' } ) { | |
991 if(!$self->adaptor() ) { | |
992 # warning('Cannot get attributes without an adaptor.'); | |
993 return []; | |
994 } | |
995 | |
996 my $aa = $self->adaptor->db->get_AttributeAdaptor(); | |
997 $self->{'attributes'} = $aa->fetch_all_by_Translation( $self ); | |
998 } | |
999 | |
1000 if( defined $attrib_code ) { | |
1001 my @results = grep { uc($_->code()) eq uc($attrib_code) } | |
1002 @{$self->{'attributes'}}; | |
1003 return \@results; | |
1004 } else { | |
1005 return $self->{'attributes'}; | |
1006 } | |
1007 } | |
1008 | |
1009 | |
1010 =head2 add_Attributes | |
1011 | |
1012 Arg [1..N] : Bio::EnsEMBL::Attribute $attribute | |
1013 Attributes to add. | |
1014 Example : $translation->add_Attributes($selenocysteine_attribute); | |
1015 Description: Adds an Attribute to the Translation. Usefull to | |
1016 do _selenocysteine. | |
1017 If you add an attribute before you retrieve any from database, | |
1018 lazy load will be disabled. | |
1019 Returntype : none | |
1020 Exceptions : throw on incorrect arguments | |
1021 Caller : general | |
1022 Status : Stable | |
1023 | |
1024 =cut | |
1025 | |
1026 sub add_Attributes { | |
1027 my $self = shift; | |
1028 my @attribs = @_; | |
1029 | |
1030 if( ! exists $self->{'attributes'} ) { | |
1031 $self->{'attributes'} = []; | |
1032 } | |
1033 | |
1034 for my $attrib ( @attribs ) { | |
1035 if( ! $attrib->isa( "Bio::EnsEMBL::Attribute" )) { | |
1036 throw( "Argument to add_Attribute must be a Bio::EnsEMBL::Attribute" ); | |
1037 } | |
1038 push( @{$self->{'attributes'}}, $attrib ); | |
1039 $self->{seq}=undef; | |
1040 } | |
1041 } | |
1042 | |
1043 | |
1044 =head2 get_all_SeqEdits | |
1045 | |
1046 Example : my @seqeds = @{$transcript->get_all_SeqEdits()}; | |
1047 Description: Retrieves all post transcriptional sequence modifications for | |
1048 this transcript. | |
1049 Returntype : Bio::EnsEMBL::SeqEdit | |
1050 Exceptions : none | |
1051 Caller : spliced_seq() | |
1052 Status : Stable | |
1053 | |
1054 =cut | |
1055 | |
1056 sub get_all_SeqEdits { | |
1057 my $self = shift; | |
1058 | |
1059 my @seqeds; | |
1060 | |
1061 my $attribs; | |
1062 | |
1063 my @edits = ('initial_met', '_selenocysteine', 'amino_acid_sub'); | |
1064 | |
1065 | |
1066 foreach my $edit(@edits){ | |
1067 $attribs = $self->get_all_Attributes($edit); | |
1068 | |
1069 # convert attributes to SeqEdit objects | |
1070 foreach my $a (@$attribs) { | |
1071 push @seqeds, Bio::EnsEMBL::SeqEdit->new(-ATTRIB => $a); | |
1072 } | |
1073 } | |
1074 return \@seqeds; | |
1075 } | |
1076 | |
1077 | |
1078 =head2 modify_translation | |
1079 | |
1080 Arg [1] : Bio::Seq $peptide | |
1081 Example : my $seq = Bio::Seq->new(-SEQ => $dna)->translate(); | |
1082 $translation->modify_translation($seq); | |
1083 Description: Applies sequence edits such as selenocysteines to the Bio::Seq | |
1084 peptide thats passed in | |
1085 Returntype : Bio::Seq | |
1086 Exceptions : none | |
1087 Caller : Bio::EnsEMBL::Transcript->translate | |
1088 Status : Stable | |
1089 | |
1090 =cut | |
1091 | |
1092 sub modify_translation { | |
1093 my ( $self, $seq ) = @_; | |
1094 | |
1095 my @seqeds = @{ $self->get_all_SeqEdits() }; | |
1096 | |
1097 # Sort in reverse order to avoid complication of adjusting | |
1098 # downstream edits. | |
1099 # HACK: The translation ENSP00000420939 somehow makes the next line | |
1100 # bomb out ($a or $b becomes undef) if the start() method | |
1101 # is used. I haven't been able to find out why. It has 10 | |
1102 # Selenocysteine seqedits that looks correct. | |
1103 # /Andreas (release 59) | |
1104 @seqeds = sort { $b->{'start'} <=> $a->{'start'} } @seqeds; | |
1105 | |
1106 # Apply all edits. | |
1107 my $peptide = $seq->seq(); | |
1108 foreach my $se (@seqeds) { | |
1109 $se->apply_edit( \$peptide ); | |
1110 } | |
1111 | |
1112 $seq->seq($peptide); | |
1113 | |
1114 return $seq; | |
1115 } | |
1116 | |
1117 =head2 load | |
1118 | |
1119 Arg [1] : Boolean $load_xrefs | |
1120 Load (or don't load) xrefs. Default is to load xrefs. | |
1121 Example : $translation->load(); | |
1122 Description : The Ensembl API makes extensive use of | |
1123 lazy-loading. Under some circumstances (e.g., | |
1124 when copying genes between databases), all data of | |
1125 an object needs to be fully loaded. This method | |
1126 loads the parts of the object that are usually | |
1127 lazy-loaded. | |
1128 Returns : none | |
1129 | |
1130 =cut | |
1131 | |
1132 sub load { | |
1133 my ( $self, $load_xrefs ) = @_; | |
1134 | |
1135 if ( !defined($load_xrefs) ) { $load_xrefs = 1 } | |
1136 | |
1137 $self->seq(); | |
1138 | |
1139 $self->stable_id(); | |
1140 $self->get_all_Attributes(); | |
1141 $self->get_all_ProteinFeatures(); | |
1142 | |
1143 if ($load_xrefs) { | |
1144 $self->get_all_DBEntries(); | |
1145 } | |
1146 } | |
1147 | |
1148 =head2 temporary_id | |
1149 | |
1150 Description: DEPRECATED This method should not be needed. Use dbID, | |
1151 stable_id or something else. | |
1152 | |
1153 =cut | |
1154 | |
1155 sub temporary_id { | |
1156 my $self = shift; | |
1157 deprecate( "I cant see what a temporary_id is good for, please use " . | |
1158 "dbID or stableID or\n try without an id." ); | |
1159 $self->{'temporary_id'} = shift if( @_ ); | |
1160 return $self->{'temporary_id'}; | |
1161 } | |
1162 | |
1163 | |
1164 =head2 get_all_DASFactories | |
1165 | |
1166 Function : Retrieves a listref of registered DAS objects | |
1167 Returntype: Listref of DAS Objects | |
1168 Exceptions: none | |
1169 Caller : webcode | |
1170 Example : $dasref = $prot->get_all_DASFactories; | |
1171 Status : Stable | |
1172 | |
1173 =cut | |
1174 | |
1175 sub get_all_DASFactories { | |
1176 my $self = shift; | |
1177 return [ $self->adaptor()->db()->_each_DASFeatureFactory ]; | |
1178 } | |
1179 | |
1180 | |
1181 =head2 get_all_DAS_Features | |
1182 | |
1183 Example : $features = $prot->get_all_DAS_Features; | |
1184 Description: Retreives a hash reference to a hash of DAS feature | |
1185 sets, keyed by the DNS, NOTE the values of this hash | |
1186 are an anonymous array containing: | |
1187 (1) a pointer to an array of features; | |
1188 (2) a pointer to the DAS stylesheet | |
1189 Returntype : hashref of Bio::SeqFeatures | |
1190 Exceptions : none | |
1191 Caller : webcode | |
1192 Status : Stable | |
1193 | |
1194 =cut | |
1195 | |
1196 sub get_all_DAS_Features{ | |
1197 my $self = shift; | |
1198 | |
1199 my $db = $self->adaptor->db; | |
1200 my $GeneAdaptor = $db->get_GeneAdaptor; | |
1201 my $Gene = $GeneAdaptor->fetch_by_translation_stable_id($self->stable_id) || return; | |
1202 my $slice = $Gene->feature_Slice; | |
1203 | |
1204 return $self->SUPER::get_all_DAS_Features($slice); | |
1205 } | |
1206 | |
1207 =head2 summary_as_hash | |
1208 | |
1209 Example : $translation_summary = $translation->summary_as_hash(); | |
1210 Description : Retrieves a textual summary of this Translation. | |
1211 Not inherited from Feature. | |
1212 Returns : hashref of arrays of descriptive strings | |
1213 Status : Intended for internal use | |
1214 =cut | |
1215 | |
1216 sub summary_as_hash { | |
1217 my $self = shift; | |
1218 my %summary; | |
1219 $summary{'ID'} = $self->display_id; | |
1220 $summary{'genomic_start'} = $self->genomic_start; | |
1221 $summary{'genomic_end'} = $self->genomic_end; | |
1222 my $transcript = $self->transcript; | |
1223 $summary{'Parent'} = $transcript->display_id; | |
1224 return \%summary; | |
1225 } | |
1226 | |
1227 1; |