#!/usr/bin/env bash
# DeepCoil contract runner.
#
#   ./run --check                 verify isolated env bin/deepcoil (exit 0/1)
#   ./run [deepcoil args...]      run $DEEPCOIL_ENV_PREFIX/bin/deepcoil
#
# 8-feature pipeline runs: ./run -i in.fasta -out_path OUT -n_cpu N
# DeepCoil writes per-accession <safe_id>.out files into OUT (tab-separated:
# aa, cc, raw_cc, prob_a, prob_d). PhaSePred binarizes max(raw_cc) >= 0.82.
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
env_prefix="${DEEPCOIL_ENV_PREFIX:-$repo_root/.external_envs/deepcoil}"
exe="$env_prefix/bin/deepcoil"

if [[ "${1:-}" == "--check" ]]; then
  if [[ ! -x "$exe" ]]; then
    echo "DeepCoil executable not found: $exe (install: bash tools/DeepCoil/install.sh)" >&2
    exit 1
  fi
  exit 0
fi

if [[ ! -x "$exe" ]]; then
  cat >&2 <<EOF
DeepCoil executable not found: $exe

Create the isolated environment with:
  bash tools/DeepCoil/install.sh
(or point DEEPCOIL_ENV_PREFIX at an existing prefix)
EOF
  exit 1
fi

exec "$exe" "$@"