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…

    if r56["verdict"] != "FAIL":
        raise RuntimeError(f"XREACT self-test 56 (conflicted LOT-B + separate consistent failing LOT-A) must FAIL, got {r56}")

    # Case 57 (R11 B2a + R13 0037-B1 pure subtraction): Invalid global IgG + linked Fab on separate RUN_LOT-B_FAB_02 ->
    # ALL cross-run Fab endpoints (fab_run != obs_run) are UNCONDITIONALLY withheld to HOLD_INVALID_OR_INCOMPLETE_ASSAY
    # with ZERO [FAIL] reasons (even if independent_matched_igg_controls metadata is supplied for RUN_LOT-B_FAB_02,
    # because fab_run lacks donor/stratum/dose-matched quantitative IgG measurements!); moving Fab onto the SAME run
    # RUN_LOT-B_PLATE_01 (sharing paired quantitative matched_rabbit_igg with valid independent IgG provenance) restores FAIL!
    lot_b_fab_2run = build_valid_xreact_lot("LOT-B")
    lot_b_fab_2run["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},
    ]
    lot_b_fab_2run["independent_matched_igg_isotype_valid"] = True
    lot_b_fab_2run["independent_matched_igg_isotype_lot_id"] = "IND-RABBIT-IGG-LOT-B-2026"
    lot_b_fab_2run["independent_matched_igg_controls"] = [
        build_valid_xreact_independent_igg_control("LOT-B", "RUN_LOT-B_PLATE_01", "IND-RABBIT-IGG-LOT-B-2026"),
    ]
    for rec in lot_b_fab_2run["observations"]:
        rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_FAB_02"
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] > 0.0:
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    ctrl_igg_false_fab20 = json.loads(json.dumps(ctrl_igg_false))
    ctrl_igg_false_fab20["fab2_vs_intact_igg_deconvolution"]["direct_fab_c3d_max_pct"] = 20.0
    r57_hold = evaluate_gate30_atg_xreact({
        "controls": ctrl_igg_false_fab20,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fab_2run],
    })
    lot_b_fab_2run_with_meta = json.loads(json.dumps(lot_b_fab_2run))
    lot_b_fab_2run_with_meta["independent_matched_igg_controls"].append(
        build_valid_xreact_independent_igg_control("LOT-B", "RUN_LOT-B_FAB_02", "IND-RABBIT-IGG-LOT-B-2026")
    )
    r57_xrun_meta_still_hold = evaluate_gate30_atg_xreact({
        "controls": ctrl_igg_false_fab20,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fab_2run_with_meta],
    })
    lot_b_fab_samerun_fail = json.loads(json.dumps(lot_b_fab_2run))
    for rec in lot_b_fab_samerun_fail["observations"]:
        rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_PLATE_01"
    r57_fail = evaluate_gate30_atg_xreact({
        "controls": ctrl_igg_false_fab20,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fab_samerun_fail],
    })
    if (
        r57_hold["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r57_hold["reasons"])
        or not any("CROSS_RUN_FAB_DECONVOLUTION_UNSUPPORTED_REQUIRES_SAME_RUN_PAIRED_CONTROL" in rs for rs in r57_hold["reasons"])
        or r57_xrun_meta_still_hold["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r57_xrun_meta_still_hold["reasons"])
        or not any("CROSS_RUN_FAB_DECONVOLUTION_UNSUPPORTED_REQUIRES_SAME_RUN_PAIRED_CONTROL" in rs for rs in r57_xrun_meta_still_hold["reasons"])
        or r57_fail["verdict"] != "FAIL"
        or r57_hold.get("fab2_same_run_paired_control_required") is not True
        or r57_hold.get("cross_run_fab2_deconvolution_withheld") is not True
    ):
        raise RuntimeError(
            f"XREACT self-test 57 (R11 B2 + R13 0037-B1 cross-run Fab withheld & same-run FAIL) failed: "
            f"hold={r57_hold['verdict']}, xrun_meta={r57_xrun_meta_still_hold['verdict']}, fail={r57_fail['verdict']}"
        )

    # Case 58 (R11 B2b): Uncovered cross-run Fab on RUN_LOT-B_FAB_02 + independently valid failing primary endpoint
    # on RUN_LOT-B_PLATE_01 (which HAS valid independent IgG provenance) -> biological FAIL preserved!
    lot_b_fab_2run_plus_obs_fail = json.loads(json.dumps(lot_b_fab_2run))
    for rec in lot_b_fab_2run_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
    r58 = evaluate_gate30_atg_xreact({
        "controls": ctrl_igg_false_fab20,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fab_2run_plus_obs_fail],
    })
    if r58["verdict"] != "FAIL":
        raise RuntimeError(f"XREACT self-test 58 (R11 B2 uncovered Fab + valid obs_run FAIL) must FAIL, got {r58}")

    # Case 59 (R11 B3a): Positive-exposure {1, 5, 15, 50} C3d = 4.9% (passing) with SOLE invalid measurement at
    # 0.0 ug/mL vehicle (c3d_pct = 100.0%, intact_igg_c3d_pct = 100.0%, matched IgG = 0.4%) -> MUST quarantine
    # BEFORE 0-50 AUC adjudication and return HOLD_INVALID (0 FAIL reasons), NOT permanent FAIL!
    # Restoring the 0.0 ug/mL vehicle baseline to 0.5% -> MUST return PASS!
    lot_b_bad_veh = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_bad_veh["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["dose_ug_ml"] == 0.0:
                rec["c3d_pct"] = 100.0
                rec["fab2_deconvolution"]["intact_igg_c3d_pct"] = 100.0
                rec["matched_rabbit_igg"]["c3d_pct"] = 0.4
            else:
                rec["c3d_pct"] = 4.9
                rec["fab2_deconvolution"]["intact_igg_c3d_pct"] = 4.9
                rec["matched_rabbit_igg"]["c3d_pct"] = 0.4
    r59_hold = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_bad_veh],
    })
    lot_b_fixed_veh = json.loads(json.dumps(lot_b_bad_veh))
    for rec in lot_b_fixed_veh["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] == 0.0:
            rec["c3d_pct"] = 0.5
            rec["fab2_deconvolution"]["intact_igg_c3d_pct"] = 0.5
    r59_pass = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fixed_veh],
    })
    if (
        r59_hold["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r59_hold["reasons"])
        or r59_hold["per_lot_verdicts"]["LOT-B"]["vehicle_series_quarantined"] < 6
        or r59_hold.get("vehicle_validated_before_auc_enforced") is not True
        or r59_pass["verdict"] != "PASS"
    ):
        raise RuntimeError(
            f"XREACT self-test 59 (R11 B3 vehicle-before-AUC quarantine) failed: hold={r59_hold['verdict']}, pass={r59_pass['verdict']}"
        )

    # Case 60 (R11 B3b): Invalid 0.0 ug/mL vehicle on sc_islet_cd64t_null + SEPARATE validated failing series on
    # sc_islet_cd64t_pos -> biological FAIL preserved; ALSO invalid 0.0 ug/mL fab2_c3d_pct=100% with passing 4.9%
    # positive-exposure Fab -> HOLD_INVALID (0 FAIL reasons)!
    lot_b_bad_veh_plus_sep_fail = json.loads(json.dumps(lot_b_bad_veh))
    for rec in lot_b_bad_veh_plus_sep_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_pos" and rec["dose_ug_ml"] > 0.0:
            rec["c3d_pct"] = 20.0
            rec["fab2_deconvolution"]["intact_igg_c3d_pct"] = 20.0
    r60_sep_fail = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_bad_veh_plus_sep_fail],
    })
    lot_b_bad_fab_veh = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_bad_fab_veh["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            rec["fab2_deconvolution"]["fab2_c3d_pct"] = 100.0 if rec["dose_ug_ml"] == 0.0 else 4.9
    ctrl_fab100 = json.loads(json.dumps(valid_ctrl))
    ctrl_fab100["fab2_vs_intact_igg_deconvolution"]["direct_fab_c3d_max_pct"] = 100.0
    r60_fab_veh_hold = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab100,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_bad_fab_veh],
    })
    if (
        r60_sep_fail["verdict"] != "FAIL"
        or r60_fab_veh_hold["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r60_fab_veh_hold["reasons"])
    ):
        raise RuntimeError(
            f"XREACT self-test 60 (R11 B3 separate validated FAIL + fab2 vehicle quarantine) failed: "
            f"sep_fail={r60_sep_fail['verdict']}, fab_veh_hold={r60_fab_veh_hold['verdict']}"
        )

    # Case 61 (R12 0037-B1a): Sol's exact HLA-E 0.0 ug/mL vehicle positive-control run failure!
    # When one stratum's six 0.0 ug/mL vehicle rows fail positive-control validation, ALL dependent endpoints
    # (point-level, 1-15 AUC, AND 0-50 AUC) for that stratum MUST quarantine to HOLD_INVALID_OR_INCOMPLETE_ASSAY
    # (BOTH with passing clinical-dose HLA-E AND with failing 50% clinical-dose HLA-E -> ZERO [FAIL] reasons!),
    # while a separate valid failing stratum/lot STILL preserves fail-first biological FAIL!
    lot_b_veh_posfail_pass = build_valid_xreact_lot("LOT-B")
    lot_b_veh_posfail_pass["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_VEH_FAIL", "cd3_pos_ctrl_pct": 50.0, "b6h12_pos_ctrl_pct": 95.0},
    ]
    for rec in lot_b_veh_posfail_pass["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] == 0.0:
            rec["plate_or_run_id"] = "RUN_LOT-B_VEH_FAIL"
            rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_VEH_FAIL"
    r61_pass_clin = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_veh_posfail_pass],
    })
    lot_b_veh_posfail_low_hlae = json.loads(json.dumps(lot_b_veh_posfail_pass))
    for rec in lot_b_veh_posfail_low_hlae["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] in (1.0, 5.0, 15.0):
            rec["hla_e_binding_retention_pct"] = 50.0
    r61_low_clin = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_veh_posfail_low_hlae],
    })
    lot_b_veh_posfail_sep_fail = json.loads(json.dumps(lot_b_veh_posfail_low_hlae))
    for rec in lot_b_veh_posfail_sep_fail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_pos" and rec["dose_ug_ml"] in (1.0, 5.0, 15.0):
            rec["hla_e_binding_retention_pct"] = 50.0
    r61_sep_fail = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_veh_posfail_sep_fail],
    })
    if (
        r61_pass_clin["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or r61_pass_clin["per_lot_verdicts"]["LOT-B"]["vehicle_series_quarantined"] == 0
        or any(k.startswith("sc_islet_cd64t_null@") for k in r61_pass_clin["per_lot_verdicts"]["LOT-B"]["endpoints"]["XREACT_HLA_E_BINDING_RETENTION"])
        or r61_low_clin["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r61_low_clin["reasons"])
        or r61_sep_fail["verdict"] != "FAIL"
    ):
        raise RuntimeError(
            f"XREACT self-test 61 (R12 0037-B1 vehicle positive-control run failure quarantine) failed: "
            f"pass_clin={r61_pass_clin['verdict']}, low_clin={r61_low_clin['verdict']}, sep_fail={r61_sep_fail['verdict']}"
        )

    # Case 62 (R12 0037-B1b): Sol's exact HLA-E 0.0 ug/mL vehicle invalid matched-IgG baseline AND Fab-only 0.0 ug/mL
    # vehicle control failure -> BOTH quarantine to HOLD_INVALID_OR_INCOMPLETE_ASSAY with ZERO [FAIL] reasons!
    lot_b_veh_iggfail = build_valid_xreact_lot("LOT-B")
    for rec in lot_b_veh_iggfail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["dose_ug_ml"] == 0.0:
                rec["matched_rabbit_igg"]["hla_e_binding_retention_pct"] = 50.0
            elif rec["dose_ug_ml"] in (1.0, 5.0, 15.0):
                rec["hla_e_binding_retention_pct"] = 50.0
    r62_igg_veh = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_veh_iggfail],
    })
    lot_b_fab_veh_ctrlfail = build_valid_xreact_lot("LOT-B")
    lot_b_fab_veh_ctrlfail["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_VEH_BAD", "cd3_pos_ctrl_pct": 50.0, "b6h12_pos_ctrl_pct": 95.0},
    ]
    for rec in lot_b_fab_veh_ctrlfail["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null":
            if rec["dose_ug_ml"] == 0.0:
                rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_FAB_VEH_BAD"
            elif rec["dose_ug_ml"] in (1.0, 5.0, 15.0):
                rec["fab2_deconvolution"]["fab2_c3d_pct"] = 20.0
    ctrl_fab20_valid = json.loads(json.dumps(valid_ctrl))
    ctrl_fab20_valid["fab2_vs_intact_igg_deconvolution"]["direct_fab_c3d_max_pct"] = 20.0
    r62_fab_veh = evaluate_gate30_atg_xreact({
        "controls": ctrl_fab20_valid,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_fab_veh_ctrlfail],
    })
    if (
        r62_igg_veh["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r62_igg_veh["reasons"])
        or r62_igg_veh["per_lot_verdicts"]["LOT-B"]["vehicle_series_quarantined"] == 0
        or r62_fab_veh["verdict"] != "HOLD_INVALID_OR_INCOMPLETE_ASSAY"
        or any(rs.startswith("[FAIL]") for rs in r62_fab_veh["reasons"])
    ):
        raise RuntimeError(
            f"XREACT self-test 62 (R12 0037-B1 vehicle invalid IgG & Fab vehicle control failure) failed: "
            f"igg_veh={r62_igg_veh['verdict']}, fab_veh={r62_fab_veh['verdict']}"
        )

    # Case 63 (R12 0037-B4a): Sol's exact global-IgG-valid cross-run Fab (fab_run != obs_run) WITHOUT
    # independent_matched_igg_controls for fab_run -> MUST quarantine to HOLD_INVALID_OR_INCOMPLETE_ASSAY
    # (NEVER PASS on passing Fab AND NEVER biological FAIL on 20% Fab)!
    lot_b_global_valid_xrun_pass = build_valid_xreact_lot("LOT-B")
    lot_b_global_valid_xrun_pass["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_global_valid_xrun_pass["observations"]:
        rec["fab2_deconvolution"]["plate_or_run_id"] = "RUN_LOT-B_FAB_02"
    r63_pass_held = evaluate_gate30_atg_xreact({
        "controls": valid_ctrl,
        "lots": [build_valid_xreact_lot("LOT-A"), lot_b_global_valid_xrun_pass],
    })
    lot_b_global_valid_xrun_fab20 = json.loads(json.dumps(lot_b_global_valid_xrun_pass))
    for rec in lot_b_global_valid_xrun_fab20["observations"]:
        if rec["stratum"] == "sc_islet_cd64t_null" and rec["dose_ug_ml"] > 0.0: