Bio/SearchIO/blasttable.pm

filter: Statementstmt 87.2% 157 / 180 Branchbran 73.0% 57 / 78 Conditioncond 61.1% 22 / 36 MC/DCmcdc 39.1% 9 / 23 Subroutinesub 80.9% 17 / 21 Podpod 91.6% 11 / 12 totaltotal 78.0% 273 / 350 CC 53 SCAR 27.6
CC
53
Cov
80%
within_element
42.0
next_result
27.3
characters
9.1
CRAP 15.8
« Bio/Tree/RandomFactory.pm ↑ Summary Bio/Tools/Genemark.pm »
1 #
2 # BioPerl module for Bio::SearchIO::blasttable
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::SearchIO::blasttable - Driver module for SearchIO for parsing NCBI -m 8/9 format
17  
18 =head1 SYNOPSIS
19  
20 # do not use this module directly
21 use Bio::SearchIO;
22 my $parser = Bio::SearchIO->new(-file => $file,
23 -format => 'blasttable');
24  
25 while( my $result = $parser->next_result ) {
26 }
27  
28 =head1 DESCRIPTION
29  
30 This module will support parsing NCBI -m 8 or -m 9 tabular output
31 and WU-BLAST -mformat 2 or -mformat 3 tabular output.
32  
33 =head1 FEEDBACK
34  
35 =head2 Mailing Lists
36  
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to
39 the Bioperl mailing list. Your participation is much appreciated.
40  
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43  
44 =head2 Support
45  
46 Please direct usage questions or support issues to the mailing list:
47  
48 I<bioperl-l@bioperl.org>
49  
50 rather than to the module maintainer directly. Many experienced and
51 reponsive experts will be able look at the problem and quickly
52 address it. Please include a thorough description of the problem
53 with code and data examples if at all possible.
54  
55 =head2 Reporting Bugs
56  
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via
59 the web:
60  
61 https://github.com/bioperl/bioperl-live/issues
62  
63 =head1 AUTHOR - Jason Stajich
64  
65 Email jason-at-bioperl-dot-org
66  
67 =head1 APPENDIX
68  
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
71  
72 =cut
73  
74 # Let the code begin...
75  
76  
77 package Bio::SearchIO::blasttable;
78 3 $Bio::SearchIO::blasttable::VERSION = '1.7.8';
79 3 ▶use vars qw(%MAPPING %MODEMAP $DEFAULT_WRITER_CLASS $DefaultProgramName);
Subroutine BEGIN: called CC=1 SCAR=0.0
80 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 3 ▶use Bio::Search::Result::ResultFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 3 ▶use Bio::Search::Hit::HitFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 3 ▶use Bio::Search::HSP::HSPFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 3 $DefaultProgramName = 'BLASTN';
86 3 $DEFAULT_WRITER_CLASS = 'Bio::SearchIO::Writer::HitTableWriter';
87  
88 # mapping of terms to Bioperl hash keys
89 3 %MODEMAP = (
90 'Result' => 'result',
91 'Hit' => 'hit',
92 'Hsp' => 'hsp'
93 );
94  
95 3 %MAPPING = (
96 'Hsp_bit-score' => 'HSP-bits',
97 'Hsp_score' => 'HSP-score',
98 'Hsp_evalue' => 'HSP-evalue',
99 'Hsp_query-from' => 'HSP-query_start',
100 'Hsp_query-to' => 'HSP-query_end',
101 'Hsp_hit-from' => 'HSP-hit_start',
102 'Hsp_hit-to' => 'HSP-hit_end',
103 'Hsp_positive' => 'HSP-conserved',
104 'Hsp_identity' => 'HSP-identical',
105 'Hsp_mismatches' => 'HSP-mismatches',
106 'Hsp_qgapblocks' => 'HSP-query_gapblocks',
107 'Hsp_hgapblocks' => 'HSP-hit_gapblocks',
108 'Hsp_gaps' => 'HSP-hsp_gaps',
109 'Hsp_hitgaps' => 'HSP-hit_gaps',
110 'Hsp_querygaps' => 'HSP-query_gaps',
111 'Hsp_align-len' => 'HSP-hsp_length',
112 'Hsp_query-frame'=> 'HSP-query_frame',
113 'Hsp_hit-frame' => 'HSP-hit_frame',
114  
115 'Hit_id' => 'HIT-name',
116 'Hit_len' => 'HIT-length',
117 'Hit_accession' => 'HIT-accession',
118 'Hit_def' => 'HIT-description',
119 'Hit_signif' => 'HIT-significance',
120 'Hit_score' => 'HIT-score',
121 'Hit_bits' => 'HIT-bits',
122  
123 'Result_program' => 'RESULT-algorithm_name',
124 'Result_version' => 'RESULT-algorithm_version',
125 'Result_query-def'=> 'RESULT-query_name',
126 'Result_query-len'=> 'RESULT-query_length',
127 'Result_query-acc'=> 'RESULT-query_accession',
128 'Result_querydesc'=> 'RESULT-query_description',
129 'Result_db' => 'RESULT-database_name',
130 'Result_db-len' => 'RESULT-database_entries',
131 'Result_db-let' => 'RESULT-database_letters',
132 );
133  
134 3 ▶use base qw(Bio::SearchIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 =head2 new
137  
138 Title : new
139 Usage : my $obj = Bio::SearchIO::blasttable->new();
140 Function: Builds a new Bio::SearchIO::blasttable object
141 Returns : an instance of Bio::SearchIO::blasttable
142 Args :
143  
144  
145 =cut
146  
147 11 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
148 11 my ($self,@args) = @_;
149 11 $self->SUPER::_initialize(@args);
150  
151 11 my ($pname) = $self->_rearrange([qw(PROGRAM_NAME)],
152 @args);
153 11 ▶ $self->program_name($pname || $DefaultProgramName);
Condition66%2/3
$pname || $Bio::SearchIO::blasttable::DefaultProgramName
l!l&&r!l&&!r
290
MC/DC0%0/2
$pname || $Bio::SearchIO::blasttable::DefaultProgramName
$pname $Bio::SearchIO::blasttable::DefaultProgramName
Truth table66%2/3
A || B
A= $pnameB= $Bio::SearchIO::blasttable::DefaultProgramName
ABresult
1X1
011
000
154 11 $self->_eventHandler->register_factory('result', Bio::Search::Result::ResultFactory->new(-type => 'Bio::Search::Result::GenericResult'));
155 11 $self->_eventHandler->register_factory('hit', Bio::Search::Hit::HitFactory->new(-type => 'Bio::Search::Hit::GenericHit'));
156 11 $self->_eventHandler->register_factory('hsp', Bio::Search::HSP::HSPFactory->new(-type => 'Bio::Search::HSP::GenericHSP'));
157 }
158  
159  
160 =head2 next_result
161  
162 Title : next_result
163 Usage : my $result = $parser->next_result
164 Function: Parse the next result from the data stream
165 Returns : L<Bio::Search::Result::ResultI>
166 Args : none
167  
168  
169 =cut
170  
171 12 ▶sub next_result{
Subroutine next_result: called CC=27 SCAR=33.1
Pod documented
172 12 my ($self) = @_;
173 12 my ($lastquery,$lasthit);
174 12 local $/ = "\n";
175 12 local $_;
176 12 my ($alg, $ver);
177 12 ▶ while( defined ($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 766 8 774
178 # WU-BLAST -mformat 3 only
179 766 ▶ if(m{^#\s((?:\S+?)?BLAST[NPX])\s(\d+\.\d+.+\d{4}\])}) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^#\s((?:\S+?)?BLAST[NPX])\s(\d+\.\d+.+\d{4}\])/) { } 1 765 766
elsif (/^#\s+((?:\S+?)?BLAST[NPX])\s+(.+)/) { } 1 764 765
180 1 ($alg, $ver) = ($1, $2);
181 # only one header for whole file with WU-BLAST
182 # so $alg and $ver won't get set properly for
183 # each result
184 1 ▶ $self->program_name($alg) if $alg;
Branch: 1 branch
BranchTrueFalseTotal
if $alg 1 0 1
185 1 ▶ $self->element({'Name' => 'Result_version',
Branch: 1 branch
BranchTrueFalseTotal
if $ver 1 0 1
186 'Data' => $ver}) if $ver;
187 1 next;
188 }
189 # -m 9 only
190 elsif(m{^#\s+((?:\S+?)?BLAST[NPX])\s+(.+)}) {
191 1 ($alg, $ver) = ($1, $2);
192 1 next;
193 }
194 764 ▶ next if /^#/ || /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#/ or /^\s*$/ 78 686 764
Condition100%3/3
/^#/ or /^\s*$/
l!l&&r!l&&!r
6513686
MC/DC100%2/2
/^#/ or /^\s*$/
/^#/ /^\s*$/
Truth table100%3/3
A or B
A= /^#/B= /^\s*$/
ABresult
1X1
011
000
195  
196 686 my @fields = split;
197 686 ▶ next if @fields == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @fields == 1 0 686 686
198 686 my ($qname,$hname, $percent_id, $hsp_len, $mismatches,$gapsm,
199 $qstart,$qend,$hstart,$hend,$evalue,$bits);
200 # WU-BLAST-specific
201 686 my ($num_scores, $raw_score, $identities, $positives, $percent_pos,
202 $qgap_blocks,$qgaps, $sgap_blocks, $sgaps, $qframe,
203 $sframe);
204 # NCBI -m8 and -m9
205 686 ▶ if (@fields == 12) {
Branch: 3 branches
BranchTrueFalseTotal
if (@fields == 12) { } 8 678 686
elsif (@fields == 13) { } 675 3 678
elsif (@fields == 22 or @fields == 24) { } 3 0 3
206 8 ($qname,$hname, $percent_id, $hsp_len, $mismatches,$gapsm,
207 $qstart,$qend,$hstart,$hend,$evalue,$bits) = @fields;
208 # NCBI -m8 and -m9, v 2.2.18+
209 } elsif (@fields == 13) {
210 675 ($qname, $hname, $percent_id, $percent_pos, $hsp_len, $mismatches, $gapsm,
211 $qstart,$qend,$hstart,$hend,$evalue,$bits) = @fields;
212 }
213 # WU-BLAST -mformat 2 and 3
214 ▶ elsif ((@fields == 22) or (@fields == 24)) {
Condition33%1/3
@fields == 22 or @fields == 24
l!l&&r!l&&!r
030
MC/DC0%0/2
@fields == 22 or @fields == 24
@fields == 22 @fields == 24
Truth table33%1/3
A or B
A= @fields == 22B= @fields == 24
ABresult
1X1
011
000
215 3 ($qname,$hname,$evalue,$num_scores, $bits, $raw_score, $hsp_len,
216 $identities, $positives,$mismatches, $percent_id, $percent_pos,
217 $qgap_blocks, $qgaps, $sgap_blocks, $sgaps, $qframe, $qstart,
218 $qend, $sframe, $hstart,$hend,) = @fields;
219 # we need total gaps in the alignment
220 3 $gapsm=$qgaps+$sgaps;
221 }
222  
223 686 ▶ if (@fields == 12 || @fields == 13) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields == 12 or @fields == 13) 683 3 686
Condition100%3/3
@fields == 12 or @fields == 13
l!l&&r!l&&!r
86753
MC/DC100%2/2
@fields == 12 or @fields == 13
@fields == 12 @fields == 13
Truth table100%3/3
A or B
A= @fields == 12B= @fields == 13
ABresult
1X1
011
000
224 # need to determine total gaps in the alignment for NCBI output
225 # since NCBI reports number of gapopens and NOT total gaps
226 683 my $qlen = abs($qstart - $qend) + 1;
227 683 my $querygaps = $hsp_len - $qlen;
228 683 my $hlen = abs($hstart - $hend) + 1;
229 683 my $hitgaps = $hsp_len - $hlen;
230 683 $gapsm = $querygaps + $hitgaps;
231 }
232  
233 # Remember Jim's code is 0 based
234 686 ▶ if( defined $lastquery &&
Branch: 3 branches
BranchTrueFalseTotal
if (defined $lastquery and $lastquery ne $qname) { } 4 682 686
elsif (not defined $lastquery) { } 11 671 682
elsif ($lasthit ne $hname) { } 640 31 671
Condition100%3/3
defined $lastquery and $lastquery ne $qname
!ll&&!rl&&r
116714
MC/DC100%2/2
defined $lastquery and $lastquery ne $qname
defined $lastquery $lastquery ne $qname
Truth table100%3/3
A and B
A= defined $lastqueryB= $lastquery ne $qname
ABresult
0X0
100
111
235 $lastquery ne $qname ) {
236 4 $self->end_element({'Name' => 'Hit'});
237 4 $self->end_element({'Name' => 'Result'});
238 4 $self->_pushback($_);
239 4 return $self->end_document;
240 } elsif( ! defined $lastquery ) {
241 11 $self->{'_result_count'}++;
242 11 $self->start_element({'Name' => 'Result'});
243 11 ▶ $self->element({'Name' => 'Result_program',
Condition66%2/3
$alg || $self->program_name
l!l&&r!l&&!r
290
MC/DC0%0/2
$alg || $self->program_name
$alg $self->program_name
Truth table66%2/3
A || B
A= $algB= $self->program_name
ABresult
1X1
011
000
244 'Data' => $alg || $self->program_name});
245 11 ▶ $self->element({'Name' => 'Result_version',
Branch: 1 branch
BranchTrueFalseTotal
if $ver 2 9 11
246 'Data' => $ver}) if $ver;
247 11 $self->element({'Name' => 'Result_query-def',
248 'Data' => $qname});
249 11 $self->start_element({'Name' => 'Hit'});
250 11 $self->element({'Name' => 'Hit_id',
251 'Data' => $hname});
252 # we'll store the 1st hsp bits as the hit bits
253 11 $self->element({'Name' => 'Hit_bits',
254 'Data' => $bits});
255 # we'll store the 1st hsp value as the hit evalue
256 11 $self->element({'Name' => 'Hit_signif',
257 'Data' => $evalue});
258
259 } elsif( $lasthit ne $hname ) {
260 640 ▶ if( $self->in_element('hit') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 640 0 640
261 640 $self->end_element({'Name' => 'Hit'});
262 }
263 640 $self->start_element({'Name' => 'Hit'});
264 640 $self->element({'Name' => 'Hit_id',
265 'Data' => $hname});
266 # we'll store the 1st hsp bits as the hit bits
267 640 $self->element({'Name' => 'Hit_bits',
268 'Data' => $bits});
269 # we'll store the 1st hsp value as the hit evalue
270 640 $self->element({'Name' => 'Hit_signif',
271 'Data' => $evalue});
272 }
273 682 my $identical = $hsp_len - $mismatches - $gapsm;
274 # If $positives value is absent, try to recover it from $percent_pos,
275 # this is better than letting the program to assume "conserved == identical"
276 682 ▶ if (not defined $positives and defined $percent_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $positives and defined $percent_pos) 671 11 682
Condition100%3/3
not defined $positives and defined $percent_pos
!ll&&!rl&&r
38671
MC/DC100%2/2
not defined $positives and defined $percent_pos
not defined $positives defined $percent_pos
Truth table100%3/3
not(A) and B
A= not defined $positivesB= defined $percent_pos
ABresult
0X0
100
111
277 671 $positives = sprintf "%d", ($percent_pos * $hsp_len / 100);
278 }
279 682 $self->start_element({'Name' => 'Hsp'});
280 682 $self->element({'Name' => 'Hsp_evalue',
281 'Data' => $evalue});
282 682 $self->element({'Name' => 'Hsp_bit-score',
283 'Data' => $bits});
284 682 $self->element({'Name' => 'Hsp_identity',
285 'Data' => $identical});
286 682 $self->element({'Name' => 'Hsp_positive',
287 'Data' => $positives});
288 682 $self->element({'Name' => 'Hsp_gaps',
289 'Data' => $gapsm});
290 682 $self->element({'Name' => 'Hsp_query-from',
291 'Data' => $qstart});
292 682 $self->element({'Name' => 'Hsp_query-to',
293 'Data' => $qend});
294  
295 682 $self->element({'Name' => 'Hsp_hit-from',
296 'Data' => $hstart });
297 682 $self->element({'Name' => 'Hsp_hit-to',
298 'Data' => $hend });
299 682 $self->element({'Name' => 'Hsp_align-len',
300 'Data' => $hsp_len});
301 682 $self->end_element({'Name' => 'Hsp'});
302 682 $lastquery = $qname;
303 682 $lasthit = $hname;
304 }
305 # fencepost
306 8 ▶ if( defined $lasthit && defined $lastquery ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lasthit and defined $lastquery) 7 1 8
Condition66%2/3
defined $lasthit and defined $lastquery
!ll&&!rl&&r
107
MC/DC50%1/2
defined $lasthit and defined $lastquery
defined $lasthit defined $lastquery
Truth table66%2/3
A and B
A= defined $lasthitB= defined $lastquery
ABresult
0X0
100
111
307 7 ▶ if( $self->in_element('hit') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hit")) 7 0 7
308 7 $self->end_element({'Name' => 'Hit'});
309 }
310 7 $self->end_element({'Name' => 'Result'});
311 7 return $self->end_document;
312 }
313 }
314  
315 =head2 start_element
316  
317 Title : start_element
318 Usage : $eventgenerator->start_element
319 Function: Handles a start element event
320 Returns : none
321 Args : hashref with at least 2 keys 'Data' and 'Name'
322  
323  
324 =cut
325  
326 10142 ▶sub start_element{
Subroutine start_element: called CC=4 SCAR=13.9
Pod documented
327 10142 my ($self,$data) = @_;
328 # we currently don't care about attributes
329 10142 my $nm = $data->{'Name'};
330 10142 ▶ if( my $type = $MODEMAP{$nm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $Bio::SearchIO::blasttable::MODEMAP{$nm}) 1344 8798 10142
331 1344 $self->_mode($type);
332 1344 ▶ if( $self->_will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_will_handle($type)) 1344 0 1344
333 1344 my $func = sprintf("start_%s",lc $type);
334 1344 $self->_eventHandler->$func($data->{'Attributes'});
335 }
336 1344 unshift @{$self->{'_elements'}}, $type;
337 }
338 10142 ▶ if($nm eq 'Result') {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm eq "Result") 11 10131 10142
339 11 $self->{'_values'} = {};
340 11 $self->{'_result'}= undef;
341 11 $self->{'_mode'} = '';
342 }
343  
344 }
345  
346 =head2 end_element
347  
348 Title : start_element
349 Usage : $eventgenerator->end_element
350 Function: Handles an end element event
351 Returns : none
352 Args : hashref with at least 2 keys 'Data' and 'Name'
353  
354  
355 =cut
356  
357 10142 ▶sub end_element {
Subroutine end_element: called CC=6 SCAR=18.8
Pod documented
358 10142 my ($self,$data) = @_;
359 10142 my $nm = $data->{'Name'};
360 10142 my $rc;
361 # Hsp are sort of weird, in that they end when another
362 # object begins so have to detect this in end_element for now
363
364 10142 ▶ if( my $type = $MODEMAP{$nm} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $type = $Bio::SearchIO::blasttable::MODEMAP{$nm}) { } 1344 8798 10142
elsif ($Bio::SearchIO::blasttable::MAPPING{$nm}) { } 8798 0 8798
365 1344 ▶ if( $self->_will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_will_handle($type)) 1344 0 1344
366 1344 my $func = sprintf("end_%s",lc $type);
367 $rc = $self->_eventHandler->$func($self->{'_reporttype'},
368 1344 $self->{'_values'});
369 }
370 1344 shift @{$self->{'_elements'}};
371  
372 } elsif( $MAPPING{$nm} ) {
373 8798 ▶ if ( ref($MAPPING{$nm}) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::SearchIO::blasttable::MAPPING{$nm}) =~ /hash/i) { } 0 8798 8798
374 0 my $key = (keys %{$MAPPING{$nm}})[0];
375 0 $self->{'_values'}->{$key}->{$MAPPING{$nm}->{$key}} = $self->{'_last_data'};
376 } else {
377 8798 $self->{'_values'}->{$MAPPING{$nm}} = $self->{'_last_data'};
378 }
379 } else {
380 0 $self->warn( "unknown nm $nm ignoring\n");
381 }
382 10142 $self->{'_last_data'} = ''; # remove read data if we are at
383 # end of an element
384 10142 ▶ $self->{'_result'} = $rc if( $nm eq 'Result' );
Branch: 1 branch
BranchTrueFalseTotal
if $nm eq "Result" 11 10131 10142
385 10142 return $rc;
386  
387 }
388  
389 =head2 element
390  
391 Title : element
392 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
393 Function: Convience method that calls start_element, characters, end_element
394 Returns : none
395 Args : Hash ref with the keys 'Name' and 'Data'
396  
397  
398 =cut
399  
400 8798 ▶sub element{
Subroutine element: called CC=1 SCAR=0.0
Pod documented
401 8798 my ($self,$data) = @_;
402 8798 $self->start_element($data);
403 8798 $self->characters($data);
404 8798 $self->end_element($data);
405 }
406  
407  
408 =head2 characters
409  
410 Title : characters
411 Usage : $eventgenerator->characters($str)
412 Function: Send a character events
413 Returns : none
414 Args : string
415  
416  
417 =cut
418  
419 8798 ▶sub characters{
Subroutine characters: called CC=7 SCAR=22.0
Pod documented
420 8798 my ($self,$data) = @_;
421  
422 # deep bug fix: set $self->{'_last_data'} to undef if $$data{Data} is
423 # a valid slot, whose value is undef --
424 # allows an undef to be propagated to object constructors and
425 # handled there as desired; in particular, when Hsp_postive => -conserved
426 # is not defined (in BLASTN, e.g.), the value of hsp's {CONSERVED} property is
427 # set to the value of {IDENTICAL}.
428 #/maj
429 # return unless ( defined $data->{'Data'} );
430 8798 ▶ return unless ( grep /Data/, keys %$data );
Branch: 1 branch
BranchTrueFalseTotal
unless grep /Data/, keys %$data 0 8798 8798
431 8798 ▶ if ( !defined $data->{'Data'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{"Data"}) 8 8790 8798
432 8 $self->{'_last_data'} = undef;
433 8 return;
434 }
435 8790 ▶ if( $data->{'Data'} =~ /^\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Data"} =~ /^\s+$/) 0 8790 8790
436 0 ▶ return unless $data->{'Name'} =~ /Hsp\_(midline|qseq|hseq)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data->{"Name"} =~ /Hsp\_(midline|qseq|hseq)/ 0 0 0
437 }
438  
439 8790 ▶ if( $self->in_element('hsp') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/) 0 8790 8790
Condition66%2/3
$self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
!ll&&!rl&&r
197868120
MC/DC0%0/2
$self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
$self->in_element("hsp") $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
Truth table66%2/3
A and B
A= $self->in_element("hsp")B= $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
ABresult
0X0
100
111
440 $data->{'Name'} =~ /Hsp\_(qseq|hseq|midline)/ ) {
441
442 0 $self->{'_last_hspdata'}->{$data->{'Name'}} .= $data->{'Data'};
443 }
444
445 8790 $self->{'_last_data'} = $data->{'Data'};
446 }
447  
448 =head2 _mode
449  
450 Title : _mode
451 Usage : $obj->_mode($newval)
452 Function:
453 Example :
454 Returns : value of _mode
455 Args : newvalue (optional)
456  
457  
458 =cut
459  
460 1344 ▶sub _mode{
Subroutine _mode: called CC=2 SCAR=7.0
461 1344 my ($self,$value) = @_;
462 1344 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1344 0 1344
463 1344 $self->{'_mode'} = $value;
464 }
465 1344 return $self->{'_mode'};
466 }
467  
468 =head2 within_element
469  
470 Title : within_element
471 Usage : if( $eventgenerator->within_element($element) ) {}
472 Function: Test if we are within a particular element
473 This is different than 'in' because within can be tested
474 for a whole block.
475 Returns : boolean
476 Args : string element name
477  
478  
479 =cut
480  
481 0 ▶sub within_element{
Subroutine within_element: not called CC=6 SCAR=37.4
Pod documented
482 0 my ($self,$name) = @_;
483 return 0 if ( ! defined $name &&
484 ! defined $self->{'_elements'} ||
485 0 ▶ scalar @{$self->{'_elements'}} == 0) ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name || defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0 0 0 0
Condition0%0/6
not defined $name || defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
l!l&&r!l&&!r
000
defined $name || defined $self->{'_elements'}
l!l&&r!l&&!r
000
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 table0%0/5
not(A || B) or C
A= defined $nameB= defined $self->{'_elements'}C= scalar @{$self->{"_elements"};} == 0
ABCresult
00X1
1X11
0111
1X00
0100
486 0 foreach ( @{$self->{'_elements'}} ) {
487 0 ▶ if( $_ eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $name) 0 0 0
488 0 return 1;
489 }
490 }
491 0 return 0;
492 }
493  
494 =head2 in_element
495  
496 Title : in_element
497 Usage : if( $eventgenerator->in_element($element) ) {}
498 Function: Test if we are in a particular element
499 This is different than 'in' because within can be tested
500 for a whole block.
501 Returns : boolean
502 Args : string element name
503  
504  
505 =cut
506  
507 9437 ▶sub in_element{
Subroutine in_element: called CC=2 SCAR=6.9
Pod documented
508 9437 my ($self,$name) = @_;
509 9437 ▶ return 0 if ! defined $self->{'_elements'}->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_elements"}[0] 1 9436 9437
510 9436 return ( $self->{'_elements'}->[0] eq $name)
511 }
512  
513  
514 =head2 start_document
515  
516 Title : start_document
517 Usage : $eventgenerator->start_document
518 Function: Handles a start document event
519 Returns : none
520 Args : none
521  
522  
523 =cut
524  
525 0 ▶sub start_document{
Subroutine start_document: not called CC=1 SCAR=6.9
Pod documented
526 0 my ($self) = @_;
527 0 $self->{'_lasttype'} = '';
528 0 $self->{'_values'} = {};
529 0 $self->{'_result'}= undef;
530 0 $self->{'_mode'} = '';
531 0 $self->{'_elements'} = [];
532 }
533  
534  
535 =head2 end_document
536  
537 Title : end_document
538 Usage : $eventgenerator->end_document
539 Function: Handles an end document event
540 Returns : Bio::Search::Result::ResultI object
541 Args : none
542  
543  
544 =cut
545  
546 11 ▶sub end_document{
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
547 11 my ($self,@args) = @_;
548 11 return $self->{'_result'};
549 }
550  
551 =head2 result_count
552  
553 Title : result_count
554 Usage : my $count = $searchio->result_count
555 Function: Returns the number of results we have processed
556 Returns : integer
557 Args : none
558  
559  
560 =cut
561  
562 0 ▶sub result_count {
Subroutine result_count: not called CC=1 SCAR=6.9
Pod documented
563 0 my $self = shift;
564 0 return $self->{'_result_count'};
565 }
566  
567 0 ▶sub report_count { shift->result_count }
Subroutine report_count: not called CC=1 SCAR=6.9
Pod undocumented
568  
569  
570 =head2 program_name
571  
572 Title : program_name
573 Usage : $obj->program_name($newval)
574 Function: Get/Set the program name
575 Returns : value of program_name (a scalar)
576 Args : on set, new value (a scalar or undef, optional)
577  
578  
579 =cut
580  
581 21 ▶sub program_name{
Subroutine program_name: called CC=3 SCAR=11.4
Pod documented
582 21 my $self = shift;
583  
584 21 ▶ $self->{'program_name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 12 9 21
585 21 ▶ return $self->{'program_name'} || $DefaultProgramName;
Condition33%1/3
$self->{'program_name'} || $Bio::SearchIO::blasttable::DefaultProgramName
l!l&&r!l&&!r
2100
MC/DC0%0/2
$self->{'program_name'} || $Bio::SearchIO::blasttable::DefaultProgramName
$self->{'program_name'} $Bio::SearchIO::blasttable::DefaultProgramName
Truth table33%1/3
A || B
A= $self->{'program_name'}B= $Bio::SearchIO::blasttable::DefaultProgramName
ABresult
1X1
011
000
586 }
587  
588  
589 =head2 _will_handle
590  
591 Title : _will_handle
592 Usage : Private method. For internal use only.
593 if( $self->_will_handle($type) ) { ... }
594 Function: Provides an optimized way to check whether or not an element of a
595 given type is to be handled.
596 Returns : Reference to EventHandler object if the element type is to be handled.
597 undef if the element type is not to be handled.
598 Args : string containing type of element.
599  
600 Optimizations:
601  
602 =over 2
603  
604 =item 1
605  
606 Using the cached pointer to the EventHandler to minimize repeated
607 lookups.
608  
609 =item 2
610  
611 Caching the will_handle status for each type that is encountered so
612 that it only need be checked by calling
613 handler-E<gt>will_handle($type) once.
614  
615 =back
616  
617 This does not lead to a major savings by itself (only 5-10%). In
618 combination with other optimizations, or for large parse jobs, the
619 savings good be significant.
620  
621 To test against the unoptimized version, remove the parentheses from
622 around the third term in the ternary " ? : " operator and add two
623 calls to $self-E<gt>_eventHandler().
624  
625 =cut
626  
627 2688 ▶sub _will_handle {
Subroutine _will_handle: called CC=3 SCAR=11.0
628 2688 my ($self,$type) = @_;
629 2688 my $handler = $self->{'_handler'};
630 my $will_handle = defined($self->{'_will_handle_cache'}->{$type})
631 ? $self->{'_will_handle_cache'}->{$type}
632 2688 ▶ : ($self->{'_will_handle_cache'}->{$type} =
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'_will_handle_cache'}{$type} ? : 2655 33 2688
633 $handler->will_handle($type));
634  
635 2688 ▶ return $will_handle ? $handler : undef;
Branch: 1 branch
BranchTrueFalseTotal
$will_handle ? : 2688 0 2688
636 }
637  
638 3 1;
« Bio/Tree/RandomFactory.pm ↑ Summary Bio/Tools/Genemark.pm »