EnsEMBL/Exon.pm untested

filter: Statementstmt 0.0% 0 / 449 Branchbran 0.0% 0 / 236 Conditioncond 0.0% 0 / 93 Subroutinesub 0.0% 0 / 48 Podpod 0.0% 0 / 39 totaltotal 0.0% 0 / 865 CC 119 SCAR 37.3
CC
119
Cov
0%
seq
110.0
cdna_coding_start
72.0
cdna_coding_end
72.0
CRAP 41.5
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::Exon - A class representing an Exon
34  
35 =head1 SYNOPSIS
36  
37 $exon = new Bio::EnsEMBL::Exon(
38 -START => 100,
39 -END => 200,
40 -STRAND => 1,
41 -SLICE => $slice,
42 -DBID => $dbID,
43 -ANALYSIS => $analysis,
44 -STABLE_ID => 'ENSE000000123',
45 -VERSION => 2
46 );
47  
48 # seq() returns a Bio::Seq
49 my $seq = $exon->seq->seq();
50  
51 # Peptide only makes sense within transcript context
52 my $pep = $exon->peptide($transcript)->seq();
53  
54 # Normal feature operations can be performed:
55 $exon = $exon->transform('clone');
56 $exon->move( $new_start, $new_end, $new_strand );
57 print $exon->slice->seq_region_name();
58  
59 =head1 DESCRIPTION
60  
61 This is a class which represents an exon which is part of a transcript.
62 See Bio::EnsEMBL:Transcript
63  
64 =head1 METHODS
65  
66 =cut
67  
68 package Bio::EnsEMBL::Exon;
69 $Bio::EnsEMBL::Exon::VERSION = '114.0.0_50'; # TRIAL
70 $Bio::EnsEMBL::Exon::VERSION = '114.0.050';
71 use strict;
72  
73 use Bio::EnsEMBL::Feature;
74 use Bio::Seq; # exons have to have sequences...
75  
76 use Bio::EnsEMBL::Utils::Exception qw( warning throw);
77 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
78 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
79 use Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor;
80  
81 use vars qw(@ISA);
82 @ISA = qw(Bio::EnsEMBL::Feature);
83  
84 use constant SEQUENCE_ONTOLOGY => {
85 acc => 'SO:0000147',
86 term => 'exon',
87 };
88  
89 =head2 new
90  
91 Arg [-SLICE]: Bio::EnsEMBL::SLice - Represents the sequence that this
92 feature is on. The coordinates of the created feature are
93 relative to the start of the slice.
94 Arg [-START]: The start coordinate of this feature relative to the start
95 of the slice it is sitting on. Coordinates start at 1 and
96 are inclusive.
97 Arg [-END] : The end coordinate of this feature relative to the start of
98 the slice it is sitting on. Coordinates start at 1 and are
99 inclusive.
100 Arg [-STRAND]: The orientation of this feature. Valid values are 1,-1,0.
101 Arg [-SEQNAME] : (optional) A seqname to be used instead of the default name
102 of the of the slice. Useful for features that do not have an
103 attached slice such as protein features.
104 Arg [-dbID] : (optional) internal database id
105 Arg [-ADAPTOR]: (optional) Bio::EnsEMBL::DBSQL::BaseAdaptor
106 Arg [-PHASE] : the phase.
107 Arg [-END_PHASE]: the end phase
108 Arg [-STABLE_ID]: (optional) the stable id of the exon
109 Arg [-VERSION] : (optional) the version
110 Arg [-CREATED_DATE] : (optional) the created date
111 Arg [-MODIFIED_DATE]: (optional) the last midifeid date
112  
113 Example : none
114 Description: create an Exon object
115 Returntype : Bio::EnsEMBL::Exon
116 Exceptions : if phase is not valid (i.e. 0,1, 2 -1)
117 Caller : general
118 Status : Stable
119  
120 =cut
121  
122 sub new {
123 my $class = shift;
124  
125 $class = ref $class || $class;
126  
127 my $self = $class->SUPER::new( @_ );
128  
129 my ( $phase, $end_phase, $stable_id, $version, $created_date,
130 $modified_date, $is_current, $is_constitutive )
131 = rearrange( [
132 "PHASE", "END_PHASE",
133 "STABLE_ID", "VERSION",
134 "CREATED_DATE", "MODIFIED_DATE",
135 "IS_CURRENT", "IS_CONSTITUTIVE"
136 ],
137 @_
138 );
139  
140 if ( defined($phase) ) { # make sure phase is valid.
141 $self->phase($phase);
142 }
143  
144 $self->{'end_phase'} = $end_phase;
145 $self->{'stable_id'} = $stable_id;
146 $self->{'created_date'} = $created_date;
147 $self->{'modified_date'} = $modified_date;
148  
149 # Default version
150 if ( !defined($version) ) { $version = 1 }
151 $self->{'version'} = $version;
152  
153 # Default is_current
154 if ( !defined($is_current) ) { $is_current = 1 }
155 $self->{'is_current'} = $is_current;
156  
157 # Default is_constitutive
158 if ( !defined($is_constitutive) ) { $is_constitutive = 0 }
159 $self->{'is_constitutive'} = $is_constitutive;
160  
161 return $self;
162 }
163  
164  
165 =head2 end_phase
166  
167 Arg [1] : (optional) int $end_phase
168 Example : $end_phase = $feat->end_phase;
169 Description: Gets/Sets the end phase of the exon.
170 end_phase = number of bases from the last incomplete codon of
171 this exon.
172 Usually, end_phase = (phase + exon_length)%3
173 but end_phase could be -1 if the exon is half-coding and its 3
174 prime end is UTR.
175 Returntype : int
176 Exceptions : warning if end_phase is called without an argument and the
177 value is not set.
178 Caller : general
179 Status : Stable
180  
181 =cut
182  
183 sub end_phase {
184 my $self = shift;
185 if (@_) {
186 $self->{'end_phase'} = shift;
187 }
188 else {
189 if ( !defined( $self->{'end_phase'} ) ) {
190 my $stable_id = '';
191 $stable_id = $self->stable_id if defined $self->stable_id;
192 warning("No end phase set in Exon ".$stable_id.". You must set it explicitly.");
193 }
194 }
195 return $self->{'end_phase'};
196 }
197  
198  
199 =head2 phase
200  
201 Arg [1] : (optional) int $phase
202 Example : my $phase = $exon->phase;
203 $exon->phase(2);
204 Description: Gets/Sets the phase of the exon.
205 Returntype : int
206 Exceptions : throws if phase is not (0, 1 2 or -1).
207 Caller : general
208 Status : Stable
209  
210  
211 Get or set the phase of the Exon, which tells the
212 translation machinery, which makes a peptide from
213 the DNA, where to start.
214  
215 The Ensembl phase convention can be thought of as
216 "the number of bases of the first codon which are
217 on the previous exon". It is therefore 0, 1 or 2
218 (or -1 if the exon is non-coding). In ascii art,
219 with alternate codons represented by B<###> and
220 B<+++>:
221  
222 Previous Exon Intron This Exon
223 ...------------- -------------...
224  
225 5' Phase 3'
226 ...#+++###+++### 0 +++###+++###+...
227 ...+++###+++###+ 1 ++###+++###++...
228 ...++###+++###++ 2 +###+++###+++...
229  
230 Here is another explanation from Ewan:
231  
232 Phase means the place where the intron lands
233 inside the codon - 0 between codons, 1 between
234 the 1st and second base, 2 between the second and
235 3rd base. Exons therefore have a start phase and
236 a end phase, but introns have just one phase.
237  
238 =cut
239  
240 sub phase {
241 my ($self,$value) = @_;
242
243 if (defined($value)) {
244 # Value must be 0,1,2, or -1 for non-coding
245 if ($value =~ /^(-1|0|1|2)$/) {
246 #print STDERR "Setting phase to $value\n";
247 $self->{'phase'} = $value;
248 } else {
249 throw("Bad value ($value) for exon phase. Should only be" .
250 " -1,0,1,2\n");
251 }
252 }
253 return $self->{'phase'};
254 }
255  
256  
257 =head2 frame
258  
259 Arg [1] : none
260 Example : $frame = $exon->frame
261 Description: Gets the frame of this exon
262 Returntype : int
263 Exceptions : thrown if an arg is passed
264 thrown if frame cannot be calculated due to a bad phase value
265 Caller : general
266 Status : Stable
267  
268 =cut
269  
270 sub frame {
271 my ($self,$value) = @_;
272  
273 if( defined $value ) {
274 throw("Cannot set frame. Deduced from seq_start and phase");
275 }
276  
277 # frame is mod 3 of the translation point
278  
279 if( $self->phase == -1 ) {
280 return '.'; # gff convention for no frame info
281 }
282 if( $self->phase == 0 ) {
283 return $self->start%3;
284 }
285  
286 if( $self->phase == 1 ) {
287 return ($self->start+2)%3;
288 }
289  
290 if( $self->phase == 2 ) {
291 return ($self->start+1)%3;
292 }
293  
294 throw("bad phase in exon ".$self->phase);
295  
296 }
297  
298  
299 =head2 start
300  
301 Arg [1] : int $start (optional)
302 Example : $start = $exon->start();
303 Description: Getter/Setter for the start of this exon. The superclass
304 implmentation is overridden to flush the internal sequence
305 cache if this value is altered
306 Returntype : int
307 Exceptions : none
308 Caller : general
309 Status : Stable
310  
311 =cut
312  
313 sub start {
314 my $self = shift;
315 # if an arg was provided, flush the internal sequence cache
316 delete $self->{'_seq_cache'} if(@_);
317 return $self->SUPER::start(@_);
318 }
319  
320  
321 =head2 end
322  
323 Arg [1] : int $end (optional)
324 Example : $end = $exon->end();
325 Description: Getter/Setter for the end of this exon. The superclass
326 implmentation is overridden to flush the internal sequence
327 cache if this value is altered
328 Returntype : int
329 Exceptions : none
330 Caller : general
331 Status : Stable
332  
333 =cut
334  
335 sub end {
336 my $self = shift;
337 # if an arg was provided, flush the internal sequence cache
338 delete $self->{'_seq_cache'} if(@_);
339 return $self->SUPER::end(@_);
340 }
341  
342  
343 =head2 strand
344  
345 Arg [1] : int $strand (optional)
346 Example : $start = $exon->strand();
347 Description: Getter/Setter for the strand of this exon. The superclass
348 implmentation is overridden to flush the internal sequence
349 cache if this value is altered
350 Returntype : int
351 Exceptions : none
352 Caller : general
353 Status : Stable
354  
355 =cut
356  
357 sub strand {
358 my $self = shift;
359 # if an arg was provided, flush the internal sequence cache
360 delete $self->{'_seq_cache'} if(@_);
361 return $self->SUPER::strand(@_);
362 }
363  
364 =head2 cdna_start
365  
366 Arg [1] : Bio::EnsEMBL::Transcript $transcript
367 The transcript for which cDNA coordinates should be
368 relative to.
369 Example : $cdna_start = $exon->cdna_start($transcript);
370 Description : Returns the start position of the exon in cDNA
371 coordinates.
372 Since an exon may be part of one or more transcripts,
373 the relevant transcript must be given as argument to
374 this method.
375 Return type : Integer
376 Exceptions : Throws if the given argument is not a transcript.
377 Throws if the first part of the exon maps into a gap.
378 Throws if the exon can not be mapped at all.
379 Caller : General
380 Status : Stable
381  
382 =cut
383  
384 sub cdna_start {
385 my ($self, $transcript) = @_;
386 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
387  
388 my $id = $transcript->dbID();
389
390 if(defined $id && exists $self->{cdna_start}->{$id}) {
391 return $self->{cdna_start}->{$id};
392 }
393
394 my $cdna_start;
395 my @coords = $transcript->genomic2cdna($self->seq_region_start(), $self->seq_region_end(), $self->strand());
396 if(@coords && !$coords[0]->isa('Bio::EnsEMBL::Mapper::Gap')) {
397 $cdna_start = $coords[0]->start();
398 }
399 elsif(@coords) {
400 throw "First part of exon maps into gap";
401 }
402 else {
403 throw "Can not map exon";
404 }
405
406 if(defined $id) {
407 $self->{cdna_start}->{$id} = $cdna_start;
408 }
409  
410 return $cdna_start;
411 } ## end sub cdna_start
412  
413 =head2 cdna_end
414  
415 Arg [1] : Bio::EnsEMBL::Transcript $transcript
416 The transcript for which cDNA coordinates should be
417 relative to.
418 Example : $cdna_end = $exon->cdna_end($transcript);
419 Description : Returns the end position of the exon in cDNA
420 coordinates.
421 Since an exon may be part of one or more transcripts,
422 the relevant transcript must be given as argument to
423 this method.
424 Return type : Integer
425 Exceptions : Throws if the given argument is not a transcript.
426 Throws if the last part of the exon maps into a gap.
427 Throws if the exon can not be mapped at all.
428 Caller : General
429 Status : Stable
430  
431 =cut
432  
433 sub cdna_end {
434 my ($self, $transcript) = @_;
435 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
436  
437 my $id = $transcript->dbID();
438
439 if(defined $id && exists $self->{cdna_end}->{$id}) {
440 return $self->{cdna_end}->{$id};
441 }
442
443 my $cdna_end;
444 my @coords = $transcript->genomic2cdna($self->seq_region_start(), $self->seq_region_end(), $self->strand());
445 if(@coords && !$coords[-1]->isa('Bio::EnsEMBL::Mapper::Gap')) {
446 $cdna_end = $coords[-1]->end();
447 }
448 elsif(@coords) {
449 throw "Last part of exon maps into gap";
450 }
451 else {
452 throw "Can not map exon";
453 }
454
455 if(defined $id) {
456 $self->{cdna_end}->{$id} = $cdna_end;
457 }
458  
459 return $cdna_end;
460 } ## end sub cdna_end
461  
462 =head2 cdna_coding_start
463  
464 Arg [1] : Bio::EnsEMBL::Transcript $transcript
465 The transcript for which cDNA coordinates should be
466 relative to.
467 Example : $cdna_coding_start = $exon->cdna_coding_start($transcript);
468 Description : Returns the start position of the coding region of the
469 exon in cDNA coordinates. Returns undef if the whole
470 exon is non-coding.
471 Since an exon may be part of one or more transcripts,
472 the relevant transcript must be given as argument to
473 this method.
474 Return type : Integer or undef
475 Exceptions : Throws if the given argument is not a transcript.
476 Caller : General
477 Status : Stable
478  
479 =cut
480  
481 sub cdna_coding_start {
482 my ($self, $transcript) = @_;
483 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
484  
485 my $id = $transcript->dbID();
486
487 if(defined $id && exists $self->{cdna_coding_start}->{$id}) {
488 return $self->{cdna_coding_start}->{$id};
489 }
490
491 my $cdna_coding_start;
492 my $transcript_coding_start = $transcript->cdna_coding_start();
493 if(defined $transcript_coding_start) {
494 my $cdna_start = $self->cdna_start($transcript);
495
496 if ( $transcript_coding_start < $cdna_start ) {
497 # Coding region starts upstream of this exon...
498  
499 if ( $transcript->cdna_coding_end() < $cdna_start ) {
500 # ... and also ends upstream of this exon.
501 $cdna_coding_start = undef;
502 }
503 else {
504 # ... and does not end upstream of this exon.
505 $cdna_coding_start = $cdna_start;
506 }
507 } else {
508 # Coding region starts either within or downstream of this
509 # exon.
510  
511 if ( $transcript_coding_start <= $self->cdna_end($transcript) ) {
512 # Coding region starts within this exon.
513 $cdna_coding_start = $transcript_coding_start;
514 }
515 else {
516 # Coding region starts downstream of this exon.
517 $cdna_coding_start = undef;
518 }
519 }
520 }
521 else {
522 $cdna_coding_start = undef;
523 }
524
525 if(defined $id) {
526 $self->{cdna_coding_start}->{$id} = $cdna_coding_start;
527 $self->{cdna_coding_end}->{$id} = undef if ! defined $cdna_coding_start;
528 }
529
530 return $cdna_coding_start;
531 } ## end sub cdna_coding_start
532  
533 =head2 cdna_coding_end
534  
535 Arg [1] : Bio::EnsEMBL::Transcript $transcript
536 The transcript for which cDNA coordinates should be
537 relative to.
538 Example : $cdna_coding_end = $exon->cdna_coding_end($transcript);
539 Description : Returns the end position of the coding region of the
540 exon in cDNA coordinates. Returns undef if the whole
541 exon is non-coding.
542 Since an exon may be part of one or more transcripts,
543 the relevant transcript must be given as argument to
544 this method.
545 Return type : Integer or undef
546 Exceptions : Throws if the given argument is not a transcript.
547 Caller : General
548 Status : Stable
549  
550 =cut
551  
552 sub cdna_coding_end {
553 my ($self, $transcript) = @_;
554 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
555  
556 my $id = $transcript->dbID();
557
558 if(defined $id && exists $self->{cdna_coding_end}->{$id}) {
559 return $self->{cdna_coding_end}->{$id};
560 }
561
562 my $cdna_coding_end;
563 my $transcript_coding_end = $transcript->cdna_coding_end();
564 if(defined $transcript_coding_end) {
565 my $cdna_end = $self->cdna_end($transcript);
566
567 if ( $transcript_coding_end > $cdna_end ) {
568
569 # Coding region ends downstream of this exon...
570 if ( $transcript->cdna_coding_start() > $cdna_end ) {
571 # ... and also starts downstream of this exon.
572 $cdna_coding_end = undef;
573 }
574 else {
575 # ... and does not start downstream of this exon.
576 $cdna_coding_end = $cdna_end;
577 }
578 }
579 else {
580 # Coding region ends either within or upstream of this
581 # exon.
582  
583 if ( $transcript_coding_end >= $self->cdna_start($transcript) ) {
584 # Coding region ends within this exon.
585 $cdna_coding_end = $transcript_coding_end;
586 }
587 else {
588 # Coding region ends upstream of this exon.
589 $cdna_coding_end = undef;
590 }
591 }
592 }
593 else {
594 $cdna_coding_end = undef;
595 }
596
597 if(defined $id) {
598 $self->{cdna_coding_end}->{$id} = $cdna_coding_end;
599 $self->{cdna_coding_start}->{$id} = undef if ! defined $cdna_coding_end;
600 }
601
602 return $cdna_coding_end;
603 } ## end sub cdna_coding_end
604  
605 =head2 coding_region_start
606  
607 Arg [1] : Bio::EnsEMBL::Transcript $transcript
608 Example : $coding_region_start =
609 $exon->coding_region_start($transcript);
610 Description : Returns the start position of the coding region
611 of the exon in slice-relative coordinates on the
612 forward strand. Returns undef if the whole exon is
613 non-coding.
614 Since an exon may be part of one or more transcripts,
615 the relevant transcript must be given as argument to
616 this method.
617 Return type : Integer or undef
618 Exceptions : Throws if the given argument is not a transcript.
619 Caller : General
620 Status : Stable
621  
622 =cut
623  
624 # The implementation of this method is analogous to the implementation
625 # of cdna_coding_start().
626  
627 sub coding_region_start {
628 my ($self, $transcript) = @_;
629 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
630  
631 my $id = $transcript->dbID();
632
633 if(defined $id && exists $self->{coding_region_start}->{$id}) {
634 return $self->{coding_region_start}->{$id};
635 }
636
637 my $coding_region_start;
638 my $transcript_coding_start = $transcript->coding_region_start();
639 if(defined $transcript_coding_start) {
640 my $start = $self->start();
641
642 if ( $transcript_coding_start < $start ) {
643 # Coding region starts upstream of this exon...
644  
645 if ( $transcript->coding_region_end() < $start ) {
646 # ... and also ends upstream of this exon.
647 $coding_region_start = undef;
648 }
649 else {
650 # ... and does not end upstream of this exon.
651 $coding_region_start = $start;
652 }
653 }
654 else {
655 # Coding region starts either within or downstream of this
656 # exon.
657  
658 if ( $transcript_coding_start <= $self->end() ) {
659 # Coding region starts within this exon.
660 $coding_region_start = $transcript_coding_start;
661 }
662 else {
663 # Coding region starts downstream of this exon.
664 $coding_region_start = undef;
665 }
666 }
667 }
668 else {
669 $coding_region_start = undef;
670 }
671
672 if(defined $id) {
673 $self->{coding_region_start}->{$id} = $coding_region_start;
674 $self->{coding_region_end}->{$id} = undef if ! defined $coding_region_start;
675 }
676
677 return $coding_region_start;
678 } ## end sub coding_region_start
679  
680 =head2 coding_region_end
681  
682 Arg [1] : Bio::EnsEMBL::Transcript $transcript
683 Example : $coding_region_end =
684 $exon->coding_region_end($transcript);
685 Description : Returns the end position of the coding region of
686 the exon in slice-relative coordinates on the
687 forward strand. Returns undef if the whole exon is
688 non-coding.
689 Since an exon may be part of one or more transcripts,
690 the relevant transcript must be given as argument to
691 this method.
692 Return type : Integer or undef
693 Exceptions : Throws if the given argument is not a transcript.
694 Caller : General
695 Status : Stable
696  
697 =cut
698  
699 # The implementation of this method is analogous to the implementation
700 # of cdna_coding_end().
701  
702 sub coding_region_end {
703 my ($self, $transcript) = @_;
704 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
705  
706 my $id = $transcript->dbID();
707
708 if(defined $id && exists $self->{coding_region_end}->{$id}) {
709 return $self->{coding_region_end}->{$id};
710 }
711
712 my $coding_region_end;
713 my $transcript_coding_end = $transcript->coding_region_end();
714 if(defined $transcript_coding_end) {
715
716 my $end = $self->end();
717 if($transcript_coding_end > $end) {
718 # Coding region ends downstream of this exon...
719  
720 if ( $transcript->coding_region_start() > $end ) {
721 # ... and also starts downstream of this exon.
722 $coding_region_end = undef;
723 }
724 else {
725 # ... and does not start downstream of this exon.
726 $coding_region_end = $end;
727 }
728 }
729 else {
730 # Coding region ends either within or upstream of this
731 # exon.
732 if ( $transcript_coding_end >= $self->start() ) {
733 $coding_region_end = $transcript_coding_end;
734 }
735 else {
736 $coding_region_end = undef;
737 }
738 }
739 }
740 else {
741 # This is a non-coding transcript.
742 $coding_region_end = undef;
743 }
744
745 if(defined $id) {
746 $self->{coding_region_end}->{$id} = $coding_region_end;
747 $self->{coding_region_start}->{$id} = undef if ! defined $coding_region_end;
748 }
749
750 return $coding_region_end;
751 } ## end sub coding_region_end
752  
753  
754 =head2 rank
755  
756 Arg [1] : Bio::EnsEMBL::Transcript $transcript
757 The transcript for which the exon rank
758 is requested.
759 Example : $rank = $exon->rank($transcript);
760 Description : Returns the rank of the exon relative to
761 the transcript.
762 Since an exon may be part of one or more transcripts,
763 the relevant transcript must be given as argument to
764 this method.
765 Return type : Integer
766 Exceptions : Throws if the given argument is not a transcript.
767 Throws if the exon does not belong to the transcript.
768 Caller : General
769 Status : Stable
770  
771 =cut
772  
773 sub rank {
774 my ($self, $transcript) = @_;
775 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
776  
777 my $rank = $transcript->exon_rank($self);
778  
779 return $rank;
780 } ## end sub rank
781  
782 =head2 slice
783  
784 Arg [1] : Bio::EnsEMBL::Slice
785 Example : $slice = $exon->slice();
786 Description: Getter/Setter for the slice this exon is on. The superclass
787 implmentation is overridden to flush the internal sequence
788 cache if this value is altered
789 Returntype : Bio::EnsEMBL::Slice
790 Exceptions : none
791 Caller : general
792 Status : Stable
793  
794 =cut
795  
796 sub slice {
797 my ( $self, $slice ) = @_;
798  
799 if ( defined($slice) ) {
800 # If a new slice was provided, flush the internal sequence cache and
801 # transfer all supporting evidence to the new slice.
802  
803 delete $self->{'_seq_cache'};
804  
805 if ( exists( $self->{'_supporting_evidence'} ) ) {
806 my @new_features;
807  
808 for my $old_feature ( @{ $self->{'_supporting_evidence'} } ) {
809  
810 my $new_feature;
811  
812 if ( defined( $old_feature->slice() ) ) {
813 $new_feature = $old_feature->transfer($slice);
814 } else {
815 # If the old feature does not have a slice, assume transfer is
816 # not necessary.
817 $new_feature = $old_feature;
818 }
819  
820 push( @new_features, $new_feature );
821 }
822  
823 $self->{'_supporting_evidence'} = \@new_features;
824 }
825  
826 return $self->SUPER::slice($slice);
827 } elsif ( @_ > 1 ) {
828 return $self->SUPER::slice(undef);
829 } else {
830 return $self->SUPER::slice();
831 }
832 } ## end sub slice
833  
834 =head2 equals
835  
836 Arg [1] : Bio::EnsEMBL::Exon exon
837 Example : if ($exonA->equals($exonB)) { ... }
838 Description : Compares two exons for equality.
839 The test for eqality goes through the following list
840 and terminates at the first true match:
841  
842 1. If Bio::EnsEMBL::Feature::equals() returns false,
843 then the exons are *not* equal.
844 2. If both exons have stable IDs: if these are the
845 same, the exons are equal, otherwise not.
846 3. If the exons have the same start, end, strand, and
847 phase, then they are equal, otherwise not.
848  
849 Return type : Boolean (0, 1)
850  
851 Exceptions : Thrown if a non-transcript is passed as the argument.
852  
853 =cut
854  
855 sub equals {
856 my ( $self, $exon ) = @_;
857  
858 if ( !defined($exon) ) { return 0 }
859 if ( $self eq $exon ) { return 1 }
860  
861 assert_ref( $exon, 'Bio::EnsEMBL::Exon' );
862  
863 my $feature_equals = $self->SUPER::equals($exon);
864 if ( defined($feature_equals) && $feature_equals == 0 ) {
865 return 0;
866 }
867  
868 if ( defined( $self->stable_id() ) && defined( $exon->stable_id() ) )
869 {
870 if ( $self->stable_id() eq $exon->stable_id() ) {
871 return 1;
872 }
873 else {
874 return 0;
875 }
876 }
877  
878 if ( $self->start() == $exon->start() &&
879 $self->end() == $exon->end() &&
880 $self->strand() == $exon->strand() &&
881 $self->phase() == $exon->phase() &&
882 $self->end_phase() == $exon->end_phase() )
883 {
884 return 1;
885 }
886  
887 return 0;
888 } ## end sub equals
889  
890 =head2 move
891  
892 Arg [1] : int start
893 Arg [2] : int end
894 Arg [3] : (optional) int strand
895 Example : None
896 Description: Sets the start, end and strand in one call rather than in
897 3 seperate calls to the start(), end() and strand() methods.
898 This is for convenience and for speed when this needs to be
899 done within a tight loop. This overrides the superclass
900 move() method so that the internal sequence cache can be
901 flushed if the exon if moved.
902 Returntype : none
903 Exceptions : Thrown is invalid arguments are provided
904 Caller : general
905 Status : Stable
906  
907 =cut
908  
909 sub move {
910 my $self = shift;
911 # flush the internal sequence cache
912 delete $self->{'_seq_cache'};
913 return $self->SUPER::move(@_);
914 }
915  
916  
917 =head2 transform
918  
919 Arg 1 : String $coordinate_system_name
920 Arg [2] : String $coordinate_system_version
921 Description: moves this exon to the given coordinate system. If this exon has
922 attached supporting evidence, they move as well.
923 Returntype : Bio::EnsEMBL::Exon
924 Exceptions : wrong parameters
925 Caller : general
926 Status : Stable
927  
928 =cut
929  
930 sub transform {
931 my $self = shift;
932  
933 my $new_exon = $self->SUPER::transform( @_ );
934 if (not defined $new_exon or
935 $new_exon->length != $self->length) {
936 return undef;
937 }
938  
939 if( exists $self->{'_supporting_evidence'} ) {
940 my @new_features;
941 for my $old_feature ( @{$self->{'_supporting_evidence'}} ) {
942 my $new_feature = $old_feature->transform( @_ );
943 if (defined $new_feature) {
944 push( @new_features, $new_feature );
945 }
946 }
947 $new_exon->{'_supporting_evidence'} = \@new_features;
948 }
949  
950 #dont want to share the same sequence cache
951 delete $new_exon->{'_seq_cache'};
952  
953 return $new_exon;
954 }
955  
956  
957 =head2 transfer
958  
959 Arg [1] : Bio::EnsEMBL::Slice $destination_slice
960 Example : none
961 Description: Moves this Exon to given target slice coordinates. If Features
962 are attached they are moved as well. Returns a new exon.
963 Returntype : Bio::EnsEMBL::Exon
964 Exceptions : none
965 Caller : general
966 Status : Stable
967  
968 =cut
969  
970 sub transfer {
971 my $self = shift;
972  
973 my $new_exon = $self->SUPER::transfer( @_ );
974 return undef unless $new_exon;
975  
976 if( exists $self->{'_supporting_evidence'} ) {
977 my @new_features;
978 for my $old_feature ( @{$self->{'_supporting_evidence'}} ) {
979 my $new_feature = $old_feature->transfer( @_ );
980 push( @new_features, $new_feature );
981 }
982 $new_exon->{'_supporting_evidence'} = \@new_features;
983 }
984  
985 #dont want to share the same sequence cache
986 delete $new_exon->{'_seq_cache'};
987  
988 return $new_exon;
989 }
990  
991  
992 =head2 add_supporting_features
993  
994 Arg [1] : Bio::EnsEMBL::Feature $feature
995 Example : $exon->add_supporting_features(@features);
996 Description: Adds a list of supporting features to this exon.
997 Duplicate features are not added.
998 If supporting features are added manually in this
999 way, prior to calling get_all_supporting_features then the
1000 get_all_supporting_features call will not retrieve supporting
1001 features from the database.
1002 Returntype : none
1003 Exceptions : throw if any of the features are not Feature
1004 throw if any of the features are not in the same coordinate
1005 system as the exon
1006 Caller : general
1007 Status : Stable
1008  
1009 =cut
1010  
1011 sub add_supporting_features {
1012 my ($self,@features) = @_;
1013  
1014 return unless @features;
1015  
1016 $self->{_supporting_evidence} ||= [];
1017
1018 # check whether this feature object has been added already
1019 FEATURE: foreach my $feature (@features) {
1020 unless($feature && $feature->isa("Bio::EnsEMBL::Feature")) {
1021 throw("Supporting feat [$feature] not a " .
1022 "Bio::EnsEMBL::Feature");
1023 }
1024
1025 if ((defined $self->slice() && defined $feature->slice())&&
1026 ( $self->slice()->name() ne $feature->slice()->name())){
1027 throw("Supporting feat not in same coord system as exon\n" .
1028 "exon is attached to [".$self->slice()->name()."]\n" .
1029 "feat is attached to [".$feature->slice()->name()."]");
1030 }
1031  
1032 foreach my $added_feature ( @{ $self->{_supporting_evidence} } ){
1033 # compare objects
1034 if ( $feature == $added_feature ){
1035 # this feature has already been added
1036 next FEATURE;
1037 }
1038 }
1039
1040 # no duplicate was found, add the feature
1041 push(@{$self->{_supporting_evidence}},$feature);
1042 }
1043 }
1044  
1045  
1046 =head2 flush_supporting_features
1047  
1048 Example : $exon->flush_supporting_features;
1049 Description : Removes all supporting evidence from the exon.
1050 Return type : (Empty) listref
1051 Exceptions : none
1052 Caller : general
1053 Status : Stable
1054  
1055 =cut
1056  
1057 sub flush_supporting_features {
1058 my $self = shift;
1059 $self->{'_supporting_evidence'} = [];
1060 }
1061  
1062  
1063 =head2 get_all_supporting_features
1064  
1065 Arg [1] : none
1066 Example : @evidence = @{$exon->get_all_supporting_features()};
1067 Description: Retrieves any supporting features added manually by
1068 calls to add_supporting_features. If no features have been
1069 added manually and this exon is in a database (i.e. it has
1070 an adaptor), fetch from the database
1071 Returntype : listreference of Bio::EnsEMBL::BaseAlignFeature objects
1072 Exceptions : none
1073 Caller : general
1074 Status : Stable
1075  
1076 =cut
1077  
1078 sub get_all_supporting_features {
1079 my $self = shift;
1080  
1081 if( !exists $self->{_supporting_evidence} ) {
1082 if($self->adaptor) {
1083 my $sfa = $self->adaptor->db->get_SupportingFeatureAdaptor();
1084 $self->{_supporting_evidence} = $sfa->fetch_all_by_Exon($self);
1085 }
1086 }
1087
1088 return $self->{_supporting_evidence} || [];
1089 }
1090  
1091  
1092 =head2 find_supporting_evidence
1093  
1094 # This method is only for genebuild backwards compatibility.
1095 # Avoid using it if possible
1096  
1097 Arg [1] : Bio::EnsEMBL::Feature $features
1098 The list of features to search for supporting (i.e. overlapping)
1099 evidence.
1100 Arg [2] : (optional) boolean $sorted
1101 Used to speed up the calculation of overlapping features.
1102 Should be set to true if the list of features is sorted in
1103 ascending order on their start coordinates.
1104 Example : $exon->find_supporting_evidence(\@features);
1105 Description: Looks through all the similarity features and
1106 stores as supporting features any feature
1107 that overlaps with an exon.
1108 Returntype : none
1109 Exceptions : none
1110 Caller : general
1111 Status : Medium Risk
1112  
1113 =cut
1114  
1115 sub find_supporting_evidence {
1116 my ($self,$features,$sorted) = @_;
1117  
1118 foreach my $f (@$features) {
1119 # return if we have a sorted feature array
1120 if ($sorted == 1 && $f->start > $self->end) {
1121 return;
1122 }
1123 if ($f->sub_SeqFeature) {
1124 my @subf = $f->sub_SeqFeature;
1125
1126 $self->find_supporting_evidence(\@subf);
1127 }
1128 else {
1129 if ($f->entire_seq()->name eq $self->slice()->name) {
1130 if ($f->end >= $self->start && $f->start <= $self->end && $f->strand == $self->strand) {
1131 $self->add_supporting_features($f);
1132 }
1133 }
1134 }
1135 }
1136 }
1137  
1138  
1139 =head2 stable_id
1140  
1141 Arg [1] : string $stable_id
1142 Example : none
1143 Description: get/set for attribute stable_id
1144 Returntype : string
1145 Exceptions : none
1146 Caller : general
1147 Status : Stable
1148  
1149 =cut
1150  
1151 sub stable_id {
1152 my $self = shift;
1153 $self->{'stable_id'} = shift if( @_ );
1154 return $self->{'stable_id'};
1155 }
1156  
1157  
1158 =head2 created_date
1159  
1160 Arg [1] : string $created_date
1161 Example : none
1162 Description: get/set for attribute created_date
1163 Returntype : string
1164 Exceptions : none
1165 Caller : general
1166 Status : Stable
1167  
1168 =cut
1169  
1170 sub created_date {
1171 my $self = shift;
1172 $self->{'created_date'} = shift if ( @_ );
1173 return $self->{'created_date'};
1174 }
1175  
1176  
1177 =head2 modified_date
1178  
1179 Arg [1] : string $modified_date
1180 Example : none
1181 Description: get/set for attribute modified_date
1182 Returntype : string
1183 Exceptions : none
1184 Caller : general
1185 Status : Stable
1186  
1187 =cut
1188  
1189 sub modified_date {
1190 my $self = shift;
1191 $self->{'modified_date'} = shift if ( @_ );
1192 return $self->{'modified_date'};
1193 }
1194  
1195  
1196 =head2 version
1197  
1198 Arg [1] : string $version
1199 Example : none
1200 Description: get/set for attribute version
1201 Returntype : string
1202 Exceptions : none
1203 Caller : general
1204 Status : Stable
1205  
1206 =cut
1207  
1208 sub version {
1209 my $self = shift;
1210 $self->{'version'} = shift if( @_ );
1211 return $self->{'version'};
1212 }
1213  
1214 =head2 stable_id_version
1215  
1216 Arg [1] : (optional) String - the stable ID with version to set
1217 Example : $exon->stable_id("ENSE0000000001.3");
1218 Description: Getter/setter for stable id with version for this exon.
1219 Returntype : String
1220 Exceptions : none
1221 Caller : general
1222 Status : Stable
1223  
1224 =cut
1225  
1226 sub stable_id_version {
1227 my $self = shift;
1228 if(my $stable_id = shift) {
1229 # See if there's an embedded period, assume that's a
1230 # version, might not work for some species but you
1231 # should use ->stable_id() and version() if you're worried
1232 # about ambiguity
1233 my $vindex = rindex($stable_id, '.');
1234 # Set the stable_id and version pair depending on if
1235 # we found a version delimiter in the stable_id
1236 ($self->{stable_id}, $self->{version}) = ($vindex > 0 ?
1237 (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) :
1238 $stable_id, undef);
1239 }
1240 return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : '');
1241 }
1242  
1243 =head2 is_current
1244  
1245 Arg [1] : Boolean $is_current
1246 Example : $exon->is_current(1)
1247 Description: Getter/setter for is_current state of this exon.
1248 Returntype : Int
1249 Exceptions : none
1250 Caller : general
1251 Status : Stable
1252  
1253 =cut
1254  
1255 sub is_current {
1256 my ( $self, $value ) = @_;
1257  
1258 if ( defined($value) ) {
1259 $self->{'is_current'} = $value;
1260 }
1261 return $self->{'is_current'};
1262 }
1263  
1264 =head2 is_constitutive
1265  
1266 Arg [1] : Boolean $is_constitutive
1267 Example : $exon->is_constitutive(0)
1268 Description: Getter/setter for is_constitutive state of this exon.
1269 Returntype : Int
1270 Exceptions : none
1271 Caller : general
1272 Status : Stable
1273  
1274 =cut
1275  
1276 sub is_constitutive {
1277 my ( $self, $value ) = @_;
1278  
1279 if ( defined($value) ) {
1280 $self->{'is_constitutive'} = $value;
1281 }
1282 return $self->{'is_constitutive'};
1283 }
1284  
1285 =head2 is_coding
1286  
1287 Arg [1] : Bio::EnsEMBL::Transcript
1288 Example : $exon->is_coding()
1289 Description: Says if the exon is within the translation or not
1290 Returntype : Int
1291 Exceptions : none
1292 Caller : general
1293 Status : Stable
1294  
1295 =cut
1296  
1297 sub is_coding {
1298 my ( $self, $transcript) = @_;
1299  
1300 if (!$transcript) { throw("Transcript parameter is required for " . __PACKAGE__ . "->is_coding()."); }
1301  
1302 if (!$transcript->translate) { return 0; }
1303  
1304 # coding region overlaps start of exon
1305 if ($transcript->coding_region_start <= $self->start && $self->start <= $transcript->coding_region_end) { return 1; }
1306  
1307 # coding region overlaps end of exon
1308 if ($transcript->coding_region_end >= $self->end && $self->end >= $transcript->coding_region_start) { return 1; }
1309  
1310 # to handle cases where transcript coding region can fall within the exon start and exon end, eg: if it is one exon transcript
1311 if ($transcript->coding_region_start >= $self->start && $transcript->coding_region_end <= $self->end ) { return 1; }
1312 return 0;
1313 }
1314  
1315  
1316 =head2 adjust_start_end
1317  
1318 Arg 1 : int $start_adjustment
1319 Arg 2 : int $end_adjustment
1320 Example : none
1321 Description: returns a new Exon with this much shifted coordinates
1322 Returntype : Bio::EnsEMBL::Exon
1323 Exceptions : none
1324 Caller : Transcript->get_all_translateable_Exons()
1325 Status : Stable
1326  
1327 =cut
1328  
1329 sub adjust_start_end {
1330 my ( $self, $start_adjust, $end_adjust ) = @_;
1331  
1332 my $new_exon = Bio::EnsEMBL::Exon->new();
1333 %{$new_exon} = %{$self};
1334  
1335 #invalidate the sequence cache
1336 delete $new_exon->{'_seq_cache'};
1337  
1338 if( $self->strand() == 1 ) {
1339 $new_exon->start( $self->start() + $start_adjust );
1340 $new_exon->end( $self->end() + $end_adjust )
1341 } else {
1342 $new_exon->start( $self->start() - $end_adjust );
1343 $new_exon->end( $self->end() - $start_adjust )
1344 }
1345  
1346 return $new_exon;
1347 }
1348  
1349  
1350 =head2 peptide
1351  
1352 Arg [1] : Bio::EnsEMBL::Transcript $tr
1353 Example : my $pep_str = $exon->peptide($transcript)->seq;
1354 Description: Retrieves the portion of the transcripts peptide
1355 encoded by this exon. The transcript argument is necessary
1356 because outside of the context of a transcript it is not
1357 possible to correctly determine the translation. Note that
1358 an entire amino acid will be present at the exon boundaries
1359 even if only a partial codon is present. Therefore the
1360 concatenation of all of the peptides of a transcripts exons
1361 is not the same as a transcripts translation because the
1362 summation may contain duplicated amino acids at splice sites.
1363 In the case that this exon is entirely UTR, a Bio::Seq object
1364 with an empty sequence string is returned.
1365 Returntype : Bio::Seq
1366 Exceptions : thrown if transcript argument is not provided
1367 Caller : general
1368 Status : Stable
1369  
1370 =cut
1371  
1372 sub peptide {
1373 my $self = shift;
1374 my $tr = shift;
1375  
1376 unless($tr && ref($tr) && $tr->isa('Bio::EnsEMBL::Transcript')) {
1377 throw("transcript arg must be Bio::EnsEMBL:::Transcript not [$tr]");
1378 }
1379
1380 #convert exons coordinates to peptide coordinates
1381 my $tmp_exon = $self->transfer($tr->slice);
1382 if (!$tmp_exon) {
1383 throw("Couldn't transfer exon to transcript's slice");
1384 }
1385
1386 my @coords =
1387 $tr->genomic2pep($tmp_exon->start, $tmp_exon->end, $tmp_exon->strand);
1388
1389 #filter out gaps
1390 @coords = grep {$_->isa('Bio::EnsEMBL::Mapper::Coordinate')} @coords;
1391
1392 #if this is UTR then the peptide will be empty string
1393 my $pep_str = '';
1394
1395
1396 if(scalar(@coords) > 1) {
1397 my $coord = $self->_merge_ajoining_coords(\@coords);
1398 if($coord) {
1399 @coords = ($coord);
1400 }
1401 else {
1402 my ($e_id, $tr_id) = ($self->stable_id(), $tr->stable_id());
1403 throw("Error. Exon maps to multiple locations in peptide and those".
1404 " locations are not continuous." .
1405 " Is this exon [$e_id] a member of this transcript [$tr_id]?");
1406 }
1407 }
1408 elsif(scalar(@coords) == 1) {
1409 my $c = $coords[0];
1410 my $pep = $tr->translate;
1411
1412 #bioperl doesn't give back residues for incomplete codons
1413 #make sure we don't subseq too far...
1414 my ($start, $end);
1415 $end = ($c->end > $pep->length) ? $pep->length : $c->end;
1416 $start = ($c->start < $end) ? $c->start : $end;
1417 $pep_str = $tr->translate->subseq($start, $end);
1418 }
1419
1420 return
1421 Bio::Seq->new( -seq => $pep_str,
1422 -moltype => 'protein',
1423 -alphabet => 'protein',
1424 -id => $self->display_id );
1425 }
1426  
1427 =head2 _merge_ajoining_coords
1428
1429 Arg [1] : ArrayRef of Bio::EnsEMBL::Mapper::Coordinate objects
1430 Example :
1431 Description : Merges coords which are ajoining or overlapping
1432 Returntype : Bio::EnsEMBL::Mapper::Coordinate or undef if it cannot happen
1433 Exceptions : Exception if the cooords cannot be condensed into one location
1434 Caller : internal
1435 Status : Development
1436  
1437 =cut
1438
1439 sub _merge_ajoining_coords {
1440 my ($self, $coords) = @_;
1441
1442 my $okay = 1;
1443 my $coord = shift @{$coords};
1444 my $start = $coord->start();
1445 my $last_end = $coord->end();
1446 foreach my $other_coord (@{$coords}) {
1447 if( ($last_end + 1) >= $other_coord->start() ) {
1448 $last_end = $other_coord->end();
1449 }
1450 else {
1451 $okay = 0;
1452 last;
1453 }
1454 }
1455
1456 if(!$okay) {
1457 return;
1458 }
1459
1460 my $new_coord = Bio::EnsEMBL::Mapper::Coordinate->new(
1461 $coord->id(), $start, $last_end, $coord->strand(), $coord->rank());
1462 return $new_coord;
1463 }
1464  
1465  
1466  
1467  
1468 =head2 seq
1469  
1470 Arg [1] : none
1471 Example : my $seq_str = $exon->seq->seq;
1472 Description: Retrieves the dna sequence of this Exon.
1473 Returned in a Bio::Seq object. Note that the sequence may
1474 include UTRs (or even be entirely UTR).
1475 Returntype : Bio::Seq or undef
1476 Exceptions : warning if argument passed,
1477 warning if exon does not have attatched slice
1478 warning if exon strand is not defined (or 0)
1479 Caller : general
1480 Status : Stable
1481  
1482 =cut
1483  
1484 sub seq {
1485 my ( $self, $arg ) = @_;
1486  
1487 if ( defined $arg ) {
1488 warning("seq setting on Exon not supported currently");
1489 $self->{'_seq_cache'} = $arg->seq();
1490 }
1491  
1492 if ( !defined( $self->{'_seq_cache'} ) ) {
1493 my $seq;
1494  
1495 if ( !defined $self->slice() ) {
1496 warning("Cannot retrieve seq for exon without slice\n");
1497 return undef;
1498 }
1499  
1500 if ( !$self->strand() ) {
1501 warning("Cannot retrieve seq for unstranded exon\n");
1502 return undef;
1503 }
1504  
1505 if ($self->slice->is_circular() ) {
1506 if ( $self->slice->start > $self->slice->end) {
1507 # Normally exons overlapping chromosome origin will have negative feature start, but slice will be from 1 .. length
1508 # But in case you got an exon attached to a sub slice try this
1509 my $mid_point = $self->slice()->seq_region_length() - $self->slice()->start() + 1;
1510 my $seq1 = $self->slice()->subseq( $self->start(), $mid_point, $self->strand() );
1511  
1512 my $seq2 = $self->slice()->subseq( $mid_point + 1, $self->end(), $self->strand() );
1513  
1514 $seq = $self->strand() > 0 ? "$seq1$seq2" : "$seq2$seq1";
1515 } elsif ( $self->start < 0 || $self->start > $self->end) {
1516 # Normally exons overlapping chromosome origin will be 0 based, and can have negative start
1517 # But if you go via sub_Slice it gives you chromosome based coordinates, i.e it will have start greater then end
1518 my $start_point = $self->slice->seq_region_length + $self->slice->start;
1519 my $mid_point = $self->slice->seq_region_length;
1520 my $seq1 = $self->slice->subseq( $self->start, $mid_point, $self->strand);
1521 my $seq2 = $self->slice->subseq(1, $self->end, $self->strand );
1522 $seq = $self->strand > 0 ? "$seq1$seq2" : "$seq2$seq1";
1523 } else {
1524 # End this is the case for genes not overlapping the origin
1525 $seq = $self->slice()->subseq( $self->start(), $self->end(), $self->strand() );
1526 }
1527 } else {
1528 $seq = $self->slice()->subseq( $self->start(), $self->end(), $self->strand() );
1529 }
1530  
1531 $self->{'_seq_cache'} = $seq;
1532 } ## end if ( !defined( $self->...))
1533  
1534 return
1535 Bio::Seq->new( -seq => $self->{'_seq_cache'},
1536 -id => $self->display_id,
1537 -moltype => 'dna',
1538 -alphabet => 'dna' );
1539 } ## end sub seq
1540  
1541  
1542 =head2 hashkey
1543  
1544 Arg [1] : none
1545 Example : if(exists $hash{$exon->hashkey}) { do_something(); }
1546 Description: Returns a unique hashkey that can be used to uniquely identify
1547 this exon. Exons are considered to be identical if they share
1548 the same seq_region, start, end, strand, phase, end_phase.
1549 Note that this will consider two exons on different slices
1550 to be different, even if they actually are not.
1551 Returntype : string formatted as slice_name-start-end-strand-phase-end_phase
1552 Exceptions : thrown if not all the necessary attributes needed to generate
1553 a unique hash value are set
1554 set
1555 Caller : general
1556 Status : Stable
1557  
1558 =cut
1559  
1560 sub hashkey {
1561 my $self = shift;
1562  
1563 my $slice = $self->{'slice'};
1564 my $slice_name = ($slice) ? $slice->name() : undef;
1565 my $start = $self->{'start'};
1566 my $end = $self->{'end'};
1567 my $strand = $self->{'strand'};
1568 my $phase = $self->{'phase'};
1569 my $end_phase = $self->{'end_phase'};
1570  
1571 if(!defined($slice_name)) {
1572 throw('Slice must be set to generate correct hashkey.');
1573 }
1574  
1575 if(!defined($start)) {
1576 warning("start attribute must be defined to generate correct hashkey.");
1577 }
1578  
1579 if(!defined($end)) {
1580 throw("end attribute must be defined to generate correct hashkey.");
1581 }
1582  
1583 if(!defined($strand)) {
1584 throw("strand attribute must be defined to generate correct hashkey.");
1585 }
1586  
1587 if(!defined($phase)) {
1588 throw("phase attribute must be defined to generate correct hashkey.");
1589 }
1590  
1591 if(!defined($end_phase)) {
1592 throw("end_phase attribute must be defined to generate correct hashkey.");
1593 }
1594  
1595 return "$slice_name-$start-$end-$strand-$phase-$end_phase";
1596 }
1597  
1598  
1599 =head2 display_id
1600  
1601 Arg [1] : none
1602 Example : print $exons->display_id();
1603 Description: This method returns a string that is considered to be
1604 the 'display' identifier. For exons this is (depending on
1605 availability and in this order) the stable Id, the dbID or an
1606 empty string.
1607 Returntype : string
1608 Exceptions : none
1609 Caller : web drawing code
1610 Status : Stable
1611  
1612 =cut
1613  
1614 sub display_id {
1615 my $self = shift;
1616 return $self->{'stable_id'} || $self->dbID || '';
1617 }
1618  
1619  
1620 =head2 load
1621  
1622 Args : None
1623 Example : $exon->load();
1624 Description : The Ensembl API makes extensive use of
1625 lazy-loading. Under some circumstances (e.g.,
1626 when copying genes between databases), all data of
1627 an object needs to be fully loaded. This method
1628 loads the parts of the object that are usually
1629 lazy-loaded.
1630 Returns : Nothing.
1631  
1632 =cut
1633  
1634 sub load {
1635 my ($self) = @_;
1636  
1637 $self->analysis();
1638 $self->stable_id();
1639 $self->get_all_supporting_features();
1640 }
1641  
1642  
1643 =head2 summary_as_hash
1644  
1645 Example : $exon_summary = $exon->summary_as_hash();
1646 Description : Extends Feature::summary_as_hash
1647 Retrieves a summary of this Exon.
1648 Returns : hashref of descriptive strings
1649 Status : Intended for internal use
1650 =cut
1651  
1652 sub summary_as_hash {
1653 my $self = shift;
1654 my $summary_ref = $self->SUPER::summary_as_hash;
1655 $summary_ref->{'constitutive'} = $self->is_constitutive;
1656 $summary_ref->{'ensembl_phase'} = $self->phase;
1657 $summary_ref->{'ensembl_end_phase'} = $self->end_phase;
1658 $summary_ref->{'exon_id'} = $summary_ref->{'id'};
1659 return $summary_ref;
1660 }
1661  
1662  
1663 1;