#!/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


rm SECISresultats.txt
rm copiasborrar

# SECIS                 

mkdir SECIS

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}                                   	

  SECISearch.pl -e -12.6 Fastasubseq/${semillas}_${genome}_${Evalue}.fastasubseq.fa      # Format (loose)

  mkdir copiasborrar
  cp   ${semillas}_${genome}_${Evalue}.fastasubseq.fa.std.secis copiasborrar 2> error.temp
  x=`cat error.temp`

  if [ "$x" = "" ] ; then
  mkdir SECIS/$semillas
  mkdir SECIS/$semillas/$genome
  mkdir SECIS/$semillas/$genome/$Evalue
  mkdir SECIS/$semillas/$genome/$Evalue/Images	 

  mv   ${semillas}_${genome}_${Evalue}.fastasubseq.fa.std.secis SECIS/$semillas/$genome/$Evalue/
  mv   ${semillas}_${genome}_${Evalue}.fastasubseq.fa.std_png SECIS/$semillas/$genome/$Evalue/Images/
  mv   ${semillas}_${genome}_${Evalue}.fastasubseq.fa.std.hit SECIS/$semillas/$genome/$Evalue/

  echo ${semillas}_${genome}_${Evalue} >> SECISresultats.txt
  fi					
		
  } done
 } done
} done


