OpenIslet

scripts/verify_iip0041_clinical_h1_cd64t_siglec.py

EXP-028 (CAND-031 / Target IIP-0041 — Bucket 2A) Remediated Verification Suite

script Release v0.8.0 gen-eb955f8266035aba 984 KB · 69 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…

) -> tuple[float | None, str]:
    """Format an exact non-negative Fraction percentage inside an isolated Decimal display context (trap- and overflow-immune)."""
    with localcontext(_CLEAN_DISPLAY_DECIMAL_CTX()):
        if not out_of_assay_range:
            scaled_int = round(derived_ret_frac * 10000)
            display_dec = (Decimal(scaled_int) / Decimal(10000)).quantize(Decimal("0.0001"))
            display_ret_float = float(display_dec)
            return display_ret_float, f"{display_ret_float:.4f}%"
        int_part = derived_ret_frac.numerator // derived_ret_frac.denominator
        if int_part >= 1:
            exp = len(str(int_part)) - 1
            mantissa_1e4 = round((derived_ret_frac * 10000) / (10 ** exp))
            if mantissa_1e4 >= 100000:
                exp += 1
                mantissa_1e4 = round((derived_ret_frac * 10000) / (10 ** exp))
            display_dec = (Decimal(mantissa_1e4) / Decimal(10000)) * Decimal(f"1e{exp}")
        else:
            display_dec = Decimal(derived_ret_frac.numerator) / Decimal(derived_ret_frac.denominator)
        return None, f"{display_dec:.4E}%"


# =============================================================================
# EXACT STDLIB BETA DISTRIBUTION & CLOPPER-PEARSON HELPERS (ZERO SCIPY DRIFT)
# =============================================================================
def _betacf(a: float, b: float, x: float) -> float:
    maxit = 400
    eps = 3.0e-14
    fpmin = 1.0e-300
    qab = a + b
    qap = a + 1.0
    qam = a - 1.0
    c = 1.0
    d = 1.0 - qab * x / qap
    if abs(d) < fpmin:
        d = fpmin
    d = 1.0 / d
    h = d
    for m in range(1, maxit + 1):
        m2 = 2 * m
        aa = m * (b - m) * x / ((qam + m2) * (a + m2))
        d = 1.0 + aa * d
        if abs(d) < fpmin:
            d = fpmin
        c = 1.0 + aa / c
        if abs(c) < fpmin:
            c = fpmin
        d = 1.0 / d
        h *= d * c
        aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2))
        d = 1.0 + aa * d
        if abs(d) < fpmin:
            d = fpmin
        c = 1.0 + aa / c
        if abs(c) < fpmin:
            c = fpmin
        d = 1.0 / d
        delta = d * c
        h *= delta
        if abs(delta - 1.0) < eps:
            break
    return h


def beta_cdf(x: float, a: float, b: float) -> float:
    if x <= 0.0:
        return 0.0
    if x >= 1.0:
        return 1.0
    bt = math.exp(
        math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b)
        + a * math.log(x) + b * math.log(1.0 - x)
    )
    if x < (a + 1.0) / (a + b + 2.0):
        return bt * _betacf(a, b, x) / a
    return 1.0 - bt * _betacf(b, a, 1.0 - x) / b


def beta_ppf(q: float, a: float, b: float) -> float:
    if q <= 0.0:
        return 0.0
    if q >= 1.0:
        return 1.0
    lo, hi = 0.0, 1.0
    for _ in range(90):
        mid = 0.5 * (lo + hi)
        if beta_cdf(mid, a, b) < q:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)


def clopper_pearson_ci(k: int, n: int, alpha: float = 0.05) -> tuple[float, float]:
    lo = 0.0 if k == 0 else beta_ppf(alpha / 2.0, float(k), float(n - k + 1))
    hi = 1.0 if k == n else beta_ppf(1.0 - alpha / 2.0, float(k + 1), float(n - k))
    return lo, hi


def _beta_posterior_summary(a0: float, b0: float, k: int, n: int, *, overlap_status: str) -> dict[str, Any]:
    a1 = a0 + k
    b1 = b0 + (n - k)
    mean = a1 / (a1 + b1)
    ci_lo = beta_ppf(0.025, a1, b1)
    ci_hi = beta_ppf(0.975, a1, b1)
    p_ge_88 = 1.0 - beta_cdf(0.88, a1, b1)
    p_ge_90 = 1.0 - beta_cdf(0.90, a1, b1)
    return {
        "prior_params": [round(a0, 4), round(b0, 4)],
        "posterior_params": [round(a1, 4), round(b1, 4)],
        "overlap_status": overlap_status,
        "posterior_mean_pct": round(100.0 * mean, 2),
        "credible_95_pct": [round(100.0 * ci_lo, 2), round(100.0 * ci_hi, 2)],
        "prob_ge_88pct": round(100.0 * p_ge_88, 2),
        "prob_ge_90pct": round(100.0 * p_ge_90, 2),
        "prob_ge_90_exact": round(p_ge_90, 6),
    }


def analyze_clinical_h1_reanchor() -> dict[str, Any]:
    # Non-informative priors (ZERO overlap with Reichman 2025) vs Reichman-anchored priors.
    # Live ISLET-1-BLUEPRINT.md line 37 conditions H1..H4 on having passed laboratory/GMP release checks
    # and cites Reichman 2025 to anchor clinical post-release H1 = 0.88; therefore:
    #   (a) Blueprint H1 MUST remain P(response | released lot infused) (never overloaded with CMC lot-release rate),
    #   (b) P_release_CMC (release-only operational yield) and H1_CMC_ATTEMPTED_LOT_READINESS =
    #       P_release_CMC * P_infuse_given_released * H1_Blueprint are tracked in a strictly separate readiness ledger,
    #   (c) updating Beta(8.8, 1.2) with Reichman's 12 outcomes double-counts Reichman, and
    #   (d) mixed-cohort pooled counts (13/13, 11/13, 12/14, 16/16) are descriptive sensitivities conditional on
    #       assumed common-endpoint counts ONLY (primary_verified=False; never an exchangeable promotion likelihood).
    non_informative_priors = {
        "uniform_Beta_1_1": (1.0, 1.0),
        "jeffreys_Beta_0p5_0p5": (0.5, 0.5),
    }
    anchored_priors = {
        "openislet_prior_Beta_8p8_1p2_n10": (8.8, 1.2),
        "openislet_prior_Beta_17p6_2p4_n20": (17.6, 2.4),
    }

    # Explicit per-study endpoint, observation-window, intercurrent-event, and missing-data adjudication ledger
    per_study_endpoint_adjudication_ledger = [
        {
            "study_id": "Reichman_2025_NEJM_PMID_40544428",
            "pmid": "40544428",
            "source_pointers": "Reichman et al. NEJM 2025 (PMID:40544428), Results and Figures 2-3 (NCT04786262 Parts A/B/C)",
            "product_class": "ALLOGENEIC_HESC_SC_ISLET_ZIMISLECEL_VX880",
            "transplant_site": "INTRAPORTAL_HEPATIC",
            "immunosuppression_regimen": "DE_NOVO_GLUCOCORTICOID_FREE_CHRONIC_SYSTEMIC_IS",
            "observation_window": "12 months (Day 365 efficacy follow-up; primary SHE window Days 90-365; HbA1c window Days 180-365)",
            "analyzed_population_definition": (
                "14 dosed participants in Parts A-C who had completed >= 12 months of follow-up at data cutoff "
                "(2 half-dose participants in Part A + 12 full-dose participants in Parts B/C); excludes any "
                "additional dosed participants with < 12 months of follow-up."
            ),
            "original_published_primary_endpoint": (
                "Elimination of severe hypoglycemic events (Days 90-365) with HbA1c < 7.0% or >= 1 percentage-point reduction "
                "from baseline (distinct from the stricter proposed common C2b sustained composite requiring simultaneous "
                "HbA1c < 7.0%, CGM TIR > 70%, 0 SHEs, and quantitative stimulated C-peptide)."
            ),
            "published_counts": {
                "analyzed_ge12mo_followup_population_n": 14,
                "analyzed_ge12mo_followup_breakdown": "2 half-dose Part A + 12 full-dose Parts B/C (participants with >= 12 months follow-up)",
                "analyzed_ge12mo_followup_c_peptide_engraftment_parts_abc": "14/14",
                "full_dose_12mo_analysis_n": 12,
                "full_dose_original_glycemic_target_met": "12/12",
                "day365_cgm_records_in_figure_3_n": 11,
                "day365_cgm_missing_count_of_12": 1,
                "day365_insulin_independence": "10/12",
                "protocol_prohibited_peri_infusion_glucocorticoids_n": 2,
                "protocol_prohibited_glucocorticoid_note": (
                    "Two full-dose participants received protocol-prohibited peri-infusion glucocorticoids; "
                    "those same 2 participants remained on exogenous insulin at Day 365."
                ),
                "trial_deaths_in_analyzed_14_n": 2,
                "trial_deaths_product_vs_regimen_attribution": {
                    "death_1_cryptococcal_meningitis": (
                        "Fatal cryptococcal meningitis (~19.5 months post-infusion) — occurred following surgery "
                        "complicated by skull-base injury, prolonged protocol-prohibited systemic glucocorticoids, "
                        "and concurrent chronic immunosuppression; assessed by investigators as UNRELATED to "
                        "zimislecel (the cell product) BUT RELATED to the chronic immunosuppressive medication regimen."
                    ),
                    "death_2_preexisting_neurocognitive_disease": (
                        "Progression of pre-existing neurocognitive disease (~30 months post-infusion) — assessed "
                        "as UNRELATED to zimislecel and unrelated to the immunosuppressive regimen."
                    ),
                },
                "trial_deaths_note": (
                    "2 deaths occurred in the 14-participant >=12-month analyzed population: "
                    "1 fatal cryptococcal meningitis (~19.5 months post-infusion) following surgery complicated by "
                    "skull-base injury, prolonged protocol-prohibited systemic glucocorticoids, and concurrent "
                    "chronic immunosuppression (assessed by investigators as unrelated to zimislecel [product] BUT "
                    "related to the chronic immunosuppressive medication regimen), and 1 progression of pre-existing "
                    "neurocognitive disease (~30 months post-infusion, unrelated to zimislecel or immunosuppression)."
                ),
            },
            "attempted_gmp_lots_cmc_denominator_disclosed": False,
            "missing_data_and_adjudication_status": "PUBLISHED_STUDY_SPECIFIC_ENDPOINT_ONLY_NOT_COMMON_C2B_ADJUDICATED",
        },
        {
            "study_id": "Wang_2024_Cell_PMID_39326417",
            "pmid": "39326417",
            "source_pointers": "Wang et al. Cell 2024 (PMID:39326417), Methods, Results, and Figures 2-3 (ChiCTR2300072200)",
            "product_class": "AUTOLOGOUS_UNEDITED_CIPSC_ISLET",
            "transplant_site": "ABDOMINAL_ANTERIOR_RECTUS_SHEATH",
            "immunosuppression_regimen": "CONTINUED_3_DRUG_PRIOR_LIVER_TRANSPLANT_IS_PLUS_PERI_INFUSION_INDUCTION",
            "observation_window": "1 year (365 days); insulin independence from Day 75 through 1-year follow-up",
            "original_published_primary_endpoint": "Single-recipient safety and 1-year glycemic/C-peptide restoration case report",
            "published_counts": {
                "infused_t1d_recipients_n": 1,
                "insulin_independence_day75_to_1yr": "1/1",
                "stimulated_c_peptide_and_improved_tir_and_0_she": "1/1",
                "missing_primary_cgm_count": 0,
            },
            "attempted_gmp_lots_cmc_denominator_disclosed": False,
            "missing_data_and_adjudication_status": "SINGLE_RECIPIENT_OBSERVED_INCOMPATIBLE_PRODUCT_SITE_REGIMEN_FOR_ALLO_POOLING",
        },
        {
            "study_id": "Wu_2024_CellDiscov_PMID_38684699",
            "pmid": "38684699",
            "source_pointers": "Wu et al. Cell Discov 2024 (PMID:38684699), T2D autologous endoderm SC-islet case",
            "product_class": "AUTOLOGOUS_ENDODERM_SC_ISLET_T2D",
            "transplant_site": "INTRAPORTAL_HEPATIC",
            "immunosuppression_regimen": "PRIOR_KIDNEY_TRANSPLANT_SYSTEMIC_IS",
            "observation_window": "116 weeks reported in T2D recipient (distinct disease from T1D)",
            "original_published_primary_endpoint": "Single-recipient T2D insulin-free glycemic control",
            "published_counts": {"infused_t2d_recipients_n": 1, "insulin_independence": "1/1"},
            "attempted_gmp_lots_cmc_denominator_disclosed": False,
            "missing_data_and_adjudication_status": "DISTINCT_DISEASE_T2D_EXCLUDED_FROM_T1D_H1_LIKELIHOOD",
        },
        {
            "study_id": "Shi_2026_LancetDE_PMID_41765034",
            "pmid": "41765034",
            "source_pointers": "Shi et al. Lancet Diabetes Endocrinol Apr 2026;14(4):285-288 (PMID:41765034; Letter with 0 abstract chars in PubMed XML)",
            "product_class": "MIXED_UNVERIFIED_PAYWALLED_LETTER_REPORT",
            "transplant_site": "UNVERIFIED_FROM_PRIMARY_PDF",
            "immunosuppression_regimen": "CHRONIC_IS_AND_REPORTED_AUTOLOGOUS_IS_WITHDRAWAL_LOSS_PER_SECONDARY_REPORT",
            "observation_window": "Unverified from paywalled primary full text; repeat infusion reported in first recipient",
            "original_published_primary_endpoint": "Unverified from paywalled primary Letter full text",
            "published_counts": {"reported_recipients_n": 3, "primary_verified_counts": None},
            "attempted_gmp_lots_cmc_denominator_disclosed": False,
            "missing_data_and_adjudication_status": "UNAUTHENTICATED_PAYWALLED_LETTER_SENSITIVITY_ONLY",
        },
    ]

    cohorts = [
        {
            "cohort_id": "C1a_Reichman2025_FullDose_InsulinFree",
            "label": "Reichman et al. 2025 (NEJM; PMID:40544428) full-dose zimislecel Parts B/C insulin independence at Day 365 (10/12 under chronic glucocorticoid-free IS; 2/12 non-independent recipients received protocol-prohibited peri-infusion glucocorticoids)",
            "k": 10, "n": 12, "includes_reichman": True, "setting": "ALLOGENEIC_ESC",
            "primary_verified": True, "common_c2b_adjudicated": False, "exchangeable_likelihood_valid": True,
            "analysis_role": "SINGLE_STUDY_PUBLISHED_INSULIN_INDEPENDENCE_OBSERVATION",
            "immunosuppression_status": "CHRONIC_SYSTEMIC_IS_WITH_2_OF_12_PROHIBITED_GLUCOCORTICOID_INTERCURRENT_EVENTS",