Merge pull request #111 from adsj/master
[bioperl-live.git] / examples / searchio / rawwriter.pl
blob521cf7403f44a318b3bf10b38d6a8fc031aa4c43
1 #!/usr/bin/env perl
3 # Demonstrates the use of a SearchIO Blast parser for producing
4 # output of raw HSP data from a Blast report input stream.
6 # Shows how to print out raw BLAST alignment data for each HSP.
8 # Usage:
9 # STDIN: stream containing one or more BLAST or PSI-BLAST reports.
10 # STDOUT: Raw alignment data for each HSP of each hit (BLAST format)
11 # STDERR: Progress info and any errors.
13 # For more documentation about working with Blast result objects,
14 # see docs for these modules:
15 # Bio::Search::Result::BlastResult
16 # Bio::Search::Hit::BlastHit
17 # Bio::Search::HSP::BlastHSP
19 # For more documentation about the PSI-Blast parser, see docs for
20 # Bio::SearchIO::psiblast
22 # Author: Steve Chervitz <sac@bioperl.org>
24 # TODO:
25 # * Implement a Bio::SearchIO::Writer::HSPTextWriter object
26 # that can do this. Then this example can fit into the standard
27 # model used by the other writer examples in which a writer
28 # object is created and hooked up with a SearchIO output object.
30 use strict;
32 use lib '../../';
34 use Bio::SearchIO;
36 # In this case, we only want raw alignments, and we only need to screen
37 # on significance info (E- or P-value) so we don't need
38 # to do a full parse of the alignments. Thus, we're using a -shalow_parse
39 # flag to indicate that we don't need to parse alignments. This should
40 # result in faster processing.
41 # TODO: Convert this to use -format='blast'. Shallow-parse option not supported there.
42 my $in = Bio::SearchIO->new(-format => 'psiblast',
43 -fh => \*ARGV,
44 -signif => 0.1,
45 -shallow_parse => 1,
46 -hold_raw_data => 1 );
48 while ( my $result = $in->next_result() ) {
49 print STDERR "\nBLAST Results for $result\n\n";
50 my $count = 0;
51 foreach( $result->hits ) {
52 print "Alignment for hit #", ++$count, "\n\n";
53 print $_->raw_hit_data();
55 print "=" x 50 , "\n";
58 printf STDERR "\n%d Blast report(s) processed.\n", $in->result_count;