OpenIslet

scripts/run_layer5_personalized_patient_compiler.py

Layer 5: Personalized Patient-DNA & Multiplex CRISPR Compiler + 10,000-Patient Global Population Simulator (v0.8.0)

script Release v0.8.0 gen-eb955f8266035aba 494 KB · 31 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/run_layer5_personalized_patient_compiler.py · SHA-256: 0b285369ac6e4409…

                    p_g * engineering_complexity_discount(
                        min(k_g, 4), b_g, lambda_K=engineering_parameters["lambda_K"], gamma_B=engineering_parameters["gamma_B"]
                    )
                )
            donor_tyk2_rows.append({
                "donor_tyk2_rs34536443_genotype": donor_g,
                "kb_complexity_counts": kb_g,
                "recipients_prescribed_tyk2_prime_editing": pe_cnt,
                "total_tyk2_alleles_requiring_prime_edit_across_cohort": allele_sum,
                "analytic_personalized_mean_survival_pct": round(100.0 * float(np.mean(surv_vec)), 4),
                "complexity_discounted_personalized_utility_pct": round(100.0 * float(np.mean(disc_vec)), 4),
                "b_prime_sct_k4_complexity_discounted_utility_pct": round(100.0 * float(np.mean(b_prime_sct_disc_vec)), 4),
                "max_abs_patient_survival_difference_vs_default_gg": round(
                    float(np.max(np.abs(np.asarray(surv_vec, dtype=np.float64) - base_surv_arr))),
                    12,
                ),
            })
        donor_tyk2_sensitivity_summary = {
            "decision_id": "DEC-090",
            "proposal_id": "IIP-0011",
            "variant": "TYK2 rs34536443 (c.3310C>G, p.Pro1104Ala in the catalytic JH1 kinase domain; PMID:27807284, PMID:35470158)",
            "cohort_evaluated": "Exact 10,000 main-simulation SIM-* patient records held fixed (separate COP-* copula sensitivity records excluded)",
            "default_donor_genotype_in_main_trial": "G/G",
            "donor_genotype_comparison_table": donor_tyk2_rows,
            "assigned_survival_invariance_verified": bool(
                all(r["max_abs_patient_survival_difference_vs_default_gg"] == 0.0 for r in donor_tyk2_rows)
            ),
            "survival_and_utility_interpretation_note": (
                "Every simulated patient's assigned 5-year survival probability is identical across G/G, G/C, and natural C/C donor seed lines; "
                "heterozygous G/C reduces the allele count requiring prime editing from 2 to 1 while retaining edited locus count B = 1, whereas "
                "natural homozygous C/C removes the optional TYK2 prime-editing step (B = 1 -> 0) for all 4,374 TYK2-eligible recipients. "
                "The complexity-discounted utility shift reflects solely removal of the assumed gamma_B locus-editing discount, not measured manufacturing yield or clinical benefit."
            ),
            "mcb_product_scope_and_seedline_qualification_gates": (
                "Collapsing two TYK2-stratified Master Cell Bank sublines (B = 0 and B = 1) into a single B = 0 subline applies strictly to the "
                "TYK2 stratification dimension within a defined product: the main 10,000-patient simulation still retains 2,367 K = 5 endogenous-HLA-C "
                "Plan B patients (and the promoted B'-SCT route maintains separate K = 4 C1/C2/C1C2 KIR-matched products and requires >= 2 independent "
                "MCB clones from distinct donors; GY-005). Any candidate natural TYK2 C/C (p.Pro1104Ala/p.Pro1104Ala) donor hPSC line must clear: "
                "(1) Stage 0->7 endocrine precursor emergence and mature SC-islet yield equivalence (Chandra et al. 2022 PMID:36289205), "
                "(2) Stage-0 Rule S8 (< 70% shield-induction trigger) across both Locus-1 5xISRE->HLA-E and Locus-3 CXCL10::SERPINB9-GSG-P2A-PD-L1 "
                "under IFN-alpha plus low IFN-gamma alongside lineage-specific resting HLA-E and Hour-0 CD47 floors (GY-001, GY-009), and "
                "(3) 30x WGS, >= 63,000x TP53/PPM1D/BCOR duplex-seq, CAST-seq, and potency release (GY-006)."
            ),
            "primary_citations": ["PMID:27807284", "PMID:35470158", "PMID:36289205"],
        }
    return {
        "model_classification_and_scope_note_sol_v80_10": (
            "Illustrative assigned-rule scenario simulation (NOT clinical trial data, fitted survival hazard model, or "
            "validated epidemiological forecast): each of the 10,000 virtual patient records is passed through "
            "compile_personalized_patient_blueprint() and evaluated against conditional assigned-rule penalties (base 0.982, "
            "unedited control fixed at 0.0) to check rule-consistency across Arm 1B (Hour-0 CD47-IgV floor), Plan B "
            "(HLA-C-retaining sub-bank for high KIR+ NKG2A- NK fractions), and TYK2 P1104A protection (closing AUDIT-REF)."
        ),
        "total_virtual_patients_simulated": total_n,
        "global_5yr_survival_unedited_allogeneic_pct": round(100.0 * overall_counts["unedited_5yr_survival"] / total_n, 2),
        "global_5yr_survival_hla_e_only_pct": round(100.0 * overall_counts["hla_e_only_5yr_survival"] / total_n, 2),
        "global_5yr_survival_standardized_openislet_plan_a_pct": round(
            100.0 * overall_counts["standardized_plan_a_5yr_survival"] / total_n, 2
        ),
        "global_5yr_survival_personalized_dna_compiled_openislet_pct": round(
            100.0 * overall_counts["personalized_compiled_5yr_survival"] / total_n, 2
        ),
        "global_5yr_survival_ablated_compiler_control_pct": round(
            100.0 * overall_counts["ablated_compiler_control_5yr_survival"] / total_n, 2
        ),
        "global_analytic_expected_5yr_survival_standardized_plan_a_pct": round(analytic_standard_pct, 2),
        "global_analytic_expected_5yr_survival_personalized_compiled_pct": round(analytic_personalized_pct, 2),
        "global_analytic_expected_5yr_survival_ablated_arm1a_control_pct": round(100.0 * float(np.mean(all_abl_analytic)), 2),
        "analytic_max_ancestry_disparity_gap_personalized_pct_v80_065": round(analytic_gap_pct, 2),
        "sampled_max_ancestry_disparity_gap_personalized_pct": round(sampled_gap_pct, 2),
        "max_ancestry_disparity_gap_personalized_pct": round(sampled_gap_pct, 2),
        "deprecated_sampled_aliases": {"max_ancestry_disparity_gap_personalized_pct": "sampled_max_ancestry_disparity_gap_personalized_pct"},
        "ancestry_disparity_gap_methodology_note_v80_065": (
            f"The analytic primary model-implied ancestry gap is {analytic_gap_pct:.2f} pp before Bernoulli noise. "
            f"The sampled secondary gap is {sampled_gap_pct:.2f} pp in one seed=20261023 Bernoulli realization, "
            "N=2,000 per cohort. Legacy max_ancestry_disparity_gap_personalized_pct is a deprecated sampled alias."
        ),
        "editing_complexity_and_manufacturing_sensitivity_audit_v80_009": {
            "kb_edit_count_distribution_across_10000_patients": kb_counts,
            "conditional_on_release_qc_mean_personalized_survival_pct": pers_mean_4,
            "conditional_on_release_qc_mean_standardized_plan_a_survival_pct": std_mean_4,
            "bpr09_selected_physical_route_loading_audit": {
                "finding_id": "BPR-09",
                "decision_id": "DEC-133",
                "legacy_fixed_200cm2_mean_personalized_survival_pct": pers_mean_4,
                "selected_physical_route_mean_personalized_survival_pct": round(100.0 * float(np.mean(all_pers_selected_route_bpr09)), 4),
                "mean_delta_pp_selected_route_minus_legacy_fixed_200cm2": round(
                    100.0 * (float(np.mean(all_pers_selected_route_bpr09)) - float(np.mean(all_pers_analytic))), 4
                ),
                "min_individual_delta_pp": round(
                    100.0 * float(np.min(np.asarray(all_pers_selected_route_bpr09) - np.asarray(all_pers_analytic))), 4
                ),
                "max_individual_delta_pp": round(
                    100.0 * float(np.max(np.asarray(all_pers_selected_route_bpr09) - np.asarray(all_pers_analytic))), 4
                ),
                "do_not_adopt_delta_as_revised_patient_forecast": True,
                "provenance_note": (
                    "evaluate_regimen_survival_probability() defaults to loading_area_mode='selected_physical_route' "
                    "(scoring local loading against selected modular cassette area while preserving forced single-pouch 200 cm^2 stress "
                    "controls and exposing an optional total_burden_penalty_per_extra_100k_ieq hook). The legacy fixed-200 cm^2 "
                    "population replay (97.4963%) is retained above for provenance; the +0.0470 pp selected-route delta is a scorer "
                    "audit only and is NOT adopted as a revised clinical forecast."
                ),
            },
            "ranker_complexity_discounted_personalized_utility_pct": pers_disc_4,
            "ranker_complexity_discounted_standardized_plan_a_utility_pct": round(
                analytic_standard_pct * standard_discount, 4
            ),
            "unmaterialized_plan_b_without_cd47_hlae_mean_survival_pct": unmat_b_mean_pct,
            "unmaterialized_plan_b_complexity_discounted_mean_utility_pct": unmat_b_disc_pct,
            "unmaterialized_plan_b_minus_materialized_plan_b_prime_unpenalized_pp": round(unmat_b_mean_pct - pers_mean_4, 4),
            "unmaterialized_plan_b_minus_materialized_plan_b_prime_complexity_discounted_pp": round(unmat_b_disc_pct - pers_disc_4, 4),
            "unpenalized_plan_b_minus_discounted_plan_b_prime_cross_scale_delta_pp": round(unmat_b_mean_pct - pers_disc_4, 4),
            "unmaterialized_plan_b_minus_standardized_plan_a_pp": round(unmat_b_mean_pct - std_mean_4, 4),
            "unmaterialized_plan_b_complexity_discounted_minus_standardized_plan_a_pp": round(unmat_b_disc_pct - std_mean_4, 4),
            "engineering_utility_prior_parameters": engineering_parameters,
            "engineering_utility_prior_sensitivity": engineering_sensitivity,
            "four_corner_prior_box_vs_plan_a_comparison_sonnet55_r2": [
                {
                    "corner_label": f"lambda_K_{row['lambda_K']}_gamma_B_{row['gamma_B']}",
                    "lambda_K": row["lambda_K"],
                    "gamma_B": row["gamma_B"],
                    "personalized_discounted_utility_pct": row["ranker_complexity_discounted_personalized_utility_pct"],
                    "standardized_plan_a_k4_b0_discount_factor": round(
                        engineering_complexity_discount(4, 0, row["lambda_K"], row["gamma_B"]), 6
                    ),
                    "standardized_plan_a_discounted_utility_pct": round(
                        analytic_standard_pct * engineering_complexity_discount(4, 0, row["lambda_K"], row["gamma_B"]), 4
                    ),
                    "standardized_plan_a_if_k5_dual_safe_harbor_discounted_utility_pct": round(
                        analytic_standard_pct * engineering_complexity_discount(5, 0, row["lambda_K"], row["gamma_B"]), 4
                    ),
                    "personalized_minus_standardized_plan_a_pp": round(
                        row["ranker_complexity_discounted_personalized_utility_pct"]
                        - round(analytic_standard_pct * engineering_complexity_discount(4, 0, row["lambda_K"], row["gamma_B"]), 4),
                        4,
                    ),
                    "personalized_exceeds_standardized_plan_a": bool(
                        row["ranker_complexity_discounted_personalized_utility_pct"]
                        > round(analytic_standard_pct * engineering_complexity_discount(4, 0, row["lambda_K"], row["gamma_B"]), 4)
                    ),
                }
                for row in engineering_sensitivity
            ],
            "hla_c_allele_leader_peptide_and_nkg2a_kd_table_sonnet55_r2": [
                {
                    "hla_c_allele_or_group": "HLA-C*01:02, HLA-C*03:04 (Cw*0304), HLA-C*04:01 (Cw*0401), HLA-C*06:02, HLA-Cw*0302 (Lin et al. 2023 PMID:37264229 Table 1 & Supp Table 1)",
                    "leader_class": "SP-1C",
                    "leader_nonamer_p1_to_p9": "VMAPRTLIL",
                    "vales_gomez_1999_cd94_nkg2a_kd_uM": 7.35,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2a_kd_uM": 1.33,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2a_ci95_uM": [1.15, 1.53],
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2c_kd_uM": 4.35,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2c_ci95_uM": [4.24, 4.46],
                    "endogenous_hla_e_nkg2a_engageable": True,
                    "endogenous_hla_e_nkg2a_engageable_evidence_status": "DIRECT_SPR_MEASURED_VALES_GOMEZ_1999_TABLE1_AND_LIN_2023_SUPP_TABLE1",
                },
                {
                    "hla_c_allele_or_group": "HLA-Cw*0402 (HLA-C*04:02 rare P3-Glu variant)",
                    "leader_class": "Cw*0402_P3_Glu_variant",
                    "leader_nonamer_p1_to_p9": "VMEPRTLIL",
                    "vales_gomez_1999_cd94_nkg2a_kd_uM": None,
                    "vales_gomez_1999_cd94_nkg2a_kd_lower_bound_uM": ">= 75.30",
                    "endogenous_hla_e_nkg2a_engageable": False,
                    "endogenous_hla_e_nkg2a_engageable_evidence_status": "DIRECT_SPR_LOWER_BOUND_VALES_GOMEZ_1999_TABLE1",
                },
                {
                    "hla_c_allele_or_group": "HLA-C*02:02, HLA-C*15:02, HLA-C*15:05 (Lin et al. 2023 PMID:37264229 Table 1 & Supp Table 1; AUDIT-REF & AUDIT-REF)",
                    "leader_class": "SP-2C",
                    "leader_nonamer_p1_to_p9": "VMAPRTLLL",
                    "vales_gomez_1999_cd94_nkg2a_kd_uM": None,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2a_kd_uM": 1.70,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2a_ci95_uM": [1.50, 1.93],
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2c_kd_uM": 4.97,
                    "lin_2023_supp_table1_soluble_hlae0103_cd94_nkg2c_ci95_uM": [4.80, 5.14],
                    "endogenous_hla_e_nkg2a_engageable": True,
                    "endogenous_hla_e_nkg2a_engageable_evidence_status": "DIRECT_SOLUBLE_HLAE_SPR_LIN_2023_SUPP_TABLE1_P6_THR_P8_LEU_INTACT_SCT_UNMEASURED",
                },
                {
                    "hla_c_allele_or_group": "HLA-C*07:01, HLA-C*07:02 (UniProt P10321)",
                    "leader_class": "SP-3C",
                    "leader_nonamer_p1_to_p9": "VMAPRALLL",
                    "vales_gomez_1999_cd94_nkg2a_kd_uM": None,
                    "endogenous_hla_e_nkg2a_engageable": False,
                    "endogenous_hla_e_nkg2a_engageable_evidence_status": "FUNCTIONAL_DEFICIT_LIN_2023_PMID_37264229_TABLE1_P6_ALA_NO_NKG2A_ENGAGEMENT",
                },
            ],
            "sp3c_uncloaked_survival_penalty_sensitivity_grid_muse_r2": [
                {
                    "sp3c_uncloaked_survival_penalty": sp3c_pen,
                    "uncloaked_sp3c_cohort_mean_survival_delta_pp": round(100.0 * sp3c_pen, 4),
                    "active_plan_b_routed_patients_of_10000": total_plan_b_routed,
                    "population_10k_uncloaked_plan_b_mean_survival_pct": round(unmat_b_mean_pct + round(100.0 * sp3c_pen * plan_b_routed_frac, 4), 4),
                    "population_10k_uncloaked_plan_b_survival_delta_pp": round(100.0 * sp3c_pen * plan_b_routed_frac, 4),
                    "materialized_b_prime_hlae_sct_cloak_penalty_pp": 0.0,
                    "population_routing_assumption": f"CONDITIONAL_STRESS_SCENARIO_ALL_{total_plan_b_routed}_PLAN_B_ROUTED_PATIENTS_ASSIGNED_UNCLOAKED_SP3C",
                    "unmaterialized_product_contract_status": "HYPOTHETICAL_SCENARIO_ONLY_B_PRIME_REMAINS_NOT_MATERIALIZED_IN_PRODUCT_DEFINITIONS",
                    "product_contract_scope_kimi31_r3": {
                        "scenario_product": "UNMATERIALIZED_UNCLOAKED_PLAN_B_SP3C",
                        "scenario_status": "HYPOTHETICAL_STRESS_ONLY",
                        "materialized_comparator": "NONE_B_PRIME_CLOAK_NOT_MATERIALIZED_IN_PRODUCT_DEFINITIONS",
                        "hypothetical_cloaked_comparator": "PLAN_B_PRIME_HLAE_SCT_CLOAK_HYPOTHETICAL_NOT_MATERIALIZED",
                        "apply_penalty_to_materialized_b_prime": False,
                    },
                }
                for sp3c_pen in (-0.02, -0.04, -0.08, -0.15)
            ],
            "plan_b_kir_nk_threshold_sensitivity_sonnet55_r2": [
                {
                    "kir_nk_plan_b_routing_threshold": tau_kir,
                    "plan_b_routed_patients_of_10000": (
                        int(sum(1 for k_nk, _, _, _ in all_threshold_sensitivity_cases if k_nk >= tau_kir))
                        if _is_default_compiler
                        else total_plan_b_routed
                    ),
                    "analytic_personalized_mean_survival_pct": (
                        round(
                            100.0
                            * float(
                                np.mean(
                                    [
                                        p_pers_c if (k_nk >= tau_kir or k_nk < 0.48) else p_if_a_c
                                        for k_nk, p_pers_c, p_if_a_c, _ in all_threshold_sensitivity_cases
                                    ]
                                )
                            ),
                            4,
                        )
                        if _is_default_compiler
                        else pers_mean_4
                    ),
                    "complexity_discounted_personalized_utility_pct": (
                        round(
                            100.0
                            * float(
                                np.mean(
                                    [
                                        (p_pers_c if (k_nk >= tau_kir or k_nk < 0.48) else p_if_a_c)
                                        * engineering_complexity_discount(
                                            5 if k_nk >= tau_kir else 4,
                                            b_c,
                                            lambda_K=engineering_parameters["lambda_K"],
                                            gamma_B=engineering_parameters["gamma_B"],
                                        )
                                        for k_nk, p_pers_c, p_if_a_c, b_c in all_threshold_sensitivity_cases
                                    ]
                                )
                            ),
                            4,
                        )