#!/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/>.
#
#--- check if environment is ok -----------------
[ "${LOADED_COMMON_PIPELINE_SH+1}" == "" ] && echo "ERROR $0 : main config has not been loaded" 1>&2 && exit 255
#------------------------------------------------

# get args
[ $# -eq 1 ] || fatal_msg "usage: $0 <og file>"

ogfile=$1
cmd="${DIR_ORTHOLOGER_BIN}/dist_count.pl"

# check files
check_file     "$0" "$ogfile"  || exit 255
check_file     "$0" "$PL_TODO" || exit 255
check_file_exe "$0" "$cmd"     || exit 255

# run command
"$cmd" "$ogfile" "$PL_TODO"
[ $? -eq 0 ] || fatal_msg "dist_count.pl failed for input file $ogfile"

[ -f "${ogfile}.dist" ]            || fatal_msg "dist_count.pl failed to produce ${ogfile}.dist"
[ -f "${ogfile}.dist_count" ]      || fatal_msg "dist_count.pl failed to produce ${ogfile}.dist_count"
[ -f "${ogfile}.dist_111-og-ids" ] || fatal_msg "dist_count.pl failed to produce ${ogfile}.dist_111-og-ids"
