3
# Example usage of a SearchIO::psiblast parser of traditional format Blast reports.
4
# This parser represents a new and improved version of Bio/Tools/Blast.pm.
7
# STDIN: stream containing one or more BLAST or PSI-BLAST reports.
8
# STDOUT: none, but generates an output file "hspwriter.out"
9
# containing tab-delimited data on a per-HSP basis.
10
# STDERR: Progress info.
12
# In this example, we create a SearchIO parser that screens out hits
13
# based on expect (or P) scores and a default HSPTableWriter. This writer
14
# provides the same functionality as the original Bio::Tools::Blast::table2()
15
# function (i.e., a tab-delimited summary of each hit per row).
16
# HSPTableWriter, however, is customizable so you can specify just the columns
17
# you want to have in the output table.
19
# For more documentation about the writer, including
20
# a complete list of columns, execute:
21
# perldoc Bio::SearchIO::Writer::HSPTableWriter.
23
# For more documentation about working with Blast result objects,
24
# see docs for these modules:
25
# Bio::Search::Result::BlastResult
26
# Bio::Search::Hit::BlastHit
27
# Bio::Search::HSP::BlastHSP
29
# For more documentation about the PSI-Blast parser, see docs for
30
# Bio::SearchIO::psiblast
32
# Author: Steve Chervitz <sac@bioperl.org>
33
# Revision: $Id: hspwriter.pl,v 1.2 2002/01/11 08:05:42 sac Exp $
39
use Bio::SearchIO::Writer::HSPTableWriter;
41
# These are the columns that will be in the output table of BLAST results.
57
print STDERR "\nUsing SearchIO->new()\n";
59
# Note that all parameters for the $in, $out, and $writer objects are optional.
60
# Default in = STDIN; Default out = STDOUT; Default writer = all columns
61
# In this example, we're reading from STDIN and writing to a STDOUT
62
my $in = Bio::SearchIO->new( -format => 'psiblast' );
63
my $writer = Bio::SearchIO::Writer::HSPTableWriter->new( -columns => \@columns );
64
my $out = Bio::SearchIO->new( -format => 'psiblast',
66
-file => ">hspwriter.out" );
68
while ( my $result = $in->next_result() ) {
69
printf STDERR "\nReport %d: $result\n", $in->report_count;
72
$out->write_result($result, ($in->report_count - 1 ? 0 : 1) );
75
print STDERR "Hitless Blast Report: $result ";
76
print STDERR ($result->no_hits_found ? "\n" : "(filtered)\n");
79
## For a simple progress monitor, uncomment this line:
80
#print STDERR "."; print STDERR "\n" if $in->report_count % 50 == 0;
83
printf STDERR "\n%d Blast report(s) processed.\n", $in->report_count;
84
printf STDERR "Output sent to file: %s\n", $out->file if $out->file;