Bio/SearchIO/infernal.pm

filter: Statementstmt 67.0% 335 / 500 Branchbran 48.8% 166 / 340 Conditioncond 50.0% 59 / 118 MC/DCmcdc 27.7% 20 / 72 Subroutinesub 82.7% 24 / 29 Podpod 100% 21 / 21 totaltotal 57.8% 625 / 1080 CC 216 SCAR 58.6
CC
216
Cov
58%
_parse_pre
1406.0
_parse_old
930.0
_parse_latest
54.8
CRAP 351.1
« Bio/SeqUtils.pm ↑ Summary Bio/Tools/Run/WrapperBase/CommandExts.pm »
1 #
2 # BioPerl module for Bio::SearchIO::infernal
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Chris Fields <cjfields-at-uiuc-dot-edu>
7 #
8 # Copyright Chris Fields
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::SearchIO::infernal - SearchIO-based Infernal parser
17  
18 =head1 SYNOPSIS
19  
20 my $parser = Bio::SearchIO->new(-format => 'infernal',
21 -file => 'purine.inf');
22 while( my $result = $parser->next_result ) {
23 # general result info, such as model used, Infernal version
24 while( my $hit = $result->next_hit ) {
25 while( my $hsp = $hit->next_hsp ) {
26 # ...
27 }
28 }
29 }
30  
31 =head1 DESCRIPTION
32  
33 This is a SearchIO-based parser for Infernal output from the cmsearch program.
34 It currently parses cmsearch output for Infernal versions 0.7-1.1; older
35 versions may work but will not be supported.
36  
37 The latest version of Infernal is 1.1. The output has changed substantially
38 relative to version 1.0. Versions 1.x are stable releases (and output has
39 stabilized) therefore it is highly recommended that users upgrade to using
40 the latest Infernal release. Support for the older pre-v.1 developer releases
41 will be dropped for future core 1.6 releases.
42  
43 =head1 FEEDBACK
44  
45 =head2 Mailing Lists
46  
47 User feedback is an integral part of the evolution of this and other
48 Bioperl modules. Send your comments and suggestions preferably to
49 the Bioperl mailing list. Your participation is much appreciated.
50  
51 bioperl-l@bioperl.org - General discussion
52 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53  
54 =head2 Support
55  
56 Please direct usage questions or support issues to the mailing list:
57  
58 I<bioperl-l@bioperl.org>
59  
60 rather than to the module maintainer directly. Many experienced and
61 reponsive experts will be able look at the problem and quickly
62 address it. Please include a thorough description of the problem
63 with code and data examples if at all possible.
64  
65 =head2 Reporting Bugs
66  
67 Report bugs to the Bioperl bug tracking system to help us keep track
68 of the bugs and their resolution. Bug reports can be submitted via the
69 web:
70  
71 https://github.com/bioperl/bioperl-live/issues
72  
73 =head1 AUTHOR - Chris Fields
74  
75 Email cjfields-at-uiuc-dot-edu
76  
77 =head1 CONTRIBUTORS
78  
79 Jeffrey Barrick, Michigan State University
80 Paul Cantalupo, University of Pittsburgh
81  
82 =head1 APPENDIX
83  
84 The rest of the documentation details each of the object methods.
85 Internal methods are usually preceded with a _
86  
87 =cut
88  
89 # Let the code begin...
90  
91 package Bio::SearchIO::infernal;
92 2 $Bio::SearchIO::infernal::VERSION = '1.7.8';
93 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 2 ▶use base qw(Bio::SearchIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 2 our %MODEMAP = (
99 'Result' => 'result',
100 'Hit' => 'hit',
101 'Hsp' => 'hsp'
102 );
103  
104 2 our %MAPPING = (
105 'Hsp_bit-score' => 'HSP-bits',
106 'Hsp_score' => 'HSP-score',
107 'Hsp_evalue' => 'HSP-evalue', # evalues only in v0.81, optional
108 'Hsp_pvalue' => 'HSP-pvalue', # pvalues only in v0.81, optional
109 'Hsp_query-from' => 'HSP-query_start',
110 'Hsp_query-to' => 'HSP-query_end',
111 'Hsp_query-strand'=> 'HSP-query_strand',
112 'Hsp_hit-from' => 'HSP-hit_start',
113 'Hsp_hit-to' => 'HSP-hit_end',
114 'Hsp_hit-strand' => 'HSP-hit_strand',
115 'Hsp_gaps' => 'HSP-hsp_gaps',
116 'Hsp_hitgaps' => 'HSP-hit_gaps',
117 'Hsp_querygaps' => 'HSP-query_gaps',
118 'Hsp_qseq' => 'HSP-query_seq',
119 'Hsp_ncline' => 'HSP-nc_seq',
120 'Hsp_hseq' => 'HSP-hit_seq',
121 'Hsp_midline' => 'HSP-homology_seq',
122 'Hsp_pline' => 'HSP-pp_seq',
123 'Hsp_structure' => 'HSP-meta',
124 'Hsp_align-len' => 'HSP-hsp_length',
125 'Hsp_stranded' => 'HSP-stranded',
126  
127 'Hit_id' => 'HIT-name',
128 'Hit_len' => 'HIT-length',
129 'Hit_gi' => 'HIT-ncbi_gi',
130 'Hit_accession' => 'HIT-accession',
131 'Hit_desc' => 'HIT-description',
132 'Hit_def' => 'HIT-description',
133 'Hit_signif' => 'HIT-significance', # evalues in v1.1 and v0.81, optional
134 'Hit_p' => 'HIT-p', # pvalues only in 1.0, optional
135 'Hit_score' => 'HIT-score', # best HSP bit score (in v1.1, the only HSP bit score)
136 'Hit_bits' => 'HIT-bits', # best HSP bit score (ditto)
137  
138 'Infernal_program' => 'RESULT-algorithm_name', # get/set
139 'Infernal_version' => 'RESULT-algorithm_version', # get/set
140 'Infernal_query-def'=> 'RESULT-query_name', # get/set
141 'Infernal_query-len'=> 'RESULT-query_length',
142 'Infernal_query-acc'=> 'RESULT-query_accession', # get/set
143 'Infernal_querydesc'=> 'RESULT-query_description', # get/set
144 'Infernal_cm' => 'RESULT-cm_name',
145 'Infernal_db' => 'RESULT-database_name', # get/set
146 'Infernal_db-len' => 'RESULT-database_entries', # in v1.1 only
147 'Infernal_db-let' => 'RESULT-database_letters', # in v1.1 only
148 );
149  
150 2 my $MINSCORE = 0;
151 2 my $DEFAULT_ALGORITHM = 'cmsearch';
152 2 my $DEFAULT_VERSION = '1.1';
153  
154 2 my @VALID_SYMBOLS = qw(5-prime 3-prime single-strand unknown gap);
155 2 my %STRUCTURE_SYMBOLS = (
156 '5-prime' => '<',
157 '3-prime' => '>',
158 'single-strand' => ':',
159 'unknown' => '?',
160 'gap' => '.'
161 );
162  
163 =head2 new
164  
165 Title : new
166 Usage : my $obj = Bio::SearchIO::infernal->new();
167 Function: Builds a new Bio::SearchIO::infernal object
168 Returns : Bio::SearchIO::infernal
169 Args : -fh/-file => cmsearch (infernal) filename
170 -format => 'infernal'
171 -model => query model (Rfam ID) (default undef)
172 -database => database name (default undef)
173 -query_acc => query accession, eg. Rfam accession RF####
174 -query_desc => query description, eg. Rfam description
175 -hsp_minscore => minimum HSP score cutoff
176 -convert_meta => boolean, set to convert meta string to simple WUSS format
177 -symbols => hash ref of structure symbols to use
178 (default symbols in %STRUCTURE_SYMBOLS hash)
179  
180 =cut
181  
182 4 ▶sub _initialize {
Subroutine _initialize: called CC=10 SCAR=24.0
183 4 my ( $self, @args ) = @_;
184 4 $self->SUPER::_initialize(@args);
185 4 my ($model, $database, $convert, $symbols, $cutoff,
186 $desc, $accession, $algorithm, $version) =
187 $self->_rearrange([qw(MODEL
188 DATABASE
189 CONVERT_META
190 SYMBOLS
191 HSP_MINSCORE
192 QUERY_DESC
193 QUERY_ACC
194 ALGORITHM
195 VERSION)],@args);
196 4 my $handler = $self->_eventHandler;
197 4 $handler->register_factory(
198 'result',
199 Bio::Factory::ObjectFactory->new(
200 -type => 'Bio::Search::Result::INFERNALResult',
201 -interface => 'Bio::Search::Result::ResultI',
202 -verbose => $self->verbose
203 )
204 );
205  
206 4 $handler->register_factory(
207 'hit',
208 Bio::Factory::ObjectFactory->new(
209 -type => 'Bio::Search::Hit::ModelHit',
210 -interface => 'Bio::Search::Hit::HitI',
211 -verbose => $self->verbose
212 )
213 );
214  
215 4 $handler->register_factory(
216 'hsp',
217 Bio::Factory::ObjectFactory->new(
218 -type => 'Bio::Search::HSP::ModelHSP',
219 -interface => 'Bio::Search::HSP::HSPI',
220 -verbose => $self->verbose
221 )
222 );
223  
224 4 ▶ defined $model && $self->model($model);
Branch: 1 branch
BranchTrueFalseTotal
defined $model and $self->model($model) 1 3 4
225 4 ▶ defined $database && $self->database($database);
Branch: 1 branch
BranchTrueFalseTotal
defined $database and $self->database($database) 0 4 4
226 4 ▶ defined $accession && $self->query_accession($accession);
Branch: 1 branch
BranchTrueFalseTotal
defined $accession and $self->query_accession($accession) 1 3 4
227 4 ▶ defined $convert && $self->convert_meta($convert);
Branch: 1 branch
BranchTrueFalseTotal
defined $convert and $self->convert_meta($convert) 0 4 4
228 4 ▶ defined $desc && $self->query_description($desc);
Branch: 1 branch
BranchTrueFalseTotal
defined $desc and $self->query_description($desc) 1 3 4
229  
230 4 ▶ $version ||= $DEFAULT_VERSION;
Condition33%1/3
$version ||= $DEFAULT_VERSION
l!l&&r!l&&!r
040
MC/DC0%0/2
$version ||= $DEFAULT_VERSION
$version $DEFAULT_VERSION
Truth table33%1/3
A ||= B
A= $versionB= $DEFAULT_VERSION
ABresult
1X1
011
000
231 4 $self->version($version);
232 4 ▶ $symbols ||= \%STRUCTURE_SYMBOLS;
Condition50%1/2
$symbols ||= \%STRUCTURE_SYMBOLS
l!l
04
MC/DC0%0/1
$symbols ||= \%STRUCTURE_SYMBOLS
$symbols
Truth table50%1/2
A
A= $symbols
Aresult
11
00
233 4 $self->structure_symbols($symbols);
234 4 ▶ $cutoff ||= $MINSCORE;
Condition33%1/3
$cutoff ||= $MINSCORE
l!l&&r!l&&!r
004
MC/DC0%0/2
$cutoff ||= $MINSCORE
$cutoff $MINSCORE
Truth table33%1/3
A ||= B
A= $cutoffB= $MINSCORE
ABresult
1X1
011
000
235 4 $self->hsp_minscore($cutoff);
236 4 ▶ $algorithm ||= $DEFAULT_ALGORITHM;
Condition33%1/3
$algorithm ||= $DEFAULT_ALGORITHM
l!l&&r!l&&!r
040
MC/DC0%0/2
$algorithm ||= $DEFAULT_ALGORITHM
$algorithm $DEFAULT_ALGORITHM
Truth table33%1/3
A ||= B
A= $algorithmB= $DEFAULT_ALGORITHM
ABresult
1X1
011
000
237 4 $self->algorithm($algorithm);
238 }
239  
240 =head2 next_result
241  
242 Title : next_result
243 Usage : my $hit = $searchio->next_result;
244 Function: Returns the next Result from a search
245 Returns : Bio::Search::Result::ResultI object
246 Args : none
247  
248 =cut
249  
250 6 ▶sub next_result {
Subroutine next_result: called CC=10 SCAR=25.3
Pod documented
251 6 my ($self) = @_;
252 6 ▶ unless (exists $self->{'_handlerset'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_handlerset"}) 4 2 6
253 4 my $line;
254 4 ▶ while ($line = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line = $self->_readline) 4 0 4
255 # advance to first line
256 4 ▶ next if $line =~ m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 4 4
257 # newer output starts with model name
258 4 ▶ if ($line =~ m{^\#\s+cmsearch\s}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\#\s+cmsearch\s/) { } 4 0 4
elsif ($line =~ /^CM\s\d+:/) { } 0 0 0
259 4 my $secondline = $self->_readline;
260 4 ▶ if ($secondline =~ m{INFERNAL 1\.1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secondline =~ /INFERNAL 1\.1/) { } 3 1 4
261 3 $self->{'_handlerset'} = '1.1';
262 }
263 else {
264 1 $self->{'_handlerset'} = 'latest'; # v1.0
265 }
266 4 $self->_pushback($secondline);
267 }
268 elsif ($line =~ m{^CM\s\d+:}) {
269 0 $self->{'_handlerset'} = 'pre-1.0';
270 }
271 else {
272 0 $self->{'_handlerset'} ='old';
273 }
274 4 last;
275 }
276 4 $self->_pushback($line);
277 }
278 return ($self->{'_handlerset'} eq '1.1') ? $self->_parse_v1_1 :
279 ($self->{'_handlerset'} eq 'latest') ? $self->_parse_latest :
280 6 ▶ ($self->{'_handlerset'} eq 'pre-1.0') ? $self->_parse_pre :
Branch: 3 branches
BranchTrueFalseTotal
$self->{'_handlerset'} eq '1.1' ? : 5 1 6
$self->{'_handlerset'} eq 'latest' ? : 1 0 1
$self->{'_handlerset'} eq 'pre-1.0' ? : 0 0 0
281 $self->_parse_old;
282 }
283  
284  
285 5 ▶sub _parse_v1_1 {
Subroutine _parse_v1_1: called CC=53 SCAR=40.0
286 5 my ($self) = @_;
287 5 my $seentop = 0;
288 5 local $/ = "\n";
289 5 my ($accession, $description) = ($self->query_accession, $self->query_description);
290 5 my ($buffer, $last, %modelcounter, @hit_list, %hitindex,
291 @hsp_list, %hspindex);
292 5 $self->start_document();
293 5 $buffer = $self->_readline;
294 5 ▶ if ( !defined $buffer || $buffer =~ m/^\[ok/ ) { # end of report
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $buffer or $buffer =~ /^\[ok/) { } 1 4 5
Condition66%2/3
not defined $buffer or $buffer =~ /^\[ok/
l!l&&r!l&&!r
014
MC/DC50%1/2
not defined $buffer or $buffer =~ /^\[ok/
not defined $buffer $buffer =~ /^\[ok/
Truth table66%2/3
not(A) or B
A= not defined $bufferB= $buffer =~ /^\[ok/
ABresult
1X1
011
000
295 1 return undef;
296 }
297 else {
298 4 $self->_pushback($buffer);
299 }
300  
301 PARSER: # Parse each line of report
302 4 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 52 0 52
303 52 my $hit_counter = 0;
304 52 my $lineorig = $buffer;
305 52 chomp $buffer;
306  
307 # INFERNAL program name
308 52 ▶ if ( $buffer =~ m/^\#\s(\S+)\s\:\:\s/ ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($buffer =~ /^\#\s(\S+)\s\:\:\s/) { } 3 49 52
elsif ($buffer =~ /^\#\sINFERNAL\s+(\S+)\s+\((.+)\)/) { } 3 46 49
elsif ($buffer =~ /^\#\squery (?:\w+ )?file\:\s+(\S+)/) { } 3 43 46
elsif ($buffer =~ /^\#\starget\s\S+\sdatabase\:\s+(\S+)/) { } 3 40 43
elsif ($buffer =~ /^Query:\s+(\S+)\s+\[CLEN=(\d+)\]$/) { } 4 36 40
elsif ($buffer =~ s/^Accession:\s+// and not $accession) { } 3 33 36
elsif ($buffer =~ s/^Description:\s+// and not $description) { } 2 31 33
elsif ($buffer =~ /^Hit scores:/) { } 4 27 31
elsif ($buffer =~ /^Hit alignments:/) { } 4 23 27
elsif ($buffer =~ /Internal CM pipeline statistics summary:/) { } 4 19 23
309 3 $seentop = 1;
310 3 my $prog = $1;
311 3 $self->start_element( { 'Name' => 'Result' } );
312 3 $self->element_hash( { 'Infernal_program' => uc($prog) } );
313 }
314  
315 # INFERNAL version and release date
316 elsif ( $buffer =~ m/^\#\sINFERNAL\s+(\S+)\s+\((.+)\)/ ) {
317 3 my $version = $1;
318 3 my $versiondate = $2;
319 3 $self->{'_cmidline'} = $buffer;
320 3 $self->element_hash( { 'Infernal_version' => $version } );
321 }
322  
323 # Query info
324 elsif ( $buffer =~ /^\#\squery (?:\w+ )?file\:\s+(\S+)/ ) {
325 3 $self->{'_cmfileline'} = $lineorig;
326 3 $self->element_hash( { 'Infernal_cm' => $1 } );
327 }
328  
329 # Database info
330 elsif ( $buffer =~ m/^\#\starget\s\S+\sdatabase\:\s+(\S+)/ ) {
331 3 $self->{'_cmseqline'} = $lineorig;
332 3 $self->element_hash( { 'Infernal_db' => $1 } );
333 }
334  
335 # Query data
336 elsif ( $buffer =~ m/^Query:\s+(\S+)\s+\[CLEN=(\d+)\]$/ ) {
337 4 $self->element_hash( { 'Infernal_query-def' => $1,
338 'Infernal_query-len' => $2,
339 'Infernal_query-acc' => $accession,
340 'Infernal_querydesc' => $description,
341 } );
342 }
343  
344 # Get query accession
345 ▶ elsif ( $buffer =~ s/^Accession:\s+// && ! $accession) {
Condition66%2/3
$buffer =~ s/^Accession:\s+// and not $accession
!ll&&!rl&&r
3303
MC/DC50%1/2
$buffer =~ s/^Accession:\s+// and not $accession
$buffer =~ s/^Accession:\s+// not $accession
Truth table66%2/3
A and not(B)
A= $buffer =~ s/^Accession:\s+//B= not $accession
ABresult
0X0
100
111
346 3 $buffer =~ s/\s+$//;
347 3 $self->element_hash( { 'Infernal_query-acc' => $buffer } );
348 }
349  
350 # Get query description
351 ▶ elsif ( $buffer =~ s/^Description:\s+// && ! $description) {
Condition66%2/3
$buffer =~ s/^Description:\s+// and not $description
!ll&&!rl&&r
3102
MC/DC50%1/2
$buffer =~ s/^Description:\s+// and not $description
$buffer =~ s/^Description:\s+// not $description
Truth table66%2/3
A and not(B)
A= $buffer =~ s/^Description:\s+//B= not $description
ABresult
0X0
100
111
352 2 $buffer =~ s/\s+$//;
353 2 $self->element_hash( { 'Infernal_querydesc' => $buffer } );
354 }
355  
356 # Process hit table - including those below inclusion threshold
357 elsif ( $buffer =~ m/^Hit scores:/) {
358 4 @hit_list = (); # here is case there are multi-query reports
359 4 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 38 0 38
360 38 ▶ if ( $buffer =~ m/^Hit alignments:/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($buffer =~ /^Hit alignments:/) { } 4 34 38
elsif ($buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /\-\-\-/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/) { } 19 15 34
361 4 $self->_pushback($buffer);
362 4 last;
363 }
364 ▶ elsif ( $buffer =~ m/^\s+rank\s+E-value/
Condition100%9/9
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /\-\-\-/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/
l!l&&r!l&&!r
18115
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /\-\-\-/ or $buffer =~ /^$/
l!l&&r!l&&!r
9916
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /\-\-\-/
l!l&&r!l&&!r
4525
MC/DC100%4/4
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /\-\-\-/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/
$buffer =~ /^\s+rank\s+E-value/ $buffer =~ /\-\-\-/ $buffer =~ /^$/ $buffer =~ /No hits detected/
Truth table100%5/5
A or B or C or D
A= $buffer =~ /^\s+rank\s+E-value/B= $buffer =~ /\-\-\-/C= $buffer =~ /^$/D= $buffer =~ /No hits detected/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
365 || $buffer =~ m/\-\-\-/
366 || $buffer =~ m/^$/
367 || $buffer =~ m/No hits detected/ ) {
368 19 next;
369 }
370  
371 # Process hit
372 15 $hit_counter++;
373 15 my ($rank, $threshold, $eval, $score,
374 $bias, $hitid, $start, $end, $strand,
375 $mdl, $truc, $gc, @desc) = split( " ", $buffer );
376 15 my $desc = join " ", @desc;
377 15 ▶ $desc = '' if ( !defined($desc) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $desc 0 15 15
378  
379 15 push @hit_list, [ $hitid, $desc, $eval, $score ];
380 15 $hitindex{ $hitid.$hit_counter } = $#hit_list;
381 }
382 }
383  
384 # Process hit alignments
385 elsif ( $buffer =~ /^Hit alignments:/ ) {
386 4 my $hitid;
387 4 my $align_counter = 0;
388 4 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 38 0 38
389 38 ▶ if ( $buffer =~ /^Internal CM pipeline statistics summary/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ /^Internal CM pipeline statistics summary/) 4 34 38
390 4 $self->_pushback($buffer);
391 4 last;
392 }
393 34 ▶ if ( $buffer =~ m/^\>\>\s(\S*)\s+(.*)/ ) { # defline of hit
Branch: 2 branches
BranchTrueFalseTotal
if ($buffer =~ /^\>\>\s(\S*)\s+(.*)/) { } 15 19 34
elsif ($buffer =~ /NC$/) { } 15 4 19
394 15 $hitid = $1;
395 15 my $desc = $2;
396 15 $align_counter++;
397 15 my $hitid_alignctr = $hitid.$align_counter;
398 15 $modelcounter{$hitid_alignctr} = 0;
399  
400 # The Hit Description from the Hit table can be truncated if
401 # it is too long, so use the '>>' line description instead
402 15 $hit_list[ $hitindex{$hitid_alignctr} ][1] = $desc;
403  
404 # Process hit information table
405 15 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 75 0 75
406 75 ▶ if ( $buffer =~ m/^Internal CM pipeline statistics/
Branch: 2 branches
BranchTrueFalseTotal
if ($buffer =~ /^Internal CM pipeline statistics/ or $buffer =~ /NC$/ or $buffer =~ /^\>\>/) { } 15 60 75
elsif ($buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /^\s----/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/) { } 45 15 60
Condition66%4/6
$buffer =~ /^Internal CM pipeline statistics/ or $buffer =~ /NC$/ or $buffer =~ /^\>\>/
l!l&&r!l&&!r
15060
$buffer =~ /^Internal CM pipeline statistics/ or $buffer =~ /NC$/
l!l&&r!l&&!r
01560
MC/DC33%1/3
$buffer =~ /^Internal CM pipeline statistics/ or $buffer =~ /NC$/ or $buffer =~ /^\>\>/
$buffer =~ /^Internal CM pipeline statistics/ $buffer =~ /NC$/ $buffer =~ /^\>\>/
Truth table50%2/4
A or B or C
A= $buffer =~ /^Internal CM pipeline statistics/B= $buffer =~ /NC$/C= $buffer =~ /^\>\>/
ABCresult
1XX1
01X1
0011
0000
407 || $buffer =~ m/NC$/
408 || $buffer =~ m/^\>\>/ ) {
409 15 $self->_pushback($buffer);
410 15 last;
411 }
412 ▶ elsif ( $buffer =~ m/^\s+rank\s+E-value/
Condition88%8/9
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /^\s----/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/
l!l&&r!l&&!r
45015
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /^\s----/ or $buffer =~ /^$/
l!l&&r!l&&!r
301515
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /^\s----/
l!l&&r!l&&!r
151530
MC/DC75%3/4
$buffer =~ /^\s+rank\s+E-value/ or $buffer =~ /^\s----/ or $buffer =~ /^$/ or $buffer =~ /No hits detected/
$buffer =~ /^\s+rank\s+E-value/ $buffer =~ /^\s----/ $buffer =~ /^$/ $buffer =~ /No hits detected/
Truth table80%4/5
A or B or C or D
A= $buffer =~ /^\s+rank\s+E-value/B= $buffer =~ /^\s----/C= $buffer =~ /^$/D= $buffer =~ /No hits detected/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
413 || $buffer =~ m/^\s----/
414 || $buffer =~ m/^$/
415 || $buffer =~ m/No hits detected/ ) {
416 45 next;
417 }
418  
419 # Get hsp data from table, push into @hsp;
420 15 my ( $rank, $threshold, $eval,
421 $score, $bias, $model,
422 $cm_start, $cm_stop, $cm_cov,
423 $seq_start, $seq_stop, $seq_strand, $seq_cov,
424 $acc, $trunc, $gc,
425 ) = split( " ", $buffer );
426  
427 # Try to get the Hit Length from the alignment information.
428 # For cmsearch, if sequence coverage ends in ']' it means that the
429 # alignment runs full-length flush to the end of the target.
430 15 ▶ my $hitlength = ( $seq_cov =~ m/\]$/ ) ? $seq_stop : 0;
Branch: 1 branch
BranchTrueFalseTotal
$seq_cov =~ /\]$/ ? : 10 5 15
431  
432 15 my $tmphit = $hit_list[ $hitindex{$hitid_alignctr} ];
433 15 ▶ if ( !defined $tmphit ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmphit) 0 15 15
434 0 $self->warn("Incomplete information: can't find HSP $hitid in list of hits\n");
435 0 next;
436 }
437  
438 15 push @hsp_list, [ $hitid,
439 $cm_start, $cm_stop,
440 $seq_start, $seq_stop,
441 $score, $eval,
442 $hitlength];
443 15 $modelcounter{$hitid_alignctr}++;
444 15 my $hsp_key = $hitid_alignctr . "_" . $modelcounter{$hitid_alignctr};
445 15 $hspindex{$hsp_key} = $#hsp_list;
446 }
447 }
448 elsif ( $buffer =~ m/NC$/ ) { # start of HSP
449 # need CS line to get number of spaces before structure data
450 15 my $csline = $self->_readline;
451 15 $csline =~ m/^(\s+)\S+ CS$/;
452 15 my $offset = length($1);
453 15 $self->_pushback($csline);
454 15 $self->_pushback($buffer); # set up for loop
455  
456 15 my ($ct, $strln) = 0;
457 15 my $hspdata;
458 15 HSP:
459 my %hspline = ('0' => 'nc', '1' => 'meta',
460 '2' => 'query', '3' => 'midline',
461 '4' => 'hit', '5' => 'pp');
462 HSP:
463 15 ▶ while (defined ($buffer = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 168 0 168
464 168 chomp $buffer;
465 168 ▶ if ( $buffer =~ /^>>\s/
Branch: 2 branches
BranchTrueFalseTotal
if ($buffer =~ /^>>\s/ or $buffer =~ /^Internal CM pipeline statistics/) { } 15 153 168
elsif ($ct % 6 == 0 and $buffer =~ /^$/) { } 27 231 258
Condition100%3/3
$buffer =~ /^>>\s/ or $buffer =~ /^Internal CM pipeline statistics/
l!l&&r!l&&!r
123153
MC/DC100%2/2
$buffer =~ /^>>\s/ or $buffer =~ /^Internal CM pipeline statistics/
$buffer =~ /^>>\s/ $buffer =~ /^Internal CM pipeline statistics/
Truth table100%3/3
A or B
A= $buffer =~ /^>>\s/B= $buffer =~ /^Internal CM pipeline statistics/
ABresult
1X1
011
000
466 || $buffer =~ /^Internal CM pipeline statistics/) {
467 15 $self->_pushback($buffer);
468 15 last HSP;
469 }
470 ▶ elsif ( $ct % 6 == 0 && $buffer =~ /^$/ ) {
Condition100%3/3
$ct % 6 == 0 and $buffer =~ /^$/
!ll&&!rl&&r
1052127
MC/DC100%2/2
$ct % 6 == 0 and $buffer =~ /^$/
$ct % 6 == 0 $buffer =~ /^$/
Truth table100%3/3
A and B
A= $ct % 6 == 0B= $buffer =~ /^$/
ABresult
0X0
100
111
471 27 next;
472 }
473 126 my $iterator = $ct % 6;
474 # NC line ends with ' NC' so remove these from the strlen count
475 126 ▶ $strln = ( length($buffer) - 3 ) if $iterator == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator == 0 21 105 126
476 126 my $data = substr($buffer, $offset, $strln-$offset);
477 126 $hspdata->{ $hspline{$iterator} } .= $data;
478  
479 126 $ct++;
480 } # 'HSP' while loop
481  
482 15 my $strlen = 0;
483 # catch any insertions and add them into the actual length
484 15 ▶ while ($hspdata->{'query'} =~ m{\*\[\s*(\d+)\s*\]\*}g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hspdata->{"query"} =~ /\*\[\s*(\d+)\s*\]\*/g) 2 15 17
485 2 $strlen += $1;
486 }
487 # add on the actual residues
488 15 $strlen += $hspdata->{'query'} =~ tr{A-Za-z}{A-Za-z};
489 my $metastr = ($self->convert_meta) ? ($self->simple_meta($hspdata->{'meta'})) :
490 15 ▶ $hspdata->{'meta'};
Branch: 1 branch
BranchTrueFalseTotal
$self->convert_meta ? : 0 15 15
491  
492 15 my $hitid_alignctr = $hitid . $align_counter;
493 15 my $hsp_key = $hitid_alignctr . "_" . $modelcounter{$hitid_alignctr};
494 15 my $hsp = $hsp_list[ $hspindex{$hsp_key} ];
495 push (@$hsp, $hspdata->{'nc'}, $metastr,
496 $hspdata->{'query'}, $hspdata->{'midline'},
497 15 $hspdata->{'hit'}, $hspdata->{'pp'});
498 }
499 }
500 } # end of 'Hit alignments:' section of report
501  
502 # Process internal pipeline stats (end of report)
503 elsif ( $buffer =~ m/Internal CM pipeline statistics summary:/ ) {
504 4 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 68 0 68
505 68 ▶ last if ( $buffer =~ m!^//! );
Branch: 1 branch
BranchTrueFalseTotal
if $buffer =~ m[^//] 4 64 68
506  
507 64 ▶ if ( $buffer =~ /^Target sequences:\s+(\d+)\s+\((\d+) residues/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ /^Target sequences:\s+(\d+)\s+\((\d+) residues/) 4 60 64
508 4 $self->element_hash( { 'Infernal_db-len' => $1,
509 'Infernal_db-let' => $2, } );
510 }
511 }
512 4 last; # of the outer while defined $self->readline
513 }
514  
515 # Leftovers
516 else {
517 #print STDERR "Missed line: $buffer\n";
518 19 $self->debug($buffer);
519 }
520 48 $last = $buffer;
521 } # PARSER end
522  
523 # Final processing of hits and hsps
524 4 my $hit_counter = 0;
525 4 foreach my $hit ( @hit_list ) {
526 15 $hit_counter++;
527 15 my ($hit_name, $hit_desc, $hit_signif, $hit_score) = @$hit;
528 15 ▶ my $num_hsp = $modelcounter{$hit_name . $hit_counter} || 0;
Condition50%1/2
$modelcounter{$hit_name . $hit_counter} || 0
l!l
150
MC/DC0%0/1
$modelcounter{$hit_name . $hit_counter} || 0
$modelcounter{$hit_name . $hit_counter}
Truth table50%1/2
A
A= $modelcounter{$hit_name . $hit_counter}
Aresult
11
00
529  
530 15 $self->start_element( { 'Name' => 'Hit' } );
531 15 $self->element_hash( {'Hit_id' => $hit_name,
532 'Hit_desc' => $hit_desc,
533 'Hit_signif'=> $hit_signif,
534 'Hit_score' => $hit_score,
535 'Hit_bits' => $hit_score, } );
536 15 for my $i ( 1 .. $num_hsp ) {
537 15 my $hsp_key = $hit_name . $hit_counter . "_" . $i;
538 15 my $hsp = $hsp_list[ $hspindex{$hsp_key} ];
539 15 ▶ if ( defined $hsp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hsp) 15 0 15
540 15 my $hspid = shift @$hsp;
541  
542 15 my ($cm_start, $cm_stop, $seq_start, $seq_stop,
543 $score, $eval, $hitlength, $ncline,
544 $csline, $qseq, $midline, $hseq, $pline) = @$hsp;
545 15 ▶ if ( $hitlength != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hitlength != 0) 10 5 15
546 10 $self->element(
547 { 'Name' => 'Hit_len', 'Data' => $hitlength }
548 );
549 }
550  
551 15 $self->start_element( { 'Name' => 'Hsp' } );
552 15 $self->element_hash( { 'Hsp_stranded' => 'HIT',
553 'Hsp_query-from' => $cm_start,
554 'Hsp_query-to' => $cm_stop,
555 'Hsp_hit-from' => $seq_start,
556 'Hsp_hit-to' => $seq_stop,
557 'Hsp_score' => $score,
558 'Hsp_bit-score' => $score,
559 'Hsp_evalue' => $eval,
560 'Hsp_ncline' => $ncline,
561 'Hsp_structure' => $csline,
562 'Hsp_qseq' => $qseq,
563 'Hsp_midline' => $midline,
564 'Hsp_hseq' => $hseq,
565 'Hsp_pline' => $pline,
566 } );
567  
568 15 $self->end_element( { 'Name' => 'Hsp' } );
569 }
570 }
571 15 $self->end_element( { 'Name' => 'Hit' } );
572 }
573  
574 4 $self->end_element( { 'Name' => 'Result' } );
575 4 my $result = $self->end_document();
576 4 return $result;
577 }
578  
579  
580 =head2 start_element
581  
582 Title : start_element
583 Usage : $eventgenerator->start_element
584 Function: Handles a start element event
585 Returns : none
586 Args : hashref with at least 2 keys 'Data' and 'Name'
587  
588  
589 =cut
590  
591 38 ▶sub start_element {
Subroutine start_element: called CC=5 SCAR=16.2
Pod documented
592 38 my ( $self, $data ) = @_;
593  
594 # we currently don't care about attributes
595 38 my $nm = $data->{'Name'};
596 38 my $type = $MODEMAP{$nm};
597 38 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 38 0 38
598 38 ▶ if ( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 38 0 38
599 38 my $func = sprintf( "start_%s", lc $type );
600 38 $self->_eventHandler->$func( $data->{'Attributes'} );
601 }
602 38 unshift @{ $self->{'_elements'} }, $type;
603 }
604 38 ▶ if ( defined $type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and $type eq "result") 4 34 38
Condition66%2/3
defined $type and $type eq "result"
!ll&&!rl&&r
0344
MC/DC50%1/2
defined $type and $type eq "result"
defined $type $type eq "result"
Truth table66%2/3
A and B
A= defined $typeB= $type eq "result"
ABresult
0X0
100
111
605 && $type eq 'result' )
606 {
607 4 $self->{'_values'} = {};
608 4 $self->{'_result'} = undef;
609 }
610 }
611  
612 =head2 end_element
613  
614 Title : start_element
615 Usage : $eventgenerator->end_element
616 Function: Handles an end element event
617 Returns : none
618 Args : hashref with at least 2 keys, 'Data' and 'Name'
619  
620 =cut
621  
622 49 ▶sub end_element {
Subroutine end_element: called CC=8 SCAR=21.3
Pod documented
623 49 my ( $self, $data ) = @_;
624 49 my $nm = $data->{'Name'};
625 49 my $type = $MODEMAP{$nm};
626 49 my $rc;
627  
628 49 ▶ if ($type) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type) { } 39 10 49
elsif ($Bio::SearchIO::infernal::MAPPING{$nm}) { } 10 0 10
629 39 ▶ if ( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 39 0 39
630 39 my $func = sprintf( "end_%s", lc $type );
631 $rc = $self->_eventHandler->$func( $self->{'_reporttype'},
632 39 $self->{'_values'} );
633 }
634 39 my $lastelem = shift @{ $self->{'_elements'} };
635  
636 # Infernal 1.1 allows one to know hit->length in some instances
637 # so remove it so it doesn't carry over to next hit. Tried flushing
638 # all 'type' values from {_values} buffer but it breaks legacy tests
639 39 ▶ if ($type eq 'hit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "hit") 16 23 39
640 16 delete $self->{_values}{'HIT-length'};
641 16 delete $self->{_values}{'HSP-hit_length'};
642 }
643 }
644 elsif ( $MAPPING{$nm} ) {
645 10 ▶ if ( ref( $MAPPING{$nm} ) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::SearchIO::infernal::MAPPING{$nm}) =~ /hash/i) { } 0 10 10
646 0 my $key = ( keys %{ $MAPPING{$nm} } )[0];
647 $self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } =
648 0 $self->{'_last_data'};
649 }
650 else {
651 10 $self->{'_values'}->{ $MAPPING{$nm} } = $self->{'_last_data'};
652 }
653 }
654 else {
655 0 $self->debug("unknown nm $nm, ignoring\n");
656 }
657 49 $self->{'_last_data'} = ''; # remove read data if we are at
658 # end of an element
659 49 ▶ $self->{'_result'} = $rc if ( defined $type && $type eq 'result' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type eq "result" 5 44 49
Condition100%3/3
defined $type and $type eq "result"
!ll&&!rl&&r
10345
MC/DC100%2/2
defined $type and $type eq "result"
defined $type $type eq "result"
Truth table100%3/3
A and B
A= defined $typeB= $type eq "result"
ABresult
0X0
100
111
660 49 return $rc;
661 }
662  
663 =head2 element
664  
665 Title : element
666 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
667 Function: Convenience method that calls start_element, characters, end_element
668 Returns : none
669 Args : Hash ref with the keys 'Name' and 'Data'
670  
671 =cut
672  
673 10 ▶sub element {
Subroutine element: called CC=1 SCAR=0.0
Pod documented
674 10 my ( $self, $data ) = @_;
675 # simple data calls (%MAPPING) do not need start_element
676 10 $self->characters($data);
677 10 $self->end_element($data);
678 }
679  
680 =head2 element_hash
681  
682 Title : element
683 Usage : $eventhandler->element_hash({'Hsp_hit-from' => $start,
684 'Hsp_hit-to' => $end,
685 'Hsp_score' => $lastscore});
686 Function: Convenience method that takes multiple simple data elements and
687 maps to appropriate parameters
688 Returns : none
689 Args : Hash ref with the mapped key (in %MAPPING) and value
690  
691 =cut
692  
693 70 ▶sub element_hash {
Subroutine element_hash: called CC=8 SCAR=23.1
Pod documented
694 70 my ($self, $data) = @_;
695 70 ▶ $self->throw("Must provide data hash ref") if !$data || !ref($data);
Branch: 1 branch
BranchTrueFalseTotal
unless $data and ref $data 0 70 70
Condition33%1/3
$data and ref $data
!ll&&!rl&&r
0070
MC/DC0%0/2
$data and ref $data
$data ref $data
Truth table33%1/3
A and B
A= $dataB= ref $data
ABresult
0X0
100
111
696 70 for my $nm (sort keys %{$data}) {
697 382 ▶ next if $data->{$nm} && $data->{$nm} =~ m{^\s*$}o;
Branch: 1 branch
BranchTrueFalseTotal
if $data->{$nm} and $data->{$nm} =~ /^\s*$/o 8 374 382
Condition100%3/3
$data->{$nm} and $data->{$nm} =~ /^\s*$/o
!ll&&!rl&&r
193558
MC/DC100%2/2
$data->{$nm} and $data->{$nm} =~ /^\s*$/o
$data->{$nm} $data->{$nm} =~ /^\s*$/o
Truth table100%3/3
A and B
A= $data->{$nm}B= $data->{$nm} =~ /^\s*$/o
ABresult
0X0
100
111
698 374 ▶ if ( $MAPPING{$nm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SearchIO::infernal::MAPPING{$nm}) 374 0 374
699 374 ▶ if ( ref( $MAPPING{$nm} ) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::SearchIO::infernal::MAPPING{$nm}) =~ /hash/i) { } 0 374 374
700 0 my $key = ( keys %{ $MAPPING{$nm} } )[0];
701 $self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } =
702 0 $data->{$nm};
703 }
704 else {
705 374 $self->{'_values'}->{ $MAPPING{$nm} } = $data->{$nm};
706 }
707 }
708 }
709 }
710  
711 =head2 characters
712  
713 Title : characters
714 Usage : $eventgenerator->characters($str)
715 Function: Send a character events
716 Returns : none
717 Args : string
718  
719  
720 =cut
721  
722 10 ▶sub characters {
Subroutine characters: called CC=3 SCAR=12.5
Pod documented
723 10 my ( $self, $data ) = @_;
724 10 ▶ return unless ( defined $data->{'Data'} && $data->{'Data'} !~ /^\s+$/o );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o 0 10 10
Condition33%1/3
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o
defined $data->{"Data"} not $data->{"Data"} =~ /^\s+$/o
Truth table33%1/3
A and not(B)
A= defined $data->{"Data"}B= not $data->{"Data"} =~ /^\s+$/o
ABresult
0X0
100
111
725 10 $self->{'_last_data'} = $data->{'Data'};
726 }
727  
728 =head2 within_element
729  
730 Title : within_element
731 Usage : if( $eventgenerator->within_element($element) ) {}
732 Function: Test if we are within a particular element
733 This is different than 'in' because within can be tested
734 for a whole block.
735 Returns : boolean
736 Args : string element name
737  
738 =cut
739  
740 5 ▶sub within_element {
Subroutine within_element: called CC=6 SCAR=19.3
Pod documented
741 5 my ( $self, $name ) = @_;
742 return 0
743 if ( !defined $name
744 || !defined $self->{'_elements'}
745 5 ▶ || scalar @{ $self->{'_elements'} } == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0 0 5 5
Condition33%2/6
not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
l!l&&r!l&&!r
005
defined $name && defined $self->{'_elements'}
!ll&&!rl&&r
005
MC/DC0%0/3
not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
defined $name defined $self->{'_elements'} scalar @{$self->{"_elements"};} == 0
Truth table25%1/4
not(A && B) or C
A= defined $nameB= defined $self->{'_elements'}C= scalar @{$self->{"_elements"};} == 0
ABCresult
0XX1
10X1
1111
1100
746 5 foreach ( @{ $self->{'_elements'} } ) {
747 6 ▶ return 1 if ( $_ eq $name );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $name 3 3 6
748 }
749 2 return 0;
750 }
751  
752 =head2 in_element
753  
754 Title : in_element
755 Usage : if( $eventgenerator->in_element($element) ) {}
756 Function: Test if we are in a particular element
757 This is different than 'within' because 'in' only
758 tests its immediate parent.
759 Returns : boolean
760 Args : string element name
761  
762 =cut
763  
764 8 ▶sub in_element {
Subroutine in_element: called CC=2 SCAR=7.1
Pod documented
765 8 my ( $self, $name ) = @_;
766 8 ▶ return 0 if !defined $self->{'_elements'}->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_elements"}[0] 0 8 8
767 8 return ( $self->{'_elements'}->[0] eq $name );
768 }
769  
770 =head2 start_document
771  
772 Title : start_document
773 Usage : $eventgenerator->start_document
774 Function: Handle a start document event
775 Returns : none
776 Args : none
777  
778 =cut
779  
780 6 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
781 6 my ($self) = @_;
782 6 $self->{'_lasttype'} = '';
783 6 $self->{'_values'} = {};
784 6 $self->{'_result'} = undef;
785 6 $self->{'_elements'} = [];
786 }
787  
788 =head2 end_document
789  
790 Title : end_document
791 Usage : $eventgenerator->end_document
792 Function: Handles an end document event
793 Returns : Bio::Search::Result::ResultI object
794 Args : none
795  
796 =cut
797  
798 5 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
799 5 my ($self) = @_;
800 5 return $self->{'_result'};
801 }
802  
803 =head2 result_count
804  
805 Title : result_count
806 Usage : my $count = $searchio->result_count
807 Function: Returns the number of results we have processed
808 Returns : integer
809 Args : none
810  
811 =cut
812  
813 0 ▶sub result_count {
Subroutine result_count: not called CC=1 SCAR=6.9
Pod documented
814 0 my $self = shift;
815 0 return $self->{'_result_count'};
816 }
817  
818 =head2 model
819  
820 Title : model
821 Usage : my $model = $parser->model();
822 Function: Get/Set model; Infernal currently does not output
823 the model name (Rfam ID)
824 Returns : String (name of model)
825 Args : [optional] String (name of model)
826  
827 =cut
828  
829 1 ▶sub model {
Subroutine model: called CC=2 SCAR=8.1
Pod documented
830 1 my $self = shift;
831 1 ▶ return $self->{'_model'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
832 0 return $self->{'_model'};
833 }
834  
835 =head2 database
836  
837 Title : database
838 Usage : my $database = $parser->database();
839 Function: Get/Set database; pre-v.1 versions of Infernal do not output
840 the database name
841 Returns : String (database name)
842 Args : [optional] String (database name)
843  
844 =cut
845  
846 0 ▶sub database {
Subroutine database: not called CC=2 SCAR=17.9
Pod documented
847 0 my $self = shift;
848 0 ▶ return $self->{'_database'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
849 0 return $self->{'_database'};
850 }
851  
852 =head2 algorithm
853  
854 Title : algorithm
855 Usage : my $algorithm = $parser->algorithm();
856 Function: Get/Set algorithm; pre-v.1 versions of Infernal do not output
857 the algorithm name
858 Returns : String (algorithm name)
859 Args : [optional] String (algorithm name)
860  
861 =cut
862  
863 4 ▶sub algorithm {
Subroutine algorithm: called CC=2 SCAR=8.1
Pod documented
864 4 my $self = shift;
865 4 ▶ return $self->{'_algorithm'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
866 0 return $self->{'_algorithm'};
867 }
868  
869 =head2 query_accession
870  
871 Title : query_accession
872 Usage : my $acc = $parser->query_accession();
873 Function: Get/Set query (model) accession; pre-v1.1 Infernal does not output
874 the accession number (Rfam accession #)
875 Returns : String (accession)
876 Args : [optional] String (accession)
877  
878 =cut
879  
880 7 ▶sub query_accession {
Subroutine query_accession: called CC=2 SCAR=6.9
Pod documented
881 7 my $self = shift;
882 7 ▶ return $self->{'_query_accession'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 6 7
883 6 return $self->{'_query_accession'};
884 }
885  
886 =head2 query_description
887  
888 Title : query_description
889 Usage : my $acc = $parser->query_description();
890 Function: Get/Set query (model) description; pre-v1.1 Infernal does not output
891 the Rfam description
892 Returns : String (description)
893 Args : [optional] String (description)
894  
895 =cut
896  
897 7 ▶sub query_description {
Subroutine query_description: called CC=2 SCAR=6.9
Pod documented
898 7 my $self = shift;
899 7 ▶ return $self->{'_query_description'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 6 7
900 6 return $self->{'_query_description'};
901 }
902  
903 =head2 hsp_minscore
904  
905 Title : hsp_minscore
906 Usage : my $cutoff = $parser->hsp_minscore();
907 Function: Get/Set min bit score cutoff (for generating Hits/HSPs)
908 Returns : score (number)
909 Args : [optional] score (number)
910  
911 =cut
912  
913 4 ▶sub hsp_minscore {
Subroutine hsp_minscore: called CC=2 SCAR=8.1
Pod documented
914 4 my $self = shift;
915 4 ▶ return $self->{'_hsp_minscore'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
916 0 return $self->{'_hsp_minscore'};
917 }
918  
919 =head2 convert_meta
920  
921 Title : convert_meta
922 Usage : $parser->convert_meta(1);
923 Function: Get/Set boolean flag for converting Infernal WUSS format
924 to a simple bracketed format (simple WUSS by default)
925 Returns : boolean flag (TRUE or FALSE)
926 Args : [optional] boolean (eval's to TRUE or FALSE)
927  
928 =cut
929  
930 18 ▶sub convert_meta {
Subroutine convert_meta: called CC=2 SCAR=7.1
Pod documented
931 18 my $self = shift;
932 18 ▶ return $self->{'_convert_meta'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 18 18
933 18 return $self->{'_convert_meta'};
934 }
935  
936 =head2 version
937  
938 Title : version
939 Usage : $parser->version();
940 Function: Set the Infernal cmsearch version
941 Returns : version
942 Args : [optional] version
943  
944 =cut
945  
946 4 ▶sub version {
Subroutine version: called CC=2 SCAR=8.1
Pod documented
947 4 my $self = shift;
948 4 ▶ return $self->{'_version'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
949 0 return $self->{'_version'};
950 }
951  
952 =head2 structure_symbols
953  
954 Title : structure_symbols
955 Usage : my $hashref = $parser->structure_symbols();
956 Function: Get/Set RNA structure symbols
957 Returns : Hash ref of delimiters (5' stem, 3' stem, single-strand, etc)
958 : default = < (5-prime)
959 > (3-prime)
960 : (single-strand)
961 ? (unknown)
962 . (gap)
963 Args : Hash ref of substitute delimiters, using above keys.
964  
965 =cut
966  
967 4 ▶sub structure_symbols {
Subroutine structure_symbols: called CC=5 SCAR=16.8
Pod documented
968 4 my ($self, $delim) = @_;
969 4 ▶ if ($delim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delim) 4 0 4
970 4 ▶ if (ref($delim) =~ m{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($delim) =~ /HASH/) { } 4 0 4
971 4 my %data = %{ $delim };
972 4 for my $d (@VALID_SYMBOLS) {
973 20 ▶ if ( exists $data{$d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data{$d}) 20 0 20
974 20 $self->{'_delimiter'}->{$d} = $data{$d};
975 }
976 }
977 } else {
978 0 $self->throw("Args to helix_delimiters() should be in a hash reference");
979 }
980 }
981 4 return $self->{'_delimiter'};
982 }
983  
984 =head2 simple_meta
985  
986 Title : simple_meta
987 Usage : my $string = $parser->simple_meta($str);
988 Function: converts more complex WUSS meta format into simple bracket format
989 using symbols defined in structure_symbols()
990 Returns : converted string
991 Args : [required] string to convert
992 Note : This is a very simple conversion method to get simple bracketed
993 format from Infernal data. If the convert_meta() flag is set,
994 this is the method used to convert the strings.
995  
996 =cut
997  
998 0 ▶sub simple_meta {
Subroutine simple_meta: not called CC=2 SCAR=17.9
Pod documented
999 0 my ($self, $str) = @_;
1000 0 ▶ $self->throw("No string arg sent!") if !$str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 0 0
1001 0 my $structs = $self->structure_symbols();
1002 my ($ls, $rs, $ss, $unk, $gap) = ($structs->{'5-prime'}, $structs->{'3-prime'},
1003 $structs->{'single-strand'}, $structs->{'unknown'},
1004 0 $structs->{'gap'});
1005 0 $str =~ s{[\(\<\[\{]}{$ls}g;
1006 0 $str =~ s{[\)\>\]\}]}{$rs}g;
1007 0 $str =~ s{[:,_-]}{$ss}g;
1008 0 $str =~ s{\.}{$gap}g;
1009 # unknown not handled yet
1010 0 return $str;
1011 }
1012  
1013 ## private methods
1014  
1015 # this is a hack which guesses the format and sets the handler for parsing in
1016 # an instance; it'll be taken out when infernal 1.0 is released
1017  
1018 1 ▶sub _parse_latest {
Subroutine _parse_latest: called CC=42 SCAR=40.0
1019 1 my ($self) = @_;
1020 1 my $seentop = 0;
1021 1 local $/ = "\n";
1022 1 my ($accession, $description) = ($self->query_accession, $self->query_description);
1023 1 my ($maxscore, $mineval, $minpval);
1024 1 $self->start_document();
1025 1 my ($lasthit, $lastscore, $lasteval, $lastpval, $laststart, $lastend);
1026 PARSER:
1027 1 ▶ while (my $line = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->_readline) 55 0 55
1028 55 ▶ next if $line =~ m{^\s+$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 7 48 55
1029 # stats aren't parsed yet...
1030 48 ▶ if ($line =~ m{^\#\s+cmsearch}xms) {
Branch: 10 branches
BranchTrueFalseTotal
if ($line =~ /^\#\s+cmsearch/msx) { } 1 47 48
elsif ($line =~ /^\#\sINFERNAL\s+(\d+\.\d+)/msx) { } 1 46 47
elsif ($line =~ /^\#\scommand:.*?\s(\S+)$/msx) { } 1 45 46
elsif ($line =~ /^\#\s+dbsize\(Mb\):\s+(\d+\.\d+)/msx) { } 1 44 45
elsif ($line =~ /^CM(?:\s(\d+))?:\s*(\S+)/msx) { } 1 43 44
elsif ($line =~ /^>\s*(\S+)/) { } 1 42 43
elsif ($line =~ m[ ^\sQuery\s=\s\d+\s-\s\d+,\s # Query start/end Target\s=\s(\d+)\s-\s(\d+) # Target start/end ]mosx) { } 3 39 42
elsif ($line =~ / ^\sScore\s=\s([\d\.]+),\s # Score = Bitscore (for now) (?:E\s=\s([\d\.e-]+),\s # E-val optional P\s=\s([\d\.e-]+),\s)? # P-val optional GC\s= # GC not captured /mosx) { } 3 36 39
elsif ($line =~ /^(\s+)[<>\{\}\(\)\[\]:_,-\.]+/msx) { } 3 33 36
elsif ($line =~ m[^//]msx) { } 1 32 33
1031 1 $seentop = 1;
1032 1 $self->start_element({'Name' => 'Result'});
1033 1 $self->element_hash({
1034 'Infernal_program' => 'CMSEARCH'
1035 });
1036 }
1037 elsif ($line =~ m{^\#\sINFERNAL\s+(\d+\.\d+)}xms) {
1038 1 $self->element_hash({
1039 'Infernal_version' => $1,
1040 });
1041 }
1042 elsif ($line =~ m{^\#\scommand:.*?\s(\S+)$}xms) {
1043 1 $self->element_hash({
1044 'Infernal_db' => $1,
1045 });
1046 }
1047 elsif ($line =~ m{^\#\s+dbsize\(Mb\):\s+(\d+\.\d+)}xms) {
1048 # store absolute DB length
1049 1 $self->element_hash({
1050 'Infernal_db-let' => $1 * 1e6
1051 });
1052 }
1053 elsif ($line =~ m{^CM(?:\s(\d+))?:\s*(\S+)}xms) {
1054 # not sure, but it's possible single reports may contain multiple
1055 # models; if so, they should be rolled over into a new ResultI
1056 #print STDERR "ACC: $accession\nDESC: $description\n";
1057 1 $self->element_hash({
1058 'Infernal_query-def' => $2, # present in output now
1059 'Infernal_query-acc' => $accession,
1060 'Infernal_querydesc' => $description
1061 });
1062 }
1063 elsif ($line =~ m{^>\s*(\S+)} ){
1064 #$self->debug("Start Hit: Found hit:$1\n");
1065 1 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 0 1 1
1066 0 $self->element_hash({'Hit_score' => $maxscore,
1067 'Hit_bits' => $maxscore});
1068 0 ($maxscore, $minpval, $mineval) = undef;
1069 0 $self->end_element({'Name' => 'Hit'});
1070 }
1071 1 $lasthit = $1;
1072 }
1073 elsif ($line =~ m{
1074 ^\sQuery\s=\s\d+\s-\s\d+,\s # Query start/end
1075 Target\s=\s(\d+)\s-\s(\d+) # Target start/end
1076 }xmso) {
1077 # Query (model) start/end always the same, determined from
1078 # the HSP length
1079 3 ($laststart, $lastend) = ($1, $2);
1080 #$self->debug("Found hit coords:$laststart - $lastend\n");
1081 } elsif ($line =~ m{
1082 ^\sScore\s=\s([\d\.]+),\s # Score = Bitscore (for now)
1083 (?:E\s=\s([\d\.e-]+),\s # E-val optional
1084 P\s=\s([\d\.e-]+),\s)? # P-val optional
1085 GC\s= # GC not captured
1086 }xmso
1087 ) {
1088 3 ($lastscore, $lasteval, $lastpval) = ($1, $2, $3);
1089 #$self->debug(sprintf("Found hit data:Score:%s,Eval:%s,Pval:%s\n",$lastscore, $lasteval||'', $lastpval||''));
1090 3 ▶ $maxscore ||= $lastscore;
Condition66%2/3
$maxscore ||= $lastscore
l!l&&r!l&&!r
210
MC/DC0%0/2
$maxscore ||= $lastscore
$maxscore $lastscore
Truth table66%2/3
A ||= B
A= $maxscoreB= $lastscore
ABresult
1X1
011
000
1091 3 ▶ if ($lasteval && $lastpval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lasteval and $lastpval) 3 0 3
Condition33%1/3
$lasteval and $lastpval
!ll&&!rl&&r
003
MC/DC0%0/2
$lasteval and $lastpval
$lasteval $lastpval
Truth table33%1/3
A and B
A= $lastevalB= $lastpval
ABresult
0X0
100
111
1092 3 ▶ $mineval ||= $lasteval;
Condition66%2/3
$mineval ||= $lasteval
l!l&&r!l&&!r
210
MC/DC0%0/2
$mineval ||= $lasteval
$mineval $lasteval
Truth table66%2/3
A ||= B
A= $minevalB= $lasteval
ABresult
1X1
011
000
1093 3 ▶ $minpval ||= $lastpval;
Condition66%2/3
$minpval ||= $lastpval
l!l&&r!l&&!r
210
MC/DC0%0/2
$minpval ||= $lastpval
$minpval $lastpval
Truth table66%2/3
A ||= B
A= $minpvalB= $lastpval
ABresult
1X1
011
000
1094 3 ▶ $mineval = ($mineval > $lasteval) ? $lasteval :
Branch: 1 branch
BranchTrueFalseTotal
$mineval > $lasteval ? : 0 3 3
1095 $mineval;
1096 3 ▶ $minpval = ($minpval > $lastpval) ? $lastpval :
Branch: 1 branch
BranchTrueFalseTotal
$minpval > $lastpval ? : 0 3 3
1097 $minpval;
1098 }
1099 3 ▶ $maxscore = ($maxscore < $lastscore) ? $lastscore :
Branch: 1 branch
BranchTrueFalseTotal
$maxscore < $lastscore ? : 0 3 3
1100 $maxscore;
1101 3 ▶ if (!$self->within_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->within_element("hit")) 1 2 3
1102 1 my ($gi, $acc, $ver) = $self->_get_seq_identifiers($lasthit);
1103 1 $self->start_element({'Name' => 'Hit'});
1104 1 ▶ $self->element_hash({
Branch: 2 branches
BranchTrueFalseTotal
$ver ? : 0 1 1
$acc ? : 1 0 1
1105 'Hit_id' => $lasthit,
1106 'Hit_accession' => $ver ? "$acc.$ver" :
1107 $acc ? $acc : $lasthit,
1108 'Hit_gi' => $gi
1109 });
1110 }
1111 3 ▶ if (!$self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_element("hsp")) 3 0 3
1112 3 $self->start_element({'Name' => 'Hsp'});
1113 }
1114  
1115 # hsp is similar to older output
1116 } elsif ($line =~ m{^(\s+)[<>\{\}\(\)\[\]:_,-\.]+}xms) { # start of HSP
1117 3 $self->_pushback($line); # set up for loop
1118 #$self->debug("Start HSP\n");
1119 # what is length of the gap to the structure data?
1120 3 my $offset = length($1);
1121 3 my ($ct, $strln) = 0;
1122 3 my $hsp;
1123 3 HSP:
1124 my %hsp_key = ('0' => 'meta',
1125 '1' => 'query',
1126 '2' => 'midline',
1127 '3' => 'hit');
1128 HSP:
1129 3 ▶ while (defined ($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 31 0 31
1130 31 chomp $line;
1131 31 ▶ next if (!$line); # toss empty lines
Branch: 1 branch
BranchTrueFalseTotal
unless $line 8 23 31
1132 # next if $line =~ m{^\s*$}; # toss empty lines
1133 # it is possible to have homology lines consisting
1134 # entirely of spaces if the subject has a large
1135 # insertion where nothing matches the model
1136  
1137 # exit loop if at end of file or upon next hit/HSP
1138 23 ▶ if ($line =~ m{^\s{0,2}\S+}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{0,2}\S+/) 3 20 23
1139 3 $self->_pushback($line);
1140 3 last HSP;
1141 }
1142 # iterate to keep track of each line (4 lines per hsp block)
1143 20 my $iterator = $ct % 4;
1144 # strlen set only with structure lines (proper length)
1145 20 ▶ $strln = length($line) if $iterator == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator == 0 5 15 20
1146 # only grab the data needed (hit start and stop in hit line above)
1147  
1148 20 my $data = substr($line, $offset, $strln-$offset);
1149 20 $hsp->{ $hsp_key{$iterator} } .= $data;
1150  
1151 20 $ct++;
1152 }
1153  
1154 # query start, end are from the actual query length (entire hit is
1155 # mapped to CM data, so all CM data is represented)
1156 # works for now...
1157 3 ▶ if ($self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hsp")) 3 0 3
1158 # In some cases with HSPs unaligned residues are present in
1159 # the hit or query (Ex: '*[ 8]*' is 8 unaligned residues).
1160 # This info needs to be passed on unmodifed to the HSP class
1161 # and handled there as it is subjectively changed based on
1162 # use.
1163 3 my $strlen = 0;
1164  
1165 # catch any insertions and add them into the actual length
1166 3 ▶ while ($hsp->{'query'} =~ m{\*\[\s*(\d+)\s*\]\*}g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hsp->{"query"} =~ /\*\[\s*(\d+)\s*\]\*/g) 2 3 5
1167 2 $strlen += $1;
1168 }
1169 # add on the actual residues
1170 3 $strlen += $hsp->{'query'} =~ tr{A-Za-z}{A-Za-z};
1171  
1172 my $metastr = ($self->convert_meta) ? ($self->simple_meta($hsp->{'meta'})) :
1173 3 ▶ $hsp->{'meta'};
Branch: 1 branch
BranchTrueFalseTotal
$self->convert_meta ? : 0 3 3
1174 $self->element_hash(
1175 {'Hsp_stranded' => 'HIT',
1176 'Hsp_qseq' => $hsp->{'query'},
1177 'Hsp_hseq' => $hsp->{'hit'},
1178 3 'Hsp_midline' => $hsp->{'midline'},
1179 'Hsp_structure' => $metastr,
1180 'Hsp_query-from' => 1,
1181 'Infernal_query-len' => $strlen,
1182 'Hsp_query-to' => $strlen,
1183 'Hsp_hit-from' => $laststart,
1184 'Hsp_hit-to' => $lastend,
1185 'Hsp_score' => $lastscore,
1186 'Hsp_bit-score' => $lastscore,
1187 });
1188 3 ▶ $self->element_hash(
Branch: 1 branch
BranchTrueFalseTotal
if $lasteval and $lastpval 3 0 3
Condition33%1/3
$lasteval and $lastpval
!ll&&!rl&&r
003
MC/DC0%0/2
$lasteval and $lastpval
$lasteval $lastpval
Truth table33%1/3
A and B
A= $lastevalB= $lastpval
ABresult
0X0
100
111
1189 {'Hsp_evalue' => $lasteval,
1190 'Hsp_pvalue' => $lastpval,
1191 }) if ($lasteval && $lastpval);
1192 3 $self->end_element({'Name' => 'Hsp'});
1193 }
1194 # result now ends with // and 'Fin'
1195 } elsif ($line =~ m{^//}xms ) {
1196 1 ▶ if ($self->within_element('result') && $seentop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->within_element("result") and $seentop) 1 0 1
Condition33%1/3
$self->within_element("result") and $seentop
!ll&&!rl&&r
001
MC/DC0%0/2
$self->within_element("result") and $seentop
$self->within_element("result") $seentop
Truth table33%1/3
A and B
A= $self->within_element("result")B= $seentop
ABresult
0X0
100
111
1197 1 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 1 0 1
1198 1 $self->element_hash({'Hit_score' => $maxscore,
1199 'Hit_bits' => $maxscore});
1200 # don't know where to put minpval yet
1201 1 ▶ $self->element_hash({'Hit_signif' => $mineval}) if $mineval;
Branch: 1 branch
BranchTrueFalseTotal
if $mineval 1 0 1
1202 1 ▶ $self->element_hash({'Hit_p' => $minpval}) if $minpval;
Branch: 1 branch
BranchTrueFalseTotal
if $minpval 1 0 1
1203 1 $self->end_element({'Name' => 'Hit'});
1204 }
1205 1 last PARSER;
1206 }
1207 }
1208 }
1209 1 ▶ $self->within_element('hit') && $self->end_element( { 'Name' => 'Hit' } );
Branch: 1 branch
BranchTrueFalseTotal
$self->within_element("hit") and $self->end_element({"Name", "Hit"}) 0 1 1
1210 1 ▶ $self->end_element( { 'Name' => 'Result' } ) if $seentop;
Branch: 1 branch
BranchTrueFalseTotal
if $seentop 1 0 1
1211 1 return $self->end_document();
1212 }
1213  
1214 # cmsearch 0.81 (pre-1.0)
1215 0 ▶sub _parse_pre {
Subroutine _parse_pre: not called CC=37 SCAR=72.5
1216 0 my ($self) = @_;
1217 0 my $seentop = 0;
1218 0 local $/ = "\n";
1219 0 my ($accession, $db, $algorithm, $description, $version) =
1220 ($self->query_accession, $self->database, $self->algorithm,
1221 $self->query_description, '0.81');
1222 0 my ($maxscore, $mineval, $minpval);
1223 0 $self->start_document();
1224 0 my ($lasthit, $lastscore, $lasteval, $lastpval, $laststart, $lastend);
1225 PARSER:
1226 0 ▶ while (my $line = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->_readline) 0 0 0
1227 0 ▶ next if $line =~ m{^\s+$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 0 0 0
1228 # stats aren't parsed yet...
1229 0 ▶ if ($line =~ m{CM\s\d+:\s*(\S+)}xms) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line =~ /CM\s\d+:\s*(\S+)/msx) { } 0 0 0
elsif ($line =~ /^>\s*(\S+)/) { } 0 0 0
elsif ($line =~ m[ ^\sQuery\s=\s\d+\s-\s\d+,\s # Query start/end Target\s=\s(\d+)\s-\s(\d+) # Target start/end ]mosx) { } 0 0 0
elsif ($line =~ / ^\sScore\s=\s([\d\.]+),\s # Score = Bitscore (for now) (?:E\s=\s([\d\.e-]+),\s # E-val optional P\s=\s([\d\.e-]+),\s)? # P-val optional GC\s= # GC not captured /mosx) { } 0 0 0
elsif ($line =~ /^(\s+)[<>\{\}\(\)\[\]:_,-\.]+/msx) { } 0 0 0
elsif ($line =~ m[^//]msx) { } 0 0 0
1230 #$self->debug("Start Result: Found model:$1\n");
1231 0 ▶ if (!$self->within_element('result')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->within_element("result")) 0 0 0
1232 0 $seentop = 1;
1233 0 $self->start_element({'Name' => 'Result'});
1234 0 $self->element_hash({
1235 'Infernal_program' => $algorithm,
1236 'Infernal_query-def' => $1, # present in output now
1237 'Infernal_query-acc' => $accession,
1238 'Infernal_querydesc' => $description,
1239 'Infernal_db' => $db
1240 });
1241 }
1242 } elsif ($line =~ m{^>\s*(\S+)} ){
1243 #$self->debug("Start Hit: Found hit:$1\n");
1244 0 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 0 0 0
1245 0 $self->element_hash({'Hit_score' => $maxscore,
1246 'Hit_bits' => $maxscore});
1247 0 ($maxscore, $minpval, $mineval) = undef;
1248 0 $self->end_element({'Name' => 'Hit'});
1249 }
1250 0 $lasthit = $1;
1251 }
1252 elsif ($line =~ m{
1253 ^\sQuery\s=\s\d+\s-\s\d+,\s # Query start/end
1254 Target\s=\s(\d+)\s-\s(\d+) # Target start/end
1255 }xmso) {
1256 # Query (model) start/end always the same, determined from
1257 # the HSP length
1258 0 ($laststart, $lastend) = ($1, $2);
1259 #$self->debug("Found hit coords:$laststart - $lastend\n");
1260 } elsif ($line =~ m{
1261 ^\sScore\s=\s([\d\.]+),\s # Score = Bitscore (for now)
1262 (?:E\s=\s([\d\.e-]+),\s # E-val optional
1263 P\s=\s([\d\.e-]+),\s)? # P-val optional
1264 GC\s= # GC not captured
1265 }xmso
1266 ) {
1267 0 ($lastscore, $lasteval, $lastpval) = ($1, $2, $3);
1268 #$self->debug(sprintf("Found hit data:Score:%s,Eval:%s,Pval:%s\n",$lastscore, $lasteval||'', $lastpval||''));
1269 0 ▶ $maxscore ||= $lastscore;
Condition0%0/3
$maxscore ||= $lastscore
l!l&&r!l&&!r
000
MC/DC0%0/2
$maxscore ||= $lastscore
$maxscore $lastscore
Truth table0%0/3
A ||= B
A= $maxscoreB= $lastscore
ABresult
1X1
011
000
1270 0 ▶ if ($lasteval && $lastpval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lasteval and $lastpval) 0 0 0
Condition0%0/3
$lasteval and $lastpval
!ll&&!rl&&r
000
MC/DC0%0/2
$lasteval and $lastpval
$lasteval $lastpval
Truth table0%0/3
A and B
A= $lastevalB= $lastpval
ABresult
0X0
100
111
1271 0 ▶ $mineval ||= $lasteval;
Condition0%0/3
$mineval ||= $lasteval
l!l&&r!l&&!r
000
MC/DC0%0/2
$mineval ||= $lasteval
$mineval $lasteval
Truth table0%0/3
A ||= B
A= $minevalB= $lasteval
ABresult
1X1
011
000
1272 0 ▶ $minpval ||= $lastpval;
Condition0%0/3
$minpval ||= $lastpval
l!l&&r!l&&!r
000
MC/DC0%0/2
$minpval ||= $lastpval
$minpval $lastpval
Truth table0%0/3
A ||= B
A= $minpvalB= $lastpval
ABresult
1X1
011
000
1273 0 ▶ $mineval = ($mineval > $lasteval) ? $lasteval :
Branch: 1 branch
BranchTrueFalseTotal
$mineval > $lasteval ? : 0 0 0
1274 $mineval;
1275 0 ▶ $minpval = ($minpval > $lastpval) ? $lastpval :
Branch: 1 branch
BranchTrueFalseTotal
$minpval > $lastpval ? : 0 0 0
1276 $minpval;
1277 }
1278 0 ▶ $maxscore = ($maxscore < $lastscore) ? $lastscore :
Branch: 1 branch
BranchTrueFalseTotal
$maxscore < $lastscore ? : 0 0 0
1279 $maxscore;
1280 0 ▶ if (!$self->within_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->within_element("hit")) 0 0 0
1281 0 my ($gi, $acc, $ver) = $self->_get_seq_identifiers($lasthit);
1282 0 $self->start_element({'Name' => 'Hit'});
1283 0 ▶ $self->element_hash({
Branch: 2 branches
BranchTrueFalseTotal
$ver ? : 0 0 0
$acc ? : 0 0 0
1284 'Hit_id' => $lasthit,
1285 'Hit_accession' => $ver ? "$acc.$ver" :
1286 $acc ? $acc : $lasthit,
1287 'Hit_gi' => $gi
1288 });
1289 }
1290 0 ▶ if (!$self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_element("hsp")) 0 0 0
1291 0 $self->start_element({'Name' => 'Hsp'});
1292 }
1293  
1294 # hsp is similar to older output
1295 } elsif ($line =~ m{^(\s+)[<>\{\}\(\)\[\]:_,-\.]+}xms) { # start of HSP
1296 0 $self->_pushback($line); # set up for loop
1297 #$self->debug("Start HSP\n");
1298 # what is length of the gap to the structure data?
1299 0 my $offset = length($1);
1300 0 my ($ct, $strln) = 0;
1301 0 my $hsp;
1302 0 HSP:
1303 my %hsp_key = ('0' => 'meta',
1304 '1' => 'query',
1305 '2' => 'midline',
1306 '3' => 'hit');
1307 HSP:
1308 0 ▶ while (defined ($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 0 0 0
1309 0 chomp $line;
1310 0 ▶ next if (!$line); # toss empty lines
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
1311 # next if $line =~ m{^\s*$}; # toss empty lines
1312 # it is possible to have homology lines consisting
1313 # entirely of spaces if the subject has a large
1314 # insertion where nothing matches the model
1315  
1316 # exit loop if at end of file or upon next hit/HSP
1317 0 ▶ if ($line =~ m{^\s{0,2}\S+}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{0,2}\S+/) 0 0 0
1318 0 $self->_pushback($line);
1319 0 last HSP;
1320 }
1321 # iterate to keep track of each line (4 lines per hsp block)
1322 0 my $iterator = $ct%4;
1323 # strlen set only with structure lines (proper length)
1324 0 ▶ $strln = length($line) if $iterator == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator == 0 0 0 0
1325 # only grab the data needed (hit start and stop in hit line above)
1326  
1327 0 my $data = substr($line, $offset, $strln-$offset);
1328 0 $hsp->{ $hsp_key{$iterator} } .= $data;
1329  
1330 0 $ct++;
1331 }
1332  
1333 # query start, end are from the actual query length (entire hit is
1334 # mapped to CM data, so all CM data is represented)
1335 # works for now...
1336 0 ▶ if ($self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hsp")) 0 0 0
1337 0 my $strlen = $hsp->{'query'} =~ tr{A-Za-z}{A-Za-z};
1338  
1339 0 my $metastr;
1340 $metastr = ($self->convert_meta) ? ($self->simple_meta($hsp->{'meta'})) :
1341 0 ▶ ($hsp->{'meta'});
Branch: 1 branch
BranchTrueFalseTotal
$self->convert_meta ? : 0 0 0
1342 $self->element_hash(
1343 {'Hsp_stranded' => 'HIT',
1344 'Hsp_qseq' => $hsp->{'query'},
1345 'Hsp_hseq' => $hsp->{'hit'},
1346 0 'Hsp_midline' => $hsp->{'midline'},
1347 'Hsp_structure' => $metastr,
1348 'Hsp_query-from' => 1,
1349 'Infernal_query-len' => $strlen,
1350 'Hsp_query-to' => $strlen,
1351 'Hsp_hit-from' => $laststart,
1352 'Hsp_hit-to' => $lastend,
1353 'Hsp_score' => $lastscore,
1354 'Hsp_bit-score' => $lastscore,
1355 });
1356 0 ▶ $self->element_hash(
Branch: 1 branch
BranchTrueFalseTotal
if $lasteval and $lastpval 0 0 0
Condition0%0/3
$lasteval and $lastpval
!ll&&!rl&&r
000
MC/DC0%0/2
$lasteval and $lastpval
$lasteval $lastpval
Truth table0%0/3
A and B
A= $lastevalB= $lastpval
ABresult
0X0
100
111
1357 {'Hsp_evalue' => $lasteval,
1358 'Hsp_pvalue' => $lastpval,
1359 }) if ($lasteval && $lastpval);
1360 0 $self->end_element({'Name' => 'Hsp'});
1361 }
1362 # result now ends with // and 'Fin'
1363 } elsif ($line =~ m{^//}xms ) {
1364 0 ▶ if ($self->within_element('result') && $seentop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->within_element("result") and $seentop) 0 0 0
Condition0%0/3
$self->within_element("result") and $seentop
!ll&&!rl&&r
000
MC/DC0%0/2
$self->within_element("result") and $seentop
$self->within_element("result") $seentop
Truth table0%0/3
A and B
A= $self->within_element("result")B= $seentop
ABresult
0X0
100
111
1365 0 $self->element(
1366 {'Name' => 'Infernal_version',
1367 'Data' => $version}
1368 );
1369 0 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 0 0 0
1370 0 $self->element_hash({'Hit_score' => $maxscore,
1371 'Hit_bits' => $maxscore});
1372 # don't know where to put minpval yet
1373 0 ▶ $self->element_hash({'Hit_signif' => $mineval}) if $mineval;
Branch: 1 branch
BranchTrueFalseTotal
if $mineval 0 0 0
1374 0 $self->end_element({'Name' => 'Hit'});
1375 }
1376 0 last PARSER;
1377 }
1378 }
1379 }
1380 0 ▶ $self->within_element('hit') && $self->end_element( { 'Name' => 'Hit' } );
Branch: 1 branch
BranchTrueFalseTotal
$self->within_element("hit") and $self->end_element({"Name", "Hit"}) 0 0 0
1381 0 ▶ $self->end_element( { 'Name' => 'Result' } ) if $seentop;
Branch: 1 branch
BranchTrueFalseTotal
if $seentop 0 0 0
1382 0 return $self->end_document();
1383 }
1384  
1385 # cmsearch 0.72 and below; will likely be dropped when Infernal 1.0 is released
1386 0 ▶sub _parse_old {
Subroutine _parse_old: not called CC=30 SCAR=68.4
1387 0 my ($self) = @_;
1388 0 my $seentop = 0;
1389 0 local $/ = "\n";
1390 0 my ($accession, $db, $algorithm, $model, $description, $version) =
1391 ($self->query_accession, $self->database, $self->algorithm,
1392 $self->model, $self->query_description, $self->version);
1393 0 my $maxscore;
1394 0 my $cutoff = $self->hsp_minscore;
1395 0 $self->start_document();
1396 0 local ($_);
1397 0 my $line;
1398 0 my ($lasthit, $lastscore, $laststart, $lastend);
1399 0 my $hitline;
1400 PARSER:
1401 0 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 0 0 0
1402 0 ▶ next if $line =~ m{^\s+$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 0 0 0
1403 # bypass this for now...
1404 0 ▶ next if $line =~ m{^HMM\shit};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^HMM\shit/ 0 0 0
1405 # pre-0.81
1406 0 ▶ if ($line =~ m{^sequence:\s+(\S+)} ){
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^sequence:\s+(\S+)/) { } 0 0 0
elsif ($line =~ /^hit\s+\d+\s+:\s+(\d+)\s+(\d+)\s+(\d+\.\d+)\s+bits/msx) { } 0 0 0
elsif ($line =~ /^(\s+)[<>\{\}\(\)\[\]:_,-\.]+/msx) { } 0 0 0
elsif ($line =~ /^memory/msx or $line =~ /^CYK\smemory/msx) { } 0 0 0
1407 0 ▶ if (!$self->within_element('result')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->within_element("result")) 0 0 0
1408 0 $seentop = 1;
1409 0 $self->start_element({'Name' => 'Result'});
1410 0 $self->element_hash({
1411 'Infernal_program' => $algorithm,
1412 'Infernal_query-def' => $model,
1413 'Infernal_query-acc' => $accession,
1414 'Infernal_querydesc' => $description,
1415 'Infernal_db' => $db
1416 });
1417 }
1418 0 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 0 0 0
1419 0 $self->element_hash({'Hit_score' => $maxscore,
1420 'Hit_bits' => $maxscore});
1421 0 $maxscore = undef;
1422 0 $self->end_element({'Name' => 'Hit'});
1423 }
1424 0 $lasthit = $1;
1425 } elsif ($line =~ m{^hit\s+\d+\s+:\s+(\d+)\s+(\d+)\s+(\d+\.\d+)\s+bits}xms) {
1426 0 ($laststart, $lastend, $lastscore) = ($1, $2, $3);
1427 0 ▶ $maxscore = $lastscore unless $maxscore;
Branch: 1 branch
BranchTrueFalseTotal
unless $maxscore 0 0 0
1428 0 ▶ if ($lastscore > $cutoff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lastscore > $cutoff) 0 0 0
1429 0 ▶ if (!$self->within_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->within_element("hit")) 0 0 0
1430 0 my ($gi, $acc, $ver) = $self->_get_seq_identifiers($lasthit);
1431 0 $self->start_element({'Name' => 'Hit'});
1432 0 ▶ $self->element_hash({
Branch: 2 branches
BranchTrueFalseTotal
$ver ? : 0 0 0
$acc ? : 0 0 0
1433 'Hit_id' => $lasthit,
1434 'Hit_accession' => $ver ? "$acc.$ver" :
1435 $acc ? $acc : $lasthit,
1436 'Hit_gi' => $gi
1437 });
1438 }
1439 # necessary as infernal 0.71 has repeated hit line
1440 0 ▶ if (!$self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->in_element("hsp")) 0 0 0
1441 0 $self->start_element({'Name' => 'Hsp'});
1442 }
1443 0 ▶ $maxscore = ($maxscore < $lastscore) ? $lastscore :
Branch: 1 branch
BranchTrueFalseTotal
$maxscore < $lastscore ? : 0 0 0
1444 $maxscore;
1445 }
1446 } elsif ($line =~ m{^(\s+)[<>\{\}\(\)\[\]:_,-\.]+}xms) { # start of HSP
1447 0 $self->_pushback($line); # set up for loop
1448 # what is length of the gap to the structure data?
1449 0 my $offset = length($1);
1450 0 my ($ct, $strln) = 0;
1451 0 my $hsp;
1452 0 HSP:
1453 my %hsp_key = ('0' => 'meta',
1454 '1' => 'query',
1455 '2' => 'midline',
1456 '3' => 'hit');
1457 HSP:
1458 0 ▶ while ($line = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line = $self->_readline) 0 0 0
1459 0 ▶ next if $line =~ m{^\s*$}; # toss empty lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
1460 0 chomp $line;
1461 # exit loop if at end of file or upon next hit/HSP
1462 0 ▶ if (!defined($line) || $line =~ m{^\S+}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $line or $line =~ /^\S+/) 0 0 0
Condition0%0/3
not defined $line or $line =~ /^\S+/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $line or $line =~ /^\S+/
not defined $line $line =~ /^\S+/
Truth table0%0/3
not(A) or B
A= not defined $lineB= $line =~ /^\S+/
ABresult
1X1
011
000
1463 0 $self->_pushback($line);
1464 0 last HSP;
1465 }
1466 # iterate to keep track of each line (4 lines per hsp block)
1467 0 my $iterator = $ct%4;
1468 # strlen set only with structure lines (proper length)
1469 0 ▶ $strln = length($line) if $iterator == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator == 0 0 0 0
1470 # only grab the data needed (hit start and stop in hit line above)
1471  
1472 0 my $data = substr($line, $offset, $strln-$offset);
1473 0 $hsp->{ $hsp_key{$iterator} } .= $data;
1474 0 $ct++;
1475 }
1476 # query start, end are from the actual query length (entire hit is
1477 # mapped to CM data, so all CM data is represented)
1478 # works for now...
1479 0 ▶ if ($self->in_element('hsp')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hsp")) 0 0 0
1480 0 my $strlen = $hsp->{'query'} =~ tr{A-Za-z}{A-Za-z};
1481
1482 0 my $metastr;
1483 # Ugh...these should be passed in a hash
1484 $metastr = ($self->convert_meta) ? ($self->simple_meta($hsp->{'meta'})) :
1485 0 ▶ ($hsp->{'meta'});
Branch: 1 branch
BranchTrueFalseTotal
$self->convert_meta ? : 0 0 0
1486 $self->element_hash(
1487 {'Hsp_stranded' => 'HIT',
1488 'Hsp_qseq' => $hsp->{'query'},
1489 'Hsp_hseq' => $hsp->{'hit'},
1490 0 'Hsp_midline' => $hsp->{'midline'},
1491 'Hsp_structure' => $metastr,
1492 'Hsp_query-from' => 1,
1493 'Infernal_query-len' => $strlen,
1494 'Hsp_query-to' => $strlen,
1495 'Hsp_hit-from' => $laststart,
1496 'Hsp_hit-to' => $lastend,
1497 'Hsp_score' => $lastscore,
1498 'Hsp_bit-score' => $lastscore
1499 });
1500 0 $self->end_element({'Name' => 'Hsp'});
1501 }
1502 ▶ } elsif ($line =~ m{^memory}xms || $line =~ m{^CYK\smemory}xms ) {
Condition0%0/3
$line =~ /^memory/msx or $line =~ /^CYK\smemory/msx
l!l&&r!l&&!r
000
MC/DC0%0/2
$line =~ /^memory/msx or $line =~ /^CYK\smemory/msx
$line =~ /^memory/msx $line =~ /^CYK\smemory/msx
Truth table0%0/3
A or B
A= $line =~ /^memory/msxB= $line =~ /^CYK\smemory/msx
ABresult
1X1
011
000
1503 0 ▶ if ($self->within_element('result') && $seentop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->within_element("result") and $seentop) 0 0 0
Condition0%0/3
$self->within_element("result") and $seentop
!ll&&!rl&&r
000
MC/DC0%0/2
$self->within_element("result") and $seentop
$self->within_element("result") $seentop
Truth table0%0/3
A and B
A= $self->within_element("result")B= $seentop
ABresult
0X0
100
111
1504 0 $self->element(
1505 {'Name' => 'Infernal_version',
1506 'Data' => $version}
1507 );
1508 0 ▶ if ($self->in_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 0 0 0
1509 0 $self->element_hash({'Hit_score' => $maxscore,
1510 'Hit_bits' => $maxscore});
1511 0 $self->end_element({'Name' => 'Hit'});
1512 }
1513 0 last PARSER;
1514 }
1515 }
1516 }
1517 0 ▶ $self->within_element('hit') && $self->end_element( { 'Name' => 'Hit' } );
Branch: 1 branch
BranchTrueFalseTotal
$self->within_element("hit") and $self->end_element({"Name", "Hit"}) 0 0 0
1518 0 ▶ $self->end_element( { 'Name' => 'Result' } ) if $seentop;
Branch: 1 branch
BranchTrueFalseTotal
if $seentop 0 0 0
1519 0 return $self->end_document();
1520 }
1521  
1522 2 1;
« Bio/SeqUtils.pm ↑ Summary Bio/Tools/Run/WrapperBase/CommandExts.pm »