scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py · SHA-256: 20706180ed1ed6a2…
hard_stops.append("FAIL_HARD_STOP_SPECULATIVE_CXADR_KO_BARRED_FROM_ACTIVE_GATE0V")
if not _is_valid_sha256_hex(payload.get("cxadr_locus_genotyping_evidence_sha256")):
holds.append("HOLD_GATE0V_MISSING_CXADR_GENOTYPING_EVIDENCE_SHA256")
# ------------------------------------------------------------------
# 1. Genotype & Antiviral Competence (Gate 0V-Geno) reconciled with Canonical Product
# ------------------------------------------------------------------
geno_valid = isinstance(geno, str) and geno in ALLOWED_ANTIVIRAL_GENOTYPES
if not geno_valid:
holds.append("HOLD_GATE0V_UNRECOGNIZED_OR_MISSING_ANTIVIRAL_GENOTYPE_STRATUM")
elif canonical_product_def is not None:
tyk2_cls = canonical_product_def.get("tyk2_product_genotype_class")
if tyk2_cls == "TYK2_PE_P1104A" and geno not in ("TYK2_P1104A_HOM__IFIH1_WT", "TYK2_P1104A_HET__IFIH1_WT"):
holds.append("HOLD_GATE0V_GENOTYPE_CONFLICTS_WITH_CANONICAL_PRODUCT_DEFINITION")
elif tyk2_cls == "TYK2_KO_PROPOSED":
holds.append("HOLD_GATE0V_TYK2_KO_VARIANT_NOT_QUALIFIED_BY_WT_OR_P1104A_STRATUM")
if geno == "TYK2_P1104A_HOM__IFIH1_WT":
if payload.get("mycobacterial_tb_igra_screening_attested") is not True:
holds.append("HOLD_GATE0V_TYK2_P1104A_HOM_REQUIRES_TB_MYCOBACTERIAL_SCREENING")
if not _is_valid_sha256_hex(payload.get("tb_igra_evidence_sha256")):
holds.append("HOLD_GATE0V_TYK2_P1104A_HOM_MISSING_TB_IGRA_EVIDENCE_SHA256")
# ------------------------------------------------------------------
# 1B. Ectopic Viral Receptor Declaration & Mandatory Powered Strain-Specific Addenda (B2 + B5 + B6)
# ------------------------------------------------------------------
ectopic_raw = payload.get("ectopic_viral_receptors_expressed")
cd46_results: Dict[str, Any] = {}
cd55_results: Dict[str, Any] = {}
supplemental_adjudicated: List[str] = []
if not isinstance(ectopic_raw, list) or any(
not isinstance(r, str) or r not in ALLOWED_ECTOPIC_RECEPTORS for r in ectopic_raw
):
holds.append("HOLD_GATE0V_MISSING_OR_INVALID_ECTOPIC_VIRAL_RECEPTORS_LIST")
ectopic_set: set[str] = set()
else:
ectopic_set = set(ectopic_raw)
# B2: Exact canonical registry lookup (ZERO substring inference!)
implied_receptors = (
set(canonical_product_def.get("required_ectopic_viral_receptors") or [])
if canonical_product_def is not None
else set()
)
for req_rec in sorted(implied_receptors):
if req_rec not in ectopic_set:
holds.append(f"HOLD_GATE0V_UNDECLARED_ECTOPIC_RECEPTOR_{req_rec}_FOR_PRODUCT_VARIANT")
effective_ectopic = ectopic_set | implied_receptors
cd46_add = payload.get("cd46_tropic_viral_addendum")
if "CD46_WT" in effective_ectopic:
if not isinstance(cd46_add, dict):
holds.append("HOLD_GATE0V_CD46_WT_ARM_REQUIRES_COMPLETED_CD46_VIRAL_ADDENDUM")
else:
if cd46_add.get("hhv6b_cd134_scope_distinguished") is not True:
holds.append("HOLD_GATE0V_CD46_ADDENDUM_MISSING_HHV6A_VS_HHV6B_RECEPTOR_SCOPE")
if cd46_add.get("measles_wt_slam_nectin4_scope_distinguished") is not True:
holds.append("HOLD_GATE0V_CD46_ADDENDUM_MISSING_MEASLES_STRAIN_RECEPTOR_SCOPE")
for v_id in CD46_ADDENDUM_VIRUSES:
v_tag = v_id.upper()
vb = cd46_add.get(v_id)
if not isinstance(vb, dict):
holds.append(f"HOLD_GATE0V_CD46_ADDENDUM_MISSING_{v_tag}")
continue
t72 = _to_exact_decimal_nonneg(vb.get("titer_72h_log10_pfu_u95"))
d14 = _to_exact_decimal(vb.get("day14_log10_reduction_l95"))
d28_pfu = _to_exact_decimal_nonneg(vb.get("day28_supernatant_pfu_ml"))
d28_vol = _to_exact_decimal_nonneg(vb.get("day28_assay_volume_ml"))
d28_lod = _to_exact_decimal_nonneg(vb.get("day28_lod_pfu_ml"))
dd_k = vb.get("day28_5lineage_ddpcr_confirmed_k")
dd_n = vb.get("day28_5lineage_cells_screened_per_lineage_min_n")
ev_sha = vb.get("protocol_evidence_sha256")
v_ok = True
if t72 is None or not (Decimal(0) <= t72 <= Decimal("15")):
holds.append(f"HOLD_GATE0V_CD46_INVALID_72H_TITER_{v_tag}")
v_ok = False
elif t72 > Decimal("2.0"):
hard_stops.append(f"FAIL_HARD_STOP_CD46_ADDENDUM_72H_TITER_{v_tag}")
v_ok = False
if d14 is None or not (Decimal("-10") <= d14 <= Decimal("15")):
holds.append(f"HOLD_GATE0V_CD46_INVALID_DAY14_CLEARANCE_{v_tag}")
v_ok = False
elif d14 < Decimal("3.0"):
hard_stops.append(f"FAIL_HARD_STOP_CD46_ADDENDUM_DAY14_CLEARANCE_{v_tag}")
v_ok = False
if d28_pfu is None or d28_pfu < Decimal(0) or d28_vol is None or d28_vol < Decimal("1.0") or d28_lod is None or d28_lod <= Decimal(0) or d28_lod > Decimal("1.0"):
holds.append(f"HOLD_GATE0V_CD46_INVALID_DAY28_PLAQUE_OR_LOD_{v_tag}")
v_ok = False
elif d28_pfu > Decimal(0):
hard_stops.append(f"FAIL_HARD_STOP_CD46_ADDENDUM_DAY28_SHEDDING_{v_tag}")
v_ok = False
u_cd46_str: str | None = None
if not (_is_strict_int(dd_k) and _is_strict_int(dd_n) and dd_n >= 1 and 0 <= dd_k <= dd_n):
holds.append(f"HOLD_GATE0V_CD46_INVALID_DDPCR_COUNTS_{v_tag}")
v_ok = False
else:
if dd_k >= 1:
hard_stops.append(f"FAIL_HARD_STOP_CD46_ADDENDUM_CONFIRMED_PERSISTENCE_{v_tag}")
v_ok = False
if not _check_estimand_sampling_unit_basis(
vb.get("per_unit_counts"),
k_val=dd_k,
n_val=dd_n,
label=f"CD46_{v_tag}",
zero_tolerance_hard_stop_token=f"FAIL_HARD_STOP_CD46_ADDENDUM_CONFIRMED_PERSISTENCE_{v_tag}",
):
v_ok = False
if deff is None:
v_ok = False
else:
dd_n_indep = _exact_floor_div_by_decimal(dd_n, deff)
if dd_n_indep < 1:
holds.append(f"HOLD_GATE0V_CD46_UNDERPOWERED_DDPCR_{v_tag}")
v_ok = False
elif dd_k == 0:
u_cd46 = sound_zero_event_clopper_pearson_upper(dd_n_indep, alpha_3p, min_eta_cal, prec=80)["u_thinned_upper_dec"]
u_cd46_str = format(u_cd46, "f")[:24]
if u_cd46 > cap_frac_persist:
holds.append(f"HOLD_GATE0V_CD46_UNDERPOWERED_DDPCR_{v_tag}")
v_ok = False
if not _is_valid_sha256_hex(ev_sha):
holds.append(f"HOLD_GATE0V_CD46_MISSING_EVIDENCE_SHA256_{v_tag}")
v_ok = False
cd46_results[v_id] = {"passed": v_ok, "u_cd46_upper_80d": u_cd46_str}
elif isinstance(cd46_add, dict):
# B6: Never silently drop submitted adverse CD46 addendum data even on non-CD46 arms!
supplemental_adjudicated.append("supplemental_addendum:cd46_tropic_viral_addendum")
for v_id in CD46_ADDENDUM_VIRUSES:
vb = cd46_add.get(v_id)
if not isinstance(vb, dict):
continue
v_tag = v_id.upper()
t72 = _to_exact_decimal(vb.get("titer_72h_log10_pfu_u95"))
d14 = _to_exact_decimal(vb.get("day14_log10_reduction_l95"))
d28_pfu = _to_exact_decimal(vb.get("day28_supernatant_pfu_ml"))
dd_k = vb.get("day28_5lineage_ddpcr_confirmed_k")
if t72 is not None and t72 > Decimal("2.0"):
hard_stops.append(f"FAIL_HARD_STOP_SUPPLEMENTAL_CD46_ADDENDUM_72H_TITER_{v_tag}")
if d14 is not None and d14 < Decimal("3.0"):
hard_stops.append(f"FAIL_HARD_STOP_SUPPLEMENTAL_CD46_ADDENDUM_DAY14_CLEARANCE_{v_tag}")
if d28_pfu is not None and d28_pfu > Decimal(0):
hard_stops.append(f"FAIL_HARD_STOP_SUPPLEMENTAL_CD46_ADDENDUM_DAY28_SHEDDING_{v_tag}")
if _is_strict_int(dd_k) and dd_k >= 1:
hard_stops.append(f"FAIL_HARD_STOP_SUPPLEMENTAL_CD46_ADDENDUM_CONFIRMED_PERSISTENCE_{v_tag}")
cd55_add = payload.get("cd55_tropic_echovirus_addendum")
if "CD55_FULL_LENGTH" in effective_ectopic:
# R04-B4: Require SEPARATE per-strain (echovirus_7 AND echovirus_11) attributable evidence
# blocks with per-strain acute/Day-14/Day-28 clearance AND per-strain x 5-lineage raw
# persistence counts (confirmed_k == 0, cells_screened_n) each individually clearing exact-Decimal
# Clopper-Pearson U <= 5e-4! Reject any legacy aggregate-only block or missing strain/lineage!
if not isinstance(cd55_add, dict):
holds.append("HOLD_GATE0V_CD55_FULL_LENGTH_REQUIRES_COMPLETED_ECHOVIRUS_ADDENDUM")
cd55_results = {
"passed": False,
"detection_efficiency_assurance_level": "CONDITIONAL_ON_ASSUMED_MINIMUM_ETA_PENDING_LINKED_CALIBRANT_EVIDENCE",
"assumed_minimum_eta_used": str(min_eta_cal),
"strain_results": {},
}
else:
c55_ok = True
strains_raw = cd55_add.get("echovirus_strain_panel")
if not isinstance(strains_raw, list) or not set(CD55_REQUIRED_ECHOVIRUS_STRAINS).issubset(
{str(s).strip().lower() for s in strains_raw if isinstance(s, str)}
):
holds.append("HOLD_GATE0V_CD55_MISSING_REQUIRED_ECHOVIRUS_STRAIN_PANEL")
c55_ok = False
if not _is_valid_sha256_hex(cd55_add.get("protocol_evidence_sha256")):
holds.append("HOLD_GATE0V_CD55_MISSING_PROTOCOL_EVIDENCE_SHA256")
c55_ok = False
# Always inspect any submitted top-level legacy keys so adverse data or underpowered
# overrides are never silently ignored even if present alongside strain_results!
leg_t72 = _to_exact_decimal(cd55_add.get("echovirus_titer_72h_log10_pfu_u95"))
leg_d14 = _to_exact_decimal(cd55_add.get("echovirus_day14_log10_reduction_l95"))
leg_d28 = _to_exact_decimal(cd55_add.get("echovirus_day28_supernatant_pfu_ml"))
leg_k = cd55_add.get("echovirus_persistence_confirmed_k")
leg_n = cd55_add.get("echovirus_cells_screened_per_lineage_min_n")
if leg_t72 is not None and leg_t72 > Decimal("2.0"):
hard_stops.append("FAIL_HARD_STOP_CD55_ADDENDUM_72H_TITER")
c55_ok = False
if leg_d14 is not None and leg_d14 < Decimal("3.0"):
hard_stops.append("FAIL_HARD_STOP_CD55_ADDENDUM_DAY14_CLEARANCE")
c55_ok = False
if leg_d28 is not None and leg_d28 > Decimal(0):
hard_stops.append("FAIL_HARD_STOP_CD55_ADDENDUM_DAY28_SHEDDING")
c55_ok = False
if _is_strict_int(leg_k) and leg_k >= 1:
hard_stops.append("FAIL_HARD_STOP_CD55_ECHOVIRUS_PERSISTENCE_DETECTED")
c55_ok = False
if leg_n is not None:
if not (_is_strict_int(leg_n) and leg_n >= 1):
holds.append("HOLD_GATE0V_CD55_UNDERPOWERED_ECHOVIRUS_DENOMINATOR")
c55_ok = False
elif deff is None:
c55_ok = False
else:
leg_n_indep = _exact_floor_div_by_decimal(leg_n, deff)
if leg_n_indep < 1:
holds.append("HOLD_GATE0V_CD55_UNDERPOWERED_ECHOVIRUS_DENOMINATOR")
c55_ok = False
else:
u_leg = sound_zero_event_clopper_pearson_upper(
leg_n_indep, alpha_3p, min_eta_cal, prec=80
)["u_thinned_upper_dec"]
if u_leg > cap_frac_persist:
holds.append("HOLD_GATE0V_CD55_UNDERPOWERED_ECHOVIRUS_DENOMINATOR")
c55_ok = False
strain_results_raw = cd55_add.get("strain_results")
per_strain_out: Dict[str, Any] = {}
overall_min_n: int | None = None
overall_max_u: Decimal | None = None
if not isinstance(strain_results_raw, dict):
holds.append("HOLD_GATE0V_CD55_MISSING_PER_STRAIN_RESULTS_AGGREGATE_ONLY_REJECTED")
c55_ok = False
else:
for strain_id in CD55_REQUIRED_ECHOVIRUS_STRAINS:
s_tag = strain_id.upper()
sb = strain_results_raw.get(strain_id)
if not isinstance(sb, dict):
holds.append(f"HOLD_GATE0V_CD55_MISSING_STRAIN_BLOCK_{s_tag}")
c55_ok = False
per_strain_out[strain_id] = {"passed": False, "lineage_results": {}}
continue
s_ok = True
if not _is_valid_sha256_hex(sb.get("protocol_evidence_sha256")):
holds.append(f"HOLD_GATE0V_CD55_MISSING_STRAIN_EVIDENCE_SHA256_{s_tag}")
s_ok = False
t72_s = _to_exact_decimal(sb.get("titer_72h_log10_pfu_u95"))
d14_s = _to_exact_decimal(sb.get("day14_log10_reduction_l95"))
d28_pfu_s = _to_exact_decimal(sb.get("day28_supernatant_pfu_ml"))
d28_vol_s = _to_exact_decimal(sb.get("day28_assay_volume_ml"))
d28_lod_s = _to_exact_decimal(sb.get("day28_lod_pfu_ml"))
if t72_s is None or not (Decimal(0) <= t72_s <= Decimal("15")):
holds.append(f"HOLD_GATE0V_CD55_INVALID_72H_TITER_{s_tag}")
s_ok = False
elif t72_s > Decimal("2.0"):
hard_stops.append(f"FAIL_HARD_STOP_CD55_ADDENDUM_72H_TITER_{s_tag}")
s_ok = False
if d14_s is None or not (Decimal("-10") <= d14_s <= Decimal("15")):
holds.append(f"HOLD_GATE0V_CD55_INVALID_DAY14_CLEARANCE_{s_tag}")
s_ok = False
elif d14_s < Decimal("3.0"):
hard_stops.append(f"FAIL_HARD_STOP_CD55_ADDENDUM_DAY14_CLEARANCE_{s_tag}")
s_ok = False
if (
d28_pfu_s is None or d28_pfu_s < Decimal(0)