#!/usr/bin/env bash
# This is a wrapper for the pipeline script
# It:
# - loads require modules and conda environments
# - parses the variables directly to the python script

SCRIPTDIRNAME=$(readlink -f $(dirname "$BASH_SOURCE"))

# add "bin" to PATH
if [[ ":$PATH:" != *":${SCRIPTDIRNAME}:"* ]];then
	export PATH=${PATH}:${SCRIPTDIRNAME}
fi

TOOLDIR=$(dirname "$SCRIPTDIRNAME")

# find out if you are running on biowulf or frce
hpc_name=$(scontrol show config | grep ClusterName | sed "s/^.*= //")
# load conda
if [[ $hpc_name == biowulf ]]; then
	module load singularity snakemake/7
elif [[ $hpc_name == fnlcr ]]; then
	module load singularity
	export PATH="/mnt/projects/CCBR-Pipelines/bin:$PATH"
else
	echo "You are NOT running on BIOWULF or on FRCE"
	echo "Please make sure that the following tools are available:"
	echo "  - python >= 3.11"
	echo "  - singularity "
	echo "  - snakemake = 7"
fi

${TOOLDIR}/main.py "$@" || true
