~ubuntu-branches/ubuntu/lucid/bioperl/lucid

« back to all changes in this revision

Viewing changes to examples/searchio/writer/hspwriter.pl

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env perl 
2
 
 
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.
5
 
#
6
 
# Usage:
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.
11
 
#
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.
18
 
#
19
 
# For more documentation about the writer, including
20
 
# a complete list of columns, execute:
21
 
#   perldoc Bio::SearchIO::Writer::HSPTableWriter.
22
 
#
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
28
 
#
29
 
# For more documentation about the PSI-Blast parser, see docs for
30
 
#   Bio::SearchIO::psiblast
31
 
#
32
 
# Author: Steve Chervitz <sac@bioperl.org>
33
 
# Revision: $Id: hspwriter.pl,v 1.2 2002/01/11 08:05:42 sac Exp $
34
 
 
35
 
use strict;
36
 
use lib '../../../';
37
 
 
38
 
use Bio::SearchIO;
39
 
use Bio::SearchIO::Writer::HSPTableWriter;
40
 
 
41
 
# These are the columns that will be in the output table of BLAST results.
42
 
my @columns = qw(
43
 
                 query_name
44
 
                 query_length
45
 
                 hit_name
46
 
                 hit_length
47
 
                 rank
48
 
                 expect
49
 
                 frac_identical_query
50
 
                 length_aln_query
51
 
                 gaps_total
52
 
                 strand_query
53
 
                 strand_hit
54
 
                );
55
 
 
56
 
 
57
 
print STDERR "\nUsing SearchIO->new()\n";
58
 
 
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', 
65
 
                                 -writer => $writer,
66
 
                                 -file   => ">hspwriter.out" );
67
 
 
68
 
while ( my $result = $in->next_result() ) {
69
 
  printf STDERR "\nReport %d: $result\n", $in->report_count;
70
 
  
71
 
  if( $result->hits ) {
72
 
    $out->write_result($result, ($in->report_count - 1 ? 0 : 1) );
73
 
  }
74
 
  else {
75
 
    print STDERR "Hitless Blast Report: $result ";
76
 
    print STDERR ($result->no_hits_found ? "\n" : "(filtered)\n");
77
 
  }
78
 
  
79
 
  ## For a simple progress monitor, uncomment this line:
80
 
  #print STDERR "."; print STDERR "\n" if $in->report_count % 50 == 0;
81
 
}
82
 
 
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;
85