OpenIslet

scripts/rank_islet1_stacks.py

Step 5 & 6: Project Islet-1 Sign-Sensitive, Endpoint-Oriented & Locus-Penalized Evaluator (v0.6.9).

script Release v0.8.0 gen-eb955f8266035aba 638 KB · 42 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/rank_islet1_stacks.py · SHA-256: c05d5fe606219e88…

                for it in items
            }

        rx = _avg_ranks_by_id(loaded_list)
        ry = _avg_ranks_by_id(zero_list)
        cids = list(rx.keys())
        mx = sum(rx[cid] for cid in cids) / len(cids)
        my = sum(ry[cid] for cid in cids) / len(cids)
        num = sum((rx[cid] - mx) * (ry[cid] - my) for cid in cids)
        den_x = math.sqrt(sum((rx[cid] - mx) ** 2 for cid in cids))
        den_y = math.sqrt(sum((ry[cid] - my) ** 2 for cid in cids))
        return num / (den_x * den_y) if (den_x > 0 and den_y > 0) else 1.0

    feasible_spearman_rho = _tie_aware_spearman_from_scores(feasible_combos, feas_zero_list)
    k4b0_spearman_rho = _tie_aware_spearman_from_scores(k4b0_loaded_list, k4b0_zero_list)

    oat_prior_tornado = {}
    for pk, pmeta in orig_priors.items():
        lo_v, hi_v = float(pmeta["plausible_range"][0]), float(pmeta["plausible_range"][1])
        ENGINEERING_PRIORS_AND_SENSITIVITY_TABLE[pk]["point_estimate"] = lo_v
        lo_map = {c["combination_id"]: c for c in run_combinatorial_multi_gate_search(target_profiles)}
        ENGINEERING_PRIORS_AND_SENSITIVITY_TABLE[pk]["point_estimate"] = hi_v
        hi_map = {c["combination_id"]: c for c in run_combinatorial_multi_gate_search(target_profiles)}
        ENGINEERING_PRIORS_AND_SENSITIVITY_TABLE[pk]["point_estimate"] = pmeta["point_estimate"]
        oat_prior_tornado[pk] = {
            "plausible_range": [lo_v, hi_v],
            "point_estimate": float(pmeta["point_estimate"]),
            "scenario_a_rank_at_low": lo_map[chassis_a_id]["global_rank_among_all_combinations"],
            "scenario_a_rank_at_high": hi_map[chassis_a_id]["global_rank_among_all_combinations"],
            "scenario_a_composite_at_low": lo_map[chassis_a_id]["composite_series_system_utility"],
            "scenario_a_composite_at_high": hi_map[chassis_a_id]["composite_series_system_utility"],
            "scenario_a_composite_swing": round(
                hi_map[chassis_a_id]["composite_series_system_utility"] - lo_map[chassis_a_id]["composite_series_system_utility"], 4
            ),
            "scenario_b_rank_at_low": lo_map[chassis_b_id]["global_rank_among_all_combinations"],
            "scenario_b_rank_at_high": hi_map[chassis_b_id]["global_rank_among_all_combinations"],
            "scenario_b_composite_at_low": lo_map[chassis_b_id]["composite_series_system_utility"],
            "scenario_b_composite_at_high": hi_map[chassis_b_id]["composite_series_system_utility"],
            "scenario_b_composite_swing": round(
                hi_map[chassis_b_id]["composite_series_system_utility"] - lo_map[chassis_b_id]["composite_series_system_utility"], 4
            ),
            "scenario_a_remains_rank1_at_both_bounds": (
                lo_map[chassis_a_id]["global_rank_among_all_combinations"] == 1
                and hi_map[chassis_a_id]["global_rank_among_all_combinations"] == 1
            ),
        }
    orig_pw_ent = copy.deepcopy(COMPLETE_GATE_COEFFICIENT_REGISTRY.get("pw_base_scale", {"logit_value": 0.08, "plausible_range": [0.05, 0.12]}))
    orig_pw = float(orig_pw_ent.get("logit_value", 0.08)) if isinstance(orig_pw_ent, dict) else float(orig_pw_ent)
    pw_range = list(orig_pw_ent.get("plausible_range", [0.05, 0.12])) if isinstance(orig_pw_ent, dict) else [0.05, 0.12]
    if isinstance(COMPLETE_GATE_COEFFICIENT_REGISTRY.get("pw_base_scale"), dict):
        COMPLETE_GATE_COEFFICIENT_REGISTRY["pw_base_scale"]["logit_value"] = float(pw_range[0])
    else:
        COMPLETE_GATE_COEFFICIENT_REGISTRY["pw_base_scale"] = float(pw_range[0])
    lo_pw_map = {c["combination_id"]: c for c in run_combinatorial_multi_gate_search(target_profiles)}
    if isinstance(COMPLETE_GATE_COEFFICIENT_REGISTRY.get("pw_base_scale"), dict):
        COMPLETE_GATE_COEFFICIENT_REGISTRY["pw_base_scale"]["logit_value"] = float(pw_range[1])
    else:
        COMPLETE_GATE_COEFFICIENT_REGISTRY["pw_base_scale"] = float(pw_range[1])
    hi_pw_map = {c["combination_id"]: c for c in run_combinatorial_multi_gate_search(target_profiles)}
    COMPLETE_GATE_COEFFICIENT_REGISTRY["pw_base_scale"] = orig_pw_ent
    oat_prior_tornado["pw_base_scale"] = {
        "plausible_range": pw_range,
        "point_estimate": orig_pw,
        "scenario_a_rank_at_low": lo_pw_map[chassis_a_id]["global_rank_among_all_combinations"],
        "scenario_a_rank_at_high": hi_pw_map[chassis_a_id]["global_rank_among_all_combinations"],
        "scenario_a_composite_at_low": lo_pw_map[chassis_a_id]["composite_series_system_utility"],
        "scenario_a_composite_at_high": hi_pw_map[chassis_a_id]["composite_series_system_utility"],
        "scenario_a_composite_swing": round(
            hi_pw_map[chassis_a_id]["composite_series_system_utility"] - lo_pw_map[chassis_a_id]["composite_series_system_utility"], 4
        ),
        "scenario_b_rank_at_low": lo_pw_map[chassis_b_id]["global_rank_among_all_combinations"],
        "scenario_b_rank_at_high": hi_pw_map[chassis_b_id]["global_rank_among_all_combinations"],
        "scenario_b_composite_at_low": lo_pw_map[chassis_b_id]["composite_series_system_utility"],
        "scenario_b_composite_at_high": hi_pw_map[chassis_b_id]["composite_series_system_utility"],
        "scenario_b_composite_swing": round(
            hi_pw_map[chassis_b_id]["composite_series_system_utility"] - lo_pw_map[chassis_b_id]["composite_series_system_utility"], 4
        ),
        "scenario_a_remains_rank1_at_both_bounds": (
            lo_pw_map[chassis_a_id]["global_rank_among_all_combinations"] == 1
            and hi_pw_map[chassis_a_id]["global_rank_among_all_combinations"] == 1
        ),
    }

    top10_loaded = [c["combination_id"] for c in all_combos[:10]]
    top10_zero = [c["combination_id"] for c in zero_combos[:10]]
    top10_overlap = len(set(top10_loaded) & set(top10_zero))
    top10_exact_order_matches = sum(1 for a, b in zip(top10_loaded, top10_zero) if a == b)

    return {
        "methodology_note": (
            "Explicit variance decomposition across the uniform 2,160-stack grid (six pooled pediatric gate logits, "
            "comparing loaded empirical gene-signal channels against all three gene-signal channels zeroed), "
            "independent per-stack output-logit perturbation sensitivity, correlated shared-parameter registry "
            "Monte Carlo sensitivity (perturbing COMPLETE_GATE_COEFFICIENT_REGISTRY and lambda_K/gamma_B once per draw "
            "so all stacks sharing a module shift together), and deterministic One-at-a-Time (OAT) plausible-range prior "
            "tornado diagnostics across all 6 structural priors + pw_base_scale. Also reports exact top-10 membership overlap when all "
            "empirical gene signals are zeroed (F-04: structural priors and Graveyard rules determine macro-tier "
            "membership, whereas empirical gene signals act as local within-tier tie-breakers)."
        ),
        "engineering_priors_plausible_range_tornado_diagnostics": oat_prior_tornado,
        "uniform_grid_pooled_pediatric_gate_logit_variance_decomposition": {
            "design": "Uniform 2,160-stack grid, 6 pooled pediatric gate logits (12,960 gate-logit evaluations), all gene-signal channels zeroed vs loaded",
            "var_structural_priors": round(vs, 6),
            "var_empirical_gene_signal_delta": round(ve, 6),
            "var_empirical_gene_signal_delta_corpus_only": round(ve_corpus, 6),
            "var_empirical_gene_signal_delta_omics_only": round(ve_omics, 6),
            "twice_covariance": round(2.0 * cov_se, 6),
            "var_total": round(vt, 6),
            "structural_share_of_component_variance_sum": round(vs / (vs + ve), 6),
            "empirical_gene_signal_share_of_component_variance_sum": round(ve / (vs + ve), 6),
            "empirical_corpus_only_share_of_component_variance_sum": round(ve_corpus / (vs + ve_corpus), 6),
            "empirical_omics_only_share_of_component_variance_sum": round(ve_omics / (vs + ve_omics), 6),
            "structural_share_of_total_variance": round(vs / vt, 6),
            "empirical_gene_signal_share_of_total_variance": round(ve / vt, 6),
            "twice_covariance_share_of_total_variance": round((2.0 * cov_se) / vt, 6),
            "top10_membership_overlap_loaded_vs_zero_gene_signal": f"{top10_overlap} / 10",
            "top10_exact_rank_matches_loaded_vs_zero_gene_signal": f"{top10_exact_order_matches} / 10",
        },
        "feasible_subset_and_within_top_tier_variance_decomposition_sol_v80_r2_14": {
            "feasible_subset_n_stacks": len(feasible_combos),
            "feasible_var_structural_priors": round(vs_feas, 6),
            "feasible_var_empirical_gene_signal_delta": round(ve_feas, 6),
            "feasible_var_total": round(vt_feas, 6),
            "feasible_structural_share_of_component_variance_sum": round(vs_feas / (vs_feas + ve_feas), 6),
            "feasible_empirical_share_of_component_variance_sum": round(ve_feas / (vs_feas + ve_feas), 6),
            "feasible_structural_share_of_total_variance": round(vs_feas / vt_feas, 6),
            "feasible_spearman_rho_loaded_vs_zero_gene_signal": round(feasible_spearman_rho, 6),
            "top25_membership_overlap_loaded_vs_zero_gene_signal": f"{top25_overlap} / 25",
            "top50_membership_overlap_loaded_vs_zero_gene_signal": f"{top50_overlap} / 50",
            "top_tier_code_defined_n_stacks": len(top_tier_actual_logits) // 6,
            "top_tier_var_structural_priors": round(vs_top, 6),
            "top_tier_var_empirical_gene_signal_delta": round(ve_top, 6),
            "top_tier_twice_covariance": round(vt_top - vs_top - ve_top, 6),
            "top_tier_var_total": round(vt_top, 6),
            "top_tier_structural_share_of_component_variance_sum": round(vs_top / (vs_top + ve_top), 6),
            "top_tier_empirical_share_of_component_variance_sum": round(ve_top / (vs_top + ve_top), 6),
            "top_tier_structural_share_of_total_variance": round(vs_top / vt_top, 6),
            "feasible_k4_b0_n_stacks": len(k4b0_loaded_list),
            "feasible_k4_b0_var_structural_priors": round(vs_k4, 6),
            "feasible_k4_b0_var_empirical_gene_signal_delta": round(ve_k4, 6),
            "feasible_k4_b0_twice_covariance": round(vt_k4 - vs_k4 - ve_k4, 6),
            "feasible_k4_b0_var_total": round(vt_k4, 6),
            "feasible_k4_b0_structural_share_of_component_variance_sum": round(vs_k4 / (vs_k4 + ve_k4), 6),
            "feasible_k4_b0_empirical_share_of_component_variance_sum": round(ve_k4 / (vs_k4 + ve_k4), 6),
            "feasible_k4_b0_structural_share_of_total_variance": round(vs_k4 / vt_k4, 6),
            "feasible_k4_b0_spearman_rho_loaded_vs_zero_gene_signal": round(k4b0_spearman_rho, 6),
        },
        "direct_output_gate_logit_perturbation_monte_carlo": mc_results,
        "shared_parameter_registry_monte_carlo": shared_param_mc,
    }


CANDIDATE_ARCHITECTURES = [
    {
        "architecture_id": "ISLET1_CHASSIS_A_UNIVERSAL_LEAN_4LOCUS",
        "name": "Islet-1 Universal Chassis A ('Lean 4-Locus Swap-In Core + Biallelic AAVS1-[455bp HNRNPA2B1-proximal candidate (legacy CBX3-A2UCOE)]-EEF1A1-core-iCasp9')",
        "matched_combinatorial_search_id": (
            "ALLO_B2M_HLAE_CD47_SWAP_CIITA_KO__AUTO_NONE__"
            "CYTO_CXCL10_SWAP_PDL1_SERPINB9__ER_NONE__"
            "NICHE_TRIHORMONAL_120UM_MVF_CAO2__SAF_AAVS1_CAG_ICASP9_BIALLELIC"
        ),
        "genomic_locus_edit_count_K": 4,
        "base_edit_count_B": 0,
        "graveyard_warn_reconciliation_note": (
            "Triggers GRAVEYARD_009 (WARN: resting Hour-0 B2M-locus surface density deficit across materialized internal promoters [Arm 1B/A* Syn_5xISRE_minP HLA-E resting prior < 15,000 + EEF1A1-core CD47 silencing risk; Arm 1A EEF1A1-core 2A] and unmaterialized endogenous-B2M comparators; IIP-0048) and GRAVEYARD_010 "
            "(WARN: MHC-null indirect APC bystander blindspot). In the evaluator, WARN rules apply pre-registered "
            "quantitative logit discounts (-0.20 in Gate 3 for GRAVEYARD_009; -0.25 in Gate 2B for GRAVEYARD_010) "
            "and attach mandatory Stage-0/Stage-1 Go/No-Go decision gates (Decision Experiment #1 QuantiBRITE flow + "
            "Arm 1B 2A-free bidirectional comparison; Decision Experiment #2 HLA-DQ2/DQ8 DC indirect presentation & "
            "incremental SA-FasL Delta_TUNEL+ <= +5.0 pp screen) without hard-zeroing the stack (Finding 040)."
        ),
        "locus1_and_locus4_engineering_audit_notes": {
            "locus1_arm1a_vs_arm1b_donor_size_and_delivery": (
                "Arm 1A bicistronic donor (4,880 bp donor / 5,170 bp with ITRs) exceeds the 4,700 bp single-AAV6 packaging limit "
                "and requires non-viral linear dsDNA/ceDNA HDR or Bridge-RNA recombinase (PMID:36008610, PMID:38926615, PMID:41642947) "
                "while leaving a 21-aa cytosolic -GSG-P2A tail on HLA-E*01:03; Arm 1B scarless 2A-free bidirectional cassette "
                "[SV40pA-CD47-IgV-GPI(antisense) <- EEF1A1-core | Syn_5xISRE_minP -> HLA-E*01:03(VMAPRTLVL)-bGHpA] is 3,974 bp donor / "
                "4,264 bp with ITRs (+436 bp headroom below the 4,700 bp single-AAV6 limit) and eliminates all 2A peptide tails (Findings 075, 076, 077)."
            ),
            "hla_e_vmaprtlvl_hcmv_ul40_and_kw_motif_note": (
                "VMAPRTLVL matches the HLA-A*02:01 leader and has ~12% sequence overlap with clinical HCMV UL40 isolates (vs ~43% for VMAPRTLIL; "
                "Lin et al. 2023 PMID:37264229), reducing but not eliminating NKG2C+ adaptive NK recognition in HCMV-seropositive recipients; "
                "Stage-0 Decision Experiment #1 compares WT HLA-E*01:03(VMAPRTLVL) against cytoplasmic tail KW-motif retention-signal removal "
                "(He et al. 2025 PMC12582296) across HCMV+ NKG2C+ and NKG2A- KIR2DL1/2/3+ primary NK donors (Finding 078)."
            ),
            "cd47_igv_gpi_vs_dct_ectodomain_note": (
                "CD47-IgV-GPI was evaluated in non-islet systems (human Jurkat/macrophage phagocytosis, murine A20 lymphoma, murine C57BL/6 LSK hematopoietic stem/progenitor cell competitive repopulation, and human EA.hy926 endothelial tube-formation plus 10-day NCG Matrigel-plug angiogenesis assays; Xu et al. 2024 Cell Rep Med PMID:38508139, PMC10983038; reclassified to Tier_2B under IIP-0008 / DEC-086) rather than mature beta-cells or HUVECs; "
                "Stage-0 Decision Experiment #1 compares CD47-IgV-GPI against cytoplasmically truncated transmembrane CD47-dCT and full-length "
                "CD47-WT (OA3-323; Ghimire et al. 2023 PMID:37820008 Cdc42/GSIS counter-evidence) for GPI-PLC sensitivity, anti-CD47 QuantiBRITE density (clone B6H12 in Stage 0 vs Hu et al. 2023 PMID:37156915 clone CC2C6 + BD Quantibrite calibration, OQ-008), "
                "and dynamic perifusion GSIS (Finding 079)."
            ),
            "sa_fasl_sa_thbd_immunosuppression_and_fratricide_note": (
                "Published murine and NHP SA-FasL PEG-microgel studies (Headen et al. 2018 PMID:29867165; Lei et al. 2022 PMID:35559682) included transient short-course "
                "rapamycin, whereas Turan et al. 2024 (PMID:38709159) evaluated direct islet surface biotinylation co-displaying SA-THBD (SA-TM) and SA-CD47 in a murine syngeneic intraportal IBMIR/engraftment model without rapamycin and Kazmi et al. 2026 (PMID:41842939) demonstrated immunosuppression-free murine BALB/c->C57BL/6 intraportal allograft survival with "
                "direct surface SA-THBD + SA-CD47 (without SA-FasL, PEG microgels, or rapamycin); because IL-1beta sensitizes human beta-cells to Fas (CD95) apoptosis (Loweth et al. 1998 PMID:9588443), "
                "Decision Experiment #2 enforces an incremental fratricide kill gate of Delta_TUNEL+ <= +5.0 pp above cytokine-matched SA-THBD-only control AND anti-Fas ZB4 mAb rescue <= 5.0 pp (Finding 080; L3B-01/02/03 [DEC-077])."
            ),
            "locus4_a2ucoe_xiap_and_smac_salvage_note": (
                "Locus 4 uses the 455 bp HNRNPA2B1-proximal candidate (legacy CBX3-A2UCOE alias; insulation function pending) + 250 bp cHS4 insulator driving the 230 bp human EEF1A1 core promoter "
                "(3,457 bp donor / 3,747 bp with ITRs <= 4,700 bp single-AAV6 limit; PMID:25605798, PMID:28860464, PMID:23307570, PMID:26455413). "
                "Because hypoxia/cytokines upregulate XIAP (BIRC4), which inhibits processed Caspase-9 via its BIR3 domain (Srinivasula et al. 2001 PMID:11242052), "
                "Decision Experiment #4 evaluates an unvalidated preclinical salvage hypothesis of co-dosing AP1903 with an IAP antagonist "
                "(IV birinapant [PMC4742409] or oral xevinapant [noting Phase III TrilynX termination, doi:10.1200/JCO-25-00272]) (Findings 081, 086)."
            ),
            "step1_step2_sequential_editing_and_biallelic_hdr_yield_note": (
                "Sequential 2-step editing (<=2 loci/step) with orthogonal nucleases (HiFi-SpCas9 + AsCas12a Ultra) and transient i53/RAD51 mRNA "
                "targets ~25-40% single-locus biallelic HDR (~6-16% dual-locus biallelic clone yield per step across 96-384 screened clones; "
                "Schiroli et al. 2019 PMID:30905619; Kosicki et al. 2018 PMID:30010673; Turchiano et al. 2021 PMID:33626327). "
                "In Step 2, targeting Locus 3 (CXCL10, Chr4q21) and Locus 4 (AAVS1, Chr19q13.42) yields N_effective = 2 simultaneously cleaved "
                "chromosomal loci (1 heterotypic locus pair), or N_total = 4 diploid alleles (6 allele pairs: 4 inter-chromosomal + 2 homologous sister/homolog pairs) (Findings 028, 082)."
            ),
        },
        "edit_stack_specification": [
            {
                "locus": 1,
                "edit": "B2M-ISRE::[EEF1A1-core + chimeric intron]-HLA-E*01:03(VMAPRTLVL)-GSG-P2A-CD47-IgV-GPI-WPREmut6 (or Stage-0 Pre-Pilot Scarless 2A-Free Bidirectional Arm 1B; Endogenous B2M exon 1 knock-in)",