Bio::DB::Universal: move into its own distribution
[bioperl-live.git] / examples / searchio / psiblast_iterations.pl
blob39734d1a3cee5366db337b38e98c428a68c9067b
1 #!/usr/bin/perl
3 # Demonstrates the use of a SearchIO parser for processing
4 # the iterations within a PSI-BLAST report.
6 # Usage:
7 # STDIN: none; supply filename of PSI-BLAST report on command-line
8 # STDOUT: information parsed from the input data.
9 # STDERR: errors.
11 # For more documentation about working with Iteration objects,
12 # see docs for:
13 # Bio::Search::Iteration::IterationI
15 # Author: Steve Chervitz <sac@bioperl.org>
17 use strict;
18 use lib '../../';
20 use Bio::SearchIO;
22 my $file = shift or die "Usage: $0 <BLAST-report-file>\n";
23 my $in = new Bio::SearchIO(-format => 'blast',
24 -file => $file, #comment this out to read STDIN
25 #-fh => \*ARGV, #uncomment this to read STDIN
28 # Iterate over all results in the input stream
29 while (my $result = $in->next_result) {
31 printf "Result #%d: %s\n", $in->result_count, $result->to_string;
32 printf "Total Iterations: %d\n", $result->num_iterations();
34 # Iterate over all iterations and process old and new hits
35 # separately.
37 while( my $it = $result->next_iteration) {
38 printf "\nIteration %d\n", $it->number;
39 printf "Converged: %d\n", $it->converged;
41 # Print out the hits not found in previous iteration
42 printf "New hits: %d\n", $it->num_hits_new;
43 while( my $hit = $it->next_hit_new ) {
44 printf " %s, Expect=%g\n", $hit->name, $hit->expect;
47 # Print out the hits found in previous iteration
48 printf "Old hits: %d\n", $it->num_hits_old;
49 while( my $hit = $it->next_hit_old ) {
50 printf " %s, Expect=%g\n", $hit->name, $hit->expect;
53 printf "%s\n\n", '-' x 50;
56 printf "Total Reports processed: %d: %s\n", $in->result_count;
58 __END__
60 # NOTE: The following functionality is just proposed
61 # (does not yet exist but might, given sufficient hew and cry):
63 # Zero-in on the new hits found in last iteration.
64 # By default, iteration() returns the last one.
66 my $last_iteration = $result->iteration();
67 while( my $hit = $last_iteration->next_hit) {
68 # Do something with new hit...
71 # Get the first iteration
73 my $first_iteration = $result->iteration(1);