Blast.pl
#! /usr/bin/perl -w
# *************************************************************
# This Programme does the following in sequence
# -> Performs regular Blast
# -> Infile as folder and write the progress
# Author : Rajkumar (itc@rajkumar.in)
# Release: JUL 2009
# *************************************************************
# Libraries
use strict;
use Bio::Perl;
use Bio::SeqIO;
use Parallel::ForkManager;
# At the top: Time Start
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# Variables
my $path = "/home/raj/bio";
my $path1 = "$path/user/raja";
my $path2 = "$path1/blast/BES-NR";
my $multifasta = "$path2/BES.fa";
my $infiledir = "$path2/multifasta";
my $outdir = "$path2/blastout";
my $db = "$path/data/nr/nr";
my ($i, $total) = $_;
my (@files, @files_)= @_;
# Multi-threading
my $midstop = "0"; # If midstop is 0 it deals with all the files
my $cpu = "1";
my $pm = new Parallel::ForkManager(16);
# Getting the Grip of folders
if (-e $outdir ) {`rm -fr $outdir`;}
if (! -e $outdir) {`mkdir $outdir`;}
# Functions
opendir (DIR, "$infiledir") or die $!;
@files = readdir(DIR);
close(DIR);
my $c_files = @files - 2;
$i = 0;
foreach my $file(@files) {
next if ($file eq "." or $file eq "..");
$i++;
#if ($i > $midstop) {last };
$pm->start and next;
my $percent = ($i/$c_files)*100;
$percent = sprintf("%.2f", $percent);
print "\n\tInitiated [$i of $c_files] | $percent% ";
chdir $infiledir;
`blastall -p blastx -d $db -i $file -m 9 -o $outdir/\/$file.out -a $cpu`;
# -p program
# -d database
# -i query file
# -e evalue
# -m 8 tab delimited out
# -o outfile
# -a number of CPUs
# -q Penalty for a nucleotide mismatch (blastn only) default = -3
# -v Number of database sequences to show one-line
# -K Number of best hits from a region to keep
print "OK.";
$pm->finish;
}
$pm->wait_all_children;
print "\nAll Done!\n\n";
# At the End: Time Calculation
my ($sec_,$min_,$hour_,$mday_,$mon_,$year_,$wday_,$yday_,$isdst_) = localtime(time);
my $days = $mday_-$mday;
my $hours = $hour_-$hour;
my $mins = $min_-$min;
my $secs = $sec_-$sec;
print "\n------------------------\nDuration: ";
if ($days>0) { print "$days days";}
if ($hours>0) { print ": $hours hours";}
if ($mins>0) { print ": $mins mins";}
if ($secs>0) { print ": $secs secs";}
print "\n------------------------\n";
# END