tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / scripts / searchio / search2table.PLS
blob6ebe60c88f1b924ebb5b2139ffe74c3e749a526a
1 #!/usr/bin/perl -w
3 =head1 NAME
5 search2table - turn SearchIO parseable reports into tab delimited format like NCBI's -m 9
7 =head1 SYNOPSIS
9 search2table -f fasta -i file.FASTA -o output.table
11 =head1 DESCRIPTION
13 Turn SearchIO reports into a tabular format like NCBI's -m 9 output.
15 =head1 FEEDBACK
17 =head2 Mailing Lists
19 User feedback is an integral part of the evolution of this and other
20 Bioperl modules. Send your comments and suggestions preferably to
21 the Bioperl mailing list. Your participation is much appreciated.
23 bioperl-l@bioperl.org - General discussion
24 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
26 =head2 Reporting Bugs
28 Report bugs to the Bioperl bug tracking system to help us keep track
29 of the bugs and their resolution. Bug reports can be submitted via
30 email or the web:
32 http://bugzilla.open-bio.org/
34 =head1 AUTHOR
36 Jason Stajich jason_at_bioperl-dot-org
38 =cut
40 use strict;
41 use Bio::SearchIO;
42 use Getopt::Long;
44 my ($format, $file,$output) = ('blast');
46 GetOptions(
47 'f|format:s' => \$format,
48 'i|input:s' => \$file,
49 'o|output:s' => \$output);
51 if( @ARGV ) {
52 $file = shift;
55 my $in = Bio::SearchIO->new(-format => $format,
56 -file => $file);
57 my $out;
58 if( $output ) {
59 open($out,">$output") || die "cannot open $output for writing";
60 } else {
61 $out = \*STDOUT;
64 while( my $r = $in->next_result ) {
65 while( my $hit = $r->next_hit ) {
66 while( my $hsp = $hit->next_hsp ) {
67 my $mismatchcount = $hsp->length('total') -
68 ($hsp->num_conserved + $hsp->gaps('total'));
69 print $out join("\t", ( $r->query_name,
70 $hit->name,
71 sprintf("%.2f",$hsp->percent_identity),
72 $hsp->length('total'),
73 $mismatchcount,
74 $hsp->gaps('total'),
75 # flip start/end on rev strand
76 $hsp->query->strand < 0 ?
77 ( $hsp->query->end,
78 $hsp->query->start ) :
79 ( $hsp->query->start,
80 $hsp->query->end ),
81 $hsp->hit->strand < 0 ?
82 ( $hsp->hit->end,
83 $hsp->hit->start ) :
84 ( $hsp->hit->start,
85 $hsp->hit->end ),
87 $hsp->evalue,
88 # chance this to $hsp->sw_score
89 # if you would rather have that
90 # it will only work for FASTA parsing though!
91 $hsp->bits)),"\n";