EnsEMBL/Transcript.pm untested

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