r_run1x9_80 = evaluate_gate30_shield_spr( build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(0,) * 9, donor_suppressions=(80.0,) * 9, shared_assay_runs_n=1, ) ) r_run1x9_30 = evaluate_gate30_shield_spr( build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(0,) * 9, donor_suppressions=(30.0,) * 9, shared_assay_runs_n=1, ) ) c_staircase = json.loads(json.dumps(base_pass)) for idx_d, d in enumerate(c_staircase["tcell_blockade_and_apc_cytotoxicity_donors"]): # Alternating shared batch and shared assay_run chain across 9 valid single-mixture donors -> 1 joint component! b_idx = (idx_d // 2) + 1 r_idx = ((idx_d + 1) // 2) + 1 d["cocktail_mixture_id"] = f"MIX_SHIELD_{b_idx:02d}" d["expression_batch_ids"] = [f"BATCH_ECOLI_{b_idx:02d}"] d["assay_run_id"] = f"SHIELD_ASSAY_RUN_{r_idx:02d}" r_staircase = evaluate_gate30_shield_spr(c_staircase) if ( r_run1x9_80["verdict"] != "HOLD" or r_run1x9_80["derived_summary"]["suppression_run_clusters_n"] != 1 or abs(r_run1x9_80["derived_summary"]["suppression_responder_l95_clopper_pearson_pct"] - 5.0) > 1e-4 or r_run1x9_30["verdict"] != "HOLD" or r_run1x9_30["derived_summary"]["suppression_run_clusters_n"] != 1 or r_staircase["verdict"] != "HOLD" or r_staircase["derived_summary"]["suppression_independent_joint_clusters_n"] != 1 ): raise RuntimeError( f"R10 shared-run / staircase cluster guard failed: " f"run80={r_run1x9_80['verdict']}, run30={r_run1x9_30['verdict']}, stair={r_staircase['verdict']}" ) # 75 (R10 B5a): Missing or invalid donor_sampling_and_independence_design or missing assay_run_id -> HOLD_INVALID! c_no_sd = json.loads(json.dumps(base_pass)) c_no_sd.pop("donor_sampling_and_independence_design", None) c_bad_sd = json.loads(json.dumps(base_pass)) c_bad_sd["donor_sampling_and_independence_design"]["sampling_design_class"] = "CONVENIENCE_CLUSTERED" c_no_run = json.loads(json.dumps(base_pass)) c_no_run["tcell_blockade_and_apc_cytotoxicity_donors"][0].pop("assay_run_id", None) r_no_sd = evaluate_gate30_shield_spr(c_no_sd) r_bad_sd = evaluate_gate30_shield_spr(c_bad_sd) r_no_run = evaluate_gate30_shield_spr(c_no_run) if ( r_no_sd["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_no_sd["derived_summary"]["authorization_grade_suppression_inference_valid"] is not False or r_bad_sd["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_no_run["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" ): raise RuntimeError( f"R10 sampling design / assay_run_id enforcement failed: " f"no_sd={r_no_sd['verdict']}, bad_sd={r_bad_sd['verdict']}, no_run={r_no_run['verdict']}" ) # 76 (R10 B5b / 0039-B3): GY-018 explicitly clustered text AND invalid unit class / flags -> ALL HOLD_INVALID! c_gy_clustered_txt = json.loads(json.dumps(base_pass)) for d in c_gy_clustered_txt["tcell_blockade_and_apc_cytotoxicity_donors"]: d["gy018_independence_justification"]["independent_experimental_unit"] = "Technical reads from one well only" d["gy018_independence_justification"]["clustering_controls"] = "None; all reads share the same well and are dependent" c_gy_bad_cls = json.loads(json.dumps(base_pass)) c_gy_bad_cls["tcell_blockade_and_apc_cytotoxicity_donors"][0]["gy018_independence_justification"]["independent_unit_class"] = "TECHNICAL_REPLICATE_SINGLE_WELL" c_gy_bad_flag = json.loads(json.dumps(base_pass)) c_gy_bad_flag["tcell_blockade_and_apc_cytotoxicity_donors"][0]["gy018_independence_justification"]["within_donor_units_physically_independent"] = False r_gy_clustered_txt = evaluate_gate30_shield_spr(c_gy_clustered_txt) r_gy_bad_cls = evaluate_gate30_shield_spr(c_gy_bad_cls) r_gy_bad_flag = evaluate_gate30_shield_spr(c_gy_bad_flag) if any(r["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" for r in (r_gy_clustered_txt, r_gy_bad_cls, r_gy_bad_flag)): raise RuntimeError( f"R10 GY-018 clustered-unit rejection failed: " f"txt={r_gy_clustered_txt['verdict']}, cls={r_gy_bad_cls['verdict']}, flag={r_gy_bad_flag['verdict']}" ) # 77 (R10 B6 / 0039-B4 / R13 0039-B2): Unified precedence — missing roster + 18/60 donor cyto -> HOLD_INVALID (fwer_valid=False), # whereas missing roster + valid 650-800 nM SPR FAIL -> FAIL (failure_domain=INDEPENDENT_NON_DONOR_SPR, fwer_valid=False)! c_noroster_cyto18 = build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(18, 0, 0, 0, 0, 0, 0, 0, 0), include_preregistered_roster=False, ) c_noroster_sprfail = build_valid_shield_spr_observation(n_eff_per_donor=60, include_preregistered_roster=False) c_noroster_sprfail["on_target_analytes"][0]["ic50_l95_nm"] = 650.0 c_noroster_sprfail["on_target_analytes"][0]["ic50_u95_nm"] = 800.0 r_noroster_cyto18 = evaluate_gate30_shield_spr(c_noroster_cyto18) r_noroster_sprfail = evaluate_gate30_shield_spr(c_noroster_sprfail) if ( r_noroster_cyto18["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_noroster_cyto18["derived_summary"]["authorization_grade_fwer_bound_valid"] is not False or r_noroster_cyto18["derived_summary"]["failure_domain"] is not None or r_noroster_sprfail["verdict"] != "FAIL" or r_noroster_sprfail["derived_summary"]["authorization_grade_fwer_bound_valid"] is not False or r_noroster_sprfail["derived_summary"]["failure_domain"] != "INDEPENDENT_NON_DONOR_SPR" ): raise RuntimeError( f"R10 unified roster vs independent SPR precedence failed: " f"cyto18={r_noroster_cyto18['verdict']}, sprfail={r_noroster_sprfail}" ) # 78 (R10 B7 / 0039-B5): Extreme finite suppression_pct=-1e200 via BOTH direct dict AND strict JSON -> HOLD_INVALID (ZERO OverflowError!), # plus direct overflow-immunity check on _shield_student_t_ci_pct([-1e200, 80.0, 80.0]) and [-1e300, 1e300, 0.0]! c_neg1e200 = json.loads(json.dumps(base_pass)) c_neg1e200["tcell_blockade_and_apc_cytotoxicity_donors"][0]["suppression_pct"] = -1e200 r_neg1e200_direct = evaluate_gate30_shield_spr(c_neg1e200) r_neg1e200_json = evaluate_gate30_shield_spr(load_strict_json_text(json.dumps(c_neg1e200), "r10_neg1e200")) diag_m1, diag_l1, diag_u1 = _shield_student_t_ci_pct([-1e200, 80.0, 80.0]) diag_m2, diag_l2, diag_u2 = _shield_student_t_ci_pct([-1e300, 1e300, 0.0]) if ( r_neg1e200_direct["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_neg1e200_json["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or not all(math.isfinite(x) for x in (diag_m1, diag_l1, diag_u1, diag_m2, diag_l2, diag_u2)) ): raise RuntimeError( f"R10 -1e200 overflow-immunity check failed: " f"direct={r_neg1e200_direct['verdict']}, json={r_neg1e200_json['verdict']}" ) # 79 (R10 M2 / 0039-M2): Native WT InsB:9-23 on-target SPR row MUST declare peptide_sequence and match register_qc peptide_reagent_lot_id! c_wt_noseq = json.loads(json.dumps(base_pass)) c_wt_noseq["on_target_analytes"][3].pop("peptide_sequence", None) c_wt_badlot = json.loads(json.dumps(base_pass)) c_wt_badlot["on_target_analytes"][3]["peptide_reagent_lot_id"] = "REAGENT_WT15_OTHER_LOT99" r_wt_noseq = evaluate_gate30_shield_spr(c_wt_noseq) r_wt_badlot = evaluate_gate30_shield_spr(c_wt_badlot) if r_wt_noseq["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_wt_badlot["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT": raise RuntimeError( f"R10 WT15 peptide_sequence / reagent lot linkage failed: " f"noseq={r_wt_noseq['verdict']}, badlot={r_wt_badlot['verdict']}" ) # 80 (R10 M1 & Cluster Calibration Proof): External custody flag & exact cluster-level false-PASS <= 0.05 verification! if ( r_pass["derived_summary"].get("external_preregistration_custody_required") is not True or "external" not in str(r_pass["derived_summary"].get("local_json_replay_scope_note", "")).lower() or "disjoint" not in str(r_pass["derived_summary"].get("suppression_statistical_boundary_note", "")).lower() ): raise RuntimeError("R10 external custody & statistical boundary metadata missing from derived_summary") for m_clusters in (1, 3, 5, 6, 8, 9, 12): pass_ks_c = [ kv for kv in range(m_clusters + 1) if _clopper_pearson_one_sided_95_pct(kv, m_clusters, alpha=0.05)[0] >= _SHIELD_SUPPRESSION_PASS_THRESHOLD_PCT ] p_fp_c = sum(_shield_binom_pmf(m_clusters, kv, 0.69) for kv in pass_ks_c) if p_fp_c > 0.05 + 1e-12: raise RuntimeError(f"Cluster-level false-PASS exceeded 0.05 for M={m_clusters}: {p_fp_c:.6f}") # 81 (R11 0037-B1): Fixed 8:1 stratified HLA-DQ allocation, 9/9 responders across 9 distinct batches/runs -> HOLD (NOT PASS!) c_strat_8to1 = build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(0,) * 9, donor_suppressions=(80.0,) * 9, sampling_design_class="STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT", ) for idx_s, d in enumerate(c_strat_8to1["tcell_blockade_and_apc_cytotoxicity_donors"]): d["hla_genotype"] = "HLA-DQ2.5" if idx_s < 8 else "HLA-DQ8" r_strat_8to1 = evaluate_gate30_shield_spr(c_strat_8to1) c_srs_9of9 = json.loads(json.dumps(c_strat_8to1)) c_srs_9of9["donor_sampling_and_independence_design"]["sampling_design_class"] = ( "SIMPLE_RANDOM_OR_CONSECUTIVE_INDEPENDENT_T1D_COHORT" ) c_srs_9of9["donor_sampling_and_independence_design"]["between_donor_independence_justification"] = ( "DISJOINT_BATCH_AND_RUN_INDEPENDENT_T1D_DONOR_COHORT" ) r_srs_9of9 = evaluate_gate30_shield_spr(c_srs_9of9) if ( r_strat_8to1["verdict"] != "HOLD" or r_strat_8to1["derived_summary"].get("donor_sampling_design_valid") is not True or r_strat_8to1["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not False or r_strat_8to1["derived_summary"].get("authorization_grade_suppression_inference_valid") is not False or r_strat_8to1["derived_summary"].get("authorization_grade_fwer_bound_valid") is not True or not any("STRATIFIED_COHORT_REQUIRES_TARGET_WEIGHTED_SUPPRESSION_ESTIMATOR" in rs for rs in r_strat_8to1["reasons"]) or r_srs_9of9["verdict"] != "PASS" or r_srs_9of9["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not True ): raise RuntimeError( f"R11 0037-B1 8:1 stratified cohort narrowing failed: " f"strat={r_strat_8to1['verdict']}, srs={r_srs_9of9['verdict']}" ) # 82 (R11 0039-B1): Fixed 20:1 stratified HLA-DQ allocation, 20/21 responders across 21 distinct batches/runs -> HOLD (NOT PASS!) c_strat_20to1 = build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(0,) * 21, donor_suppressions=(80.0,) * 20 + (0.0,), sampling_design_class="STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT", ) for idx_s, d in enumerate(c_strat_20to1["tcell_blockade_and_apc_cytotoxicity_donors"]): d["hla_genotype"] = "HLA-DQ2.5" if idx_s < 20 else "HLA-DQ8" r_strat_20to1 = evaluate_gate30_shield_spr(c_strat_20to1) if ( r_strat_20to1["verdict"] != "HOLD" or r_strat_20to1["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not False or r_strat_20to1["derived_summary"].get("authorization_grade_suppression_inference_valid") is not False or abs(r_strat_20to1["derived_summary"].get("suppression_responder_l95_clopper_pearson_pct", 0.0) - 79.327504) > 1e-3 or not any("STRATIFIED_COHORT_REQUIRES_TARGET_WEIGHTED_SUPPRESSION_ESTIMATOR" in rs for rs in r_strat_20to1["reasons"]) ): raise RuntimeError(f"R11 0039-B1 20:1 stratified cohort narrowing failed: {r_strat_20to1}") # 83 (R11 Symmetric Stratified Low-Rate & Legacy/Quota Rejection): 1:20 stratified cohort with 1/21 responder # and no enhancement/cyto/SPR fail -> HOLD (NOT unweighted population-rate suppression FAIL!); # legacy PROSPECTIVE_INDEPENDENT_T1D_DONOR_COHORT & QUOTA_* rejected as HOLD_INVALID_OR_MISSING_INPUT! c_strat_1to20_low = build_valid_shield_spr_observation( n_eff_per_donor=60, donor_k_obs=(0,) * 21, donor_suppressions=(80.0,) + (30.0,) * 20, sampling_design_class="STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT", ) for idx_s, d in enumerate(c_strat_1to20_low["tcell_blockade_and_apc_cytotoxicity_donors"]): d["hla_genotype"] = "HLA-DQ2.5" if idx_s == 0 else "HLA-DQ8" r_strat_1to20_low = evaluate_gate30_shield_spr(c_strat_1to20_low) c_srs_1to20_low = json.loads(json.dumps(c_strat_1to20_low)) c_srs_1to20_low["donor_sampling_and_independence_design"]["sampling_design_class"] = ( "SIMPLE_RANDOM_OR_CONSECUTIVE_INDEPENDENT_T1D_COHORT" ) c_srs_1to20_low["donor_sampling_and_independence_design"]["between_donor_independence_justification"] = ( "DISJOINT_BATCH_AND_RUN_INDEPENDENT_T1D_DONOR_COHORT" ) r_srs_1to20_low = evaluate_gate30_shield_spr(c_srs_1to20_low) c_legacy_prosp = json.loads(json.dumps(base_pass)) c_legacy_prosp["donor_sampling_and_independence_design"]["sampling_design_class"] = ( "PROSPECTIVE_INDEPENDENT_T1D_DONOR_COHORT" ) r_legacy_prosp = evaluate_gate30_shield_spr(c_legacy_prosp) c_quota_cls = json.loads(json.dumps(base_pass)) c_quota_cls["donor_sampling_and_independence_design"]["sampling_design_class"] = "QUOTA_INDEPENDENT_T1D_COHORT" r_quota_cls = evaluate_gate30_shield_spr(c_quota_cls) if ( r_strat_1to20_low["verdict"] != "HOLD" or r_strat_1to20_low["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not False or r_strat_1to20_low["derived_summary"].get("failure_domain") is not None or not any("STRATIFIED_COHORT_REQUIRES_TARGET_WEIGHTED_SUPPRESSION_ESTIMATOR" in rs for rs in r_strat_1to20_low["reasons"]) or r_srs_1to20_low["verdict"] != "FAIL" or r_srs_1to20_low["derived_summary"].get("failure_domain") != "ROSTERED_DONOR_COHORT" or r_legacy_prosp["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_legacy_prosp["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not False or r_quota_cls["verdict"] != "HOLD_INVALID_OR_MISSING_INPUT" or r_quota_cls["derived_summary"].get("suppression_inference_authorized_by_sampling_design") is not False ): raise RuntimeError( f"R11 symmetric stratified low-rate / legacy / quota rejection failed: " f"strat_low={r_strat_1to20_low['verdict']}, srs_low={r_srs_1to20_low['verdict']}, " f"legacy={r_legacy_prosp['verdict']}, quota={r_quota_cls['verdict']}" ) # 84 (R11 Safety Preservation on Stratified Cohorts + 0039-M1 Assay Acceptance Range): # Stratified cohort WITH SPR FAIL or fixed-roster Bonferroni cytotoxicity FAIL MUST still return FAIL!