File size: 3,902 Bytes
5888f5c | 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 | #!/usr/bin/env python3
import argparse
import csv
import hashlib
from pathlib import Path
try:
import yaml
except Exception as exc:
raise SystemExit(f"PyYAML is required to parse manifest.yaml: {exc}")
def count_lines(path: Path) -> int:
with path.open("r", encoding="utf-8") as handle:
return sum(1 for line in handle if line.strip())
def sha256_file(path: Path) -> str:
h = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
h.update(chunk)
return h.hexdigest()
parser = argparse.ArgumentParser()
parser.add_argument("--data-root", default=".")
parser.add_argument("--sample-pt", type=int, default=3)
parser.add_argument("--require-checksums", action="store_true")
args = parser.parse_args()
root = Path(args.data_root).resolve()
manifest_path = root / "manifest.yaml"
if not manifest_path.is_file():
raise SystemExit(f"missing manifest: {manifest_path}")
data = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
required_keys = [
"resource",
"platform_resource",
"website_integration",
"runtime",
"onescience",
"runtime_package",
"files",
"relations",
"run_matrix",
"capabilities",
"commands",
"expected_outputs",
"diagnostics",
"domain_extension",
]
missing = [k for k in required_keys if k not in data]
if missing:
raise SystemExit(f"missing manifest keys: {missing}")
if data["resource"]["id"] != "OneScience/proteinmpnn":
raise SystemExit(f"unexpected resource id: {data['resource']['id']}")
if data["platform_resource"]["primary"]["repo_id"] != "OneScience/proteinmpnn":
raise SystemExit("platform_resource.primary.repo_id mismatch")
ds = root / "pdb_2021aug02_sample"
for rel in ["README", "list.csv", "valid_clusters.txt", "test_clusters.txt"]:
p = ds / rel
if not p.is_file() or p.stat().st_size == 0:
raise SystemExit(f"missing or empty file: {p}")
pdb_dir = ds / "pdb"
if not pdb_dir.is_dir():
raise SystemExit(f"missing pdb dir: {pdb_dir}")
pt_files = sorted(pdb_dir.rglob("*.pt"))
if len(pt_files) != 870:
raise SystemExit(f"unexpected pt file count: {len(pt_files)}")
with (ds / "list.csv").open("r", encoding="utf-8", newline="") as handle:
reader = csv.DictReader(handle)
expected = ["CHAINID", "DEPOSITION", "RESOLUTION", "HASH", "CLUSTER", "SEQUENCE"]
if reader.fieldnames != expected:
raise SystemExit(f"unexpected list.csv columns: {reader.fieldnames}")
rows = 0
for row in reader:
rows += 1
if rows <= 5 and not row["SEQUENCE"]:
raise SystemExit("empty sequence in list.csv sample")
if rows <= 0:
raise SystemExit("list.csv has no data rows")
valid_lines = count_lines(ds / "valid_clusters.txt")
test_lines = count_lines(ds / "test_clusters.txt")
if valid_lines <= 0 or test_lines <= 0:
raise SystemExit("cluster split files must be non-empty")
checksum_path = root / "checksums.sha256"
if args.require_checksums and not checksum_path.is_file():
raise SystemExit(f"missing checksum manifest: {checksum_path}")
if checksum_path.is_file():
checksum_lines = count_lines(checksum_path)
if checksum_lines < 874:
raise SystemExit(f"checksum manifest has too few entries: {checksum_lines}")
sample = []
for path in pt_files[: max(args.sample_pt, 0)]:
if path.stat().st_size <= 0:
raise SystemExit(f"empty pt file: {path}")
sample.append(f"{path.relative_to(root)}:{path.stat().st_size}:{sha256_file(path)[:16]}")
print("DATASET_VALIDATION_OK")
print(f"manifest_resource={data['resource']['id']}")
print(f"data_files={sum(1 for p in ds.rglob('*') if p.is_file())}")
print(f"pt_files={len(pt_files)}")
print(f"list_rows={rows}")
print(f"valid_clusters={valid_lines}")
print(f"test_clusters={test_lines}")
if sample:
print("sample_pt=" + ",".join(sample))
|