3 # BioPerl module for Bio::SearchIO::FastHitEventBuilder
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::SearchIO::FastHitEventBuilder - Event Handler for SearchIO events.
21 # Do not use this object directly, this object is part of the SearchIO
22 # event based parsing system.
24 # to use the FastHitEventBuilder do this
26 use Bio::SearchIO::FastHitEventBuilder;
28 my $searchio = Bio::SearchIO->new(-format => $format, -file => $file);
30 $searchio->attach_EventHandler(Bio::SearchIO::FastHitEventBuilder->new());
32 while( my $r = $searchio->next_result ) {
33 while( my $h = $r->next_hit ) {
34 # note that Hits will NOT have HSPs
40 This object handles Search Events generated by the SearchIO classes
41 and build appropriate Bio::Search::* objects from them. This object
42 is intended for lightweight parsers which only want Hits and not deal
43 with the overhead of HSPs. It is a lot faster than the standard
44 parser event handler but of course you are getting less information
52 User feedback is an integral part of the evolution of this and other
53 Bioperl modules. Send your comments and suggestions preferably to
54 the Bioperl mailing list. Your participation is much appreciated.
56 bioperl-l@bioperl.org - General discussion
57 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
61 Please direct usage questions or support issues to the mailing list:
63 L<bioperl-l@bioperl.org>
65 rather than to the module maintainer directly. Many experienced and
66 reponsive experts will be able look at the problem and quickly
67 address it. Please include a thorough description of the problem
68 with code and data examples if at all possible.
72 Report bugs to the Bioperl bug tracking system to help us keep track
73 of the bugs and their resolution. Bug reports can be submitted via the
76 http://bugzilla.open-bio.org/
78 =head1 AUTHOR - Jason Stajich
80 Email jason-at-bioperl.org
84 The rest of the documentation details each of the object methods.
85 Internal methods are usually preceded with a _
90 # Let the code begin...
93 package Bio
::SearchIO
::FastHitEventBuilder
;
94 use vars
qw(%KNOWNEVENTS);
97 use Bio::Search::HSP::HSPFactory;
98 use Bio::Search::Hit::HitFactory;
99 use Bio::Search::Result::ResultFactory;
101 use base qw(Bio::Root::Root Bio::SearchIO::EventHandlerI);
106 Usage : my $obj = Bio::SearchIO::FastHitEventBuilder->new();
107 Function: Builds a new Bio::SearchIO::FastHitEventBuilder object
108 Returns : Bio::SearchIO::FastHitEventBuilder
109 Args : -hit_factory => Bio::Factory::ObjectFactoryI
110 -result_factory => Bio::Factory::ObjectFactoryI
112 See L<Bio::Factory::ObjectFactoryI> for more information
117 my ($class,@args) = @_;
118 my $self = $class->SUPER::new
(@args);
119 my ($hitF,$resultF) = $self->_rearrange([qw(HIT_FACTORY
120 RESULT_FACTORY)],@args);
121 $self->register_factory('hit', $hitF ||
122 Bio
::Factory
::ObjectFactory
->new(
123 -type
=> 'Bio::Search::Hit::GenericHit',
124 -interface
=> 'Bio::Search::Hit::HitI'));
126 $self->register_factory('result', $resultF ||
127 Bio
::Factory
::ObjectFactory
->new(
128 -type
=> 'Bio::Search::Result::GenericResult',
129 -interface
=> 'Bio::Search::Result::ResultI'));
134 # new comes from the superclass
139 Usage : if( $handler->will_handle($event_type) ) { ... }
140 Function: Tests if this event builder knows how to process a specific event
142 Args : event type name
148 my ($self,$type) = @_;
149 # these are the events we recognize
150 return ( $type eq 'hit' || $type eq 'result' );
160 Usage : $handler->start_result($resulttype)
161 Function: Begins a result event cycle
163 Args : Type of Report
168 my ($self,$type) = @_;
169 $self->{'_resulttype'} = $type;
170 $self->{'_hits'} = [];
177 Usage : my @results = $parser->end_result
178 Function: Finishes a result handler cycle Returns : A Bio::Search::Result::ResultI
184 my ($self,$type,$data) = @_;
185 if( defined $data->{'runid'} &&
186 $data->{'runid'} !~ /^\s+$/ ) {
188 if( $data->{'runid'} !~ /^lcl\|/) {
189 $data->{"RESULT-query_name"}= $data->{'runid'};
191 ($data->{"RESULT-query_name"},$data->{"RESULT-query_description"}) = split(/\s+/,$data->{"RESULT-query_description"},2);
194 if( my @a = split(/\|/,$data->{'RESULT-query_name'}) ) {
195 my $acc = pop @a ; # this is for accession |1234|gb|AAABB1.1|AAABB1
196 # this is for |123|gb|ABC1.1|
197 $acc = pop @a if( ! defined $acc || $acc =~ /^\s+$/);
198 $data->{"RESULT-query_accession"}= $acc;
200 delete $data->{'runid'};
202 my %args = map { my $v = $data->{$_}; s/RESULT//; ($_ => $v); }
203 grep { /^RESULT/ } keys %{$data};
205 $args{'-algorithm'} = uc( $args{'-algorithm_name'} || $type);
206 $args{'-hits'} = $self->{'_hits'};
207 my $result = $self->factory('result')->create(%args);
208 $self->{'_hits'} = [];
215 Usage : $handler->start_hit()
216 Function: Starts a Hit event cycle
218 Args : type of event and associated hashref
224 my ($self,$type) = @_;
232 Usage : $handler->end_hit()
233 Function: Ends a Hit event cycle
234 Returns : Bio::Search::Hit::HitI object
235 Args : type of event and associated hashref
241 my ($self,$type,$data) = @_;
242 my %args = map { my $v = $data->{$_}; s/HIT//; ($_ => $v); } grep { /^HIT/ } keys %{$data};
243 $args{'-algorithm'} = uc( $args{'-algorithm_name'} || $type);
244 $args{'-query_len'} = $data->{'RESULT-query_length'};
245 my ($hitrank) = scalar @
{$self->{'_hits'}} + 1;
246 $args{'-rank'} = $hitrank;
247 my $hit = $self->factory('hit')->create(%args);
248 push @
{$self->{'_hits'}}, $hit;
249 $self->{'_hsps'} = [];
253 =head2 Factory methods
257 =head2 register_factory
259 Title : register_factory
260 Usage : $handler->register_factory('TYPE',$factory);
261 Function: Register a specific factory for a object type class
263 Args : string representing the class and
264 Bio::Factory::ObjectFactoryI
266 See L<Bio::Factory::ObjectFactoryI> for more information
270 sub register_factory
{
271 my ($self, $type,$f) = @_;
272 if( ! defined $f || ! ref($f) ||
273 ! $f->isa('Bio::Factory::ObjectFactoryI') ) {
274 $self->throw("Cannot set factory to value $f".ref($f)."\n");
276 $self->{'_factories'}->{lc($type)} = $f;
283 Usage : my $f = $handler->factory('TYPE');
284 Function: Retrieves the associated factory for requested 'TYPE'
285 Returns : a Bio::Factory::ObjectFactoryI or undef if none registered
286 Args : name of factory class to retrieve
288 See L<Bio::Factory::ObjectFactoryI> for more information
293 my ($self,$type) = @_;
294 return $self->{'_factories'}->{lc($type)} || $self->throw("No factory registered for $type");
297 =head2 inclusion_threshold
299 See L<Bio::SearchIO::blast::inclusion_threshold>.
303 sub inclusion_threshold
{
305 return $self->{'_inclusion_threshold'} = shift if @_;
306 return $self->{'_inclusion_threshold'};