#$ -N Yahs-AJ
#$ -cwd
#$ -o ../logs/$JOB_NAME.$JOB_ID.log
#$ -e ../logs/$JOB_NAME.$JOB_ID.err
#$ -pe smp 56
#$ -l h_vmem=4.4g

###################################################3
DIR=/mnt/data/arslan/Teas/01_Assembly/Arima-Yahs/Yahs-AJ

export PATH=/mnt/bin/yahs/yahs/:$PATH

mkdir -p $DIR
cd $DIR

yahs -o AJ ../Output-AJ/AJ.curated.fasta  ../Output-AJ/AJ.combine.markdup.bam

#Convert Yahs Output for juicebox

BIN=AJ.bin
AGP=AJ_scaffolds_final.agp
JUICER=/home/max/juicer/juicer_tools_1.22.01.jar
GENOM_SCAFF=AJ_scaffolds_final.fa
GENOME_CONTIG=../Output-AJ/AJ.curated.fasta


bioawk -c fastx '{print $name"\t"length($seq)}' ${GENOME_CONTIG} > chrom.sizes.orig
bioawk -c fastx '{print $name"\t"length($seq)}' ${GENOM_SCAFF} > chrom.sizes

CSIZE1=./chrom.sizes.orig
CSIZE2=./chrom.sizes

juicer pre -a -o out_JBAT ${BIN} ${AGP} ${CSIZE1} > out_JBAT.log 2>&1 \


(java -Xmx36G -jar ${JUICER} pre out_JBAT.txt out_JBAT.hic.part <(cat out_JBAT.log  | grep PRE_C_SIZE | awk '{print $2" "$3}')) \
&& (mv out_JBAT.hic.part out_JBAT.hic)
