#!/bin/bash 

PATH_resultsgreen="~/Escriptori/vipera/green_proteins/resultsgreen"

cd $PATH_resultsgreen

samples="eEFsec(1)(hit1) GPx8(hit2) MsrA(hit5) SecS(hit1) SelR3(hit1) eEFsec(2)(hit1) GPx(hit1) Sel0(1)(hit1) Sel0(2)(hit1) eEFsec(3)(hit1) MsrA(hit1) PSTK(hit1) SelU2(hit1) GPx4(hit1) MsrA(hit2) SBP2(1)(hit1) SPS1(hit1) MsrA(hit3) SBP2(2)(hit1) SelI(hit1) SPS1(hit2)
GPx8(hit1) MsrA(hit4) SECp43(hit1) SelR2(hit1)"

for sample in $samples
do

	cd $sample

	contig=$(cut -d ':' -f1 $sample.exon.gff | uniq) #contig's ID
	
	echo ">$sample($contig)" >> ~/Escriptori/vipera/coordenades/resultats_coordenades/coordenades_exonsgreen.txt
	
	counter=1

	linecount=$(wc $sample.exon.gff -l $f | cut -f1 -d' ')

	while [ $counter -le $linecount ] 
		do		

		a=$(cut -d '(' -f2 $sample.exon.gff | cut -d ',' -f1 | uniq) #start we gave to the fastasubseq
		
		b=$(cut -f4 $sample.exon.gff | awk NR==$counter) #relative start in the fastasubseq

		c=$(cut -f5 $sample.exon.gff | awk NR==$counter) #relative end in the fastasubseq

		d=$(($a+$b)) #abolute start of the exon in the contig

		e=$(($a+$c)) #abolute end of the exon in the contig
		
		echo "exon$counter	start:$d	end:$e" >> ~/Escriptori/vipera/coordenades/resultats_coordenades/green_coordenades_exons.txt
		
		counter=$(($counter + 1))

		echo $counter

		done

	counter=1
	cd $PATH_resultsgreen

done




