#!/usr/bin/perl -w # Parsing BLAST reports with BioPerl's Bio::SearchIO module; # Recover single HSP (the first one); # No filtering options; #use strict; use Bio::SearchIO; # Prompt the user for the file name if it's not an argument; # NOTE: BLAST file must be in text (not html) format; if (! $ARGV[0]) { $usage = "./blast_parsing_single.pl BLASTREPORT"; print "Usage is '$usage' or.....\n"; print "What is the BLAST file to parse? "; # Get input and remove the newline character at the end; chomp ( $inFile = ); } else { $inFile = $ARGV[0]; } $report = new Bio::SearchIO( -format => 'blast', -file => "$inFile" ); # Prints the header for the columns; print "Query_Name\tQuery_Acc\tQuery_Len\tHit_Acc\tHit_Desc\tHit_Signif\n"; # Go through BLAST reports while( $result = $report->next_result ) { #print $result->query_name . "\t" ; $counter = 0; # Just takes the first hit while ( $hit = $result->next_hit) { if ($counter == 0) { # Print tab-delimited data; print $result->query_name, "\t"; print $result->query_accession, "\t"; print $result->query_length, "\t"; print $hit->accession, "\t"; print $hit->description, "\t"; print $hit->significance, "\t"; $counter++; } } print "\n"; }