

#!/usr/bin/env bash
#SBATCH --time=02:00:00
#SBATCH --mem-per-cpu=64G
#SBATCH --cpus-per-task=4
#SBATCH --job-name=panaroo
#SBATCH --output=slurm_panaroo_%j.out
#SBATCH --error=slurm_panaroo_%j.err

# Load singularity module
module load singularityce

# Declare variables
# input data folder 
datadir=
# results folder (03_output_mrsa)
wd=
# Path to singularity images folder
singpath=/shares/amr.imm.uzh/bioinfo/singularity/

# Use the input data folder to generate an array containing the sample names
array=($(ls $datadir | cut -f 1 -d '_' | uniq))

# Move to the results folder, create input and output folders
cd $wd
mkdir -p panaroo/annotation_files
mkdir -p panaroo/panaroo_output


# generate soft links to the .gff files while looping through the sample names
for sample_id in "${array[@]}"
do
	ln -s $wd/$sample_id/prokka_annotation/$sample_id.gff $wd/panaroo/annotation_files/
done 

# Runs singularity on the annotations and send the output to the output folder
echo Starting panaroo $(date +"%T")
cd $wd/panaroo
$singpath/panaroo_1.3.0--pyhdfd78af_0.sif \
panaroo -i ./annotation_files/*.gff -o ./panaroo_output/ \
--clean-mode strict --remove-invalid-genes -a 'core' -t $SLURM_CPUS_PER_TASK
echo Done $(date +"%T")