## to use: put 2 narrowPeak and 2 corresponding bed files in the folder
## usage: ./pipe.sh  *.narrowPeak

pipe_path="/home/shaopengliu/pipe_script/ATAC-seq/"
small=$1
big=$2
echo $small
echo $big

inter1=`echo ${small#peakcall_}`
name1=`echo ${inter1%_peaks.narrowPeak}`
bed1=$name1'.extended.bed'

inter2=`echo ${big#peakcall_}`
name2=`echo ${inter2%_peaks.narrowPeak}`
bed2=$name2'.extended.bed'




# find the shared peak
intersectBed -a $small -b $big -f 0.1 -F 0.1 -wa -wb > shared_peak.txt

# merge the 1_multi projection peaks
python $pipe_path'compare_replicate/merge_dup_peaks.py' shared_peak.txt nodup_shared_peak.txt

# merge overlap range
python $pipe_path'compare_replicate/merge_peak_range.py' nodup_shared_peak.txt count.txt

# count the reads under peak
# file1
python $pipe_path'compare_replicate/cheng_compare/try_compare.py' $name1/ $bed1 count.txt
mv reads.txt $name1'.txt'
# file2
python $pipe_path'compare_replicate/cheng_compare/try_compare.py' $name2/ $bed2 count.txt
mv reads.txt $name2'.txt'


# plot
python3.5  $pipe_path'compare_replicate/plot_overlap.py'   $name1'.txt'    $name2'.txt'



