#!/bin/bash

merged_nodups=$1
chrom_sizes=/storage3/estsoi/mcph_ko_rad21__rad21/modified.chrom.sizes
out_cool=$2
cool_resolution=1000
tmpdir=/storage3/estsoi/tmp


sort -T $tmpdir -o ${merged_nodups} -m -k2,2d -k6,6d -k4,4n -k8,8n -k1,1n -k5,5n -k3,3n ${merged_nodups}
cat ${merged_nodups} | awk 'BEGIN {OFS="\t"} ($9>=30)&&($12>=30) {print $2,$3,$6,$7}' | cooler cload pairs -c1 1 -p1 2 -c2 3 -p2 4 ${chrom_sizes}:${cool_resolution} - ${out_cool}
