OpenIslet

scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py

Provisional IIP-0058 / DEC-139 / GATE-37 / GY-036 (Round-14 Blueprint Alignment; staged in iip0058/):

script Release v0.8.0 gen-eb955f8266035aba 837 KB · 62 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_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py · SHA-256: 33439d619c00fcc3…

        {
            "cell_line": "H1_hESC",
            "published_total_loaded_recovery_pct": 15.81,
            "denominator": "ALL_LOADED_STAGE4_CELLS (already incorporates starting GP2+ prevalence; NOT multiplied by %GP2+)",
            "implied_loaded_billions_per_1B_gp2_harvested": round(1.0 / 0.1581, 2),
            "implied_loaded_billions_exact_3dec": round(1.0 / 0.1581, 3),
        },
        {
            "cell_line": "H9_hESC",
            "published_total_loaded_recovery_pct": 23.83,
            "displayed_3replicate_mean_recovery_pct": 23.38,
            "denominator": "ALL_LOADED_STAGE4_CELLS (already incorporates starting GP2+ prevalence; NOT multiplied by %GP2+)",
            "implied_loaded_billions_per_1B_gp2_harvested": round(1.0 / 0.2383, 2),
            "implied_loaded_billions_printed_3dec": round(1.0 / 0.2383, 3),
            "implied_loaded_billions_replicate_mean_2dec": round(1.0 / 0.2338, 2),
            "implied_loaded_billions_replicate_mean_3dec": round(1.0 / 0.2338, 3),
            "table1_discrepancy_note": (
                "Aghazadeh 2022 Table 1 prints H9 mean recovery as 23.83% (4.196 B / 4.20 B loaded per 1 B recovered), "
                "whereas the three listed H9 replicate values average 23.38% (4.277 B / 4.28 B loaded per 1 B recovered)."
            ),
        },
    ]

    conditional_yield_matrix = []
    for gp2_frac in (0.05, 0.10, 0.20, 0.25, 0.40, 0.65):
        for eta_cond in (0.20, 0.65):
            net_frac = gp2_frac * eta_cond
            req_billions = 1.0 / net_frac
            conditional_yield_matrix.append({
                "stage4_gp2_pos_frac": gp2_frac,
                "conditional_per_gp2_capture_efficiency_eta_cond": eta_cond,
                "denominator_note": "eta_cond = recovered_GP2+ / loaded_GP2+ (must be measured directly; distinct from Aghazadeh total-loaded yield)",
                "net_stage4_harvest_frac": round(net_frac, 4),
                "required_stage4_input_billions_for_1B_PP": round(req_billions, 2),
                "expansion_penalty_vs_65pct_line": round(0.65 / gp2_frac, 2),
                "policy_disposition": (
                    "AUTOLOGOUS_BYPASS_SEPARATE_DISPOSITION_LT_25PCT"
                    if gp2_frac < 0.25
                    else ("INTERMEDIATE_CAUTION_25_TO_39PCT" if gp2_frac < 0.40 else "ALLOGENEIC_MCB_QUALIFIED_GE_40PCT")
                ),
            })

    ds_s_vals = [x["sg_sg_dist_A"] for x in ss_verified_7p6s]
    ds_t_vals = [x["sg_sg_dist_A"] for x in ss_verified_7p6t]
    _require(abs(min(ds_s_vals) - 2.027) < 0.002 and abs(max(ds_s_vals) - 2.070) < 0.002, f"7P6S disulfide range drift: {ds_s_vals}")
    _require(abs(min(ds_t_vals) - 2.032) < 0.002 and abs(max(ds_t_vals) - 2.074) < 0.002, f"7P6T disulfide range drift: {ds_t_vals}")

    return {
        "gp2_uniprot": "P55259",
        "paralog_uniprot": "P07911",
        "crystal_anchors": {
            "7P6S": {
                "resolution_A": 1.35,
                "sha256": crystal_data["source_rcsb_cc0_sha256"]["7P6S"],
                "deposited_nag_site_count": 2,
                "deposited_nag_linked_asns": sorted(g_s["deposited_nag_sites_linked_asn"].values()),
                "unmodeled_d10c_asn_sequons": [88, 134],
                "disulfide_sg_sg_range_A": [min(ds_s_vals), max(ds_s_vals)],
            },
            "7P6T": {
                "resolution_A": 1.40,
                "sha256": crystal_data["source_rcsb_cc0_sha256"]["7P6T"],
                "deposited_nag_site_count": 3,
                "deposited_nag_linked_asns": sorted(g_t["deposited_nag_sites_linked_asn"].values()),
                "unmodeled_d10c_asn_sequons": [88],
                "disulfide_sg_sg_range_A": [min(ds_t_vals), max(ds_t_vals)],
            },
        },
        "d10c_disulfides_verified_6_7P6S": ss_verified_7p6s,
        "d10c_disulfides_verified_6_7P6T": ss_verified_7p6t,
        "d10c_disulfide_range_summary_A": {
            "7P6S_min_max_A": [min(ds_s_vals), max(ds_s_vals)],
            "7P6T_min_max_A": [min(ds_t_vals), max(ds_t_vals)],
            "combined_min_max_A": [min(min(ds_s_vals), min(ds_t_vals)), max(max(ds_s_vals), max(ds_t_vals))],
        },
        "surface_epitopes_4_nag_vs_asn_separated": epitopes,
        "crystal_bfactor_caveat": (
            "G3 residue-mean B-factor is 15.571 A^2 in 7P6S vs 26.909 A^2 in 7P6T; crystal-specific "
            "B-factors depend on crystal packing/resolution and do not establish general solution rigidity."
        ),
        "paralog_umod_exclusivity": {
            "mature_identity_pct": 44.07,
            "d10c_identity_pct": 60.0,
            "zp_identity_pct": 55.25,
            "hpa_pancreatic_umod_protein_qualitative": "not detected",
            "hpa_umod_protein_distribution": "Detected in single (kidney only); qualitative IHC readout, not a numeric 0% assay",
            "gtex_v8_gp2_pancreas_tpm": 13259.0,
            "gtex_v8_umod_pancreas_tpm": 2.509,
            "gtex_v8_pancreas_gp2_over_umod_ratio": round(13259.0 / 2.509, 1),
        },
        "aghazadeh_2022_pmid35364010_primary_observations_vs_prospective_gate": {
            "observed_teratomas_gp2_pos_nsg_15wk": "0/11",
            "observed_controls": "4/15 unsorted, 3/17 flow-through (NSG, 15 wk)",
            "observed_0_of_11_exact_onesided_95pct_u95_pct": round(agha_0_of_11_u95, 2),
            "prospective_gate35_criterion": "0/12 SCID-Beige at 26 wk (NEW prospective gate; exact one-sided 95% U95 = 22.09%)",
            "prospective_0_of_12_exact_onesided_95pct_u95_pct": round(prospective_0_of_12_u95, 2),
        },
        "aghazadeh_table1_total_loaded_yields": aghazadeh_table1_total_loaded_yields,
        "conditional_capture_sensitivity_matrix": conditional_yield_matrix,
        "rt1_deployment_contract": {
            "scope": "ALLOGENEIC_MCB_INTERMEDIATE_BANKING_ONLY",
            "allogeneic_min_gp2_pct": 40.0,
            "autologous_bypass_lt_gp2_pct": 25.0,
            "autologous_ge_25pct_on_allo_gate": "REJECTED_OUT_OF_SCOPE",
            "max_mature_acinar_cpa1_prss1_ptf1a_pct": 2.0,
            "acinar_vs_progenitor_definition": (
                "Excludes mature exocrine acinar contamination (CPA1+/PRSS1+/PTF1A+ <= 2.0% of total live Stage-4 cells), "
                "explicitly distinguishing mature acinar cells from intended PDX1+/NKX6.1+ (including PTF1A-coexpressing) "
                "multipotent pancreatic progenitors (Cogger et al. 2017 PMID:28835709)."
            ),
            "min_gpi_post_dissociation_mfi_retention_pct": 85.0,
            "sc_ec_attribution": (
                "Stage-4 GP2+ enriches PDX1+/NKX6.1+ progenitors (PMID:28380361) and showed 0/11 NSG teratomas "
                "at 15 wk (U95=23.84%, PMID:35364010), but does NOT purge Stage-5 TPH1+ SC-EC bifurcation "
                "(persistent NGN3 expression is associated with human and murine pancreatic EC-like differentiation "
                "per Misra et al. Mar 2026 PMID:41851084; suppressing persistent NGN3 is a prospective Stage-5 "
                "hypothesis gated on empirical post-sort TPH1+ readout)."
            ),
        },
    }


def verify_stage6_7_itga1_narrowed_ridge_and_entpd3(crystal_data: dict[str, Any]) -> dict[str, Any]:
    d_1pt6_a = crystal_data["itga1_1pt6_A"]
    d_1pt6_b = crystal_data["itga1_1pt6_B"]
    d_1qc5_a = crystal_data["itga1_1qc5_A"]
    d_1qc5_b = crystal_data["itga1_1qc5_B"]
    models_2m32 = crystal_data["itga1_2m32_models"]
    _require(len(models_2m32) == 10, f"Expected all 10 NMR models of 2M32, got {len(models_2m32)}")

    # Verify ZERO deposited glycan atoms across all ITGA1 experimental PDBs
    for lbl, entry in [("1PT6:A", d_1pt6_a), ("1PT6:B", d_1pt6_b), ("1QC5:A", d_1qc5_a), ("1QC5:B", d_1qc5_b)]:
        _require(entry["deposited_glycan_atom_count"] == 0, f"Unexpected glycan atoms in {lbl}")
    for m_id, m_entry in models_2m32.items():
        _require(m_entry["deposited_glycan_atom_count"] == 0, f"Unexpected glycan atoms in 2M32 model {m_id}")

    ridge_u = ("292", "295", "296")
    aa_map = {292: "K", 295: "Q", 296: "D", 298: "E", 299: "D", 300: "E", 333: "E", 238: "K", 239: "K", 241: "V"}

    # Apo X-ray chains (all 4 chains: 1PT6:A, 1PT6:B, 1QC5:A, 1QC5:B)
    apo_summary: dict[str, Any] = {}
    for lbl, entry in [("1PT6:A", d_1pt6_a), ("1PT6:B", d_1pt6_b), ("1QC5:A", d_1qc5_a), ("1QC5:B", d_1qc5_b)]:
        r_pts = [pt for u in ridge_u for pt in entry["patch_atoms"][u]]
        asn_pts = [pt for g in ("217", "317", "341") for pt in entry["asn_sequon_atoms"][g]]
        apo_summary[lbl] = {
            "ridge_min_d_Mg_A": round(min_dist_sets(r_pts, [entry["mg"]]), 3),
            "ridge_min_d_protein_asn_sequons_N217_N317_N341_A": round(min_dist_sets(r_pts, asn_pts), 3),
            "ridge_min_d_seg_338_358_A": round(min_dist_sets(r_pts, entry["seg_338_358_heavy"]), 3),
            "deposited_glycan_atom_count": 0,
        }
    _require(abs(apo_summary["1PT6:A"]["ridge_min_d_Mg_A"] - 20.930) < 0.005, f"1PT6:A d_Mg drift: {apo_summary['1PT6:A']}")

    # Evaluate ALL 10 NMR conformers of 2M32 with exact Kabsch superposition!
    core_u = sorted(int(k) for k in d_1pt6_a["core_ca"].keys())
    seg_u = sorted(int(k) for k in d_1pt6_a["seg_338_358_ca"].keys())
    p_core_1pt6 = [d_1pt6_a["core_ca"][str(u)] for u in core_u]
    p_core_1qc5 = [d_1qc5_a["core_ca"][str(u)] for u in core_u]

    conformer_rows: list[dict[str, Any]] = []
    d_colls: list[float] = []
    d_segs: list[float] = []
    d_mgs: list[float] = []
    d_asns: list[float] = []
    p2_colls: list[float] = []
    rmsds_1pt6: list[float] = []
    rmsds_1qc5: list[float] = []
    seg_means: list[float] = []
    seg_maxs: list[float] = []

    for m_idx in range(1, 11):
        dm = models_2m32[str(m_idx)]
        q_core = [dm["core_ca"][str(u)] for u in core_u]
        rmsd_1pt6, tf_1pt6 = kabsch_superpose(p_core_1pt6, q_core)
        rmsd_1qc5, _ = kabsch_superpose(p_core_1qc5, q_core)

        shifts = [math.dist(tf_1pt6(dm["seg_338_358_ca"][str(u)]), d_1pt6_a["seg_338_358_ca"][str(u)]) for u in seg_u]
        s_mean = sum(shifts) / len(shifts)
        s_max = max(shifts)
        s_max_u = seg_u[shifts.index(s_max)]

        r_pts = [pt for u in ridge_u for pt in dm["patch_atoms"][u]]
        p2_pts = [pt for u in ("238", "239", "241") for pt in dm["patch_atoms"][u]]
        asn_pts = [pt for g in ("217", "317", "341") for pt in dm["asn_sequon_atoms"][g]]
        seg_pts = dm["seg_338_358_heavy"]
        coll_pts = dm["collagen_heavy"]

        dc = min_dist_sets(r_pts, coll_pts)
        ds = min_dist_sets(r_pts, seg_pts)
        dm_mg = min_dist_sets(r_pts, [dm["mg"]])
        da = min_dist_sets(r_pts, asn_pts)
        d_e333 = min_dist_sets(dm["patch_atoms"]["333"], seg_pts)
        d_e300 = min_dist_sets(dm["patch_atoms"]["300"], seg_pts)
        p2_dc = min_dist_sets(p2_pts, coll_pts)

        d_colls.append(dc)
        d_segs.append(ds)
        d_mgs.append(dm_mg)
        d_asns.append(da)
        p2_colls.append(p2_dc)
        rmsds_1pt6.append(rmsd_1pt6)
        rmsds_1qc5.append(rmsd_1qc5)
        seg_means.append(s_mean)
        seg_maxs.append(s_max)

        conformer_rows.append({
            "conformer_model": m_idx,
            "preselected_31_core_rmsd_vs_1PT6_A": round(rmsd_1pt6, 3),
            "preselected_31_core_rmsd_vs_1QC5_A": round(rmsd_1qc5, 3),
            "seg_338_358_mean_ca_shift_A": round(s_mean, 3),
            "seg_338_358_max_ca_shift_A": round(s_max, 3),
            "seg_338_358_max_shift_uniprot_res": s_max_u,
            "ridge_min_d_collagen_A": round(dc, 3),
            "ridge_min_d_seg_338_358_A": round(ds, 3),
            "ridge_min_d_Mg_A": round(dm_mg, 3),
            "ridge_min_d_protein_asn_sequons_A": round(da, 3),
            "e333_min_d_seg_338_358_A": round(d_e333, 3),
            "e300_min_d_seg_338_358_A": round(d_e300, 3),
            "meets_legacy_cuts_coll15p6_and_seg12p2": bool(dc >= 15.6 and ds >= 12.2),
        })

    # Assert exact ensemble reproduction matching independent SVD audit
    _require(abs(conformer_rows[0]["preselected_31_core_rmsd_vs_1PT6_A"] - 1.232) < 0.002, "M1 1PT6 RMSD drift")
    _require(abs(conformer_rows[0]["preselected_31_core_rmsd_vs_1QC5_A"] - 1.216) < 0.002, "M1 1QC5 RMSD drift")
    _require(abs(conformer_rows[0]["seg_338_358_max_ca_shift_A"] - 14.867) < 0.005, "M1 seg max shift drift")
    _require(abs(min(d_colls) - 14.838) < 0.005, f"Ensemble min d_collagen drift: {min(d_colls)}")
    _require(abs(min(d_segs) - 10.909) < 0.005, f"Ensemble min d_seg_338_358 drift: {min(d_segs)}")
    _require(abs(min(d_mgs) - 19.690) < 0.005, f"Ensemble min d_Mg drift: {min(d_mgs)}")

    count_coll_ge_15p6 = sum(1 for x in d_colls if x >= 15.6)
    count_coll_ge_14p5 = sum(1 for x in d_colls if x >= 14.5)
    count_seg_ge_12p2 = sum(1 for x in d_segs if x >= 12.2)
    count_seg_ge_10p5 = sum(1 for x in d_segs if x >= 10.5)
    count_both_legacy = sum(1 for r in conformer_rows if r["meets_legacy_cuts_coll15p6_and_seg12p2"])
    _require(count_coll_ge_15p6 == 7 and count_coll_ge_14p5 == 10, "Unexpected collagen conformer counts")
    _require(count_seg_ge_12p2 == 7 and count_seg_ge_10p5 == 10, "Unexpected seg_338_358 conformer counts")
    _require(count_both_legacy == 6, f"Expected 6/10 conformers meeting both legacy cuts, got {count_both_legacy}")

    # Per-residue Patch #1 ensemble summary (min across all 10 2M32 models + Model 1 + apo 1PT6/1QC5)
    asn_1pt6 = [pt for g in ("217", "317", "341") for pt in d_1pt6_a["asn_sequon_atoms"][g]]
    asn_1qc5 = [pt for g in ("217", "317", "341") for pt in d_1qc5_a["asn_sequon_atoms"][g]]
    per_res: dict[str, Any] = {}
    for u in (292, 295, 296, 298, 299, 300, 333):
        key = f"{aa_map[u]}{u}"
        su = str(u)
        d_seg_m_all = [min_dist_sets(models_2m32[str(m)]["patch_atoms"][su], models_2m32[str(m)]["seg_338_358_heavy"]) for m in range(1, 11)]
        d_coll_m_all = [min_dist_sets(models_2m32[str(m)]["patch_atoms"][su], models_2m32[str(m)]["collagen_heavy"]) for m in range(1, 11)]
        d_mg_m_all = [min_dist_sets(models_2m32[str(m)]["patch_atoms"][su], [models_2m32[str(m)]["mg"]]) for m in range(1, 11)]
        d_asn_m_all = [
            min_dist_sets(
                models_2m32[str(m)]["patch_atoms"][su],