#! /usr/bin/perl -w use strict; use Bio::SearchIO; use Getopt::Std; #Written by CSR on 3.7.08 #Simple blast parser my %args; getopts('i:n:', \%args); my $usage = "Warning, missing information\nUsage is: scriptname.pl -i [infile] -n [number of blast hits]\n"; my $infile; my $num; my $count = 0; #command line arguments if ($args{i}) { $infile = $args{i}; } else { die "$usage"; } if ($args{n}) { $num = $args{n}; } else { die "$usage"; } #input my $in = new Bio::SearchIO(-format => 'blast', -file => $infile); #output my $outfile = $infile.".parsed"; open (PARSED , "> $outfile") or die "COULD NOT WRITE TO THE OUTFILE\n"; #headerline print PARSED "SeqID\tHit Acc#\tDescription\tEvalue\n"; #parse with bioperl while( my $result = $in->next_result ) { my $qname = $result->query_name; $count = 0; while( my $hit = $result->next_hit ) { my $check = $result->num_hits; $count++; if ($num > $check) { die "# of hits is too high...pick a smaller number.\n"; } if ($count <= $num) { my $acc = $hit->accession; my $desc = $hit->description; my $signif = $hit->significance; print PARSED "$qname\t$acc\t$desc\t$signif\n"; } } } close (PARSED);