# To run saturation analysis based on *.extended.bed file
# run in target folder in which target file locate
# parameter: file_name

bed_file=$1
temp=`echo ${bed_file##*/}`
name=`echo ${temp%%.extended.bed}`
genome=mm
pipe_path="/home/shaopengliu/pipe_script/ATAC-seq/"


# step1, sub-sampling
echo "processing sub-sampling process......"
date

python3.5 $pipe_path'saturation/saturation_sub-samping.py'  $bed_file
echo "sub-sampling done......"


# step2, collect file and run peak-calling
mkdir saturation_$name
mv *.extended.bed ./saturation_$name/
cd ./saturation_$name

for file in `ls *.extended.bed`;
do
	macs2 callpeak -t $file -g $genome -q 0.01 -n 'peakcall_'$file --nomodel --shift -100 --extsize 200
done
echo "peak calling done......"


# step3, get results
echo "getting the results"
python3.5 $pipe_path'saturation/saturation_result_by_Million.py' 'peakcall_'$name'.extended.bed_peaks.narrowPeak'

rm *sample*.extended.bed
mv *.extended.bed ../
cd ..
echo "finished"

 

