File size: 1,921 Bytes
881cb3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()