#SrcFolder="/data/zhang/wuj/scripts/SpliceTrap.0.8";

outputname=$1;
CutoffLevel=$2;
Outputfolder=$3
SrcFolder=$5
JunctionCut=$4
noIRM=$8

echo "CUTOFF: Entering cutoff step...";
echo "CUTOFF: Cache folder: $outputname.filter"
mkdir $Outputfolder/$outputname.filter
cd $Outputfolder/$outputname.filter
ln -s ../$outputname.ratio
ln -s ../$outputname.nums
echo "CUTOFF: spliting file....and generating shell scripts..."
split -11000 $outputname.ratio

for ratiofiles in  x*
do
        echo "perl $SrcFolder/ApplyCutoff.jie.pl $ratiofiles $CutoffLevel $JunctionCut $noIRM > $ratiofiles.out" >>filter.sh
done

echo "CUTOFF: submit scripts..."
perl $SrcFolder/batchqsub.pl filter.sh
echo "CUTOFF: merging file...."
cat *.out >../$outputname.raw
cd ../
#perl /data/zhang/wuj/tools/SpliceTrap.0.8/ApplyCutoff.jie.pl $outputname.ratio $outputname.nums 8 >$outputname.txt
if [ "$noIRM" ];then
	awk '{printf $22"\t"$2"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$12"\t"$13"\t"$14"\t"$15"\n"}' $outputname.raw >$outputname.txt
else
	awk '{printf $22"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$12"\t"$13"\t"$14"\t"$15"\n"}' $outputname.raw >$outputname.txt
fi
rm $outputname.filter -rf

