#!/bin/bash 

PATH_resultsred="~/Escriptori/Treballbioinfo/vipera/red_proteins/resultsred"

cd $PATH_resultsred

samples="DI1(hit1) DI1(hit3) DI2(hit2) GPx3(hit1) GPx(hit2) Sel15(hit1) SelI(hit1) SelP1(hit1) SelR1(hit1) SelU1(hit1) TR3(hit1)
DI1(hit2) DI2(hit1) GPx2(hit1) GPx(hit1) GPx(hit3) SelH(hit1) SelN(hit1) SelP2(hit1) SelT(hit1) SPS(hit1) TR(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) #identificador del contig
	
	echo ">$sample($c)" >> ~/Escriptori/coordenades/resultats_coordenades/coordenades_secis_absolutes.txt

	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" >> ~/Escriptori/coordenades/resultats_coordenades/coordenades_secis_absolutes.txt

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

# cat DI1\(hit1\).secis.fasta | egrep positions | cut -d ':' -f4 | cut -f1 | cut -d '-' -f2 | cut -d ' ' -f1 | awk 'NR==1'
#>GPx(hit1)(K72798.34)
	#Secis1	type=1	start:265582	end=62572783
	#Secis1	type=1	start:265582	end=62572783
	
