XML::Parser::PerlSAX required for these tests
[bioperl-live.git] / examples / searchio / htmlwriter.pl
blobdb715ca550deda91c6a81fa3f024d85e04990021
1 #!/usr/bin/perl
3 # Demonstrates the use of a SearchIO Blast parser and a SearchWriterI object
4 # for producing HTML Blast output from a Blast report input stream.
6 # Usage:
7 # STDIN: none; supply filename of BLAST report on command-line
8 # STDOUT: none; generates an output file "searchio.html"
9 # containing HTML-formatted Blast Report
10 # STDERR: Any errors that occurred.
12 # For more documentation about the writer, including
13 # a complete list of columns, see the docs for
14 # Bio::SearchIO::Writer::HTMLResultWriter.
16 # For more documentation about working with Blast result objects,
17 # see docs for these modules:
18 # Bio::Search::Result::BlastResult
19 # Bio::Search::Iteration::IterationI
20 # Bio::Search::Hit::BlastHit
21 # Bio::Search::HSP::BlastHSP
23 # For more documentation about the Blast parser, see docs for
24 # Bio::SearchIO
26 # Author: Steve Chervitz <sac@bioperl.org>
29 use strict;
30 use lib '../../';
32 use Bio::SearchIO;
33 use Bio::SearchIO::Writer::HTMLResultWriter;
35 my $outfile = "searchio.html";
36 my $file = shift or die "Usage: $0 <BLAST-report-file>\n HTML output is saved to $outfile\n";
38 my $in = Bio::SearchIO->new( -format => 'blast',
39 -file => $file, #comment this out to read STDIN
40 #-fh => \*ARGV, #uncomment this to read from STDIN
41 -verbose => 0 );
43 my $writer = new Bio::SearchIO::Writer::HTMLResultWriter();
44 my $out = new Bio::SearchIO(-writer => $writer,
45 -file => ">$outfile");
48 while ( my $result = $in->next_result() ) {
49 eval {
50 # printf STDERR "Report %d: $result\n", $in->result_count;
51 $out->write_result($result, 1);
53 if($@) {
54 warn "Warning: Blast parsing or writing exception caught for $result:\n$@\n";
58 printf STDERR "\n%d Blast report(s) processed.\n", $in->result_count;
59 printf STDERR "Output sent to file: %s\n", $out->file if $out->file;