if not lb_schema_ok: break if pm_f <= 0.0 or r3_f <= 0.0 or c3_f <= 0.0 or not lytic_valid or not lb_schema_ok: fails.append(f"FAIL_GATE_C1_{o2_tag}_INVALID_DIVERSION_ASSAY_VALUES") elif worst_beta_c3 > 0.85: fails.append(f"FAIL_GATE_C1_{o2_tag}_CLEAVED_CASP3_NOT_REDUCED_VS_CTRL") elif pmlkl is False and (worst_pm > 1.25 or worst_r3 > 1.25 or worst_n1 >= 5.0 or worst_g8 >= 5.0 or lytic_elevated): fails.append(f"FAIL_GATE_C1_{o2_tag}_UNDECLARED_NECROPTOSIS_DIVERSION") elif pmlkl is True: if not (is_strict_bool(blk.get("gy016_nec1s_gsk872_orthogonal_rescue_cleared")) and blk["gy016_nec1s_gsk872_orthogonal_rescue_cleared"]): fails.append(f"FAIL_GATE_C1_{o2_tag}_PMLKL_GY016_ORTHOGONAL_DIVERSION_REQUIRED") elif worst_n1 >= 5.0 or worst_g8 >= 5.0 or lytic_elevated: fails.append(f"FAIL_GATE_C1_{o2_tag}_UNRESOLVED_NECROPTOSIS_RESCUE_SIGNAL") # Mandatory specimen-linked delivery-only mock-transfection control per block (Dossier C ยง5 C-1)! mock_blks = blk.get("mock_transfection_control_by_block") mock_req_keys = frozenset({ "block_id", "specimen_id", "delivery_reagent_lot_id", "unstressed_mock_plated_t0", "unstressed_mock_surviving", "stressed_mock_plated_t0", "stressed_mock_surviving", "stressed_mock_casp9_raw", }) if mock_blks is None or (isinstance(mock_blks, list) and len(mock_blks) == 0): holds.append(f"HOLD_GATE_C1_{o2_tag}_MISSING_MOCK_TRANSFECTION_CONTROL") elif not isinstance(mock_blks, list) or len(mock_blks) != expected_n: fails.append(f"FAIL_GATE_C1_{o2_tag}_INVALID_MOCK_TRANSFECTION_CONTROL") else: bids_norm_m = [str(x).strip().upper() for x in bids] seen_msp: set[str] = set() um_pcts: list[float] = [] sm_pcts: list[float] = [] sm_c9: list[float] = [] mock_ok = True for mi, mrow in enumerate(mock_blks): if ( not isinstance(mrow, Mapping) or set(mrow.keys()) != mock_req_keys or not is_nonempty_str(mrow.get("block_id")) or str(mrow["block_id"]).strip().upper() != bids_norm_m[mi] or not is_nonempty_str(mrow.get("specimen_id")) or not is_nonempty_str(mrow.get("delivery_reagent_lot_id")) ): mock_ok = False; break msp = str(mrow["specimen_id"]).strip().upper() if msp in seen_msp: mock_ok = False; break seen_msp.add(msp) up0, usv = mrow.get("unstressed_mock_plated_t0"), mrow.get("unstressed_mock_surviving") sp0, ssv = mrow.get("stressed_mock_plated_t0"), mrow.get("stressed_mock_surviving") mc9 = mrow.get("stressed_mock_casp9_raw") if not ( all(is_strict_int(x) for x in (up0, usv, sp0, ssv)) and int(up0) > 0 and 0 <= int(usv) <= int(up0) and int(sp0) > 0 and 0 <= int(ssv) <= int(sp0) and is_finite_num(mc9) and float(mc9) > 0.0 ): mock_ok = False; break um_pcts.append(100.0 * float(int(usv)) / float(int(up0))) sm_pcts.append(100.0 * float(int(ssv)) / float(int(sp0))) sm_c9.append(float(mc9)) if not mock_ok: fails.append(f"FAIL_GATE_C1_{o2_tag}_INVALID_MOCK_TRANSFECTION_CONTROL") else: mean_veh = sum(eff_veh_f) / expected_n mean_um = sum(um_pcts) / expected_n if mean_um < 0.85 * mean_veh or any(um_pcts[i] < 0.75 * eff_veh_f[i] for i in range(expected_n)): fails.append(f"FAIL_GATE_C1_{o2_tag}_MOCK_DELIVERY_TOXICITY_EXCESSIVE") mean_ctrl = sum(eff_ctrl_f) / expected_n mean_tr = sum(eff_tr_f) / expected_n mean_sm = sum(sm_pcts) / expected_n mean_sm_c9 = sum(sm_c9) / expected_n mean_tr_c9 = sum(c9_tr_f) / expected_n if ( abs(mean_sm - mean_ctrl) > 10.0 or mean_tr <= mean_sm or not ((mean_tr - mean_sm) >= 15.0 or (100.0 * mean_tr / mean_veh) >= 85.0) or mean_tr_c9 >= mean_sm_c9 ): fails.append(f"FAIL_GATE_C1_{o2_tag}_MOCK_CONTROL_CONCORDANCE_OR_SPECIFICITY_FAILED") return (str(aid).strip(), c9_f, ctrl_f, tr_f, veh_f, recomp_beta_p, recomp_c9_p) def evaluate_gate42_gy032_channel_c_screen(rec: Mapping[str, Any]) -> dict[str, Any]: """GATE-42 (IIP-0064): Full 5x2 IIP-0049 causal attribution, exact Holm-5 + composite IUT, cross-lot unique C-2, & data-backed switch parity.""" fails: list[str] = [] holds: list[str] = [] _check_allowed_keys(rec, GATE42_ALLOWED_KEYS, fails, "GATE42") target = str(rec.get("target_gene", "")).strip().upper() if target in ("MAP3K7", "BACH2"): fails.append(f"FAIL_EXCLUDED_CANDIDATE_BLOCKED:{target}") elif target not in C1_FAMILY_GENES: fails.append("FAIL_UNRECOGNIZED_TARGET_GENE") c1_raw = rec.get("c1_evidence") expected_nt = str(c1_raw.get("comparator_nt_lot_id", "")).strip() if isinstance(c1_raw, Mapping) and is_nonempty_str(c1_raw.get("comparator_nt_lot_id")) else None if isinstance(c1_raw, Mapping) and expected_nt is None: fails.append("FAIL_GATE42_MISSING_MANDATORY_COMPARATOR_NT_LOT_ID") sentinel_nt = expected_nt if expected_nt is not None else "__MISSING_REQUIRED_NT_LOT_ID__" spec, _, b_fails, b_holds, mat_ev, sw_ev, g0v_ev, g31_ev = _validate_canonical_binding_v6( rec, allow_design_a=True, coating_gate=False, phase="EXACT_PRODUCT", require_materialization=True, require_switches=True, expected_candidate_gene=target if target in C1_FAMILY_GENES else None, expected_comparator_nt_lot_id=sentinel_nt if isinstance(c1_raw, Mapping) else None, ) fails.extend(b_fails) holds.extend(b_holds) prod_s = str(rec.get("product_id", "")).strip() bank_s = str(rec.get("bank_id", "")).strip() lot_s = str(rec.get("lot_id", "")).strip() route_s = str(rec.get("route_id", "")).strip().upper() is_design_a = (prod_s == "ISLET1_DESIGN_A_V080_REF") if is_design_a and route_s != "R1": fails.append("FAIL_DESIGN_A_DIAGNOSTIC_MUST_USE_UNCOATED_R1") df_ev = _validate_content_receipt( rec.get("drug_free_exposure_evidence"), expected_stage="DRUG_FREE_EXPOSURE", expected_prod=prod_s, expected_bank=bank_s, expected_lot=lot_s, expected_route=route_s, expected_scope="exact_product", expected_parent=mat_ev, allowed_extra_keys=frozenset({"route_coated", "added_drugs_count"}), fails=fails, holds=holds, missing_hold="HOLD_DRUG_FREE_EXPOSURE_RECEIPT_MISSING", fail_code="FAIL_DRUG_FREE_EXPOSURE_FAILED", mismatch_code="FAIL_DRUG_FREE_EXPOSURE_SCOPE_MISMATCH", ) if df_ev is not None: if df_ev.get("route_coated") is not False or df_ev.get("added_drugs_count") != 0: fails.append("FAIL_GATE42_REQUIRES_100PCT_DRUG_FREE_UNCOATED_EXPOSURE") if not (is_strict_bool(rec.get("zero_fasta_minted")) and rec["zero_fasta_minted"]): fails.append("FAIL_ZERO_FASTA_MINTED_BOUNDARY_VIOLATED") g36_ev: Optional[Mapping[str, Any]] = None if is_design_a: if "foundry_v2_gate36_evidence" in rec and rec["foundry_v2_gate36_evidence"] is not None: fails.append("FAIL_DESIGN_A_FORBIDS_FOUNDRY_V2_GATE36_RECEIPT") elif spec is not None and spec["foundry_v2_biologics_eligible"]: g36_ev = _validate_content_receipt( rec.get("foundry_v2_gate36_evidence"), expected_stage="GATE-36-FOUNDRY-V2", expected_prod=prod_s, expected_bank=bank_s, expected_lot=lot_s, expected_route=route_s, expected_scope="exact_product", expected_parent=mat_ev, min_prereq_receipts=[("DRUG_FREE_EXPOSURE", df_ev)], allowed_extra_keys=frozenset({ "canonical_gate36_producer_sha256", "canonical_gate36_verdict", "foundry_v2_module_scope", "active_drug_free_modules", "module_producer_receipt_sha256s", "exogenous_shield_excluded_from_drug_free_scope", "live_gate32_debris_recall_receipt", "matched_foundry_exposure_verified", }), fails=fails, holds=holds, missing_hold="HOLD_FOUNDRY_V2_GATE36_RECEIPT_MISSING", fail_code="FAIL_FOUNDRY_V2_GATE36_FAILED", mismatch_code="FAIL_FOUNDRY_V2_GATE36_SCOPE_MISMATCH", ) if g36_ev is not None: if not is_valid_sha256_hex(g36_ev.get("canonical_gate36_producer_sha256")): fails.append("FAIL_FOUNDRY_V2_GATE36_MISSING_PRODUCER_SHA256") if g36_ev.get("canonical_gate36_verdict") != "PASS": fails.append("FAIL_FOUNDRY_V2_GATE36_NOT_PASSED") if g36_ev.get("foundry_v2_module_scope") != "INTRINSIC_CUFF_BIOLOGICS_NO_EXOGENOUS_SHIELD": fails.append("FAIL_FOUNDRY_V2_GATE36_EXOGENOUS_SHIELD_OUTSIDE_DRUG_FREE_SCOPE") if not (is_strict_bool(g36_ev.get("exogenous_shield_excluded_from_drug_free_scope")) and g36_ev["exogenous_shield_excluded_from_drug_free_scope"]): fails.append("FAIL_FOUNDRY_V2_GATE36_EXOGENOUS_SHIELD_NOT_EXCLUDED") # Strict zero-administered-agent drug-free path excludes pre-transplant administered GATE-36-INVVAX # (GATE-36:89,97), permitting ONLY graft-intrinsic / cuff modules {"GATE-36-CUFF", "GATE-36-INS"}! allowed_df_mods = frozenset({"GATE-36-CUFF", "GATE-36-INS"}) act_mods = g36_ev.get("active_drug_free_modules") mod_shas = g36_ev.get("module_producer_receipt_sha256s") act_mods_str_ok = isinstance(act_mods, list) and all(isinstance(m, str) for m in act_mods) if not ( act_mods_str_ok and len(act_mods) >= 1 and set(act_mods) <= allowed_df_mods and len(set(act_mods)) == len(act_mods) and isinstance(mod_shas, Mapping) and set(mod_shas.keys()) == set(act_mods) and all(is_valid_sha256_hex(v) for v in mod_shas.values()) ): fails.append("FAIL_FOUNDRY_V2_GATE36_INVALID_DRUG_FREE_MODULE_PRODUCERS") if not (is_strict_bool(g36_ev.get("matched_foundry_exposure_verified")) and g36_ev["matched_foundry_exposure_verified"]): fails.append("FAIL_FOUNDRY_V2_GATE36_EXPOSURE_UNVERIFIED") # Explicit GATE-32 disposition for drug-free Foundry subset: # - GATE-36-CUFF active -> MUST provide validated passing live GATE-32 debris-recall receipt. # - ONLY GATE-36-INS active (no exogenous SHIELD & no CUFF) -> accepts validated GATE-32 receipt OR # explicit sentinel "NOT_APPLICABLE_NO_EXOGENOUS_SHIELD_OR_CUFF_DEBRIS_CLAIM". g32_raw = g36_ev.get("live_gate32_debris_recall_receipt") cuff_active = act_mods_str_ok and ("GATE-36-CUFF" in act_mods) ins_only_active = act_mods_str_ok and set(act_mods) == {"GATE-36-INS"} if g32_raw == "NOT_APPLICABLE_NO_EXOGENOUS_SHIELD_OR_CUFF_DEBRIS_CLAIM": if cuff_active or not ins_only_active: fails.append("FAIL_FOUNDRY_V2_GATE36_CUFF_REQUIRES_LIVE_GATE32_RECEIPT") g32_ev = None else: g32_ev = _validate_content_receipt( g32_raw, expected_stage="GATE-32-DEBRIS-RECALL", expected_prod=prod_s, expected_bank=bank_s, expected_lot=lot_s, expected_route=route_s, expected_scope="exact_product", expected_parent=mat_ev, allowed_extra_keys=frozenset({ "canonical_gate32_producer_sha256", "debris_recall_verdict", "debris_recall_l95_suppressed_frac", "residual_class2_recall_u95_frac", "unrelated_recall_preserved", }), fails=fails, holds=holds, missing_hold="HOLD_FOUNDRY_V2_GATE36_LIVE_GATE32_RECEIPT_MISSING", fail_code="FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_FAILED", mismatch_code="FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_SCOPE_MISMATCH", ) if g32_ev is not None: if not is_valid_sha256_hex(g32_ev.get("canonical_gate32_producer_sha256")): fails.append("FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_MISSING_PRODUCER_SHA256") if g32_ev.get("debris_recall_verdict") != "PASS_DEBRIS_RECALL_FULL_CREDIT": fails.append("FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_DEBRIS_RECALL_NOT_PASSED") # Exact live GATE-36:34 GATE-32 thresholds: l95 >= 0.70, residual_class2_u95 <= 0.30, unrelated_recall_preserved == True! dr_l95 = g32_ev.get("debris_recall_l95_suppressed_frac") rc2_u95 = g32_ev.get("residual_class2_recall_u95_frac") unrel = g32_ev.get("unrelated_recall_preserved") if not (is_finite_num(dr_l95) and 0.70 <= float(dr_l95) <= 1.0): fails.append("FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_RECALL_L95_BELOW_0P70") if not (is_finite_num(rc2_u95) and 0.0 <= float(rc2_u95) <= 0.30): fails.append("FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_RESIDUAL_CLASS2_EXCEEDS_0P30") if not (is_strict_bool(unrel) and unrel): fails.append("FAIL_FOUNDRY_V2_GATE36_LIVE_GATE32_UNRELATED_RECALL_COMPROMISED") t32 = parse_utc_iso_ts(g32_ev.get("recorded_at_utc")) t36 = parse_utc_iso_ts(g36_ev.get("recorded_at_utc")) if t32 is not None and t36 is not None and t32 > t36: fails.append("FAIL_CHRONOLOGICAL_PREREQ_POSTDATES_STAGE:GATE-32_AFTER_GATE-36") # Complete canonical 5 x 2 IIP-0049 Stage-2 Attribution Matrix (docs/TNFA-IFNG-INTRINSIC-APOPTOSIS-QUALIFICATION-NOTE.md:54-60)! att_prereqs: list[tuple[str, Optional[Mapping[str, Any]]]] = [("BANK_MATERIALIZATION", mat_ev), ("DRUG_FREE_EXPOSURE", df_ev)] if g36_ev is not None: att_prereqs.append(("GATE-36-FOUNDRY-V2", g36_ev)) att_extras = frozenset({ "reference_comparator_backgrounds", "reference_comparator_measurements", "stage1_gatekeeper_record", "stage2_block_manifest", "stage1_cytokine_window_positive", "stage1_cytokine_drop_pp", "stage2_il1_independent_apoptosis_persists", "residual_viable_beta_drop_pp", "concurrent_controls_valid", "t0_original_plated_denominators_used", "biological_blocks_n", "background_class", "foundry_v2_gate36_receipt_sha256", "stage2_normoxia_mechanism_panel", "stage2_hypoxia_15mmhg_mechanism_panel", }) att_ev = _validate_content_receipt( rec.get("iip0049_foundry_attribution_evidence"), expected_stage="IIP0049_ATTRIBUTION", expected_prod=prod_s, expected_bank=bank_s, expected_lot=lot_s, expected_route=route_s, expected_scope="exact_product", min_prereq_receipts=att_prereqs, allowed_extra_keys=att_extras, fails=fails, holds=holds, missing_hold="HOLD_IIP0049_STAGE1_STAGE2_ATTRIBUTION_MISSING", fail_code="FAIL_IIP0049_ATTRIBUTION_FAILED", mismatch_code="FAIL_IIP0049_ATTRIBUTION_SCOPE_MISMATCH",