#!/bin/bash # submit_all_dto.sh # Submits one SLURM array job per {perturbation}/{binding_source} combination. # # Run from the DTO root -- the directory holding index/, dto_lists.sqsh and # run_dto.sh. # # Usage: # bash submit_all.sh [--dry-run] # bash submit_all.sh --test # single combo, array=1-5 # bash submit_all.sh --dry-run --test # # The input tree is split in two: index/ holds the per-pair lookup.txt and # background.csv and is read straight off the filesystem, while the ranked lists # live in the SquashFS image and are opened by each task (see run_dto.sh). Pairs # are therefore enumerated from index/, and results are written to a third root # so nothing lands inside either input tree. # # Overridable: # DTO_INDEX_ROOT default /index # DTO_RESULTS_ROOT default /results # DTO_INPUT_SQUASHFS default /dto_lists.sqsh when that file exists; # exported to the tasks, which read the lists from it. # Leave unset only if the lists are unpacked on disk. set -euo pipefail DTO_ROOT=$(pwd) SCRIPT="${DTO_ROOT}/run_dto.sh" INDEX_ROOT="${DTO_INDEX_ROOT:-${DTO_ROOT}/index}" RESULTS_ROOT="${DTO_RESULTS_ROOT:-${DTO_ROOT}/results}" # Default the archive to the one sitting next to this script, and tell the tasks # which path prefix in lookup.txt it stands in for. if [[ -z "${DTO_INPUT_SQUASHFS:-}" && -f "${DTO_ROOT}/dto_lists.sqsh" ]]; then DTO_INPUT_SQUASHFS="${DTO_ROOT}/dto_lists.sqsh" fi export DTO_INPUT_SQUASHFS="${DTO_INPUT_SQUASHFS:-}" export DTO_INPUT_ROOT="${DTO_INPUT_ROOT:-${DTO_ROOT}/lists}" DRY_RUN=false TEST_PERT="" TEST_BINDING="" # Parse args while [[ $# -gt 0 ]]; do case "$1" in --dry-run) DRY_RUN=true; shift ;; --test) TEST_PERT="${2:-}" TEST_BINDING="${3:-}" if [[ -z "$TEST_PERT" || -z "$TEST_BINDING" ]]; then echo "Usage: --test e.g. --test hackett cc" >&2 exit 1 fi shift 3 ;; *) echo "Unknown argument: $1" >&2; exit 1 ;; esac done $DRY_RUN && echo "[dry-run] No jobs will be submitted." [[ -n "$TEST_PERT" ]] && echo "[test] Single combo: ${TEST_PERT}/${TEST_BINDING}, array=1-5" if [[ -n "$DTO_INPUT_SQUASHFS" ]]; then if [[ ! -f "$DTO_INPUT_SQUASHFS" ]]; then echo "ERROR: DTO_INPUT_SQUASHFS does not exist: $DTO_INPUT_SQUASHFS" >&2 exit 1 fi echo "Ranked lists: ${DTO_INPUT_SQUASHFS} (standing in for ${DTO_INPUT_ROOT})" else echo "Ranked lists: unpacked, read directly from the paths in lookup.txt" fi echo "Index: ${INDEX_ROOT}" echo "Results: ${RESULTS_ROOT}" echo "" # An unmatched glob would otherwise be passed through literally and counted as a # skip, so a wrong root reports "Submitted: 0" and exits clean. Fail instead. shopt -s nullglob LOOKUPS=("${INDEX_ROOT}"/*/*/lookup.txt) shopt -u nullglob if (( ${#LOOKUPS[@]} == 0 )); then echo "ERROR: no //lookup.txt found under ${INDEX_ROOT}" >&2 echo " Run from the DTO root, or set DTO_INDEX_ROOT." >&2 exit 1 fi submitted=0 skipped=0 for LOOKUP in "${LOOKUPS[@]}"; do COMBO_DIR=$(dirname "$LOOKUP") BINDING_SRC=$(basename "$COMBO_DIR") PERT=$(basename "$(dirname "$COMBO_DIR")") # Results go to their own root, mirroring /, so neither # input tree is written into: index/ stays exactly what was rsynced, and the # ranked lists are read-only inside the image. OUTPUT_DIR="${RESULTS_ROOT}/${PERT}/${BINDING_SRC}" BACKGROUND="${COMBO_DIR}/background.csv" # If --test, skip everything except the requested combo if [[ -n "$TEST_PERT" ]]; then [[ "$PERT" == "$TEST_PERT" && "$BINDING_SRC" == "$TEST_BINDING" ]] || continue fi if [[ ! -f "$BACKGROUND" ]]; then echo "SKIP: $PERT/$BINDING_SRC — background.csv not found at $BACKGROUND" >&2 ((skipped++)) || true continue fi N=$(wc -l < "$LOOKUP") if [[ "$N" -eq 0 ]]; then echo "SKIP: $PERT/$BINDING_SRC — empty lookup" >&2 ((skipped++)) || true continue fi # In test mode, only run first 5 tasks ARRAY_SPEC="1-${N}" [[ -n "$TEST_PERT" ]] && ARRAY_SPEC="1-5" JOB_NAME="dto_${PERT}_${BINDING_SRC}" LOG_DIR="${OUTPUT_DIR}/logs" mkdir -p "$LOG_DIR" echo "Submitting: $PERT/$BINDING_SRC (array=${ARRAY_SPEC})" if $DRY_RUN; then echo " sbatch --job-name=${JOB_NAME} \\" echo " --array=${ARRAY_SPEC} \\" echo " --output=${LOG_DIR}/dto_%A_%a.out \\" echo " --error=${LOG_DIR}/dto_%A_%a.err \\" echo " ${SCRIPT} ${LOOKUP} ${OUTPUT_DIR} ${BACKGROUND}" else sbatch \ --job-name="${JOB_NAME}" \ --array="${ARRAY_SPEC}" \ --output="${LOG_DIR}/dto_%A_%a.out" \ --error="${LOG_DIR}/dto_%A_%a.err" \ "${SCRIPT}" "${LOOKUP}" "${OUTPUT_DIR}" "${BACKGROUND}" fi ((submitted++)) || true done if [[ -n "$TEST_PERT" && $submitted -eq 0 && $skipped -eq 0 ]]; then echo "ERROR: combo ${TEST_PERT}/${TEST_BINDING} not found — check pert and binding_src names" >&2 exit 1 fi echo "" echo "Done. Submitted: ${submitted} Skipped: ${skipped}"