Bio/SearchIO/IteratedSearchResultEventBuilder.pm

filter: Statementstmt 79.7% 75 / 94 Branchbran 35.7% 10 / 28 Conditioncond 42.8% 15 / 35 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 60.2% 115 / 191 CC 27 SCAR 30.1
CC
27
Cov
64%
_add_hit
45.0
_store_hit
11.0
will_handle
6.9
CRAP 20.3
« Bio/Root/Root.pm ↑ Summary Bio/Location/Split.pm »
1 #------------------------------------------------------------------
2 #
3 # BioPerl module for Bio::SearchIO::IteratedSearchResultEventBuilder
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Steve Chervitz <sac@bioperl.org> and Jason Stajich <jason@bioperl.org>
8 #
9 # Copyright Steve Chervitz
10 #
11 # You may distribute this module under the same terms as perl itself
12 #------------------------------------------------------------------
13  
14 # POD documentation - main docs before the code
15  
16 =head1 NAME
17  
18 Bio::SearchIO::IteratedSearchResultEventBuilder - Event Handler for
19 SearchIO events.
20  
21 =head1 SYNOPSIS
22  
23 # Do not use this object directly, this object is part of the SearchIO
24 # event based parsing system.
25  
26 =head1 DESCRIPTION
27  
28 This object handles Search Events generated by the SearchIO classes
29 and build appropriate Bio::Search::* objects from them.
30  
31 =head1 FEEDBACK
32  
33 =head2 Mailing Lists
34  
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
38  
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41  
42 =head2 Support
43  
44 Please direct usage questions or support issues to the mailing list:
45  
46 I<bioperl-l@bioperl.org>
47  
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
52  
53 =head2 Reporting Bugs
54  
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via the
57 web:
58  
59 https://github.com/bioperl/bioperl-live/issues
60  
61 =head1 AUTHOR - Steve Chervitz
62  
63 Email sac-at-bioperl.org
64  
65 =head1 CONTRIBUTORS
66  
67 Parts of code based on SearchResultEventBuilder by Jason Stajich
68 jason@bioperl.org
69  
70 Sendu Bala, bix@sendu.me.uk
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  
80 # Let the code begin...
81  
82  
83 package Bio::SearchIO::IteratedSearchResultEventBuilder;
84 13 $Bio::SearchIO::IteratedSearchResultEventBuilder::VERSION = '1.7.8';
85 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 13 ▶use Bio::Factory::ObjectFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 13 ▶use base qw(Bio::SearchIO::SearchResultEventBuilder);
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 =head2 new
92  
93 Title : new
94 Usage : my $obj = Bio::SearchIO::IteratedSearchResultEventBuilder->new();
95 Function: Builds a new Bio::SearchIO::IteratedSearchResultEventBuilder object
96 Returns : Bio::SearchIO::IteratedSearchResultEventBuilder
97 Args : -hsp_factory => Bio::Factory::ObjectFactoryI
98 -hit_factory => Bio::Factory::ObjectFactoryI
99 -result_factory => Bio::Factory::ObjectFactoryI
100 -iteration_factory => Bio::Factory::ObjectFactoryI
101 -inclusion_threshold => e-value threshold for inclusion in the
102 PSI-BLAST score matrix model (blastpgp)
103 -signif => float or scientific notation number to be used
104 as a P- or Expect value cutoff
105 -score => integer or scientific notation number to be used
106 as a blast score value cutoff
107 -bits => integer or scientific notation number to be used
108 as a bit score value cutoff
109 -hit_filter => reference to a function to be used for
110 filtering hits based on arbitrary criteria.
111  
112 See L<Bio::SearchIO::SearchResultEventBuilder> for more information
113  
114 =cut
115  
116 45 ▶sub new {
Subroutine new: called CC=5 SCAR=18.5
Pod documented
117 45 my ($class,@args) = @_;
118 45 my $self = $class->SUPER::new(@args);
119 45 my ($resultF, $iterationF, $hitF, $hspF) =
120 $self->_rearrange([qw(RESULT_FACTORY
121 ITERATION_FACTORY
122 HIT_FACTORY
123 HSP_FACTORY)],@args);
124 45 $self->_init_parse_params(@args);
125  
126 # Note that we need to override the setting of result and factories here
127 # so that we can set different default factories than are set by the super class.
128 45 ▶ $self->register_factory('result', $resultF ||
Condition33%1/3
$resultF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Result::BlastResult', '-interface', 'Bio::Search::Result::ResultI')
l!l&&r!l&&!r
0450
MC/DC0%0/2
$resultF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Result::BlastResult', '-interface', 'Bio::Search::Result::ResultI')
$resultF 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Result::BlastResult', '-interface', 'Bio::Search::Result::ResultI')
Truth table33%1/3
A || B
A= $resultFB= 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Result::BlastResult', '-interface', 'Bio::Search::Result::ResultI')
ABresult
1X1
011
000
129 Bio::Factory::ObjectFactory->new(
130 -type => 'Bio::Search::Result::BlastResult',
131 -interface => 'Bio::Search::Result::ResultI'));
132  
133 45 ▶ $self->register_factory('hit', $hitF ||
Condition33%1/3
$hitF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Hit::BlastHit', '-interface', 'Bio::Search::Hit::HitI')
l!l&&r!l&&!r
0450
MC/DC0%0/2
$hitF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Hit::BlastHit', '-interface', 'Bio::Search::Hit::HitI')
$hitF 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Hit::BlastHit', '-interface', 'Bio::Search::Hit::HitI')
Truth table33%1/3
A || B
A= $hitFB= 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Hit::BlastHit', '-interface', 'Bio::Search::Hit::HitI')
ABresult
1X1
011
000
134 Bio::Factory::ObjectFactory->new(
135 -type => 'Bio::Search::Hit::BlastHit',
136 -interface => 'Bio::Search::Hit::HitI'));
137  
138 45 ▶ $self->register_factory('hsp', $hspF ||
Condition33%1/3
$hspF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::HSP::GenericHSP', '-interface', 'Bio::Search::HSP::HSPI')
l!l&&r!l&&!r
0450
MC/DC0%0/2
$hspF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::HSP::GenericHSP', '-interface', 'Bio::Search::HSP::HSPI')
$hspF 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::HSP::GenericHSP', '-interface', 'Bio::Search::HSP::HSPI')
Truth table33%1/3
A || B
A= $hspFB= 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::HSP::GenericHSP', '-interface', 'Bio::Search::HSP::HSPI')
ABresult
1X1
011
000
139 Bio::Factory::ObjectFactory->new(
140 -type => 'Bio::Search::HSP::GenericHSP',
141 -interface => 'Bio::Search::HSP::HSPI'));
142  
143 # TODO: Change this to BlastIteration (maybe)
144 45 ▶ $self->register_factory('iteration', $iterationF ||
Condition33%1/3
$iterationF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Iteration::GenericIteration', '-interface', 'Bio::Search::Iteration::IterationI')
l!l&&r!l&&!r
0450
MC/DC0%0/2
$iterationF || 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Iteration::GenericIteration', '-interface', 'Bio::Search::Iteration::IterationI')
$iterationF 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Iteration::GenericIteration', '-interface', 'Bio::Search::Iteration::IterationI')
Truth table33%1/3
A || B
A= $iterationFB= 'Bio::Factory::ObjectFactory'->new('-type', 'Bio::Search::Iteration::GenericIteration', '-interface', 'Bio::Search::Iteration::IterationI')
ABresult
1X1
011
000
145 Bio::Factory::ObjectFactory->new(
146 -type => 'Bio::Search::Iteration::GenericIteration',
147 -interface => 'Bio::Search::Iteration::IterationI'));
148  
149 45 return $self;
150 }
151  
152 =head2 will_handle
153  
154 Title : will_handle
155 Usage : if( $handler->will_handle($event_type) ) { ... }
156 Function: Tests if this event builder knows how to process a specific event
157 Returns : boolean
158 Args : event type name
159  
160 =cut
161  
162 159 ▶sub will_handle{
Subroutine will_handle: called CC=6 SCAR=19.3
Pod documented
163 159 my ($self,$type) = @_;
164 # these are the events we recognize
165 159 ▶ return ( $type eq 'hsp' || $type eq 'hit' || $type eq 'result'
Condition66%10/15
$type eq 'hsp' || $type eq 'hit' || $type eq 'result' || $type eq 'iteration' || $type eq 'newhits' || $type eq 'oldhits'
l!l&&r!l&&!r
15900
$type eq "hsp" or $type eq "hit" or $type eq "result" or $type eq "iteration" or $type eq "newhits"
l!l&&r!l&&!r
15900
$type eq "hsp" or $type eq "hit" or $type eq "result" or $type eq "iteration"
l!l&&r!l&&!r
119400
$type eq "hsp" or $type eq "hit" or $type eq "result"
l!l&&r!l&&!r
794040
$type eq "hsp" or $type eq "hit"
l!l&&r!l&&!r
394080
MC/DC0%0/6
$type eq 'hsp' || $type eq 'hit' || $type eq 'result' || $type eq 'iteration' || $type eq 'newhits' || $type eq 'oldhits'
$type eq "hsp" $type eq "hit" $type eq "result" $type eq "iteration" $type eq "newhits" $type eq 'oldhits'
Truth table57%4/7
A or B or C or D or E || F
A= $type eq "hsp"B= $type eq "hit"C= $type eq "result"D= $type eq "iteration"E= $type eq "newhits"F= $type eq 'oldhits'
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
166 || $type eq 'iteration' || $type eq 'newhits' || $type eq 'oldhits' );
167 }
168  
169 =head2 SAX methods
170  
171 =cut
172  
173 =head2 start_result
174  
175 Title : start_result
176 Usage : $handler->start_result($resulttype)
177 Function: Begins a result event cycle
178 Returns : none
179 Args : Type of Report
180  
181 =cut
182  
183 40 ▶sub start_result {
Subroutine start_result: called CC=1 SCAR=0.0
Pod documented
184 40 my $self = shift;
185 #print STDERR "ISREB: start_result()\n";
186 40 $self->SUPER::start_result(@_);
187 40 $self->{'_iterations'} = [];
188 40 $self->{'_iteration_count'} = 0;
189 40 $self->{'_old_hit_names'} = undef;
190 40 $self->{'_hit_names_below'} = undef;
191 40 return;
192 }
193  
194 =head2 start_iteration
195  
196 Title : start_iteration
197 Usage : $handler->start_iteration()
198 Function: Starts an Iteration event cycle
199 Returns : none
200 Args : type of event and associated hashref
201  
202 =cut
203  
204 40 ▶sub start_iteration {
Subroutine start_iteration: called CC=1 SCAR=0.0
Pod documented
205 40 my ($self,$type) = @_;
206  
207 #print STDERR "ISREB: start_iteration()\n";
208 40 $self->{'_iteration_count'}++;
209  
210 # Reset arrays for the various classes of hits.
211 # $self->{'_newhits_unclassified'} = [];
212 40 $self->{'_newhits_below'} = [];
213 40 $self->{'_newhits_not_below'} = [];
214 40 $self->{'_oldhits_below'} = [];
215 40 $self->{'_oldhits_newly_below'} = [];
216 40 $self->{'_oldhits_not_below'} = [];
217 40 $self->{'_hitcount'} = 0;
218 40 return;
219 }
220  
221  
222 =head2 end_iteration
223  
224 Title : end_iteration
225 Usage : $handler->end_iteration()
226 Function: Ends an Iteration event cycle
227 Returns : Bio::Search::Iteration object
228 Args : type of event and associated hashref
229  
230 =cut
231  
232 40 ▶sub end_iteration {
Subroutine end_iteration: called CC=1 SCAR=0.0
Pod documented
233 40 my ($self,$type,$data) = @_;
234  
235 # print STDERR "ISREB: end_iteration()\n";
236  
237 0 my %args = map { my $v = $data->{$_}; s/ITERATION//; ($_ => $v); }
238 40 grep { /^ITERATION/ } keys %{$data};
239  
240 40 $args{'-number'} = $self->{'_iteration_count'};
241 40 $args{'-oldhits_below'} = $self->{'_oldhits_below'};
242 40 $args{'-oldhits_newly_below'} = $self->{'_oldhits_newly_below'};
243 40 $args{'-oldhits_not_below'} = $self->{'_oldhits_not_below'};
244 40 $args{'-newhits_below'} = $self->{'_newhits_below'};
245 40 $args{'-newhits_not_below'} = $self->{'_newhits_not_below'};
246 40 $args{'-hit_factory'} = $self->factory('hit');
247  
248 40 my $it = $self->factory('iteration')->create_object(%args);
249 40 push @{$self->{'_iterations'}}, $it;
250 40 return $it;
251 }
252  
253 # Title : _add_hit (private function for internal use only)
254 # Purpose : Applies hit filtering and calls _store_hit if it passes filtering.
255 # Argument: Bio::Search::Hit::HitI object
256  
257 923 ▶sub _add_hit {
Subroutine _add_hit: called CC=13 SCAR=38.1
258 923 my ($self, $hit) = @_;
259  
260 923 my $hit_name = uc($hit->{-name});
261 923 my $hit_signif = $hit->{-significance};
262 923 my $ithresh = $self->{'_inclusion_threshold'};
263  
264 # Test significance using custom function (if supplied)
265 923 my $add_hit = 1;
266  
267 923 my $hit_filter = $self->{'_hit_filter'};
268  
269 923 ▶ if($hit_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hit_filter) { } 0 923 923
270 # since &hit_filter is out of our control and would expect a HitI object,
271 # we're forced to make one for it
272 0 $hit = $self->factory('hit')->create_object(%{$hit});
273 0 ▶ $add_hit = 0 unless &$hit_filter($hit);
Branch: 1 branch
BranchTrueFalseTotal
unless &$hit_filter($hit) 0 0 0
274 }
275 else {
276 923 ▶ if($self->{'_confirm_significance'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_confirm_significance"}) 0 923 923
277 0 ▶ $add_hit = 0 unless $hit_signif <= $self->{'_max_significance'};
Branch: 1 branch
BranchTrueFalseTotal
unless $hit_signif <= $self->{"_max_significance"} 0 0 0
278 }
279 923 ▶ if($self->{'_confirm_score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_confirm_score"}) 0 923 923
280 0 ▶ my $hit_score = $hit->{-score} || $hit->{-hsps}->[0]->{-score};
Condition0%0/3
$hit->{'-score'} || $hit->{'-hsps'}[0]{'-score'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hit->{'-score'} || $hit->{'-hsps'}[0]{'-score'}
$hit->{'-score'} $hit->{'-hsps'}[0]{'-score'}
Truth table0%0/3
A || B
A= $hit->{'-score'}B= $hit->{'-hsps'}[0]{'-score'}
ABresult
1X1
011
000
281 0 ▶ $add_hit = 0 unless $hit_score >= $self->{'_min_score'};
Branch: 1 branch
BranchTrueFalseTotal
unless $hit_score >= $self->{"_min_score"} 0 0 0
282 }
283 923 ▶ if($self->{'_confirm_bits'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_confirm_bits"}) 0 923 923
284 0 ▶ my $hit_bits = $hit->{-bits} || $hit->{-hsps}->[0]->{-bits};
Condition0%0/3
$hit->{'-bits'} || $hit->{'-hsps'}[0]{'-bits'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hit->{'-bits'} || $hit->{'-hsps'}[0]{'-bits'}
$hit->{'-bits'} $hit->{'-hsps'}[0]{'-bits'}
Truth table0%0/3
A || B
A= $hit->{'-bits'}B= $hit->{'-hsps'}[0]{'-bits'}
ABresult
1X1
011
000
285 0 ▶ $add_hit = 0 unless $hit_bits >= $self->{'_min_bits'};
Branch: 1 branch
BranchTrueFalseTotal
unless $hit_bits >= $self->{"_min_bits"} 0 0 0
286 }
287 }
288  
289 923 ▶ $add_hit && $self->_store_hit($hit, $hit_name, $hit_signif);
Branch: 1 branch
BranchTrueFalseTotal
$add_hit and $self->_store_hit($hit, $hit_name, $hit_signif) 923 0 923
290 # Building hit lookup hashes for determining if the hit is old/new and
291 # above/below threshold.
292 923 $self->{'_old_hit_names'}->{$hit_name}++;
293 923 ▶ $self->{'_hit_names_below'}->{$hit_name}++ if $hit_signif <= $ithresh;
Branch: 1 branch
BranchTrueFalseTotal
if $hit_signif <= $ithresh 578 345 923
294 }
295  
296 # Title : _store_hit (private function for internal use only)
297 # Purpose : Collects hit objects into defined sets that are useful for
298 # analyzing PSI-blast results.
299 # These are ultimately added to the iteration object in end_iteration().
300 #
301 # Strategy:
302 # Primary split = old vs. new
303 # Secondary split = below vs. above threshold
304 # 1. Has this hit occurred in a previous iteration?
305 # 1.1. If yes, was it below threshold?
306 # 1.1.1. If yes, ---> [oldhits_below]
307 # 1.1.2. If no, is it now below threshold?
308 # 1.1.2.1. If yes, ---> [oldhits_newly_below]
309 # 1.1.2.2. If no, ---> [oldhits_not_below]
310 # 1.2. If no, is it below threshold?
311 # 1.2.1. If yes, ---> [newhits_below]
312 # 1.2.2. If no, ---> [newhits_not_below]
313 # 1.2.3. If don't know (no inclusion threshold data), ---> [newhits_unclassified]
314 # Note: As long as there's a default inclusion threshold,
315 # there won't be an unclassified set.
316 #
317 # For the first iteration, it might be nice to detect non-PSI blast reports
318 # and put the hits in the unclassified set.
319 # However, it shouldn't matter where the hits get put for the first iteration
320 # for non-PSI blast reports since they'll get flattened out in the
321 # result and iteration search objects.
322  
323 923 ▶sub _store_hit {
Subroutine _store_hit: called CC=6 SCAR=24.0
324 923 my ($self, $hit, $hit_name, $hit_signif) = @_;
325  
326 923 my $ithresh = $self->{'_inclusion_threshold'};
327  
328 # This is the assumption leading to Bug 1986. The assumption here is that
329 # the hit name is unique (and thus new), therefore any subsequent encounters
330 # with a hit containing the same name are filed as old hits. This isn't
331 # always true (see the bug report for a few examples). Adding an explicit
332 # check for the presence of iterations, adding to new hits otherwise.
333  
334 923 ▶ if (exists $self->{'_old_hit_names'}->{$hit_name}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_old_hit_names'}{$hit_name} and scalar @{$self->{'_iterations'};}) { } 0 923 923
Condition50%1/2
exists $self->{"_old_hit_names"}{$hit_name} and scalar @{$self->{"_iterations"};}
!ll
9230
MC/DC0%0/1
exists $self->{"_old_hit_names"}{$hit_name} and scalar @{$self->{"_iterations"};}
exists $self->{"_old_hit_names"}{$hit_name}
Truth table50%1/2
A
A= exists $self->{"_old_hit_names"}{$hit_name}
Aresult
00
11
335 0 && scalar @{$self->{_iterations}}) {
336 0 ▶ if (exists $self->{'_hit_names_below'}->{$hit_name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'_hit_names_below'}{$hit_name}) { } 0 0 0
elsif ($hit_signif <= $ithresh) { } 0 0 0
337 0 push @{$self->{'_oldhits_below'}}, $hit;
338 } elsif ($hit_signif <= $ithresh) {
339 0 push @{$self->{'_oldhits_newly_below'}}, $hit;
340 } else {
341 0 push @{$self->{'_oldhits_not_below'}}, $hit;
342 }
343 } else {
344 923 ▶ if ($hit_signif <= $ithresh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hit_signif <= $ithresh) { } 578 345 923
345 578 push @{$self->{'_newhits_below'}}, $hit;
346 } else {
347 345 push @{$self->{'_newhits_not_below'}}, $hit;
348 }
349 }
350 923 $self->{'_hitcount'}++;
351 }
352  
353 13 1;
« Bio/Root/Root.pm ↑ Summary Bio/Location/Split.pm »