from __future__ import annotations import gzip import json import sys from pathlib import Path import pandas as pd ROOT = Path(__file__).resolve().parent WORKSPACE = Path(__file__).resolve().parents[3] sys.path.insert(0, str(WORKSPACE / "src")) from oa_tl import multiscale_pseudosnp_linear_autoencoder as model # noqa: E402 EXPECTED_FEATURE_HASH = "a9ce199b9a6e7c6185cd3945ef468e0051f89fc813277e86ab4c8ce23cdbc858" DEVELOPMENT = WORKSPACE / "outputs" / "runs" / "20260807T1305Z_expanded_discovery_dataset" / "development.tsv" def read_jsonl_gz(path: Path): with gzip.open(path, "rt", encoding="utf-8") as handle: for line in handle: yield json.loads(line) def main() -> None: if model._sha256_file(DEVELOPMENT) != model.GOVERNED_DEVELOPMENT_SHA256: raise RuntimeError("governed development table hash changed") full = pd.read_csv(DEVELOPMENT, sep="\t", low_memory=False) cohort = model.select_oa2025_pip_triplets(full, threshold=model.PIP_THRESHOLD) fold_map, fold_receipt = model.formal_full_graph_fold_map(full) cohort["outer_fold"] = cohort["split_group_id"].astype(str).map(fold_map).astype(int) exported = list(read_jsonl_gz(ROOT / "data" / "supervised_model_input.jsonl.gz")) if len(exported) != len(cohort): raise RuntimeError("exported supervised cohort row count differs") for expected, actual in zip(cohort.itertuples(index=False), exported): if ( str(expected.example_id) != actual["example_id"] or int(expected.label) != actual["label"] or str(expected.sequence_ref) != actual["sequence_ref"] or str(expected.sequence_alt) != actual["sequence_alt"] or int(expected.outer_fold) != actual["outer_fold"] ): raise RuntimeError(f"supervised source alignment failed: {actual['example_id']}") pseudo_paths = sorted((ROOT / "data").glob("pretraining-*.jsonl.gz")) pairs = ( (record["sequence_ref"], record["sequence_alt"]) for path in pseudo_paths for record in read_jsonl_gz(path) ) features = model.multiscale_feature_matrix(pairs) feature_hash = model._sha256_csr(features) if feature_hash != EXPECTED_FEATURE_HASH: raise RuntimeError(f"pseudo-SNP feature hash mismatch: {feature_hash}") print( "PASS: governed 168-row cohort and fold map align; " f"20,000 x 9,216 feature CSR SHA256={feature_hash}; " f"fold_assignment_sha256={fold_receipt['assignment_sha256']}" ) if __name__ == "__main__": main()