blastparse.pl
use Bio::SearchIO;
if (! $ARGV[0])
{
print "What is the BLAST text file to parse? ";
chomp ($inFile = <STDIN>);
}
else
{
$inFile = $ARGV[0];
}
$report = new Bio::SearchIO( -file => "$inFile", -format => "blast");
while($result = $report->next_result)
{
$hitNumber = 0;
while($hit = $result->next_hit)
{
$hitNumber++;
while ($hsp = $hit->next_hsp)
{
$queryName = $result->query_name;
$queryAcc = $result->query_accession;
$queryLength = $result->query_length;
$queryDesc = $result->query_description;
$dbName = $result->database_name;
$numSeqsInDb = $result->database_entries;
$numHits = $result->num_hits;
$hitName = $hit->name;
$hitAcc = $hit->accession;
$hitDesc = $hit->description;
$hitEvalue = $hit->significance;
$hitBits = $hit->bits;
$numHsps = $hit->num_hsps;
$hspEvalue = $hsp->evalue;
$fracIdentical = $hsp->frac_identical;
$fracConserved = $hsp->frac_conserved;
$numGaps = $hsp->gaps;
$hspLength = $hsp->hsp_length;
$hspQuerySeq = $hsp->query_string;
$hspHitSeq = $hsp->hit_string;
$hspConsensus = $hsp->homology_string;
$hspLength = $hsp->hsp_length;
$hspRank = $hsp->rank;
$queryStrand = $hsp->strand('query');
$hitStrand = $hsp->strand('hit');
$queryStart = $hsp->start('query');
$queryEnd = $hsp->end('query');
$hspStart = $hsp->start('hit');
$hspEnd = $hsp->end('hit');
$hspScore = $hsp->score;
$hspBits = $hsp->bits;
}
}
}