rework to optimize a bit, again for bug #3172
[bioperl-live.git] / scripts / utilities / search2BSML.PLS
blob9d3ecf880a470238f090c95fc0dda8b19cc6192f
1 #!perl -w
3 # Author:      Jason Stajich <jason-at-bioperl-dot-org>
4 # Description: Turn SearchIO parseable report(s) into a GFF report
6 =head1 NAME
8 search2bsml - Turn SearchIO parseable reports(s) into a BSML report
10 =head1 SYNOPSIS
12 Usage:
13   search2bsml [-o outputfile] [-f reportformat] [-i inputfilename]  OR file1 file2 ..
15 =head1 DESCRIPTION
17 This script will turn a protein Search report (BLASTP, FASTP, SSEARCH, 
18 AXT, WABA, SIM4) into a BSML File.
20 The options are:
22    -i infilename        - (optional) inputfilename, will read
23                           either ARGV files or from STDIN
24    -o filename          - the output filename [default STDOUT]
25    -f format            - search result format (blast, fasta,waba,axt)
26                           (ssearch is fasta format). default is blast.
27    -h                   - this help menu
29 Additionally specify the filenames you want to process on the
30 command-line.  If no files are specified then STDIN input is assumed.
31 You specify this by doing: search2gff E<lt> file1 file2 file3
33 =head1 AUTHOR
35 Jason Stajich, jason-at-bioperl-dot-org
37 =cut
39 use strict;
40 use Getopt::Long;
41 use Bio::SearchIO;
43 my ($output,$input,$format,$type,$help,$cutoff);
44 $format = 'blast'; # by default
45 GetOptions(
46            'i|input:s'  => \$input,
47            'o|output:s' => \$output,
48            'f|format:s' => \$format,
49            'c|cutoff:s' => \$cutoff,
50            'h|help'     => sub{ exec('perldoc',$0);
51                                 exit(0)
52                                 },
53            );
54 # if no input is provided STDIN will be used
55 my $parser = new Bio::SearchIO(-format => $format, 
56                                -file   => $input);
58 my $out;
59 if( defined $output ) {
60     $out = new Bio::SearchIO(-file => ">$output",
61                              -output_format => 'BSMLResultWriter');
62 } else { 
63     $out = new Bio::SearchIO(-output_format => 'BSMLResultWriter'); # STDOUT
66 while( my $result = $parser->next_result ) {
67     $out->write_result($result);