DRMHB / examples /05_read_evaluation.py
AlejandroGZ's picture
v2.6 dataset
881cb3b
Raw History Blame Contribute Delete
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()