Parse BES-SELF
<source lang=perl>
- !/usr/bin/perl -w
- Libraries
use Bio::SearchIO; use Parallel::ForkManager;
- Variables
my ($i) = $_;
- Input prompt
if (! $ARGV[0]) { print "What is the BLAST file to parse? "; chomp ($inFile = <STDIN>); } else { $inFile = $ARGV[0]; }
- Multithreading
my $pm = new Parallel::ForkManager(16);
- Some counting
my $c_entries = `grep -c "Sequences producing significant alignments" $inFile`; chomp $c_entries;
- Making the outfile
open (GFF, ">".$inFile.".csv"); print GFF "Query\tHitName\tHitDesc\tHSP_rank\t\%ID\teValue\tHSP_length\n"; close GFF;
- Parsing Function
$report = new Bio::SearchIO(
-file=>"$inFile",
-format => "blast");
$i = 0; # Go through BLAST reports one by one while($result = $report->next_result) {
$i++; $pm->start and next;
# Go through each each matching sequence while($hit = $result->next_hit) {
# Go through each each HSP for this sequence while ($hsp = $hit->next_hsp) {
# Capture the results my $accesssion = $result->query_accession; my $hitname = $hit->name;
my $HitDesc = $hit->description; my $rank = $hsp->rank;
my $identity = $hsp->percent_identity; my $evalue = $hsp->evalue; my $hsp_length = $hsp->hsp_length;
#Conditions next if $hsp->percent_identity < 80 ; next if $hsp->hsp_length < 80 ; $identity = sprintf ("%.2f", $identity);
# Writing into files open (GFF, ">>".$inFile.".csv"); print GFF "$accesssion\t$hitname\t$HitDesc\t$rank\t$identity\t$evalue\t$hsp_length\n"; close GFF;
#Decorating the log my $percent = ($i/$c_entries)*100; $percent = sprintf("%.2f", $percent);
print "\n\tCompleted [$i of $c_entries] | $percent% ";
} }
$pm->finish;
}
$pm->wait_all_children;
- END
</perl>