EnsEMBL/Transcript.pm untested

filter: Statementstmt 0.0% 0 / 1107 Branchbran 0.0% 0 / 478 Conditioncond 0.0% 0 / 168 Subroutinesub 0.0% 0 / 103 Podpod 0.0% 0 / 88 totaltotal 0.0% 0 / 1944 CC 240 SCAR 44.9
CC
240
Cov
0%
transform
600.0
summary_as_hash
210.0
add_Exon
182.0
CRAP 89.1
1 =head1 LICENSE
2  
3 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4 Copyright [2016-2024] EMBL-European Bioinformatics Institute
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::Transcript - object representing an Ensembl transcript
34  
35 =head1 SYNOPSIS
36  
37 Creation:
38  
39 my $tran = new Bio::EnsEMBL::Transcript();
40 my $tran = new Bio::EnsEMBL::Transcript( -EXONS => \@exons );
41  
42 Manipulation:
43  
44 # Returns an array of Exon objects
45 my @exons = @{ $tran->get_all_Exons() };
46  
47 # Returns the peptide translation of the exons as a Bio::Seq
48 if ( $tran->translation() ) {
49 my $pep = $tran->translate();
50 } else {
51 print "Transcript ", $tran->stable_id(), " is non-coding\n";
52 }
53  
54 =head1 DESCRIPTION
55  
56 A representation of a transcript within the Ensembl system. A transcript
57 consists of a set of Exons and (possibly) a Translation which defines the
58 coding and non-coding regions of the exons.
59  
60 =cut
61  
62 package Bio::EnsEMBL::Transcript;
63 $Bio::EnsEMBL::Transcript::VERSION = '113.0.0';
64 use strict;
65  
66 use Bio::EnsEMBL::Feature;
67 use Bio::EnsEMBL::UTR;
68 use Bio::EnsEMBL::Intron;
69 use Bio::EnsEMBL::ExonTranscript;
70 use Bio::EnsEMBL::CDS;
71 use Bio::EnsEMBL::MANE;
72 use Bio::EnsEMBL::TranscriptMapper;
73 use Bio::EnsEMBL::SeqEdit;
74 use Bio::EnsEMBL::Biotype;
75 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
76 use Bio::EnsEMBL::Utils::Exception qw(warning throw );
77 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
78  
79 use parent qw(Bio::EnsEMBL::Feature);
80  
81 use constant SEQUENCE_ONTOLOGY => {
82 acc => 'SO:0000673',
83 term => 'transcript',
84 };
85  
86 =head2 new
87  
88 Arg [-EXONS] :
89 reference to list of Bio::EnsEMBL::Exon objects - exons which make up
90 this transcript
91 Arg [-STABLE_ID] :
92 string - the stable identifier of this transcript
93 Arg [-VERSION] :
94 int - the version of the stable identifier of this transcript
95 Arg [-EXTERNAL_NAME] :
96 string - the external database name associated with this transcript
97 Arg [-EXTERNAL_DB] :
98 string - the name of the database the external name is from
99 Arg [-EXTERNAL_STATUS]:
100 string - the status of the external identifier
101 Arg [-DISPLAY_XREF]:
102 Bio::EnsEMBL::DBEntry - The external database entry that is used
103 to label this transcript when it is displayed.
104 Arg [-CREATED_DATE]:
105 string - the date the transcript was created
106 Arg [-MODIFIED_DATE]:
107 string - the date the transcript was last modified
108 Arg [-DESCRIPTION]:
109 string - the transcripts description
110 Arg [-BIOTYPE]:
111 string - the biotype e.g. "protein_coding"
112 Arg [-IS_CURRENT]:
113 Boolean - specifies if this is the current version of the transcript
114 Arg [-SOURCE]:
115 string - the transcript source, e.g. "ensembl"
116  
117 Example : $tran = new Bio::EnsEMBL::Transcript(-EXONS => \@exons);
118 Description: Constructor. Instantiates a Transcript object.
119 Returntype : Bio::EnsEMBL::Transcript
120 Exceptions : throw on bad arguments
121 Caller : general
122 Status : Stable
123  
124 =cut
125  
126 sub new {
127 my $proto = shift;
128  
129 my $class = ref($proto) || $proto;
130  
131 my $self = $class->SUPER::new(@_);
132  
133 my (
134 $exons, $stable_id, $version,
135 $external_name, $external_db, $external_status,
136 $display_xref, $created_date, $modified_date,
137 $description, $biotype, $confidence,
138 $external_db_name, $is_current,
139 $source
140 );
141  
142 (
143 $exons, $stable_id, $version,
144 $external_name, $external_db, $external_status,
145 $display_xref, $created_date, $modified_date,
146 $description, $biotype, $confidence,
147 $external_db_name, $is_current,
148 $source
149 )
150 = rearrange( [
151 'EXONS', 'STABLE_ID',
152 'VERSION', 'EXTERNAL_NAME',
153 'EXTERNAL_DB', 'EXTERNAL_STATUS',
154 'DISPLAY_XREF', 'CREATED_DATE',
155 'MODIFIED_DATE', 'DESCRIPTION',
156 'BIOTYPE', 'CONFIDENCE',
157 'EXTERNAL_DB_NAME',
158 'IS_CURRENT', 'SOURCE'
159 ],
160 @_
161 );
162  
163 if ($exons) {
164 $self->{'_trans_exon_array'} = $exons;
165 $self->recalculate_coordinates();
166 }
167  
168 $self->stable_id($stable_id);
169 $self->{'created_date'} = $created_date;
170 $self->{'modified_date'} = $modified_date;
171 $self->external_name($external_name) if ( defined $external_name );
172 $self->external_db($external_db) if ( defined $external_db );
173 $self->external_status($external_status)
174 if ( defined $external_status );
175 $self->display_xref($display_xref) if ( defined $display_xref );
176 $self->edits_enabled(1);
177  
178 $self->description($description);
179  
180 $self->{'biotype'} = $biotype;
181  
182 $self->source($source);
183  
184 # Default version
185 if ( !defined($version) ) { $version = 1 }
186 $self->{'version'} = $version;
187  
188 # default is_current
189 $is_current = 1 unless ( defined($is_current) );
190 $self->{'is_current'} = $is_current;
191  
192 return $self;
193 } ## end sub new
194  
195 =head2 get_all_DBLinks
196  
197 Arg [1] : String database name (optional)
198 SQL wildcard characters (_ and %) can be used to
199 specify patterns.
200  
201 Arg [2] : (optional) String, external database type, can be one of
202 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
203 SQL wildcard characters (_ and %) can be used to
204 specify patterns.
205  
206 Example : my @dblinks = @{ $transcript->get_all_DBLinks() };
207 @dblinks = @{ $transcript->get_all_DBLinks('Uniprot%') };}
208 @dblinks = @{ $transcript->get_all_DBLinks('%', 'ENSEMBL') };
209  
210 Description: Retrieves *all* related DBEntries for this
211 transcript. This includes all DBEntries that are
212 associated with the corresponding translation.
213  
214 If you only want to retrieve the DBEntries associated
215 with the transcript (and not the translation) then
216 you should use the get_all_DBEntries() call instead.
217  
218 Note: Each entry may be listed more than once. No
219 uniqueness checks are done. Also if you put in an
220 incorrect external database name no checks are done
221 to see if this exists, you will just get an empty
222 list.
223  
224 Return type: Listref of Bio::EnsEMBL::DBEntry objects
225 Exceptions : none
226 Caller : general
227 Status : Stable
228  
229 =cut
230  
231 sub get_all_DBLinks {
232 my ( $self, $db_name_exp, $ex_db_type ) = @_;
233  
234 my @links =
235 @{ $self->get_all_DBEntries( $db_name_exp, $ex_db_type ) };
236  
237 # Add all of the transcript and translation xrefs to the return list.
238 my $translation = $self->translation();
239 if ( defined($translation) ) {
240 push( @links,
241 @{$translation->get_all_DBEntries( $db_name_exp, $ex_db_type ) }
242 );
243 }
244  
245 @links = sort { _compare_xrefs() } @links;
246  
247 return \@links;
248 }
249  
250 =head2 get_all_xrefs
251  
252 Arg [1] : String database name (optional)
253 SQL wildcard characters (_ and %) can be used to
254 specify patterns.
255  
256 Example : @xrefs = @{ $transcript->get_all_xrefs() };
257 @xrefs = @{ $transcript->get_all_xrefs('Uniprot%') };
258  
259 Description: Retrieves *all* related xrefs for this transcript.
260 This includes all xrefs that are associated with the
261 corresponding translation of this transcript.
262  
263 If you want to retrieve the xrefs associated with
264 only the transcript (and not the translation) then
265 you should use the get_all_object_xrefs() method
266 instead.
267  
268 Note: Each entry may be listed more than once. No
269 uniqueness checks are done. Also if you put in an
270 incorrect external database name no checks are done
271 to see if this exists, you will just get an empty
272 list.
273  
274 NB: This method is an alias for the
275 get_all_DBLinks() method.
276  
277 Return type: Listref of Bio::EnsEMBL::DBEntry objects
278  
279 Status : Stable
280  
281 =cut
282  
283 sub get_all_xrefs {
284 my $self = shift;
285 return $self->get_all_DBLinks(@_);
286 }
287  
288 =head2 get_all_DBEntries
289  
290 Arg [1] : (optional) String, external database name,
291 SQL wildcard characters (_ and %) can be used to
292 specify patterns.
293  
294 Arg [2] : (optional) String, external database type, can be one of
295 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
296 SQL wildcard characters (_ and %) can be used to
297 specify patterns.
298  
299 Example : my @dbentries = @{ $transcript->get_all_DBEntries() };
300 @dbentries = @{ $transcript->get_all_DBEntries('Uniprot%') };}
301 @dbentries = @{ $transcript->get_all_DBEntries('%', 'ENSEMBL') };}
302  
303 Description: Retrieves DBEntries (xrefs) for this transcript.
304 This does *not* include the corresponding
305 translations DBEntries (see get_all_DBLinks()).
306  
307 This method will attempt to lazy-load DBEntries
308 from a database if an adaptor is available and no
309 DBEntries are present on the transcript (i.e. they
310 have not already been added or loaded).
311  
312 Returntype : Listref of Bio::EnsEMBL::DBEntry objects
313 Exceptions : none
314 Caller : get_all_DBLinks, TranscriptAdaptor::store
315 Status : Stable
316  
317 =cut
318  
319 sub get_all_DBEntries {
320 my ( $self, $ex_db_exp, $ex_db_type ) = @_;
321  
322 my $cache_name = 'dbentries';
323  
324 if ( defined($ex_db_exp) ) {
325 $cache_name .= $ex_db_exp;
326 }
327  
328 if ( defined($ex_db_type) ) {
329 $cache_name .= $ex_db_type;
330 }
331  
332 # if not cached, retrieve all of the xrefs for this transcript
333 if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) )
334 {
335 $self->{$cache_name} =
336 $self->adaptor()->db()->get_DBEntryAdaptor()
337 ->fetch_all_by_Transcript( $self, $ex_db_exp, $ex_db_type );
338 }
339  
340 $self->{$cache_name} ||= [];
341  
342 return $self->{$cache_name};
343 } ## end sub get_all_DBEntries
344  
345 =head2 get_all_object_xrefs
346  
347 Arg [1] : (optional) String, external database name
348  
349 Arg [2] : (optional) String, external_db type
350  
351 Example : @oxrefs = @{ $transcript->get_all_object_xrefs() };
352  
353 Description: Retrieves xrefs for this transcript. This does
354 *not* include xrefs that are associated with the
355 corresponding translations of this transcript (see
356 get_all_xrefs()).
357  
358 This method will attempt to lazy-load xrefs from a
359 database if an adaptor is available and no xrefs are
360 present on the transcript (i.e. they have not already
361 been added or loaded).
362  
363 NB: This method is an alias for the
364 get_all_DBentries() method.
365  
366 Return type: Listref of Bio::EnsEMBL::DBEntry objects
367  
368 Status : Stable
369  
370 =cut
371  
372 sub get_all_object_xrefs {
373 my $self = shift;
374 return $self->get_all_DBEntries(@_);
375 }
376  
377 =head2 add_DBEntry
378  
379 Arg [1] : Bio::EnsEMBL::DBEntry $dbe
380 The dbEntry to be added
381 Example : my $dbe = Bio::EnsEMBL::DBEntery->new(...);
382 $transcript->add_DBEntry($dbe);
383 Description: Associates a DBEntry with this transcript. Note that adding
384 DBEntries will prevent future lazy-loading of DBEntries for this
385 gene (see get_all_DBEntries).
386 Returntype : none
387 Exceptions : thrown on incorrect argument type
388 Caller : general
389 Status : Stable
390  
391 =cut
392  
393 sub add_DBEntry {
394 my $self = shift;
395 my $dbe = shift;
396  
397 unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) {
398 throw('Expected DBEntry argument');
399 }
400  
401 $self->{'dbentries'} ||= [];
402 push @{$self->{'dbentries'}}, $dbe;
403 }
404  
405  
406 =head2 get_all_supporting_features
407  
408 Example : my @evidence = @{ $transcript->get_all_supporting_features };
409 Description: Retrieves any supporting features added manually by
410 calls to add_supporting_features.
411 Returntype : Listref of Bio::EnsEMBL::FeaturePair objects
412 Exceptions : none
413 Caller : general
414 Status : Stable
415  
416 =cut
417  
418 sub get_all_supporting_features {
419 my $self = shift;
420  
421 if( !exists $self->{_supporting_evidence} ) {
422 if($self->adaptor) {
423 my $tsfa = $self->adaptor->db->get_TranscriptSupportingFeatureAdaptor();
424 $self->{_supporting_evidence} = $tsfa->fetch_all_by_Transcript($self);
425 }
426 }
427
428 return $self->{_supporting_evidence} || [];
429 }
430  
431  
432 =head2 add_supporting_features
433  
434 Arg [1-N] : Bio::EnsEMBL::FeaturePair $feature
435 The supporting features to add
436 Example : $transcript->add_supporting_features(@features);
437 Description: Adds a list of supporting features to this Transcript.
438 The added features can be retieved by
439 get_all_supporting_features().
440 Returntype : none
441 Exceptions : throw if any of the features are not FeaturePairs
442 throw if any of the features are not in the same coordinate
443 system as the Transcript
444 Caller : general
445 Status : Stable
446
447 =cut
448
449 sub add_supporting_features {
450 my ($self, @features) = @_;
451  
452 return unless @features;
453
454 $self->{_supporting_evidence} ||= [];
455
456 # check whether this feature object has been added already
457 FEATURE: foreach my $feature (@features) {
458  
459 if (!defined($feature) || ref($feature) eq "ARRAY") {
460 throw("Element in transcript supporting features array is undefined or is an ARRAY for " . $self->dbID);
461 }
462 if (!$feature || !$feature->isa("Bio::EnsEMBL::FeaturePair")) {
463 print "feature = " . $feature . "\n";
464 throw("Supporting feat [$feature] not a " .
465 "Bio::EnsEMBL::FeaturePair");
466 }
467
468 if ((defined $self->slice() && defined $feature->slice())&&
469 ( $self->slice()->name() ne $feature->slice()->name())){
470 throw("Supporting feat not in same coord system as transcript\n" .
471 "transcript is attached to [".$self->slice()->name()."]\n" .
472 "feat is attached to [".$feature->slice()->name()."]");
473 }
474  
475 foreach my $added_feature ( @{ $self->{_supporting_evidence} } ){
476 # compare objects
477 if ( $feature == $added_feature ){
478 #this feature has already been added
479 next FEATURE;
480 }
481 }
482
483 #no duplicate was found, add the feature
484 push(@{$self->{_supporting_evidence}}, $feature);
485 }
486 }
487  
488  
489 =head2 flush_supporting_features
490  
491 Example : $transcript->flush_supporting_features;
492 Description : Removes all supporting evidence from the transcript.
493 Return type : (Empty) listref
494 Exceptions : none
495 Caller : general
496 Status : Stable
497  
498 =cut
499  
500 sub flush_supporting_features {
501 my $self = shift;
502 $self->{'_supporting_evidence'} = [];
503 }
504  
505  
506 =head2 external_db
507  
508 Arg [1] : (optional) String - name of external db to set
509 Example : $transcript->external_db('HGNC');
510 Description: Getter/setter for attribute external_db. The db is the one that
511 belongs to the external_name.
512 Returntype : String
513 Exceptions : none
514 Caller : general
515 Status : Stable
516  
517 =cut
518  
519 sub external_db {
520 my ( $self, $ext_dbname ) = @_;
521  
522 if(defined $ext_dbname) {
523 return ( $self->{'external_db'} = $ext_dbname );
524 }
525  
526 if( exists $self->{'external_db'} ) {
527 return $self->{'external_db'};
528 }
529  
530 my $display_xref = $self->display_xref();
531  
532 if( defined $display_xref ) {
533 return $display_xref->dbname()
534 } else {
535 return undef;
536 }
537 }
538  
539  
540 =head2 external_status
541  
542 Arg [1] : (optional) String - status of the external db
543 Example : $transcript->external_status('KNOWNXREF');
544 Description: Getter/setter for attribute external_status. The status of
545 the external db of the one that belongs to the external_name.
546 Returntype : String
547 Exceptions : none
548 Caller : general
549 Status : Stable
550  
551 =cut
552  
553 sub external_status {
554 my ( $self, $ext_status ) = @_;
555  
556 if(defined $ext_status) {
557 return ( $self->{'external_status'} = $ext_status );
558 }
559  
560 if( exists $self->{'external_status'} ) {
561 return $self->{'external_status'};
562 }
563  
564 my $display_xref = $self->display_xref();
565  
566 if( defined $display_xref ) {
567 return $display_xref->status()
568 } else {
569 return undef;
570 }
571 }
572  
573  
574 =head2 external_name
575  
576 Arg [1] : (optional) String - the external name to set
577 Example : $transcript->external_name('BRCA2-001');
578 Description: Getter/setter for attribute external_name.
579 Returntype : String or undef
580 Exceptions : none
581 Caller : general
582 Status : Stable
583  
584 =cut
585  
586 sub external_name {
587 my ($self, $ext_name) = @_;
588  
589 if(defined $ext_name) {
590 return ( $self->{'external_name'} = $ext_name );
591 }
592  
593 if( exists $self->{'external_name'} ) {
594 return $self->{'external_name'};
595 }
596  
597 my $display_xref = $self->display_xref();
598  
599 if( defined $display_xref ) {
600 return $display_xref->display_id()
601 } else {
602 return undef;
603 }
604 }
605  
606 =head2 source
607  
608 Arg [1] : (optional) String - the source to set
609 Example : $transcript->source('ensembl');
610 Description: Getter/setter for attribute source
611 Returntype : String
612 Exceptions : none
613 Caller : general
614 Status : Stable
615  
616 =cut
617  
618 sub source {
619 my $self = shift;
620 $self->{'source'} = shift if( @_ );
621 return ( $self->{'source'} || "ensembl" );
622 }
623  
624 =head2 display_xref
625  
626 Arg [1] : (optional) Bio::EnsEMBL::DBEntry - the display xref to set
627 Example : $transcript->display_xref($db_entry);
628 Description: Getter/setter for display_xref for this transcript.
629 Returntype : Bio::EnsEMBL::DBEntry
630 Exceptions : none
631 Caller : general
632 Status : Stable
633  
634 =cut
635  
636 sub display_xref {
637 my $self = shift;
638 $self->{'display_xref'} = shift if(@_);
639 return $self->{'display_xref'};
640 }
641  
642 =head2 is_canonical
643  
644 Args [1] : (optional) Boolean is_canonical
645  
646 Example : if ($transcript->is_canonical()) { ... }
647  
648 Description : Returns true (non-zero) if the transcript is the
649 canonical transcript of its gene, false (0) if not. If the code
650 returns an undefined it is because its state is not currently
651 known. Internally the code will consult the database for this
652 value if it is unknown and the transcript has a dbID and an
653 attached adaptor
654  
655 Return type : Boolean
656  
657 Status : Stable
658  
659 =cut
660  
661 sub is_canonical {
662 my ( $self, $value ) = @_;
663
664 #Shortcut call
665 return $self->{is_canonical} if defined $self->{is_canonical};
666
667 if ( defined($value) ) {
668 $self->{is_canonical} = ( $value ? 1 : 0 );
669 }
670 else {
671 if(! defined $self->{is_canonical} && $self->dbID() && $self->adaptor()) {
672 $self->{is_canonical} = $self->adaptor()->is_Transcript_canonical($self);
673 }
674 }
675  
676 return $self->{is_canonical};
677 }
678  
679 =head2 translation
680  
681 Args : None
682 Example : if ( $transcript->translation() ) {
683 print( $transcript->translation()->stable_id(), "\n" );
684 } else {
685 print("Pseudogene\n");
686 }
687 Description: Getter/setter for the Translation object which
688 defines the CDS (and as a result the peptide encoded
689 by) this transcript. This function will return
690 undef if this transcript is a pseudogene, i.e. a
691 non-translating transcript such as an ncRNA. This
692 is the accepted method of determining whether a
693 transcript is a pseudogene or not.
694 Returntype : Bio::EnsEMBL::Translation
695 Exceptions : none
696 Caller : general
697 Status : Stable
698  
699 =cut
700  
701 sub translation {
702 my ( $self, $translation ) = @_;
703  
704 if ( defined($translation) ) {
705 assert_ref( $translation, 'Bio::EnsEMBL::Translation' );
706  
707 $self->{'translation'} = $translation;
708 $translation->transcript($self);
709  
710 $self->{'cdna_coding_start'} = undef;
711 $self->{'cdna_coding_end'} = undef;
712  
713 $self->{'coding_region_start'} = undef;
714 $self->{'coding_region_end'} = undef;
715  
716 $self->{'transcript_mapper'} = undef;
717  
718 } elsif ( @_ > 1 ) {
719 if ( defined( $self->{'translation'} ) ) {
720 # Removing existing translation
721  
722 $self->{'translation'}->transcript(undef);
723 delete( $self->{'translation'} );
724  
725 $self->{'cdna_coding_start'} = undef;
726 $self->{'cdna_coding_end'} = undef;
727  
728 $self->{'coding_region_start'} = undef;
729 $self->{'coding_region_end'} = undef;
730  
731 $self->{'transcript_mapper'} = undef;
732 }
733 } elsif ( !exists( $self->{'translation'} )
734 && defined( $self->adaptor() ) )
735 {
736 $self->{'translation'} =
737 $self->adaptor()->db()->get_TranslationAdaptor()
738 ->fetch_by_Transcript($self);
739 }
740  
741 return $self->{'translation'};
742 } ## end sub translation
743  
744 =head2 get_all_alternative_translations
745  
746 Args : None
747 Example :
748  
749 my @alt_translations =
750 @{ $transcript->get_all_alternative_translations() };
751  
752 Description: Fetches all alternative translations defined for this
753 transcript. The canonical translation is not returned.
754  
755 Returntype : Arrayref to Bio::EnsEMBL::Translation
756 Exceptions : None
757 Caller : General
758 Status : Stable
759  
760 =cut
761  
762 sub get_all_alternative_translations {
763 my ($self) = @_;
764  
765 if ( !exists( $self->{'alternative_translations'} )
766 && defined( $self->adaptor() ) )
767 {
768 my $pa = $self->adaptor()->db()->get_TranslationAdaptor();
769 my @translations =
770 @{ $pa->fetch_all_alternative_by_Transcript($self) };
771  
772 $self->{'alternative_translations'} = \@translations;
773 }
774  
775 return $self->{'alternative_translations'};
776 }
777  
778 =head2 add_alternative_translation
779  
780 Args : Bio::EnsEMBL::Translation $translation
781 Example :
782  
783 $transcript->add_alternative_translation($translation);
784  
785 Description: Adds an alternative translation to this transcript.
786 Returntype : None
787 Exceptions : None
788 Caller : General
789 Status : Stable
790  
791 =cut
792  
793 sub add_alternative_translation {
794 my ( $self, $translation ) = @_;
795  
796 if ( !( defined($translation)
797 && ref($translation)
798 && $translation->isa('Bio::EnsEMBL::Translation') ) )
799 {
800 throw("Bio::EnsEMBL::Translation argument expected.");
801 }
802  
803 # Load the existsing alternative translations from the database if
804 # they haven't already been loaded.
805 $self->get_all_alternative_translations();
806  
807 push( @{ $self->{'alternative_translations'} }, $translation );
808 }
809  
810 =head2 spliced_seq
811  
812 Args : soft_mask (opt)
813 if specified, will return a sequence where UTR regions are lowercased
814 Description: Retrieves all Exon sequences and concats them together.
815 No phase padding magic is done, even if phases do not align.
816 Returntype : Text
817 Exceptions : none
818 Caller : general
819 Status : Stable
820  
821 =cut
822  
823 sub spliced_seq {
824 my ( $self, $soft_mask ) = @_;
825  
826 my $seq_string = "";
827 for my $ex ( @{$self->get_all_Exons()} ) {
828 my $seq = $ex->seq();
829 if(!$seq) {
830 warning("Could not obtain seq for exon. Transcript sequence may not " .
831 "be correct.");
832 $seq_string .= 'N' x $ex->length();
833 } else {
834 my $exon_seq = $seq->seq();
835 if ($soft_mask) {
836 my $padstr;
837 if (!defined ($ex->coding_region_start($self))) {
838 $exon_seq = lc($exon_seq);
839 }
840  
841 if ($ex->coding_region_start($self) > $ex->start()) {
842 my $forward_length = $ex->coding_region_start($self) - $ex->start();
843 my $reverse_length = $ex->end() - $ex->coding_region_start($self);
844 if ($ex->strand == 1) {
845 $exon_seq = lc (substr($exon_seq, 0, $forward_length)) . substr($exon_seq, $forward_length);
846 } else {
847 $exon_seq = substr($exon_seq, 0, $reverse_length+1) . lc(substr($exon_seq, $reverse_length+1));
848 }
849 }
850  
851 if ($ex->coding_region_end($self) < $ex->end()) {
852 my $forward_length = $ex->coding_region_end($self) - $ex->start();
853 my $reverse_length = $ex->end() - $ex->coding_region_end($self);
854 if ($ex->strand == 1) {
855 $exon_seq = substr($exon_seq, 0, $forward_length+1) . lc(substr($exon_seq, $forward_length+1));
856 } else {
857 $exon_seq = lc(substr($exon_seq, 0, $reverse_length)) . substr($exon_seq, $reverse_length);
858 }
859 }
860 }
861 $seq_string .= $exon_seq;
862 }
863 }
864  
865 # apply post transcriptional edits
866 if($self->edits_enabled()) {
867 my @seqeds = @{$self->get_all_SeqEdits()};
868  
869 # sort edits in reverse order to remove complication of
870 # adjusting downstream edits
871 @seqeds = sort {$b->start() <=> $a->start()} @seqeds;
872  
873 foreach my $se (@seqeds) {
874 $se->apply_edit(\$seq_string);
875 }
876 }
877  
878 return $seq_string;
879 }
880  
881  
882 =head2 translateable_seq
883  
884 Args : none
885 Example : print $transcript->translateable_seq(), "\n";
886 Description: Returns a sequence string which is the the translateable part
887 of the transcripts sequence. This is formed by splicing all
888 Exon sequences together and apply all defined RNA edits.
889 Then the coding part of the sequence is extracted and returned.
890 The code will not support monkey exons any more. If you want to
891 have non phase matching exons, defined appropriate _rna_edit
892 attributes!
893  
894 An empty string is returned if this transcript is a pseudogene
895 (i.e. is non-translateable).
896 Returntype : Text
897 Exceptions : none
898 Caller : general
899 Status : Stable
900  
901 =cut
902  
903 sub translateable_seq {
904 my ( $self ) = @_;
905  
906 if ( !$self->translation() ) {
907 return '';
908 }
909  
910 my $mrna = $self->spliced_seq();
911  
912 my $start = $self->cdna_coding_start();
913 my $end = $self->cdna_coding_end();
914  
915 $mrna = substr( $mrna, $start - 1, $end - $start + 1 );
916  
917 my $start_phase = $self->translation->start_Exon->phase();
918 if( $start_phase > 0 ) {
919 $mrna = "N"x$start_phase . $mrna;
920 }
921 if( ! $start || ! $end ) {
922 return "";
923 }
924  
925 return $mrna;
926 }
927  
928  
929 =head2 cdna_coding_start
930  
931 Arg [1] : (optional) $value
932 Example : $relative_coding_start = $transcript->cdna_coding_start;
933 Description: Retrieves the position of the coding start of this transcript
934 in cdna coordinates (relative to the start of the 5prime end of
935 the transcript, excluding introns, including utrs).
936  
937 This will return undef if this is a pseudogene (i.e. a
938 transcript with no translation).
939 Returntype : int
940 Exceptions : none
941 Caller : five_prime_utr, get_all_snps, general
942 Status : Stable
943  
944 =cut
945  
946 sub cdna_coding_start {
947 my $self = shift;
948  
949 if( @_ ) {
950 $self->{'cdna_coding_start'} = shift;
951 }
952  
953 if(!defined $self->{'cdna_coding_start'} && defined $self->translation){
954 # calc coding start relative from the start of translation (in cdna coords)
955 my $start = 0;
956  
957 my @exons = @{$self->get_all_Exons};
958 my $exon;
959  
960 while($exon = shift @exons) {
961 if($exon == $self->translation->start_Exon) {
962 #add the utr portion of the start exon
963 $start += $self->translation->start;
964 last;
965 } else {
966 #add the entire length of this non-coding exon
967 $start += $exon->length;
968 }
969 }
970  
971 # adjust cdna coords if sequence edits are enabled
972 if($self->edits_enabled()) {
973 my @seqeds = @{$self->get_all_SeqEdits()};
974 if (scalar @seqeds) {
975 my $transl_start = $self->get_all_Attributes('_transl_start');
976 if (@{$transl_start}) {
977 $start = $transl_start->[0]->value;
978 } else {
979 # sort in reverse order to avoid adjustment of downstream edits
980 @seqeds = sort {$b->start() <=> $a->start()} @seqeds;
981  
982 foreach my $se (@seqeds) {
983 # use less than start so that start of CDS can be extended
984 if($se->start() < $start) {
985 $start += $se->length_diff();
986 }
987 }
988 }
989 }
990 }
991  
992 $self->{'cdna_coding_start'} = $start;
993 }
994  
995 return $self->{'cdna_coding_start'};
996 }
997  
998  
999 =head2 cdna_coding_end
1000  
1001 Arg [1] : (optional) $value
1002 Example : $cdna_coding_end = $transcript->cdna_coding_end;
1003 Description: Retrieves the end of the coding region of this transcript in
1004 cdna coordinates (relative to the five prime end of the
1005 transcript, excluding introns, including utrs).
1006  
1007 This will return undef if this transcript is a pseudogene
1008 (i.e. a transcript with no translation and therefor no CDS).
1009 Returntype : int
1010 Exceptions : none
1011 Caller : general
1012 Status : Stable
1013  
1014 =cut
1015  
1016 sub cdna_coding_end {
1017 my $self = shift;
1018  
1019 if( @_ ) {
1020 $self->{'cdna_coding_end'} = shift;
1021 }
1022  
1023 if(!defined $self->{'cdna_coding_end'} && defined $self->translation) {
1024 my @exons = @{$self->get_all_Exons};
1025  
1026 my $end = 0;
1027 while(my $exon = shift @exons) {
1028 if($exon == $self->translation->end_Exon) {
1029 # add coding portion of the final coding exon
1030 $end += $self->translation->end;
1031 last;
1032 } else {
1033 # add entire exon
1034 $end += $exon->length;
1035 }
1036 }
1037  
1038 # adjust cdna coords if sequence edits are enabled
1039 if($self->edits_enabled()) {
1040 my @seqeds = @{$self->get_all_SeqEdits()};
1041 if (scalar @seqeds) {
1042 my $transl_end = $self->get_all_Attributes('_transl_end');
1043 if (@{$transl_end}) {
1044 $end = $transl_end->[0]->value;
1045 } else {
1046 # sort in reverse order to avoid adjustment of downstream edits
1047 @seqeds = sort {$b->start() <=> $a->start()} @seqeds;
1048  
1049 foreach my $se (@seqeds) {
1050 # use less than or equal to end+1 so end of the CDS can be extended
1051 if($se->start() <= $end + 1) {
1052 $end += $se->length_diff();
1053 }
1054 }
1055 }
1056 }
1057 }
1058  
1059 $self->{'cdna_coding_end'} = $end;
1060 }
1061  
1062 return $self->{'cdna_coding_end'};
1063 }
1064  
1065  
1066 =head2 coding_region_start
1067  
1068 Arg [1] : (optional) $value
1069 Example : $coding_region_start = $transcript->coding_region_start
1070 Description: Retrieves the start of the coding region of this transcript
1071 in genomic coordinates (i.e. in either slice or contig coords).
1072 By convention, the coding_region_start is always lower than
1073 the value returned by the coding_end method.
1074 The value returned by this function is NOT the biological
1075 coding start since on the reverse strand the biological coding
1076 start would be the higher genomic value.
1077  
1078 This function will return undef if this is a pseudogene
1079 (a non-translated transcript).
1080 Returntype : int
1081 Exceptions : none
1082 Caller : general
1083 Status : Stable
1084  
1085 =cut
1086  
1087 sub coding_region_start {
1088 my ($self, $value) = @_;
1089  
1090 if( defined $value ) {
1091 $self->{'coding_region_start'} = $value;
1092 } elsif(!defined $self->{'coding_region_start'} &&
1093 defined $self->translation) {
1094 #calculate the coding start from the translation
1095 my $start;
1096 my $strand = $self->translation()->start_Exon->strand();
1097 if( $strand == 1 ) {
1098 $start = $self->translation()->start_Exon->start();
1099 $start += ( $self->translation()->start() - 1 );
1100 } else {
1101 $start = $self->translation()->end_Exon->end();
1102 $start -= ( $self->translation()->end() - 1 );
1103 }
1104 $self->{'coding_region_start'} = $start;
1105 }
1106  
1107 return $self->{'coding_region_start'};
1108 }
1109  
1110  
1111 =head2 coding_region_end
1112  
1113 Arg [1] : (optional) $value
1114 Example : $coding_region_end = $transcript->coding_region_end
1115 Description: Retrieves the end of the coding region of this transcript
1116 in genomic coordinates (i.e. in either slice or contig coords).
1117 By convention, the coding_region_end is always higher than the
1118 value returned by the coding_region_start method.
1119 The value returned by this function is NOT the biological
1120 coding end since on the reverse strand the biological coding
1121 end would be the lower genomic value.
1122  
1123 This function will return undef if this is a pseudogene
1124 (a non-translated transcript).
1125 Returntype : int
1126 Exceptions : none
1127 Caller : general
1128 Status : Stable
1129  
1130 =cut
1131  
1132 sub coding_region_end {
1133 my ($self, $value ) = @_;
1134  
1135 my $strand;
1136 my $end;
1137  
1138 if( defined $value ) {
1139 $self->{'coding_region_end'} = $value;
1140 } elsif( ! defined $self->{'coding_region_end'}
1141 && defined $self->translation() ) {
1142 $strand = $self->translation()->start_Exon->strand();
1143 if( $strand == 1 ) {
1144 $end = $self->translation()->end_Exon->start();
1145 $end += ( $self->translation()->end() - 1 );
1146 } else {
1147 $end = $self->translation()->start_Exon->end();
1148 $end -= ( $self->translation()->start() - 1 );
1149 }
1150 $self->{'coding_region_end'} = $end;
1151 }
1152  
1153 return $self->{'coding_region_end'};
1154 }
1155  
1156  
1157 =head2 edits_enabled
1158  
1159 Arg [1] : (optional) boolean $newval
1160 Example : $transcript->edits_enabled(1);
1161 Description: Enables/Disables the application of SeqEdits to this transcript.
1162 Edits are enabled by default, and affect the cdna/mrna
1163 sequences coordinates and the resultant translation.
1164 Returntype : boolean - the current value of the edits
1165 Exceptions : none
1166 Caller : general, cdna_coding_start, cdna_coding_end, length
1167 Status : Stable
1168  
1169 =cut
1170  
1171 sub edits_enabled {
1172 my ( $self, $boolean ) = @_;
1173  
1174 if ( defined($boolean) ) {
1175 $self->{'edits_enabled'} = $boolean;
1176  
1177 # flush cached values that will be different with/without edits
1178 $self->{'cdna_coding_start'} = undef;
1179 $self->{'cdna_coding_end'} = undef;
1180 $self->{'transcript_mapper'} = undef;
1181 }
1182  
1183 return $self->{'edits_enabled'};
1184 }
1185  
1186  
1187 =head2 get_all_SeqEdits
1188  
1189 Arg [1] : none
1190 Example : my @seqeds = @{$transcript->get_all_SeqEdits()};
1191 Description: Retrieves all post transcriptional sequence modifications for
1192 this transcript.
1193 Returntype : Bio::EnsEMBL::SeqEdit
1194 Exceptions : none
1195 Caller : spliced_seq()
1196 Status : Stable
1197  
1198 =cut
1199  
1200 sub get_all_SeqEdits {
1201 my $self = shift;
1202  
1203 my @seqeds;
1204  
1205 my $attribs = $self->get_all_Attributes('_rna_edit');
1206  
1207 # convert attributes to SeqEdit objects
1208 foreach my $a (@$attribs) {
1209 push @seqeds, Bio::EnsEMBL::SeqEdit->new(-ATTRIB => $a);
1210 }
1211  
1212 return \@seqeds;
1213 }
1214  
1215  
1216 =head2 get_all_Attributes
1217  
1218 Arg [1] : optional string $attrib_code
1219 The code of the attribute type to retrieve values for.
1220 Example : ($rna_edits) = @{$transcript->get_all_Attributes('_rna_edit')};
1221 @transc_attributes = @{$transcript->get_all_Attributes()};
1222 Description: Gets a list of Attributes of this transcript.
1223 Optionally just get Attrubutes for given code.
1224 Returntype : listref Bio::EnsEMBL::Attribute
1225 Exceptions : warning if transcript does not have attached adaptor and
1226 attempts lazy load.
1227 Caller : general
1228 Status : Stable
1229  
1230 =cut
1231  
1232 sub get_all_Attributes {
1233 my $self = shift;
1234 my $attrib_code = shift;
1235  
1236 if( ! exists $self->{'attributes' } ) {
1237 if(!$self->adaptor() ) {
1238 return [];
1239 }
1240  
1241 my $attribute_adaptor = $self->adaptor->db->get_AttributeAdaptor();
1242 $self->{'attributes'} = $attribute_adaptor->fetch_all_by_Transcript($self);
1243 }
1244  
1245 if( defined $attrib_code) {
1246 my @results = grep { uc($_->code()) eq uc($attrib_code) }
1247 @{$self->{'attributes'}};
1248 return \@results;
1249 } else {
1250 return $self->{'attributes'};
1251 }
1252 }
1253  
1254  
1255 =head2 add_Attributes
1256  
1257 Arg [1...] : Bio::EnsEMBL::Attribute $attribute
1258 You can have more Attributes as arguments, all will be added.
1259 Example : $transcript->add_Attributes($rna_edit_attribute);
1260 Description: Adds an Attribute to the Transcript. Usefull to do _rna_edits.
1261 If you add an attribute before you retrieve any from database,
1262 lazy load will be disabled.
1263 Returntype : none
1264 Exceptions : throw on incorrect arguments
1265 Caller : general
1266 Status : Stable
1267  
1268 =cut
1269  
1270 sub add_Attributes {
1271 my ( $self, @attribs ) = @_;
1272  
1273 if ( !exists( $self->{'attributes'} ) ) {
1274 $self->{'attributes'} = [];
1275 }
1276  
1277 my $seq_change = 0;
1278 foreach my $attrib (@attribs) {
1279 assert_ref( $attrib, 'Bio::EnsEMBL::Attribute' );
1280  
1281 push( @{ $self->{'attributes'} }, $attrib );
1282  
1283 if ( $attrib->code() eq "_rna_edit" ) {
1284 $seq_change = 1;
1285 }
1286 }
1287  
1288 if ($seq_change) {
1289 my $translation = $self->translation();
1290 if ( defined($translation) ) {
1291 delete( $translation->{'seq'} );
1292 }
1293 }
1294  
1295 # flush cdna coord cache b/c we may have added a SeqEdit
1296 delete( $self->{'cdna_coding_start'} );
1297 delete( $self->{'cdna_coding_end'} );
1298 delete( $self->{'transcript_mapper'} );
1299 } ## end sub add_Attributes
1300  
1301  
1302 =head2 add_Exon
1303  
1304 Title : add_Exon
1305 Example : $trans->add_Exon($exon)
1306 Returns : None
1307 Args [1]: Bio::EnsEMBL::Exon object to add
1308 Args [2]: rank
1309 Exceptions: throws if not a valid Bio::EnsEMBL::Exon
1310 : or exon clashes with another one
1311 Status : Stable
1312  
1313 =cut
1314  
1315 sub add_Exon {
1316 my ( $self, $exon, $rank ) = @_;
1317  
1318 assert_ref( $exon, 'Bio::EnsEMBL::Exon' );
1319  
1320 $self->{'_trans_exon_array'} ||= [];
1321  
1322 if ( defined($rank) ) {
1323 $self->{'_trans_exon_array'}->[ $rank - 1 ] = $exon;
1324 return;
1325 }
1326  
1327 my $was_added = 0;
1328  
1329 my $ea = $self->{'_trans_exon_array'};
1330  
1331 if ( @{$ea} ) {
1332 if ( $exon->strand() == 1 ) {
1333  
1334 my $exon_start = $exon->start();
1335  
1336 if ( $exon_start > $ea->[-1]->end() ) {
1337 push( @{$ea}, $exon );
1338 $was_added = 1;
1339 } else {
1340 # Insert it at correct place
1341  
1342 my $i = 0;
1343 foreach my $e ( @{$ea} ) {
1344 if ( $exon_start < $e->start() ) {
1345 if ( $exon->end() >= $e->start() ) {
1346 # Overlap
1347 last;
1348 }
1349 if ( $i and $exon_start <= $ea->[$i-1]->end() ) {
1350 # Overlap
1351 last;
1352 }
1353 splice( @{$ea}, $i, 0, $exon );
1354 $was_added = 1;
1355 last;
1356 }
1357 ++$i;
1358 }
1359  
1360 }
1361  
1362 } else {
1363  
1364 my $exon_end = $exon->end();
1365  
1366 if ( $exon_end < $ea->[-1]->start() ) {
1367 push( @{$ea}, $exon );
1368 $was_added = 1;
1369 } else {
1370 # Insert it at correct place
1371  
1372 my $i = 0;
1373 foreach my $e ( @{$ea} ) {
1374 if ( $exon_end > $e->end() ) {
1375 if ( $exon->start() <= $e->end() ) {
1376 # Overlap
1377 last;
1378 }
1379 if ( $i and $exon_end >= $ea->[$i-1]->start() ) {
1380 # Overlap
1381 last;
1382 }
1383 splice( @{$ea}, $i, 0, $exon );
1384 $was_added = 1;
1385 last;
1386 }
1387 ++$i;
1388 }
1389  
1390 }
1391  
1392 } ## end else [ if ( $exon->strand() ==...)]
1393 } else {
1394 push( @{$ea}, $exon );
1395 $was_added = 1;
1396 }
1397  
1398 # sanity check:
1399 if ( !$was_added ) {
1400 # The exon was not added because it was overloapping with an
1401 # existing exon.
1402 my $all_str = '';
1403  
1404 foreach my $e ( @{$ea} ) {
1405 $all_str .= ' '
1406 . $e->start() . '-'
1407 . $e->end() . ' ('
1408 . $e->strand() . ') '
1409 . ( $e->stable_id() || '' ) . "\n";
1410 }
1411  
1412 my $cur_str = ' '
1413 . $exon->start() . '-'
1414 . $exon->end() . ' ('
1415 . $exon->strand() . ') '
1416 . ( $exon->stable_id() || '' ) . "\n";
1417  
1418 throw( "Exon overlaps with other exon in same transcript.\n"
1419 . "Transcript Exons:\n$all_str\n"
1420 . "This Exon:\n$cur_str" );
1421 }
1422  
1423 # recalculate start, end, slice, strand
1424 $self->recalculate_coordinates();
1425 } ## end sub add_Exon
1426  
1427  
1428 =head2 get_all_Exons
1429  
1430 Arg [1] : Boolean
1431 Only return constitutive exons if true (non-zero)
1432  
1433 Example : my @exons = @{ $transcript->get_all_Exons() };
1434 my @exons = @{ $transcript->get_all_Exons( -constitutive => 1 ) };
1435  
1436 Description: Returns an listref of the exons in this transcript
1437 in order, i.e. the first exon in the listref is the
1438 5prime most exon in the transcript. Only returns
1439 constitutive exons if the CONSTITUTIVE argument is
1440 true.
1441  
1442 Returntype : listref to Bio::EnsEMBL::Exon objects
1443 Exceptions : none
1444 Caller : general
1445 Status : Stable
1446  
1447 =cut
1448  
1449 sub get_all_Exons {
1450 my ( $self, @args ) = @_;
1451  
1452 my $constitutive;
1453 if (@args) {
1454 $constitutive = rearrange( ['CONSTITUTIVE'], @args );
1455 }
1456  
1457 if (!defined( $self->{'_trans_exon_array'} )
1458 && defined( $self->adaptor() ) )
1459 {
1460 $self->{'_trans_exon_array'} =
1461 $self->adaptor()->db()->get_ExonAdaptor()
1462 ->fetch_all_by_Transcript($self);
1463 }
1464  
1465 my @result;
1466 if ( defined($constitutive) && $constitutive != 0 ) {
1467 foreach my $exon ( @{ $self->{'_trans_exon_array'} } ) {
1468 if ( $exon->is_constitutive() ) {
1469 push( @result, $exon );
1470 }
1471 }
1472 } else {
1473 @result = @{ $self->{'_trans_exon_array'} };
1474 }
1475  
1476 return \@result;
1477 } ## end sub get_all_Exons
1478  
1479  
1480 =head2 get_all_ExonTranscripts
1481  
1482 Example : my @exon_transcripts = @{ $transcript->get_all_ExonTranscripts() };
1483  
1484 Description: Returns an listref of the exons in this transcript
1485 in order, i.e. the first exon in the listref is the
1486 5prime most exon in the transcript.
1487  
1488 Returntype : listref to Bio::EnsEMBL::ExonTranscript objects
1489 Exceptions : none
1490 Caller : general
1491 Status : Stable
1492  
1493 =cut
1494  
1495 sub get_all_ExonTranscripts {
1496 my ( $self, @args ) = @_;
1497  
1498 if (!defined( $self->{'_trans_exon_array'} )
1499 && defined( $self->adaptor() ) )
1500 {
1501 $self->{'_trans_exon_array'} =
1502 $self->adaptor()->db()->get_ExonAdaptor()
1503 ->fetch_all_by_Transcript($self);
1504 }
1505  
1506 my @result;
1507 my $i = 0;
1508 foreach my $exon ( @{ $self->{'_trans_exon_array'} } ) {
1509 $i++;
1510 my $exon_transcript = Bio::EnsEMBL::ExonTranscript->new(
1511 -EXON => $exon,
1512 -RANK => $i,
1513 -TRANSCRIPT => $self
1514 );
1515 push (@result, $exon_transcript) ;
1516 }
1517  
1518 return \@result;
1519 } ## end sub get_all_ExonTranscripts
1520  
1521 =head2 get_all_constitutive_Exons
1522  
1523 Arg : None
1524  
1525 Example : my @exons = @{ $transcript->get_all_constitutive_Exons() };
1526  
1527 Description: Returns an listref of the constitutive exons in this
1528 transcript in order, i.e. the first exon in the
1529 listref is the 5prime most exon in the transcript.
1530  
1531 Returntype : listref to Bio::EnsEMBL::Exon objects
1532 Exceptions : none
1533 Caller : general
1534 Status : Stable
1535  
1536 =cut
1537  
1538 sub get_all_constitutive_Exons {
1539 my ($self) = @_;
1540 return $self->get_all_Exons( '-constitutive' => 1 );
1541 }
1542  
1543 =head2 get_all_IntronSupportingEvidence
1544  
1545 Example : $ise->get_all_IntronSupportingEvidence();
1546 Description : Fetches all ISE instances linked to this Transript
1547 Returntype : ArrayRef[Bio::EnsEMBL::IntronSupportEvidence] retrieved from
1548 the DB or from those added via C<add_IntronSupportingEvidence>
1549 Exceptions : None
1550  
1551 =cut
1552  
1553 sub get_all_IntronSupportingEvidence {
1554 my ($self) = @_;
1555 if(! defined $self->{_ise_array} && defined $self->adaptor()) {
1556 my $isea = $self->adaptor()->db()->get_IntronSupportingEvidenceAdaptor();
1557 $self->{_ise_array} = $isea->fetch_all_by_Transcript($self);
1558 }
1559 return $self->{_ise_array} || [];
1560 }
1561  
1562  
1563 =head2 add_IntronSupportingEvidence
1564  
1565 Arg [1] : Bio::EnsEMBL::IntronSupportEvidence Object to add
1566 Example : $ise->add_IntronSupportingEvidence($ise);
1567 Description : Adds the IntronSupportEvidence instance to this Transcript. The
1568 code checks to see if it is a unique ISE instance
1569 Returntype : Boolean; true means it was added. False means it was not
1570 as this ISE was already attached
1571 Exceptions : None
1572  
1573 =cut
1574  
1575 sub add_IntronSupportingEvidence {
1576 my ($self, $ise) = @_;
1577 assert_ref($ise, 'Bio::EnsEMBL::IntronSupportingEvidence', 'IntronSupportingEvidence');
1578 my $unique = 1;
1579 foreach my $other_ise (@{$self->{_ise_array}}) {
1580 if($ise->equals($other_ise)) {
1581 $unique = 0;
1582 last;
1583 }
1584 }
1585 if($unique) {
1586 push(@{$self->{_ise_array}}, $ise);
1587 return 1;
1588 }
1589 return 0;
1590 }
1591  
1592 =head2 get_all_Introns
1593  
1594 Arg [1] : none
1595 Example : my @introns = @{$transcript->get_all_Introns()};
1596 Description: Returns an listref of the introns in this transcript in order.
1597 i.e. the first intron in the listref is the 5prime most exon in
1598 the transcript.
1599 Returntype : listref to Bio::EnsEMBL::Intron objects
1600 Exceptions : none
1601 Caller : general
1602 Status : Stable
1603  
1604 =cut
1605  
1606 sub get_all_Introns {
1607 my ($self) = @_;
1608 if( ! defined $self->{'_trans_exon_array'} && defined $self->adaptor() ) {
1609 $self->{'_trans_exon_array'} = $self->adaptor()->db()->
1610 get_ExonAdaptor()->fetch_all_by_Transcript( $self );
1611 }
1612  
1613 my @introns=();
1614 my @exons = @{$self->{'_trans_exon_array'}};
1615 for(my $i=0; $i < scalar(@exons)-1; $i++){
1616 my $intron = new Bio::EnsEMBL::Intron($exons[$i],$exons[$i+1]);
1617 push(@introns, $intron)
1618 }
1619 return \@introns;
1620 }
1621  
1622 =head2 get_all_CDS_Introns
1623  
1624 Arg [1] : none
1625 Example : my @introns = @{$transcript->get_all_CDS_Introns()};
1626 Description: Returns an listref of the introns between coding exons in this transcript in order.
1627 Returntype : listref to Bio::EnsEMBL::Intron objects
1628 Exceptions : none
1629 Caller : general
1630 Status : Stable
1631  
1632 =cut
1633  
1634 sub get_all_CDS_Introns {
1635 my ($self) = @_;
1636 # return an empty list if there is no translation
1637 my $translation = $self->translation or return [];
1638 if( ! defined $self->{'_trans_exon_array'} && defined $self->adaptor() ) {
1639 $self->{'_trans_exon_array'} = $self->adaptor()->db()->
1640 get_ExonAdaptor()->fetch_all_by_Transcript( $self );
1641 }
1642  
1643 my @introns=();
1644 my @exons = @{$self->{'_trans_exon_array'}};
1645 for(my $i=0; $i < scalar(@exons)-1; $i++){
1646 if (!$exons[$i]->is_coding($self)) { next; }
1647 my $intron = new Bio::EnsEMBL::Intron($exons[$i],$exons[$i+1]);
1648 push(@introns, $intron)
1649 }
1650 return \@introns;
1651 }
1652  
1653  
1654 =head2 length
1655  
1656 Args : none
1657 Example : my $t_length = $transcript->length
1658 Description: Returns the sum of the length of all the exons in the transcript.
1659 Returntype : int
1660 Exceptions : none
1661 Caller : general
1662 Status : Stable
1663  
1664 =cut
1665  
1666 sub length {
1667 my( $self ) = @_;
1668  
1669 my $length = 0;
1670 foreach my $ex (@{$self->get_all_Exons}) {
1671 $length += $ex->length;
1672 }
1673  
1674 # adjust the length if post transcriptional edits are enabled
1675 if($self->edits_enabled()) {
1676 foreach my $se (@{$self->get_all_SeqEdits()}) {
1677 $length += $se->length_diff();
1678 }
1679 }
1680  
1681 return $length;
1682 }
1683  
1684  
1685 =head2 flush_Exons
1686  
1687 Arg [1] : none
1688 Example : $transcript->flush_Exons();
1689 Description: Removes all Exons from this transcript and flushes related
1690 internal caches.
1691 Returntype : none
1692 Exceptions : none
1693 Caller : general
1694 Status : Stable
1695  
1696 =cut
1697  
1698 sub flush_Exons {
1699 my ($self) = @_;
1700  
1701 $self->{'transcript_mapper'} = undef;
1702 $self->{'coding_region_start'} = undef;
1703 $self->{'coding_region_end'} = undef;
1704 $self->{'cdna_coding_start'} = undef;
1705 $self->{'cdna_coding_end'} = undef;
1706 $self->{'start'} = undef;
1707 $self->{'end'} = undef;
1708 $self->{'strand'} = undef;
1709  
1710 $self->{'_trans_exon_array'} = [];
1711 }
1712  
1713 =head2 flush_IntronSupportingEvidence
1714  
1715 Example : $transcript->flush_IntronSupportingEvidence();
1716 Description: Removes all IntronSupportingEvidence from this transcript
1717 Returntype : none
1718 Exceptions : none
1719 Caller : general
1720 Status : Stable
1721  
1722 =cut
1723  
1724 sub flush_IntronSupportingEvidence {
1725 my ($self) = @_;
1726 $self->{_ise_array} = [];
1727 return;
1728 }
1729  
1730 =head2 five_prime_utr
1731  
1732 Arg [1] : none
1733 Example : my $five_prime = $transcrpt->five_prime_utr
1734 or warn "No five prime UTR";
1735 Description: Obtains a Bio::Seq object of the five prime UTR of this
1736 transcript. If this transcript is a pseudogene
1737 (i.e. non-translating) or has no five prime UTR undef is
1738 returned instead.
1739 Returntype : Bio::Seq or undef
1740 Exceptions : none
1741 Caller : general
1742 Status : Stable
1743  
1744 =cut
1745  
1746 sub five_prime_utr {
1747 my $self = shift;
1748  
1749 my $cdna_coding_start = $self->cdna_coding_start();
1750  
1751 return undef if(!$cdna_coding_start);
1752  
1753 my $seq = substr($self->spliced_seq, 0, $cdna_coding_start - 1);
1754  
1755 return undef if(!$seq);
1756  
1757 return
1758 Bio::Seq->new( -id => $self->display_id,
1759 -moltype => 'dna',
1760 -alphabet => 'dna',
1761 -seq => $seq );
1762 }
1763  
1764  
1765 =head2 three_prime_utr
1766  
1767 Arg [1] : none
1768 Example : my $three_prime = $transcrpt->three_prime_utr
1769 or warn "No three prime UTR";
1770 Description: Obtains a Bio::Seq object of the three prime UTR of this
1771 transcript. If this transcript is a pseudogene
1772 (i.e. non-translating) or has no three prime UTR,
1773 undef is returned instead.
1774 Returntype : Bio::Seq or undef
1775 Exceptions : none
1776 Caller : general
1777 Status : Stable
1778  
1779 =cut
1780  
1781 sub three_prime_utr {
1782 my $self = shift;
1783  
1784 my $cdna_coding_end = $self->cdna_coding_end();
1785  
1786 return undef if(!$cdna_coding_end);
1787  
1788 my $seq = substr($self->spliced_seq, $cdna_coding_end);
1789  
1790 return undef if(!$seq);
1791  
1792 return
1793 Bio::Seq->new( -id => $self->display_id,
1794 -moltype => 'dna',
1795 -alphabet => 'dna',
1796 -seq => $seq );
1797 }
1798  
1799 =head2 five_prime_utr_Feature
1800  
1801 Example : my $five_prime = $transcrpt->five_prime_utr_Feature
1802 or warn "No five prime UTR";
1803 Description: Returns the genomic coordinates of the start and end of the
1804 5' UTR of this transcript. Note that if you want the sequence
1805 of the 5' UTR use C<five_prime_utr> as this will return the
1806 sequence from the spliced transcript.
1807 Returntype : Bio::EnsEMBL::Feature or undef if there is no UTR
1808 Exceptions : none
1809  
1810 =cut
1811  
1812 sub five_prime_utr_Feature {
1813 my ($self) = @_;
1814 my $start = $self->seq_region_end();
1815 my $end = 0;
1816 my $features = $self->get_all_five_prime_UTRs();
1817 if (scalar(@$features) == 0) { return; }
1818 foreach my $feature (@$features) {
1819 if ($feature->start() < $start) {
1820 $start = $feature->start();
1821 }
1822 if ($feature->end() > $end) {
1823 $end = $feature->end();
1824 }
1825 }
1826 my $feature = Bio::EnsEMBL::Feature->new(
1827 -START => $start,
1828 -END => $end,
1829 -STRAND => $self->strand(),
1830 -SLICE => $self->slice(),
1831 -TYPE => 'five_prime_UTR',
1832 -TRANSCRIPT => $self
1833 );
1834 return $feature;
1835 }
1836  
1837  
1838  
1839 =head2 three_prime_utr_Feature
1840  
1841 Example : my $five_prime = $transcrpt->three_prime_utr_Feature
1842 or warn "No three prime UTR";
1843 Description: Returns the genomic coordinates of the start and end of the
1844 3' UTR of this transcript. Note that if you want the sequence
1845 of the 3' UTR use C<three_prime_utr> as this will return the
1846 sequence from the spliced transcript.
1847 Returntype : Bio::EnsEMBL::Feature or undef if there is no UTR
1848 Exceptions : none
1849  
1850 =cut
1851  
1852 sub three_prime_utr_Feature {
1853 my ($self) = @_;
1854 my $start = $self->seq_region_end();
1855 my $end = 0;
1856 my $features = $self->get_all_three_prime_UTRs();
1857 if (scalar(@$features) == 0) { return; }
1858 foreach my $feature (@$features) {
1859 if ($feature->start() < $start) {
1860 $start = $feature->start();
1861 }
1862 if ($feature->end() > $end) {
1863 $end = $feature->end();
1864 }
1865 }
1866 my $feature = Bio::EnsEMBL::Feature->new(
1867 -START => $start,
1868 -END => $end,
1869 -STRAND => $self->strand(),
1870 -SLICE => $self->slice(),
1871 -TYPE => 'three_prime_UTR',
1872 -TRANSCRIPT => $self
1873 );
1874 return $feature;
1875 }
1876  
1877  
1878 =head2 get_all_five_prime_UTRs
1879  
1880 Example : my $five_primes = $transcript->get_all_five_prime_UTRs
1881 Description: Returns a list of features forming the 5' UTR of this transcript.
1882 Returntype : listref of Bio::EnsEMBL::UTR
1883 Exceptions : none
1884  
1885 =cut
1886  
1887 sub get_all_five_prime_UTRs {
1888 my ($self) = @_;
1889 my $translation = $self->translation();
1890 return [] if ! $translation;
1891  
1892 my @utrs;
1893  
1894 my $cdna_coding_start = $self->cdna_coding_start();
1895  
1896 # if it is greater than 1 then it must have UTR
1897 if($cdna_coding_start > 1) {
1898 my @projections = $self->cdna2genomic(1, ($cdna_coding_start-1));
1899 foreach my $projection (@projections) {
1900 next if $projection->isa('Bio::EnsEMBL::Mapper::Gap');
1901 my $utr = Bio::EnsEMBL::UTR->new(
1902 -START => $projection->start - $self->slice->start + 1,
1903 -END => $projection->end - $self->slice->start + 1,
1904 -SEQ_REGION_START => $projection->start,
1905 -SEQ_REGION_END => $projection->end,
1906 -STRAND => $projection->strand,
1907 -SLICE => $self->slice,
1908 -TRANSCRIPT => $self,
1909 -TYPE => 'five_prime_utr'
1910 );
1911 push(@utrs, $utr);
1912 }
1913 }
1914  
1915 return \@utrs;
1916 }
1917  
1918  
1919 =head2 get_all_three_prime_UTRs
1920  
1921 Example : my $three_primes = $transcript->get_all_three_prime_UTRs
1922 Description: Returns a list of features forming the 3' UTR of this transcript.
1923 Returntype : listref of Bio::EnsEMBL::UTR
1924 Exceptions : none
1925  
1926 =cut
1927  
1928 sub get_all_three_prime_UTRs {
1929 my ($self) = @_;
1930 my $translation = $self->translation();
1931 return [] if ! $translation;
1932  
1933 my @utrs;
1934  
1935 my $cdna_coding_end = $self->cdna_coding_end();
1936 if($cdna_coding_end < $self->length()) {
1937 my @projections = $self->cdna2genomic(($cdna_coding_end+1), $self->length());
1938 foreach my $projection (@projections) {
1939 next if $projection->isa('Bio::EnsEMBL::Mapper::Gap');
1940 my $utr = Bio::EnsEMBL::UTR->new(
1941 -START => $projection->start - $self->slice->start + 1,
1942 -END => $projection->end - $self->slice->start + 1,
1943 -SEQ_REGION_START => $projection->start,
1944 -SEQ_REGION_END => $projection->end,
1945 -STRAND => $projection->strand,
1946 -SLICE => $self->slice,
1947 -TRANSCRIPT => $self,
1948 -TYPE => 'three_prime_utr'
1949 );
1950 push(@utrs, $utr);
1951 }
1952 }
1953  
1954 return \@utrs;
1955 }
1956  
1957 =head2 get_all_CDS
1958  
1959 Example : my $cds = $transcript->get_all_CDS
1960 Description: Returns a list of features forming the coding regions of the transcript
1961 Returntype : listref of Bio::EnsEMBL::CDS
1962 Exceptions : none
1963  
1964 =cut
1965  
1966 sub get_all_CDS {
1967 my ($self) = @_;
1968 my $translation = $self->translation();
1969 return [] if ! $translation;
1970  
1971 my @cds;
1972 my $translation_id = $translation->stable_id();
1973  
1974 foreach my $exon (@{ $self->get_all_translateable_Exons}) {
1975 my $phase = $exon->phase();
1976 $phase = 0 if $phase < 0;
1977 $phase =~ tr/12/21/;
1978  
1979 my $cds = Bio::EnsEMBL::CDS->new(
1980 -START => $exon->start,
1981 -END => $exon->end,
1982 -STRAND => $exon->strand,
1983 -SEQ_REGION_START => $exon->seq_region_start,
1984 -SEQ_REGION_END => $exon->seq_region_end,
1985 -TRANSLATION_ID => $translation_id,
1986 -SLICE => $self->slice,
1987 -TRANSCRIPT => $self,
1988 -PHASE => $phase
1989 );
1990 push(@cds, $cds);
1991 }
1992  
1993 return \@cds;
1994 }
1995  
1996  
1997  
1998 =head2 get_all_translateable_Exons
1999  
2000 Args : none
2001 Description: Returns a list of exons that translate with the
2002 start and end exons truncated to the CDS regions.
2003 This function does not take into account any SeqEdits
2004 (post transcriptional RNA modifictions) when constructing the
2005 the 'translateable' exons, and it does not update the phase
2006 information of the created 'translateable' exons.
2007  
2008 If this transcript is a pseudogene (i.e. non-translateable)
2009 a reference to an empty list is returned.
2010  
2011 Returntype : listref Bio::EnsEMBL::Exon
2012 Exceptions : throw if translation has invalid information
2013 Caller : Genebuild
2014 Status : Stable
2015  
2016 =cut
2017  
2018  
2019 sub get_all_translateable_Exons {
2020 my ( $self ) = @_;
2021  
2022 #return an empty list if there is no translation (i.e. pseudogene)
2023 my $translation = $self->translation or return [];
2024 my $start_exon = $translation->start_Exon;
2025 my $end_exon = $translation->end_Exon;
2026 my $t_start = $translation->start;
2027 my $t_end = $translation->end;
2028  
2029 my( @translateable );
2030  
2031 foreach my $ex (@{$self->get_all_Exons}) {
2032  
2033 if ($ex ne $start_exon and ! @translateable) {
2034 next; # Not yet in translated region
2035 }
2036  
2037 my $length = $ex->length;
2038  
2039 my $adjust_start = 0;
2040 my $adjust_end = 0;
2041 # Adjust to translation start if this is the start exon
2042 if ($ex == $start_exon ) {
2043 if ($t_start < 1 or $t_start > $length) {
2044 warning("WARN: Translation start '$t_start' is outside exon " . $ex->display_id . " length=$length");
2045 return [];
2046 }
2047 $adjust_start = $t_start - 1;
2048 }
2049  
2050 # Adjust to translation end if this is the end exon
2051 if ($ex == $end_exon) {
2052 # if ($t_end < 1 or $t_end > $length) {
2053 # throw("Translation end '$t_end' is outside exon $ex length=$length");
2054 # }
2055 $adjust_end = $t_end - $length;
2056 }
2057  
2058 # Make a truncated exon if the translation start or
2059 # end causes the coordinates to be altered.
2060 if ($adjust_end || $adjust_start) {
2061 my $newex = $ex->adjust_start_end( $adjust_start, $adjust_end );
2062  
2063 push( @translateable, $newex );
2064 } else {
2065 push(@translateable, $ex);
2066 }
2067  
2068 # Exit the loop when we've found the last exon
2069 last if $ex eq $end_exon;
2070 }
2071 return \@translateable;
2072 }
2073  
2074  
2075 =head2 translate
2076  
2077 Arg [1] : Boolean, emulate the behavior of old bioperl versions where
2078 an incomplete final codon of 2 characters is padded and guessed
2079 Example : none
2080 Description: Return the peptide (plus eventual stop codon) for
2081 this transcript. Does N-padding of non-phase
2082 matching exons. It uses translateable_seq
2083 internally. Returns undef if this Transcript does
2084 not have a translation (i.e. pseudogene).
2085 Returntype : Bio::Seq or undef
2086 Exceptions : none
2087 Caller : general
2088 Status : Stable
2089  
2090 =cut
2091  
2092 sub translate {
2093 my ($self, $complete_codon) = @_;
2094  
2095 if ( !defined( $self->translation() ) ) { return undef }
2096  
2097 my $mrna = $self->translateable_seq();
2098  
2099 # Alternative codon tables (such as the mitochondrial codon table)
2100 # can be specified for a sequence region via the seq_region_attrib
2101 # table. A list of codon tables and their codes is at:
2102 # http://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi
2103  
2104 my $codon_table_id;
2105 my ( $complete5, $complete3 );
2106 if ( defined( $self->slice() ) ) {
2107 my $attrib;
2108  
2109 ($attrib) = @{ $self->slice()->get_all_Attributes('codon_table') };
2110 if ( defined($attrib) ) {
2111 $codon_table_id = $attrib->value();
2112 }
2113  
2114 ($attrib) = @{ $self->slice()->get_all_Attributes('complete5') };
2115 if ( defined($attrib) ) {
2116 $complete5 = $attrib->value();
2117 }
2118  
2119 ($attrib) = @{ $self->slice()->get_all_Attributes('complete3') };
2120 if ( defined($attrib) ) {
2121 $complete3 = $attrib->value();
2122 }
2123 }
2124 $codon_table_id ||= 1; # default vertebrate codon table
2125  
2126 # Remove final stop codon from the mrna if it is present. Produced
2127 # peptides will not have '*' at end. If terminal stop codon is
2128 # desired call translatable_seq directly and produce a translation
2129 # from it.
2130  
2131 if ( CORE::length($mrna) % 3 == 0 ) {
2132 my $codon_table =
2133 Bio::Tools::CodonTable->new( -id => $codon_table_id );
2134  
2135 if ( $codon_table->is_ter_codon( substr( $mrna, -3, 3 ) ) ) {
2136 substr( $mrna, -3, 3, '' );
2137 }
2138 } elsif ( CORE::length($mrna) % 3 == 2 ) {
2139 # If we have a partial codon of 2 bp we need to decide if we
2140 # trim it or not to fix some bad behaviour in older bioperl
2141 # versions
2142 if ( $complete_codon ) {
2143 # If we want to do the bad behavior of bioperl 1.6.1 and older
2144 # where we guess the last codon if inomplete, pad an N
2145 # to the mrna sequence
2146 $mrna .= 'N';
2147 } else {
2148 # Otherwise trim those last two bp off so the behavior is
2149 # consistent across bioperl versions
2150 substr( $mrna, -2, 2, '' );
2151 }
2152 }
2153  
2154 if ( CORE::length($mrna) < 1 ) { return undef }
2155  
2156 my $display_id = $self->translation->display_id()
2157 || "" . $self->translation();
2158  
2159 my $peptide = Bio::Seq->new( -seq => $mrna,
2160 -moltype => 'dna',
2161 -alphabet => 'dna',
2162 -id => $display_id );
2163  
2164 my $translation =
2165 $peptide->translate( undef, undef, undef, $codon_table_id, undef,
2166 undef, $complete5, $complete3 );
2167  
2168 if ( $self->edits_enabled() ) {
2169 $self->translation()->modify_translation($translation);
2170 }
2171  
2172 return $translation;
2173 } ## end sub translate
2174  
2175  
2176 =head2 seq
2177  
2178 Description: Returns a Bio::Seq object which consists of just
2179 : the sequence of the exons concatenated together,
2180 : without messing about with padding with N\'s from
2181 : Exon phases like B<dna_seq> does.
2182 Args : none
2183 Example : none
2184 Returntype : Bio::Seq
2185 Exceptions : none
2186 Caller : general
2187 Status : Stable
2188  
2189 =cut
2190  
2191 sub seq {
2192 my ($self) = @_;
2193  
2194 return
2195 Bio::Seq->new( -id => $self->display_id,
2196 -moltype => 'dna',
2197 -alphabet => 'dna',
2198 -seq => $self->spliced_seq );
2199 }
2200  
2201  
2202 =head2 pep2genomic
2203  
2204 Description: See Bio::EnsEMBL::TranscriptMapper::pep2genomic
2205  
2206 =cut
2207  
2208 sub pep2genomic {
2209 my $self = shift;
2210 return $self->get_TranscriptMapper()->pep2genomic(@_);
2211 }
2212  
2213  
2214 =head2 genomic2pep
2215  
2216 Description: See Bio::EnsEMBL::TranscriptMapper::genomic2pep
2217  
2218 =cut
2219  
2220 sub genomic2pep {
2221 my $self = shift;
2222 return $self->get_TranscriptMapper()->genomic2pep(@_);
2223 }
2224  
2225  
2226 =head2 cdna2genomic
2227  
2228 Description: See Bio::EnsEMBL::TranscriptMapper::cdna2genomic
2229  
2230 =cut
2231  
2232 sub cdna2genomic {
2233 my $self = shift;
2234 return $self->get_TranscriptMapper()->cdna2genomic(@_);
2235 }
2236  
2237  
2238 =head2 genomic2cdna
2239  
2240 Description: See Bio::EnsEMBL::TranscriptMapper::genomic2cdna
2241  
2242 =cut
2243  
2244 sub genomic2cdna {
2245 my $self = shift;
2246 return $self->get_TranscriptMapper->genomic2cdna(@_);
2247 }
2248  
2249  
2250 =head2 get_TranscriptMapper
2251  
2252 Args : none
2253 Example : my $trans_mapper = $transcript->get_TranscriptMapper();
2254 Description: Gets a TranscriptMapper object which can be used to perform
2255 a variety of coordinate conversions relating this transcript,
2256 genomic sequence and peptide resulting from this transcripts
2257 translation.
2258 Returntype : Bio::EnsEMBL::TranscriptMapper
2259 Exceptions : none
2260 Caller : cdna2genomic, pep2genomic, genomic2cdna, cdna2genomic
2261 Status : Stable
2262  
2263 =cut
2264  
2265 sub get_TranscriptMapper {
2266 my ( $self ) = @_;
2267 return $self->{'transcript_mapper'} ||=
2268 Bio::EnsEMBL::TranscriptMapper->new($self);
2269 }
2270  
2271  
2272 =head2 start_Exon
2273  
2274 Title : start_Exon
2275 Usage : $start_exon = $transcript->start_Exon;
2276 Returntype : Bio::EnsEMBL::Exon
2277 Description : The first exon in the transcript.
2278 Args : NONE
2279 Status : Stable
2280  
2281 =cut
2282  
2283 sub start_Exon {
2284 my $self = shift;
2285 return $self->get_all_Exons()->[0];
2286 }
2287  
2288  
2289 =head2 end_Exon
2290  
2291 Title : end_exon
2292 Usage : $end_exon = $transcript->end_Exon;
2293 Description : The last exon in the transcript.
2294 Returntype : Bio::EnsEMBL::Exon
2295 Args : NONE
2296 Status : Stable
2297  
2298 =cut
2299  
2300 sub end_Exon {
2301 my $self = shift;
2302 return $self->get_all_Exons()->[-1];
2303 }
2304  
2305  
2306 =head2 description
2307  
2308 Title : description
2309 Usage : $obj->description($newval)
2310 Function:
2311 Returns : String
2312 Args : newvalue (optional)
2313 Status : Stable
2314  
2315 =cut
2316  
2317 sub description {
2318 my $self = shift;
2319 $self->{'description'} = shift if( @_ );
2320 return $self->{'description'};
2321 }
2322  
2323  
2324 =head2 version
2325  
2326 Title : version
2327 Usage : $obj->version()
2328 Function:
2329 Returns : String
2330 Args :
2331 Status : Stable
2332  
2333 =cut
2334  
2335 sub version {
2336 my $self = shift;
2337 $self->{'version'} = shift if( @_ );
2338 return $self->{'version'};
2339 }
2340  
2341 =head2 stable_id
2342  
2343 Title : stable_id
2344 Usage : $obj->stable_id
2345 Function:
2346 Returns : String
2347 Args :
2348 Status : Stable
2349  
2350 =cut
2351  
2352 sub stable_id {
2353 my $self = shift;
2354 $self->{'stable_id'} = shift if( @_ );
2355 return $self->{'stable_id'};
2356 }
2357  
2358 =head2 stable_id_version
2359  
2360 Arg [1] : (optional) String - the stable ID with version to set
2361 Example : $transcript->stable_id("ENST0000000001.3");
2362 Description: Getter/setter for stable id with version for this transcript.
2363 Returntype : String
2364 Exceptions : none
2365 Caller : general
2366 Status : Stable
2367  
2368 =cut
2369  
2370 sub stable_id_version {
2371 my $self = shift;
2372 if(my $stable_id = shift) {
2373 # See if there's an embedded period, assume that's a
2374 # version, might not work for some species but you
2375 # should use ->stable_id() and version() if you're worried
2376 # about ambiguity
2377 my $vindex = rindex($stable_id, '.');
2378 # Set the stable_id and version pair depending on if
2379 # we found a version delimiter in the stable_id
2380 ($self->{stable_id}, $self->{version}) = ($vindex > 0 ?
2381 (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) :
2382 $stable_id, undef);
2383 }
2384 return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : '');
2385 }
2386  
2387 =head2 is_current
2388  
2389 Arg [1] : Boolean $is_current
2390 Example : $transcript->is_current(1)
2391 Description: Getter/setter for is_current state of this transcript.
2392 Returntype : Int
2393 Exceptions : none
2394 Caller : general
2395 Status : Stable
2396  
2397 =cut
2398  
2399 sub is_current {
2400 my $self = shift;
2401 $self->{'is_current'} = shift if (@_);
2402 return $self->{'is_current'};
2403 }
2404  
2405  
2406 =head2 created_date
2407  
2408 Arg [1] : (optional) string to be used for the created date
2409 Example : none
2410 Description: get/set for attribute created date
2411 Returntype : string
2412 Exceptions : none
2413 Caller : general
2414 Status : Stable
2415  
2416 =cut
2417  
2418 sub created_date {
2419 my $self = shift;
2420 $self->{'created_date'} = shift if ( @_ );
2421 return $self->{'created_date'};
2422 }
2423  
2424  
2425 =head2 modified_date
2426  
2427 Arg [1] : (optional) string to be used for the modified date
2428 Example : none
2429 Description: get/set for attribute modified date
2430 Returntype : string
2431 Exceptions : none
2432 Caller : general
2433 Status : Stable
2434  
2435 =cut
2436  
2437 sub modified_date {
2438 my $self = shift;
2439 $self->{'modified_date'} = shift if ( @_ );
2440 return $self->{'modified_date'};
2441 }
2442  
2443  
2444 =head2 swap_exons
2445  
2446 Arg [1] : Bio::EnsEMBL::Exon $old_Exon
2447 An exon that should be replaced
2448 Arg [2] : Bio::EnsEMBL::Exon $new_Exon
2449 The replacement Exon
2450 Example : none
2451 Description: exchange an exon in the current Exon list with a given one.
2452 Usually done before storing of Gene, so the Exons can
2453 be shared between Transcripts.
2454 Returntype : none
2455 Exceptions : none
2456 Caller : GeneAdaptor->store()
2457 Status : Stable
2458  
2459 =cut
2460  
2461 sub swap_exons {
2462 my ( $self, $old_exon, $new_exon, $skip_exon_sf) = @_;
2463
2464 my $arref = $self->{'_trans_exon_array'};
2465 for(my $i = 0; $i < @$arref; $i++) {
2466 if($arref->[$i] == $old_exon ) {
2467 $new_exon->add_supporting_features(@{$old_exon->get_all_supporting_features}) unless $skip_exon_sf;
2468 $arref->[$i] = $new_exon;
2469 last;
2470 }
2471 }
2472  
2473 if( defined $self->{'translation'} ) {
2474 if( $self->translation()->start_Exon() == $old_exon ) {
2475 $self->translation()->start_Exon( $new_exon );
2476 }
2477 if( $self->translation()->end_Exon() == $old_exon ) {
2478 $self->translation()->end_Exon( $new_exon );
2479 }
2480 }
2481 }
2482  
2483 =head2 exon_rank
2484  
2485 Arg [1] : Bio::EnsEMBL::Exon $Exon
2486 Query exon
2487 Example : $rank = $transcript->exon_rank($exon);
2488 Description: Returns the rank of an exon relative to the transcript
2489 Returntype : none
2490 Exceptions : Throws if the exon does not belong to the transcript
2491 Caller : General
2492 Status : Stable
2493  
2494 =cut
2495  
2496 sub exon_rank {
2497 my ( $self, $exon ) = @_;
2498  
2499 if (!defined( $self->{'_trans_exon_array'} )
2500 && defined( $self->adaptor() ) )
2501 {
2502 $self->{'_trans_exon_array'} =
2503 $self->adaptor()->db()->get_ExonAdaptor()
2504 ->fetch_all_by_Transcript($self);
2505 }
2506  
2507 my $arref = $self->{'_trans_exon_array'};
2508 my $rank;
2509  
2510 if (!defined $arref) {
2511 throw "Transcript does not have any exons";
2512 }
2513 for(my $i = 0; $i < @$arref; $i++) {
2514 if($arref->[$i]->stable_id() eq $exon->stable_id()) {
2515 $rank = $i+1;
2516 last;
2517 }
2518 }
2519  
2520 if (!defined $rank) {
2521 throw "Exon does not belong to transcript";
2522 }
2523  
2524 return $rank;
2525 }
2526  
2527  
2528 =head2 equals
2529  
2530 Arg [1] : Bio::EnsEMBL::Transcript transcript
2531 Example : if ($transcriptA->equals($transcriptB)) { ... }
2532 Description : Compares two transcripts for equality.
2533 The test for eqality goes through the following list
2534 and terminates at the first true match:
2535  
2536 1. If Bio::EnsEMBL::Feature::equals() returns false,
2537 then the transcripts are *not* equal.
2538 2. If the biotypes differ, then the transcripts are
2539 *not* equal.
2540 3. If both transcripts have stable IDs: if these are
2541 the same, the transcripts are equal, otherwise not.
2542 4. If both transcripts have the same number of exons
2543 and if these are (when compared pair-wise sorted by
2544 start-position and length) the same, then they are
2545 equal, otherwise not.
2546  
2547 Return type : Boolean (0, 1)
2548  
2549 Exceptions : Thrown if a non-transcript is passed as the argument.
2550  
2551 =cut
2552  
2553 sub equals {
2554 my ( $self, $transcript ) = @_;
2555  
2556 if ( !defined($transcript) ) { return 0 }
2557 if ( $self eq $transcript ) { return 1 }
2558  
2559 assert_ref( $transcript, 'Bio::EnsEMBL::Transcript' );
2560  
2561 my $feature_equals = $self->SUPER::equals($transcript);
2562 if ( defined($feature_equals) && $feature_equals == 0 ) {
2563 return 0;
2564 }
2565  
2566 if ( $self->get_Biotype->name ne $transcript->get_Biotype->name ) {
2567 return 0;
2568 }
2569  
2570 if ( defined( $self->stable_id() ) &&
2571 defined( $transcript->stable_id() ) )
2572 {
2573 if ( $self->stable_id() eq $transcript->stable_id() ) {
2574 return 1;
2575 }
2576 else {
2577 return 0;
2578 }
2579 }
2580  
2581 my @self_exons = sort {
2582 $a->start() <=> $b->start() ||
2583 $a->length() <=> $b->length()
2584 } @{ $self->get_all_Exons() };
2585 my @transcript_exons = sort {
2586 $a->start() <=> $b->start() ||
2587 $a->length() <=> $b->length()
2588 } @{ $transcript->get_all_Exons() };
2589  
2590 if ( scalar(@self_exons) != scalar(@transcript_exons) ) {
2591 return 0;
2592 }
2593  
2594 while (@self_exons) {
2595 my $self_exon = shift(@self_exons);
2596 my $transcript_exon = shift(@transcript_exons);
2597  
2598 if ( !$self_exon->equals($transcript_exon) ) {
2599 return 0;
2600 }
2601 }
2602  
2603 return 1;
2604 } ## end sub equals
2605  
2606 =head2 transform
2607  
2608 Arg 1 : String $coordinate_system_name
2609 Arg [2] : String $coordinate_system_version
2610 Example : $transcript = $transcript->transform('contig');
2611 $transcript = $transcript->transform('chromosome', 'NCBI33');
2612 Description: Moves this Transcript to the given coordinate system.
2613 If this Transcript has Exons attached, they move as well.
2614 A new Transcript is returned. If the transcript cannot be
2615 transformed to the destination coordinate system undef is
2616 returned instead.
2617 Returntype : Bio::EnsEMBL::Transcript
2618 Exceptions : wrong parameters
2619 Caller : general
2620 Status : Medium Risk
2621 : deprecation needs to be removed at some time
2622  
2623 =cut
2624  
2625  
2626 sub transform {
2627 my $self = shift;
2628  
2629 my $new_transcript = $self->SUPER::transform(@_);
2630 if ( !defined($new_transcript) ) {
2631 my @segments = @{ $self->project(@_) };
2632 # if it projects, maybe the exons transform well?
2633 # lazy load them here
2634 if ( !@segments ) {
2635 return undef;
2636 }
2637 $self->get_all_Exons();
2638 }
2639  
2640  
2641 if( exists $self->{'_trans_exon_array'} ) {
2642 my @new_exons;
2643 my ( $low_start, $hi_end, $slice );
2644 # we want to check whether the transform preserved 5prime 3prime
2645 # ordering. This assumes 5->3 order. No complaints on transsplicing.
2646  
2647 my ( $last_new_start, $last_old_strand,
2648 $last_new_strand, $start_exon, $end_exon,
2649 $last_seq_region_name );
2650 my $first = 1;
2651 my $ignore_order = 0;
2652 my $order_broken = 0;
2653  
2654 for my $old_exon ( @{$self->{'_trans_exon_array'}} ) {
2655 my $new_exon = $old_exon->transform( @_ );
2656 return undef if( !defined $new_exon );
2657 if( ! defined $new_transcript ) {
2658 if( !$first ) {
2659 if( $old_exon->strand() != $last_old_strand ) {
2660 # transsplicing, ignore ordering
2661 $ignore_order = 1;
2662 }
2663  
2664 if( $new_exon->slice()->seq_region_name() ne
2665 $last_seq_region_name ) {
2666 return undef;
2667 }
2668  
2669 if( $last_new_strand == 1 and
2670 $new_exon->start() < $last_new_start ) {
2671 $order_broken = 1;
2672 }
2673  
2674 if( $last_new_strand == -1 and
2675 $new_exon->start() > $last_new_start ) {
2676 $order_broken = 1;
2677 }
2678  
2679 #additional check that if exons were on same strand previously, they should be again
2680 if(($last_old_strand == $old_exon->strand()) and !($last_new_strand == $new_exon->strand())){
2681 return undef;
2682 }
2683  
2684 if( $new_exon->start() < $low_start ) {
2685 $low_start = $new_exon->start();
2686 }
2687 if( $new_exon->end() > $hi_end ) {
2688 $hi_end = $new_exon->end();
2689 }
2690 } else {
2691 $first = 0;
2692 $low_start = $new_exon->start();
2693 $hi_end = $new_exon->end();
2694 }
2695  
2696 $last_seq_region_name = $new_exon->slice()->seq_region_name();
2697 $last_old_strand = $old_exon->strand();
2698 $last_new_start = $new_exon->start();
2699 $last_new_strand = $new_exon->strand();
2700 }
2701  
2702 if( defined $self->{'translation'} ) {
2703 if( $self->translation()->start_Exon() == $old_exon ) {
2704 $start_exon = $new_exon;
2705 }
2706 if( $self->translation()->end_Exon() == $old_exon ) {
2707 $end_exon = $new_exon;
2708 }
2709 }
2710 push( @new_exons, $new_exon );
2711 }
2712  
2713 if( $order_broken && !$ignore_order ) {
2714 warning( "Order of exons broken in transform of ".$self->dbID() );
2715 return undef;
2716 }
2717  
2718 if( !defined $new_transcript ) {
2719 %$new_transcript = %$self;
2720 bless $new_transcript, ref( $self );
2721 $new_transcript->start( $low_start );
2722 $new_transcript->end( $hi_end );
2723 $new_transcript->slice( $new_exons[0]->slice() );
2724 $new_transcript->strand( $new_exons[0]->strand() );
2725 }
2726  
2727 $new_transcript->{'_trans_exon_array'} = \@new_exons;
2728  
2729 # should be ok to do inside exon array loop
2730 # translations only exist together with the exons ...
2731  
2732 if( defined $self->{'translation'} ) {
2733 my $new_translation;
2734 %$new_translation = %{$self->{'translation'}};;
2735 bless $new_translation, ref( $self->{'translation'} );
2736 $new_transcript->{'translation'} = $new_translation;
2737 $new_translation->start_Exon( $start_exon );
2738 $new_translation->end_Exon( $end_exon );
2739 }
2740 }
2741  
2742 if( exists $self->{'_supporting_evidence'} ) {
2743 my @new_features;
2744 for my $old_feature ( @{$self->{'_supporting_evidence'}} ) {
2745 my $new_feature = $old_feature->transform( @_ );
2746 if (defined $new_feature) {
2747 push @new_features, $new_feature;
2748 }
2749 }
2750 $new_transcript->{'_supporting_evidence'} = \@new_features;
2751 }
2752
2753 if(exists $self->{_ise_array}) {
2754 my @new_features;
2755 foreach my $old_feature ( @{$self->{_ise_array}} ) {
2756 my $new_feature = $old_feature->transform(@_);
2757 push( @new_features, $new_feature );
2758 }
2759 $new_transcript->{_ise_array} = \@new_features;
2760 }
2761  
2762 if(exists $self->{attributes}) {
2763 $new_transcript->{attributes} = [@{$self->{attributes}}];
2764 }
2765  
2766 # flush cached internal values that depend on the exon coords
2767 $new_transcript->{'transcript_mapper'} = undef;
2768 $new_transcript->{'coding_region_start'} = undef;
2769 $new_transcript->{'coding_region_end'} = undef;
2770 $new_transcript->{'cdna_coding_start'} = undef;
2771 $new_transcript->{'cdna_coding_end'} = undef;
2772  
2773 return $new_transcript;
2774 }
2775  
2776  
2777 =head2 transfer
2778  
2779 Arg 1 : Bio::EnsEMBL::Slice $destination_slice
2780 Example : $transcript = $transcript->transfer($slice);
2781 Description: Moves this transcript to the given slice.
2782 If this Transcripts has Exons attached, they move as well.
2783 Returntype : Bio::EnsEMBL::Transcript
2784 Exceptions : none
2785 Caller : general
2786 Status : Stable
2787  
2788 =cut
2789  
2790  
2791 sub transfer {
2792 my $self = shift;
2793  
2794 my $new_transcript = $self->SUPER::transfer( @_ );
2795 return undef unless $new_transcript;
2796  
2797 if( defined $self->{'translation'} ) {
2798 my $new_translation;
2799 %$new_translation = %{$self->{'translation'}};;
2800 bless $new_translation, ref( $self->{'translation'} );
2801 $new_transcript->{'translation'} = $new_translation;
2802 }
2803  
2804 if( exists $self->{'_trans_exon_array'} ) {
2805 my @new_exons;
2806 for my $old_exon ( @{$self->{'_trans_exon_array'}} ) {
2807 my $new_exon = $old_exon->transfer( @_ );
2808 if( defined $new_transcript->{'translation'} ) {
2809 if( $new_transcript->translation()->start_Exon() == $old_exon ) {
2810 $new_transcript->translation()->start_Exon( $new_exon );
2811 }
2812 if( $new_transcript->translation()->end_Exon() == $old_exon ) {
2813 $new_transcript->translation()->end_Exon( $new_exon );
2814 }
2815 }
2816 push( @new_exons, $new_exon );
2817 }
2818  
2819 $new_transcript->{'_trans_exon_array'} = \@new_exons;
2820 }
2821  
2822 if( exists $self->{'_supporting_evidence'} ) {
2823 my @new_features;
2824 for my $old_feature ( @{$self->{'_supporting_evidence'}} ) {
2825 my $new_feature = $old_feature->transfer( @_ );
2826 push( @new_features, $new_feature );
2827 }
2828 $new_transcript->{'_supporting_evidence'} = \@new_features;
2829 }
2830
2831 if(exists $self->{_ise_array}) {
2832 my @new_features;
2833 foreach my $old_feature ( @{$self->{_ise_array}} ) {
2834 my $new_feature = $old_feature->transfer(@_);
2835 push( @new_features, $new_feature );
2836 }
2837 $new_transcript->{_ise_array} = \@new_features;
2838 }
2839  
2840 if(exists $self->{attributes}) {
2841 $new_transcript->{attributes} = [@{$self->{attributes}}];
2842 }
2843  
2844 # flush cached internal values that depend on the exon coords
2845 $new_transcript->{'transcript_mapper'} = undef;
2846 $new_transcript->{'coding_region_start'} = undef;
2847 $new_transcript->{'coding_region_end'} = undef;
2848 $new_transcript->{'cdna_coding_start'} = undef;
2849 $new_transcript->{'cdna_coding_end'} = undef;
2850  
2851 return $new_transcript;
2852 }
2853  
2854  
2855 =head recalculate_coordinates
2856  
2857 Args : none
2858 Example : none
2859 Description: called when exon coordinate change happened to recalculate the
2860 coords of the transcript. This method should be called if one
2861 of the exons has been changed.
2862 Returntype : none
2863 Exceptions : none
2864 Caller : internal
2865 Status : Stable
2866  
2867 =cut
2868  
2869 sub recalculate_coordinates {
2870 my ($self) = @_;
2871  
2872 my $exons = $self->get_all_Exons();
2873  
2874 if ( !$exons || !@{$exons} ) { return }
2875  
2876 my ( $slice, $start, $end, $strand );
2877  
2878 my $e_index;
2879 for ( $e_index = 0; $e_index < @{$exons}; $e_index++ ) {
2880 my $e = $exons->[$e_index];
2881  
2882 # Skip missing or unmapped exons!
2883 if ( defined($e) && defined( $e->start() ) ) {
2884 $slice = $e->slice();
2885 $strand = $e->strand();
2886 $start = $e->start();
2887 $end = $e->end();
2888  
2889 last;
2890 }
2891 }
2892  
2893 my $transsplicing = 0;
2894  
2895 # Start loop after first exon with coordinates
2896 for ( ; $e_index < @{$exons}; $e_index++ ) {
2897 my $e = $exons->[$e_index];
2898  
2899 # Skip missing or unmapped exons!
2900 if ( !defined($e) || !defined( $e->start() ) ) { next }
2901  
2902 if ( $e->start() < $start ) {
2903 $start = $e->start();
2904 }
2905  
2906 if ( $e->end() > $end ) {
2907 $end = $e->end();
2908 }
2909  
2910 if ( defined($slice)
2911 && $e->slice()
2912 && $e->slice()->name() ne $slice->name() )
2913 {
2914 throw( "Exons with different slices "
2915 . "are not allowed on one Transcript" );
2916 }
2917  
2918 if ( $e->strand() != $strand ) {
2919 $transsplicing = 1;
2920 }
2921 } ## end for ( ; $e_index < @{$exons...})
2922 if ($transsplicing) {
2923 warning("Transcript contained trans splicing event");
2924 }
2925  
2926 $self->start($start);
2927 $self->end($end);
2928 $self->strand($strand);
2929 $self->slice($slice);
2930  
2931 # flush cached internal values that depend on the exon coords
2932 $self->{'transcript_mapper'} = undef;
2933 $self->{'coding_region_start'} = undef;
2934 $self->{'coding_region_end'} = undef;
2935 $self->{'cdna_coding_start'} = undef;
2936 $self->{'cdna_coding_end'} = undef;
2937 } ## end sub recalculate_coordinates
2938  
2939  
2940 =head2 display_id
2941  
2942 Arg [1] : none
2943 Example : print $transcript->display_id();
2944 Description: This method returns a string that is considered to be
2945 the 'display' identifier. For transcripts this is (depending on
2946 availability and in this order) the stable Id, the dbID or an
2947 empty string.
2948 Returntype : string
2949 Exceptions : none
2950 Caller : web drawing code
2951 Status : Stable
2952  
2953 =cut
2954  
2955 sub display_id {
2956 my $self = shift;
2957 return $self->{'stable_id'} || $self->dbID || '';
2958 }
2959  
2960  
2961 =head2 get_all_DASFactories
2962  
2963 Arg [1] : none
2964 Function : Retrieves a listref of registered DAS objects
2965 Returntype: [ DAS_objects ]
2966 Exceptions:
2967 Caller :
2968 Example : $dasref = $prot->get_all_DASFactories
2969 Status : Stable
2970  
2971 =cut
2972  
2973 sub get_all_DASFactories {
2974 my $self = shift;
2975 return [ $self->adaptor()->db()->_each_DASFeatureFactory ];
2976 }
2977  
2978  
2979 =head2 get_all_DAS_Features
2980  
2981 Arg [1] : none
2982 Example : $features = $prot->get_all_DAS_Features;
2983 Description: Retrieves a hash reference to a hash of DAS feature
2984 sets, keyed by the DNS, NOTE the values of this hash
2985 are an anonymous array containing:
2986 (1) a pointer to an array of features;
2987 (2) a pointer to the DAS stylesheet
2988 Returntype : hashref of Bio::SeqFeatures
2989 Exceptions : ?
2990 Caller : webcode
2991 Status : Stable
2992  
2993  
2994 =cut
2995  
2996 sub get_all_DAS_Features {
2997 my ($self,@args) = @_;
2998  
2999 my $db = $self->adaptor->db;
3000 my $GeneAdaptor = $db->get_GeneAdaptor;
3001 my $Gene = $GeneAdaptor->fetch_by_transcript_stable_id($self->stable_id);
3002 my $slice = $Gene->feature_Slice;
3003 return $self->SUPER::get_all_DAS_Features($slice);
3004 }
3005  
3006  
3007 =head2 get_all_RNAProducts
3008  
3009 Arg [1] : optional string $type_code type of rnaproducts to retrieve
3010 Example : @transc_mirnas = @{$transcript->get_all_RNAProducts('miRNA')};
3011 @transc_rnaproducts = @{$transcript->get_all_RNAProducts()};
3012 Description: Gets a list of RNAProducts of this transcript.
3013 Optionally just get RNAProducts for given type code.
3014 Returntype : listref Bio::EnsEMBL::RNAProduct
3015 Exceptions : none
3016 Caller : general
3017 Status : In Development
3018  
3019 =cut
3020  
3021 sub get_all_RNAProducts {
3022 my ($self, $type_code) = @_;
3023  
3024 if (!exists $self->{'rnaproducts'}) {
3025 if (!$self->adaptor()) {
3026 return [];
3027 }
3028  
3029 my $rnaproduct_adaptor = $self->adaptor->db->get_RNAProductAdaptor();
3030 $self->{'rnaproducts'} = $rnaproduct_adaptor->fetch_all_by_Transcript($self);
3031 }
3032  
3033 if (defined $type_code) {
3034 my @results = grep { $_->type_code() eq $type_code } @{$self->{'rnaproducts'}};
3035 return \@results;
3036 } else {
3037 return $self->{'rnaproducts'};
3038 }
3039 }
3040  
3041  
3042  
3043 =head2 _compare_xrefs
3044  
3045 Description: compare xrefs based on priority (descending), then
3046 name (ascending), then display_label (ascending)
3047  
3048 =cut
3049  
3050 sub _compare_xrefs {
3051 # compare on priority first (descending)
3052 if ( $a->priority() != $b->priority() ) {
3053 return $b->priority() <=> $a->priority();
3054 } else {
3055 # equal priorities, compare on external_db name
3056 if ( $a->dbname() ne $b->dbname() ) {
3057 return $a->dbname() cmp $b->dbname();
3058 } else {
3059 # equal priorities and names, compare on display_label
3060 return $a->display_id() cmp $b->display_id();
3061 }
3062 }
3063 }
3064  
3065  
3066 =head2 load
3067  
3068 Arg [1] : Boolean $load_xrefs
3069 Load (or don't load) xrefs. Default is to load xrefs.
3070 Example : $transcript->load();
3071 Description : The Ensembl API makes extensive use of
3072 lazy-loading. Under some circumstances (e.g.,
3073 when copying genes between databases), all data of
3074 an object needs to be fully loaded. This method
3075 loads the parts of the object that are usually
3076 lazy-loaded. It will also call the equivalent
3077 method on any translation and on all exons of the
3078 transcript.
3079 Returntype : None
3080  
3081 =cut
3082  
3083 sub load {
3084 my ( $self, $load_xrefs ) = @_;
3085  
3086 if ( !defined($load_xrefs) ) { $load_xrefs = 1 }
3087  
3088 my $translation = $self->translation();
3089 if ( defined($translation) ) {
3090 $translation->load($load_xrefs);
3091  
3092 my $alt_translations = $self->get_all_alternative_translations();
3093  
3094 if ( defined($alt_translations) ) {
3095 foreach my $alt_translation ( @{$alt_translations} ) {
3096 $alt_translation->load($load_xrefs);
3097 }
3098 }
3099 }
3100  
3101 foreach my $exon ( @{ $self->get_all_Exons() } ) {
3102 $exon->load();
3103 }
3104  
3105 $self->stable_id();
3106 $self->analysis();
3107 $self->get_all_Attributes();
3108 $self->get_all_supporting_features();
3109 $self->get_all_IntronSupportingEvidence();
3110  
3111 if ($load_xrefs) {
3112 $self->get_all_DBEntries();
3113 }
3114  
3115 } ## end sub load
3116  
3117 =head2 summary_as_hash
3118  
3119 Example : $transcript_summary = $transcript->summary_as_hash();
3120 Description : Extends Feature::summary_as_hash
3121 Retrieves a summary of this Transcript.
3122 Returns : hashref of descriptive strings
3123 Status : Intended for internal use
3124 =cut
3125  
3126 sub summary_as_hash {
3127 my $self = shift;
3128 my $summary_ref = $self->SUPER::summary_as_hash;
3129 $summary_ref->{'description'} = $self->description;
3130 $summary_ref->{'Name'} = $self->external_name if $self->external_name;
3131 $summary_ref->{'biotype'} = $self->get_Biotype->name;
3132 $summary_ref->{'logic_name'} = $self->analysis->logic_name() if defined $self->analysis();
3133 my $parent_gene = $self->get_Gene();
3134 $summary_ref->{'Parent'} = $parent_gene->stable_id;
3135 $summary_ref->{'source'} = $self->source();
3136 $summary_ref->{'transcript_id'} = $summary_ref->{'id'};
3137  
3138 ## Specific attributes for merged species
3139 ## No data will be stored if these fields are not available
3140 my $havana_transcript = $self->havana_transcript();
3141 $summary_ref->{'havana_transcript'} = $havana_transcript->display_id() if defined $havana_transcript;
3142 $summary_ref->{'havana_version'} = $havana_transcript->version() if defined $havana_transcript;
3143 $summary_ref->{'ccdsid'} = $self->ccds->display_id() if $self->ccds();
3144 $summary_ref->{'transcript_support_level'} = $self->tsl() if $self->tsl();
3145  
3146 my @tags;
3147 push @tags, $self->get_all_Attributes('gencode_basic')->[0]->code if $self->gencode_basic();
3148 push @tags, 'Ensembl_canonical' if $self->is_canonical();
3149 push @tags, $self->get_all_Attributes('gencode_primary')->[0]->code if $self->gencode_primary();
3150  
3151 my $mane = $self->mane_transcript();
3152 if ($mane) {
3153 push @tags, $mane->type() if ($mane->type());
3154 }
3155  
3156 $summary_ref->{'tag'} = \@tags if @tags;
3157  
3158 ## Stable identifier of the parent transcript this transcript was projected from
3159 my $proj_parent_attributes = $self->get_all_Attributes("proj_parent_t");
3160 if (@{$proj_parent_attributes}) {
3161 $summary_ref->{'projection_parent_transcript'} = $proj_parent_attributes->[0]->value;
3162 }
3163 return $summary_ref;
3164 }
3165  
3166 =head2 gencode_basic
3167  
3168 Example : $gencode_basic = $transcript->gencode_basic();
3169 Description : Returns true if gencode_basic is set
3170 Returns : boolean
3171 =cut
3172  
3173 sub gencode_basic {
3174 my $self = shift;
3175 my @attributes = @{ $self->get_all_Attributes('gencode_basic') };
3176 my $basic = 0;
3177 $basic = 1 if scalar(@attributes) > 0;
3178 return $basic;
3179 }
3180  
3181 =head2 gencode_primary
3182  
3183 Example : $gencode_primary = $transcript->gencode_primary();
3184 Description : Returns true if gencode_primary is set
3185 Returns : boolean
3186 =cut
3187  
3188 sub gencode_primary {
3189 my $self = shift;
3190 my @attributes = @{ $self->get_all_Attributes('gencode_primary') };
3191 my $primary = 0;
3192 $primary = 1 if scalar(@attributes) > 0;
3193 return $primary;
3194 }
3195  
3196 =head2 tsl
3197  
3198 Example : $tsl = $transcript->tsl();
3199 Description : Returns the corresponding transcript support level
3200 Returns : string
3201 =cut
3202  
3203 sub tsl {
3204 my $self = shift;
3205 my @attributes = @{ $self->get_all_Attributes('TSL') };
3206 my $tsl;
3207 $tsl = $attributes[0]->value if scalar(@attributes) > 0;
3208 if (defined $tsl) { $tsl =~ s/tsl//; }
3209 return $tsl;
3210 }
3211  
3212 =head2 appris
3213  
3214 Example : $appris = $transcript->appris();
3215 Description : Returns the corresponding APPRIS tag
3216 Returns : string
3217  
3218 =cut
3219  
3220 sub appris {
3221 my $self = shift;
3222 my @attributes = @{ $self->get_all_Attributes('appris') };
3223 my $appris;
3224 $appris = $attributes[0]->value if scalar(@attributes) > 0;
3225  
3226 return $appris;
3227 }
3228  
3229 =head2 havana_transcript
3230  
3231 Example : $havana_transcript = $transcript->havana_transcript();
3232 Description : Locates the corresponding havana transcript
3233 Returns : Bio::EnsEMBL::DBEntry
3234 =cut
3235  
3236 sub havana_transcript {
3237 my $self = shift;
3238 my @otts = @{ $self->get_all_DBEntries('Vega_transcript') };
3239 my $ott;
3240 foreach my $xref (@otts) {
3241 if ($xref->display_id() =~ /OTT/) {
3242 $ott = $xref;
3243 last;
3244 }
3245 }
3246 return $ott;
3247 }
3248  
3249 =head2 ccds
3250  
3251 Example : $ccds = $transcript->ccds();
3252 Description : Locates the corresponding ccds xref
3253 Returns : Bio::EnsEMBL::DBEntry
3254 =cut
3255  
3256 sub ccds {
3257 my $self = shift;
3258 my @ccds = @{ $self->get_all_DBEntries('CCDS') };
3259 my $ccds;
3260 $ccds = $ccds[0] if scalar(@ccds) > 0;
3261 return $ccds;
3262 }
3263  
3264  
3265  
3266 =head2 get_Gene
3267
3268 Example : $gene = $transcript->get_Gene;
3269 Description : Locates the parent Gene using a transcript dbID
3270 Returns : Bio::EnsEMBL::Gene
3271  
3272 =cut
3273  
3274 sub get_Gene {
3275 my $self = shift;
3276 my $gene_adaptor = $self->adaptor->db->get_GeneAdaptor();
3277 my $parent_gene = $gene_adaptor->fetch_by_transcript_id($self->dbID);
3278 return $parent_gene;
3279 }
3280  
3281 =head2 get_Biotype
3282  
3283 Example : my $biotype = $transcript->get_Biotype;
3284 Description: Returns the Biotype object of this transcript.
3285 When no biotype exists, defaults to 'protein_coding'.
3286 When used to set to a biotype that does not exist in
3287 the biotype table, a biotype object is created with
3288 the provided argument as name and object_type transcript.
3289 Returntype : Bio::EnsEMBL::Biotype
3290 Exceptions : none
3291  
3292 =cut
3293  
3294 sub get_Biotype {
3295 my ( $self ) = @_;
3296  
3297 # have a biotype object, return it
3298 if ( ref $self->{'biotype'} eq 'Bio::EnsEMBL::Biotype' ) {
3299 return $self->{'biotype'};
3300 }
3301  
3302 # biotype is first set as a string retrieved from the transcript table
3303 # there is no biotype object in the transcript object, retrieve it using the biotype string
3304 # if no string, default to protein_coding. this is legacy behaviour and should probably be revisited
3305 my $biotype_name = $self->{'biotype'} // 'protein_coding';
3306  
3307 return $self->set_Biotype( $biotype_name );
3308 }
3309  
3310 =head2 set_Biotype
3311  
3312 Arg [1] : Arg [1] : String - the biotype name to set
3313 Example : my $biotype = $transcript->set_Biotype('protin_coding');
3314 Description: Sets the Biotype of this transcript to the provided biotype name.
3315 Returns the Biotype object of this transcript.
3316 When no biotype exists, defaults to 'protein_coding' name.
3317 When setting a biotype that does not exist in
3318 the biotype table, a biotype object is created with
3319 the provided argument as name and object_type transcript.
3320 Returntype : Bio::EnsEMBL::Biotype
3321 Exceptions : If no argument provided
3322  
3323 =cut
3324  
3325 sub set_Biotype {
3326 my ( $self, $name ) = @_;
3327  
3328 throw('No argument provided') unless defined $name;
3329  
3330 # retrieve biotype object from the biotype adaptor
3331 if( defined $self->adaptor() ) {
3332 my $ba = $self->adaptor()->db()->get_BiotypeAdaptor();
3333 $self->{'biotype'} = $ba->fetch_by_name_object_type( $name, 'transcript' );
3334 }
3335 # if $self->adaptor is unavailable, create a new biotype object containing name and object_type only
3336 else {
3337 $self->{'biotype'} = Bio::EnsEMBL::Biotype->new(
3338 -NAME => $name,
3339 -OBJECT_TYPE => 'transcript',
3340 )
3341 }
3342  
3343 return $self->{'biotype'} ;
3344 }
3345  
3346 =head2 biotype
3347 Arg [1] : (optional) String - the biotype to set
3348 Example : $transcript->biotype("protein_coding");
3349 Description: Getter/setter for the attribute biotype name.
3350 Recommended to use instead for a getter:
3351 $biotype = $transcript->get_Biotype;
3352 and for a setter:
3353 $biotype = $transcript->set_Biotype("protein_coding");
3354 The String biotype name can then be retrieved by
3355 calling name on the Biotype object:
3356 $biotype_name = $biotype->name;
3357 Returntype : String
3358 Exceptions : none
3359 Caller : general
3360 Status : Stable
3361 =cut
3362  
3363 sub biotype {
3364 my ( $self, $biotype_name) = @_;
3365  
3366 # Setter? set_Biotype()
3367 if (defined $biotype_name) {
3368 return $self->set_Biotype($biotype_name)->name;
3369 }
3370  
3371 # Getter? get_Biotype()
3372 return $self->get_Biotype->name;
3373 }
3374  
3375 =head2 mane_transcript
3376 Example : $mane = $transcript->mane_transcript();
3377 Description: Retrieve the corresponding MANE transcript
3378 Returntype : Bio::EnsEMBL::MANE
3379 Exceptions : none
3380 Caller : general
3381 Status : Stable
3382 =cut
3383  
3384 sub mane_transcript {
3385 my ($self) = @_;
3386 if ($self->is_mane) {
3387  
3388 my $mane = Bio::EnsEMBL::MANE->new(
3389 -SEQ_REGION_START => $self->seq_region_start,
3390 -SEQ_REGION_END => $self->seq_region_end,
3391 -START => $self->start,
3392 -END => $self->end,
3393 -STABLE_ID => $self->stable_id,
3394 -SLICE => $self->slice,
3395 -TRANSCRIPT => $self
3396 );
3397 return $mane;
3398 }
3399 return undef;
3400 }
3401  
3402 =head2 is_mane
3403 Example : $boolean = $transcript->is_mane();
3404 Description: Check if a transcript is part of MANE
3405 Returntype : boolean
3406 Exceptions : none
3407 Caller : general
3408 Status : Stable
3409 =cut
3410  
3411 sub is_mane {
3412 my ($self) = @_;
3413 my $is_mane = 0;
3414 foreach my $attribute (@{ $self->get_all_Attributes() } ) {
3415 if ($attribute->code=~ /MANE/) {
3416 $is_mane = 1;
3417 }
3418 }
3419 return $is_mane;
3420 }
3421  
3422 1;