#!/bin/bash
#SBATCH -p queue_name
#SBATCH -N 1
#SBATCH -n 12
#SBATCH -J busco_v5
#SBATCH -t 168:00:00

module load python/3
thr=12

# Assembly
fasta=/path/to/genome/assembly.fasta
name=assembly.busco_v5

# Prepare conda environment
load_conda()
{
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/path/to/local/opt/miniconda2/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/path/to/local/opt/miniconda2/etc/profile.d/conda.sh" ]; then
            . "/path/to/local/opt/miniconda2/etc/profile.d/conda.sh"
        else
            export PATH="/path/to/local/opt/miniconda2/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
}

# Activate conda environenment
load_conda
conda activate /path/to/local/opt/miniconda2/envs/busco-5.0
# busco variables (should stay the same, unless running a different lineage)
busco=/path/to/local/opt/miniconda2/envs/busco-5.0/bin/busco
# export vars
export PATH=/path/to/local/opt/miniconda2/envs/busco-5.0/bin:$PATH
unset PYTHONPATH
export PYTHONPATH=/path/to/local/opt/miniconda2/envs/busco-5.0/lib/python3.9/site-packages:$PYTHONPATH

# Move to working directory
cd $work

# create tmp directory
tmp=./${name}_tmp
mkdir -p $tmp

# busco command
cmd=(
    python3 $busco
    --in $fasta
    --out $name
    --lineage_dataset actinopterygii_odb10
    --mode geno
    --cpu $thr
    --augustus
    --augustus_species zebrafish
    --f
)

# run command
echo "${cmd[@]}"
"${cmd[@]}"

# remove tmp directory
rm -r $tmp
