#PBS -q dl560g10q@vm-pbs2
#PBS -l select=1:ncpus=5:mem=10g
#PBS -l walltime=3:00:00
#PBS -l cput=30:00:00

source activate nn_Polina_tf2;
export PATH=$PATH:~/programms/bwa-0.7.17;
WORK_DIR=~/loxP_project/2022-06-14_rings/
cd $WORK_DIR; mkdir align; 
cd align;
# Declare a string array with type

declare -a files=("undetermine")

for file in "${files[@]}"
do
echo ${file}
mkdir ${file}
## align paired reads
bwa mem -t 5 -M /mnt/storage/home/psbelokopytova/insulatory_index/bds_pipeline_genome_data/hg38/bwa_index/GRCh38_no_alt_analysis_set_GCA_000001405.15.fasta $WORK_DIR/cutadapt/cut_barc_praimers_cutIL_undetermine_R1.fq.gz $WORK_DIR/cutadapt/cut_barc_praimers_cutIL_undetermine_R2.fq.gz | samtools view -bS -@ 5 | samtools sort > $WORK_DIR/align/${file}/${file}.sorted.bam
samtools index $WORK_DIR/align/${file}/${file}.sorted.bam > $WORK_DIR/align/${file}/${file}.sorted.bam.bai
## create coverage file
~/programms/bedtools2/bin/bedtools genomecov -ibam $WORK_DIR/align/${file}/${file}.sorted.bam -bg > $WORK_DIR/align/${file}/${file}.bedgraph
## create sam
samtools view $WORK_DIR/align/${file}/${file}.sorted.bam > $WORK_DIR/align/${file}/${file}.sorted.sam
python ~/loxP_project/plot_depth_hist.py $WORK_DIR/align/${file}/${file}.bedgraph $WORK_DIR/align/${file}/${file}.modifyed.bedgraph
done
