#!/bin/bash

         export PATH=/cursos/BI/bin/ncbiblast/bin:$PATH             # pel NCBI Blast
         cp /cursos/BI/bin/ncbiblast/.ncbirc ~/                     # pel NCBI Blast
	 export PATH=/cursos/BI/bin/exonerate/i386/bin:$PATH	    # per lexonerate
	 export PATH=/cursos/BI/bin:$PATH			    # pel genewise, fastaseqfromGFF.pl i t_coffee
	 export WISECONFIGDIR=/cursos/BI/soft/wise-2.2.0/wisecfg    # pel genewise	
	 export PATH=/cursos/BI/bin/netblast/bin:$PATH		    # pel blastp
	 export PATH=/cursos/BI/bin:$PATH			    # per el SECISsearch


		for carpetes in ./Semillas/*; do {
		semilla_fa=`basename $carpetes`
		semilla=${semilla_fa%.fa}
		semillas=$semillas" $semilla"
		} done

# BLASTP. Usarem la mateixa declaració de variables que hem utilitzat fins ara. Res de nou, usarem el filtre de genomes de querys que obtinguin exons al exonerate, de manera que realitzem alineaments contra proteines d'interès i no aberrants.              

mkdir BLASTP

for semillas in ./Evalues/* ; do {
 for genome in $semillas/* ; do {
  for Evalue in $genome/* ; do {
  
  semillas=`basename $semillas`
  genome=`basename $genome`
  Evalue=`basename $Evalue`
  Evalue=${Evalue%.txt}

  echo ${semillas}_${genome}_${Evalue}:

  exon=`grep -w exon Exonerate/Seleccionados/EXONERATE_${semillas}_${genome}_${Evalue}.gff`
  grep -w exon Exonerate/Seleccionados/EXONERATE_${semillas}_${genome}_${Evalue}.gff > exon.temp
  if [ "$exon" != "" ]; then		
		
     mkdir BLASTP/$semillas
     mkdir BLASTP/$semillas/$genome

     blastcl3 -p blastp -i proteina/proteina_${semillas}_${genome}_${Evalue}.fa -d nr > BLASTP/$semillas/$genome/BLASTP_${semillas}_${genome}_${Evalue}.txt


			
   fi

  } done
 } done
} done


