Bio-SearchIO-blastxml
view release on metacpan or search on metacpan
lib/Bio/SearchIO/blastxml.pm view on Meta::CPAN
}
return $self->{'_use_tempfile'};
}
sub blasttype{
my ($self,$value) = @_;
if ($value) {
$self->throw("$value is not a supported BLAST type") unless exists $VALID_TYPE{$value};
my $ok;
eval {
$ok = $self->_load_module($VALID_TYPE{$value});
};
if ($@) {
print STDERR <<END;
$self: data module $VALID_TYPE{$value} cannot be found
Exception $@
For more information about the Bio::SearchIO::blastxml system please see the Bio::SearchIO::blastxml.
END
return unless $ok;
}
# BlastHandler does the heavy lifting
my $xmlhandler = $VALID_TYPE{$value}->new(-verbose => $self->verbose);
# The XML handler does the heavy work, passes data to object handler
if ($value =~ /^PSI/) {
my $handler = Bio::SearchIO::IteratedSearchResultEventBuilder->new();
$self->{'_handler'} = $handler; # cache
}
$xmlhandler->eventHandler($self->_eventHandler());
# start up the parser factory
my $parserfactory = XML::SAX::ParserFactory->parser(
Handler => $xmlhandler);
$self->{'_xmlparser'} = $parserfactory;
$self->saxparser(ref($parserfactory));
$self->{'_blasttype'} = $value;
}
return $self->{'_blasttype'};
}
sub saxparser {
my $self = shift;
return ref($self->{'_xmlparser'});
}
sub _chunk_normalblast {
my ($self, $tfh) = @_;
local $/ = "\n";
local $_;
$self->{'_blastdata'} = '';
my ($sawxmlheader, $okaytoprocess);
my $mode = 'header';
my $tail = << 'XML_END';
</BlastOutput_iterations>
</BlastOutput>
XML_END
# no buffering needed (famous last words...)
my $fh = $self->_fh;
#chop up XML into edible bits for the parser
while( defined( my $line = <$fh>) ) {
next if $line =~ /^\s*$/;
next if $line =~ m{^\s*</BlastOutput_iterations>}xmso || $line =~ m{^</BlastOutput>}xmso;
if( $line =~ m{^RPS-BLAST}i ) {
$self->{'_type'} = 'RPS-BLAST';
next;
} elsif ($line =~ m{^<\?xml\sversion="1.0"}xms) {# <?xml version="1.0"?> & <?xml version="1.0" encoding="UTF-8"?>
delete $self->{'_header'} if exists $self->{'_header'};
$sawxmlheader++;
$mode = 'header';
} elsif ($line =~ m{^\s*<Iteration>}xmso) {
if (!$sawxmlheader) {
if (defined $tfh) {
print $tfh $self->{'_header'}
} else {
$self->{'_blastdata'} .= $self->{'_header'};
}
}
$mode = 'iteration';
} elsif ($line =~ m{^\s*</Iteration>}xmso) {
if (defined $tfh) {
print $tfh $line.$tail;
} else {
$self->{'_blastdata'} .= $line.$tail;
}
$okaytoprocess++;
last;
}
if (defined $tfh) {
print $tfh $line;
} else {
$self->{'_blastdata'} .= $line;
}
$self->{"_$mode"} .= $line if $mode eq 'header';
}
return $okaytoprocess;
}
sub _chunk_psiblast {
my ($self, $tfh) = @_;
local $/ = "\n";
local $_;
$self->{'_blastdata'} = '';
my ($sawxmlheader, $okaytoprocess);
# no buffering needed (famous last words...)
my $fh = $self->_fh;
#chop up XML into edible bits for the parser
while( defined( my $line = <$fh>) ) {
if (defined $tfh) {
print $tfh $line;
} else {
$self->{'_blastdata'} .= $line;
}
#$self->{"_$mode"} .= $line;
if ($line =~ m{^</BlastOutput>}xmso) {
$okaytoprocess++;
last;
}
}
( run in 0.484 second using v1.01-cache-2.11-cpan-71847e10f99 )