OpenIslet

scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py

IIP-0042 / DEC-121 (CAND-033 / EXP-030): Master Exact 2^20 Multi-Layer Portfolio

script Release v0.8.0 gen-eb955f8266035aba 881 KB · 63 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_iip0042_master_multilayer_portfolio_crosswalk.py · SHA-256: 16964a158458b5cf…

            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    r63_fab20_held = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_global_valid_xrun_fab20],
    })
    if (
        r63_pass_held["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or r63_pass_held["per_lot_verdicts"]["LOT-B"]["verified_independent_igg_control_run_ids"] != []
        or r63_fab20_held["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r63_fab20_held["reasons"])
    ):
        raise RuntimeError(
            f"XREACT self-test 63 (R12 0037-B4 global-IgG-valid uncovered cross-run Fab) failed: "
            f"pass_held={r63_pass_held['verdict']}, fab20_held={r63_fab20_held['verdict']}"
        )

    # Case 64 (R12 0037-B4b + R13 0037-B1 pure subtraction): Global-IgG-valid cross-run Fab EVEN WITH
    # independent_matched_igg_controls metadata for fab_run MUST STILL BE WITHHELD to HOLD_INVALID_OR_INCOMPLETE_ASSAY
    # (0 [FAIL] reasons on 20% cross-run Fab, NEVER PASS on passing cross-run Fab!), while same-run Fab
    # (fab_run == obs_run) passes/fails cleanly AND cross-run Fab + valid obs_run failing primary c5b9_pct=20% -> FAIL!
    lot_b_xrun_covered_pass = json.loads(json.dumps(lot_b_global_valid_xrun_pass))
    lot_b_xrun_covered_pass["independent_matched_igg_controls"] = [
        build_valid_xreact_independent_igg_control("LOT-B", "RUN_LOT-B_FAB_02", "IND-IGG-FAB-02")
    ]
    for rec in lot_b_xrun_covered_pass["observations"]:
        rec["fab2_deconvolution"]["independent_matched_igg_isotype_valid"] = True
        rec["fab2_deconvolution"]["independent_matched_igg_isotype_lot_id"] = "IND-IGG-FAB-02"
    r64_xrun_meta_pass_held = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_covered_pass],
    })
    lot_b_xrun_covered_fail = json.loads(json.dumps(lot_b_xrun_covered_pass))
    for rec in lot_b_xrun_covered_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] > 0.0:
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    r64_xrun_meta_fail_held = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_covered_fail],
    })
    lot_b_samerun_pass = build_valid_xreact_lot("LOT-B")
    r64_samerun_pass = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_samerun_pass],
    })
    lot_b_samerun_fail = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_samerun_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] > 0.0:
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    r64_samerun_fail = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_samerun_fail],
    })
    lot_b_xrun_uncovered_plus_obs_fail = json.loads(json.dumps(lot_b_global_valid_xrun_pass))
    for rec in lot_b_xrun_uncovered_plus_obs_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_pos" and rec["dose_ug_ml"] == 5.0:
            rec["c5b9_pct"] = 20.0
            rec["fab2_deconvolution"]["intact_igg_c5b9_pct"] = 20.0
    r64_obs_fail = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_uncovered_plus_obs_fail],
    })
    if (
        r64_xrun_meta_pass_held["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r64_xrun_meta_pass_held["reasons"])
        or not any("CROSS_RUN_FAB_DECONVOLUTION_UNSUPPORTED_REQUIRES_SAME_RUN_PAIRED_CONTROL" in rs for rs in r64_xrun_meta_pass_held["reasons"])
        or r64_xrun_meta_fail_held["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r64_xrun_meta_fail_held["reasons"])
        or r64_samerun_pass["verdict"] != "PASS"
        or r64_samerun_fail["verdict"] != "FAIL"
        or r64_obs_fail["verdict"] != "FAIL"
    ):
        raise RuntimeError(
            f"XREACT self-test 64 (R13 0037-B1 cross-run Fab unconditionally withheld + same-run pass/fail + obs FAIL) failed: "
            f"xrun_pass={r64_xrun_meta_pass_held['verdict']}, xrun_fail={r64_xrun_meta_fail_held['verdict']}, "
            f"samerun_pass={r64_samerun_pass['verdict']}, samerun_fail={r64_samerun_fail['verdict']}, obs_fail={r64_obs_fail['verdict']}"
        )

    # Case 65 (R13 0037-B1 Sol cross-run Fab AUC comparator closure): Verify ZERO Fab point or Fab AUC endpoints
    # are biologically adjudicated on a cross-run lot even when fab_run carries valid positive controls + metadata
    # independent_matched_igg_controls, while a SEPARATE valid same-run failing lot (LOT-A) STILL returns FAIL!
    lot_b_xrun_auc_zero = json.loads(json.dumps(lot_b_xrun_covered_fail))
    r65_xrun_withheld = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_auc_zero],
    })
    lot_b_xrun_ep = r65_xrun_withheld["per_lot_verdicts"]["LOT-B"]["endpoints"]
    lot_b_xrun_fab_auc_keys = [
        k for k in lot_b_xrun_ep["XREACT_PER_DONOR_DOSE_AUC_VS_MATCHED_IGG"] if k.startswith("fab2_")
    ]
    lot_a_samerun_fab_fail = build_valid_xreact_lot("LOT-A")
    for rec in lot_a_samerun_fab_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] > 0.0:
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    r65_sep_samerun_fail = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [lot_a_samerun_fab_fail, lot_b_xrun_auc_zero],
    })
    if (
        r65_xrun_withheld["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r65_xrun_withheld["reasons"])
        or len(lot_b_xrun_ep["XREACT_LINKED_FAB2_C3D"]) != 0
        or len(lot_b_xrun_ep["XREACT_LINKED_FAB2_C5B9"]) != 0
        or len(lot_b_xrun_ep["XREACT_LINKED_FAB2_LYSIS"]) != 0
        or len(lot_b_xrun_fab_auc_keys) != 0
        or r65_sep_samerun_fail["verdict"] != "FAIL"
    ):
        raise RuntimeError(
            f"XREACT self-test 65 (R13 0037-B1 cross-run Fab AUC zero-adjudication + sep same-run FAIL) failed: "
            f"withheld={r65_xrun_withheld['verdict']}, fab_auc_keys={lot_b_xrun_fab_auc_keys}, sep_fail={r65_sep_samerun_fail['verdict']}"
        )

    # Case 66 (R16 0037-B1): Uncapped paired ratios (100 * ATG / IgG) across HLA-E (point + 1-15 & 0-50 AUC),
    # CD47 AUC, and SC-islet / iEC viability AUCs! Sol's exact 6-donor HLA-E reproducer: 5 donors at 90/100 and
    # 1 donor at 100/80 in a complete two-lot synthetic panel -> uncapped ratios [90, 90, 90, 90, 90, 125] ->
    # Student-t L95 = 80.8383% < 85.0% -> HOLD across all 3 clinical points and both AUC brackets!
    lot_b_hla_ratio = build_valid_xreact_lot("LOT-B")
    donors_b66 = sorted({rec["donor_id"] for rec in lot_b_hla_ratio["observations"]})
    for rec in lot_b_hla_ratio["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["donor_id"] == donors_b66[-1]:
                rec["hla_e_binding_retention_pct"] = 100.0
                rec["matched_rabbit_igg"]["hla_e_binding_retention_pct"] = 80.0
            else:
                rec["hla_e_binding_retention_pct"] = 90.0
                rec["matched_rabbit_igg"]["hla_e_binding_retention_pct"] = 100.0
    r66_hla = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_hla_ratio],
    })
    ep66_hla = r66_hla["per_lot_verdicts"]["LOT-B"]["endpoints"]
    hla_pt_l95s = [
        ep66_hla["XREACT_HLA_E_BINDING_RETENTION"][f"sc_islet_cd64t_null@{d}"]["paired_atg_over_igg_pct"]["l95_t"]
        for d in (1, 5, 15)
    ]
    hla_pt_verdicts = [
        ep66_hla["XREACT_HLA_E_BINDING_RETENTION"][f"sc_islet_cd64t_null@{d}"]["paired_atg_over_igg_pct"]["verdict"]
        for d in (1, 5, 15)
    ]
    hla_abs_l95 = ep66_hla["XREACT_HLA_E_BINDING_RETENTION"]["sc_islet_cd64t_null@1"]["absolute_retention_pct"]["l95_t"]
    hla_auc_1_15 = ep66_hla["XREACT_PER_DONOR_DOSE_AUC_VS_MATCHED_IGG"]["hla_e_auc_1_15@sc_islet_cd64t_null"]["paired_atg_over_igg_auc"]
    hla_auc_0_50 = ep66_hla["XREACT_PER_DONOR_DOSE_AUC_VS_MATCHED_IGG"]["hla_e_auc_0_50@sc_islet_cd64t_null"]["paired_atg_over_igg_auc"]

    lot_b_cd47_ratio = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_cd47_ratio["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["donor_id"] == donors_b66[-1]:
                rec["cd47_sirpa_retention_pct"] = 100.0
                rec["matched_rabbit_igg"]["cd47_sirpa_retention_pct"] = 80.0
            else:
                rec["cd47_sirpa_retention_pct"] = 90.0
                rec["matched_rabbit_igg"]["cd47_sirpa_retention_pct"] = 100.0
    r66_cd47 = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_cd47_ratio],
    })
    cd47_auc_1_15 = r66_cd47["per_lot_verdicts"]["LOT-B"]["endpoints"]["XREACT_PER_DONOR_DOSE_AUC_VS_MATCHED_IGG"]["cd47_auc_1_15@sc_islet_cd64t_null"]

    lot_b_viab_ratio = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_viab_ratio["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["donor_id"] == donors_b66[-1]:
                rec["sc_islet_viability_pct"] = 100.0
                rec["matched_rabbit_igg"]["sc_islet_viability_pct"] = 80.0
            else:
                rec["sc_islet_viability_pct"] = 95.0
                rec["matched_rabbit_igg"]["sc_islet_viability_pct"] = 100.0
    r66_viab = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_viab_ratio],
    })
    viab_auc_1_15 = r66_viab["per_lot_verdicts"]["LOT-B"]["endpoints"]["XREACT_PER_DONOR_DOSE_AUC_VS_MATCHED_IGG"]["sc_viab_auc_1_15@sc_islet_cd64t_null"]

    if (
        r66_hla["verdict"] != "HOLD"
        or r66_hla.get("uncapped_paired_ratios_enforced") is not True
        or any(v != "HOLD" for v in hla_pt_verdicts)
        or any(abs(v - 80.8383) > 1e-4 for v in hla_pt_l95s)
        or abs(hla_abs_l95 - 87.3824) > 1e-4
        or hla_auc_1_15["verdict"] != "HOLD"
        or abs(hla_auc_1_15["l95_t"] - 80.8383) > 1e-4
        or hla_auc_0_50["verdict"] != "HOLD"
        or abs(hla_auc_0_50["l95_t"] - 80.8383) > 1e-4
        or not any("85.0% paired lower-bound criterion" in rs for rs in r66_hla["reasons"])
        or r66_cd47["verdict"] != "HOLD"
        or cd47_auc_1_15["verdict"] != "HOLD"
        or abs(cd47_auc_1_15["l95_t"] - 80.8383) > 1e-4
        or r66_viab["verdict"] == "PASS"
        or viab_auc_1_15["verdict"] == "PASS"
        or viab_auc_1_15["l95_t"] >= 90.0
    ):
        raise RuntimeError(
            f"XREACT self-test 66 (R16 0037-B1 uncapped paired ratios HLA-E/CD47/viability) failed: "
            f"hla={r66_hla['verdict']} pts={hla_pt_l95s} auc1_15={hla_auc_1_15} auc0_50={hla_auc_0_50}, "
            f"cd47={r66_cd47['verdict']} {cd47_auc_1_15}, viab={r66_viab['verdict']} {viab_auc_1_15}"
        )

    # Case 67 (R16 0037-M1): Adjudicable same-run Fab maxima MUST exclude withheld cross-run Fab rows
    # (c3d stays 1.8%, NOT 4.0%), report withheld_cross_run_fab_maxima separately (4.0%), and set
    # linked_fab2_deconvolution_reconciled=False whenever any cross-run Fab row is withheld!
    lot_b_xrun_c3d4 = build_valid_xreact_lot("LOT-B")
    lot_b_xrun_c3d4["lot_positive_controls"] = [
        {"lot_id": "LOT-B", "plate_or_run_id": "RUN_LOT-B_PLATE_01", "cd3_pos_ctrl_pct": 94.0, "b6h12_pos_ctrl_pct": 95.0},
        {"lot_id": "LOT-B", "plate_or_run_id": "RUN_LOT-B_FAB_02", "cd3_pos_ctrl_pct": 94.0, "b6h12_pos_ctrl_pct": 95.0},
    ]
    for rec in lot_b_xrun_c3d4["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] == 15.0:
            rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_FAB_02"
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 4.0
    ctrl_fab4_m1 = json.loads(json.dumps(valid_ctrl))
    ctrl_fab4_m1["fab2_vs_intact_igg_deconvolution"]["direct_fab_c3d_max_pct"] = 4.0
    r67_ctrl4 = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab4_m1,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_c3d4],
    })
    r67_ctrl18 = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_xrun_c3d4],
    })
    if (
        r67_ctrl4["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r67_ctrl4["reasons"])
        or r67_ctrl4["derived_direct_fab_maxima_pct"]["direct_fab_c3d_max_pct"] != 1.8
        or r67_ctrl4["withheld_cross_run_fab_maxima"]["direct_fab_c3d_max_pct"] != 4.0
        or r67_ctrl4["withheld_cross_run_fab_rows_count"] != 6
        or r67_ctrl4["linked_fab2_deconvolution_reconciled"] is not False
        or r67_ctrl18["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or r67_ctrl18["derived_direct_fab_maxima_pct"]["direct_fab_c3d_max_pct"] != 1.8
        or r67_ctrl18["withheld_cross_run_fab_maxima"]["direct_fab_c3d_max_pct"] != 4.0
        or r67_ctrl18["linked_fab2_deconvolution_reconciled"] is not False
    ):
        raise RuntimeError(
            f"XREACT self-test 67 (R16 0037-M1 separated adjudicable vs withheld cross-run Fab maxima) failed: "
            f"ctrl4={r67_ctrl4['derived_direct_fab_maxima_pct']} withheld={r67_ctrl4['withheld_cross_run_fab_maxima']} rec={r67_ctrl4['linked_fab2_deconvolution_reconciled']}, "
            f"ctrl18_rec={r67_ctrl18['linked_fab2_deconvolution_reconciled']}"
        )

    # Cases 68-72 (R16 0037-B1 5-way XREACT rejected-Fab-linkage vs primary FAIL regression matrix):
    # Control-valid primary 12.0% C3d FAIL on sc_islet_cd64t_null @ 15 ug/mL across all 6 donors:
    #   (68) valid same-run agreement (intact_igg_c3d_pct=12.0%) -> FAIL
    #   (69) valid same-run discordance (intact_igg_c3d_pct=1.2% on matching lot/donor/stratum/dose & same run) -> HOLD (0 [FAIL], 6 conflicts)
    #   (70) missing linkage (lot_id & donor_id omitted in fab2_deconvolution, intact=1.2%) -> FAIL (primary preserved, 0 conflicts!)
    #   (71) wrong-donor linkage (donor_id='WRONG_DONOR_99' in fab2_deconvolution, intact=1.2%) -> FAIL (primary preserved, 0 conflicts!)
    #   (72) cross-run linkage (plate_or_run_id='RUN_LOT-B_FAB_02' in fab2_deconvolution, intact=1.2%) -> FAIL (primary preserved, 0 conflicts!)
    lot_b_m68_agree = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_m68_agree["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] == 15.0:
            rec["c3d_pct"] = 12.0
            rec["fab2_deconvolution"]["intact_igg_c3d_pct"] = 12.0
    r68_agree = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,