#PBS -q bl2x220g7q
#PBS -l select=1:ncpus=5:mem=10g
#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/202204191141Polya/4c_plasmid/2022-04-08/
cd $WORK_DIR; 
[ -d stat ] || mkdir align; 
cd align;
# Declare a string array with type
declare -a files=("61")

for file in "${files[@]}"
do
echo ${file}

## align to hg38 and plasmid with CMV
#bwa mem -t 5 -M /mnt/storage/home/psbelokopytova/scratch/202204191141Polya/4c_plasmid/genome/hg38_plasmid_cmv_oldseq.fa $WORK_DIR/cutadapt/cutIL_${file}_1.fq.gz $WORK_DIR/cutadapt/cutIL_${file}_2.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;
python /mnt/storage/home/psbelokopytova/scratch/202202211224Polina_data/4c_plasmid/modify_bedgraph.py $WORK_DIR $file
## create sam
samtools view $WORK_DIR/align/${file}/${file}.sorted.bam > $WORK_DIR/align/${file}/${file}.sorted.sam
## claculatite mapping statistics
samtools idxstats $WORK_DIR/align/${file}/${file}.sorted.bam > $WORK_DIR/align/${file}/${file}_mapping_stat.txt
done
