#!/bin/bash

mkdir -p ../t_coffee/SCORES
mkdir -p ../t_coffee/html_unic_exo
mkdir -p ../t_coffee/aln_unic_exo

for year_d in ../t_coffee/exit_tcof/Exonerate/*; do {
	year=`basename $year_d`
	mkdir -p ../t_coffee/SCORES/$year
	mkdir -p ../t_coffee/html_unic_exo/$year
	mkdir -p ../t_coffee/aln_unic_exo/$year

	for genome_d in ../t_coffee/exit_tcof/Exonerate/$year/*; do {
		genome=`basename $genome_d`
	
		mkdir -p ../t_coffee/SCORES/$year/$genome
		mkdir -p ../t_coffee/html_unic_exo/$year/$genome
		mkdir -p ../t_coffee/aln_unic_exo/$year/$genome
		
		for query_d in ../t_coffee/exit_tcof/Exonerate/$year/$genome/*; do {
	
			query=`basename $query_d`

			mkdir -p ../t_coffee/SCORES/$year/$genome/$query
			mkdir -p ../t_coffee/html_unic_exo/$year/$genome/$query
			mkdir -p ../t_coffee/aln_unic_exo/$year/$genome/$query
			
			for hits_dnum in ../t_coffee/exit_tcof/Exonerate/$year/$genome/$query/*; do {
			
				hits_num=`basename $hits_dnum`
	
				mkdir -p ../t_coffee/SCORES/$year/$genome/$query/$hits_num
				mkdir -p ../t_coffee/html_unic_exo/$year/$genome/$query/$hits_num
				mkdir -p ../t_coffee/aln_unic_exo/$year/$genome/$query/$hits_num

for protein_d in $hits_dnum/*; do {
protein=`basename $protein_d`
ordena=${protein%.fa}
	echo $ordena

	perl ./valorscore.pl < $protein_d $genome $query $hits_num $protein $year

} done


t=0
batalla=0
              
for scores_d in ../t_coffee/SCORES/$year/$genome/$query/$hits_num/*; do { 
scores=`basename $scores_d`
sordenat=${scores%.fa}

z=`cat $scores_d`
echo $z
if [ $batalla == "0" ]; then
{  

batalla=`perl ./sCORgran.pl $z`


echo Funciona
cp ../t_coffee/exit_tcof/Exonerate/$year/$genome/$query/$hits_num/$scores ../t_coffee/res_unic_exo/$year/$genome/$query/$hits_num/
cp ../t_coffee/html/Exonerate/$year/$genome/$query/$hits_num/$sordenat.html ../t_coffee/html_unic_exo/$year/$genome/$query/$hits_num/
cp ../t_coffee/aln/Exonerate/$year/$genome/$query/$hits_num/$sordenat.aln ../t_coffee/aln_unic_exo/$year/$genome/$query/$hits_num/
}

else 

{
y="../t_coffee/res_unic_exo/$year/$genome/$query/$hits_num"
p="../t_coffee/html_unic_exo/$year/$genome/$query/$hits_num"
l="../t_coffee/aln_unic_exo/$year/$genome/$query/$hits_num"

batalla=`perl ./sCORgran.pl $z $batalla`

echo $t
echo $z
if (($t<$z)); then {
rm -r $y
mkdir $y
rm -r $p
mkdir $p
rm -r $l
mkdir $l

echo Funcionabe?
cp ../t_coffee/exit_tcof/Exonerate/$year/$genome/$query/$hits_num/$scores ../t_coffee/res_unic_exo/$year/$genome/$query/$hits_num/$scores
cp ../t_coffee/html/Exonerate/$year/$genome/$query/$hits_num/$sordenat.html ../t_coffee/html_unic_exo/$year/$genome/$query/$hits_num/$sordenat.html
cp ../t_coffee/aln/Exonerate/$year/$genome/$query/$hits_num/$sordenat.aln ../t_coffee/aln_unic_exo/$year/$genome/$query/$hits_num/$sordenat.aln
}
fi
t=$batalla
echo siqueva
}
fi


} done
} done
} done
} done
} done







