#! /bin/bash

##############################################
# 
# Compute PTIH (percent tags in hotspots)
# 
# Write results to filename _TAGS_.ptih.out
#
##############################################

tags=_TAGS_
uncompr=_UNCOMPR_

echo "Computing PTIH..."

name=`basename $tags`

ntags=`grep TotalTagCount $name-pass1/$name.stdout | cut -d" " -f2`

hotd=$name-both-passes
hot=$hotd/$name.hotspot.twopass.zscore.wig
out=$name.ptih.out
tih=`$uncompr $tags | setops -e -1 - $hot | wc -l`
echo "tih = $tih"
ptih=`echo "scale=4; $tih/$ntags" | bc`
echo "ptih = $ptih"
printf "%12d  %12d  %.4f\n" $ntags $tih $ptih > $out
