#!/bin/bash

tempDir=/galaxy-prod/tmp

inputfile=${1}
inputfile2=${2}
outputfile=${3}
inputFC=${4}


if [ "${inputfile2}" == "1" ]
then 
        echo 
        awk -v FC=$inputFC '{if (NR == 1 || ($2 != "NDE" && $2 <= -(log(FC)/log(2)))) print $0}' $inputfile > $outputfile
#exit;

elif [ "${inputfile2}" == "2" ]
then        
        awk -v FC=${inputFC} '{if (NR == 1 || ($2 != "NDE" && $2 >= (log(FC)/log(2)))) print $0}' $inputfile > $outputfile
else  
        awk -v FC=${inputFC} '{if ((NR == 1 || ($2 != "NDE" && $2 <= -(log(FC)/log(2)))) || (NR == 1 || ($2 != "NDE" && $2 >= (log(FC)/log(2))))) print $0}' $inputfile > $outputfile
fi

echo "done"
date





#logx(y) = logn(y)/logn(x) 

#The NR==1 condition makes sure the file header gets printed