| 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 Bio::EnsEMBL::Intron - A class representing an Intron | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | $intron = Bio::EnsEMBL::Intron->new( exon1, exon2, $analysis ); | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | |||
| 40 | package Bio::EnsEMBL::Intron; | ||
| 41 | $Bio::EnsEMBL::Intron::VERSION = '114.0.0'; | ||
| 42 | use strict; | ||
| 43 | use warnings; | ||
| 44 | |||
| 45 | use Bio::EnsEMBL::Utils::Exception qw( warning throw ); | ||
| 46 | |||
| 47 | use base qw(Bio::EnsEMBL::Feature); | ||
| 48 | |||
| 49 | =head2 new | ||
| 50 | |||
| 51 | Arg [1] : Bio::EnsEMBL::Exon The 5' exon for the intron; required | ||
| 52 | Arg [2] : Bio::EnsEMBL::Exon The 3' exon for the intron; required | ||
| 53 | Arg [3] : Bio::EnsEMBL::Analysis Analysis to link to this Intron | ||
| 54 | Example : $intron = new Bio::EnsEMBL::Intron($exon1, $exon2) | ||
| 55 | Description: Create an Intron object from two exons and an optional analysis | ||
| 56 | Returntype : Bio::EnsEMBL::Intron | ||
| 57 | Exceptions : exons not on the same strand or slice. | ||
| 58 | Caller : general | ||
| 59 | Status : Stable | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub new { | ||
| 64 | my ( $proto, $e1, $e2, $analysis ) = @_; | ||
| 65 | |||
| 66 | my $class = ref $proto || $proto; | ||
| 67 | |||
| 68 | my $self = $class->SUPER::new(); | ||
| 69 | |||
| 70 | if ( $e1->strand() == -1 ) { | ||
| 71 | $self->{'end'} = $e1->start() - 1; | ||
| 72 | $self->{'start'} = $e2->end() + 1; | ||
| 73 | } else { | ||
| 74 | $self->{'start'} = $e1->end() + 1; | ||
| 75 | $self->{'end'} = $e2->start() - 1; | ||
| 76 | } | ||
| 77 | |||
| 78 | if ( $e1->strand() != $e2->strand() ) { | ||
| 79 | # throw("Exons on different strand. Not allowed"); | ||
| 80 | } else { | ||
| 81 | $self->{'strand'} = $e1->strand(); | ||
| 82 | } | ||
| 83 | |||
| 84 | if ( $e1->slice() != $e2->slice() ) { | ||
| 85 | if ( ( $e1->slice()->seq_region_name() ne | ||
| 86 | $e2->slice()->seq_region_name() ) | ||
| 87 | && ( $e1->slice()->coord_system_name() ne | ||
| 88 | $e2->slice()->coord_system_name() ) ) | ||
| 89 | { | ||
| 90 | throw("Exons on different slices. Not allowed"); | ||
| 91 | } else { | ||
| 92 | warning("Exons have different slice references to the same seq_region"); | ||
| 93 | } | ||
| 94 | } else { | ||
| 95 | $self->{'slice'} = $e1->slice(); | ||
| 96 | } | ||
| 97 | |||
| 98 | if($analysis) { | ||
| 99 | $self->analysis($analysis); | ||
| 100 | } | ||
| 101 | |||
| 102 | $self->{'prev'} = $e1; | ||
| 103 | $self->{'next'} = $e2; | ||
| 104 | |||
| 105 | return $self; | ||
| 106 | } ## end sub new | ||
| 107 | |||
| 108 | =head2 length | ||
| 109 | |||
| 110 | Args : none | ||
| 111 | Example : $length = $intron->length(); | ||
| 112 | Description: Returns the length of this intron | ||
| 113 | Returntype : Integer | ||
| 114 | Exceptions : none | ||
| 115 | Caller : general | ||
| 116 | Status : Stable | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | sub length { | ||
| 121 | my ($self) = @_; | ||
| 122 | |||
| 123 | # TODO: Introns on circular slices, see Feature.pm but allow for | ||
| 124 | # zero-length introns. | ||
| 125 | |||
| 126 | return $self->{'end'} - $self->{'start'} + 1; | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | =head2 prev_Exon | ||
| 131 | |||
| 132 | Args : none | ||
| 133 | Example : $exon = $intron->prev_Exon | ||
| 134 | Description: Returns the exon before this Intron | ||
| 135 | Returntype : Bio::EnsEMBL::Exon | ||
| 136 | Exceptions : none | ||
| 137 | Caller : general | ||
| 138 | Status : Stable | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | sub prev_Exon { | ||
| 143 | my ($self) = shift; | ||
| 144 | |||
| 145 | return $self->{'prev'}; | ||
| 146 | } | ||
| 147 | |||
| 148 | |||
| 149 | =head2 next_Exon | ||
| 150 | |||
| 151 | Args : none | ||
| 152 | Example : $exon = $intron->next_Exon | ||
| 153 | Description: Returns the exon after this Intron | ||
| 154 | Returntype : Bio::EnsEMBL::Exon | ||
| 155 | Exceptions : none | ||
| 156 | Caller : general | ||
| 157 | Status : Stable | ||
| 158 | |||
| 159 | =cut | ||
| 160 | |||
| 161 | sub next_Exon { | ||
| 162 | my ($self) = shift; | ||
| 163 | |||
| 164 | return $self->{'next'}; | ||
| 165 | } | ||
| 166 | |||
| 167 | =head2 rank | ||
| 168 | |||
| 169 | Args : none | ||
| 170 | Example : $rank = $intron->rank | ||
| 171 | Description: Returns the rank of this Intron | ||
| 172 | Returntype : Integer | ||
| 173 | Exceptions : none | ||
| 174 | Caller : general | ||
| 175 | Status : Stable | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | sub rank { | ||
| 180 | my ($self, $transcript) = @_; | ||
| 181 | |||
| 182 | return $self->prev_Exon->rank($transcript); | ||
| 183 | } | ||
| 184 | |||
| 185 | =head2 is_splice_canonical | ||
| 186 | |||
| 187 | Example : my $canonical = $intron->is_splice_canonical(); | ||
| 188 | Description : Indicates if the splice site is considered normal. This means | ||
| 189 | splice site variants equal to (D == donor, A == acceptor) | ||
| 190 | GT (D) => AG (A) | ||
| 191 | AT (D) => AC (A) | ||
| 192 | GC (D) => AG (A) | ||
| 193 | Returntype : Boolean indicating if the splice was as expected | ||
| 194 | Exceptions : See splice_seq | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub is_splice_canonical { | ||
| 199 | my ($self) = @_; | ||
| 200 | my $splice = join q{}, @{$self->splice_seq()}; | ||
| 201 | my $canonical = { | ||
| 202 | 'GTAG' => 1, 'ATAC' => 1, 'GCAG' => 1 | ||
| 203 | }->{$splice}; | ||
| 204 | return $canonical || 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | =head2 splice_seq | ||
| 208 | |||
| 209 | Example : my ($donor, $acceptor) = @{$intron->splice_seq}; | ||
| 210 | Description : Get the donor and acceptor splice sites for this intron | ||
| 211 | Returntype : ArrayRef[String] The donor and acceptor sequences as Strings | ||
| 212 | Exceptions : Thrown if a feature Slice cannot be found | ||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | sub splice_seq { | ||
| 217 | my ($self) = @_; | ||
| 218 | my $slice = $self->feature_Slice(); | ||
| 219 | throw "Cannot retrieve feature_Slice() for this Intron" unless $slice; | ||
| 220 | my $length = $self->length(); | ||
| 221 | my $donor_seq = uc($slice->subseq(1,2)); | ||
| 222 | my $acceptor_seq = uc($slice->subseq($length - 1, $length)); | ||
| 223 | return [$donor_seq, $acceptor_seq]; | ||
| 224 | } | ||
| 225 | |||
| 226 | 1; | ||
| 227 | |||
| 228 |