Bio/Tools/QRNA.pm

filter: Statementstmt 92.1% 117 / 127 Branchbran 88.8% 64 / 72 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 89.8% 213 / 237 CC 43 SCAR 25.7
CC
43
Cov
90%
_parse_pair
24.2
_make_feature
9.9
next_feature
5.0
CRAP 13.0
« Bio/AlignIO/fasta.pm ↑ Summary Bio/Index/Fasta.pm »
1 #
2 # BioPerl module for Bio::Tools::QRNA
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl-dot-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::QRNA - A Parser for qrna output
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tools::QRNA;
21 my $parser = Bio::Tools::QRNA->new(-file => $qrnaoutput);
22 while( my $feature = $parser->next_feature ) {
23 # do something here
24 }
25  
26 =head1 DESCRIPTION
27  
28 Parses QRNA output (E.Rivas:
29 http://selab.janelia.org/software.html
30 ftp://selab.janelia.org/pub/software/qrna/).
31  
32 This module is not complete, but currently it packs information from
33 each QRNA alignment into a single Bio::SeqFeature::Generic object.
34  
35 Not all options for QRNA output have been tested or tried. It has
36 been tested on sliding window output (-w -x) and shuffled output (-b
37 or -B).
38  
39 See t/QRNA.t for example usage.
40  
41 At some point we may have more complicated feature object which will
42 support this data rather than forcing most of the information into
43 tag/value pairs in a SeqFeature::Generic.
44  
45 Running with -verbose =E<gt> 1 will store extra data in the feature. The
46 entire unparsed entry for a particular feature will be stored as a
47 string in the tag 'entry' it is accessible via:
48  
49 my ($entry) = $f->each_tag_value('entry');
50  
51 The winning model for any given alignment test will be the name stored
52 in the primary_tag field of feature. The bit score will stored in the
53 score field. The logoddpost is available via the a tag/value pair.
54 This example code will show how to print out the score and log odds
55 post for each model.
56  
57 # assuming you got a feature already
58 print "model score logoddspost\n";
59 foreach my $model ( qw(OTH COD RNA) ) {
60 my ($score) = $f->get_tag_values("$model\_score");
61 my ($logoddspost) = $f->get_tag_values("$model\_logoddspost");
62 print "$model $score $logoddspost\n";
63 }
64  
65 The start and end of the alignment for both the query and hit sequence
66 are available through the L<Bio::SeqFeature::FeaturePair> interface,
67 specifically L<Bio::SeqFeature::FeaturePair::feature1> and
68 L<Bio::SeqFeature::FeaturePair::feature2>. Additionally if you have
69 run QRNA with an input file which has the location of the alignment
70 stored in the FASTA filename as in (ID/START-END) which is the default
71 output format from L<Bio::AlignIO::fasta> produced alignment output,
72 this module will re-number start/end for the two sequences so they are
73 in the actual coordinates of the sequence rather than the relative
74 coordinates of the alignment. You may find the bioperl utillity
75 script search2alnblocks useful in creating your input files for QRNA.
76  
77 Some other words of warning, QRNA uses a 0 based numbering system for
78 sequence locations, Bioperl uses a 1 based system. You'll notice that
79 locations will be +1 they are reported in the raw QRNA output.
80  
81 =head1 FEEDBACK
82  
83 =head2 Mailing Lists
84  
85 User feedback is an integral part of the evolution of this and other
86 Bioperl modules. Send your comments and suggestions preferably to
87 the Bioperl mailing list. Your participation is much appreciated.
88  
89 bioperl-l@bioperl.org - General discussion
90 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
91  
92 =head2 Support
93  
94 Please direct usage questions or support issues to the mailing list:
95  
96 I<bioperl-l@bioperl.org>
97  
98 rather than to the module maintainer directly. Many experienced and
99 reponsive experts will be able look at the problem and quickly
100 address it. Please include a thorough description of the problem
101 with code and data examples if at all possible.
102  
103 =head2 Reporting Bugs
104  
105 Report bugs to the Bioperl bug tracking system to help us keep track
106 of the bugs and their resolution. Bug reports can be submitted via
107 the web:
108  
109 https://github.com/bioperl/bioperl-live/issues
110  
111 =head1 AUTHOR - Jason Stajich
112  
113 Email jason-at-bioperl-dot-org
114  
115 =head1 APPENDIX
116  
117 The rest of the documentation details each of the object methods.
118 Internal methods are usually preceded with a _
119  
120 =cut
121  
122  
123 # Let the code begin...
124  
125  
126 package Bio::Tools::QRNA;
127 2 $Bio::Tools::QRNA::VERSION = '1.7.8';
128 2 ▶use vars qw(@Models);
Subroutine BEGIN: called CC=1 SCAR=0.0
129 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 2 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 2 ▶use Bio::SeqFeature::FeaturePair;
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134 2 ▶use base qw(Bio::Root::IO Bio::SeqAnalysisParserI);
Subroutine BEGIN: called CC=1 SCAR=0.0
135 2 @Models = qw(OTH COD RNA);
136  
137 =head2 new
138  
139 Title : new
140 Usage : my $obj = Bio::Tools::QRNA->new();
141 Function: Builds a new Bio::Tools::QRNA object
142 Returns : an instance of Bio::Tools::QRNA
143 Args : -fh/-file filehandle/filename standard input for
144 Bio::Root:IO objects
145  
146 =cut
147  
148 =head2 next_feature
149  
150 Title : next_feature
151 Usage : my $feature = $parser->next_feature
152 Function: Get the next QRNA feature
153 Returns :
154 Args :
155  
156  
157 =cut
158  
159 48 ▶sub next_feature {
Subroutine next_feature: called CC=5 SCAR=16.2
Pod documented
160 48 my ($self) = @_;
161 48 ▶ my $f = shift @{$self->{'_parsed_features'} || []};
Condition100%2/2
$self->{'_parsed_features'} || []
l!l
462
MC/DC100%1/1
$self->{'_parsed_features'} || []
$self->{'_parsed_features'}
Truth table100%2/2
A
A= $self->{'_parsed_features'}
Aresult
11
00
162 48 ▶ if( ! defined $f && $self->_parse_pair ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $f and $self->_parse_pair) 47 1 48
Condition66%2/3
not defined $f and $self->_parse_pair
!ll&&!rl&&r
0147
MC/DC50%1/2
not defined $f and $self->_parse_pair
not defined $f $self->_parse_pair
Truth table66%2/3
not(A) and B
A= not defined $fB= $self->_parse_pair
ABresult
0X0
100
111
163 47 ▶ $f = shift @{$self->{'_parsed_features'} || []};
Condition50%1/2
$self->{'_parsed_features'} || []
l!l
470
MC/DC0%0/1
$self->{'_parsed_features'} || []
$self->{'_parsed_features'}
Truth table50%1/2
A
A= $self->{'_parsed_features'}
Aresult
11
00
164 }
165 48 return $f;
166 }
167  
168 48 ▶sub _parse_pair {
Subroutine _parse_pair: called CC=24 SCAR=31.9
169 48 my ($self,@args) = @_;
170 48 my (@features,%data);
171 48 my $seenstart = 0;
172 48 ▶ while( defined( $_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 927 2 929
173 927 ▶ next if( /^\#\-\-/o );
Branch: 1 branch
BranchTrueFalseTotal
if /^\#\-\-/o 12 915 927
174 915 ▶ if( /^\#\s+(qrna)\s+(\S+)\s+\(([^\)]+)\)/o ) {
Branch: 12 branches
BranchTrueFalseTotal
if (/^\#\s+(qrna)\s+(\S+)\s+\(([^\)]+)\)/o) { } 2 913 915
elsif (/^\#\s+(PAM model)\s+\=\s+(.+)\s+$/o) { } 2 911 913
elsif (/^\#\s+(RNA model)\s+\=\s+(\S+)/o) { } 2 909 911
elsif (/^\#\s+(seq file)\s+\=\s+(.+)\s+$/o) { } 2 907 909
elsif (/^\#\s+(\d+)\s+\[([\-+])\s+strand\]/o) { } 94 813 907
elsif (/^\#/) { } 4 809 813
elsif (/>(\S+)\s+\((\d+)\)/) { } 96 713 809
elsif (/^length alignment:\s+(\d+)\s+\(id\=(\d+(\.\d+)?)\)/o) { } 51 662 713
elsif (/^pos([XY]):\s+(\d+)\-(\d+)\s+\[(\d+)\-(\d+)\]\((\d+)\)\s+ \-\-\s+\((\S+\s+\S+\s+\S+\s+\S+)\)/ox) { } 102 560 662
elsif (/^winner\s+\=\s+(\S{3})/) { } 51 509 560
elsif (/^(\S{3})\s+ends\s+\=\s+(\-?\d+)\s+(\-?\d+)/) { } 153 356 509
elsif (/^\s+(logoddspost)?OTH\s+\=\s+/ox) { } 102 254 356
175 2 $self->program_name($1);
176 2 $self->program_version($2);
177 2 $self->program_date($3);
178 } elsif( /^\#\s+(PAM model)\s+\=\s+(.+)\s+$/o ) {
179 2 $self->PAM_model($2);
180 } elsif( /^\#\s+(RNA model)\s+\=\s+(\S+)/o ) {
181 2 $self->RNA_model($2);
182 } elsif( /^\#\s+(seq file)\s+\=\s+(.+)\s+$/o ) {
183 2 $self->seq_file($2);
184 } elsif( /^\#\s+(\d+)\s+\[([\-+])\s+strand\]/o ) {
185 94 ▶ if( $seenstart ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seenstart) 46 48 94
186 46 ▶ if( $data{'alignment_len'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"alignment_len"}) 46 0 46
187 46 push @features, $self->_make_feature(\%data);
188 }
189 46 $self->_pushback($_);
190 46 last;
191 }
192 48 $seenstart = 1;
193 } elsif( /^\#/ ) {
194 4 next;
195 } elsif( />(\S+)\s+\((\d+)\)/ ) {
196 96 ▶ if( @{$data{'seqs'} || []} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$data{'seqs'} or [];} == 2) { } 0 96 96
Condition100%2/2
$data{'seqs'} || []
l!l
4848
MC/DC100%1/1
$data{'seqs'} || []
$data{'seqs'}
Truth table100%2/2
A
A= $data{'seqs'}
Aresult
11
00
197 0 $self->warn( "already seen seqs ".join(' ', ,map { $_->[0] }
198 0 @{$data{'seqs'}}). "\n");
199 } else {
200 96 push @{$data{'seqs'}}, [$1,$2];
201 }
202 } elsif( /^length alignment:\s+(\d+)\s+\(id\=(\d+(\.\d+)?)\)/o ) {
203
204 51 ▶ if( $data{'alignment_len'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"alignment_len"}) 3 48 51
205 3 push @features, $self->_make_feature(\%data);
206 # reset all the data but the 'seqs' field
207 3 %data = ( 'seqs' => $data{'seqs'} );
208 }
209
210 51 ▶ if( /\(((sre_)?shuffled)\)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(((sre_)?shuffled)\)/) 0 51 51
211 0 $data{'shuffled'} = $1;
212 }
213 51 $data{'alignment_len'} = $1;
214 51 $data{'alignment_pid'} = $2;
215 } elsif ( /^pos([XY]):\s+(\d+)\-(\d+)\s+\[(\d+)\-(\d+)\]\((\d+)\)\s+
216 \-\-\s+\((\S+\s+\S+\s+\S+\s+\S+)\)/ox ) {
217 102 $data{"seq\_$1"}->{'aln'} = [ $2,$3, $4,$5, $6];
218 102 @{$data{"seq\_$1"}->{'base_comp'}} = split(/\s+/,$7);
219 } elsif( /^winner\s+\=\s+(\S{3})/ ) {
220 51 $data{'winning_model'} = $1;
221 } elsif( /^(\S{3})\s+ends\s+\=\s+(\-?\d+)\s+(\-?\d+)/ ) {
222 # QRNA is 0-based
223 # Bioperl is 1 based
224 153 $data{'model_location'}->{$1} = [ $2,$3 ];
225 } elsif( /^\s+(logoddspost)?OTH\s+\=\s+/ox ) {
226 102 ▶ while( /(\S+)\s+\=\s+(\-?\d+(\.\d+))/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(\S+)\s+\=\s+(\-?\d+(\.\d+))/g) 306 102 408
227 306 my ($model,$score)= ($1,$2);
228 306 ▶ if( $model =~ s/^logoddspost// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model =~ s/^logoddspost//) { } 153 153 306
229 153 $data{'model_scores'}->{'logoddspost'}->{$model} = $score;
230 } else {
231 153 $data{'model_scores'}->{'bits'}->{$model} = $score;
232 }
233 }
234 }
235 865 $data{'entry'} .= $_;
236 }
237 48 ▶ if( @features ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@features) 47 1 48
238 47 push @{$self->{'_parsed_features'}}, @features;
239 47 return scalar @features;
240 }
241 1 return 0;
242 }
243  
244 =head2 PAM_model
245  
246 Title : PAM_model
247 Usage : $obj->PAM_model($newval)
248 Function:
249 Example :
250 Returns : value of PAM_model (a scalar)
251 Args : on set, new value (a scalar or undef, optional)
252  
253  
254 =cut
255  
256 3 ▶sub PAM_model{
Subroutine PAM_model: called CC=2 SCAR=6.9
Pod documented
257 3 my $self = shift;
258 3 ▶ return $self->{'PAM_model'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 1 3
259 1 return $self->{'PAM_model'};
260 }
261  
262 =head2 RNA_model
263  
264 Title : RNA_model
265 Usage : $obj->RNA_model($newval)
266 Function:
267 Example :
268 Returns : value of RNA_model (a scalar)
269 Args : on set, new value (a scalar or undef, optional)
270  
271  
272 =cut
273  
274 3 ▶sub RNA_model{
Subroutine RNA_model: called CC=2 SCAR=6.9
Pod documented
275 3 my $self = shift;
276  
277 3 ▶ return $self->{'RNA_model'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 1 3
278 1 return $self->{'RNA_model'};
279 }
280  
281 =head2 seq_file
282  
283 Title : seq_file
284 Usage : $obj->seq_file($newval)
285 Function:
286 Example :
287 Returns : value of seq_file (a scalar)
288 Args : on set, new value (a scalar or undef, optional)
289  
290  
291 =cut
292  
293 3 ▶sub seq_file{
Subroutine seq_file: called CC=2 SCAR=6.9
Pod documented
294 3 my $self = shift;
295  
296 3 ▶ return $self->{'seq_file'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 1 3
297 1 return $self->{'seq_file'};
298 }
299  
300  
301 =head2 program_name
302  
303 Title : program_name
304 Usage : $obj->program_name($newval)
305 Function:
306 Example :
307 Returns : value of program_name (a scalar)
308 Args : on set, new value (a scalar or undef, optional)
309  
310  
311 =cut
312  
313 52 ▶sub program_name{
Subroutine program_name: called CC=3 SCAR=11.1
Pod documented
314 52 my $self = shift;
315  
316 52 ▶ return $self->{'program_name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 50 52
317 50 ▶ return $self->{'program_name'} || 'qrna';
Condition50%1/2
$self->{'program_name'} || 'qrna'
l!l
500
MC/DC0%0/1
$self->{'program_name'} || 'qrna'
$self->{'program_name'}
Truth table50%1/2
A
A= $self->{'program_name'}
Aresult
11
00
318 }
319  
320 =head2 program_version
321  
322 Title : program_version
323 Usage : $obj->program_version($newval)
324 Function:
325 Example :
326 Returns : value of program_version (a scalar)
327 Args : on set, new value (a scalar or undef, optional)
328  
329  
330 =cut
331  
332 3 ▶sub program_version{
Subroutine program_version: called CC=2 SCAR=6.9
Pod documented
333 3 my $self = shift;
334  
335 3 ▶ return $self->{'program_version'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 1 3
336 1 return $self->{'program_version'};
337 }
338  
339 =head2 program_date
340  
341 Title : program_date
342 Usage : $obj->program_date($newval)
343 Function:
344 Example :
345 Returns : value of program_date (a scalar)
346 Args : on set, new value (a scalar or undef, optional)
347  
348  
349 =cut
350  
351 3 ▶sub program_date{
Subroutine program_date: called CC=2 SCAR=6.9
Pod documented
352 3 my $self = shift;
353 3 ▶ return $self->{'program_date'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 1 3
354 1 return $self->{'program_date'};
355 }
356  
357 49 ▶sub _make_feature {
Subroutine _make_feature: called CC=9 SCAR=22.9
358 49 my ($self,$data) = @_;
359 49 my ($qoffset,$hoffset) = (1,1);
360 # when you run qrna and have produced ID/START-END
361 # formatted input strings we can remap the location
362 # to the original
363  
364 # name is stored as the first entry in the seq array ref
365 my ($qid,$hid) = ( $data->{'seqs'}->[0]->[0],
366 49 $data->{'seqs'}->[1]->[0]);
367 49 ▶ if( $qid =~ /(\S+)\/(\d+)\-(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qid =~ m[(\S+)/(\d+)\-(\d+)]) 3 46 49
368 3 ($qid,$qoffset) = ($1,$2);
369 }
370 49 ▶ if( $hid =~ /(\S+)\/(\d+)\-(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hid =~ m[(\S+)/(\d+)\-(\d+)]) 3 46 49
371 3 ($hid,$hoffset) = ($1,$2);
372 }
373  
374 49 my $f = Bio::SeqFeature::FeaturePair->new();
375  
376 49 my ($s,$e) = @{$data->{'model_location'}->{$data->{'winning_model'}}};
377 my $qf = Bio::SeqFeature::Generic->new
378 ( -primary_tag => $data->{'winning_model'},
379 -source_tag => $self->program_name,
380 49 ▶ -score => $data->{'model_scores'}->{'bits'}->{$data->{'winning_model'}},
Branch: 1 branch
BranchTrueFalseTotal
$s < $e ? : 23 26 49
381 -start => $s+$qoffset,
382 -end => $e+$qoffset,
383 -seq_id => $qid,
384 -strand => ($s < $e ) ? 1 : -1,
385 );
386  
387 49 my $hf = Bio::SeqFeature::Generic->new
388 ( -primary_tag => $qf->primary_tag,
389 -source_tag => $qf->source_tag,
390 -score => $qf->score,
391 -seq_id => $hid,
392 -start => $s + $hoffset,
393 -end => $e + $hoffset,
394 -strand => $qf->strand,
395 );
396 49 $f->feature1($qf);
397 49 $f->feature2($hf);
398 49 $f->add_tag_value('alignment_len', $data->{'alignment_len'});
399 49 $f->add_tag_value('alignment_pid', $data->{'alignment_pid'});
400 # store the other model scores and data
401 49 foreach my $model ( @Models ) {
402 147 $f->add_tag_value("$model\_score", $data->{'model_scores'}->{'bits'}->{$model});
403 147 $f->add_tag_value("$model\_logoddspost", $data->{'model_scores'}->{'logoddspost'}->{$model});
404 147 ▶ if( ! $data->{'model_location'}->{$model} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{'model_location'}{$model}) { } 0 147 147
405 0 ▶ if( $self->verbose > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose > 0) 0 0 0
406 0 $self->debug( $data->{'entry'} );
407 }
408 $self->throw("no location parsed for $model in ",
409 0 (map { @$_ } @{$data->{'seqs'}}), " ", $f->start, " ", $f->end);
410 } else {
411 $f->add_tag_value("$model\_positions",
412 147 join("..",@{$data->{'model_location'}->{$model} }));
413 }
414 }
415 # probably a better way to store this - as
416 # a seq object perhaps
417 49 $f->add_tag_value('seq1', @{$data->{'seqs'}->[0]});
418 49 $f->add_tag_value('seq2', @{$data->{'seqs'}->[1]});
419 49 ▶ $f->add_tag_value('entry', $data->{'entry'}) if $self->verbose > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 0 0 49 49
420 49 ▶ if( $data->{'shuffled'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"shuffled"}) 0 49 49
421 0 $f->add_tag_value('shuffled', $data->{'shuffled'});
422 }
423 49 return $f;
424 }
425 2 1;
« Bio/AlignIO/fasta.pm ↑ Summary Bio/Index/Fasta.pm »