#!/bin/bash
wordcount $1 testt.txt -wordsize=2
wordcount $1 testtt.txt -wordsize=1
A=$(($(grep 'A' testtt.txt|awk '{print$2}')+(0)))
G=$(($(grep 'G' testtt.txt|awk '{print$2}')+(0)))
T=$(($(grep 'T' testtt.txt|awk '{print$2}')+(0)))
C=$(($(grep 'C' testtt.txt|awk '{print$2}')+(0)))
summ2=$((($A)+($T)+($G)+($C)))
echo $summ2
summ3=$((($summ2)-1))
AT=$(($(grep 'AT' testt.txt|awk '{print$2}')+0))
TA=$(($(grep 'TA' testt.txt|awk '{print$2}')+0))
AC=$(($(grep 'AC' testt.txt|awk '{print$2}')+0))
CA=$(($(grep 'CA' testt.txt|awk '{print$2}')+0))
GA=$(($(grep 'GA' testt.txt|awk '{print$2}')+0))
AG=$(($(grep 'AG' testt.txt|awk '{print$2}')+0))
AA=$(($(grep 'AA' testt.txt|awk '{print$2}')+0))
GG=$(($(grep 'GG' testt.txt|awk '{print$2}')+0))
TT=$(($(grep 'TT' testt.txt|awk '{print$2}')+0))
CC=$(($(grep 'CC' testt.txt|awk '{print$2}')+0))
GT=$(($(grep 'GT' testt.txt|awk '{print$2}')+0))
TG=$(($(grep 'TG' testt.txt|awk '{print$2}')+0))
TC=$(($(grep 'TC' testt.txt|awk '{print$2}')+0))
CT=$(($(grep 'CT' testt.txt|awk '{print$2}')+0))
CG=$(($(grep 'CG' testt.txt|awk '{print$2}')+0))
GC=$(($(grep 'GC' testt.txt|awk '{print$2}')+0))
dinucl=$(($AA+$CC+$GG+$TT+$AG+$GA+$AT+$TA+$AC+$CA+$GT+$TG+$CT+$TC+$CG+$GC))
TA1=$((((($A)*($T)*100000/$((($summ3)))/($summ2)))-((($TA)*100000/($dinucl)))))
CA1=$((((($A)*($C)*100000/$((($summ3)))/($summ2)))-((($CA)*100000/($dinucl)))))
GA1=$((((($A)*($G)*100000/$((($summ3)))/($summ2)))-((($GA)*100000/($dinucl)))))
TG1=$((((($G)*($T)*100000/$((($summ3)))/($summ2)))-((($TG)*100000/($dinucl)))))
TC1=$((((($C)*($T)*100000/$((($summ3)))/($summ2)))-((($TC)*100000/($dinucl)))))
GC1=$((((($C)*($G)*100000/$((($summ3)))/($summ2)))-((($GC)*100000/($dinucl)))))
AT1=$((((($A)*($T)*100000/$((($summ3)))/($summ2)))-((($AT)*100000/($dinucl)))))
AC1=$((((($A)*($C)*100000/$((($summ3)))/($summ2)))-((($AC)*100000/($dinucl)))))
AG1=$((((($A)*($G)*100000/$((($summ3)))/($summ2)))-((($AG)*100000/($dinucl)))))
GT1=$((((($G)*($T)*100000/$((($summ3)))/($summ2)))-((($GT)*100000/($dinucl)))))
CT1=$((((($C)*($T)*100000/$((($summ3)))/($summ2)))-((($CT)*100000/($dinucl)))))
CG1=$((((($C)*($G)*100000/$((($summ3)))/($summ2)))-((($CG)*100000/($dinucl)))))
GG1=$((((($G)*($G)*100000/$((($summ3)))/($summ2)))-((($GG)*100000/($dinucl)))))
AA1=$((((($A)*($A)*100000/$((($summ3)))/($summ2)))-((($AA)*100000/($dinucl)))))
TT1=$((((($T)*($T)*100000/$((($summ3)))/($summ2)))-((($TT)*100000/($dinucl)))))
CC1=$((((($C)*($C)*100000/$((($summ3)))/($summ2)))-((($CC)*100000/($dinucl)))))
otcl=($AT1 $TA1 $AC1 $CA1 $AG1 $GA1 $GT1 $TG1 $CT1 $TC1 $CG1 $GC1 $GG1 $AA1 $CC1 $TT1)
IFS=$'\n' sorted=($(sort -n <<<"${otcl[*]}")); unset IFS
echo ${otcl[@]}
echo ${sorted[@]}
tt=0
cc=0
ttt=0
for i in ${otcl[*]};do
	if [ ${sorted[15]} = $i ]
	then
		ttt=$((($tt)))
	else
		tt=$((($tt)+(1)))
	fi
	if [ ${sorted[0]} = $i ]
        then
                tttt=$((($cc)))
        else
		cc=$((($cc)+(1)))
	fi
done
otcl1=(AT TA AC CA AG GA GT TG CT TC CG GC GG AA CC TT)
tttt2=$(((-1)*(${otcl[$(($tttt))]})))
if [[ $tttt2 > ${otcl[$(($ttt))]} ]]
then
	result=${otcl1[$(($tttt))]}
else
	result=${otcl1[$(($ttt))]}
fi
echo $result
rm testt.txt
rm testtt.txt
