scripts/verify_iip0041_clinical_h1_cd64t_siglec.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…
diff_n = _strict_int(payload.get("independent_differentiations_n"), min_val=min_diff)
if sera_n is None or nk_n is None or diff_n is None:
reasons.append(
f"Invalid, omitted, or underpowered exact-int sampling counts "
f"(sera={payload.get('independent_t1d_sera_n')!r} [min {min_sera}], "
f"nk={payload.get('independent_nk_donors_n')!r} [min {min_nk}], "
f"diffs={payload.get('independent_differentiations_n')!r} [min {min_diff}])."
)
# Mandatory matched head-to-head assay run & donor/sera/differentiation panel identity on payload
payload_run_id = _strict_literal_id(payload.get("paired_assay_run_id"))
if payload_run_id is None:
reasons.append(f"Missing or whitespace-padded mandatory literal paired_assay_run_id={payload.get('paired_assay_run_id')!r}.")
p_sera_ids, ps_errs = _validate_literal_panel_id_list(payload.get("t1d_sera_panel_ids"), field_name="t1d_sera_panel_ids", min_count=min_sera)
p_nk_ids, pn_errs = _validate_literal_panel_id_list(payload.get("nk_donor_panel_ids"), field_name="nk_donor_panel_ids", min_count=min_nk)
p_diff_ids, pd_errs = _validate_literal_panel_id_list(payload.get("differentiation_batch_ids"), field_name="differentiation_batch_ids", min_count=min_diff)
reasons.extend(ps_errs + pn_errs + pd_errs)
if sera_n is not None and p_sera_ids is not None and len(p_sera_ids) != sera_n:
reasons.append(f"Payload t1d_sera_panel_ids count ({len(p_sera_ids)}) != independent_t1d_sera_n ({sera_n}).")
if nk_n is not None and p_nk_ids is not None and len(p_nk_ids) != nk_n:
reasons.append(f"Payload nk_donor_panel_ids count ({len(p_nk_ids)}) != independent_nk_donors_n ({nk_n}).")
if diff_n is not None and p_diff_ids is not None and len(p_diff_ids) != diff_n:
reasons.append(f"Payload differentiation_batch_ids count ({len(p_diff_ids)}) != independent_differentiations_n ({diff_n}).")
payload_panel_digest: str | None = None
if payload_run_id is not None and p_sera_ids is not None and p_nk_ids is not None and p_diff_ids is not None:
payload_panel_digest = compute_paired_assay_panel_digest(payload_run_id, p_sera_ids, p_nk_ids, p_diff_ids)
if "panel_digest" in payload and payload["panel_digest"] is not None and payload["panel_digest"] != payload_panel_digest:
reasons.append("Payload panel_digest does not match canonical digest of paired_assay_run_id and panel IDs.")
# 5. Mandatory separate 1-copy & 2-copy QuantiBRITE density + linked raw t0_mfi/day90_mfi retention derivation
# using context-independent exact Fraction cross-product comparisons over already-decoded inputs
# (JSON-decoded IEEE-754 float64 precision for strict JSON intake; exact Decimal/int precision when passed directly;
# always immune to ambient decimal.getcontext() precision and traps!)
dens_min_frac = Fraction(Decimal(str(gate_cfg["quantibrite_surface_density_min_molecules_per_cell"])))
ret_min = Decimal(str(gate_cfg["day90_mfi_retention_min_pct"]))
ret_min_frac = Fraction(ret_min)
ret_max_assay = Decimal(str(gate_cfg.get("day90_mfi_retention_max_assay_domain_pct", 1000.0)))
ret_max_assay_frac = Fraction(ret_max_assay)
ret_tol = Decimal(str(gate_cfg["day90_mfi_retention_reconciliation_tolerance_pp"]))
ret_tol_frac = Fraction(ret_tol)
adcc_max = Decimal(str(gate_cfg["intact_and_igg_adcc_u95_max_pct"]))
ap_max = Decimal(str(gate_cfg["ap_c5b9_u95_max_pct"]))
nhs_max = Decimal(str(gate_cfg["overall_20pct_nhs_u95_max_pct"]))
adcc_max_frac = Fraction(adcc_max)
ap_max_frac = Fraction(ap_max)
nhs_max_frac = Fraction(nhs_max)
derived_mfi_retentions: dict[str, float | None] = {}
payload_cand_head_to_head: dict[str, Any] = {}
for copy_lbl in ("copy1_monoallelic", "copy2_biallelic"):
sub = payload.get(copy_lbl)
if not isinstance(sub, dict):
reasons.append(f"Missing mandatory separate {copy_lbl} qualification block.")
continue
t0 = _strict_decimal_in_range(sub.get("quantibrite_t0_molecules_per_cell"), min_val=Decimal("0"))
d90 = _strict_decimal_in_range(sub.get("quantibrite_day90_molecules_per_cell"), min_val=Decimal("0"))
t0_mfi = _strict_decimal_in_range(sub.get("t0_mfi"), min_val=Decimal("0"), exclusive_min=True)
d90_mfi = _strict_decimal_in_range(sub.get("day90_mfi"), min_val=Decimal("0"))
ret_reported_raw = sub.get("day90_mfi_retention_pct_vs_t0")
adcc_int = _strict_decimal_in_range(sub.get("intact_serum_cd16_adcc_u95_pct"), min_val=Decimal("0"), max_val=Decimal("100"))
adcc_igg = _strict_decimal_in_range(sub.get("igg_attributable_cd16_adcc_u95_pct"), min_val=Decimal("0"), max_val=Decimal("100"))
ap_c5b9 = _strict_decimal_in_range(sub.get("ap_c5b9_u95_pct"), min_val=Decimal("0"), max_val=Decimal("100"))
nhs20 = _strict_decimal_in_range(sub.get("overall_20pct_nhs_u95_pct"), min_val=Decimal("0"), max_val=Decimal("100"))
preload_ok = _strict_bool(sub.get("post_7day_10mgml_igg_preload_functional_pass"))
if t0 is None or Fraction(t0) < dens_min_frac:
reasons.append(f"{copy_lbl}: t=0 calibrated CD64t density invalid or < {float(dens_min_frac):.0f} molecules/cell.")
if d90 is None or Fraction(d90) < dens_min_frac:
reasons.append(f"{copy_lbl}: Day-90 calibrated CD64t density invalid or < {float(dens_min_frac):.0f} molecules/cell.")
if t0_mfi is None or d90_mfi is None:
reasons.append(
f"{copy_lbl}: mandatory linked raw t0_mfi (> 0) and day90_mfi (>= 0) required to derive and authenticate Day-90 MFI retention."
)
else:
# Exact context-independent rational cross-product comparisons FIRST (NEVER affected by caller Decimal traps/precision/Emax):
# 100 * day90_mfi / t0_mfi >= ret_min <==> Fraction(day90_mfi) * 100 >= Fraction(t0_mfi) * Fraction(ret_min)
# 100 * day90_mfi / t0_mfi <= ret_max_assay <==> Fraction(day90_mfi) * 100 <= Fraction(t0_mfi) * Fraction(ret_max_assay)
d90_mfi_frac = Fraction(d90_mfi)
t0_mfi_frac = Fraction(t0_mfi)
derived_ret_frac = (d90_mfi_frac * 100) / t0_mfi_frac
out_of_assay_range_mfi = (d90_mfi_frac * 100) > (t0_mfi_frac * ret_max_assay_frac)
passes_mfi_retention = (not out_of_assay_range_mfi) and ((d90_mfi_frac * 100) >= (t0_mfi_frac * ret_min_frac))
# Display formatting AFTER exact Fraction comparison inside a clean Decimal context explicitly clearing
# Inexact/Rounded/Clamped/Subnormal/Underflow and locking wide exponent bounds (supports direct Fraction,
# Decimal, int, and float inputs; NEVER calls float() on out-of-range ratios!).
display_ret_float, display_ret_str = _format_exact_fraction_pct_display(
derived_ret_frac,
out_of_assay_range=out_of_assay_range_mfi,
)
derived_mfi_retentions[copy_lbl] = display_ret_float
if out_of_assay_range_mfi:
reasons.append(
f"OUT_OF_ASSAY_RANGE_MFI_RETENTION: {copy_lbl}: derived Day-90 MFI retention "
f"({display_ret_str} = 100*{d90_mfi}/{t0_mfi}) exceeds physical assay domain cap [0, {ret_max_assay}]%."
)
elif not passes_mfi_retention:
reasons.append(
f"{copy_lbl}: derived Day-90 MFI retention ({display_ret_str} = 100*{d90_mfi}/{t0_mfi}) < {ret_min}%."
)
if ret_reported_raw is not None:
ret_rep = _strict_decimal_in_range(ret_reported_raw, min_val=Decimal("0"), max_val=ret_max_assay)
if ret_rep is None or abs(Fraction(ret_rep) - derived_ret_frac) > ret_tol_frac:
reasons.append(
f"{copy_lbl}: reported day90_mfi_retention_pct_vs_t0={ret_reported_raw!r} fails reconciliation "
f"against derived 100*day90_mfi/t0_mfi={display_ret_str} (max tol {ret_tol} pp)."
)
if adcc_int is None or Fraction(adcc_int) > adcc_max_frac or adcc_igg is None or Fraction(adcc_igg) > adcc_max_frac:
reasons.append(
f"{copy_lbl}: intact ({sub.get('intact_serum_cd16_adcc_u95_pct')!r}) or IgG-attributable "
f"({sub.get('igg_attributable_cd16_adcc_u95_pct')!r}) CD16+ ADCC U95_t outside [0, {adcc_max}]%."
)
if ap_c5b9 is None or Fraction(ap_c5b9) > ap_max_frac or nhs20 is None or Fraction(nhs20) > nhs_max_frac:
reasons.append(
f"{copy_lbl}: AP C5b-9 ({sub.get('ap_c5b9_u95_pct')!r}) or 20% NHS ({sub.get('overall_20pct_nhs_u95_pct')!r}) "
f"U95_t outside [0, {ap_max}]%."
)
if preload_ok is not True:
reasons.append(f"{copy_lbl}: 7-day 10 mg/mL polyclonal IgG pre-loading functional assay must be strict bool True.")
if adcc_int is not None and adcc_igg is not None and ap_c5b9 is not None and nhs20 is not None:
payload_cand_head_to_head[copy_lbl] = {
"intact_serum_cd16_adcc_u95_pct": Fraction(adcc_int),
"igg_attributable_cd16_adcc_u95_pct": Fraction(adcc_igg),
"ap_c5b9_u95_pct": Fraction(ap_c5b9),
"overall_20pct_nhs_u95_pct": Fraction(nhs20),
}
# 6. Strict boolean signaling/matrix gates + mandatory quantitative IL-1Ra, basal leak, GSIS, and AP1903 endpoints
if _strict_bool(payload.get("fcr_gamma_coip_and_phospho_syk_negative")) is not True:
reasons.append("Empirical FcRgamma (FCER1G) co-IP & phospho-Syk/ITAM negative check must be strict bool True.")
if _strict_bool(payload.get("cd274p_il1rn_ifn_titration_matrix_passed")) is not True:
reasons.append("CD274p::IL1RN IFN-gamma titration matrix check must be strict bool True.")
il1ra_min = Decimal(str(gate_cfg["il1rn_to_il1b_molar_excess_min"]))
leak_max = Decimal(str(gate_cfg["il1rn_basal_leak_max_pct"]))
gsis_min = Decimal(str(gate_cfg["gsis_retention_min_pct"]))
ap1903_min = Decimal(str(gate_cfg["ap1903_icasp9_ablation_min_pct"]))
il1ra_excess = _strict_decimal_in_range(payload.get("il1rn_to_il1b_molar_excess"), min_val=Decimal("0"))
if il1ra_excess is None or Fraction(il1ra_excess) < Fraction(il1ra_min):
reasons.append(
f"Quantitative stimulated IL-1Ra:IL-1beta molar excess ({payload.get('il1rn_to_il1b_molar_excess')!r}) "
f"missing, out of domain, or < {il1ra_min} (prospective design criterion)."
)
basal_leak = _strict_decimal_in_range(payload.get("il1rn_basal_leak_pct_of_induced"), min_val=Decimal("0"), max_val=Decimal("100"))
if basal_leak is None or Fraction(basal_leak) > Fraction(leak_max):
reasons.append(
f"Quantitative unstimulated CD274p::IL1RN basal leak ({payload.get('il1rn_basal_leak_pct_of_induced')!r}) "
f"missing, outside [0, 100]%, or > {leak_max}% (prospective design criterion)."
)
gsis_ret = _strict_decimal_in_range(payload.get("dynamic_gsis_retention_pct_of_ctrl"), min_val=Decimal("0"), max_val=Decimal("1000"))
if gsis_ret is None or Fraction(gsis_ret) < Fraction(gsis_min):
reasons.append(
f"Quantitative dynamic GSIS retention ({payload.get('dynamic_gsis_retention_pct_of_ctrl')!r}) "
f"missing, out of domain, or < {gsis_min}%."
)
ap1903_abl = _strict_decimal_in_range(payload.get("ap1903_icasp9_ablation_pct"), min_val=Decimal("0"), max_val=Decimal("100"))
if ap1903_abl is None or Fraction(ap1903_abl) < Fraction(ap1903_min):
reasons.append(
f"Quantitative AP1903 iCasp9 ablation ({payload.get('ap1903_icasp9_ablation_pct')!r}) "
f"missing, outside [0, 100]%, or < {ap1903_min}%."
)
# Optional legacy caller flag l2v3_broken_by_t1d_sera_gt_5pct: validate strict bool if supplied,
# NEVER allow bare caller boolean alone to authorize promotion or override trusted paired comparator!
caller_l2v3_broken: bool | None = None
if "l2v3_broken_by_t1d_sera_gt_5pct" in payload and payload["l2v3_broken_by_t1d_sera_gt_5pct"] is not None:
caller_l2v3_broken = _strict_bool(payload.get("l2v3_broken_by_t1d_sera_gt_5pct"))
if caller_l2v3_broken is None:
reasons.append(
f"l2v3_broken_by_t1d_sera_gt_5pct={payload.get('l2v3_broken_by_t1d_sera_gt_5pct')!r} must be explicit strict bool (True/False) when supplied."
)
# 7. Owning GY-025 requires BOTH independent classical (C1q/sensitized) AND lectin (MBL/mannan) C4b2a intervals in [0, 100]%!
cl_max = Decimal(str(gate_cfg["classical_c1q_c4b2a_u95_max_pct"]))
lec_max = Decimal(str(gate_cfg["lectin_mbl_c4b2a_u95_max_pct"]))
hold_pathways: list[str] = []
for p_label, l_key, u_key, cap_pct in (
("classical_C1q_C4b2a", "classical_c4b2a_l95_pct", "classical_c4b2a_u95_pct", cl_max),
("lectin_MBL_C4b2a", "lectin_c4b2a_l95_pct", "lectin_c4b2a_u95_pct", lec_max),
):
l95 = _strict_decimal_in_range(payload.get(l_key), min_val=Decimal("0"), max_val=Decimal("100"))
u95 = _strict_decimal_in_range(payload.get(u_key), min_val=Decimal("0"), max_val=Decimal("100"))
if l95 is None or u95 is None:
reasons.append(f"Missing or out-of-domain [0, 100]% independent {p_label} interval ({l_key}, {u_key}) required by GY-025.")
elif Fraction(u95) < Fraction(l95):
reasons.append(f"Malformed {p_label} interval (L95={l95} > U95={u95}).")
else:
payload_cand_head_to_head[l_key] = Fraction(l95)
payload_cand_head_to_head[u_key] = Fraction(u95)
if Fraction(l95) > Fraction(cap_pct):
reasons.append(f"{p_label} L95_t = {float(l95):.2f}% > {cap_pct}% -> FAIL_HARD_STOP.")
elif Fraction(u95) > Fraction(cap_pct):
hold_pathways.append(f"{p_label} (L95_t={float(l95):.2f}% <= {cap_pct}% < U95_t={float(u95):.2f}%)")
# 8. Full GY-025 physical endpoints (omitted -> caps at COMPONENT_PASS; supplied invalid/failing -> FAIL closed!)
eff_abs_min = Decimal(str(gate_cfg["efferocytosis_abs_min_pct"]))
eff_wt_min = Decimal(str(gate_cfg["efferocytosis_wt_min_pct"]))
iec_t50_max = Decimal(str(gate_cfg["iec_morphogenesis_t50_max_h"]))
iec_viab_min = Decimal(str(gate_cfg["iec_viability_min_pct"]))
pericyte_min = Decimal(str(gate_cfg["gate0g_pericyte_min_pct"]))
eff_abs_raw = payload.get("exact_stack_efferocytosis_abs_pct")
eff_wt_raw = payload.get("exact_stack_efferocytosis_pct_of_wt")
if eff_abs_raw is None and eff_wt_raw is None:
pending_full_fields.append("exact_stack_efferocytosis_abs_pct_and_pct_of_wt")
else:
eff_abs = _strict_decimal_in_range(eff_abs_raw, min_val=Decimal("0"), max_val=Decimal("100"))
eff_wt = _strict_decimal_in_range(eff_wt_raw, min_val=Decimal("0"), max_val=Decimal("1000"))
if eff_abs is None or eff_wt is None or Fraction(eff_abs) < Fraction(eff_abs_min) or Fraction(eff_wt) < Fraction(eff_wt_min):
reasons.append(
f"Combination macrophage efferocytosis guard invalid or failed "
f"(require abs in [{eff_abs_min}, 100.0]% and WT >= {eff_wt_min}% per GY-025/GY-010)."
)
iec_t50_raw = payload.get("iec_morphogenesis_t50_h")
iec_viab_raw = payload.get("iec_viability_pct")
if iec_t50_raw is None and iec_viab_raw is None:
pending_full_fields.append("iec_morphogenesis_t50_h_and_iec_viability_pct")
else:
iec_t50 = _strict_decimal_in_range(iec_t50_raw, min_val=Decimal("0"), exclusive_min=True)
iec_viab = _strict_decimal_in_range(iec_viab_raw, min_val=Decimal("0"), max_val=Decimal("100"))
if iec_t50 is None or iec_viab is None or Fraction(iec_t50) > Fraction(iec_t50_max) or Fraction(iec_viab) < Fraction(iec_viab_min):
reasons.append(
f"Standing GY-025 PLVAP+ iEC morphogenesis/viability gate invalid or failed "
f"(require 0 < t50 <= {iec_t50_max} h and viability in [{iec_viab_min}, 100.0]%; "
f"got t50={iec_t50_raw!r}, viability={iec_viab_raw!r})."
)
pericyte_raw = payload.get("gate0g_pericyte_pct")
if pericyte_raw is None:
pending_full_fields.append("gate0g_pericyte_pct")
else:
pericyte = _strict_decimal_in_range(pericyte_raw, min_val=Decimal("0"), max_val=Decimal("100"))
if pericyte is None or Fraction(pericyte) < Fraction(pericyte_min):
reasons.append(
f"Standing GY-025 Gate 0G pericyte criterion invalid or failed (require [{pericyte_min}, 100.0]%; got {pericyte_raw!r})."
)
# 9. Summary flags (strict bool validation) + INDEPENDENT TRUSTED QUALIFICATION STORE RESOLUTION (B3 & B4)!
# Bare summary booleans AND self-attested inline records can NEVER authorize promotion or arbitration closure!
for req_bool_key, desc in (
("gate0v_viral_safety_passed", "Gate 0V viral safety summary flag"),
("rule_s11_molecular_battery_passed", "Rule S11 molecular battery summary flag"),
("gy025_tier6b_master_lot_outgrowth_passed", "GY-025 Tier 6B master-lot outgrowth summary flag"),
):
if req_bool_key in payload and payload[req_bool_key] is not None:
bval = _strict_bool(payload[req_bool_key])
if bval is None:
reasons.append(f"{desc} must be strict bool when provided ({req_bool_key}={payload[req_bool_key]!r}).")
elif bval is False: