Download examples/05_read_evaluation.py from AlejandroGZ/DRMHB: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/datasets/AlejandroGZ/DRMHB/resolve/main/examples/05_read_evaluation.py
- Command line
-
hf download hf://datasets/AlejandroGZ/DRMHB/examples/05_read_evaluation.py
-
curl -L -o 05_read_evaluation.py https://huggingface.co/datasets/AlejandroGZ/DRMHB/resolve/main/examples/05_read_evaluation.py
1.92 kB
| #!/usr/bin/env python3 | |
| """List/read/export original evaluation sidecars directly from H5AD, without raw arrays.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from drmhb_workflow import check_version | |
| from vibframe_anndata import ( | |
| export_evaluation_files, | |
| list_evaluation_files, | |
| read_evaluation_json, | |
| read_evaluation_table, | |
| ) | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("h5ad", type=Path) | |
| parser.add_argument("--path", help="Exact relative path from the inventory") | |
| parser.add_argument( | |
| "--source", help="Exact source ID; required for ambiguous paths" | |
| ) | |
| parser.add_argument( | |
| "--export", type=Path, help="Recover all original sidecars (refuses overwrites)" | |
| ) | |
| args = parser.parse_args() | |
| check_version() | |
| inventory = list_evaluation_files(args.h5ad) | |
| print(inventory[["source", "path", "kind", "size_bytes"]].to_string(index=False)) | |
| if args.path: | |
| if args.path.endswith(".parquet"): | |
| table = read_evaluation_table(args.h5ad, args.path, source=args.source) | |
| print("\nArrow schema:\n", table.schema) | |
| print(table.slice(0, 5).to_pandas().to_string(index=False)) | |
| elif args.path.endswith(".json"): | |
| print( | |
| json.dumps( | |
| read_evaluation_json(args.h5ad, args.path, source=args.source), | |
| indent=2, | |
| ) | |
| ) | |
| else: | |
| parser.error( | |
| "--path must be .parquet or .json; use export for other byte-exact formats" | |
| ) | |
| if args.export: | |
| paths = export_evaluation_files(args.h5ad, args.export, source=args.source) | |
| print( | |
| f"Exported {len(paths)} original files. Dataset-wide scope, not a relabelled subset." | |
| ) | |
| if __name__ == "__main__": | |
| main() | |