scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py · SHA-256: 33439d619c00fcc3…
_check_pct(payload, "pcamkii_retention_pct", holds, failures, min_pass=95.0, phys_max=150.0, fail_code="FAIL_PCAMKII_SIGNALING_LOSS")
_check_pct(payload, "integrin_internalization_pct", holds, failures, max_pass=10.0, fail_code="FAIL_INTEGRIN_INTERNALIZATION")
_check_pct(payload, "post_sort_tph1_sc_ec_pct", holds, failures, max_pass=8.0, fail_code="FAIL_SC_EC_DEPLETION_GT_8PCT")
_check_pct(payload, "alpha_cell_respike_pct", holds, failures, min_pass=25.0, max_pass=30.0, fail_code="FAIL_OQ018_ALPHA_RESPIKE_OUTSIDE_25_30PCT")
_check_pct(payload, "common_denom_eta_sort_pct", holds, failures, min_pass=55.0, fail_code="FAIL_GY024_ETA_SORT_LT_55PCT")
# ENTPD3 mature-beta release gate: >= 50.0% required for release; absent -> non-release STAGE_LIMITED_SORT_ONLY!
parent_entpd3 = payload.get("entpd3_mature_beta_pct")
entpd3_absent = ("entpd3_mature_beta_pct" not in payload or parent_entpd3 is None)
if not entpd3_absent:
_check_pct(payload, "entpd3_mature_beta_pct", holds, failures, min_pass=50.0, fail_code="FAIL_ENTPD3_MATURE_BETA_LT_50PCT")
# Bind archived itga1_live_cell_selectivity_record (Audit R6-03 + Round-14 live GY-024 scope compliance:
# ALL 23 governing measurements required & evaluated strictly from verified GATE-37-ITGA1 archive;
# missing -> HOLD; any contradiction/mismatch or CLINICAL_LOT_RELEASE/promotion_authorized=True claim -> FAIL!)
sel_rec = payload.get("itga1_live_cell_selectivity_record")
leg_rec = payload.get("lot_evidence_record")
if sel_rec is not None and leg_rec is not None and sel_rec != leg_rec:
failures.append("FAIL_CONFLICTING_ITGA1_EVIDENCE_RECORDS")
active_rec = sel_rec if sel_rec is not None else leg_rec
active_label = "itga1_live_cell_selectivity_record"
if isinstance(active_rec, Mapping) and (
active_rec.get("authority_scope") == "CLINICAL_LOT_RELEASE"
or active_rec.get("decision") == "CLINICAL_LOT_RELEASE"
or active_rec.get("promotion_authorized") is True
):
failures.append("GY024_FAIL_ITGA1_SORT_CANNOT_AUTHORIZE_CLINICAL_LOT_RELEASE")
arch_it = _verify_upstream_evidence_record(
active_rec,
active_label,
expected_gate_source="GATE-37-ITGA1",
expected_product_id=valid_product,
expected_lot_id=valid_lot,
expected_bank_id=valid_bank,
expected_bank_origin=valid_origin,
expected_construct_manifest_sha256=valid_construct_sha,
parent_evidence_tier=valid_tier,
allowed_wetlab_decisions=frozenset({"PASS_COMPONENT_SORT_QUALIFICATION", "PASS_ITGA1_RIDGE_QUALIFICATION", "STAGE_LIMITED_SORT_ONLY"}),
allowed_wetlab_scopes=frozenset({"COMPONENT_SORT_QUALIFICATION_ONLY", "STAGE_LIMITED_SORT_ONLY"}),
trusted_evidence_store=trusted_evidence_store,
holds=holds,
failures=failures,
)
arch_it_sort_only = False
arch_sel_ratio: Optional[float] = None
if arch_it is not None:
arch_binder = arch_it.get("binder_id")
if arch_binder is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_BINDER_ID")
elif not _is_nonempty_str(arch_binder):
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_BINDER_ID")
elif valid_binder is not None and arch_binder != valid_binder:
failures.append("FAIL_ITGA1_ARCHIVE_BINDER_ID_MISMATCH")
arch_assay_lot = arch_it.get("assay_lot_id")
if arch_assay_lot is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_ASSAY_LOT_ID")
elif not _is_nonempty_str(arch_assay_lot):
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_ASSAY_LOT_ID")
else:
if valid_lot is not None and arch_assay_lot != valid_lot:
failures.append("FAIL_ITGA1_ARCHIVE_ASSAY_LOT_ID_MISMATCH")
if _is_nonempty_str(assay_lot_id) and arch_assay_lot != assay_lot_id:
failures.append("FAIL_ITGA1_ARCHIVE_ASSAY_LOT_ID_CALLER_MISMATCH")
arch_valency = arch_it.get("binder_valency")
if arch_valency is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_BINDER_VALENCY")
elif not _is_nonempty_str(arch_valency) or arch_valency != "MONOVALENT_TRACELESS":
failures.append("FAIL_ITGA1_ARCHIVE_MULTIVALENT_OR_NONTRACELESS_BINDER")
elif _is_nonempty_str(valency) and arch_valency != valency:
failures.append("FAIL_ITGA1_ARCHIVE_BINDER_VALENCY_MISMATCH")
arch_temp = arch_it.get("capture_temp_C")
if arch_temp is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_CAPTURE_TEMP_C")
elif not _is_num(arch_temp) or float(arch_temp) < -5.0 or float(arch_temp) > 50.0:
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_CAPTURE_TEMP_C")
else:
atf = float(arch_temp)
if not (0.0 <= atf <= 4.0):
failures.append("FAIL_ITGA1_ARCHIVE_TEMPERATURE_OUTSIDE_0_TO_4C")
if _is_num(temp) and abs(atf - float(temp)) > 1e-12:
failures.append("FAIL_ITGA1_ARCHIVE_CAPTURE_TEMP_C_MISMATCH")
arch_t = arch_it.get("live_cell_ec50_itga1_target_nm")
arch_o = arch_it.get("live_cell_ec50_itga2_offtarget_nm")
if arch_t is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_LIVE_CELL_EC50_ITGA1_TARGET_NM")
elif not _is_num(arch_t) or float(arch_t) <= 0.0:
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_EC50_TARGET")
elif _is_num(ec50_tgt) and abs(float(arch_t) - float(ec50_tgt)) > max(1e-12, 1e-12 * abs(float(ec50_tgt))):
failures.append("FAIL_ITGA1_ARCHIVE_EC50_TARGET_MISMATCH")
if arch_o is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_LIVE_CELL_EC50_ITGA2_OFFTARGET_NM")
elif not _is_num(arch_o) or float(arch_o) <= 0.0:
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_EC50_OFFTARGET")
elif _is_num(ec50_off) and abs(float(arch_o) - float(ec50_off)) > max(1e-12, 1e-12 * abs(float(ec50_off))):
failures.append("FAIL_ITGA1_ARCHIVE_EC50_OFFTARGET_MISMATCH")
if _is_num(arch_t) and float(arch_t) > 0.0 and _is_num(arch_o) and float(arch_o) > 0.0:
arch_sel_ratio = _safe_ratio(float(arch_o), float(arch_t))
if arch_sel_ratio is None:
failures.append("FAIL_ITGA1_ARCHIVE_NONFINITE_SELECTIVITY_RATIO")
elif arch_sel_ratio < 100.0:
failures.append("FAIL_ITGA1_ARCHIVE_SELECTIVITY_RATIO_LT_100X")
if "live_cell_a1b1_vs_a2b1_ec50_ratio" in arch_it and arch_it["live_cell_a1b1_vs_a2b1_ec50_ratio"] is not None:
arch_opt_r = arch_it["live_cell_a1b1_vs_a2b1_ec50_ratio"]
if not _is_num(arch_opt_r) or float(arch_opt_r) <= 0.0:
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_SELECTIVITY_RATIO_ALIAS")
else:
aorf = float(arch_opt_r)
if aorf < 100.0:
failures.append("FAIL_ITGA1_ARCHIVE_SELECTIVITY_RATIO_LT_100X")
if arch_sel_ratio is not None and abs(aorf - arch_sel_ratio) > max(1e-6, 0.01 * arch_sel_ratio):
failures.append("FAIL_ITGA1_ARCHIVE_SELECTIVITY_RATIO_ARITHMETIC_MISMATCH")
if _is_num(payload.get("live_cell_a1b1_vs_a2b1_ec50_ratio")) and abs(aorf - float(payload["live_cell_a1b1_vs_a2b1_ec50_ratio"])) > 1e-12:
failures.append("FAIL_ITGA1_ARCHIVE_SELECTIVITY_RATIO_CALLER_MISMATCH")
arch_ep_raw = arch_it.get("epitope_contact_residues")
arch_ep: Optional[set[str]] = None
if arch_ep_raw is None:
holds.append("HOLD_ITGA1_ARCHIVE_MISSING_EPITOPE_CONTACT_RESIDUES")
elif not isinstance(arch_ep_raw, (list, tuple, set)) or len(arch_ep_raw) == 0 or not all(_is_nonempty_str(r) for r in arch_ep_raw):
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_EPITOPE_CONTACT_RESIDUES")
else:
if any(not _is_canonical_id(r) for r in arch_ep_raw):
failures.append("FAIL_ITGA1_ARCHIVE_NONCANONICAL_EPITOPE_RESIDUE_TOKEN")
arch_ep = {r.strip().upper() for r in arch_ep_raw}
if len(arch_ep) != len(arch_ep_raw):
failures.append("FAIL_ITGA1_ARCHIVE_DUPLICATE_EPITOPE_RESIDUE_TOKEN")
if arch_ep & _ITGA1_PROHIBITED_MIDAS:
failures.append("FAIL_ITGA1_ARCHIVE_UNAUTHORIZED_MIDAS_RESIDUE_CONTACT")
if arch_ep & _ITGA1_PROHIBITED_COLLAGEN_CONTACTS:
failures.append("FAIL_ITGA1_ARCHIVE_UNAUTHORIZED_COLLAGEN_CONTACT_RESIDUE")
if arch_ep & _ITGA1_PROHIBITED_EXCISED_ALLOSTERIC:
failures.append("FAIL_ITGA1_ARCHIVE_EXCISED_SEG_338_358_RESIDUE")
if arch_ep != _ITGA1_ALLOWED_PRIMARY_RIDGE:
failures.append("FAIL_ITGA1_ARCHIVE_EPITOPE_RESIDUES_NOT_EXACT_PRIMARY_RIDGE")
elif norm_ep is not None and arch_ep != norm_ep:
failures.append("FAIL_ITGA1_ARCHIVE_EPITOPE_RESIDUES_MISMATCH")
if "targeted_residues" in arch_it and arch_it["targeted_residues"] is not None:
arch_tr_raw = arch_it["targeted_residues"]
if not isinstance(arch_tr_raw, (list, tuple, set)) or len(arch_tr_raw) == 0 or not all(_is_nonempty_str(r) for r in arch_tr_raw):
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_TARGETED_RESIDUES_ALIAS")
else:
if any(not _is_canonical_id(r) for r in arch_tr_raw):
failures.append("FAIL_ITGA1_ARCHIVE_NONCANONICAL_TARGETED_RESIDUE_TOKEN")
arch_tr = {r.strip().upper() for r in arch_tr_raw}
if len(arch_tr) != len(arch_tr_raw) or arch_tr != _ITGA1_ALLOWED_PRIMARY_RIDGE or (arch_ep is not None and arch_tr != arch_ep) or (norm_ep is not None and arch_tr != norm_ep):
failures.append("FAIL_ITGA1_ARCHIVE_TARGETED_RESIDUES_ALIAS_CONFLICT")
# Validate (decision, authority_scope, bank_qualified, promotion_authorized) as ONE coherent non-release tuple
# per live GY-024 (OFFGRID_GUARD_014): ITGA1 sorting NEVER authorizes CLINICAL_LOT_RELEASE or promotion_authorized=True!
arch_dec = arch_it.get("decision")
arch_scope = arch_it.get("authority_scope")
arch_bank = arch_it.get("bank_qualified")
arch_promo = arch_it.get("promotion_authorized")
if arch_scope == "CLINICAL_LOT_RELEASE" or arch_dec == "CLINICAL_LOT_RELEASE" or arch_promo is True:
if "GY024_FAIL_ITGA1_SORT_CANNOT_AUTHORIZE_CLINICAL_LOT_RELEASE" not in failures:
failures.append("GY024_FAIL_ITGA1_SORT_CANNOT_AUTHORIZE_CLINICAL_LOT_RELEASE")
elif valid_tier == "AUTHENTICATED_ARCHIVED_WETLAB":
if arch_dec == "STAGE_LIMITED_SORT_ONLY":
arch_it_sort_only = True
if arch_scope != "STAGE_LIMITED_SORT_ONLY" or arch_promo is not False:
failures.append("FAIL_ITGA1_ARCHIVE_DECISION_SCOPE_AUTHORITY_CONTRADICTION")
elif not entpd3_absent:
failures.append("FAIL_ITGA1_ARCHIVE_STAGE_LIMITED_CANNOT_AUTHORIZE_COMPONENT_QUALIFICATION")
elif arch_dec in ("PASS_COMPONENT_SORT_QUALIFICATION", "PASS_ITGA1_RIDGE_QUALIFICATION"):
if arch_scope != "COMPONENT_SORT_QUALIFICATION_ONLY" or arch_bank is not True or arch_promo is not False:
failures.append("FAIL_ITGA1_ARCHIVE_DECISION_SCOPE_AUTHORITY_CONTRADICTION")
else:
failures.append("FAIL_ITGA1_ARCHIVE_DECISION_SCOPE_AUTHORITY_CONTRADICTION")
else:
# Synthetic tier: reject contradictory STAGE_LIMITED_SORT_ONLY paired with non-sort scope or clinical promotion
if arch_dec == "STAGE_LIMITED_SORT_ONLY" and (
arch_scope not in ("STAGE_LIMITED_SORT_ONLY", "SYNTHETIC_SELF_TEST") or arch_promo is True
):
failures.append("FAIL_ITGA1_ARCHIVE_DECISION_SCOPE_AUTHORITY_CONTRADICTION")
# Derive & reconcile entpd3_mature_beta_pct directly from verified archive (Audit R4-07 / R6-03)!
arch_entpd3 = arch_it.get("entpd3_mature_beta_pct")
if arch_entpd3 is not None:
if not _is_num(arch_entpd3) or float(arch_entpd3) < 0.0 or float(arch_entpd3) > 100.0:
failures.append("FAIL_ITGA1_ARCHIVE_INVALID_ENTPD3_MATURE_BETA_PCT")
else:
arch_entpd3_f = float(arch_entpd3)
if arch_entpd3_f < 50.0:
failures.append("FAIL_ITGA1_ARCHIVE_ENTPD3_MATURE_BETA_LT_50PCT")
if not entpd3_absent and _is_num(parent_entpd3) and abs(arch_entpd3_f - float(parent_entpd3)) > 1e-12:
failures.append("FAIL_ITGA1_ARCHIVE_ENTPD3_MISMATCH")
elif not entpd3_absent:
failures.append("FAIL_ITGA1_ARCHIVE_MISSING_ENTPD3_MATURE_BETA_PCT")
# Require & derive ALL remaining governing ITGA1 functional/affinity/selectivity/process endpoints strictly from verified archive (Audit R6-03)!
for arch_k, strict_pos, phys_lo, phys_hi, lo_v, hi_v, fcode in (
("kd_itga1_nM", True, None, None, None, 10.0, "FAIL_ITGA1_ARCHIVE_WEAK_ITGA1_AFFINITY"),
("spr_selectivity_vs_itga2_fold", True, None, None, 100.0, None, "FAIL_ITGA1_ARCHIVE_ITGA2_PARALOG_SELECTIVITY_LT_100X"),
("spr_selectivity_vs_itga10_fold", True, None, None, 100.0, None, "FAIL_ITGA1_ARCHIVE_ITGA10_PARALOG_SELECTIVITY_LT_100X"),
("spr_selectivity_vs_itga11_fold", True, None, None, 100.0, None, "FAIL_ITGA1_ARCHIVE_ITGA11_PARALOG_SELECTIVITY_LT_100X"),
("pfak_y397_fold_vs_vehicle", True, None, None, None, 1.2, "FAIL_ITGA1_ARCHIVE_PFAK_ACTIVATION"),
("psrc_fold_vs_vehicle", True, None, None, None, 1.2, "FAIL_ITGA1_ARCHIVE_PSRC_ACTIVATION"),
("oq018_low_glucose_1mM_glucagon_fold", True, None, None, 2.0, None, "FAIL_ITGA1_ARCHIVE_OQ018_GLUCAGON_FOLD_LT_2X"),
("residual_ligand_ng_per_1e6", False, 0.0, None, 0.0, 1.0, "FAIL_ITGA1_ARCHIVE_RESIDUAL_LIGAND_LEACHING"),
("oq018_glucagon_auc_l95", False, 0.0, 2.0, 0.85, 2.0, "FAIL_ITGA1_ARCHIVE_OQ018_GLUCAGON_AUC_LT_0P85"),
("collagen_midas_inhibition_pct", False, 0.0, 100.0, 0.0, 10.0, "FAIL_ITGA1_ARCHIVE_COLLAGEN_MIDAS_BLOCK"),
("isx9_nkx61_retention_pct", False, 0.0, 150.0, 95.0, 150.0, "FAIL_ITGA1_ARCHIVE_NKX61_LOSS"),
("pcamkii_retention_pct", False, 0.0, 150.0, 95.0, 150.0, "FAIL_ITGA1_ARCHIVE_PCAMKII_LOSS"),
("integrin_internalization_pct", False, 0.0, 100.0, 0.0, 10.0, "FAIL_ITGA1_ARCHIVE_INTERNALIZATION"),
("post_sort_tph1_sc_ec_pct", False, 0.0, 100.0, 0.0, 8.0, "FAIL_ITGA1_ARCHIVE_SC_EC_GT_8PCT"),
("alpha_cell_respike_pct", False, 0.0, 100.0, 25.0, 30.0, "FAIL_ITGA1_ARCHIVE_ALPHA_RESPIKE_OUTSIDE_25_30PCT"),
("common_denom_eta_sort_pct", False, 0.0, 100.0, 55.0, 100.0, "FAIL_ITGA1_ARCHIVE_ETA_SORT_LT_55PCT"),
):
av = arch_it.get(arch_k)
if av is None:
holds.append(f"HOLD_ITGA1_ARCHIVE_MISSING_{arch_k.upper()}")
elif not _is_num(av):
failures.append(f"FAIL_ITGA1_ARCHIVE_INVALID_{arch_k.upper()}")
else:
avf = float(av)
if strict_pos and avf <= 0.0:
failures.append(f"FAIL_ITGA1_ARCHIVE_NONPOSITIVE_{arch_k.upper()}")
elif (phys_lo is not None and avf < phys_lo) or (phys_hi is not None and avf > phys_hi):
failures.append(f"FAIL_ITGA1_ARCHIVE_OUT_OF_RANGE_{arch_k.upper()}")
else:
if (lo_v is not None and avf < lo_v) or (hi_v is not None and avf > hi_v):
failures.append(fcode)
if _is_num(payload.get(arch_k)) and abs(avf - float(payload[arch_k])) > 1e-12:
failures.append(f"FAIL_ITGA1_ARCHIVE_{arch_k.upper()}_MISMATCH")
# Apply strict canonical ASCII identity validation to ALL caller & archived identifier fields (Audit R8-07)
_audit_canonical_identifier_fields(payload, label="ITGA1_PAYLOAD", failures=failures)
if arch_it is not None:
_audit_canonical_identifier_fields(arch_it, label="ITGA1_ARCHIVE", failures=failures)
final_sel_ratio = arch_sel_ratio if arch_sel_ratio is not None else computed_sel_ratio
is_wetlab_comp_ok = (
valid_tier == "AUTHENTICATED_ARCHIVED_WETLAB"
and not entpd3_absent
and not arch_it_sort_only
and not failures
and not holds
)
extra: dict[str, Any] = {
"computed_live_cell_selectivity_ratio": _safe_round_finite(final_sel_ratio, 6),
"component_sort_qualified": is_wetlab_comp_ok,
"clinical_release_requires_atomic_ledger": True,
"release_qc_complete": (not entpd3_absent and not arch_it_sort_only and not failures and not holds),
}
if (entpd3_absent or arch_it_sort_only) and not failures and not holds: