# module load singularity

scratch_dir=$(echo $PWD | sed 's/\/data\/ucct\/bi\/scratch_tmp/\/scratch/g')
mkdir logs

cat ../samples_id.txt | xargs -I @@ echo "srun --chdir ${scratch_dir} --output logs/PICARD.@@.%j.log --job-name PICARD --cpus-per-task 1 --mem 8192 --partition short_idx --time 02:00:00 singularity exec -B ${scratch_dir}/../../../ /data/ucct/bi/pipelines/singularity-images/picard:2.25.1--hdfd78af_1 picard CollectHsMetrics -BI ${scratch_dir}/../../../REFERENCES/idt_rb1_panel_20221123.interval_list -TI ${scratch_dir}/../../../REFERENCES/idt_rb1_panel_20221123.interval_list -I ${scratch_dir}/../04-mapping/@@/@@_sorted.bam -O ${scratch_dir}/@@_hsMetrics.out -VALIDATION_STRINGENCY 'LENIENT' &" > _01_picardHsMetrics.sh

echo "echo "\"SAMPLE\",\"MEAN TARGET COVERAGE\", \"PCT USABLE BASES ON TARGET\",\"FOLD ENRICHMENT\",\"PCT TARGET BASES 10X\",\"PCT TARGET BASES 20X\",\"PCT TARGET BASES 30X\",\"PCT TARGET BASES 40X\",\"PCT TARGET BASES 50X\"" > hsMetrics_all.out" > _02_hsMetrics_all.sh
cat ../../samples_id.txt | xargs -I % echo "grep '^idt_rb1_panel' %_hsMetrics.out | awk 'BEGIN{FS=\"\\t\";OFS=\",\"}{print \"%\",\$34,\$12,\$13,\$49,\$50,\$60,\$61}' >> hsMetrics_all.out" >> _02_hsMetrics_all.sh

echo "srun --chdir ${scratch_dir} --output logs/MULTIQC.%j.log --job-name MULTIQC --cpus-per-task 1 --mem 8192 --partition short_idx --time 02:00:00 singularity exec -B ${scratch_dir}/../../../ /data/ucct/bi/pipelines/singularity-images/multiqc:1.9--py_1 multiqc -v --config ${scratch_dir}/multiqc_config.yaml .." > _03_run_multiqc.sh
