
# example of usage:
# bash getTADs.sh AatrE3_V4
# be sure that file AalbS2_V3.1000.hic_5000.h5 located in the same folder and
# dirs TADs and TADs/2D/ exist

name=$1

# compute TADs with default params

res_prefix=".1000"
#res_prefix=""

hicFindTADs -m ${name}${res_prefix}.hic_1000.h5 --outPrefix TADs_notperchr/${name}.1000.hic_1000.h5.default --correctForMultipleTesting fdr
	
# check several delta params, use precomputed TAD_sep_score matrix for speeding up
#for delta in {0.01,0.05,0.1}; 
for delta in {0.05,};
do 
	hicFindTADs -m ${name}${res_prefix}.hic_1000.h5 --outPrefix TADs_notperchr/${name}${res_prefix}.hic_1000.h5.delt.${delta} --correctForMultipleTesting fdr --delta $delta --TAD_sep_score_prefix TADs_notperchr/${name}.1000.hic_1000.h5.default; 
	
	#convert TADs into Juicebox-compatible 2D annotation format, save in TADs/2D/*.2D files
	./bed2juiceAnnotation.awk TADs_notperchr/${name}${res_prefix}.hic_1000.h5.delt.${delta}_domains.bed > TADs_notperchr/2D/${name}${res_prefix}.hic_1000.h5.delt.${delta}_domains.2D
done
