#PBS -q xl230g9q
#PBS -l select=1:ncpus=5:mem=20g
#PBS -l walltime=01:00:00
#PBS -l cput=01:00:00

export PATH=$PATH:~/programms/bwa-0.7.17;
source activate nn_Polina_tf2
WORK_DIR=/mnt/scratch/ws/psbelokopytova/202301211721polina/4c_plasmid/2022-11-22/
cd $WORK_DIR; 
[ -d stat ] || mkdir align; 
cd align;
# Declare a string array with type
declare -a files=("NP_Tru9I" "NP_MseI")

for file in "${files[@]}"
do
echo ${file}
[ -d stat ] || mkdir ${file};

## align pr_plasmid1_cutMseI
bwa mem -t 5 -M -R '@RG\tID:pr_plasmid1_woMseI' /mnt/storage/home/psbelokopytova/scratch/202301211721polina/4c_plasmid/genome/hg38_NP_seq $WORK_DIR/cutadapt/${file}_pr_plasmid1_cutMseI.fq | samtools view -bS -@ 5 | samtools sort > $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutMseI.sorted.bam
##create index
samtools index $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutMseI.sorted.bam > $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutMseI.sorted.bam.bai;
##calculate statistics
samtools idxstats $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutMseI.sorted.bam > $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutMseI.sorted.stat.txt
##get sam file with supplement for hi-c statistics
#samtools view -f 256 $WORK_DIR/align/${file}/${file}_pr_plasmid1_cutTaiI.sorted.bam > #$WORK_DIR/align/${file}/${file}_pr_plasmid1_cutTaiI_supplement.sorted.sam
done
