"""Commands do not run evaluations unless `evaluate` is explicitly invoked.""" from __future__ import annotations import argparse import json from pathlib import Path def main(): parser = argparse.ArgumentParser(prog="clc-mini-bench", description="CLC NKp46 benchmark preparation and frozen-feature evaluation") sub = parser.add_subparsers(dest="command", required=True) build = sub.add_parser("build", help="Prepare annotations, deduplicated datasets, and family folds") build.add_argument("--raw", type=Path, default=Path("data/raw/measurements.csv")) build.add_argument("--output", type=Path, default=Path("data/processed")) build.add_argument("--protocol", type=Path) check = sub.add_parser("validate", help="Validate both prepared datasets and file checksums") check.add_argument("--data-dir", type=Path, default=Path("data/processed")) embeddings = sub.add_parser("embed", help="Extract frozen embeddings with ESM-2 or a custom adapter") embeddings.add_argument("--dataset", type=Path, required=True) embeddings.add_argument("--output", type=Path, required=True) embeddings.add_argument("--adapter", help="Python module:function receiving label-free sequence records") embeddings.add_argument("--model", default="facebook/esm2_t33_650M_UR50D") embeddings.add_argument("--revision", help="Model repository revision or commit") embeddings.add_argument("--batch-size", type=int, default=16) embeddings.add_argument("--device", default="cpu") evaluate = sub.add_parser("evaluate", help="Run grouped outer CV with nested Ridge model selection") evaluate.add_argument("--dataset", type=Path, required=True) feature_source = evaluate.add_mutually_exclusive_group(required=True) feature_source.add_argument("--features", type=Path) feature_source.add_argument("--composition-baseline", action="store_true") evaluate.add_argument("--output", type=Path, required=True) evaluate.add_argument("--protocol", type=Path) args = parser.parse_args() if args.command == "build": from .data import build as run result = run(args.raw, args.output, args.protocol) print(json.dumps(result["datasets"], indent=2)) elif args.command == "validate": import pandas as pd from .data import sha256_file, validate_dataset manifest = json.loads((args.data_dir / "manifest.json").read_text()) for name, expected in manifest["files"].items(): if sha256_file(args.data_dir / name) != expected: raise ValueError(f"File checksum mismatch: {name}") for platform in ("omniflic", "omniclic"): frame = pd.read_csv(args.data_dir / f"{platform}_nkp46.csv") validate_dataset(frame) print(f"{platform}: {len(frame)} samples, {frame.family_id.nunique()} families, {frame.fold_id.nunique()} folds; valid") elif args.command == "embed": from .embeddings import extract_embeddings result = extract_embeddings(args.dataset, args.output, adapter=args.adapter, model_name=args.model, batch_size=args.batch_size, device=args.device, revision=args.revision) print(json.dumps(result, indent=2)) elif args.command == "evaluate": from .evaluation import evaluate as run result = run(args.dataset, args.output, features=args.features, baseline=args.composition_baseline, protocol_path=args.protocol) print(json.dumps(result["pooled_out_of_fold"], indent=2)) if __name__ == "__main__": main()