#!/usr/bin/env bash
#
# orthologer - Pipeline for deducing orthology from fasta files.
# Copyright (C) 2005-2023 E. Zdobnov lab: F. Tegenfeldt
# <fredrik.tegenfeldt@unige.ch> based on code by E. Kriventseva
#
# This file is part of orthologer.
#
# orthologer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# orthologer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with orthologer.  If not, see <http://www.gnu.org/licenses/>.
#
[[ $# -eq 1 ]] || { echo "usage: $0 <common.sh>"; exit 0; }
[[ -f $1 ]] || { echo "error: input file is not readable - should be a common.sh"; exit 255; }
source $1 || { echo "error: failed sourcing input file $1"; exit 255; }
export DIR_PROJECT=$(dirname $1)

set -u
[[ -f $DIR_ORTHOLOGER/bin/check_setup_common.sh ]] || { echo "error: missing script $DIR_ORTHOLOGER/bin/check_setup_common.sh"; exit 255; }
source $DIR_ORTHOLOGER/bin/check_setup_common.sh
[[ $? -eq 0 ]] || { echo "error: failed loading script $DIR_ORTHOLOGER/bin/check_setup_common.sh"; exit 255; }

set_executables
#--------------------------------------------------------------
export CHK_DUMP_LEVEL=2

check_var_setup DIR DIR_BRHCLUS
check_var_setup DIR DIR_BLAST
check_var_setup DIR DIR_SWIPE     $(tst_var "ALIGNMENT_LABEL" "SWIPE")
check_var_setup DIR DIR_MMSEQS    $(tst_var "ALIGNMENT_LABEL" "MMSEQS")
check_var_setup DIR DIR_CDHIT     $(tst_var "SELECT_LABEL"    "CDHIT")

check_var_setup EXE EXE_BRHCLUS    0
check_var_setup EXE EXE_MMSEQS     0
check_var_setup EXE EXE_CDHIT_PROT 0
check_var_setup EXE EXE_BLASTP     0
check_var_setup EXE EXE_SEGMASKER  0

if (( ERROR_COUNT > 0 )); then
    echo "Found $ERROR_COUNT errors!"
    exit 255
fi
exit 0
