| |
| import argparse |
| import gzip |
| import hashlib |
| import sys |
| from pathlib import Path |
|
|
| REQUIRED_FASTA = [ |
| "chr20.fa", |
| "chr21.fa", |
| "chr22.fa", |
| "chr20_21_22.fa", |
| "chr20.fa.gz", |
| "chr21.fa.gz", |
| "chr22.fa.gz", |
| ] |
|
|
| REQUIRED_PREPROCESSED_PREFIXES = [ |
| "chr20_21_22_uint8_distinct_byte-level_train", |
| "chr20_21_22_uint8_distinct_byte-level_val", |
| "chr20_21_22_uint8_distinct_byte-level_test", |
| ] |
|
|
|
|
| def sha256(path: Path) -> str: |
| h = hashlib.sha256() |
| with path.open("rb") as f: |
| for block in iter(lambda: f.read(1024 * 1024), b""): |
| h.update(block) |
| return h.hexdigest() |
|
|
|
|
| def read_sha_manifest(path: Path) -> dict[str, str]: |
| result = {} |
| for line in path.read_text().splitlines(): |
| if not line.strip(): |
| continue |
| digest, filename = line.split(None, 1) |
| result[filename.strip()] = digest |
| return result |
|
|
|
|
| def read_sizes(path: Path) -> dict[str, int]: |
| result = {} |
| for line in path.read_text().splitlines(): |
| if not line.strip(): |
| continue |
| filename, size = line.split("\t", 1) |
| result[filename] = int(size) |
| return result |
|
|
|
|
| def check_fasta_head(path: Path) -> bool: |
| opener = gzip.open if path.suffix == ".gz" else open |
| with opener(path, "rt", encoding="utf-8", errors="replace") as f: |
| for line in f: |
| line = line.strip() |
| if line: |
| return line.startswith(">") |
| return False |
|
|
|
|
| def main() -> int: |
| parser = argparse.ArgumentParser(description="Validate the OneScience Evo2 mini genome dataset.") |
| parser.add_argument("--dataset-root", default="data_mini", help="Dataset root in the dataset repository.") |
| parser.add_argument("--package-root", default=".", help="Dataset package root. Default: current directory.") |
| parser.add_argument("--skip-sha256", action="store_true", help="Skip SHA256 checks.") |
| args = parser.parse_args() |
|
|
| root = Path(args.package_root).resolve() |
| dataset_root = (root / args.dataset_root).resolve() if not Path(args.dataset_root).is_absolute() else Path(args.dataset_root) |
| genome_root = dataset_root / "genome_data" |
| preprocessed = genome_root / "preprocessed_data" |
| errors: list[str] = [] |
|
|
| if not genome_root.is_dir(): |
| errors.append(f"missing genome_data directory: {genome_root}") |
|
|
| for rel in REQUIRED_FASTA: |
| path = genome_root / rel |
| if not path.is_file(): |
| errors.append(f"missing FASTA file: genome_data/{rel}") |
| else: |
| try: |
| if not check_fasta_head(path): |
| errors.append(f"FASTA header not found in first record: genome_data/{rel}") |
| except Exception as exc: |
| errors.append(f"cannot read FASTA file genome_data/{rel}: {exc}") |
|
|
| for prefix in REQUIRED_PREPROCESSED_PREFIXES: |
| bin_path = preprocessed / f"{prefix}.bin" |
| idx_path = preprocessed / f"{prefix}.idx" |
| if not bin_path.is_file(): |
| errors.append(f"missing preprocessed bin: {bin_path}") |
| elif bin_path.stat().st_size <= 0: |
| errors.append(f"empty preprocessed bin: {bin_path}") |
| if not idx_path.is_file(): |
| errors.append(f"missing preprocessed idx: {idx_path}") |
| elif idx_path.stat().st_size <= 0: |
| errors.append(f"empty preprocessed idx: {idx_path}") |
|
|
| size_manifest = root / "metadata" / "data_mini.files.tsv" |
| if size_manifest.is_file(): |
| for rel, expected_size in read_sizes(size_manifest).items(): |
| path = dataset_root / rel |
| if not path.is_file(): |
| errors.append(f"file listed in size manifest is missing: {rel}") |
| elif path.stat().st_size != expected_size: |
| errors.append(f"size mismatch for {rel}: {path.stat().st_size} != {expected_size}") |
| else: |
| errors.append("missing metadata/data_mini.files.tsv") |
|
|
| if not args.skip_sha256: |
| sha_manifest = root / "metadata" / "data_mini.sha256" |
| if sha_manifest.is_file(): |
| for rel, expected_digest in read_sha_manifest(sha_manifest).items(): |
| path = dataset_root / rel |
| if path.is_file() and sha256(path) != expected_digest: |
| errors.append(f"sha256 mismatch for {rel}") |
| else: |
| errors.append("missing metadata/data_mini.sha256") |
|
|
| if errors: |
| for error in errors: |
| print(f"[FAIL] {error}", file=sys.stderr) |
| return 1 |
|
|
| print("[OK] Evo2 mini dataset files, FASTA readability, preprocessed splits, sizes and hashes passed validation.") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|