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…

                "Route-2 D1 rows are hypothetical class-level compatibility scenarios outside the currently registered ROUTE_3P_MODULAR_PLANAR_ENVELOPE product definitions."
            ),
            "live_3x2_baseline_invariant": base_iip0034["live_3x2_baseline_invariant"],
            "global_access_positioning": {
                "primary_global_access_backbone": "Universal off-the-shelf allogeneic Designs A, B, X + Design Y-FullStack v2 (IIP-0034)",
                "autologous_d1b_auto_c_v2_role": "Orthogonal high-PRA (>80%) / allo-refractory rescue & modeled partial H2-diversification clinical vanguard 5th arm",
                "modeled_n1_gmp_turnaround_weeks_target": [29, 41],
                "modeled_firstgen_cmc_p1_screened_assumption": 0.62,
                "modeled_firstgen_cmc_p1_itt_assumption": 0.55,
                "modeled_mature_closed_system_cmc_p1_target": 0.70,
                "standalone_4arm_verdict_at_p1_0p62": "HONEST_FAIL_STANDALONE (56.71-57.36% locked < 57.92%; continuous break-even p1*=0.672989 at phi=0.25 and 0.746615 at phi=0.50)",
                "unified_5arm_verdict_registered_route_only_locked": (
                    "MIXED_REGISTERED_ROUTE_ONLY (registered ROUTE_3P rows W_U1..W_U4, W_U6, W_U10..W_U12 clear 57.92%: "
                    "60.05-61.04% locked at p1=0.70, 59.15-60.64% at p1=0.62 [W_U3 60.64%, W_U4 59.69%, W_U6 stress 59.15%], "
                    "62.60-63.41% nested; hypothetical Route-2 D1 rows W_U5/W_U7/W_U8/W_U9 FAIL registered-route locked at "
                    "56.48/56.17/56.17/55.98%, equaling matched A/B/X/Y with D1 excluded)"
                ),
                "unified_5arm_verdict_class_level_route_transfer": (
                    "HYPOTHETICAL_CLASS_LEVEL_TRANSFER_PASS_FOR_PHIC_LE_0P50 (requires unverified Route-2 transfer outside registered "
                    "ROUTE_3P product contracts: 58.35% on W_U8 [phi_YX=0.75, phi_C=0.50] and 58.19% on W_U9 [phi_YX=1.00, phi_C=0.50]; "
                    "crosses below 57.917640% at phi_C~0.603731 [57.8614% at phi_C=0.625, 57.6628% at phi_C=0.70] on W_U9)"
                ),
            },
            "stage0_gated_4arm_autologous_d1b_auto_v2": wavec_4arm,
            "stage0_gated_5arm_unified_waveBC_portfolio": wavebc_5arm,
            "stage0_gated_5arm_phi_c_sensitivity_counterexamples": phi_c_counterexamples,
            "autologous_p1_breakeven_sweep": p1_sweep,
            "autologous_p1_continuous_breakeven_exact": {
                "target_shared_ceiling_pct": round(c0 * 100.0, 6),
                "phi_0p25_p1_star": p1_star_25,
                "phi_0p25_first_passing_grid_point": first_pass_25,
                "phi_0p50_p1_star": p1_star_50,
                "phi_0p50_first_passing_grid_point": first_pass_50,
                "note": "Exact continuous affine zero-crossings under the 4-arm D1b@R3P (c4u=0.92, p2=0.92, p3=0.70, p4=0.70) model; first_passing_grid_point values are derived directly from autologous_p1_breakeven_sweep.",
            },
            "scenario_alias_deduplication_map": {
                "total_labeled_core_rows_across_iip0034_and_iip0035": unrounded_check["total_labeled_core_rows"],
                "distinct_core_scenario_laws": unrounded_check["distinct_core_scenario_laws"],
                "alias_full_joint_state_max_abs_diff": unrounded_check["alias_full_joint_state_max_abs_diff"],
                "alias_verification_space": "full_unrounded_2pow4n_joint_states_1048576_max_abs_diff_le_1e_12",
                "repeated_bridge_aliases": repeated_aliases,
                "note": "Joins the 5 frozen IIP-0034 bridge rows (W_BC1..W_BC5) 1-to-1 by exact scenario ID to W_U1, W_U2, W_U8, W_U11, and W_U12 across all 1,048,576 unrounded 2^(4N) joint states (max_abs_diff <= 1e-12) with exact equivalence-partition verification and dynamic distinct_core_scenario_laws.",
            },
        }
    finally:
        _ACTIVE_LAW_COLLECTOR_IIP0035.reset(_law_token)


def main() -> None:
    graph, studies, omics = load_inputs()
    target_profiles = build_target_evidence_profiles(studies, omics)
    all_combos = run_combinatorial_multi_gate_search(target_profiles)
    combo_by_id = {c["combination_id"]: c for c in all_combos}

    # Build Pareto frontier by chromosomal locus budget K strictly over feasible (non-BLOCKed) stacks, and also track clinically switched B<=1 candidates (AUDIT-REF; DEC-049):
    pareto_by_k = {}
    clinical_switched_pareto_by_k = {}
    for c in all_combos:
        if not c.get("is_feasible_candidate", True):
            continue
        k = c["total_genomic_cuts_K"]
        if k not in pareto_by_k or c["composite_series_system_utility"] > pareto_by_k[k]["composite_series_system_utility"]:
            pareto_by_k[k] = {
                "total_genomic_cuts_K": k,
                "total_base_edits_B": c["total_base_edits_B"],
                "best_combination_id": c["combination_id"],
                "composite_series_system_utility": c["composite_series_system_utility"],
                "global_rank_among_all_combinations": c["global_rank_among_all_combinations"],
                "unswitched_immune_evasive_clinical_hold": c.get("unswitched_immune_evasive_clinical_hold", False),
            }
        if not c.get("unswitched_immune_evasive_clinical_hold", False) and not c.get("multiplex_base_edit_plus_dsb_translocation_risk_flag", False):
            if k not in clinical_switched_pareto_by_k or c["composite_series_system_utility"] > clinical_switched_pareto_by_k[k]["composite_series_system_utility"]:
                clinical_switched_pareto_by_k[k] = c
    for k, p_row in pareto_by_k.items():
        cs = clinical_switched_pareto_by_k.get(k)
        p_row["clinical_switched_best_combination_id"] = cs["combination_id"] if cs else None
        p_row["clinical_switched_composite_series_system_utility"] = cs["composite_series_system_utility"] if cs else None
        p_row["clinical_switched_global_rank"] = cs["global_rank_among_all_combinations"] if cs else None

    ranked_architectures = []
    for arch in CANDIDATE_ARCHITECTURES:
        cid = arch["matched_combinatorial_search_id"]
        c = combo_by_id[cid]
        if c["total_genomic_cuts_K"] != arch["genomic_locus_edit_count_K"]:
            raise ValueError(
            f"Cut count mismatch for {arch['architecture_id']}: "
            f"{c['total_genomic_cuts_K']} vs {arch['genomic_locus_edit_count_K']}"
        )
        if c["total_base_edits_B"] != arch["base_edit_count_B"]:
            raise ValueError(
            f"Base-edit count mismatch for {arch['architecture_id']}: "
            f"{c['total_base_edits_B']} vs {arch['base_edit_count_B']}"
        )
        arch_out = dict(arch)
        product_id = {"ISLET1_CHASSIS_A_UNIVERSAL_LEAN_4LOCUS": "ISLET1_A4_ARM1B",
                      "ISLET1_CHASSIS_B_HLA_C_RETAINED_6LOCUS_HYPOTHESIS": "ISLET1_B1_6LOCUS_TYK2_KO_INS"}.get(arch["architecture_id"])
        if product_id:
            contract = _load_local_helper("product_contract").get_product_definition(product_id, root=PROJECT_ROOT)
            if contract["K"] != c["total_genomic_cuts_K"] or contract["B"] != c["total_base_edits_B"]:
                raise ValueError(f"Product contract K/B mismatch for {product_id}")
            arch_out["product_definition"] = contract
        arch_out["is_feasible_candidate"] = c["is_feasible_candidate"]
        arch_out["unblocked_diagnostic_utility"] = c["unblocked_diagnostic_utility"]
        arch_out["global_rank_among_all_combinations"] = c["global_rank_among_all_combinations"]
        arch_out["utility_pediatric_early_onset_t1d"] = c["utility_pediatric_early_onset_t1d"]
        arch_out["utility_adult_onset_lada"] = c["utility_adult_onset_lada"]
        arch_out["composite_series_system_utility"] = c["composite_series_system_utility"]
        arch_out["search_grid_lower_10pct_cred_bound_pediatric"] = c["utility_pediatric_early_onset_t1d"]["lower_10pct_cred_bound"]
        arch_out["lower_10pct_cred_bound_with_b_edit_quadratic_discount_pediatric"] = c["utility_pediatric_early_onset_t1d"]["lower_10pct_cred_bound_with_b_edit_quadratic_discount"]
        arch_out["triggered_graveyard_rules"] = c["triggered_graveyard_rules"]
        ranked_architectures.append(arch_out)

    ranked_architectures.sort(
        key=lambda a: (
            a["is_feasible_candidate"],
            a["composite_series_system_utility"],
            a["unblocked_diagnostic_utility"],
        ),
        reverse=True,
    )
    for idx, a in enumerate(ranked_architectures, 1):
        a["rank_among_6_named_architectures"] = idx

    # Build the explicit 36-run HIP-Core Wet-Lab Protocol (all design algebra below is computed exactly from this run table):
    # - Tier-1: 16-Run 2^(6-2) Resolution IV Screening Block (Runs 01-16, rank 14/22)
    # - Tier-2: 20-Run Bridge + Replicated De-Aliasing + Lead-Chassis Confirmatory Block (Runs 17-36):
    #   * Runs 17-24: 8 De-Aliasing Runs (Replicate A; Run 17 is the LEGACY lean chassis with the endogenous B2M-promoter bicistronic CD47 of Locus 1, X2 = -1)
    #   * Runs 25-26: 2 Tier-1 Bridge Reference Controls (repeating Tier-1 Run 01 [-1,-1,-1,-1,-1,-1] and Run 16 [+1,+1,+1,+1,+1,+1] inside Tier-2 so rank([X | B]) = 23/23)
    #   * Runs 27-34: 8 Replicated Tier-2 De-Aliasing Runs (Replicate B, eliminating all unit-leverage h_ii = 1.0 rows)
    #   * Runs 35-36: 2 Lead-Chassis-A confirmatory replicates (current Scenario A genotype [+1,+1,+1,-1,-1,-1]: constitutive hEF1a-core CD47 package X2 = +1), which the
    #     34-run design never built (its prediction variance at that genotype was 33/7 to 47/7 sigma^2) and which roughly halve the worst-case 2FI variance multiplier
    factor_defs = {
        "X1": {
            "symbol": "A",
            "name": "Primary_MHC_I_Missing_Self_Element",
            "gate": "Gate_2A_3_Allo_and_NK_Missing_Self",
            "factor_class": "Single_Locus_Allelic_Comparison (see locus1_x1_by_x2_physical_construct_matrix for exact 4-cell monocistronic vs bicistronic physical cassette mapping)",
            "level_minus1": "B2M-/- monocistronic CD47 knock-in without HLA-E (LOC1_X1M_X2M_B2M_CD47WT_MONOCISTRONIC when X2=-1; LOC1_X1M_X2P_HEF1A_CD47GPI_MONOCISTRONIC when X2=+1; NO orphan 2A tag)",
            "level_plus1": "B2M::HLA-E*01:03(VMAPRTLVL)-GSG-tPT2A-CD47 bicistronic exon 1 knock-in (LOC1_X1P_X2M_B2M_HLAE_TPT2A_CD47WT_BICISTRONIC when X2=-1; LOC1_X1P_X2P_HEF1A_HLAE_TPT2A_CD47GPI_BICISTRONIC when X2=+1; PMID:28504668, PMID:39621955; ~12% overlap with clinical HCMV UL40 isolates in PMID:37264229; cytoplasmic KW-motif and 2A-free bidirectional cassette evaluated in Stage-0 Pre-Pilot)",
        },
        "X2": {
            "symbol": "B",
            "name": "CD47_Promoter_and_Ectodomain_Package",
            "gate": "Gate_3_Innate_NK_Macrophage_Hour0_Stoichiometry",
            "factor_class": "Composite_Engineering_Package (strictly locked to one pre-registered construct per (X1, X2) cell in locus1_x1_by_x2_physical_construct_matrix; single-component Promoter-Only vs Ectodomain-Only [CD47-IgV-GPI vs CD47-dCT vs CD47-WT] and 2A-free bidirectional controls run in Stage-0 Decision Experiment #1)",
            "level_minus1": "Endogenous resting B2M-promoter driving full-length CD47-WT (monocistronic Kozak-ATG-CD47-WT when X1=-1; bicistronic -GSG-tPT2A-CD47-WT when X1=+1; tests Graveyard 009 Hour-0 basal density deficit and full-length CD47-WT Cdc42/GSIS signaling; PMID:37156915, PMID:37820008)",
            "level_plus1": "Locked High-Floor Constitutive/Synthetic Promoter [native human EEF1A1-core (230 bp, 19 CpGs, 60.0% GC) + chimeric intron] driving GPI-anchored CD47-IgV-GPI(DAF) (monocistronic Kozak-ATG-CD47-IgV-GPI-WPREmut6 when X1=-1; bicistronic 3'-cistron -GSG-tPT2A-CD47-IgV-GPI-WPREmut6 when X1=+1; pre-registered uniform amendment rule: if Stage-0 GPI-PLC/QuantiBRITE gate fails, all 13 X2=+1 runs across the 36-run table [8 in Tier-1, 1 in Run 26 bridge, 2 in Runs 24/34, 2 in Runs 35/36] uniformly substitute CD47-dCT prior to Stage-1 initiation; Xu et al. 2024 PMID:38508139, PMID:40668892, PMID:30778232)",
        },
        "X3": {
            "symbol": "C",
            "name": "Locus3_Chemokine_KO_and_Inducible_Shield_Package",
            "gate": "Gate_2B_3_Cytokine_and_Granzyme_B_Shield",
            "factor_class": "Composite_Single_Locus_Swap_Package (locked to the single inverted-cistron construct CXCL10::SERPINB9-GSG-tPT2A-PD-L1 in the 36-run factorial; CXCL10-/- empty-KO vs PD-L1-only vs SERPINB9-only and PD-L1-GSG-tPT2A-SERPINB9 orientation controls run in the Stage-0 Pre-Pilot / Decision Experiment #3)",
            "level_minus1": "Wild-type CXCL10 locus (no PD-L1 or SERPINB9 knock-in)",
            "level_plus1": "Locked CXCL10::SERPINB9-GSG-tPT2A-PD-L1 biallelic swap-in (deletes graft CXCL10 + expresses cytosolic SERPINB9 5'-upstream of tPT2A and untagged C-terminal PD-L1 3'-downstream; PMID:36055241, PMID:19641142, PMID:32814902, PMID:30269996, PMID:28526819, PMID:30952982)",
        },
        "X4": {
            "symbol": "D",
            "name": "TYK2_Intracellular_IFN_Signal_Dampening",
            "gate": "Gate_2B_Autoimmune_IFN_Axis_and_Stage0_Yield_Gate",
            "factor_class": "Single_Locus_Knockout (evaluated alongside Stage 6/7 post-endocrine inducible TYK2 degrader / allosteric TYK2i BMS-986165 satellite control to separate developmental KRAS/EP defect from mature beta-cell IFN-alpha protection; PMID:36289205)",
            "level_minus1": "TYK2+/+ (wild-type TYK2 preserving full Stage 0->7 endocrine differentiation yield and IFN/STAT1 promoter induction)",
            "level_plus1": "TYK2-/- (constitutive biallelic knockout dampening IFN-alpha/IL-12/IL-23 signaling while measuring Stage 0->7 monohormonal INS+ yield penalty; Chandra et al. 2022 PMID:36289205)",
        },
        "X5": {
            "symbol": "E",
            "generator_tier1": "X5 = X1 * X2 * X3",
            "name": "TXNIP_Oxidative_Stress_Shield",
            "gate": "Gate_1_Metabolic_Oxidative_Survival",
            "factor_class": "Single_Locus_Knockout",
            "level_minus1": "TXNIP+/+ (wild-type TXNIP)",
            "level_plus1": "TXNIP-/- (biallelic thioredoxin-interacting protein knockout protecting against glucotoxic/oxidative beta-cell apoptosis; Chen et al. 2008 PMID:18552236; Shalev 2014 PMID:24911120)",
        },
        "X6": {
            "symbol": "F",
            "generator_tier1": "X6 = X2 * X3 * X4",
            "name": "RNLS_ER_Stress_vs_GSIS_Shutoff_Test",
            "gate": "Gate_1_Metabolic_GSIS_Shutoff_Graveyard004",
            "factor_class": "Single_Locus_Knockout",
            "level_minus1": "RNLS+/+ (wild-type RNLS)",
            "level_plus1": "RNLS-/- (renalase knockout testing ER-stress protection vs 2.8 mM glucose shut-off delay; PMID:32719542 vs PMID:39988068)",
        },
    }
    factorial_runs = []
    tier1_tuples = []
    for run_idx in range(16):
        x1 = 1 if (run_idx & 1) else -1
        x2 = 1 if (run_idx & 2) else -1
        x3 = 1 if (run_idx & 4) else -1
        x4 = 1 if (run_idx & 8) else -1
        x5 = x1 * x2 * x3
        x6 = x2 * x3 * x4
        tier1_tuples.append((x1, x2, x3, x4, x5, x6))
        factorial_runs.append({
            "run_id": f"HIP_FACTORIAL_RUN_{run_idx + 1:02d}",
            "run_number": run_idx + 1,
            "stage_block": 0,
            "block": "Tier1_16Run_Resolution_IV_Screening",
            "coded_levels": {"X1": x1, "X2": x2, "X3": x3, "X4": x4, "X5": x5, "X6": x6},
            "locus1_physical_cassette_id": _locus1_physical_cassette_id(x1, x2),
            "embodiment_a_star_promoted_locus1_cassette_id": "LOC1_X1P_X2P_ARM1B_ASTAR_4143BP_BIDIR_2AFREE",
            "locus3_basalfloor_promoted_cassette_id": "LOC3_X3P_L3_BFB_4078BP_BASALFLOOR_SCARFREE",
            "decoded_genotype": {
                "X1_MHC_I": "B2M::HLA-E*01:03(VMAPRTLVL)" if x1 == 1 else "B2M-/-",
                "X2_CD47": "Constitutive_HighFloor_3prime_CD47_IgV_GPI_Locked" if x2 == 1 else "Endogenous_B2M_Promoter_CD47_WT",
                "X3_Locus3": "CXCL10::SERPINB9-GSG-tPT2A-PD-L1" if x3 == 1 else "CXCL10+/+",
                "X4_TYK2": "TYK2-/-" if x4 == 1 else "TYK2+/+",
                "X5_TXNIP": "TXNIP-/-" if x5 == 1 else "TXNIP+/+",
                "X6_RNLS": "RNLS-/-" if x6 == 1 else "RNLS+/+",
            },
        })

    tier2_core_tuples = [
        (1, -1, 1, -1, -1, -1),   # Run 17 (and Replicate Run 27): LEGACY lean chassis (endogenous B2M-promoter bicistronic CD47, X2 = -1); NOT the current Scenario A lead (Runs 35-36)
        (-1, -1, -1, -1, -1, 1),  # Run 18 (and Replicate Run 28): Single-factor RNLS-/- on UP421 baseline
        (-1, -1, -1, -1, 1, -1),  # Run 19 (and Replicate Run 29): Single-factor TXNIP-/- on UP421 baseline
        (-1, -1, -1, -1, 1, 1),   # Run 20 (and Replicate Run 30): Dual metabolic TXNIP-/- + RNLS-/- on UP421 baseline
        (-1, -1, -1, 1, -1, -1),  # Run 21 (and Replicate Run 31): Single-factor TYK2-/- on UP421 baseline
        (-1, -1, -1, 1, 1, -1),   # Run 22 (and Replicate Run 32): TYK2-/- + TXNIP-/- de-aliasing run
        (-1, -1, 1, -1, -1, -1),  # Run 23 (and Replicate Run 33): Single-factor CXCL10::SERPINB9-GSG-tPT2A-PD-L1 on UP421 baseline
        (-1, 1, -1, -1, -1, -1),  # Run 24 (and Replicate Run 34): Single-factor Constitutive_HighFloor_Monocistronic_CD47_IgV_GPI on UP421 baseline
    ]
    tier2_bridge_tuples = [
        tier1_tuples[0],   # Run 25: Bridge Control repeating Tier-1 Run 01 (-1,-1,-1,-1,-1,-1) inside Tier-2 batch
        tier1_tuples[15],  # Run 26: Bridge Control repeating Tier-1 Run 16 (+1,+1,+1,+1,+1,+1) inside Tier-2 batch
    ]
    tier2_all_tuples = (
        [(t, "Tier2_DeAliasing_Replicate_A") for t in tier2_core_tuples]
        + [(t, "Tier2_InterStage_Bridge_Control") for t in tier2_bridge_tuples]
        + [(t, "Tier2_DeAliasing_Replicate_B") for t in tier2_core_tuples]
    )
    for offset, ((x1, x2, x3, x4, x5, x6), sub_block) in enumerate(tier2_all_tuples, 17):
        factorial_runs.append({
            "run_id": f"HIP_FACTORIAL_RUN_{offset:02d}",
            "run_number": offset,
            "stage_block": 1,
            "block": sub_block,
            "coded_levels": {"X1": x1, "X2": x2, "X3": x3, "X4": x4, "X5": x5, "X6": x6},
            "locus1_physical_cassette_id": _locus1_physical_cassette_id(x1, x2),