#!/bin/bash
#$ -cwd
#$ -q all.q
#$ -S /bin/bash
#$ -m e

echo -n "started"
date

cd /storage/projects/ADChipSeq/CombinedTracks/bedgraph

for sample in `cut -f2 -d, ../scales.csv | sed '/"/s///g'`
do
   genomeCoverageBed -ibam  ../${sample}*bam  -bg \
     -scale `grep $sample ../scales.csv | cut -f5 -d,`  > $sample.bg
   sort -k1,1 -k2,2n $sample.bg> $sample.bgs          
   sed '/^G/ d' <$sample.bgs   > $sample.2bgs         
   sed '/^M/ d' <$sample.2bgs  > $sample.3bgs
   sed '/^N/ d' <$sample.3bgs  > $sample.4bgs
done


echo -n "finished"
date

