maint: remove hard tabs and trailing whitespace
[bioperl-live.git] / examples / searchio / resultwriter.pl
blob2033a9ffd66a395ba40a74f2e7f17eabd677a831
1 #!/usr/bin/perl
3 # Demonstrates the use of a SearchIO Blast parser and a SearchWriterI object
4 # for producing tab-delimited output of result data from a Blast report
5 # input stream.
7 # This writer only outputs information at the level of the result object.
8 # This shows that you can work with a writer that only knows about
9 # Bio::Search::Result objects and doesn't care about hit or HSP data.
10 # Therefore, the output from this example doesn't contain any information
11 # about hits or HSPs.
12 # See the hitwriter.pl and hspwriter.pl examples for that.
14 # This parser represents a new and improved version of Bio::Tools::Blast.
16 # Usage:
17 # STDIN: stream containing one or more BLAST or PSI-BLAST reports.
18 # STDOUT: none, but generates an output file "resultwriter.out"
19 # containing tab-delimited data on a per-report basis.
20 # STDERR: Any errors that occurred.
22 # For more documentation about the writer, including
23 # a complete list of columns, see the docs for
24 # Bio::SearchIO::Writer::ResultTableWriter.
26 # For more documentation about working with Blast result objects,
27 # see docs for these modules:
28 # Bio::Search::Result::BlastResult
29 # Bio::Search::Iteration::IterationI
30 # Bio::Search::Hit::BlastHit
31 # Bio::Search::HSP::BlastHSP
33 # For more documentation about the Blast parser, see docs for
34 # Bio::SearchIO
36 # Author: Steve Chervitz <sac@bioperl.org>
39 use strict;
40 use lib '../../';
42 use Bio::SearchIO;
43 use Bio::SearchIO::Writer::ResultTableWriter;
44 use Bio::SearchIO::Writer::HTMLResultWriter;
46 print "\nUsing SearchIO->new()\n";
49 # Note that all parameters for the $in, $out, and $writer objects are optional.
50 # Default in = STDIN; Default out = STDOUT; Default writer = all columns
51 # In this example, we're reading from STDIN and writing to STDOUT
52 # and using the default columns for the writer.
53 # We're also telling the script to timeout if input isn't received
54 # within 10 sec. (Note the clock is still ticking when you background the job.)
55 # Setting verbose to 1 is useful for debugging.
56 my $in = Bio::SearchIO->new( -format => 'blast',
57 -fh => \*ARGV,
58 -signif => 0.1,
59 -verbose => 0,
60 -timeout_sec => 10 );
61 # not specifying any columns to get the default.
62 my $writer = Bio::SearchIO::Writer::ResultTableWriter->new();
63 my $out = Bio::SearchIO->new( -format => 'blast',
64 -writer => $writer,
65 -file => ">resultwriter.out");
67 my $writerhtml = new Bio::SearchIO::Writer::HTMLResultWriter();
68 my $outhtml = new Bio::SearchIO(-writer => $writerhtml,
69 -file => ">searchio.html");
72 while ( my $result = $in->next_result() ) {
73 eval {
74 # printf STDERR "Report %d: $result\n", $in->result_count;
75 $out->write_result($result, ($in->result_count - 1 ? 0 : 1) );
77 $outhtml->write_result($result, 1);
79 # To get at the statistical parameters:
80 # Calling raw_statistics() returns a list containing the
81 # unparsed lines of the parameters section of the report.
82 # Here we're only interested in parameters beginning with "effective".
83 # print "Report Stats, effective data:\n";
84 # foreach( $result->raw_statistics) {
85 # print "$_" if /^effective/i;
86 # }
88 ## For a simple progress monitor, uncomment this line:
89 #print STDERR "."; print STDERR "\n" if $in->result_count % 50 == 0;
91 if($@) {
92 warn "Warning: Blast parsing or writing exception caught for $result:\n$@\n";
96 printf STDERR "\n%d Blast report(s) processed.\n", $in->result_count;
97 printf STDERR "Output sent to file: %s\n", $out->file if $out->file;