###SHORT MANUAL 
#The onliest parameter is the query file blast
#parameter and path to the species folder has to be set in the script
###NO WARRANTY ON PROPER FUNCTION

my $path="/scr/genomes/Metazoan-Animals/";
my $query_file=$ARGV[0]; #!!!HAS TO BE SET!!!
my $blastmode="tblastn";
my $evalue="1e-4";

#get all species in $path
my @species_list=`ls $path`; 



#process every species
foreach(@species_list){
    my $tax=$_;    #species
    chomp($tax);
    my $db;        #path to species genome
    my @g=`grep $tax /scr/genomes/content.praktikum`;  #get the content.praktikum line of current species

    if(@g){
    	foreach(@g){
	    #print "$_";
    	    if($_=~/ENSEMBL\s/){
    		my @temp_db=split(/\s+/,$_);
    		$db="$temp_db[4]/$temp_db[5]";
    		break;
    	    }
    	    elsif($_=~/UCSC\s/){
    		my @temp_db=split(/\s+/,$_);
    		$db="$temp_db[4]/$temp_db[5]";
    		break;
    	    } 
    	    elsif($_=~/OTHER\s/){
		
    		my @temp_db=split(/\s+/,$_);
    		$db="$temp_db[4]/$temp_db[5]";
    	    }
	    elsif($_=~/NCBI\s/){
	      
    		my @temp_db=split(/\s+/,$_);
    		$db="$temp_db[4]/$temp_db[5]";
    	    }
    	}
    }else{
    	print STDERR "Species $tax has no content.praktikum entry\n";
	next;
    }
    
    #print "#---Start blast in $tax---\n";
    print "for F in $db; do blastall -d \$F -i $query_file -m 8 -p $blastmode -e $evalue;done  >> $tax.bl;\n";
    #system("for F in $db; do blastall -d \$F -i $query_file -m 8 -p $blastmode -e $evalue;done  >> $tax.bl;"); #if you feel confident you could blast from within perl...
}
