#!/bin/bash

###DIRECTORIES/VALUE OF VARIABLES MUST BE CHANGED DEPENDING ON GENEWISE JOB

export ODIR=/users/rg/fcamara/Research/geneid_training/P.cucumerina/data/set1
export PROTEINCHUNK=/users/rg/fcamara/Research/geneid_training/P.cucumerina/data/set1/protein_chunks_uniprot

source /users/rg/fcamara/.bashrcant
export PERL5LIB=/users/rg/fcamara/Perlmods/:$PERL5LIB;

#### Running genewiseFromBLAT.pl
cd $ODIR

while read list #list_proteins_aa list_proteins_ab ....

do 

echo "### -> "$list;

 cat <<EOF > $ODIR/NQS.$list
#!/bin/bash

#$ -q rg-el6,long
#$ -N GENEWISEFROMBLAT_$list
#$ -e /users/rg/fcamara/Research/geneid_training/P.cucumerina/data/set1/errGWISE.$list.log
#$ -o /users/rg/fcamara/Research/geneid_training/P.cucumerina/data/set1/outGWISE.$list.log
#$ -pe smp 2
#$ -l  virtual_free=12G
#$ -l h_rt=64:00:00

. /etc/profile
. /users/rg/fcamara/.bashrcant
   
   export ODIR=$ODIR
   export PROTEINCHUNK=$PROTEINCHUNK
   
while read chunk # hsal_v3.3.pep.fasta.chunk1 hsal_v3.3.pep.fasta.chunk10..
do

echo "### -> "\$chunk;

#egrep -w '$chunk' $list > $PROTEINCHUNK/$chunk

/users/rg/fcamara/Research/geneid_training/P.cucumerina/data/set1/genewiseFromBLAT.pl -q $PROTEINCHUNK/\$chunk -g $ODIR/Pcucumerina.masked.fasta

  echo "### FINISHED "\$chunk; # &
done < $ODIR/$list     #list_proteins_aa

EOF

   chmod 755 $ODIR/NQS.$list
   qsub $ODIR/NQS.$list
   rm $ODIR/NQS.$list

done < $ODIR/listofchunksforgenewisepcucu

