scripts/rank_islet1_stacks.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/rank_islet1_stacks.py · SHA-256: c05d5fe606219e88…
"worst_case_2fi_23col_1191_over_1616_half_effect_beta_jk_se_pp": round(sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_full_contrast_2beta_jk_se_pp": round(2.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_dod_contrast_4beta_jk_se_pp": round(4.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_full_contrast_2beta_mde_80pct_power_normal_alpha_0_05_pp": round(mult_norm_a05 * 2.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_full_contrast_2beta_mde_80pct_power_t52_alpha_0_05_pp": round(mult_t52_a05 * 2.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_full_contrast_2beta_mde_80pct_power_t13_alpha_0_05_pp": round(mult_t13_a05 * 2.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_dod_4beta_mde_80pct_power_normal_alpha_0_05_pp": round(mult_norm_a05 * 4.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_dod_4beta_mde_80pct_power_t52_alpha_0_05_pp": round(mult_t52_a05 * 4.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"worst_case_2fi_23col_1191_over_1616_dod_4beta_mde_80pct_power_t13_alpha_0_05_pp": round(mult_t13_a05 * 4.0 * sigma_run_pp * math.sqrt(float(max_2fi_23)), 2),
"gsis_stimulation_index_22col_best_mde_80pct_power_at_sigma_run_0_45_SI_units": round(mult_t52_a05 * 2.0 * 0.45 * math.sqrt(float(min_main_22)), 2),
}
return {
"protocol_fields": protocol_fields,
"power_and_covariance_summary": power_and_covariance_summary,
"n_distinct_genotypes": n_geno,
"max_leverage_text": f"{_hip_frac_plain(max_h23)} = {float(max_h23):.6f}",
"ssr_text": _hip_frac_plain(s["ssr"]),
"all_2fi_estimable": s["rank22"] == 22,
"full_rank_with_block": s["rank23"] == 23,
"dealiasing_note": dealiasing_note,
}
def _locus1_physical_cassette_id(x1: int, x2: int) -> str:
"""Explicit 4-cell X1 x X2 physical construct mapping (Audit R02): eliminates orphan 2A tags when X1 == -1."""
if x1 == -1 and x2 == -1:
return "LOC1_X1M_X2M_B2M_CD47WT_MONOCISTRONIC"
if x1 == -1 and x2 == 1:
return "LOC1_X1M_X2P_HEF1A_CD47GPI_MONOCISTRONIC"
if x1 == 1 and x2 == -1:
return "LOC1_X1P_X2M_B2M_HLAE_TPT2A_CD47WT_BICISTRONIC"
return "LOC1_X1P_X2P_HEF1A_HLAE_TPT2A_CD47GPI_BICISTRONIC"
LOCUS1_X1_BY_X2_PHYSICAL_CONSTRUCT_MATRIX = {
"LOC1_X1M_X2M_B2M_CD47WT_MONOCISTRONIC": {
"coded_X1": -1,
"coded_X2": -1,
"cistron_valency": "Monocistronic (HLA-E absent; NO 2A peptide tag)",
"physical_allele_architecture": "B2M exon 1 KO/KI :: endogenous resting B2M promoter -> Kozak-ATG-CD47-WT(full-length, OA3-323)-bGHpA",
"purpose": "Tests endogenous resting B2M promoter driving full-length CD47-WT without HLA-E or any 2A peptide tag.",
},
"LOC1_X1M_X2P_HEF1A_CD47GPI_MONOCISTRONIC": {
"coded_X1": -1,
"coded_X2": 1,
"cistron_valency": "Monocistronic (HLA-E absent; NO 2A peptide tag)",
"physical_allele_architecture": "B2M exon 1 KO/KI :: B2M-ISRE-[native human EEF1A1-core (230 bp, 19 CpGs, 60.0% GC) + chimeric intron] -> Kozak-ATG-CD47-IgV-GPI(DAF)-WPREmut6-bGHpA",
"purpose": "Tests high-floor constitutive/synthetic promoter driving signaling-incompetent GPI-anchored CD47-IgV-GPI without HLA-E or any 2A tag.",
},
"LOC1_X1P_X2M_B2M_HLAE_TPT2A_CD47WT_BICISTRONIC": {
"coded_X1": 1,
"coded_X2": -1,
"cistron_valency": "Bicistronic tPT2A (HLA-E 5'-upstream, CD47-WT 3'-downstream)",
"physical_allele_architecture": "B2M exon 1 KO/KI :: endogenous resting B2M promoter -> HLA-E*01:03(VMAPRTLVL)-GSG-tPT2A-CD47-WT(full-length, OA3-323)-bGHpA",
"purpose": "Legacy lean chassis Locus 1 (Runs 17 & 27): tests endogenous B2M promoter driving bicistronic HLA-E + full-length CD47-WT.",
},
"LOC1_X1P_X2P_HEF1A_HLAE_TPT2A_CD47GPI_BICISTRONIC": {
"coded_X1": 1,
"coded_X2": 1,
"cistron_valency": "Bicistronic tPT2A (HLA-E 5'-upstream, CD47-IgV-GPI 3'-downstream)",
"physical_allele_architecture": "B2M exon 1 KO/KI :: B2M-ISRE-[native human EEF1A1-core (230 bp, 19 CpGs, 60.0% GC) + chimeric intron] -> HLA-E*01:03(VMAPRTLVL)-GSG-tPT2A-CD47-IgV-GPI(DAF)-WPREmut6-bGHpA",
"purpose": "Current Scenario A Lead Chassis Locus 1 (Runs 35 & 36): tests high-floor EEF1A1-core+intron driving 5'-HLA-E*01:03 (retaining cytosolic -GSG-P2A tail) and 3'-CD47-IgV-GPI (with unscarred extreme C-terminal DAF GPI signal).",
"embodiment_a_star_promoted_physical_cassette_id": "LOC1_X1P_X2P_ARM1B_ASTAR_4143BP_BIDIR_2AFREE",
"embodiment_a_star_promoted_architecture_argon_r4": "B2M exon 1 KO/KI :: antisense native EEF1A1_core_230 (canonical pinned 4,143-bp Embodiment A* sha256 0995f8e35791d219... carries native CTTTTT 5'TOP; optional EEF1A1[5'TOP-CAGAGA] challenger sha256 28b6882c63d7e6fb...)-CD47-IgV-GPI + 154-bp SPA+MAZ4 pause shield / sense Syn_5xISRE_minP-HLA-E*01:03(VMAPRTLVL, 20-aa L1) (4,143 bp donor / 4,433 bp packaged in single AAV6; mandatory for unconfounded beta_{X1 x X4} Syn_5xISRE x TYK2 P1104A interaction estimation; AUDIT-REF & DEC-078)",
},
"design_identifiability_note": (
"Because X1 = -1 cells are monocistronic (expressing CD47 alone at B2M exon 1) whereas X1 = +1 cells are bicistronic "
"(co-expressing HLA-E*01:03 and CD47 via GSG-tPT2A), the coded X1 main effect and X1:X2 interaction jointly capture HLA-E surface "
"presence plus any monocistronic-to-bicistronic translational stoichiometry shift on downstream CD47. Therefore, every factorial run "
"records absolute QuantiBRITE surface molecules/cell for both HLA-E and CD47 as continuous covariates in a secondary mediation analysis, "
"and Stage-0 Decision Experiment #1 compares the bicistronic tPT2A cassette against a 2A-free bidirectional/dual-promoter cassette (Audit R01/R02)."
),
}
def compute_dose_level_tumor_harm_scenarios_bpr04(
*,
p_esc_per_psc: float = 1e-8,
n_psc: float = 8.0,
p_20q: float = 0.0,
p_meta: float = 1e-6,
f_retrieval: float = 0.99,
s_already_offsite: float = 1.0,
u_omitted_untreated_branch: Optional[float] = None,
) -> Dict[str, Any]:
"""
Temporal-order-preserving conditional tumor-harm scenario evaluator (BPR-04 / DEC-133).
- True pre-retrieval harm withholds surgical removal credit (f_retrieval never reduces pre-retrieval risk).
- Post-retrieval harm decomposes p_meta into an already-off-site fraction s_already_offsite
(invariant to f_retrieval) and an explicitly declared future-preventable fraction (1 - s_already_offsite).
- Population-wide upper bound requires an explicit upper bound on omitted/untreated branch u < 1;
when u_omitted_untreated_branch is None, population-wide risk is explicitly reported as unestimated.
"""
if not (0.0 <= f_retrieval <= 1.0):
raise ValueError(f"f_retrieval must be in [0, 1], got {f_retrieval}")
if not (0.0 <= s_already_offsite <= 1.0):
raise ValueError(f"s_already_offsite must be in [0, 1], got {s_already_offsite}")
if u_omitted_untreated_branch is not None and not (0.0 <= u_omitted_untreated_branch <= 1.0):
raise ValueError(f"u_omitted_untreated_branch must be in [0, 1], got {u_omitted_untreated_branch}")
p_esc_dose = 1.0 - math.exp(-n_psc * p_esc_per_psc)
# True pre-retrieval risk: strictly invariant to f_retrieval across [0.0, 1.0].
p_harm_true_pre_retrieval = 1.0 - (1.0 - p_esc_dose) * (1.0 - p_20q) * (1.0 - p_meta)
# Post-retrieval risk: already-off-site portion persists at all f_retrieval; only declared preventable future share scales with (1 - f_retrieval).
p_meta_already_offsite = s_already_offsite * p_meta
p_meta_preventable_future = (1.0 - s_already_offsite) * p_meta
p_meta_post_retrieval = p_meta_already_offsite + p_meta_preventable_future * (1.0 - f_retrieval)
p_harm_post_retrieval = 1.0 - (1.0 - p_esc_dose * (1.0 - f_retrieval)) * (1.0 - p_20q) * (1.0 - p_meta_post_retrieval)
if u_omitted_untreated_branch is None:
pop_pre = None
pop_post = None
pop_status = "UNESTIMATED_PENDING_CLINICAL_SAFETY_BOUND_ON_OMITTED_UNTREATED_BRANCH_U"
else:
u = float(u_omitted_untreated_branch)
pop_pre = u + (1.0 - u) * p_harm_true_pre_retrieval
pop_post = u + (1.0 - u) * p_harm_post_retrieval
pop_status = "CONDITIONAL_ON_DECLARED_OMITTED_BRANCH_BOUND_U"
return {
"p_esc_dose": p_esc_dose,
"true_pre_retrieval_conditional_harm": p_harm_true_pre_retrieval,
"post_retrieval_conditional_harm": p_harm_post_retrieval,
"p_meta_already_offsite_component": p_meta_already_offsite,
"p_meta_preventable_future_residual_component": p_meta_preventable_future * (1.0 - f_retrieval),
"population_wide_pre_retrieval_upper_bound": pop_pre,
"population_wide_post_retrieval_upper_bound": pop_post,
"population_wide_upper_bound_status": pop_status,
"inputs": {
"p_esc_per_psc": p_esc_per_psc,
"n_psc": n_psc,
"p_20q": p_20q,
"p_meta": p_meta,
"f_retrieval": f_retrieval,
"s_already_offsite": s_already_offsite,
"u_omitted_untreated_branch": u_omitted_untreated_branch,
},
}
def build_champion_challenger_portfolio(ranked_architectures: list[dict], all_combos: list[dict], wetlab_status: dict) -> dict:
"""Keep scored grid candidates separate from unmaterialized product hypotheses."""
if not isinstance(ranked_architectures, list) or not isinstance(all_combos, list) or not all_combos:
raise ValueError("Portfolio requires named architectures and a nonempty evaluated grid")
arch_by_id = {a["architecture_id"]: a for a in ranked_architectures}
if not {"ISLET1_CHASSIS_A_UNIVERSAL_LEAN_4LOCUS", "ISLET1_CHASSIS_B_HLA_C_RETAINED_6LOCUS_HYPOTHESIS"} <= arch_by_id.keys():
raise ValueError("Portfolio requires both incumbent architecture identities")
arch_a = arch_by_id["ISLET1_CHASSIS_A_UNIVERSAL_LEAN_4LOCUS"]
arch_b = arch_by_id["ISLET1_CHASSIS_B_HLA_C_RETAINED_6LOCUS_HYPOTHESIS"]
non_ab_feasible = [
c for c in all_combos
if c.get("is_feasible_candidate", True)
and c["combination_id"] not in (arch_a["matched_combinatorial_search_id"], arch_b["matched_combinatorial_search_id"])
]
if not non_ab_feasible:
raise ValueError("Portfolio has no eligible non-incumbent grid challenger")
non_ab_feasible.sort(key=lambda c: c["global_rank_among_all_combinations"])
emergent_x = non_ab_feasible[0]
zero_warn_x = next((c for c in non_ab_feasible if len(c.get("triggered_graveyard_rules", [])) == 0), None)
er_stress_x = next((c for c in non_ab_feasible if "__ER_NONE__" not in c["combination_id"]), None)
def watchlist_reference(candidate):
if candidate is None:
return {"status": "NO_QUALIFYING_FEASIBLE_STACK", "combination_id": None, "global_rank": None, "K": None, "B": None, "composite_series_system_utility": None}
return {"status": "PRIOR_RANKED_WATCHLIST_ONLY", "combination_id": candidate["combination_id"],
"global_rank": candidate["global_rank_among_all_combinations"], "K": candidate["total_genomic_cuts_K"],
"B": candidate["total_base_edits_B"], "composite_series_system_utility": candidate["composite_series_system_utility"]}
w_ped_pf, w_adult_pf = _composite_utility_weights()
a_ped_u = arch_a["utility_pediatric_early_onset_t1d"]
a_lada_u = arch_a["utility_adult_onset_lada"]
a_g3_logit_unrounded = float(a_ped_u["gate_logits_unrounded"]["Gate3_Innate_NK_Macrophage_and_IBMIR_Shield"])
a_g3_prob_unrounded = sigmoid_unclipped(a_g3_logit_unrounded)
x_g3_prob_unrounded = sigmoid_unclipped(a_g3_logit_unrounded + 0.20)
a_comp_unrounded = (
w_ped_pf * float(a_ped_u["series_system_joint_survival_probability_unrounded"])
+ w_adult_pf * float(a_lada_u["series_system_joint_survival_probability_unrounded"])
)
x_comp_unrounded = a_comp_unrounded * (x_g3_prob_unrounded / a_g3_prob_unrounded)
a_g3_disp = round(a_g3_prob_unrounded, 4)
x_g3_disp = round(x_g3_prob_unrounded, 4)
a_comp_disp = round(a_comp_unrounded, 4)
x_comp_disp = round(a_comp_disp * x_g3_disp / a_g3_disp, 4)
rel_gain_exact_pct = round(100.0 * (x_g3_prob_unrounded / a_g3_prob_unrounded - 1.0), 2)
b_ped_u = arch_b["utility_pediatric_early_onset_t1d"]
b_lada_u = arch_b["utility_adult_onset_lada"]
b_ped_unrounded = float(b_ped_u["series_system_joint_survival_probability_unrounded"])
b_lada_unrounded = float(b_lada_u["series_system_joint_survival_probability_unrounded"])
b_comp_unrounded = w_ped_pf * b_ped_unrounded + w_adult_pf * b_lada_unrounded
b_g2b_ped_logit = float(b_ped_u["gate_logits_unrounded"]["Gate2B_Autoimmune_T1D_Memory_and_Indirect_APC_Stealth"])
b_g2b_lada_logit = float(b_lada_u["gate_logits_unrounded"]["Gate2B_Autoimmune_T1D_Memory_and_Indirect_APC_Stealth"])
b_g3_logit = float(b_ped_u["gate_logits_unrounded"]["Gate3_Innate_NK_Macrophage_and_IBMIR_Shield"])
b_ped_gy10 = b_ped_unrounded * (sigmoid_unclipped(b_g2b_ped_logit - 0.25) / sigmoid_unclipped(b_g2b_ped_logit))
b_lada_gy10 = b_lada_unrounded * (sigmoid_unclipped(b_g2b_lada_logit - 0.25) / sigmoid_unclipped(b_g2b_lada_logit))
b_comp_gy10 = w_ped_pf * b_ped_gy10 + w_adult_pf * b_lada_gy10
b_g3_ratio_m015 = sigmoid_unclipped(b_g3_logit - 0.15) / sigmoid_unclipped(b_g3_logit)
b_g3_ratio_m020 = sigmoid_unclipped(b_g3_logit - 0.20) / sigmoid_unclipped(b_g3_logit)
b_ped_gy10_m015 = b_ped_gy10 * b_g3_ratio_m015
b_comp_gy10_m015 = b_comp_gy10 * b_g3_ratio_m015
b_ped_gy10_m020 = b_ped_gy10 * b_g3_ratio_m020
b_comp_gy10_m020 = b_comp_gy10 * b_g3_ratio_m020
champion_challenger_portfolio = {
"decision_id": "DEC-007",
"portfolio_model": "3-Slot Champion-Challenger Architecture (Blueprint A, Blueprint B, Blueprint X)",
"outward_rankings_frozen": False,
"slots": {
"A": {
"slot_id": "A",
"architecture_id": arch_a["architecture_id"],
"role": "Lean Universal Off-the-Shelf Champion (K=4, B=0)",
"matched_combinatorial_search_id": arch_a["matched_combinatorial_search_id"],
"global_rank": arch_a["global_rank_among_all_combinations"],
"K": arch_a["genomic_locus_edit_count_K"],
"B": arch_a["base_edit_count_B"],
"composite_series_system_utility": arch_a["composite_series_system_utility"],
"stage0_product_variant_ids": ["ISLET1_A4_ARM1B", "ISLET1_A_STAR_4LOCUS", "ISLET1_A4_ARM1A"],
},
"B": {
"slot_id": "B",
"architecture_id": arch_b["architecture_id"],
"role": "HLA-C-Retained KIR-Matched Superdonor Comparator (Scored Grid #25: K=6, B=1 ISLET1_B1_6LOCUS_TYK2_KO_INS [0.0673] + K=5, B=1 ISLET1_B2_5LOCUS_TYK2_PE counterfactual [0.0782 complexity-discount sensitivity with gate logits held fixed; 0.0724 dropping +0.25 Gate-2B INS credit; 0.0569 full AUTO_NONE with TYK2-KO Gate-1 penalty or 0.0629 with TYK2 P1104A WT-yield]; Promoted Unscored Stage-0 Molecular Plan B'-SCT: K=4, B=0 ISLET1_B_SCT_C1_CIITA / ISLET1_B_SCT_C2_CIITA / ISLET1_B_SCT_C1C2_CIITA [counterfactual 0.1084])",
"matched_combinatorial_search_id": arch_b["matched_combinatorial_search_id"],
"global_rank": arch_b["global_rank_among_all_combinations"],
"K": arch_b["genomic_locus_edit_count_K"],
"B": arch_b["base_edit_count_B"],
"composite_series_system_utility": arch_b["composite_series_system_utility"],
"stage0_product_variant_ids": [
"ISLET1_B1_6LOCUS_TYK2_KO_INS",
"ISLET1_B2_5LOCUS_TYK2_PE",
"ISLET1_B_SCT_C1_CIITA",
"ISLET1_B_SCT_C2_CIITA",
"ISLET1_B_SCT_C1C2_CIITA",
"ISLET1_B_SCT_C1_CIITA_TYK2_PE",
"ISLET1_B_SCT_C2_CIITA_TYK2_PE",
"ISLET1_B_SCT_C1C2_CIITA_TYK2_PE",
],
},
"X": {
"slot_id": "X",
"architecture_id": "ISLET1_CHASSIS_X_EMERGENT_CHALLENGER",
"grid_alias": "X-grid (ISLET1_CHASSIS_X_CONSERVATIVE_BASE_EDIT_CHALLENGER)",
"role": "Highest-ranked feasible non-A/non-B grid challenger (K=4, B=1 conservative prime/base-edit challenger inheriting the categorical NICHE_TRIHORMONAL_120UM_MVF_CAO2 120 um lamina / <=150 um cluster-cap indicator on the 2,160-stack grid; exact utility tie at #2/#3 between #2 AUTO_DUAL_INS_LEADER_AND_DRIP_EDIT + ER_NONE [K=4, B=1, discount = 0.9650] and #3 AUTO_NONE + ER_IAPP_PRAMLINTIDE_RNLS_WT [K=4, B=1, discount = 0.9650] at 0.10463976892871349 exact unrounded composite utility [0.10463977 8-dec; 0.1046 both direct 4-dec and IEEE-754 binary64 cohort-rounded average round((0.1032 + 0.1061)/2, 4) = round(0.10464999999999999, 4) = 0.1046], resolved to #2 under reverse=True sort by the Gate-2B T1D autoantigen stealth priority tie-breaker for AUTO_DUAL_INS_LEADER_AND_DRIP_EDIT while #3 ER_IAPP_PRAMLINTIDE_RNLS_WT serves as the Gate-4 ER/amyloid Pareto watchlist challenger, whereas K=5, B=0 AUTO_NONE + ER_RNLS_KO [discount = exp(-0.15) = 0.860708] ranks #9 at 0.08189922 [0.0819]); strictly distinct from unscored off-grid Stage-0 molecular/biophysical Design X (K=4, B=0, 100 um PDMS-CaO2 lamina / 125 um cell bands / 46.39 wt% CaO2 / <=100 um cluster cap + spatial boundary-ring microgel geometry evaluated in dedicated Layer-4 PDE scenarios: ISLET1_A4_X_MOL_RNLS_WT, ISLET1_A4_DXS_ARM1C_L4CD47, ISLET1_A4_L3_BFB_BASALFLOOR, ISLET1_COMP_R4_X_BFB_DXB_LOWLOAD1500; L1B-F1, L1B-F2 & IIP-0009 / DEC-087)",
"evaluation_scope": "COMBINATORIAL_GRID_ONLY",
"molecular_proposal_included_in_score": False,