Datasets:
File size: 5,401 Bytes
163eea8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #!/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 <pert_db> <binding_db> # single combo, array=1-5
# bash submit_all.sh --dry-run --test <pert_db> <binding_db>
#
# 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 <root>/index
# DTO_RESULTS_ROOT default <root>/results
# DTO_INPUT_SQUASHFS default <root>/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 <pert> <binding_src> 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 <pert_db>/<binding_db>/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 <pert_db>/<binding_db>, 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}"
|