#!/bin/bash
#SBATCH -A brain1
#SBATCH -p brain1
#SBATCH -t 48:00:00
#SBATCH -N 1
#SBATCH --mem=20G
#SBATCH --cpus-per-task=2
#SBATCH --job-name=create_cool
#SBATCH --output=create_cool_data_for_analysis.o
#SBATCH --error=create_cool_data_for_analysis.e

source /home/belokopytova/.bashrc
mamba activate EagleC
WORK_DIR=/beegfs/data/hpcws/ws1/belokopytova-data/eagleC_test/Mod_wo_enrich
MND_DIR=/beegfs/data/hpcws/ws1/belokopytova-data/eagleC_test/Mod_wo_enrich/pre
declare -a samples=("336" "6" "36" "261" "241" "921" "631" "751" "856" "801" "1216" "1441" "1406" "1541" "1581" "1896" "1806" "2036" "2051" "2171" "2296" "2331" "2426" "2621" "2441" "3221" "3061" "2996" "2841" "2961" "3691" "3511" "3586" "3461" "3361" "4246" "4186" "4241" "3931" "3986" "303" "398" "328" "263" "68" "608" "678" "1003" "893" "693" "1518" "1448" "1218" "1528" "1368" "2108" "1658" "1778" "1893" "1728" "2578" "2338" "2283" "2208" "2593" "2983" "3293" "3013" "3193" "2783" "3408" "3363" "3368" "3353" "3573" "4028" "4098" "4188" "4303" "4158" "404" "474" "274" "189" "294" "884" "979" "769" "849" "804" "1224" "1559" "1384" "1629" "1169" "1729" "1979" "1799" "1659" "1914" "2659" "2324" "2374" "2714" "2424" "2919" "2964" "2904" "3084" "3184" "3549" "3834" "3339" "3359" "3319" "4134" "4394" "3884" "4064" "4229" "105" "525" "300" "425" "455" "1020" "915" "555" "640" "795" "1170" "1630" "1120" "1530" "1580" "1745" "1765" "1845" "1735" "2035" "2290" "2715" "2590" "2735" "2400" "2775" "3075" "3045" "3290" "2825" "3805" "3375" "3695" "3660" "3815" "4025" "3935" "4030" "3970" "3880")
cd $WORK_DIR
for sample in "${samples[@]}"
do
zcat $MND_DIR/wg.${sample}.pre.gz | awk 'BEGIN {OFS=FS="\t"} {print $2,$3,$3+5000,$6,$7,$7+5000,$9}' | cooler load -f bg2 /beegfs/data/hpcws/ws1/belokopytova-data/eagleC_test/hg19.chromsizes:5000 - $WORK_DIR/cool/wg.${sample}_5Kb.cool
cooler zoomify -r 5000N -o $WORK_DIR/cool/wg.${sample}.mcool $WORK_DIR/cool/wg.${sample}_5Kb.cool
done
