Bio::Tools::CodonTable and Bio::Tools::IUPAC: use our and drop BEGIN blocks.
[bioperl-live.git] / lib / Bio / Tools / tRNAscanSE.pm
blobb26a744c0bc3da7c74e71aead475ddf0724959d3
2 # BioPerl module for Bio::Tools::tRNAscanSE
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason-at-bioperl.org>
8 # Copyright Jason Stajich
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::Tools::tRNAscanSE - A parser for tRNAscan-SE output
18 =head1 SYNOPSIS
20 use Bio::Tools::tRNAscanSE;
22 my $parser = Bio::Tools::tRNAscanSE->new(-file => 'result.tRNAscanSE');
24 # parse the results
25 while( my $gene = $parser->next_prediction ) {
27 @exon_arr = $gene->get_SeqFeatures();
31 =head1 DESCRIPTION
33 This script will parse tRNAscan-SE output. Just the tabular output of
34 the tRNA locations in the genome for now.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
58 =head2 Reporting Bugs
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via the
62 web:
64 https://github.com/bioperl/bioperl-live/issues
66 =head1 AUTHOR - Jason Stajich
68 Email jason-at-bioperl.org
70 =head1 APPENDIX
72 The rest of the documentation details each of the object methods.
73 Internal methods are usually preceded with a _
75 =cut
78 # Let the code begin...
81 package Bio::Tools::tRNAscanSE;
83 use strict;
85 use Bio::SeqFeature::Generic;
87 use base qw(Bio::Tools::AnalysisResult);
89 use vars qw($GeneTag $SrcTag $ExonTag);
90 ($GeneTag,$SrcTag,$ExonTag) = qw(gene tRNAscan-SE exon);
92 =head2 new
94 Title : new
95 Usage : my $obj = Bio::Tools::tRNAscanSE->new();
96 Function: Builds a new Bio::Tools::tRNAscanSE object
97 Returns : an instance of Bio::Tools::tRNAscanSE
98 Args : -fh/-file for input filename
99 -genetag => primary tag used in gene features (default 'tRNA_gene')
100 -exontag => primary tag used in exon features (default 'tRNA_exon')
101 -srctag => source tag used in all features (default 'tRNAscan-SE')
104 =cut
106 sub _initialize {
107 my($self,@args) = @_;
108 $self->SUPER::_initialize(@args);
109 my ($genetag,$exontag,$srctag) = $self->SUPER::_rearrange([qw(GENETAG
110 SRCTAG
111 EXONTAG)],
112 @args);
113 $self->gene_tag(defined $genetag ? $genetag : $GeneTag);
114 $self->source_tag(defined $srctag ? $srctag : $SrcTag);
115 $self->exon_tag(defined $exontag ? $exontag : $ExonTag);
116 $self->{'_seen'} = {};
119 =head2 gene_tag
121 Title : gene_tag
122 Usage : $obj->gene_tag($newval)
123 Function: Get/Set the value used for the 'gene_tag' of genes
124 Default is 'tRNA_gene' as set by the global $GeneTag
125 Returns : value of gene_tag (a scalar)
126 Args : on set, new value (a scalar or undef, optional)
129 =cut
131 sub gene_tag{
132 my $self = shift;
134 return $self->{'gene_tag'} = shift if @_;
135 return $self->{'gene_tag'};
138 =head2 source_tag
140 Title : source_tag
141 Usage : $obj->source_tag($newval)
142 Function: Get/Set the value used for the 'source_tag' of exons and genes
143 Default is 'tRNAscan-SE' as set by the global $SrcTag
144 Returns : value of source_tag (a scalar)
145 Args : on set, new value (a scalar or undef, optional)
148 =cut
150 sub source_tag{
151 my $self = shift;
153 return $self->{'_source_tag'} = shift if @_;
154 return $self->{'_source_tag'};
157 =head2 exon_tag
159 Title : exon_tag
160 Usage : $obj->exon_tag($newval)
161 Function: Get/Set the value used for the 'primary_tag' of exons
162 Default is 'tRNA_exon' as set by the global $ExonTag
163 Returns : value of exon_tag (a scalar)
164 Args : on set, new value (a scalar or undef, optional)
167 =cut
169 sub exon_tag{
170 my $self = shift;
172 return $self->{'_exon_tag'} = shift if @_;
173 return $self->{'_exon_tag'};
177 =head2 analysis_method
179 Usage : $genscan->analysis_method();
180 Purpose : Inherited method. Overridden to ensure that the name matches
181 /tRNAscan-SE/i.
182 Returns : String
183 Argument : n/a
185 =cut
187 #-------------
188 sub analysis_method {
189 #-------------
190 my ($self, $method) = @_;
191 if($method && ($method !~ /tRNAscan-SE/i)) {
192 $self->throw("method $method not supported in " . ref($self));
194 return $self->SUPER::analysis_method($method);
197 =head2 next_feature
199 Title : next_feature
200 Usage : while($gene = $genscan->next_feature()) {
201 # do something
203 Function: Returns the next gene structure prediction of the Genscan result
204 file. Call this method repeatedly until FALSE is returned.
206 The returned object is actually a SeqFeatureI implementing object.
207 This method is required for classes implementing the
208 SeqAnalysisParserI interface, and is merely an alias for
209 next_prediction() at present.
211 Example :
212 Returns : A Bio::SeqFeature::Generic object.
213 Args :
214 See also : L<Bio::SeqFeature::Generic>
216 =cut
218 sub next_feature {
219 my ($self,@args) = @_;
220 # even though next_prediction doesn't expect any args (and this method
221 # does neither), we pass on args in order to be prepared if this changes
222 # ever
223 return $self->next_prediction(@args);
226 =head2 next_prediction
228 Title : next_prediction
229 Usage : while($gene = $genscan->next_prediction()) {
230 # do something
232 Function: Returns the next gene structure prediction of the Genscan result
233 file. Call this method repeatedly until FALSE is returned.
235 Example :
236 Returns : A Bio::SeqFeature::Generic object.
237 Args :
238 See also : L<Bio::SeqFeature::Generic>
240 =cut
242 sub next_prediction {
243 my ($self) = @_;
244 my ($genetag,$srctag,$exontag) = ( $self->gene_tag,
245 $self->source_tag,
246 $self->exon_tag);
248 while( defined($_ = $self->_readline) ) {
249 if( m/^(\S+)\s+ # sequence name
250 (\d+)\s+ # tRNA #
251 (\d+)\s+(\d+)\s+ # tRNA start,end
252 (\w{3})\s+ # tRNA type
253 ([CAGT]{3})\s+ # Codon
254 (\d+)\s+(\d+)\s+ # Intron Begin End
255 (\d+\.\d+)/ox # Cove Score
258 my ($seqid,$tRNAnum,$start,$end,$type,
259 $codon,$intron_start,$intron_end,
260 $score) = ($1,$2,$3,$4,$5,$6,$7,$8,$9);
262 my $strand = 1;
263 if( $start > $end ) {
264 ($start,$end,$strand) = ($end,$start,-1);
266 if( $self->{'_seen'}->{$type}++ ) {
267 $type .= "-".$self->{'_seen'}->{$type};
269 my $gene = Bio::SeqFeature::Generic->new
270 ( -seq_id => $seqid,
271 -start => $start,
272 -end => $end,
273 -strand => $strand,
274 -score => $score,
275 -primary_tag => $genetag,
276 -source_tag => $srctag,
277 -tag => {
278 'ID' => "tRNA:$type",
279 'Name' => "tRNA:$type",
280 'AminoAcid' => $type,
281 'Codon' => $codon,
283 if( $intron_start ) {
284 if( $intron_start > $intron_end ) {
285 ($intron_start,$intron_end) = ($intron_end,$intron_start);
287 $gene->add_SeqFeature(Bio::SeqFeature::Generic->new
288 ( -seq_id=> $seqid,
289 -start => $start,
290 -end => $intron_start-1,
291 -strand=> $strand,
292 -primary_tag => $exontag,
293 -source_tag => $srctag,
294 -tag => {
295 'Parent' => "tRNA:$type",
296 }));
297 $gene->add_SeqFeature(Bio::SeqFeature::Generic->new
298 ( -seq_id=> $seqid,
299 -start => $intron_end+1,
300 -end => $end,
301 -strand=> $strand,
302 -primary_tag => $exontag,
303 -source_tag => $srctag,
304 -tag => {
305 'Parent' => "tRNA:$type"
306 }));
307 } else {
308 $gene->add_SeqFeature(Bio::SeqFeature::Generic->new
309 ( -seq_id=> $seqid,
310 -start => $start,
311 -end => $end,
312 -strand=> $strand,
313 -primary_tag => $exontag,
314 -source_tag => $srctag,
315 -tag => {
316 'Parent' => "tRNA:$type"
317 }));
319 return $gene;