changes all issue tracking in preparation for switch to github issues
[bioperl-live.git] / Bio / SeqFeature / Gene / Exon.pm
bloba2de11698bece9c79a75a4d0b1b5d5a44c90abd5
2 # BioPerl module for Bio::SeqFeature::Gene::Exon
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Hilmar Lapp <hlapp@gmx.net>
8 # Copyright Hilmar Lapp
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::SeqFeature::Gene::Exon - a feature representing an exon
18 =head1 SYNOPSIS
20 # obtain an exon instance $exon somehow
21 print "exon from ", $exon->start(), " to ", $exon->end(),
22 " on seq ", $exon->seq_id(), ", strand ", $exon->strand(),
23 ", encodes the peptide sequence ",
24 $exon->cds()->translate()->seq(), "\n";
26 =head1 DESCRIPTION
28 This module implements a feature representing an exon by implementing
29 the Bio::SeqFeature::Gene::ExonI interface. By default an Exon is
30 coding. Supply -is_coding =E<gt> 0 to the constructor or call
31 $exon-E<gt>is_coding(0) otherwise.
33 Apart from that, this class also implements Bio::SeqFeatureI by
34 inheriting off Bio::SeqFeature::Generic.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this
41 and other Bioperl modules. Send your comments and suggestions preferably
42 to one of the Bioperl mailing lists.
43 Your participation is much appreciated.
45 bioperl-l@bioperl.org - General discussion
46 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
48 =head2 Support
50 Please direct usage questions or support issues to the mailing list:
52 I<bioperl-l@bioperl.org>
54 rather than to the module maintainer directly. Many experienced and
55 reponsive experts will be able look at the problem and quickly
56 address it. Please include a thorough description of the problem
57 with code and data examples if at all possible.
59 =head2 Reporting Bugs
61 Report bugs to the Bioperl bug tracking system to help us keep track
62 the bugs and their resolution. Bug reports can be submitted via the
63 web:
65 https://github.com/bioperl/bioperl-live/issues
67 =head1 AUTHOR - Hilmar Lapp
69 Email hlapp@gmx.net
71 =head1 APPENDIX
73 The rest of the documentation details each of the object methods.
74 Internal methods are usually preceded with a _
76 =cut
79 # Let the code begin...
82 package Bio::SeqFeature::Gene::Exon;
83 use strict;
86 use base qw(Bio::SeqFeature::Generic Bio::SeqFeature::Gene::ExonI);
89 # A list of allowed exon types. See primary_tag().
91 my @valid_exon_types = ('initial', 'internal', 'terminal');
93 sub new {
94 my ($caller, @args) = @_;
95 my $self = $caller->SUPER::new(@args);
97 my ($is_coding) =
98 $self->_rearrange([qw(IS_CODING)],@args);
99 $self->primary_tag('exon') unless $self->primary_tag();
100 $self->is_coding(defined($is_coding) ? $is_coding : 1);
101 $self->strand(0) if(! defined($self->strand()));
102 return $self;
106 =head2 is_coding
108 Title : is_coding
109 Usage : if($exon->is_coding()) {
110 # do something
112 if($is_utr) {
113 $exon->is_coding(0);
115 Function: Get/set whether or not the exon codes for amino acid.
116 Returns : TRUE if the object represents a feature translated into protein,
117 and FALSE otherwise.
118 Args : A boolean value on set.
121 =cut
123 sub is_coding {
124 my ($self,$val) = @_;
126 if(defined($val)) {
127 $self->{'_iscoding'} = $val;
129 return $self->{'_iscoding'};
132 =head2 primary_tag
134 Title : primary_tag
135 Usage : $tag = $feat->primary_tag()
136 $feat->primary_tag('exon')
137 Function: Get/set the primary tag for the exon feature.
139 This method is overridden here in order to allow only for
140 tag values following a certain convention. For consistency reasons,
141 the tag value must either contain the string 'exon' or the string
142 'utr' (both case-insensitive). In the case of 'exon', a string
143 describing the type of exon may be appended or prefixed. Presently,
144 the following types are allowed: initial, internal, and terminal
145 (all case-insensitive).
147 If the supplied tag value matches 'utr' (case-insensitive),
148 is_coding() will automatically be set to FALSE, and to TRUE
149 otherwise.
151 Returns : A string.
152 Args : A string on set.
155 =cut
157 # sub primary_tag {
158 # my ($self,$value) = @_;
160 # if(defined($value)) {
161 # if((lc($value) =~ /utr/i) || (lc($value) eq "exon") ||
162 # ((lc($value) =~ /exon/i) &&
163 # (grep { $value =~ /$_/i; } @valid_exon_types))) {
164 # $self->is_coding($value =~ /utr/i ? 0 : 1);
165 # } else {
166 # $self->throw("primary tag $value is invalid for object of class ".
167 # ref($self));
170 # return $self->SUPER::primary_tag($value);
173 =head2 location
175 Title : location
176 Usage : my $location = $exon->location()
177 Function: Returns a location object suitable for identifying the location
178 of the exon on the sequence or parent feature.
180 This method is overridden here to restrict allowed location types
181 to non-compound locations.
183 Returns : Bio::LocationI object
184 Args : none
187 =cut
189 sub location {
190 my ($self,$value) = @_;
192 if(defined($value) && $value->isa('Bio::Location::SplitLocationI')) {
193 $self->throw("split or compound location is not allowed ".
194 "for an object of type " . ref($self));
196 return $self->SUPER::location($value);
199 =head2 cds
201 Title : cds()
202 Usage : $cds = $exon->cds();
203 Function: Get the coding sequence of the exon as a sequence object.
205 The sequence of the returned object is prefixed by Ns (lower case)
206 if the frame of the exon is defined and different from zero. The
207 result is that the first base starts a codon (frame 0).
209 This implementation returns undef if the particular exon is
210 not translated to protein, i.e., is_coding() returns FALSE. Undef
211 will also be returned if no sequence is attached to this exon
212 feature.
214 Returns : A Bio::PrimarySeqI implementing object.
215 Args :
218 =cut
220 sub cds {
221 my ($self) = @_;
223 # UTR is not translated
224 return if(! $self->is_coding());
226 my $seq = $self->seq();
227 if(defined($seq) && defined($self->frame()) && ($self->frame() != 0)) {
228 my $prefix = "n" x $self->frame();
229 $seq->seq($prefix . $seq->seq());
231 return $seq;