| Summary | Included libraries | Package variables | Synopsis | Description | General documentation | Methods |
use Bio::SearchIO;
my $searchin = new Bio::SearchIO(-format => 'blastxml',
-file => 't/data/plague_yeast.bls.xml');
while( my $result = $searchin->next_result ) {
}
# one can also request that the parser NOT keep the XML data in memory
# by using the tempfile initialization flag.
my $searchin = new Bio::SearchIO(-tempfile => 1,
-format => 'blastxml',
-file => 't/data/plague_yeast.bls.xml');
while( my $result = $searchin->next_result ) {
}
| BEGIN | Code | |
| _initialize | Description | Code |
| next_result | Description | Code |
| start_document | Description | Code |
| end_document | Description | Code |
| start_element | Description | Code |
| end_element | Description | Code |
| characters | Description | Code |
| use_tempfile | Description | Code |
| _initialize | code | next | Top |
Title : _initialize Usage : private Function: Initializes the object - this is chained through new in SearchIO |
| next_result | code | prev | next | Top |
Title : next_result Usage : my $hit = $searchio->next_result; Function: Returns the next Result from a search Returns : Bio::Search::Result::ResultI object Args : none |
| start_document | code | prev | next | Top |
Title : start_document Usage : $parser->start_document; Function: SAX method to indicate starting to parse a new document Returns : none Args : none |
| end_document | code | prev | next | Top |
Title : end_document Usage : $parser->end_document; Function: SAX method to indicate finishing parsing a new document Returns : Bio::Search::Result::ResultI object Args : none |
| start_element | code | prev | next | Top |
Title : start_element Usage : $parser->start_element($data) Function: SAX method to indicate starting a new element Returns : none Args : hash ref for data |
| end_element | code | prev | next | Top |
Title : end_element Usage : $parser->end_element($data) Function: Signals finishing an element Returns : Bio::Search object dpending on what type of element Args : hash ref for data |
| characters | code | prev | next | Top |
Title : characters Usage : $parser->characters($data) Function: Signals new characters to be processed Returns : characters read Args : hash ref with the key 'Data' |
| use_tempfile | code | prev | next | Top |
Title : use_tempfile Usage : $obj->use_tempfile($newval) Function: Get/Set boolean flag on whether or not use a tempfile Example : Returns : value of use_tempfile Args : newvalue (optional) |
| BEGIN | Top |
# mapping of NCBI Blast terms to Bioperl hash keys}
%MODEMAP = ('BlastOutput' => 'result', 'Hit' => 'hit', 'Hsp' => 'hsp' ); %MAPPING = ( # HSP specific fields
'Hsp_bit-score' => 'bits', 'Hsp_score' => 'score', 'Hsp_evalue' => 'evalue', 'Hsp_query-from'=> 'querystart', 'Hsp_query-to' => 'queryend', 'Hsp_hit-from' => 'hitstart', 'Hsp_hit-to' => 'hitend', 'Hsp_positive' => 'conserved', 'Hsp_identity' => 'identical', 'Hsp_gaps' => 'gaps', 'Hsp_hitgaps' => 'hitgaps', 'Hsp_querygaps' => 'querygaps', 'Hsp_qseq' => 'queryseq', 'Hsp_hseq' => 'hitseq', 'Hsp_midline' => 'homolseq', 'Hsp_align-len' => 'hsplen', 'Hsp_query-frame'=> 'queryframe', 'Hsp_hit-frame' => 'hitframe', # these are ignored for now
'Hsp_num' => 'hsporder', 'Hsp_pattern-from' => 'patternend', 'Hsp_pattern-to' => 'patternstart', 'Hsp_density' => 'hspdensity', # Hit specific fields
'Hit_id' => 'hitname', 'Hit_len' => 'hitlen', 'Hit_accession' => 'hitacc', 'Hit_def' => 'hitdesc', 'Hit_num' => 'hitorder', 'BlastOutput_program' => 'programname', 'BlastOutput_version' => 'programver', 'BlastOutput_query-def'=> 'queryname', 'BlastOutput_query-len'=> 'querylen', 'BlastOutput_db' => 'dbname', 'BlastOutput_reference' => 'programref', 'BlastOutput_query-ID' => 'runid', 'Iteration_iter-num' => 'iternum', 'Iteration_stat' => 'iterstat', 'Parameters_matrix' => { 'param' => 'matrix'}, 'Parameters_expect' => { 'param' => 'expect'}, 'Parameters_include' => { 'param' => 'include'}, 'Parameters_sc-match' => { 'param' => 'match'}, 'Parameters_sc-mismatch' => { 'param' => 'mismatch'}, 'Parameters_gap-open' => { 'param' => 'gapopen'}, 'Parameters_gap-extend'=> { 'param' => 'gapext'}, 'Parameters_filter' => {'param' => 'filter'}, 'Statistics_db-num' => 'dbsize', 'Statistics_db-len' => 'dblets', 'Statistics_hsp-len' => { 'stat' => 'hsplength'}, 'Statistics_eff-space' => { 'stat' => 'effectivespace'}, 'Statistics_kappa' => { 'stat' => 'kappa' }, 'Statistics_lambda' => { 'stat' => 'lambda' }, 'Statistics_entropy' => { 'stat' => 'entropy'}, ); eval { require Time::HiRes }; if( $@ ) { $DEBUG = 0;
| _initialize | description | prev | next | Top |
my ($self,@args) = @_; $self->SUPER::_initialize(@args); my ($usetempfile) = $self->_rearrange([qw(TEMPFILE)],@args); defined $usetempfile && $self->use_tempfile($usetempfile); $self->{'_xmlparser'} = new XML::Parser::PerlSAX(); $DEBUG = 1 if( ! defined $DEBUG && $self->verbose > 0);}
| next_result | description | prev | next | Top |
my ($self) = @_; my $data = ''; my $firstline = 1; my ($tfh); if( $self->use_tempfile ) { $tfh = IO::File->new_tmpfile or $self->throw("Unable to open temp file: $!"); $tfh->autoflush(1); } my $okaytoprocess; while( defined( $_ = $self->_readline) ) { if( /^RPS-BLAST/i ) { $self->{'_type'} = 'RPSBLAST'; next; } if( /^<\?xml version/ && ! $firstline) { $self->_pushback($_); last; } s/\'/\`/g; s/\>/\>/g; s/\</\</g; $okaytoprocess = 1; if( defined $tfh ) { print $tfh $_; } else { $data .= $_; } $firstline = 0; } return undef unless( $okaytoprocess); my %parser_args; if( defined $tfh ) { seek($tfh,0,0); %parser_args = ('Source' => { 'ByteStream' => $tfh }, 'Handler' => $self); } else { %parser_args = ('Source' => { 'String' => $data }, 'Handler' => $self); } my $result; my $starttime; if( $DEBUG ) { $starttime = [ Time::HiRes::gettimeofday() ]; } eval { $result = $self->{'_xmlparser'}->parse(%parser_args); }; if( $@ ) { $self->warn("error in parsing a report:\n $@"); $result = undef; } if( $DEBUG ) { $self->debug( sprintf("parsing took %f seconds\n", Time::HiRes::tv_interval($starttime))); } # parsing magic here - but we call event handlers rather than}
# instantiating things
return $result;
| start_document | description | prev | next | Top |
my ($self) = @_; $self->{'_lasttype'} = ''; $self->{'_values'} = {}; $self->{'_result'}= undef;}
| end_document | description | prev | next | Top |
my ($self,@args) = @_; return $self->{'_result'};}
| start_element | description | prev | next | Top |
my ($self,$data) = @_; # we currently don't care about attributes}
my $nm = $data->{'Name'}; if( my $type = $MODEMAP{$nm} ) { if( $self->_eventHandler->will_handle($type) ) { my $func = sprintf("start_%s",lc $type); $self->_eventHandler->$func($data->{'Attributes'}); } } if($nm eq 'BlastOutput') { $self->{'_values'} = {}; $self->{'_result'}= undef; }
| end_element | description | prev | next | Top |
my ($self,$data) = @_; my $nm = $data->{'Name'}; my $rc; if($nm eq 'BlastOutput_program' && $self->{'_last_data'} =~ /(t?blast[npx])/i ) { $self->{'_type'} = uc $1; } if( my $type = $MODEMAP{$nm} ) { if( $self->_eventHandler->will_handle($type) ) { my $func = sprintf("end_%s",lc $type); $rc = $self->_eventHandler->$func($self->{'_type'}, $self->{'_values'}); } } elsif( $MAPPING{$nm} ) { if ( ref($MAPPING{$nm}) =~ /hash/i ) { my $key = (keys %{$MAPPING{$nm}})[0]; $self->{'_values'}->{$key}->{$MAPPING{$nm}->{$key}} = $self->{'_last_data'}; } else { $self->{'_values'}->{$MAPPING{$nm}} = $self->{'_last_data'}; } } elsif( $nm eq 'Iteration' || $nm eq 'Hit_hsps' || $nm eq 'Parameters' || $nm eq 'BlastOutput_param' || $nm eq 'Iteration_hits' || $nm eq 'Statistics' || $nm eq 'BlastOutput_iterations' ){ } else { $self->debug("ignoring unrecognized element type $nm\n"); } $self->{'_last_data'} = ''; # remove read data if we are at}
# end of an element
$self->{'_result'} = $rc if( $nm eq 'BlastOutput' ); return $rc;
| characters | description | prev | next | Top |
my ($self,$data) = @_; return unless ( defined $data->{'Data'} && $data->{'Data'} !~ /^\s+$/ ); $self->{'_last_data'} = $data->{'Data'};}
| use_tempfile | description | prev | next | Top |
my ($self,$value) = @_; if( defined $value) { $self->{'_use_tempfile'} = $value; } return $self->{'_use_tempfile'};}
| FEEDBACK | Top |
| Mailing Lists | Top |
bioperl-l@bioperl.org - General discussion http://bioperl.org/MailList.shtml - About the mailing lists
| Reporting Bugs | Top |
bioperl-bugs@bioperl.org http://bioperl.org/bioperl-bugs/
| AUTHOR - Jason Stajich | Top |
| CONTRIBUTORS | Top |
| APPENDIX | Top |
| new | Top |
Title : new
Usage : my $searchio = new Bio::SearchIO(-format => 'blastxml',
-file => 'filename',
-tempfile => 1);
Function: Initializes the object - this is chained through new in SearchIO
Returns : Bio::SearchIO::blastxml object
Args : One additional argument from the format and file/fh parameters.
-tempfile => boolean. Defaults to false. Write out XML data
to a temporary filehandle to send to
PerlSAX parser.| SAX methods | Top |