OpenIslet

scripts/verify_iip0041_clinical_h1_cd64t_siglec.py

EXP-028 (CAND-031 / Target IIP-0041 — Bucket 2A) Remediated Verification Suite

script Release v0.8.0 gen-eb955f8266035aba 984 KB · 69 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…

        }
    elif eff_state == "INCUMBENT_UNRESOLVED_STRADDLING_CAP":
        comp_evidence = {
            "incumbent_intact_serum_cd16_adcc_l95_pct": 1.8,
            "incumbent_intact_serum_cd16_adcc_u95_pct": 3.4,
            "incumbent_igg_attributable_cd16_adcc_l95_pct": 1.4,
            "incumbent_igg_attributable_cd16_adcc_u95_pct": 2.9,
            "incumbent_ap_c5b9_l95_pct": 1.5,
            "incumbent_ap_c5b9_u95_pct": 3.1,
            "incumbent_overall_20pct_nhs_l95_pct": 2.0,
            "incumbent_overall_20pct_nhs_u95_pct": 3.8,
            "incumbent_classical_c4b2a_l95_pct": 9.0,
            "incumbent_classical_c4b2a_u95_pct": 11.0,
            "incumbent_lectin_c4b2a_l95_pct": 3.0,
            "incumbent_lectin_c4b2a_u95_pct": 7.2,
        }
    else:
        comp_evidence = {
            "incumbent_intact_serum_cd16_adcc_l95_pct": 1.8,
            "incumbent_intact_serum_cd16_adcc_u95_pct": 3.4,
            "incumbent_igg_attributable_cd16_adcc_l95_pct": 1.4,
            "incumbent_igg_attributable_cd16_adcc_u95_pct": 2.9,
            "incumbent_ap_c5b9_l95_pct": 1.5,
            "incumbent_ap_c5b9_u95_pct": 3.1,
            "incumbent_overall_20pct_nhs_l95_pct": 2.0,
            "incumbent_overall_20pct_nhs_u95_pct": 3.8,
            "incumbent_classical_c4b2a_l95_pct": 3.8,
            "incumbent_classical_c4b2a_u95_pct": 8.1,
            "incumbent_lectin_c4b2a_l95_pct": 3.0,
            "incumbent_lectin_c4b2a_u95_pct": 7.2,
        }
    if incumbent_evidence_override:
        comp_evidence.update(incumbent_evidence_override)

    cand_arm: dict[str, Any] = {
        "copy1_monoallelic": {
            "intact_serum_cd16_adcc_u95_pct": 3.8,
            "igg_attributable_cd16_adcc_u95_pct": 3.1,
            "ap_c5b9_u95_pct": 3.4,
            "overall_20pct_nhs_u95_pct": 4.1,
        },
        "copy2_biallelic": {
            "intact_serum_cd16_adcc_u95_pct": 2.9,
            "igg_attributable_cd16_adcc_u95_pct": 2.4,
            "ap_c5b9_u95_pct": 2.8,
            "overall_20pct_nhs_u95_pct": 3.2,
        },
        "classical_c4b2a_l95_pct": 4.2,
        "classical_c4b2a_u95_pct": 8.6,
        "lectin_c4b2a_l95_pct": 3.5,
        "lectin_c4b2a_u95_pct": 7.9,
    }
    if candidate_arm_override:
        for k_ov, v_ov in candidate_arm_override.items():
            if k_ov in ("copy1_monoallelic", "copy2_biallelic") and isinstance(v_ov, dict):
                cand_arm[k_ov].update(v_ov)
            else:
                cand_arm[k_ov] = v_ov

    comp_rec = build_authenticated_paired_comparator_record(
        candidate_construct_id=construct_id,
        candidate_lot_id=lot_id,
        candidate_mcb_id=mcb_id,
        chassis_id=chassis_id,
        incumbent_comparator_construct_id=incumbent_comparator_construct_id,
        incumbent_comparator_lot_id=incumbent_comparator_lot_id,
        incumbent_comparator_mcb_id=incumbent_comparator_mcb_id,
        paired_assay_run_id=paired_assay_run_id,
        evidence_summary=comp_evidence,
        candidate_arm_evidence=cand_arm,
        t1d_sera_panel_ids=sera_ids,
        nk_donor_panel_ids=nk_ids,
        differentiation_batch_ids=diff_ids,
    )

    records_map = {
        "gate0v_record": g0v_rec,
        "rule_s11_record": s11_rec,
        "gy025_tier6b_record": t6b_rec,
        "paired_comparator_record": comp_rec,
    }
    if store_path is not None:
        write_gate28b_trusted_qualification_store(
            store_path,
            upstream_records=[g0v_rec, s11_rec, t6b_rec],
            paired_comparator_records=[comp_rec],
        )

    payload: dict[str, Any] = {
        "product_track": product_track,
        "chassis_id": chassis_id,
        "construct_id": construct_id,
        "product_variant_id": construct_id,
        "lot_id": lot_id,
        "mcb_id": mcb_id,
        "incumbent_comparator_construct_id": incumbent_comparator_construct_id,
        "incumbent_comparator_lot_id": incumbent_comparator_lot_id,
        "paired_assay_run_id": paired_assay_run_id,
        "t1d_sera_panel_ids": list(sera_ids),
        "nk_donor_panel_ids": list(nk_ids),
        "differentiation_batch_ids": list(diff_ids),
        "panel_digest": comp_rec["panel_digest"],
        "zygosity": "MONOALLELIC_1COPY_HDR_KO",
        "clones_screened_n": 48,
        "gmp_aav6_locus2_donor_families_n": 1,
        "copy1_monoallelic": {
            "quantibrite_t0_molecules_per_cell": 72000.0,
            "quantibrite_day90_molecules_per_cell": 61000.0,
            "t0_mfi": 7200.0,
            "day90_mfi": 6100.0,
            "day90_mfi_retention_pct_vs_t0": 84.7,
            **cand_arm["copy1_monoallelic"],
            "post_7day_10mgml_igg_preload_functional_pass": True,
        },
        "copy2_biallelic": {
            "quantibrite_t0_molecules_per_cell": 135000.0,
            "quantibrite_day90_molecules_per_cell": 115000.0,
            "t0_mfi": 13500.0,
            "day90_mfi": 11500.0,
            "day90_mfi_retention_pct_vs_t0": 85.2,
            **cand_arm["copy2_biallelic"],
            "post_7day_10mgml_igg_preload_functional_pass": True,
        },
        "independent_t1d_sera_n": len(sera_ids),
        "independent_nk_donors_n": len(nk_ids),
        "independent_differentiations_n": len(diff_ids),
        "fcr_gamma_coip_and_phospho_syk_negative": True,
        "cd274p_il1rn_ifn_titration_matrix_passed": True,
        "il1rn_to_il1b_molar_excess": 125.0,
        "il1rn_basal_leak_pct_of_induced": 2.4,
        "dynamic_gsis_retention_pct_of_ctrl": 94.5,
        "ap1903_icasp9_ablation_pct": 99.6,
        "classical_c4b2a_l95_pct": cand_arm["classical_c4b2a_l95_pct"],
        "classical_c4b2a_u95_pct": cand_arm["classical_c4b2a_u95_pct"],
        "lectin_c4b2a_l95_pct": cand_arm["lectin_c4b2a_l95_pct"],
        "lectin_c4b2a_u95_pct": cand_arm["lectin_c4b2a_u95_pct"],
        "exact_stack_efferocytosis_abs_pct": 84.0,
        "exact_stack_efferocytosis_pct_of_wt": 78.0,
        "iec_morphogenesis_t50_h": 28.0,
        "iec_viability_pct": 91.0,
        "gate0g_pericyte_pct": 76.0,
        "gate0v_viral_safety_passed": True,
        "rule_s11_molecular_battery_passed": True,
        "gy025_tier6b_master_lot_outgrowth_passed": True,
        "upstream_record_refs": {
            "gate0v_record_sha256": g0v_rec["record_sha256"],
            "rule_s11_record_sha256": s11_rec["record_sha256"],
            "gy025_tier6b_record_sha256": t6b_rec["record_sha256"],
            "paired_comparator_record_sha256": comp_rec["record_sha256"],
        },
    }
    if comp_rec["incumbent_adjudication_state"] == "INCUMBENT_CONCLUSIVELY_BROKEN":
        payload["l2v3_broken_by_t1d_sera_gt_5pct"] = True
    elif comp_rec["incumbent_adjudication_state"] == "INCUMBENT_INTACT_WITHIN_CAPS":
        payload["l2v3_broken_by_t1d_sera_gt_5pct"] = False
    return payload, records_map


def build_valid_gate28b_reference_payload(
    *,
    lot_id: str = "LOT-ABX-2026-001",
    mcb_id: str = "MCB-ISLET1A-001",
    chassis_id: str = "ISLET1_A",
    incumbent_comparator_construct_id: str = "L2_V3_CO_PRIMARY_CD200",
    incumbent_comparator_lot_id: str = "LOT-L2V3-2026-001",
    l2v3_broken: bool = True,
) -> dict[str, Any]:
    """Convenience wrapper returning the Gate 28-B reference payload (requires trusted_qualification_store for full authorization)."""
    payload, _ = build_valid_gate28b_reference_bundle(
        store_path=None,
        lot_id=lot_id,
        mcb_id=mcb_id,
        chassis_id=chassis_id,
        incumbent_comparator_construct_id=incumbent_comparator_construct_id,
        incumbent_comparator_lot_id=incumbent_comparator_lot_id,
        l2v3_broken=l2v3_broken,
    )
    return payload


def _run_locus2_arbitration_unit_tests() -> dict[str, Any]:
    cases: list[dict[str, Any]] = []

    with tempfile.TemporaryDirectory(prefix="openislet_g28b_test_") as td:
        td_path = pathlib.Path(td)
        store_json = td_path / "trusted_qualification_store.json"
        store_dir = td_path / "trusted_store_dir"

        base_full_pass, base_recs = build_valid_gate28b_reference_bundle(store_path=store_json, l2v3_broken=True)
        # Also populate directory-layout store for directory resolution check
        write_gate28b_trusted_qualification_store(
            store_dir,
            upstream_records=[base_recs["gate0v_record"], base_recs["rule_s11_record"], base_recs["gy025_tier6b_record"]],
            paired_comparator_records=[base_recs["paired_comparator_record"]],
        )
        # Also write retain-incumbent paired comparator record into store_json
        retain_payload, _ = build_valid_gate28b_reference_bundle(store_path=store_json, l2v3_broken=False)

        def _check_case(
            name: str,
            payload: dict[str, Any],
            expected_status: str,
            expected_auth: bool,
            *,
            store: pathlib.Path | str | None = store_json,
            sc_path: pathlib.Path | None = None,
            expected_lead_auth: bool | None = None,
            expected_arb_closed: bool | None = None,
            expected_inc_retained: bool | None = None,
            expected_pin_verified: bool | None = True,
        ) -> None:
            res = evaluate_ciita_locus2_arbitration(
                payload,
                side_contract_path=sc_path,
                trusted_qualification_store=store,
            )
            lead_exp = expected_auth if expected_lead_auth is None else expected_lead_auth
            if res["status"] != expected_status or res["full_promotion_authorized"] is not expected_auth:
                raise ValueError(
                    f"Arbitration unit test {name} failed: got status={res['status']!r}, "
                    f"auth={res['full_promotion_authorized']!r} (expected {expected_status!r}, {expected_auth!r}); "
                    f"reasons={res.get('reasons')}"
                )
            if res["lead_promotion_authorized"] is not lead_exp:
                raise ValueError(
                    f"Arbitration unit test {name} lead_promotion_authorized={res['lead_promotion_authorized']!r} != {lead_exp!r}"
                )
            if expected_arb_closed is not None and res["arbitration_closed"] is not expected_arb_closed:
                raise ValueError(f"Arbitration unit test {name} arbitration_closed mismatch: {res['arbitration_closed']!r}")
            if expected_inc_retained is not None and res["incumbent_retained"] is not expected_inc_retained:
                raise ValueError(f"Arbitration unit test {name} incumbent_retained mismatch: {res['incumbent_retained']!r}")
            if expected_pin_verified is not None and res["policy_pin_verified"] is not expected_pin_verified:
                raise ValueError(f"Arbitration unit test {name} policy_pin_verified mismatch: {res['policy_pin_verified']!r}")
            cases.append({
                "case": name,
                "status": res["status"],
                "full_promotion_authorized": res["full_promotion_authorized"],
                "lead_promotion_authorized": res["lead_promotion_authorized"],
                "arbitration_closed": res["arbitration_closed"],
                "incumbent_retained": res["incumbent_retained"],
                "policy_pin_verified": res["policy_pin_verified"],
                "pending_full_qualification_fields": res["pending_full_qualification_fields"],
                "passed": True,
            })

        # 1. Full qualification via independent JSON registry store promotes winner
        _check_case(
            "full_qualification_pass_promotes_winner",
            base_full_pass,
            "PASS_FULL_GY025_AND_GATE28B_PROMOTE",