# module load singularity

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

bacass_id() {
    if [[ "$1" =~ ^[0-9]+$ ]]; then
        printf '%s_S\n' "$1"
    else
        printf '%s\n' "$1"
    fi
}

: > _01_plasmidID.sh
while IFS= read -r sample; do
    assembly_id=$(bacass_id "$sample")
    echo "srun --chdir $scratch_dir --output logs/PLASMIDID.${sample}.%j.log --job-name PLASMIDID_${sample} --partition short_idx --time 05:00:00 env - PATH=\"\$PATH\" singularity exec --bind /data/ucct/bi/references/ --bind ${scratch_dir} --bind ${scratch_dir}/../../ /data/ucct/bi/pipelines/singularity-images/depot.galaxyproject.org-singularity-plasmidid-1.6.5--hdfd78af_0.img plasmidID -1 ${scratch_dir}/../*ASSEMBLY/01-processing/fastp/${assembly_id}_R1.fastp.fastq.gz -2 ${scratch_dir}/../*ASSEMBLY/01-processing/fastp/${assembly_id}_R2.fastp.fastq.gz -d /data/ucct/bi/references/plasmidID/plasmid_ddbb/20200203/20200203_plasmids.fasta -s ${sample} -c ${scratch_dir}/../*ASSEMBLY/03-assembly/unicycler/${assembly_id}-unicycler.fasta -a ${scratch_dir}/plasmidID_annotation_config_file.txt --no-trim -o ${scratch_dir} &" >> _01_plasmidID.sh
done < ../samples_id.txt

# micromamba activate outbreakinfo
echo "python3 summary_report_pid.py -i NO_GROUP" > _02_summary_table.sh
