Skip to content

geno_lewm.cli.calibrate

calibrate

Generate calibration.parquet by scoring a background variant set.

Runs a trained model (loaded from a deploy model_dir via :func:geno_lewm.deploy.load_scorer_modules, which does not require an existing calibration artifact) over a background VCF, records raw surprise per functional bucket, and writes the empirical-CDF calibration table consumed by the runtime/demo manifest. Run as::

geno-lewm-calibrate         --model-dir ARTIFACTS/model         --vcf ARTIFACTS/background/common.vcf         --fasta ARTIFACTS/reference/GRCh38.fa         --output ARTIFACTS/model/calibration.parquet

build_calibration

build_calibration(*, model_dir: Path, vcf: Path, fasta: Path, output: Path, summary_json: Path | None = None, window_bp: int = DEFAULT_WINDOW_BP, seed: int = 0) -> dict[str, Any]

Score the background VCF with the model in model_dir and write the table.

Source code in geno_lewm/cli/calibrate.py
def build_calibration(
    *,
    model_dir: Path,
    vcf: Path,
    fasta: Path,
    output: Path,
    summary_json: Path | None = None,
    window_bp: int = DEFAULT_WINDOW_BP,
    seed: int = 0,
) -> dict[str, Any]:
    """Score the background VCF with the model in ``model_dir`` and write the table."""
    manifest_path = model_dir / "manifest.json"
    manifest = load_manifest(manifest_path)
    encoder, action_encoder, predictor = load_scorer_modules(model_dir)
    examples = build_calibration_examples_from_vcf(
        vcf,
        encoder,
        action_encoder,
        predictor,
        reference_fasta=fasta,
        window_bp=window_bp,
    )
    table = build_calibration_table(examples, seed=seed)
    written = write_calibration_table(table, output)
    summary = {
        "schema_version": SCHEMA_VERSION,
        "generated_by": GENERATED_BY,
        "model_id": manifest.model_id(),
        "model_release": manifest.release_id,
        "model_manifest": _file_identity(
            manifest_path,
            reported_path="model/manifest.json",
        ),
        "manifest_calibration": {
            "path": manifest.calibration.file,
            "sha256": manifest.calibration.hash,
        },
        "inputs": {
            "vcf": _file_identity(vcf, reported_path=vcf.name),
            "fasta": _file_identity(fasta, reported_path=fasta.name),
        },
        "calibration_artifact": _file_identity(
            written,
            reported_path=_model_relative_path(model_dir, written),
        ),
        "parameters": {
            "window_bp": window_bp,
            "seed": seed,
        },
        "examples": len(examples),
        "buckets": len(table.buckets),
        "low_confidence_buckets": sum(1 for bucket in table.buckets if bucket.low_confidence),
    }
    if summary_json is not None:
        _write_summary(summary_json, summary)
    return summary