#!/bin/bash 

PATH_resultsgreen="~/Escritorio/Treballbioinfo/vipera/green_proteins/resultsgreen"

cd $PATH_resultsgreen

samples="GPx8(hit2) MsrA(hit5) SelR3(hit1) GPx(hit1) Sel0(1)(hit1) Sel0(2)(hit1) MsrA(hit1) SelU2(hit1) GPx4(hit1) MsrA(hit2) MsrA(hit3) SelI(hit1) MsrA(hit4) SelR2(hit1)"

for sample in $samples
do

	cd $sample

	
	a=$(cut -d '(' -f2 $sample.exon.gff | cut -d ',' -f1 | uniq) #start we gave to the fastasubseq	

	b=$(egrep positions $sample.secis.fasta | wc -l $f | cut -f1 -d' ') #number of lines counter

	c=$(cut -d ':' -f1 $sample.exon.gff | uniq) #contig's ID
	
	echo ">$sample($c)" >> ~/Escritorio/Treballbioinfo/vipera/coordenades/resultats_coordenades/SECIs_green/greencoordenades_secis_absolutes.txt #file with all proteins with their SECIs predictions

	echo ">$sample($c)" > ~/Escritorio/Treballbioinfo/vipera/coordenades/resultats_coordenades/SECIs_green/$sample.txt #File for each protein with its SECIs prediction

	counter=1

	while [ $counter -le $b ]
	do
	
		x=$(cat $sample.secis.fasta | egrep positions | cut -d ':' -f4 | cut -f1 | cut -d '-' -f1 | awk NR==$counter) #relative start
		
		y=$(cat $sample.secis.fasta | egrep positions | cut -d ':' -f4 | cut -f1 | cut -d '-' -f2 | cut -d ' ' -f1 | awk NR==$counter) #relative end

		z1=$(($a+$x)) #absolute start
		
		z2=$(($a+$y)) #absolute end
		
		z3=$(cat $sample.secis.fasta | egrep positions | cut -d ':' -f4 | cut -d' ' -f2 | awk NR==$counter) #secis type

		echo "	Secis$counter	$z3	Start:$z1	End:$z2" >> ~/Escritorio/Treballbioinfo/vipera/coordenades/resultats_coordenades/SECIs_green/greencoordenades_secis_absolutes.txt
		echo "	Secis$counter	$z3	Start:$z1	End:$z2" >> ~/Escritorio/Treballbioinfo/vipera/coordenades/resultats_coordenades/SECIs_green/$sample.txt

		counter=$(($counter+1))
	done
	
	cd $PATH_resultsgreen
	counter=1
	
done
