Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 75 lines (56 sloc) 2.231 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#!/usr/bin/perl

# Demonstrates the use of a SearchIO parser for processing
# the iterations within a PSI-BLAST report.
#
# Usage:
# STDIN: none; supply filename of PSI-BLAST report on command-line
# STDOUT: information parsed from the input data.
# STDERR: errors.
#
# For more documentation about working with Iteration objects,
# see docs for:
# Bio::Search::Iteration::IterationI
#
# Author: Steve Chervitz <sac@bioperl.org>

use strict;
use lib '../../';

use Bio::SearchIO;

my $file = shift or die "Usage: $0 <BLAST-report-file>\n";
my $in = new Bio::SearchIO(-format => 'blast',
                           -file => $file, #comment this out to read STDIN
                           #-fh => \*ARGV, #uncomment this to read STDIN
                          );

# Iterate over all results in the input stream
while (my $result = $in->next_result) {

    printf "Result #%d: %s\n", $in->result_count, $result->to_string;
    printf "Total Iterations: %d\n", $result->num_iterations();

    # Iterate over all iterations and process old and new hits
    # separately.

    while( my $it = $result->next_iteration) {
        printf "\nIteration %d\n", $it->number;
        printf "Converged: %d\n", $it->converged;

        # Print out the hits not found in previous iteration
        printf "New hits: %d\n", $it->num_hits_new;
        while( my $hit = $it->next_hit_new ) {
            printf " %s, Expect=%g\n", $hit->name, $hit->expect;
        }

        # Print out the hits found in previous iteration
        printf "Old hits: %d\n", $it->num_hits_old;
        while( my $hit = $it->next_hit_old ) {
            printf " %s, Expect=%g\n", $hit->name, $hit->expect;
        }
    }
    printf "%s\n\n", '-' x 50;
}

printf "Total Reports processed: %d: %s\n", $in->result_count;

__END__

# NOTE: The following functionality is just proposed
# (does not yet exist but might, given sufficient hew and cry):

# Zero-in on the new hits found in last iteration.
# By default, iteration() returns the last one.

my $last_iteration = $result->iteration();
while( my $hit = $last_iteration->next_hit) {
# Do something with new hit...
}

# Get the first iteration

my $first_iteration = $result->iteration(1);

Something went wrong with that request. Please try again.