Bio/Search/Result/BlastPullResult.pm

filter: Statementstmt 96.4% 134 / 139 Branchbran 86.5% 71 / 82 Conditioncond 57.1% 12 / 21 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 92.8% 13 / 14 Podpod 100% 7 / 7 totaltotal 86.5% 239 / 276 CC 51 SCAR 25.4
CC
51
Cov
90%
_discover_stats_and_params
21.0
_discover_hit_table
17.5
_discover_header
6.1
CRAP 12.7
« Bio/Tools/PrositeScan.pm ↑ Summary Bio/Matrix/PSM/IO/masta.pm »
1 #
2 # BioPerl module for Bio::Search::Result::BlastPullResult
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
7 #
8 # Copyright Sendu Bala
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::Search::Result::BlastPullResult - A parser and result object for BLASTN
17 results
18  
19 =head1 SYNOPSIS
20  
21 # generally we use Bio::SearchIO to build these objects
22 use Bio::SearchIO;
23 my $in = Bio::SearchIO->new(-format => 'blast_pull',
24 -file => 'result.blast');
25  
26 while (my $result = $in->next_result) {
27 print $result->query_name, " ", $result->algorithm, " ", $result->num_hits(), " hits\n";
28 }
29  
30 =head1 DESCRIPTION
31  
32 This object implements a parser for NCBI BLASTN result output.
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 of the bugs and their resolution. Bug reports can be submitted via the
60 web:
61  
62 https://github.com/bioperl/bioperl-live/issues
63  
64 =head1 AUTHOR - Sendu Bala
65  
66 Email bix@sendu.me.uk
67  
68 =head1 CONTRIBUTORS
69  
70 Additional contributors names and emails here
71  
72 =head1 APPENDIX
73  
74 The rest of the documentation details each of the object methods.
75 Internal methods are usually preceded with a _
76  
77 =cut
78  
79 # Let the code begin...
80  
81 package Bio::Search::Result::BlastPullResult;
82 3 $Bio::Search::Result::BlastPullResult::VERSION = '1.7.8';
83 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 3 ▶use Bio::Search::Hit::BlastPullHit;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 3 ▶use base qw(Bio::Root::Root Bio::Search::Result::PullResultI);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 =head2 new
90  
91 Title : new
92 Usage : my $obj = Bio::SearchIO::Result::hmmpfam->new();
93 Function: Builds a new Bio::SearchIO::Result::hmmpfam object
94 Returns : Bio::SearchIO::Result::hmmpfam
95 Args : -chunk => [Bio::Root::IO, $start, $end] (required if no -parent)
96 -parent => Bio::PullParserI object (required if no -chunk)
97 -parameters => hash ref of search parameters (key => value), optional
98 -statistics => hash ref of search statistics (key => value), optional
99  
100 where the array ref provided to -chunk contains an IO object
101 for a filehandle to something representing the raw data of the
102 result, and $start and $end define the tell() position within the
103 filehandle that the result data starts and ends (optional; defaults
104 to start and end of the entire thing described by the filehandle)
105  
106 =cut
107  
108 17 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
109 17 my ($class, @args) = @_;
110 17 my $self = $class->SUPER::new(@args);
111
112 17 $self->_setup(@args);
113
114 17 foreach my $field (qw( header hit_table hsp_table alignments next_model
115 models query_length stats_and_params)) {
116 136 $self->_fields->{$field} = undef;
117 }
118
119 17 $self->_dependencies( { ( query_name => 'header',
120 query_accession => 'header',
121 query_description => 'header',
122 query_length => 'header',
123 hit_table => 'header',
124 num_hits => 'hit_table',
125 no_hits_found => 'hit_table' ) } );
126
127 17 return $self;
128 }
129  
130 #
131 # PullParserI discovery methods so we can answer all ResultI questions
132 #
133  
134 17 ▶sub _discover_header {
Subroutine _discover_header: called CC=6 SCAR=18.1
135 17 my $self = shift;
136 17 $self->_chunk_seek(0);
137 17 my $header = $self->_get_chunk_by_end("Value\n");
138 17 ▶ if (!$header) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($header) 0 17 17
139 0 $header = $self->_get_chunk_by_end("***** No hits found ******\n");
140 0 $self->{_no_hits_found} = 1;
141 }
142 17 ▶ $self->throw("Invalid header returned") unless $header;
Branch: 1 branch
BranchTrueFalseTotal
unless $header 0 17 17
143 17 $self->{_after_header} = $self->_chunk_tell;
144
145 17 ($self->_fields->{query_name}) = $header =~ /^\s*(\S+)/;
146 17 $self->_fields->{query_accession} = '';
147 17 $self->_fields->{query_description} = '';
148
149 17 ▶ if ($header =~ /^Length=(\d+)/m) {
Branch: 2 branches
BranchTrueFalseTotal
if ($header =~ /^Length=(\d+)/m) { } 5 12 17
elsif ($header =~ /\((\d+) letters\)/) { } 11 1 12
150 5 $self->_fields->{query_length} = $1;
151 }
152 elsif ($header =~ /\((\d+) letters\)/) {
153 # older form?
154 11 $self->_fields->{query_length} = $1;
155
156 11 ▶ if ($header =~ /^\s*\(\d+ letters/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ /^\s*\(\d+ letters/) 1 10 11
157 # there wasn't a query sequence name
158 1 $self->_fields->{query_name} = '';
159 }
160 }
161
162 17 $self->_fields->{header} = 1;
163 }
164  
165 13 ▶sub _discover_hit_table {
Subroutine _discover_hit_table: called CC=15 SCAR=28.6
166 13 my $self = shift;
167 13 $self->_chunk_seek($self->{_after_header});
168
169 13 my $table = $self->_get_chunk_by_end("\n>");
170
171 13 ▶ if (!$table && !$self->{_no_hits_found}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table or $self->{"_no_hits_found"}) 2 11 13
Condition66%2/3
$table or $self->{"_no_hits_found"}
l!l&&r!l&&!r
1102
MC/DC50%1/2
$table or $self->{"_no_hits_found"}
$table $self->{"_no_hits_found"}
Truth table66%2/3
A or B
A= $tableB= $self->{"_no_hits_found"}
ABresult
1X1
011
000
172 # no alignments, presumably; hit table comprises the remainder of this
173 # result
174 2 ▶ while (my $line = $self->_get_chunk_by_nol(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->_get_chunk_by_nol(1)) 22 2 24
175 22 $table .= $line;
176 }
177 }
178
179 13 ▶ $table ||= '';
Condition50%1/2
$table ||= ""
l!l
130
MC/DC0%0/1
$table ||= ""
$table
Truth table50%1/2
A
A= $table
Aresult
11
00
180
181 13 $self->{_after_hit_table} = $self->_chunk_tell;
182
183 13 my $evalue_cutoff = $self->get_field('evalue_cutoff');
184 13 ▶ undef $evalue_cutoff if $evalue_cutoff eq '[unset]';
Branch: 1 branch
BranchTrueFalseTotal
if $evalue_cutoff eq "[unset]" 13 0 13
185 13 my $score_cutoff = $self->get_field('score_cutoff');
186 13 ▶ undef $score_cutoff if $score_cutoff eq '[unset]';
Branch: 1 branch
BranchTrueFalseTotal
if $score_cutoff eq "[unset]" 13 0 13
187
188 13 my @table;
189 13 my $no_hit = 1;
190 13 ▶ while ($table =~ /^(\S+)\s+(\S.*?)?\s+(\S+)\s+([\de]\S*)\s*\n/gm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ /^(\S+)\s+(\S.*?)?\s+(\S+)\s+([\de]\S*)\s*\n/gm) 93 13 106
191 93 $no_hit = 0;
192 93 my ($name, $desc, $score, $evalue) = ($1, $2, $3, $4);
193 93 ▶ $desc ||= '';
Condition100%2/2
$desc ||= ""
l!l
903
MC/DC100%1/1
$desc ||= ""
$desc
Truth table100%2/2
A
A= $desc
Aresult
11
00
194 93 ▶ if ($evalue =~ /^e/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($evalue =~ /^e/) 0 93 93
195 0 $evalue = '1'.$evalue;
196 }
197 93 ▶ next if ($evalue_cutoff && $evalue > $evalue_cutoff);
Branch: 1 branch
BranchTrueFalseTotal
if $evalue_cutoff and $evalue > $evalue_cutoff 0 93 93
Condition33%1/3
$evalue_cutoff and $evalue > $evalue_cutoff
!ll&&!rl&&r
9300
MC/DC0%0/2
$evalue_cutoff and $evalue > $evalue_cutoff
$evalue_cutoff $evalue > $evalue_cutoff
Truth table33%1/3
A and B
A= $evalue_cutoffB= $evalue > $evalue_cutoff
ABresult
0X0
100
111
198 93 ▶ next if ($score_cutoff && $score < $score_cutoff);
Branch: 1 branch
BranchTrueFalseTotal
if $score_cutoff and $score < $score_cutoff 0 93 93
Condition33%1/3
$score_cutoff and $score < $score_cutoff
!ll&&!rl&&r
9300
MC/DC0%0/2
$score_cutoff and $score < $score_cutoff
$score_cutoff $score < $score_cutoff
Truth table33%1/3
A and B
A= $score_cutoffB= $score < $score_cutoff
ABresult
0X0
100
111
199 93 push(@table, [$name, $desc, $score, $evalue]);
200 }
201 13 $self->_fields->{hit_table} = \@table;
202 13 ▶ $self->{_next_hit_index} = @table > 0 ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
@table > 0 ? : 13 0 13
203
204 13 $self->_fields->{no_hits_found} = $no_hit;
205 13 $self->_fields->{num_hits} = @table;
206 }
207  
208 41 ▶sub _discover_next_hit {
Subroutine _discover_next_hit: called CC=6 SCAR=17.9
209 41 my $self = shift;
210 41 my $hit_table = $self->get_field('hit_table');
211 41 ▶ return if $self->{_next_hit_index} == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_next_hit_index"} == -1 2 39 41
212 39 my $hit_row = ${$hit_table}[$self->{_next_hit_index}];
213
214 39 ▶ $self->_chunk_seek($self->{_end_of_previous_hit} || $self->{_after_hit_table});
Condition66%2/3
$self->{'_end_of_previous_hit'} || $self->{'_after_hit_table'}
l!l&&r!l&&!r
26130
MC/DC0%0/2
$self->{'_end_of_previous_hit'} || $self->{'_after_hit_table'}
$self->{'_end_of_previous_hit'} $self->{'_after_hit_table'}
Truth table66%2/3
A || B
A= $self->{'_end_of_previous_hit'}B= $self->{'_after_hit_table'}
ABresult
1X1
011
000
215
216 39 my ($start, $end) = $self->_find_chunk_by_end("\n>");
217 39 ▶ unless ($end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end) { } 18 21 39
218 21 ▶ $start = $self->{_end_of_previous_hit} || $self->{_after_hit_table};
Condition66%2/3
$self->{'_end_of_previous_hit'} || $self->{'_after_hit_table'}
l!l&&r!l&&!r
1830
MC/DC0%0/2
$self->{'_end_of_previous_hit'} || $self->{'_after_hit_table'}
$self->{'_end_of_previous_hit'} $self->{'_after_hit_table'}
Truth table66%2/3
A || B
A= $self->{'_end_of_previous_hit'}B= $self->{'_after_hit_table'}
ABresult
1X1
011
000
219 21 $end = $self->_chunk_true_end;
220 }
221 else {
222 18 $end += $self->_chunk_true_start;
223 }
224 39 $start += $self->_chunk_true_start;
225
226 39 $self->{_end_of_previous_hit} = $end - $self->_chunk_true_start;
227
228 #*** needs to inherit piped_behaviour, and we need to deal with _sequential
229 # ourselves
230 39 $self->_fields->{next_hit} = Bio::Search::Hit::BlastPullHit->new(-parent => $self,
231 -chunk => [$self->chunk, $start, $end],
232 -hit_data => $hit_row);
233
234 39 $self->{_next_hit_index}++;
235
236 39 ▶ if ($self->{_next_hit_index} > $#{$hit_table}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_next_hit_index"} > $#{$hit_table;}) 9 30 39
237 9 $self->{_next_hit_index} = -1;
238 }
239 }
240  
241 4 ▶sub _discover_stats_and_params {
Subroutine _discover_stats_and_params: called CC=21 SCAR=30.4
242 4 my $self = shift;
243 4 $self->_chunk_seek(0);
244 4 my ($start, $end) = $self->_find_chunk_by_end("\n Database: ");
245 4 $self->_chunk_seek($end);
246
247 4 my $gapped = 0;
248 4 ▶ while ($self->_get_chunk_by_nol(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_chunk_by_nol(1)) 135 4 139
249 135 ▶ if (/Number of letters in database:\s+(\S+)/) {
Branch: 15 branches
BranchTrueFalseTotal
if (/Number of letters in database:\s+(\S+)/) { } 4 131 135
elsif (/Number of sequences in database:\s+(\S+)/) { } 4 127 131
elsif (/^Lambda/) { } 8 119 127
elsif (/^Matrix: (.+)\n/) { } 4 115 119
elsif (/^Gap Penalties: Existence: (\d+), Extension: (\d+)/) { } 4 111 115
elsif (/^Number of Hits to DB: (\d+)/) { } 4 107 111
elsif (/^Number of extensions: (\d+)/) { } 4 103 107
elsif (/^Number of successful extensions: (\d+)/) { } 4 99 103
elsif (/^Number of sequences better than (\S+):/) { } 4 95 99
elsif (/^[Ll]ength of query: (\d+)/) { } 4 91 95
elsif (/^[Ee]ffective HSP length: (\d+)/) { } 2 89 91
elsif (/^[Ee]ffective length of database: (\d+)/) { } 4 85 89
elsif (/^[Ee]ffective search space: (\d+)/) { } 4 81 85
elsif (/^[Ee]ffective search space used: (\d+)/) { } 4 77 81
elsif (/^([TAXS]\d?): (\d+)(?: \((\S+))?/) { } 25 52 77
250 4 my $stat = $1;
251 4 $stat =~ s/,//g;
252 4 $self->add_statistic('dbletters', $stat);
253 }
254 elsif (/Number of sequences in database:\s+(\S+)/) {
255 4 my $stat = $1;
256 4 $stat =~ s/,//g;
257 4 $self->add_statistic('dbentries', $stat);
258 }
259 elsif (/^Lambda/) {
260 8 my $line = $self->_get_chunk_by_nol(1);
261 8 $line =~ /\s+(\S+)\s+(\S+)\s+(\S+)/;
262 8 ▶ $self->add_statistic($gapped ? 'lambda_gapped' : 'lambda', $1);
Branch: 1 branch
BranchTrueFalseTotal
$gapped ? : 4 4 8
263 8 ▶ $self->add_statistic($gapped ? 'kappa_gapped' : 'kappa', $2);
Branch: 1 branch
BranchTrueFalseTotal
$gapped ? : 4 4 8
264 8 ▶ $self->add_statistic($gapped ? 'entropy_gapped' : 'entropy', $3);
Branch: 1 branch
BranchTrueFalseTotal
$gapped ? : 4 4 8
265 8 $gapped = 1;
266 }
267 elsif (/^Matrix: (.+)\n/) {
268 4 $self->add_parameter('matrix', $1);
269 }
270 elsif (/^Gap Penalties: Existence: (\d+), Extension: (\d+)/) {
271 4 $self->add_parameter('gapopen', $1);
272 4 $self->add_parameter('gapext', $2);
273 }
274 elsif (/^Number of Hits to DB: (\d+)/) {
275 4 $self->add_statistic('Hits_to_DB', $1);
276 }
277 elsif (/^Number of extensions: (\d+)/) {
278 4 $self->add_statistic('num_extensions', $1);
279 }
280 elsif (/^Number of successful extensions: (\d+)/) {
281 4 $self->add_statistic('num_successful_extensions', $1);
282 }
283 elsif (/^Number of sequences better than (\S+):/) {
284 4 $self->add_parameter('expect', $1);
285 }
286 elsif (/^[Ll]ength of query: (\d+)/) {
287 4 $self->add_statistic('querylength', $1);
288 }
289 elsif (/^[Ee]ffective HSP length: (\d+)/) {
290 2 $self->add_statistic('effective_hsplength', $1);
291 }
292 elsif (/^[Ee]ffective length of database: (\d+)/) {
293 4 $self->add_statistic('effectivedblength', $1);
294 }
295 elsif (/^[Ee]ffective search space: (\d+)/) {
296 4 $self->add_statistic('effectivespace', $1);
297 }
298 elsif (/^[Ee]ffective search space used: (\d+)/) {
299 4 $self->add_statistic('effectivespaceused', $1);
300 }
301 elsif (/^([TAXS]\d?): (\d+)(?: \((\S+))?/) {
302 25 $self->add_statistic($1, $2);
303 25 ▶ $self->add_statistic($1.'_bits', $3) if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 18 7 25
304 }
305 }
306
307 4 $self->_fields->{stats_and_params} = 1;
308 }
309  
310 =head2 next_hit
311  
312 Title : next_hit
313 Usage : while( $hit = $result->next_hit()) { ... }
314 Function: Returns the next available Hit object, representing potential
315 matches between the query and various entities from the database.
316 Returns : a Bio::Search::Hit::HitI object or undef if there are no more.
317 Args : none
318  
319 =cut
320  
321 41 ▶sub next_hit {
Subroutine next_hit: called CC=1 SCAR=0.0
Pod documented
322 41 my $self = shift;
323 41 my $hit = $self->get_field('next_hit');
324 41 undef $self->_fields->{next_hit};
325 41 return $hit;
326 }
327  
328 =head2 hits
329  
330 Title : hits
331 Usage : my @hits = $result->hits
332 Function: Returns the HitI objects contained within this Result
333 Returns : Array of Bio::Search::Hit::HitI objects
334 Args : none
335  
336 See Also: L<Bio::Search::Hit::HitI>
337  
338 =cut
339  
340 2 ▶sub hits {
Subroutine hits: called CC=4 SCAR=14.0
Pod documented
341 2 my $self = shift;
342 2 ▶ my $old = $self->{_next_hit_index} || 0;
Condition50%1/2
$self->{'_next_hit_index'} || 0
l!l
02
MC/DC0%0/1
$self->{'_next_hit_index'} || 0
$self->{'_next_hit_index'}
Truth table50%1/2
A
A= $self->{'_next_hit_index'}
Aresult
11
00
343 2 $self->rewind;
344 2 my @hits;
345 2 ▶ while (defined(my $hit = $self->next_hit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hit = $self->next_hit)) 20 2 22
346 20 push(@hits, $hit);
347 }
348 2 ▶ $self->{_next_hit_index} = @hits > 0 ? $old : -1;
Branch: 1 branch
BranchTrueFalseTotal
@hits > 0 ? : 2 0 2
349 2 return @hits;
350 }
351  
352 =head2 sort_hits
353  
354 Title : sort_hits
355 Usage : $result->sort_hits('<score')
356 Function : Sorts the hits so that they come out in the desired order when
357 hits() or next_hit() is called.
358 Returns : n/a
359 Args : A coderef for the sort function. See the documentation on the Perl
360 sort() function for guidelines on writing sort functions.
361 By default the sort order is ascending significance value (ie.
362 most significant hits first).
363 *** example
364  
365 =cut
366  
367 0 ▶sub sort_hits {
Subroutine sort_hits: not called CC=1 SCAR=6.9
Pod documented
368 0 my ($self, $code_ref) = @_;
369 0 $self->throw("Not implemented yet");
370 }
371  
372 =head2 rewind
373  
374 Title : rewind
375 Usage : $result->rewind;
376 Function: Allow one to reset the Hit iterator to the beginning, so that
377 next_hit() will subsequently return the first hit and so on.
378 Returns : n/a
379 Args : none
380  
381 =cut
382  
383 2 ▶sub rewind {
Subroutine rewind: called CC=3 SCAR=11.3
Pod documented
384 2 my $self = shift;
385 2 ▶ unless ($self->_fields->{hit_table}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_fields->{"hit_table"}) 2 0 2
386 2 $self->get_field('hit_table');
387 }
388 2 ▶ $self->{_next_hit_index} = @{$self->_fields->{hit_table}} > 0 ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->_fields->{'hit_table'};} > 0 ? : 2 0 2
389 }
390  
391 =head2 get_statistic
392  
393 Title : get_statistic
394 Usage : my $gap_ext = $result->get_statistic('kappa')
395 Function: Returns the value for a specific statistic available
396 from this result
397 Returns : string
398 Args : name of statistic (string)
399  
400 =cut
401  
402 52 ▶sub get_statistic {
Subroutine get_statistic: called CC=1 SCAR=0.0
Pod documented
403 52 my $self = shift;
404 52 $self->get_field('stats_and_params');
405 52 return $self->SUPER::get_statistic(@_);
406 }
407  
408 =head2 get_parameter
409  
410 Title : get_parameter
411 Usage : my $gap_ext = $result->get_parameter('gapext')
412 Function: Returns the value for a specific parameter used
413 when running this result
414 Returns : string
415 Args : name of parameter (string)
416  
417 =cut
418  
419 15 ▶sub get_parameter {
Subroutine get_parameter: called CC=1 SCAR=0.0
Pod documented
420 15 my $self = shift;
421 15 $self->get_field('stats_and_params');
422 15 return $self->SUPER::get_parameter(@_);
423 }
424  
425 3 1;
« Bio/Tools/PrositeScan.pm ↑ Summary Bio/Matrix/PSM/IO/masta.pm »