Download example.py from TheTinyIntelLab/opal-norman: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/TheTinyIntelLab/opal-norman/resolve/main/example.py
- Command line
-
hf download hf://TheTinyIntelLab/opal-norman/example.py
-
curl -L -o example.py https://huggingface.co/TheTinyIntelLab/opal-norman/resolve/main/example.py
1.11 kB
| """Predict a supported source-specific pair without fitting or scoring.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from opal import load_model | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model-dir", type=Path, default=Path(__file__).resolve().parent) | |
| args = parser.parse_args() | |
| root = args.model_dir.resolve() | |
| assert hashlib.sha256((root / "manifest.json").read_bytes()).hexdigest() == "b7ecce11de745bf3d89807a2dbcf97073512d2d05fb44090ec92310b95d75456" | |
| model = load_model(root) | |
| a, b, context = 'AHR', 'KLF1', 'K562/CRISPRa/Norman2019' | |
| result = model.predict(a, b, context=context) | |
| reverse = model.predict(b, a, context=context) | |
| assert np.all(np.isfinite(result["effect"])) | |
| assert result["genes"].tolist() == model.manifest["gene_order"] | |
| np.testing.assert_allclose(result["effect"], reverse["effect"], rtol=0, atol=1e-10) | |
| print(json.dumps({"targets": [a, b], "context": context, "output_genes": len(result["genes"]), "scale": result.get("units", result.get("scale")), "first_five_effects": result["effect"][:5].tolist()})) | |