scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…
if grad_d <= ZERO_DEC:
fail_reasons.append("INVALID_PORTAL_INSULIN_GRADIENT")
elif grad_d < Decimal("1.5"):
fail_reasons.append("R4O_05_PORTAL_INSULIN_GRADIENT_LT_1P5X_FAIL")
extinct = obs.get("dec009_post_explant_cpeptide_extinction_verified")
if extinct is None:
extinct = obs.get("nhp_r4o05_post_omentectomy_cpeptide_extinction")
if extinct is None:
hold_reasons.append("MISSING_DEC009_POST_EXPLANT_CPEPTIDE_EXTINCTION")
elif not _is_strict_bool(extinct):
fail_reasons.append("INVALID_CPEPTIDE_EXTINCTION_BOOL")
elif not extinct:
fail_reasons.append("R4O_05_POST_OMENTECTOMY_CPEPTIDE_EXTINCTION_FAILED")
else:
grad = obs.get("nhp_r4o05_portal_peripheral_insulin_gradient")
if grad is None:
hold_reasons.append("MISSING_STAGE1_NHP_PORTAL_INSULIN_GRADIENT")
elif not _is_finite_number(grad):
fail_reasons.append("INVALID_PORTAL_INSULIN_GRADIENT")
else:
grad_d = _to_exact_decimal(grad)
if grad_d <= ZERO_DEC:
fail_reasons.append("INVALID_PORTAL_INSULIN_GRADIENT")
elif grad_d < Decimal("1.5"):
fail_reasons.append("R4O_05_PORTAL_INSULIN_GRADIENT_LT_1P5X_FAIL")
extinct = obs.get("nhp_r4o05_post_omentectomy_cpeptide_extinction")
if extinct is None:
hold_reasons.append("MISSING_STAGE1_NHP_POST_OMENTECTOMY_CPEPTIDE_EXTINCTION")
elif not _is_strict_bool(extinct):
fail_reasons.append("INVALID_CPEPTIDE_EXTINCTION_BOOL")
elif not extinct:
fail_reasons.append("R4O_05_POST_OMENTECTOMY_CPEPTIDE_EXTINCTION_FAILED")
# 8. GY-014 & H4-6-ExVivo Preconditioning Discipline + Zero-Div-Safe Derived Ratios (Review #10)
derived_rest_p1_ratio: Optional[float] = None
derived_rest_p2_ratio: Optional[float] = None
derived_rest_endpoint_ratio: Optional[float] = None
invivo_dz = obs.get("invivo_diazoxide_depot_or_credit_claimed")
if invivo_dz is None:
hold_reasons.append("MISSING_INVIVO_DIAZOXIDE_BOOL")
elif not _is_strict_bool(invivo_dz):
fail_reasons.append("INVALID_INVIVO_DIAZOXIDE_BOOL")
elif invivo_dz:
fail_reasons.append("GY014_BLOCK_INVIVO_DIAZOXIDE_PROHIBITED")
r3p06_clamp = obs.get("r3p06_5day_glycemic_clamp_enabled")
if r3p06_clamp is None:
hold_reasons.append("MISSING_R3P06_GLYCEMIC_CLAMP_BOOL")
elif not _is_strict_bool(r3p06_clamp) or not r3p06_clamp:
fail_reasons.append("R3P06_5DAY_GLYCEMIC_CLAMP_REQUIRED")
exvivo_applied = obs.get("exvivo_rest_applied")
if exvivo_applied is None:
hold_reasons.append("MISSING_EXVIVO_REST_APPLIED_BOOL")
elif not _is_strict_bool(exvivo_applied):
fail_reasons.append("INVALID_EXVIVO_REST_APPLIED_BOOL")
elif exvivo_applied:
if arm_spec is not None and arm_spec.get("exvivo_rest_eligible") is False:
fail_reasons.append("DESIGN_A_STRICTLY_PROHIBITS_EXVIVO_DIAZOXIDE_TUDCA_REST")
exvivo_agents = obs.get("exvivo_preconditioning_agents")
if exvivo_agents is None:
hold_reasons.append("MISSING_EXVIVO_AGENT_MANIFEST")
elif not isinstance(exvivo_agents, list) or len(exvivo_agents) == 0 or not all(_is_literal_nonempty_str(x) for x in exvivo_agents):
fail_reasons.append("EMPTY_OR_MALFORMED_EXVIVO_AGENT_MANIFEST")
else:
for ag in exvivo_agents:
if ag in BANNED_EXVIVO_TOKENS:
fail_reasons.append(f"UNAPPROVED_CLINICAL_PRECONDITIONING_AGENT:{ag}")
elif ag not in REQUIRED_EXVIVO_REST_AGENTS:
fail_reasons.append(f"UNRECOGNIZED_EXVIVO_PRECONDITIONING_AGENT:{ag}")
if set(exvivo_agents) != REQUIRED_EXVIVO_REST_AGENTS:
fail_reasons.append("EXVIVO_AGENT_MANIFEST_MUST_MATCH_DIAZOXIDE_GMP_AND_TUDCA_GMP")
dz_conc = obs.get("exvivo_diazoxide_uM")
tudca_conc = obs.get("exvivo_tudca_uM")
precond_h = obs.get("exvivo_preconditioning_hours")
fccp_res = obs.get("h46e01_fccp_max_reserve_pct_ctrl")
wash_cycles = obs.get("washout_cycles_n")
lcms_sup = obs.get("lcms_supernatant_diazoxide_uM")
lcms_pel = obs.get("lcms_pellet_diazoxide_uM")
if dz_conc is None:
hold_reasons.append("MISSING_EXVIVO_DIAZOXIDE_UM")
elif not _is_finite_number(dz_conc) or not (Decimal("100") <= _to_exact_decimal(dz_conc) <= Decimal("150")):
fail_reasons.append("EXVIVO_DIAZOXIDE_OUTSIDE_100_TO_150UM_WINDOW")
if tudca_conc is None:
hold_reasons.append("MISSING_EXVIVO_TUDCA_UM")
elif not _is_finite_number(tudca_conc) or not (Decimal("100") <= _to_exact_decimal(tudca_conc) <= Decimal("500")):
fail_reasons.append("EXVIVO_TUDCA_OUTSIDE_100_TO_500UM_WINDOW")
if precond_h is None:
hold_reasons.append("MISSING_EXVIVO_PRECONDITIONING_HOURS")
elif not _is_finite_number(precond_h) or not (Decimal("18") <= _to_exact_decimal(precond_h) <= Decimal("24")):
fail_reasons.append("EXVIVO_PRECONDITIONING_OUTSIDE_18_TO_24H_WINDOW")
if fccp_res is None:
hold_reasons.append("MISSING_H46E01_FCCP_MAX_RESERVE_ASSAY")
elif not _is_finite_number(fccp_res):
fail_reasons.append("INVALID_H46E01_FCCP_MAX_RESERVE")
else:
fccp_d = _to_exact_decimal(fccp_res)
if fccp_d < ZERO_DEC or fccp_d > Decimal("300"):
fail_reasons.append("INVALID_H46E01_FCCP_MAX_RESERVE")
elif fccp_d < Decimal("85"):
fail_reasons.append("H46E01_FCCP_MAX_RESERVE_LT_85PCT_COMPLEX_II_TOXICITY_FAIL")
if wash_cycles is None:
hold_reasons.append("MISSING_WASHOUT_CYCLES_N")
elif not _is_strict_int(wash_cycles) or wash_cycles < 3:
fail_reasons.append("WASHOUT_CYCLES_LT_3_FAIL")
if lcms_sup is None:
hold_reasons.append("MISSING_H46E02_LCMS_SUPERNATANT_DIAZOXIDE_UM")
elif not _is_finite_number(lcms_sup):
fail_reasons.append("GY014_LCMS_SUPERNATANT_DIAZOXIDE_EXCEEDS_0P05UM_LOQ")
else:
lcms_sup_d = _to_exact_decimal(lcms_sup)
if lcms_sup_d < ZERO_DEC or lcms_sup_d > Decimal("0.05"):
fail_reasons.append("GY014_LCMS_SUPERNATANT_DIAZOXIDE_EXCEEDS_0P05UM_LOQ")
if lcms_pel is None:
hold_reasons.append("MISSING_H46E02_LCMS_PELLET_DIAZOXIDE_UM")
elif not _is_finite_number(lcms_pel):
fail_reasons.append("GY014_LCMS_PELLET_DIAZOXIDE_EXCEEDS_0P05UM_LOQ")
else:
lcms_pel_d = _to_exact_decimal(lcms_pel)
if lcms_pel_d < ZERO_DEC or lcms_pel_d > Decimal("0.05"):
fail_reasons.append("GY014_LCMS_PELLET_DIAZOXIDE_EXCEEDS_0P05UM_LOQ")
rest_lot = obs.get("rest_assay_lot_id")
if rest_lot is None:
hold_reasons.append("MISSING_H46E03_REST_ASSAY_LOT_ID")
elif not _is_literal_nonempty_str(rest_lot) or (valid_lot_id is not None and rest_lot != valid_lot_id):
fail_reasons.append("H46E03_REST_ASSAY_LOT_ID_MISMATCH")
rest_o2 = obs.get("rest_challenge_o2_pct")
if rest_o2 is None:
hold_reasons.append("MISSING_H46E03_REST_CHALLENGE_O2_PCT")
elif not _is_finite_number(rest_o2) or _to_exact_decimal(rest_o2) != Decimal("2"):
fail_reasons.append("H46E03_REST_CHALLENGE_O2_PCT_NOT_2P0_FAIL")
rest_2p = obs.get("rest_two_pulse_gsis_verified")
if rest_2p is None:
hold_reasons.append("MISSING_H46E03_TWO_PULSE_GSIS_VERIFIED_BOOL")
elif not _is_strict_bool(rest_2p):
fail_reasons.append("INVALID_H46E03_TWO_PULSE_GSIS_VERIFIED_BOOL")
elif not rest_2p:
fail_reasons.append("H46E03_TWO_PULSE_GSIS_NOT_VERIFIED_FAIL")
p1_r = obs.get("rest_pulse1_si_rested")
p1_c = obs.get("rest_pulse1_si_control")
p2_r = obs.get("rest_pulse2_si_rested")
p2_c = obs.get("rest_pulse2_si_control")
p_dec_map: Dict[str, Optional[Decimal]] = {}
for f_name, f_val in (
("rest_pulse1_si_rested", p1_r),
("rest_pulse1_si_control", p1_c),
("rest_pulse2_si_rested", p2_r),
("rest_pulse2_si_control", p2_c),
):
if f_val is None:
hold_reasons.append(f"MISSING_H46E03_{f_name.upper()}")
p_dec_map[f_name] = None
elif not _is_finite_number(f_val) or _to_exact_decimal(f_val) <= ZERO_DEC:
fail_reasons.append(f"INVALID_H46E03_{f_name.upper()}")
p_dec_map[f_name] = None
else:
p_dec_map[f_name] = _to_exact_decimal(f_val)
p1_r_d = p_dec_map["rest_pulse1_si_rested"]
p1_c_d = p_dec_map["rest_pulse1_si_control"]
p2_r_d = p_dec_map["rest_pulse2_si_rested"]
p2_c_d = p_dec_map["rest_pulse2_si_control"]
if p1_r_d is not None and p1_c_d is not None:
if p1_r_d < Decimal("3"):
fail_reasons.append("H46E03_REST_PULSE1_SI_LT_3P0_FAIL")
if _ratio_lt_dec(p1_r_d, p1_c_d, Decimal("0.85")):
fail_reasons.append("H46E03_REST_PULSE1_DERIVED_RATIO_LT_0P85_FAIL")
r1_disp = _dec_div_to_display_float(p1_r_d, p1_c_d)
if r1_disp is not None and math.isfinite(r1_disp) and r1_disp > 0.0:
derived_rest_p1_ratio = r1_disp
else:
fail_reasons.append("INVALID_H46E03_PULSE1_RATIO_NONFINITE_OR_ZERO")
if p2_r_d is not None and p2_c_d is not None:
if p2_r_d < Decimal("3"):
fail_reasons.append("H46E03_REST_PULSE2_SI_LT_3P0_FAIL")
if _ratio_lt_dec(p2_r_d, p2_c_d, Decimal("0.85")):
fail_reasons.append("H46E03_REST_PULSE2_DERIVED_RATIO_LT_0P85_FAIL")
r2_disp = _dec_div_to_display_float(p2_r_d, p2_c_d)
if r2_disp is not None and math.isfinite(r2_disp) and r2_disp > 0.0:
derived_rest_p2_ratio = r2_disp
else:
fail_reasons.append("INVALID_H46E03_PULSE2_RATIO_NONFINITE_OR_ZERO")
t50_min = obs.get("oq018_post_washout_t50_min")
t50_fold = obs.get("oq018_post_washout_t50_fold_ctrl")
gsis_si = obs.get("oq018_post_washout_gsis_si")
auc_pct = obs.get("oq018_post_washout_first_phase_auc_pct_ctrl")
auc_l95 = obs.get("oq018_post_washout_first_phase_auc_l95_pct_ctrl")
glucagon_pct = obs.get("oq018_post_washout_glucagon_pct_ctrl")
necr_cut = obs.get("h46e03_paired_hypoxic_necrosis_reduction_pct")
if t50_min is None:
hold_reasons.append("MISSING_OQ018_POST_WASHOUT_T50_MIN")
elif not _is_finite_number(t50_min):
fail_reasons.append("OQ018_INSULIN_SHUTOFF_T50_GE_3P0MIN_FAIL")
else:
t50_min_d = _to_exact_decimal(t50_min)
if t50_min_d <= ZERO_DEC or t50_min_d >= Decimal("3"):
fail_reasons.append("OQ018_INSULIN_SHUTOFF_T50_GE_3P0MIN_FAIL")
if t50_fold is None:
hold_reasons.append("MISSING_OQ018_POST_WASHOUT_T50_FOLD_CTRL")
elif not _is_finite_number(t50_fold):
fail_reasons.append("OQ018_INSULIN_SHUTOFF_T50_FOLD_CTRL_GT_1P10_FAIL")
else:
t50_fold_d = _to_exact_decimal(t50_fold)
if t50_fold_d <= ZERO_DEC or t50_fold_d > Decimal("1.10"):
fail_reasons.append("OQ018_INSULIN_SHUTOFF_T50_FOLD_CTRL_GT_1P10_FAIL")
if gsis_si is None:
hold_reasons.append("MISSING_OQ018_POST_WASHOUT_GSIS_SI")
elif not _is_finite_number(gsis_si):
fail_reasons.append("OQ018_GSIS_SI_LT_3P0_FAIL")
else:
gsis_si_d = _to_exact_decimal(gsis_si)
if gsis_si_d < Decimal("3"):
fail_reasons.append("OQ018_GSIS_SI_LT_3P0_FAIL")
elif p1_r_d is not None and p2_r_d is not None:
lo_p_d = min(p1_r_d, p2_r_d)
hi_p_d = max(p1_r_d, p2_r_d)
if gsis_si_d < lo_p_d or gsis_si_d > hi_p_d:
fail_reasons.append("OQ018_CLAIMED_GSIS_SI_INCONSISTENT_WITH_TWO_PULSE_MEASUREMENTS")
auc_pct_d: Optional[Decimal] = None
if auc_pct is None:
hold_reasons.append("MISSING_OQ018_FIRST_PHASE_AUC_PCT_CTRL")
elif not _is_finite_number(auc_pct):
fail_reasons.append("OQ018_FIRST_PHASE_AUC_LT_90PCT_CTRL_FAIL")
else:
auc_pct_d = _to_exact_decimal(auc_pct)
if auc_pct_d < Decimal("90"):
fail_reasons.append("OQ018_FIRST_PHASE_AUC_LT_90PCT_CTRL_FAIL")