2 # BioPerl module for Bio::SearchIO::hmmer2
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SearchIO::hmmer2 - A parser for HMMER output (hmmpfam, hmmsearch)
20 # do not use this class directly it is available through Bio::SearchIO
22 my $in = Bio::SearchIO->new(-format => 'hmmer2',
23 -file => 't/data/L77119.hmmer');
24 while( my $result = $in->next_result ) {
25 # this is a Bio::Search::Result::HMMERResult object
26 print $result->query_name(), " for HMM ", $result->hmm_name(), "\n";
27 while( my $hit = $result->next_hit ) {
28 print $hit->name(), "\n";
29 while( my $hsp = $hit->next_hsp ) {
30 print "length is ", $hsp->length(), "\n";
37 This object implements a parser for HMMER output.
43 User feedback is an integral part of the evolution of this and other
44 Bioperl modules. Send your comments and suggestions preferably to
45 the Bioperl mailing list. Your participation is much appreciated.
47 bioperl-l@bioperl.org - General discussion
48 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
52 Please direct usage questions or support issues to the mailing list:
54 I<bioperl-l@bioperl.org>
56 rather than to the module maintainer directly. Many experienced and
57 reponsive experts will be able look at the problem and quickly
58 address it. Please include a thorough description of the problem
59 with code and data examples if at all possible.
63 Report bugs to the Bioperl bug tracking system to help us keep track
64 of the bugs and their resolution. Bug reports can be submitted via the
67 https://redmine.open-bio.org/projects/bioperl/
69 =head1 AUTHOR - Jason Stajich
71 Email jason-at-bioperl.org
75 The rest of the documentation details each of the object methods.
76 Internal methods are usually preceded with a _
80 # Let the code begin...
82 package Bio
::SearchIO
::hmmer2
;
86 use Bio
::Factory
::ObjectFactory
;
88 use vars
qw(%MAPPING %MODEMAP
91 use base qw(Bio::SearchIO::hmmer);
95 # mapping of HMMER items to Bioperl hash keys
97 'HMMER_Output' => 'result',
103 'Hsp_bit-score' => 'HSP-bits',
104 'Hsp_score' => 'HSP-score',
105 'Hsp_evalue' => 'HSP-evalue',
106 'Hsp_query-from' => 'HSP-query_start',
107 'Hsp_query-to' => 'HSP-query_end',
108 'Hsp_hit-from' => 'HSP-hit_start',
109 'Hsp_hit-to' => 'HSP-hit_end',
110 'Hsp_positive' => 'HSP-conserved',
111 'Hsp_identity' => 'HSP-identical',
112 'Hsp_gaps' => 'HSP-hsp_gaps',
113 'Hsp_hitgaps' => 'HSP-hit_gaps',
114 'Hsp_querygaps' => 'HSP-query_gaps',
115 'Hsp_qseq' => 'HSP-query_seq',
116 'Hsp_hseq' => 'HSP-hit_seq',
117 'Hsp_midline' => 'HSP-homology_seq',
118 'Hsp_align-len' => 'HSP-hsp_length',
119 'Hsp_query-frame' => 'HSP-query_frame',
120 'Hsp_hit-frame' => 'HSP-hit_frame',
122 'Hit_id' => 'HIT-name',
123 'Hit_len' => 'HIT-length',
124 'Hit_accession' => 'HIT-accession',
125 'Hit_desc' => 'HIT-description',
126 'Hit_signif' => 'HIT-significance',
127 'Hit_score' => 'HIT-score',
129 'HMMER_program' => 'RESULT-algorithm_name',
130 'HMMER_version' => 'RESULT-algorithm_version',
131 'HMMER_query-def' => 'RESULT-query_name',
132 'HMMER_query-len' => 'RESULT-query_length',
133 'HMMER_query-acc' => 'RESULT-query_accession',
134 'HMMER_querydesc' => 'RESULT-query_description',
135 'HMMER_hmm' => 'RESULT-hmm_name',
136 'HMMER_seqfile' => 'RESULT-sequence_file',
137 'HMMER_db' => 'RESULT-database_name',
144 Usage : my $hit = $searchio->next_result;
145 Function: Returns the next Result from a search
146 Returns : Bio::Search::Result::ResultI object
155 my ( $last, @hitinfo, @hspinfo, %hspinfo, %hitinfo );
159 my $verbose = $self->verbose; # cache for speed?
160 $self->start_document();
162 while ( defined( $_ = $self->_readline ) ) {
165 if (/^HMMER\s+(\S+)\s+\((.+)\)/o) {
166 my ( $prog, $version ) = split;
168 $self->_pushback($_);
169 $self->end_element( { 'Name' => 'HMMER_Output' } );
170 return $self->end_document();
172 $self->{'_hmmidline'} = $_;
173 $self->start_element( { 'Name' => 'HMMER_Output' } );
174 $self->{'_result_count'}++;
176 if ( defined $last ) {
177 ($reporttype) = split( /\s+/, $last );
178 $reporttype = uc($reporttype) if defined $reporttype;
181 'Name' => 'HMMER_program',
182 'Data' => $reporttype
188 'Name' => 'HMMER_version',
193 elsif (s/^HMM file:\s+//o) {
194 $self->{'_hmmfileline'} = $lineorig;
197 'Name' => 'HMMER_hmm',
202 elsif (s/^Sequence\s+(file|database):\s+//o) {
203 $self->{'_hmmseqline'} = $lineorig;
204 if ( $1 eq 'database' ) {
207 'Name' => 'HMMER_db',
214 'Name' => 'HMMER_seqfile',
219 elsif (s/^Query(\s+(sequence|HMM))?(?:\s+\d+)?:\s+//o) {
222 # we're in a multi-query report
223 $self->_pushback($lineorig);
224 $self->_pushback( $self->{'_hmmseqline'} );
225 $self->_pushback( $self->{'_hmmfileline'} );
226 $self->_pushback( $self->{'_hmmidline'} );
232 'Name' => 'HMMER_query-def',
237 elsif (s/^Accession:\s+//o) {
241 'Name' => 'HMMER_query-acc',
246 elsif (s/^Description:\s+//o) {
250 'Name' => 'HMMER_querydesc',
255 elsif ( defined $self->{'_reporttype'}
256 && $self->{'_reporttype'} eq 'HMMSEARCH' )
259 # PROCESS HMMSEARCH RESULTS HERE
260 if (/^Scores for complete sequences/o) {
261 while ( defined( $_ = $self->_readline ) ) {
263 next if ( /^Sequence\s+Description/o || /^\-\-\-/o );
265 my ( $name, $n, $evalue, $score ) =
266 ( shift @line, pop @line, pop @line, pop @line );
267 my $desc = join( ' ', @line );
268 push @hitinfo, [ $name, $desc, $evalue, $score ];
269 $hitinfo{$name} = $#hitinfo;
272 elsif (/^Parsed for domains:/o) {
275 while ( defined( $_ = $self->_readline ) ) {
278 $self->_pushback($_);
281 next if ( /^(Model|Sequence)\s+Domain/ || /^\-\-\-/ );
285 my ( $n, $domainnum, $domainct, @vals ) = (
286 m
!^(\S
+)\s
+ # host name
287 (\d
+)/(\d+)\s+ # num/num
(ie
1 of
2)
288 (\d
+)\s
+(\d
+).+?
# sequence start and end
289 (\d
+)\s
+(\d
+)\s
+ # hmm start and end
298 # array lookup so that we can get rid of things
299 # when they've been processed
300 my $info = $hitinfo[ $hitinfo{$n} ];
301 if ( !defined $info ) {
303 "Incomplete Sequence information, can't find $n hitinfo says $hitinfo{$n}"
307 push @hspinfo, [ $n, @vals ];
311 elsif (/^Alignments of top/o) {
312 my ( $prelength, $lastdomain, $count, $width );
316 while ( defined( $_ = $self->_readline ) ) {
318 || /^\s+RF\s+[x\s]+$/o );
319 if ( /^Histogram/o || m!^//!o ) {
320 if ( $self->in_element('hsp') ) {
321 $self->end_element( { 'Name' => 'Hsp' } );
323 if ( $self->within_element('hit') ) {
324 $self->end_element( { 'Name' => 'Hit' } );
331 m
/^\s
*(.+):\s
+domain\s
+(\d
+)\s
+of\s
+(\d
+)\
,\s
+
332 from\s
+(\d
+)\s
+to\s
+(\d
+)/x
335 my ( $name, $domainct, $domaintotal, $from, $to ) =
336 ( $1, $2, $3, $4, $5 );
337 $domaincounter{$name}++;
338 if ( $self->within_element('hit') ) {
339 if ( $self->within_element('hsp') ) {
340 $self->end_element( { 'Name' => 'Hsp' } );
342 $self->end_element( { 'Name' => 'Hit' } );
345 $self->start_element( { 'Name' => 'Hit' } );
348 $hitinfo[ $hitinfo{$name} ] || $self->throw(
349 "Could not find hit info for $name: Insure that your database contains only unique sequence names"
353 if ( $info->[0] ne $name ) {
355 "Somehow the Model table order does not match the order in the domains (got "
357 . ", expected $name)" );
362 'Data' => shift @
{$info}
367 'Name' => 'Hit_desc',
368 'Data' => shift @
{$info}
373 'Name' => 'Hit_signif',
374 'Data' => shift @
{$info}
379 'Name' => 'Hit_score',
380 'Data' => shift @
{$info}
384 $self->start_element( { 'Name' => 'Hsp' } );
387 'Name' => 'Hsp_identity',
393 'Name' => 'Hsp_positive',
397 my $HSPinfo = shift @hspinfo;
398 my $id = shift @
$HSPinfo;
400 if ( $id ne $name ) {
402 "Somehow the domain list details do not match the table (got $id, expected $name)"
405 if ( $domaincounter{$name} == $domaintotal ) {
406 $hitinfo[ $hitinfo{$name} ] = undef;
410 'Name' => 'Hsp_hit-from',
411 'Data' => shift @
$HSPinfo
416 'Name' => 'Hsp_hit-to',
417 'Data' => shift @
$HSPinfo
422 'Name' => 'Hsp_query-from',
423 'Data' => shift @
$HSPinfo
428 'Name' => 'Hsp_query-to',
429 'Data' => shift @
$HSPinfo
434 'Name' => 'Hsp_score',
435 'Data' => shift @
$HSPinfo
440 'Name' => 'Hsp_evalue',
441 'Data' => shift @
$HSPinfo
448 # Might want to change this so that it
449 # accumulates all the of the alignment lines into
450 # three array slots and then tests for the
452 if (/^(\s+\*\-\>)(\S+)/o) { # start of domain
453 $prelength = CORE
::length($1);
456 # deal with fact that start en stop is on same line
458 if ($data =~ s/\<\-?\*?\s*$//)
460 $width = CORE
::length($data);
465 'Name' => 'Hsp_qseq',
472 elsif (/^(\s+)(\S+)\<\-\*\s*$/o) { #end of domain
475 'Name' => 'Hsp_qseq',
479 $width = CORE
::length($2);
482 elsif (( $count != 1 && /^\s+$/o )
483 || CORE
::length($_) == 0
488 elsif ( $count == 0 ) {
489 $prelength -= 3 unless ( $second_tier++ );
490 unless ( defined $prelength ) {
492 # $self->warn("prelength not set");
497 'Name' => 'Hsp_qseq',
498 'Data' => substr( $_, $prelength )
502 elsif ( $count == 1 ) {
503 if ( !defined $prelength ) {
504 $self->warn("prelength not set");
509 'Name' => 'Hsp_midline',
511 substr( $_, $prelength, $width )
518 'Name' => 'Hsp_midline',
519 'Data' => substr( $_, $prelength )
524 elsif ( $count == 2 ) {
525 if (/^\s+(\S+)\s+(\d+|\-)\s+(\S*)\s+(\d+|\-)/o) {
528 'Name' => 'Hsp_hseq',
534 $self->warn("unrecognized line: $_\n");
537 $count = 0 if $count++ >= 2;
541 elsif ( /^Histogram/o || m!^//!o ) {
542 while ( my $HSPinfo = shift @hspinfo ) {
543 my $id = shift @
$HSPinfo;
544 my $info = [ @
{ $hitinfo[ $hitinfo{$id} ] } ];
545 next unless defined $info;
546 $self->start_element( { 'Name' => 'Hit' } );
550 'Data' => shift @
{$info}
555 'Name' => 'Hit_desc',
556 'Data' => shift @
{$info}
561 'Name' => 'Hit_signif',
562 'Data' => shift @
{$info}
567 'Name' => 'Hit_score',
568 'Data' => shift @
{$info}
571 $self->start_element( { 'Name' => 'Hsp' } );
574 'Name' => 'Hsp_query-from',
575 'Data' => shift @
$HSPinfo
580 'Name' => 'Hsp_query-to',
581 'Data' => shift @
$HSPinfo
586 'Name' => 'Hsp_hit-from',
587 'Data' => shift @
$HSPinfo
592 'Name' => 'Hsp_hit-to',
593 'Data' => shift @
$HSPinfo
598 'Name' => 'Hsp_score',
599 'Data' => shift @
$HSPinfo
604 'Name' => 'Hsp_evalue',
605 'Data' => shift @
$HSPinfo
610 'Name' => 'Hsp_identity',
616 'Name' => 'Hsp_positive',
622 'Name' => 'Hsp_positive',
626 $self->end_element( { 'Name' => 'Hsp' } );
627 $self->end_element( { 'Name' => 'Hit' } );
634 elsif ( defined $self->{'_reporttype'}
635 && $self->{'_reporttype'} eq 'HMMPFAM' )
637 # process HMMPFAM results here
638 if (/^Scores for sequence family/o) {
639 while ( defined( $_ = $self->_readline ) ) {
641 next if ( /^Model\s+Description/o || /^\-\-\-/o );
644 my ( $model, $n, $evalue, $score ) =
645 ( shift @line, pop @line, pop @line, pop @line );
646 my $desc = join( ' ', @line );
647 push @hitinfo, [ $model, $desc, $score, $evalue, $n ];
648 $hitinfo{$model} = $#hitinfo;
651 elsif (/^Parsed for domains:/o) {
653 while ( defined( $_ = $self->_readline ) ) {
656 $self->_pushback($_);
659 next if ( /^Model\s+Domain/o || /^\-\-\-/o );
662 my ( $n, $domainnum, $domainct, @vals ) = (
663 m
!^(\S
+)\s
+ # domain name
664 (\d
+)/(\d
+)\s
+ # domain num out of num
665 (\d
+)\s
+(\d
+).+?
# seq start, end
666 (\d
+)\s
+(\d
+)\s
+ # hmm start, end
674 my $hindex = $hitinfo{$n};
675 if ( !defined $hindex ) {
677 [ $n, '', $vals[5], $vals[6], $domainct ];
678 $hitinfo{$n} = $#hitinfo;
681 my $info = $hitinfo[$hindex];
682 if ( !defined $info ) {
684 "incomplete Domain information, can't find $n hitinfo says $hitinfo{$n}"
688 push @hspinfo, [ $n, @vals ];
692 elsif (/^Alignments of top/o) {
693 my ( $prelength, $lastdomain, $count, $width );
696 while ( defined( $_ = $self->_readline ) ) {
701 && /^\s+RF\s+[x\s]+$/o )
704 next if ($_ =~ m/^\s+CS\s+/o && $count == 0);
705 if ( /^Histogram/o || m!^//!o || /^Query sequence/o ) {
706 if ( $self->in_element('hsp') ) {
707 $self->end_element( { 'Name' => 'Hsp' } );
709 if ( $self->in_element('hit') ) {
710 $self->end_element( { 'Name' => 'Hit' } );
712 $self->_pushback($_);
716 if (m/(\S+):.*from\s+(\d+)\s+to\s+(\d+)/o) {
717 my ( $name, $from, $to ) = ( $1, $2, $3 );
719 if ( $self->within_element('hit') ) {
720 if ( $self->in_element('hsp') ) {
721 $self->end_element( { 'Name' => 'Hsp' } );
723 $self->end_element( { 'Name' => 'Hit' } );
725 my $info = [ @
{ $hitinfo[ $hitinfo{$name} ] } ];
727 || $info->[0] ne $name )
730 "Somehow the Model table order does not match the order in the domains (got "
732 . ", expected $name). We're back loading this from the alignment information instead"
736 /score\s+([^,\s]+),\s+E\s+=\s+(\S+)/ox
738 push @hitinfo, $info;
739 $hitinfo{$name} = $#hitinfo;
741 $self->start_element( { 'Name' => 'Hit' } );
746 'Data' => shift @
{$info}
751 'Name' => 'Hit_desc',
752 'Data' => shift @
{$info}
757 'Name' => 'Hit_score',
758 'Data' => shift @
{$info}
763 'Name' => 'Hit_signif',
764 'Data' => shift @
{$info}
768 $self->start_element( { 'Name' => 'Hsp' } );
771 'Name' => 'Hsp_identity',
777 'Name' => 'Hsp_positive',
781 my $HSPinfo = shift @hspinfo;
782 my $id = shift @
$HSPinfo;
784 if ( $id ne $name ) {
786 "Somehow the domain list details do not match the table (got $id, expected $name)"
791 'Name' => 'Hsp_query-from',
792 'Data' => shift @
$HSPinfo
797 'Name' => 'Hsp_query-to',
798 'Data' => shift @
$HSPinfo
803 'Name' => 'Hsp_hit-from',
804 'Data' => shift @
$HSPinfo
809 'Name' => 'Hsp_hit-to',
810 'Data' => shift @
$HSPinfo
815 'Name' => 'Hsp_score',
816 'Data' => shift @
$HSPinfo
821 'Name' => 'Hsp_evalue',
822 'Data' => shift @
$HSPinfo
828 if (/^(\s+\*\-\>)(\S+)/o) {
831 $prelength = CORE
::length($1);
834 # deal with fact that start en stop is on same line
836 if ($data =~ s/\<\-?\*?\s*$//)
838 $width = CORE
::length($data);
843 'Name' => 'Hsp_hseq',
851 elsif (/^(\s+)(\S+)\<\-?\*?\s*$/o) {
854 $prelength -= 3 unless ( $second_tier++ );
857 'Name' => 'Hsp_hseq',
861 $width = CORE
::length($2);
864 elsif (CORE
::length($_) == 0
865 || ( $count != 1 && /^\s+$/o )
867 || /^\s+\S+\s+\-\s+\-\s*$/ )
871 elsif ( $count == 0 ) {
872 $prelength -= 3 unless ( $second_tier++ );
873 unless ( defined $prelength ) {
875 # $self->warn("prelength not set");
880 'Name' => 'Hsp_hseq',
881 'Data' => substr( $_, $prelength )
885 elsif ( $count == 1 ) {
886 if ( !defined $prelength ) {
887 $self->warn("prelength not set");
892 'Name' => 'Hsp_midline',
894 substr( $_, $prelength, $width )
901 'Name' => 'Hsp_midline',
902 'Data' => substr( $_, $prelength )
907 elsif ( $count == 2 ) {
908 if ( /^\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+)/o
909 || /^\s+(\S+)\s+(\-)\s+(\S*)\s+(\-)/o )
913 'Name' => 'Hsp_qseq',
920 "unrecognized line ($count): $_\n");
923 $count = 0 if $count++ >= 2;
927 elsif ( /^Histogram/o || m!^//!o ) {
929 while ( my $HSPinfo = shift @hspinfo ) {
930 my $id = shift @
$HSPinfo;
931 my $info = [ @
{ $hitinfo[ $hitinfo{$id} ] } ];
932 next unless defined $info;
933 $self->start_element( { 'Name' => 'Hit' } );
937 'Data' => shift @
{$info}
942 'Name' => 'Hit_desc',
943 'Data' => shift @
{$info}
948 'Name' => 'Hit_signif',
949 'Data' => shift @
{$info}
954 'Name' => 'Hit_score',
955 'Data' => shift @
{$info}
958 $self->start_element( { 'Name' => 'Hsp' } );
961 'Name' => 'Hsp_query-from',
962 'Data' => shift @
$HSPinfo
967 'Name' => 'Hsp_query-to',
968 'Data' => shift @
$HSPinfo
973 'Name' => 'Hsp_hit-from',
974 'Data' => shift @
$HSPinfo
979 'Name' => 'Hsp_hit-to',
980 'Data' => shift @
$HSPinfo
985 'Name' => 'Hsp_score',
986 'Data' => shift @
$HSPinfo
991 'Name' => 'Hsp_evalue',
992 'Data' => shift @
$HSPinfo
997 'Name' => 'Hsp_identity',
1003 'Name' => 'Hsp_positive',
1009 'Name' => 'Hsp_positive',
1013 $self->end_element( { 'Name' => 'Hsp' } );
1014 $self->end_element( { 'Name' => 'Hit' } );
1020 # uncomment to see missed lines with verbose on
1027 $self->end_element( { 'Name' => 'HMMER_Output' } ) unless !$seentop;
1028 return $self->end_document();
1031 =head2 start_element
1033 Title : start_element
1034 Usage : $eventgenerator->start_element
1035 Function: Handles a start element event
1037 Args : hashref with at least 2 keys 'Data' and 'Name'
1043 my ( $self, $data ) = @_;
1045 # we currently don't care about attributes
1046 my $nm = $data->{'Name'};
1047 my $type = $MODEMAP{$nm};
1049 if ( $self->_eventHandler->will_handle($type) ) {
1050 my $func = sprintf( "start_%s", lc $type );
1051 $self->_eventHandler->$func( $data->{'Attributes'} );
1053 unshift @
{ $self->{'_elements'} }, $type;
1056 && $type eq 'result' )
1058 $self->{'_values'} = {};
1059 $self->{'_result'} = undef;
1065 Title : start_element
1066 Usage : $eventgenerator->end_element
1067 Function: Handles an end element event
1069 Args : hashref with at least 2 keys 'Data' and 'Name'
1075 my ( $self, $data ) = @_;
1076 my $nm = $data->{'Name'};
1077 my $type = $MODEMAP{$nm};
1080 if ( $nm eq 'HMMER_program' ) {
1081 if ( $self->{'_last_data'} =~ /(HMM\S+)/i ) {
1082 $self->{'_reporttype'} = uc $1;
1086 # Hsp are sort of weird, in that they end when another
1087 # object begins so have to detect this in end_element for now
1088 if ( $nm eq 'Hsp' ) {
1089 foreach (qw(Hsp_qseq Hsp_midline Hsp_hseq)) {
1090 my $data = $self->{'_last_hspdata'}->{$_};
1091 if ($data && $_ eq 'Hsp_hseq') {
1092 # replace hmm '.' gap symbol by '-'
1102 $self->{'_last_hspdata'} = {};
1105 if ( $self->_eventHandler->will_handle($type) ) {
1106 my $func = sprintf( "end_%s", lc $type );
1107 $rc = $self->_eventHandler->$func( $self->{'_reporttype'},
1108 $self->{'_values'} );
1110 my $lastelem = shift @
{ $self->{'_elements'} };
1112 elsif ( $MAPPING{$nm} ) {
1113 if ( ref( $MAPPING{$nm} ) =~ /hash/i ) {
1114 my $key = ( keys %{ $MAPPING{$nm} } )[0];
1115 $self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } =
1116 $self->{'_last_data'};
1119 $self->{'_values'}->{ $MAPPING{$nm} } = $self->{'_last_data'};
1123 $self->debug("unknown nm $nm, ignoring\n");
1125 $self->{'_last_data'} = ''; # remove read data if we are at
1127 $self->{'_result'} = $rc if ( defined $type && $type eq 'result' );
1134 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
1135 Function: Convience method that calls start_element, characters, end_element
1137 Args : Hash ref with the keys 'Name' and 'Data'
1143 my ( $self, $data ) = @_;
1144 $self->start_element($data);
1145 $self->characters($data);
1146 $self->end_element($data);
1152 Usage : $eventgenerator->characters($str)
1153 Function: Send a character events
1161 my ( $self, $data ) = @_;
1163 if ( $self->in_element('hsp')
1164 && $data->{'Name'} =~ /Hsp\_(qseq|hseq|midline)/o
1165 && defined $data->{'Data'} )
1167 $self->{'_last_hspdata'}->{ $data->{'Name'} } .= $data->{'Data'};
1169 return unless ( defined $data->{'Data'} && $data->{'Data'} !~ /^\s+$/o );
1171 $self->{'_last_data'} = $data->{'Data'};
1174 =head2 within_element
1176 Title : within_element
1177 Usage : if( $eventgenerator->within_element($element) ) {}
1178 Function: Test if we are within a particular element
1179 This is different than 'in' because within can be tested
1182 Args : string element name
1187 sub within_element
{
1188 my ( $self, $name ) = @_;
1191 || !defined $self->{'_elements'}
1192 || scalar @
{ $self->{'_elements'} } == 0 );
1193 foreach ( @
{ $self->{'_elements'} } ) {
1194 return 1 if ( $_ eq $name );
1202 Usage : if( $eventgenerator->in_element($element) ) {}
1203 Function: Test if we are in a particular element
1204 This is different than 'within' because 'in' only
1205 tests its immediete parent.
1207 Args : string element name
1213 my ( $self, $name ) = @_;
1214 return 0 if !defined $self->{'_elements'}->[0];
1215 return ( $self->{'_elements'}->[0] eq $name );
1218 =head2 start_document
1220 Title : start_document
1221 Usage : $eventgenerator->start_document
1222 Function: Handle a start document event
1229 sub start_document
{
1231 $self->{'_lasttype'} = '';
1232 $self->{'_values'} = {};
1233 $self->{'_result'} = undef;
1234 $self->{'_elements'} = [];
1239 Title : end_document
1240 Usage : $eventgenerator->end_document
1241 Function: Handles an end document event
1242 Returns : Bio::Search::Result::ResultI object
1250 return $self->{'_result'};
1255 Title : result_count
1256 Usage : my $count = $searchio->result_count
1257 Function: Returns the number of results we have processed
1266 return $self->{'_result_count'};