File Coverage

Bio/SeqFeature/Gene/Exon.pm
Criterion Covered Total %
statement 27 28 96.4
branch 11 14 78.5
condition 4 9 44.4
subroutine 6 6 100.0
pod 4 4 100.0
total 52 61 85.2


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::SeqFeature::Gene::Exon
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Hilmar Lapp
7             #
8             # Copyright Hilmar Lapp
9             #
10             # You may distribute this module under the same terms as perl itself
11              
12             # POD documentation - main docs before the code
13              
14             =head1 NAME
15              
16             Bio::SeqFeature::Gene::Exon - a feature representing an exon
17              
18             =head1 SYNOPSIS
19              
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";
25              
26             =head1 DESCRIPTION
27              
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 0 to the constructor or call
31             $exon-Eis_coding(0) otherwise.
32              
33             Apart from that, this class also implements Bio::SeqFeatureI by
34             inheriting off Bio::SeqFeature::Generic.
35              
36             =head1 FEEDBACK
37              
38             =head2 Mailing Lists
39              
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.
44              
45             bioperl-l@bioperl.org - General discussion
46             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47              
48             =head2 Support
49              
50             Please direct usage questions or support issues to the mailing list:
51              
52             I
53              
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.
58              
59             =head2 Reporting Bugs
60              
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:
64              
65             https://github.com/bioperl/bioperl-live/issues
66              
67             =head1 AUTHOR - Hilmar Lapp
68              
69             Email hlapp@gmx.net
70              
71             =head1 APPENDIX
72              
73             The rest of the documentation details each of the object methods.
74             Internal methods are usually preceded with a _
75              
76             =cut
77              
78              
79             # Let the code begin...
80              
81              
82             package Bio::SeqFeature::Gene::Exon;
83 9     9   50 use strict;
  9         16  
  9         245  
84              
85              
86 9     9   41 use base qw(Bio::SeqFeature::Generic Bio::SeqFeature::Gene::ExonI);
  9         11  
  9         2336  
87              
88             #
89             # A list of allowed exon types. See primary_tag().
90             #
91             my @valid_exon_types = ('initial', 'internal', 'terminal');
92              
93             sub new {
94 511     511 1 1032 my ($caller, @args) = @_;
95 511         1082 my $self = $caller->SUPER::new(@args);
96              
97 511         1177 my ($is_coding) =
98             $self->_rearrange([qw(IS_CODING)],@args);
99 511 100       1128 $self->primary_tag('exon') unless $self->primary_tag();
100 511 100       1210 $self->is_coding(defined($is_coding) ? $is_coding : 1);
101 511 100       780 $self->strand(0) if(! defined($self->strand()));
102 511         1160 return $self;
103             }
104              
105              
106             =head2 is_coding
107              
108             Title : is_coding
109             Usage : if($exon->is_coding()) {
110             # do something
111             }
112             if($is_utr) {
113             $exon->is_coding(0);
114             }
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.
119              
120              
121             =cut
122              
123             sub is_coding {
124 798     798 1 996 my ($self,$val) = @_;
125              
126 798 100       1098 if(defined($val)) {
127 757         914 $self->{'_iscoding'} = $val;
128             }
129 798         984 return $self->{'_iscoding'};
130             }
131              
132             =head2 primary_tag
133              
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.
138              
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).
146              
147             If the supplied tag value matches 'utr' (case-insensitive),
148             is_coding() will automatically be set to FALSE, and to TRUE
149             otherwise.
150              
151             Returns : A string.
152             Args : A string on set.
153              
154              
155             =cut
156              
157             # sub primary_tag {
158             # my ($self,$value) = @_;
159              
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));
168             # }
169             # }
170             # return $self->SUPER::primary_tag($value);
171             # }
172              
173             =head2 location
174              
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.
179              
180             This method is overridden here to restrict allowed location types
181             to non-compound locations.
182              
183             Returns : Bio::LocationI object
184             Args : none
185              
186              
187             =cut
188              
189             sub location {
190 5665     5665 1 6382 my ($self,$value) = @_;
191              
192 5665 50 66     7833 if(defined($value) && $value->isa('Bio::Location::SplitLocationI')) {
193 0         0 $self->throw("split or compound location is not allowed ".
194             "for an object of type " . ref($self));
195             }
196 5665         8012 return $self->SUPER::location($value);
197             }
198              
199             =head2 cds
200              
201             Title : cds()
202             Usage : $cds = $exon->cds();
203             Function: Get the coding sequence of the exon as a sequence object.
204              
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).
208              
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.
213              
214             Returns : A Bio::PrimarySeqI implementing object.
215             Args :
216              
217              
218             =cut
219              
220             sub cds {
221 1     1 1 2 my ($self) = @_;
222              
223             # UTR is not translated
224 1 50       3 return if(! $self->is_coding());
225              
226 1         116 my $seq = $self->seq();
227 1 50 33     5 if(defined($seq) && defined($self->frame()) && ($self->frame() != 0)) {
      33        
228 1         3 my $prefix = "n" x $self->frame();
229 1         79 $seq->seq($prefix . $seq->seq());
230             }
231 1         3 return $seq;
232             }
233              
234             1;