Bio/Tools/tRNAscanSE.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 80.7% 21 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 100% 6 / 6 totaltotal 82.5% 85 / 103 CC 15 SCAR 15.7
CC
15
Cov
83%
analysis_method
12.0
next_prediction
7.0
_initialize
4.2
CRAP 4.8
« Bio/SeqIO/MultiFile.pm ↑ Summary Bio/Tools/Geneid.pm »
1 #
2 # BioPerl module for Bio::Tools::tRNAscanSE
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl.org>
7 #
8 # Copyright Jason Stajich
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::Tools::tRNAscanSE - A parser for tRNAscan-SE output
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tools::tRNAscanSE;
21  
22 my $parser = Bio::Tools::tRNAscanSE->new(-file => 'result.tRNAscanSE');
23  
24 # parse the results
25 while( my $gene = $parser->next_prediction ) {
26  
27 @exon_arr = $gene->get_SeqFeatures();
28  
29 }
30  
31 =head1 DESCRIPTION
32  
33 This script will parse tRNAscan-SE output. Just the tabular output of
34 the tRNA locations in the genome for now.
35  
36 =head1 FEEDBACK
37  
38 =head2 Mailing Lists
39  
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.
43  
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46  
47 =head2 Support
48  
49 Please direct usage questions or support issues to the mailing list:
50  
51 I<bioperl-l@bioperl.org>
52  
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.
57  
58 =head2 Reporting Bugs
59  
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:
63  
64 https://github.com/bioperl/bioperl-live/issues
65  
66 =head1 AUTHOR - Jason Stajich
67  
68 Email jason-at-bioperl.org
69  
70 =head1 APPENDIX
71  
72 The rest of the documentation details each of the object methods.
73 Internal methods are usually preceded with a _
74  
75 =cut
76  
77  
78 # Let the code begin...
79  
80  
81 package Bio::Tools::tRNAscanSE;
82 2 $Bio::Tools::tRNAscanSE::VERSION = '1.7.8';
83 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 2 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 2 ▶use base qw(Bio::Tools::AnalysisResult);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 ▶use vars qw($GeneTag $SrcTag $ExonTag);
Subroutine BEGIN: called CC=1 SCAR=0.0
90 2 ($GeneTag,$SrcTag,$ExonTag) = qw(gene tRNAscan-SE exon);
91  
92 =head2 new
93  
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')
102  
103  
104 =cut
105  
106 1 ▶sub _initialize {
Subroutine _initialize: called CC=4 SCAR=14.3
107 1 my($self,@args) = @_;
108 1 $self->SUPER::_initialize(@args);
109 1 my ($genetag,$exontag,$srctag) = $self->SUPER::_rearrange([qw(GENETAG
110 SRCTAG
111 EXONTAG)],
112 @args);
113 1 ▶ $self->gene_tag(defined $genetag ? $genetag : $GeneTag);
Branch: 1 branch
BranchTrueFalseTotal
defined $genetag ? : 0 1 1
114 1 ▶ $self->source_tag(defined $srctag ? $srctag : $SrcTag);
Branch: 1 branch
BranchTrueFalseTotal
defined $srctag ? : 0 1 1
115 1 ▶ $self->exon_tag(defined $exontag ? $exontag : $ExonTag);
Branch: 1 branch
BranchTrueFalseTotal
defined $exontag ? : 0 1 1
116 1 $self->{'_seen'} = {};
117 }
118  
119 =head2 gene_tag
120  
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)
127  
128  
129 =cut
130  
131 289 ▶sub gene_tag{
Subroutine gene_tag: called CC=2 SCAR=6.9
Pod documented
132 289 my $self = shift;
133  
134 289 ▶ return $self->{'gene_tag'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 288 289
135 288 return $self->{'gene_tag'};
136 }
137  
138 =head2 source_tag
139  
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)
146  
147  
148 =cut
149  
150 289 ▶sub source_tag{
Subroutine source_tag: called CC=2 SCAR=6.9
Pod documented
151 289 my $self = shift;
152  
153 289 ▶ return $self->{'_source_tag'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 288 289
154 288 return $self->{'_source_tag'};
155 }
156  
157 =head2 exon_tag
158  
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)
165  
166  
167 =cut
168  
169 289 ▶sub exon_tag{
Subroutine exon_tag: called CC=2 SCAR=6.9
Pod documented
170 289 my $self = shift;
171  
172 289 ▶ return $self->{'_exon_tag'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 288 289
173 288 return $self->{'_exon_tag'};
174 }
175  
176  
177 =head2 analysis_method
178  
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
184  
185 =cut
186  
187 #-------------
188 0 ▶sub analysis_method {
Subroutine analysis_method: not called CC=3 SCAR=24.8
Pod documented
189 #-------------
190 0 my ($self, $method) = @_;
191 0 ▶ if($method && ($method !~ /tRNAscan-SE/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method and not $method =~ /tRNAscan-SE/i) 0 0 0
Condition0%0/3
$method and not $method =~ /tRNAscan-SE/i
!ll&&!rl&&r
000
MC/DC0%0/2
$method and not $method =~ /tRNAscan-SE/i
$method not $method =~ /tRNAscan-SE/i
Truth table0%0/3
A and not(B)
A= $methodB= not $method =~ /tRNAscan-SE/i
ABresult
0X0
100
111
192 0 $self->throw("method $method not supported in " . ref($self));
193 }
194 0 return $self->SUPER::analysis_method($method);
195 }
196  
197 =head2 next_feature
198  
199 Title : next_feature
200 Usage : while($gene = $genscan->next_feature()) {
201 # do something
202 }
203 Function: Returns the next gene structure prediction of the Genscan result
204 file. Call this method repeatedly until FALSE is returned.
205  
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.
210  
211 Example :
212 Returns : A Bio::SeqFeature::Generic object.
213 Args :
214 See also : L<Bio::SeqFeature::Generic>
215  
216 =cut
217  
218 0 ▶sub next_feature {
Subroutine next_feature: not called CC=1 SCAR=6.9
Pod documented
219 0 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 0 return $self->next_prediction(@args);
224 }
225  
226 =head2 next_prediction
227  
228 Title : next_prediction
229 Usage : while($gene = $genscan->next_prediction()) {
230 # do something
231 }
232 Function: Returns the next gene structure prediction of the Genscan result
233 file. Call this method repeatedly until FALSE is returned.
234  
235 Example :
236 Returns : A Bio::SeqFeature::Generic object.
237 Args :
238 See also : L<Bio::SeqFeature::Generic>
239  
240 =cut
241  
242 288 ▶sub next_prediction {
Subroutine next_prediction: called CC=7 SCAR=19.5
Pod documented
243 288 my ($self) = @_;
244 288 my ($genetag,$srctag,$exontag) = ( $self->gene_tag,
245 $self->source_tag,
246 $self->exon_tag);
247  
248 288 ▶ while( defined($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 298 1 299
249 298 ▶ if( m/^(\S+)\s+ # sequence name
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\S+)\s+ # sequence name (\d+)\s+ # tRNA # (\d+)\s+(\d+)\s+ # tRNA start,end (\w{3})\s+ # tRNA type ([CAGT]{3})\s+ # Codon (\d+)\s+(\d+)\s+ # Intron Begin End (\d+\.\d+)/ox) 287 11 298
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
256 ) {
257
258 287 my ($seqid,$tRNAnum,$start,$end,$type,
259 $codon,$intron_start,$intron_end,
260 $score) = ($1,$2,$3,$4,$5,$6,$7,$8,$9);
261
262 287 my $strand = 1;
263 287 ▶ if( $start > $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $end) 131 156 287
264 131 ($start,$end,$strand) = ($end,$start,-1);
265 }
266 287 ▶ if( $self->{'_seen'}->{$type}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_seen"}{$type}++) 266 21 287
267 266 $type .= "-".$self->{'_seen'}->{$type};
268 }
269 287 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,
282 });
283 287 ▶ if( $intron_start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intron_start) { } 59 228 287
284 59 ▶ if( $intron_start > $intron_end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intron_start > $intron_end) 23 36 59
285 23 ($intron_start,$intron_end) = ($intron_end,$intron_start);
286 }
287 59 $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 59 $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 228 $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 }));
318 }
319 287 return $gene;
320 }
321 }
322 }
323  
324 2 1;
« Bio/SeqIO/MultiFile.pm ↑ Summary Bio/Tools/Geneid.pm »