File size: 2,436 Bytes
88152cd | 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 | #!/usr/bin/env python3
# Copyright 2026 Emile de Bruyn
# SPDX-License-Identifier: Apache-2.0
"""Run the historical construction snapshot after strict input checks."""
import argparse
import hashlib
import os
import shutil
import subprocess
import sys
from pathlib import Path
import yaml
ROOT = Path(__file__).resolve().parents[1]
EXPECTED = {
"prosite_dat": "00f9598c5ddcef7b9d414cd24b968ad8a746e6b808e8fa525787f0e739f2e9c7",
"prosite_doc": "677dfd65f3818b7ebfc729d25abc40c633e72bb408a40eba39a3a770db3dfec1",
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--config", type=Path, default=ROOT / "construction/configs/reference.yaml")
args = parser.parse_args()
with args.config.open() as handle:
config = yaml.safe_load(handle)
for key, expected in EXPECTED.items():
path = Path(config["input"][key])
digest = hashlib.sha256(path.read_bytes()).hexdigest()
if digest != expected:
raise ValueError(f"{path}: wrong PROSITE input (SHA-256 {digest})")
if config.get("prosite_release") != "2021_04":
raise ValueError("configuration must pin PROSITE release 2021_04")
reference = Path(config["input"]["reference_motifbench_cases"])
if not reference.is_file():
raise FileNotFoundError(f"missing historical MotifBench reference cases: {reference}")
analysis = config["structure_analysis"]
if not analysis.get("use_foldseek") or not analysis.get("foldseek_conservation"):
raise ValueError("the historical configuration requires Foldseek conservation")
foldseek = shutil.which("foldseek")
if not foldseek:
foldseek = next((p for p in analysis.get("foldseek_candidates", [])
if Path(p).is_file() and os.access(p, os.X_OK)), None)
if not foldseek:
raise FileNotFoundError("Foldseek executable not found")
result = subprocess.run([foldseek, "version"], check=True, capture_output=True, text=True)
print(f"Foldseek version: {result.stdout.strip() or result.stderr.strip()}")
output = Path(config["output_root"])
if output.exists():
raise FileExistsError(f"refusing to reuse existing output directory: {output}")
sys.path.insert(0, str(ROOT / "construction"))
from motifbench_prosite.cli import main as run_pipeline
run_pipeline(["--config", str(args.config)])
if __name__ == "__main__":
main()
|