File size: 2,158 Bytes
5fcd10c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import hashlib
import json
from pathlib import Path

try:
    import yaml
except ImportError as exc:
    raise SystemExit("PyYAML is required for dataset validation: pip install pyyaml") from exc


def sha256(path: Path) -> str:
    h = hashlib.sha256()
    with path.open("rb") as f:
        for chunk in iter(lambda: f.read(1024 * 1024), b""):
            h.update(chunk)
    return h.hexdigest()


def check_json(path: Path) -> None:
    data = json.loads(path.read_text(encoding="utf-8"))
    if data.get("dialect") != "alphafold3":
        raise AssertionError(f"{path} dialect is not alphafold3")
    if "sequences" not in data or not data["sequences"]:
        raise AssertionError(f"{path} has no sequences")


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--root", default=".")
    parser.add_argument("--skip-hash", action="store_true")
    args = parser.parse_args()

    root = Path(args.root).resolve()
    manifest = yaml.safe_load((root / "metadata" / "file_manifest.yaml").read_text(encoding="utf-8"))

    for entry in manifest["dataset_directories"]:
        path = root / entry["path"]
        if not path.exists():
            raise AssertionError(f"missing linked dataset directory: {entry['path']}")

    for entry in manifest["files"]:
        path = root / entry["path"]
        if not path.is_file():
            raise AssertionError(f"missing verified data file: {entry['path']}")
        if path.name != Path(entry["source_path"]).name:
            raise AssertionError(f"filename mismatch: {entry['path']}")
        if path.stat().st_size != entry["size_bytes"]:
            raise AssertionError(f"size mismatch: {entry['path']}")
        if not args.skip_hash and sha256(path) != entry["sha256"]:
            raise AssertionError(f"sha256 mismatch: {entry['path']}")

    check_json(root / "data" / "infer_input_data" / "all_data" / "7r6r_data.json")
    check_json(root / "data" / "infer_input_data" / "all_data" / "t1119_data.json")
    print("dataset_validation_ok: true")


if __name__ == "__main__":
    main()