File Coverage

Bio/SearchIO/SearchResultEventBuilder.pm
Criterion Covered Total %
statement 172 197 87.3
branch 59 90 65.5
condition 52 98 53.0
subroutine 21 22 95.4
pod 16 16 100.0
total 320 423 75.6


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::SearchIO::SearchResultEventBuilder
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Jason Stajich
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::SearchResultEventBuilder - Event Handler for SearchIO events.
17              
18             =head1 SYNOPSIS
19              
20             # Do not use this object directly, this object is part of the SearchIO
21             # event based parsing system.
22              
23             =head1 DESCRIPTION
24              
25             This object handles Search Events generated by the SearchIO classes
26             and build appropriate Bio::Search::* objects from them.
27              
28             =head1 FEEDBACK
29              
30             =head2 Mailing Lists
31              
32             User feedback is an integral part of the evolution of this and other
33             Bioperl modules. Send your comments and suggestions preferably to
34             the Bioperl mailing list. Your participation is much appreciated.
35              
36             bioperl-l@bioperl.org - General discussion
37             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
38              
39             =head2 Support
40              
41             Please direct usage questions or support issues to the mailing list:
42              
43             I
44              
45             rather than to the module maintainer directly. Many experienced and
46             reponsive experts will be able look at the problem and quickly
47             address it. Please include a thorough description of the problem
48             with code and data examples if at all possible.
49              
50             =head2 Reporting Bugs
51              
52             Report bugs to the Bioperl bug tracking system to help us keep track
53             of the bugs and their resolution. Bug reports can be submitted via the
54             web:
55              
56             https://github.com/bioperl/bioperl-live/issues
57              
58             =head1 AUTHOR - Jason Stajich
59              
60             Email jason-at-bioperl.org
61              
62             =head1 CONTRIBUTORS
63              
64             Sendu Bala, bix@sendu.me.uk
65              
66             =head1 APPENDIX
67              
68             The rest of the documentation details each of the object methods.
69             Internal methods are usually preceded with a _
70              
71             =cut
72              
73              
74             # Let the code begin...
75              
76              
77             package Bio::SearchIO::SearchResultEventBuilder;
78              
79 30     30   155 use strict;
  30         31  
  30         686  
80              
81 30     30   7627 use Bio::Factory::ObjectFactory;
  30         47  
  30         743  
82              
83 30     30   117 use base qw(Bio::Root::Root Bio::SearchIO::EventHandlerI);
  30         35  
  30         8599  
84              
85 30         52397 use vars qw($DEFAULT_INCLUSION_THRESHOLD
86             $MAX_HSP_OVERLAP
87 30     30   120 );
  30         34  
88              
89             # e-value threshold for inclusion in the PSI-BLAST score matrix model (blastpgp)
90             # NOTE: Executing `blastpgp -` incorrectly reports that the default is 0.005.
91             # (version 2.2.2 [Jan-08-2002])
92             $DEFAULT_INCLUSION_THRESHOLD = 0.001;
93              
94             $MAX_HSP_OVERLAP = 2; # Used when tiling multiple HSPs.
95              
96             =head2 new
97              
98             Title : new
99             Usage : my $obj = Bio::SearchIO::SearchResultEventBuilder->new();
100             Function: Builds a new Bio::SearchIO::SearchResultEventBuilder object
101             Returns : Bio::SearchIO::SearchResultEventBuilder
102             Args : -hsp_factory => Bio::Factory::ObjectFactoryI
103             -hit_factory => Bio::Factory::ObjectFactoryI
104             -result_factory => Bio::Factory::ObjectFactoryI
105             -inclusion_threshold => e-value threshold for inclusion in the
106             PSI-BLAST score matrix model (blastpgp)
107             -signif => float or scientific notation number to be used
108             as a P- or Expect value cutoff
109             -score => integer or scientific notation number to be used
110             as a blast score value cutoff
111             -bits => integer or scientific notation number to be used
112             as a bit score value cutoff
113             -hit_filter => reference to a function to be used for
114             filtering hits based on arbitrary criteria.
115              
116             See L for more information
117              
118             =cut
119              
120             sub new {
121 293     293 1 689 my ($class,@args) = @_;
122 293         965 my $self = $class->SUPER::new(@args);
123 293         1216 my ($resultF, $hitF, $hspF) =
124             $self->_rearrange([qw(RESULT_FACTORY
125             HIT_FACTORY
126             HSP_FACTORY)],@args);
127 293         955 $self->_init_parse_params(@args);
128              
129 293   33     2420 $self->register_factory('result', $resultF ||
130             Bio::Factory::ObjectFactory->new(
131             -type => 'Bio::Search::Result::GenericResult',
132             -interface => 'Bio::Search::Result::ResultI'));
133              
134 293   33     1538 $self->register_factory('hit', $hitF ||
135             Bio::Factory::ObjectFactory->new(
136             -type => 'Bio::Search::Hit::GenericHit',
137             -interface => 'Bio::Search::Hit::HitI'));
138              
139 293   33     1636 $self->register_factory('hsp', $hspF ||
140             Bio::Factory::ObjectFactory->new(
141             -type => 'Bio::Search::HSP::GenericHSP',
142             -interface => 'Bio::Search::HSP::HSPI'));
143              
144 293         1283 return $self;
145             }
146              
147             # Initializes parameters used during parsing of reports.
148             sub _init_parse_params {
149              
150 385     385   708 my ($self, @args) = @_;
151             # -FILT_FUNC has been replaced by -HIT_FILTER.
152             # Leaving -FILT_FUNC in place for backward compatibility
153 385         1177 my($ithresh, $signif, $score, $bits, $hit_filter, $filt_func) =
154             $self->_rearrange([qw(INCLUSION_THRESHOLD SIGNIF SCORE BITS
155             HIT_FILTER FILT_FUNC
156             )], @args);
157              
158 385 50       1671 $self->inclusion_threshold( defined($ithresh) ? $ithresh : $DEFAULT_INCLUSION_THRESHOLD);
159 385   66     1130 my $hit_filt = $hit_filter || $filt_func;
160 385 100       835 defined $hit_filter && $self->hit_filter($hit_filt);
161 385 100       652 defined $signif && $self->max_significance($signif);
162 385 100       682 defined $score && $self->min_score($score);
163 385 100       920 defined $bits && $self->min_bits($bits);
164             }
165              
166             =head2 will_handle
167              
168             Title : will_handle
169             Usage : if( $handler->will_handle($event_type) ) { ... }
170             Function: Tests if this event builder knows how to process a specific event
171             Returns : boolean
172             Args : event type name
173              
174             =cut
175              
176             sub will_handle{
177 20958     20958 1 18491 my ($self,$type) = @_;
178             # these are the events we recognize
179 20958   66     77781 return ( $type eq 'hsp' || $type eq 'hit' || $type eq 'result' );
180             }
181              
182             =head2 SAX methods
183              
184             =cut
185              
186             =head2 start_result
187              
188             Title : start_result
189             Usage : $handler->start_result($resulttype)
190             Function: Begins a result event cycle
191             Returns : none
192             Args : Type of Report
193              
194             =cut
195              
196             sub start_result {
197 173     173 1 354 my ($self,$type) = @_;
198 173         380 $self->{'_resulttype'} = $type;
199 173         336 $self->{'_hits'} = [];
200 173         327 $self->{'_hsps'} = [];
201 173         291 $self->{'_hitcount'} = 0;
202 173         314 return;
203             }
204              
205             =head2 end_result
206              
207             Title : end_result
208             Usage : my @results = $parser->end_result
209             Function: Finishes a result handler cycle
210             Returns : A Bio::Search::Result::ResultI
211             Args : none
212              
213             =cut
214              
215             # this is overridden by IteratedSearchResultEventBuilder
216             # so keep that in mind when debugging
217              
218             sub end_result {
219 180     180 1 320 my ($self,$type,$data) = @_;
220              
221 180 50 33     662 if( defined $data->{'runid'} &&
222             $data->{'runid'} !~ /^\s+$/ ) {
223              
224 0 0       0 if( $data->{'runid'} !~ /^lcl\|/) {
225 0         0 $data->{"RESULT-query_name"} = $data->{'runid'};
226             } else {
227             ($data->{"RESULT-query_name"},
228             $data->{"RESULT-query_description"}) =
229 0         0 split(/\s+/,$data->{"RESULT-query_description"},2);
230             }
231              
232 0 0       0 if( my @a = split(/\|/,$data->{'RESULT-query_name'}) ) {
233 0         0 my $acc = pop @a ; # this is for accession |1234|gb|AAABB1.1|AAABB1
234             # this is for |123|gb|ABC1.1|
235 0 0 0     0 $acc = pop @a if( ! defined $acc || $acc =~ /^\s+$/);
236 0         0 $data->{"RESULT-query_accession"}= $acc;
237             }
238 0         0 delete $data->{'runid'};
239             }
240 1581         1527 my %args = map { my $v = $data->{$_}; s/RESULT//; ($_ => $v); }
  1581         2082  
  1581         3103  
241 180         294 grep { /^RESULT/ } keys %{$data};
  4400         4444  
  180         920  
242              
243             $args{'-algorithm'} = uc( $args{'-algorithm_name'}
244 180   66     1072 || $data->{'RESULT-algorithm_name'}
245             || $type);
246             ($self->isa('Bio::SearchIO::IteratedSearchResultEventBuilder')) ?
247             ( $args{'-iterations'} = $self->{'_iterations'} )
248 180 100       1531 : ( $args{'-hits'} = $self->{'_hits'} );
249              
250 180         423 my $result = $self->factory('result')->create_object(%args);
251 180         622 $result->hit_factory($self->factory('hit'));
252              
253             ($self->isa('Bio::SearchIO::IteratedSearchResultEventBuilder')) ?
254             ( $self->{'_iterations'} = [] )
255 180 100       965 : ( $self->{'_hits'} = [] );
256              
257 180         1060 return $result;
258             }
259              
260             =head2 start_hsp
261              
262             Title : start_hsp
263             Usage : $handler->start_hsp($name,$data)
264             Function: Begins processing a HSP event
265             Returns : none
266             Args : type of element
267             associated data (hashref)
268              
269             =cut
270              
271             sub start_hsp {
272 7792     7792 1 12762 my ($self,@args) = @_;
273 7792         10928 return;
274             }
275              
276             =head2 end_hsp
277              
278             Title : end_hsp
279             Usage : $handler->end_hsp()
280             Function: Finish processing a HSP event
281             Returns : none
282             Args : type of event and associated hashref
283              
284              
285             =cut
286              
287             sub end_hsp {
288 7792     7792 1 8571 my ($self,$type,$data) = @_;
289              
290 7792 50 33     14852 if( defined $data->{'runid'} &&
291             $data->{'runid'} !~ /^\s+$/ ) {
292              
293 0 0       0 if( $data->{'runid'} !~ /^lcl\|/) {
294 0         0 $data->{"RESULT-query_name"}= $data->{'runid'};
295             } else {
296             ($data->{"RESULT-query_name"},
297             $data->{"RESULT-query_description"}) =
298 0         0 split(/\s+/,$data->{"RESULT-query_description"},2);
299             }
300              
301 0 0       0 if( my @a = split(/\|/,$data->{'RESULT-query_name'}) ) {
302 0         0 my $acc = pop @a ; # this is for accession |1234|gb|AAABB1.1|AAABB1
303             # this is for |123|gb|ABC1.1|
304 0 0 0     0 $acc = pop @a if( ! defined $acc || $acc =~ /^\s+$/);
305 0         0 $data->{"RESULT-query_accession"}= $acc;
306             }
307 0         0 delete $data->{'runid'};
308             }
309              
310             # this code is to deal with the fact that Blast XML data
311             # always has start < end and one has to infer strandedness
312             # from the frame which is a problem for the Search::HSP object
313             # which expect to be able to infer strand from the order of
314             # of the begin/end of the query and hit coordinates
315 7792 50 33     16022 if( defined $data->{'HSP-query_frame'} && # this is here to protect from undefs
      66        
316             (( $data->{'HSP-query_frame'} < 0 &&
317             $data->{'HSP-query_start'} < $data->{'HSP-query_end'} ) ||
318             $data->{'HSP-query_frame'} > 0 &&
319             ( $data->{'HSP-query_start'} > $data->{'HSP-query_end'} ) )
320             )
321             {
322             # swap
323             ($data->{'HSP-query_start'},
324             $data->{'HSP-query_end'}) = ($data->{'HSP-query_end'},
325 0         0 $data->{'HSP-query_start'});
326             }
327 7792 50 33     18610 if( defined $data->{'HSP-hit_frame'} && # this is here to protect from undefs
      66        
328             ((defined $data->{'HSP-hit_frame'} && $data->{'HSP-hit_frame'} < 0 &&
329             $data->{'HSP-hit_start'} < $data->{'HSP-hit_end'} ) ||
330             defined $data->{'HSP-hit_frame'} && $data->{'HSP-hit_frame'} > 0 &&
331             ( $data->{'HSP-hit_start'} > $data->{'HSP-hit_end'} ) )
332             )
333             {
334             # swap
335             ($data->{'HSP-hit_start'},
336             $data->{'HSP-hit_end'}) = ($data->{'HSP-hit_end'},
337 0         0 $data->{'HSP-hit_start'});
338             }
339 7792   100     21635 $data->{'HSP-query_frame'} ||= 0;
340 7792   100     18044 $data->{'HSP-hit_frame'} ||= 0;
341             # handle Blast 2.1.2 which did not support data member: hsp_align-len
342 7792   100     22714 $data->{'HSP-query_length'} ||= $data->{'RESULT-query_length'};
343 7792   100     19273 $data->{'HSP-hit_length'} ||= $data->{'HIT-length'};
344              
345             # If undefined lengths, calculate from alignment without gaps and separators
346 7792 100       11879 if (not defined $data->{'HSP-query_length'}) {
347 971 100       1251 if (my $hsp_qry_seq = $data->{'HSP-query_seq'}) {
348 126         1377 $hsp_qry_seq =~ s/[-\.]//g;
349 126         206 $data->{'HSP-query_length'} = length $hsp_qry_seq;
350             }
351             else {
352 845         862 $data->{'HSP-query_length'} = 0;
353             }
354             }
355 7792 100       11430 if (not defined $data->{'HSP-hit_length'}) {
356 5678 100       8408 if (my $hsp_hit_seq = $data->{'HSP-hit_seq'}) {
357 131         897 $hsp_hit_seq =~ s/[-\.]//g;
358 131         203 $data->{'HSP-hit_length'} = length $hsp_hit_seq;
359             }
360             else {
361 5547         4996 $data->{'HSP-hit_length'} = 0;
362             }
363             }
364 7792   100     22643 $data->{'HSP-hsp_length'} ||= length ($data->{'HSP-homology_seq'} || '');
      100        
365              
366 131716         94049 my %args = map { my $v = $data->{$_}; s/HSP//; ($_ => $v) }
  131716         149689  
  131716         193336  
367 7792         6449 grep { /^HSP/ } keys %{$data};
  219628         223501  
  7792         36145  
368              
369             $args{'-algorithm'} = uc( $args{'-algorithm_name'} ||
370 7792   100     46164 $data->{'RESULT-algorithm_name'} || $type);
371             # copy this over from result
372 7792         10076 $args{'-query_name'} = $data->{'RESULT-query_name'};
373 7792         9160 $args{'-hit_name'} = $data->{'HIT-name'};
374 7792 50       5527 my ($rank) = scalar @{$self->{'_hsps'} || []} + 1;
  7792         18404  
375 7792         8051 $args{'-rank'} = $rank;
376              
377 7792         8447 $args{'-hit_desc'} = $data->{'HIT-description'};
378 7792         8123 $args{'-query_desc'} = $data->{'RESULT-query_description'};
379              
380 7792         6618 my $bits = $args{'-bits'};
381 7792         7240 my $hsp = \%args;
382 7792         5671 push @{$self->{'_hsps'}}, $hsp;
  7792         11436  
383              
384 7792         15509 return $hsp;
385             }
386              
387             =head2 start_hit
388              
389             Title : start_hit
390             Usage : $handler->start_hit()
391             Function: Starts a Hit event cycle
392             Returns : none
393             Args : type of event and associated hashref
394              
395             =cut
396              
397             sub start_hit{
398 8391     8391 1 12214 my ($self,$type) = @_;
399 8391         9056 $self->{'_hsps'} = [];
400 8391         12496 return;
401             }
402              
403             =head2 end_hit
404              
405             Title : end_hit
406             Usage : $handler->end_hit()
407             Function: Ends a Hit event cycle
408             Returns : Bio::Search::Hit::HitI object
409             Args : type of event and associated hashref
410              
411             =cut
412              
413             sub end_hit{
414 8391     8391 1 7826 my ($self,$type,$data) = @_;
415              
416             # Skip process unless there is HSP data or Hit Significance (e.g. a bl2seq with no similarity
417             # gives a hit with the subject, but shows a "no hits found" message instead
418             # of the alignment data and don't have a significance value).
419             # This way, we avoid false positives
420 8391         7122 my @hsp_data = grep { /^HSP/ } keys %{$data};
  142509         138563  
  8391         23283  
421 8391 50 66     25249 return unless (scalar @hsp_data > 0 or exists $data->{'HIT-significance'});
422              
423 8391         7219 my %args = map { my $v = $data->{$_}; s/HIT//; ($_ => $v); } grep { /^HIT/ } keys %{$data};
  34943         27757  
  34943         45310  
  34943         56255  
  142509         131646  
  8391         17095  
424              
425             # I hate special cases, but this is here because NCBI BLAST XML
426             # doesn't play nice and is undergoing mutation -jason
427 8391 50 33     37744 if(exists $args{'-name'} && $args{'-name'} =~ /BL_ORD_ID/ ) {
428 0         0 ($args{'-name'}, $args{'-description'}) = split(/\s+/,$args{'-description'},2);
429             }
430             $args{'-algorithm'} = uc( $args{'-algorithm_name'} ||
431 8391   100     26063 $data->{'RESULT-algorithm_name'} || $type);
432 8391         11007 $args{'-hsps'} = $self->{'_hsps'};
433 8391         10099 $args{'-query_len'} = $data->{'RESULT-query_length'};
434 8391         12649 $args{'-rank'} = $self->{'_hitcount'} + 1;
435 8391 100       12457 unless( defined $args{'-significance'} ) {
436 979 50 33     3084 if( defined $args{'-hsps'} &&
437             $args{'-hsps'}->[0] ) {
438             # use pvalue if present (WU-BLAST), otherwise evalue (NCBI BLAST)
439 979   66     2664 $args{'-significance'} = $args{'-hsps'}->[0]->{'-pvalue'} || $args{'-hsps'}->[0]->{'-evalue'};
440             }
441             }
442 8391         7503 my $hit = \%args;
443 8391         14650 $hit->{'-hsp_factory'} = $self->factory('hsp');
444 8391         15499 $self->_add_hit($hit);
445 8391         9270 $self->{'_hsps'} = [];
446 8391         15906 return $hit;
447             }
448              
449             # Title : _add_hit (private function for internal use only)
450             # Purpose : Applies hit filtering and store it if it passes filtering.
451             # Argument: Bio::Search::Hit::HitI object
452              
453             sub _add_hit {
454 5945     5945   4866 my ($self, $hit) = @_;
455 5945         8490 my $hit_signif = $hit->{-significance};
456              
457             # Test significance using custom function (if supplied)
458 5945         4146 my $add_hit = 1;
459              
460 5945         4854 my $hit_filter = $self->{'_hit_filter'};
461 5945 100       7169 if($hit_filter) {
462             # since &hit_filter is out of our control and would expect a HitI object,
463             # we're forced to make one for it
464 2         6 $hit = $self->factory('hit')->create_object(%{$hit});
  2         11  
465 2 100       11 $add_hit = 0 unless &$hit_filter($hit);
466             }
467             else {
468 5943 100       9632 if($self->{'_confirm_significance'}) {
469 55 100       274 $add_hit = 0 unless $hit_signif <= $self->{'_max_significance'};
470             }
471 5943 100       7742 if($self->{'_confirm_score'}) {
472 1215   33     2408 my $hit_score = $hit->{-score} || $hit->{-hsps}->[0]->{-score};
473 1215 100       3680 $add_hit = 0 unless $hit_score >= $self->{'_min_score'};
474             }
475 5943 100       8295 if($self->{'_confirm_bits'}) {
476 2   50     22 my $hit_bits = $hit->{-bits} || $hit->{-hsps}->[0]->{-bits} || 0;
477 2 50       6 $add_hit = 0 unless $hit_bits >= $self->{'_min_bits'};
478             }
479             }
480              
481 5945 100       8542 $add_hit && push @{$self->{'_hits'}}, $hit;;
  4681         5948  
482 5945         4146 $self->{'_hitcount'} = scalar @{$self->{'_hits'}};
  5945         7618  
483             }
484              
485             =head2 Factory methods
486              
487             =cut
488              
489             =head2 register_factory
490              
491             Title : register_factory
492             Usage : $handler->register_factory('TYPE',$factory);
493             Function: Register a specific factory for a object type class
494             Returns : none
495             Args : string representing the class and
496             Bio::Factory::ObjectFactoryI
497              
498             See L for more information
499              
500             =cut
501              
502             sub register_factory{
503 1502     1502 1 1699 my ($self, $type,$f) = @_;
504 1502 50 33     7324 if( ! defined $f || ! ref($f) ||
      33        
505             ! $f->isa('Bio::Factory::ObjectFactoryI') ) {
506 0         0 $self->throw("Cannot set factory to value $f".ref($f)."\n");
507             }
508 1502         3537 $self->{'_factories'}->{lc($type)} = $f;
509             }
510              
511             =head2 factory
512              
513             Title : factory
514             Usage : my $f = $handler->factory('TYPE');
515             Function: Retrieves the associated factory for requested 'TYPE'
516             Returns : a Bio::Factory::ObjectFactoryI
517             Throws : Bio::Root::BadParameter if none registered for the supplied type
518             Args : name of factory class to retrieve
519              
520             See L for more information
521              
522             =cut
523              
524             sub factory{
525 8943     8943 1 8831 my ($self,$type) = @_;
526 8943   33     26288 return $self->{'_factories'}->{lc($type)} ||
527             $self->throw(-class=>'Bio::Root::BadParameter',
528             -text=>"No factory registered for $type");
529             }
530              
531             =head2 inclusion_threshold
532              
533             See L.
534              
535             =cut
536              
537             sub inclusion_threshold {
538 487     487 1 567 my $self = shift;
539 487 100       1391 return $self->{'_inclusion_threshold'} = shift if @_;
540 102         210 return $self->{'_inclusion_threshold'};
541             }
542              
543             =head2 max_significance
544              
545             Usage : $obj->max_significance();
546             Purpose : Set/Get the P or Expect value used as significance screening cutoff.
547             This is the value of the -signif parameter supplied to new().
548             Hits with P or E-value at HIT level above this are skipped.
549             Returns : Scientific notation number with this format: 1.0e-05.
550             Argument : Number (sci notation, float, integer) (when setting)
551             Throws : Bio::Root::BadParameter exception if the supplied argument is
552             : not a valid number.
553             Comments : Screening of significant hits uses the data provided on the
554             : description line. For NCBI BLAST1 and WU-BLAST, this data
555             : is P-value. for NCBI BLAST2 it is an Expect value.
556              
557             =cut
558              
559             sub max_significance {
560 5     5 1 8 my $self = shift;
561 5 50       13 if (@_) {
562 5         7 my $sig = shift;
563 5 50 33     95 if( $sig =~ /[^\d.e-]/ or $sig <= 0) {
564 0         0 $self->throw(-class => 'Bio::Root::BadParameter',
565             -text => "Invalid significance value: $sig\n"
566             . "Must be a number greater than zero.",
567             -value => $sig);
568             }
569 5         8 $self->{'_confirm_significance'} = 1;
570 5         10 $self->{'_max_significance'} = $sig;
571             }
572 5         32 sprintf "%.1e", $self->{'_max_significance'};
573             }
574              
575              
576             =head2 signif
577              
578             Synonym for L
579              
580             =cut
581              
582 0     0 1 0 sub signif { shift->max_significance }
583              
584             =head2 min_score
585              
586             Usage : $obj->min_score();
587             Purpose : Gets the Blast score used as screening cutoff.
588             This is the value of the -score parameter supplied to new().
589             Hits with scores at HIT level below this are skipped.
590             Returns : Integer (or undef if not set)
591             Argument : Integer (when setting)
592             Throws : Bio::Root::BadParameter exception if the supplied argument is
593             : not a valid number.
594             Comments : Screening of significant hits uses the data provided on the
595             : description line.
596              
597             =cut
598              
599             sub min_score {
600 5     5 1 9 my $self = shift;
601 5 50       11 if (@_) {
602 5         10 my $score = shift;
603 5 50 33     36 if( $score =~ /[^\de+]/ or $score <= 0) {
604 0         0 $self->throw(-class => 'Bio::Root::BadParameter',
605             -text => "Invalid score value: $score\n"
606             . "Must be an integer greater than zero.",
607             -value => $score);
608             }
609 5         8 $self->{'_confirm_score'} = 1;
610 5         10 $self->{'_min_score'} = $score;
611             }
612 5         7 return $self->{'_min_score'};
613             }
614              
615             =head2 min_bits
616              
617             Usage : $obj->min_bits();
618             Purpose : Gets the Blast bit score used as screening cutoff.
619             This is the value of the -bits parameter supplied to new().
620             Hits with bits score at HIT level below this are skipped.
621             Returns : Integer (or undef if not set)
622             Argument : Integer (when setting)
623             Throws : Bio::Root::BadParameter exception if the supplied argument is
624             : not a valid number.
625             Comments : Screening of significant hits uses the data provided on the
626             : description line.
627              
628             =cut
629              
630             sub min_bits {
631 5     5 1 8 my $self = shift;
632 5 50       15 if (@_) {
633 5         6 my $bits = shift;
634 5 50 33     41 if( $bits =~ /[^\de+]/ or $bits <= 0) {
635 0         0 $self->throw(-class => 'Bio::Root::BadParameter',
636             -text => "Invalid bits value: $bits\n"
637             . "Must be an integer greater than zero.",
638             -value => $bits);
639             }
640 5         10 $self->{'_confirm_bits'} = 1;
641 5         12 $self->{'_min_bits'} = $bits;
642             }
643 5         16 return $self->{'_min_bits'};
644             }
645              
646             =head2 hit_filter
647              
648             Usage : $obj->hit_filter();
649             Purpose : Set/Get a function reference used for filtering out hits.
650             This is the value of the -hit_filter parameter supplied to new().
651             Hits that fail to pass the filter at HIT level are skipped.
652             Returns : Function ref (or undef if not set)
653             Argument : Function ref (when setting)
654             Throws : Bio::Root::BadParameter exception if the supplied argument is
655             : not a function reference.
656              
657             =cut
658              
659             sub hit_filter {
660 5     5 1 7 my $self = shift;
661 5 50       12 if (@_) {
662 5         10 my $func = shift;
663 5 50       12 if(not ref $func eq 'CODE') {
664 0         0 $self->throw(-class => 'Bio::Root::BadParameter',
665             -text => "Not a function reference: $func\n"
666             . "The -hit_filter parameter must be function reference.",
667             -value => $func);
668             }
669 5         10 $self->{'_hit_filter'} = $func;
670             }
671 5         8 return $self->{'_hit_filter'};
672             }
673              
674             1;