# conda activate mtbseq
# this will be performed in case a tree is requested
mkdir logs
scratch_dir=$(echo $(pwd) | sed "s@/data/bi/scratch_tmp/@/scratch/@g")

# conda activate mtbseq
mkdir Amend Bam Called Classification GATK_Bam Groups Joint Mpileup Position_Tables Statistics
cat ../*/samples.txt > samples.txt

####Create sybolik links to the folders already created
cd Bam; ln -s ../../*/Bam/* . ; cd -
cd Called; ln -s ../../*/Called/* . ; cd -
cd GATK_Bam; ln -s ../../*/GATK_Bam/* . ; cd -
cd Mpileup; ln -s ../../*/Mpileup/* . ; cd -
cd Position_Tables; ln -s ../../*/Position_Tables/* . ; cd -

##### Create join scripts
echo "srun --job-name MTBSEQ_JOIN  --output logs/MTBSEQ_JOIN.%j.log --partition middle_obx --mem 48G --chdir ${scratch_dir} --cpus-per-task 10 MTBseq --step TBjoin --threads 5 --samples samples.txt &" > _01_tb_join.sh
echo "srun --job-name MTBSEQ_AMEND  --output logs/MTBSEQ_AMEND.%j.log --partition middle_obx --mem 48G --chdir ${scratch_dir} --cpus-per-task 10 MTBseq --step TBamend --threads 5 --samples samples.txt &" > _02_tb_amend.sh
echo "srun --job-name MTBSEQ_GROUPS --output logs/MTBSEQ_GROUPS.%j.log --partition middle_obx --mem 48G --chdir ${scratch_dir} --cpus-per-task 10 MTBseq --step TBgroups --threads 5 --samples samples.txt &" > _03_tb_groups.sh

# conda activate iqtree
echo "srun --chdir ${scratch_dir} --output logs/IQTREEFULLALIGN.%j.log --job-name IQTREEFULLALIGN --cpus-per-task 20 --mem 15G --partition short_idx --time 08:00:00 iqtree -s Amend/*amended_u95_phylo_w12.plainIDs.fasta -m K3Pu+F+I -T 20 -B 1000 -pre phylo.iqtree.bootstrap &" > _04_iqtreeall.sh