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 not isinstance(cond_obj, dict):
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl} missing mandatory per-comparator register screen record",
                        )
                        continue
                    extra_ckeys = sorted(set(cond_obj.keys()) - _required_comp_cond_keys)
                    missing_ckeys = sorted(_required_comp_cond_keys - set(cond_obj.keys()))
                    if extra_ckeys or missing_ckeys:
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl} closed-schema key violation (missing={missing_ckeys}, extra={extra_ckeys})",
                        )
                    if cond_obj.get("screened") is not True:
                        comp_row_valid = False
                        _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{cond_lbl}.screened must be literal boolean True")
                    if cond_obj.get("peptide_sequence") != exp_seq:
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl}.peptide_sequence={cond_obj.get('peptide_sequence')!r} != expected {exp_seq!r}",
                        )
                    raw_c_lot = cond_obj.get("peptide_reagent_lot_id")
                    cond_lot_ok = (
                        type(raw_c_lot) is str
                        and bool(raw_c_lot)
                        and raw_c_lot == raw_c_lot.strip()
                        and bool(_SHIELD_STRICT_ID_RE.match(raw_c_lot))
                    )
                    if not cond_lot_ok:
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl} missing valid unpadded peptide_reagent_lot_id (got {raw_c_lot!r})",
                        )
                    elif not cond_rqc_ok or exp_lot is None:
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl} excluded because mandatory register_qc_records.{cond_key} QC or parent batch linkage failed",
                        )
                    elif raw_c_lot != exp_lot:
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl}.peptide_reagent_lot_id={raw_c_lot!r} != register_qc_records.{cond_key} lot {exp_lot!r}",
                        )
                    _, crep_err = _shield_check_strict_int(
                        cond_obj.get("replicates_n"), f"{cond_lbl}.replicates_n", min_val=_SHIELD_MIN_SPR_REPLICATES_N
                    )
                    if crep_err is not None:
                        comp_row_valid = False
                        _escalate("HOLD_INVALID_OR_MISSING_INPUT", crep_err)
                    raw_cev = cond_obj.get("evidence_record_id")
                    if (
                        type(raw_cev) is not str
                        or not raw_cev
                        or raw_cev != raw_cev.strip()
                        or not _SHIELD_EVIDENCE_REF_RE.match(raw_cev)
                    ):
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl}.evidence_record_id must be an unpadded audit ref matching "
                            f"{_SHIELD_EVIDENCE_REF_RE.pattern} (got {raw_cev!r})",
                        )
                    elif raw_cev in conflicted_comp_ev_ids:
                        comp_row_valid = False
                    cb_err = _shield_validate_batch_ids(
                        cond_obj.get("expression_batch_ids"),
                        cond_lbl,
                        passing_batch_constructs,
                        out_batches,
                        required_construct_all=cid_c,
                    )
                    if cb_err is not None:
                        comp_row_valid = False
                        _escalate("HOLD_INVALID_OR_MISSING_INPUT", cb_err)
                    elif b_err is None and not out_batches.issubset(tmp_ref_c):
                        comp_row_valid = False
                        _escalate(
                            "HOLD_INVALID_OR_MISSING_INPUT",
                            f"{cond_lbl}.expression_batch_ids={sorted(out_batches)} must be a subset of "
                            f"comparator[{cid_c}].expression_batch_ids={sorted(tmp_ref_c)}",
                        )
                    elif cid_c == _SHIELD_COMP2_LEAD:
                        if not out_batches.issubset(rqc_comp2_batches):
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{cond_lbl}.expression_batch_ids={sorted(out_batches)} not covered by "
                                f"register_qc_records Comp2 batches={sorted(rqc_comp2_batches)}",
                            )
                        if not out_batches.issubset(sec_comp2_qualified_batches):
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{cond_lbl}.expression_batch_ids={sorted(out_batches)} lack passing Comp2 "
                                f"SEC-MALS/DLS qualification ({sorted(sec_comp2_qualified_batches)})",
                            )

                if "crystal_ref_1jk8_14aa" in reg_screens and reg_screens["crystal_ref_1jk8_14aa"] is not None:
                    c1jk8_obj = reg_screens["crystal_ref_1jk8_14aa"]
                    c1jk8_lbl = f"comparator[{cid_c}].register_control_screens.crystal_ref_1jk8_14aa"
                    if not isinstance(c1jk8_obj, dict):
                        comp_row_valid = False
                        _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl} must be an object or null")
                    else:
                        extra_1k = sorted(set(c1jk8_obj.keys()) - _allowed_comp_1jk8_keys)
                        missing_1k = sorted(_required_comp_1jk8_keys - set(c1jk8_obj.keys()))
                        if extra_1k or missing_1k:
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{c1jk8_lbl} closed-schema key violation (missing={missing_1k}, extra={extra_1k})",
                            )
                        if c1jk8_obj.get("screened") is not True:
                            comp_row_valid = False
                            _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl}.screened must be literal boolean True")
                        if c1jk8_obj.get("peptide_sequence") != "LVEALYLVCGERGG":
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{c1jk8_lbl}.peptide_sequence={c1jk8_obj.get('peptide_sequence')!r} != expected 'LVEALYLVCGERGG'",
                            )
                        if not r1jk8_qc_valid:
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{c1jk8_lbl} supplied without passing register_qc_records.crystal_ref_1jk8_14aa QC",
                            )
                        if "peptide_reagent_lot_id" in c1jk8_obj:
                            raw_1k_lot = c1jk8_obj["peptide_reagent_lot_id"]
                            if (
                                type(raw_1k_lot) is not str
                                or not raw_1k_lot
                                or raw_1k_lot != raw_1k_lot.strip()
                                or not _SHIELD_STRICT_ID_RE.match(raw_1k_lot)
                            ):
                                comp_row_valid = False
                                _escalate(
                                    "HOLD_INVALID_OR_MISSING_INPUT",
                                    f"{c1jk8_lbl}.peptide_reagent_lot_id invalid ({raw_1k_lot!r})",
                                )
                            elif raw_1k_lot in {x for x in (rqc_hip11_lot, rqc_wt_lot, rqc_6dfx_lot) if x is not None}:
                                comp_row_valid = False
                                _escalate(
                                    "HOLD_INVALID_OR_MISSING_INPUT",
                                    f"{c1jk8_lbl}.peptide_reagent_lot_id={raw_1k_lot!r} reuses HIP11, WT15, or 6DFX lot ID",
                                )
                            elif rqc_1jk8_lot is not None and raw_1k_lot != rqc_1jk8_lot:
                                comp_row_valid = False
                                _escalate(
                                    "HOLD_INVALID_OR_MISSING_INPUT",
                                    f"{c1jk8_lbl}.peptide_reagent_lot_id={raw_1k_lot!r} != register_qc_records lot {rqc_1jk8_lot!r}",
                                )
                        _, c1rep_err = _shield_check_strict_int(
                            c1jk8_obj.get("replicates_n"), f"{c1jk8_lbl}.replicates_n", min_val=_SHIELD_MIN_SPR_REPLICATES_N
                        )
                        if c1rep_err is not None:
                            comp_row_valid = False
                            _escalate("HOLD_INVALID_OR_MISSING_INPUT", c1rep_err)
                        raw_1ev = c1jk8_obj.get("evidence_record_id")
                        if (
                            type(raw_1ev) is not str
                            or not raw_1ev
                            or raw_1ev != raw_1ev.strip()
                            or not _SHIELD_EVIDENCE_REF_RE.match(raw_1ev)
                        ):
                            comp_row_valid = False
                            _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl}.evidence_record_id invalid ({raw_1ev!r})")
                        elif raw_1ev in conflicted_comp_ev_ids:
                            comp_row_valid = False
                        tmp_1k_b: set[str] = set()
                        c1b_err = _shield_validate_batch_ids(
                            c1jk8_obj.get("expression_batch_ids"),
                            c1jk8_lbl,
                            passing_batch_constructs,
                            tmp_1k_b,
                            required_construct_all=cid_c,
                        )
                        if c1b_err is not None:
                            comp_row_valid = False
                            _escalate("HOLD_INVALID_OR_MISSING_INPUT", c1b_err)
                        elif b_err is None and not tmp_1k_b.issubset(tmp_ref_c):
                            comp_row_valid = False
                            _escalate(
                                "HOLD_INVALID_OR_MISSING_INPUT",
                                f"{c1jk8_lbl}.expression_batch_ids={sorted(tmp_1k_b)} must be a subset of "
                                f"comparator[{cid_c}].expression_batch_ids={sorted(tmp_ref_c)}",
                            )

            # R16 Shared Blocker #2: Require non-empty shared comparator expression batch intersection
            # evaluated across BOTH native WT15 AND engineered 6DFX before granting complete-comparator
            # credit, batch-linkage credit, or Track-B candidacy!
            dual_reg_batches = cond_wt_batches & cond_6dfx_batches
            if cond_wt_batches and cond_6dfx_batches and len(dual_reg_batches) == 0:
                comp_row_valid = False
                _escalate(
                    "HOLD_INVALID_OR_MISSING_INPUT",
                    f"comparator[{cid_c}]: native_wt_insb9_23_15aa expression_batch_ids={sorted(cond_wt_batches)} "
                    f"and engineered_6dfx_p8e9e_12aa expression_batch_ids={sorted(cond_6dfx_batches)} have empty "
                    f"shared-batch intersection (matched comparator material evaluated across BOTH WT15 and 6DFX "
                    f"is required to identify the register contrast; disjoint batches earn zero comparator credit "
                    f"and suppress Track-B candidacy)",
                )

            if comp_row_valid and len(dual_reg_batches) > 0:
                referenced_batches.update(dual_reg_batches)
                if cid_c == _SHIELD_COMP2_LEAD:
                    comp2_assay_batches.update(dual_reg_batches & tmp_c2_c)
                verified_comparators_both_registers.add(cid_c)
                comparator_shared_batches_by_id[cid_c] = sorted(dual_reg_batches)
        missing_comps = [c for c in _SHIELD_MANDATORY_COMP2_COMPARATORS if c not in seen_comps]
        if missing_comps:
            _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"Missing mandatory Comp2 parallel comparators: {missing_comps}")
    derived_summary["comparator_mandatory_register_controls"] = [
        "native_wt_insb9_23_15aa",
        "engineered_6dfx_p8e9e_12aa",
    ]
    derived_summary["comparator_shared_batch_required_across_wt15_and_6dfx"] = True
    derived_summary["comparator_shared_wt15_6dfx_batches"] = comparator_shared_batches_by_id
    derived_summary["comparator_wt15_and_6dfx_verified_count"] = len(verified_comparators_both_registers)
    derived_summary["comparator_mandatory_register_coverage_verified"] = bool(
        len(conflicted_comps) == 0
        and len(conflicted_comp_ev_ids) == 0
        and verified_comparators_both_registers == set(_SHIELD_MANDATORY_COMP2_COMPARATORS)
    )

    # (Step 6 SEC-MALS/DLS physicochemical qualification was evaluated strictly BEFORE Steps 3 & 4 in Step 2b above.)

    # 7. Primary human T-cell blockade & off-target APC cytotoxicity donors
    #    (R09 B2: MANDATORY cryptographically hash-pinned outcome-blind preregistered_donor_family_roster
    #             reconciled 100% against submitted donors + optional pre-assay excluded_donor_records;
    #             NEVER optional, NEVER defaults to submitted row count; missing/tampered/incomplete
    #             roster fails closed to non-authorizing HOLD_INVALID_OR_MISSING_INPUT!
    #     R09 B3: Distribution-free exact one-sided Clopper-Pearson responder-proportion suppression test
    #             over fixed N_roster (estimand P(suppression_pct >= 70.0%), PASS requires L95_CP >= 70.0%
    #             [min N_roster=9] + min >= 0.0% anti-enhancement guard + mean >= 70.0%; FAIL requires
    #             L95_CP(k_lt_40, N_roster) > 60.0%; Student-t is strictly non-authorizing diagnostic!).
    #     R09 M1: Mandatory structured gy018_independence_justification per donor.
    #     R08 B3/B4/B5: Two-pass order-independent donor_id uniqueness; fixed pre-exclusion N_roster
    #             Bonferroni FWER <= 0.05 under H0_all: max_i p_i <= 5.0%; mandatory typed T1D eligibility;
    #             exact GY-018 deff == 1.0 preserved as Decimal through JSON decoding.)
    roster_obj = observation.get("preregistered_donor_family_roster")
    roster_verified = False
    roster_id_val: str | None = None
    roster_ts_val: str | None = None