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…
"description": "Zero intrinsic protection against IFN-gamma/IL-1beta/TNF-alpha or Granzyme B bystander killing.",
},
}
ER_AMYLOID_MODULES = {
"ER_NONE": {
"label": "No Intrinsic ER/Amyloid Gene Edit (Relies on Stage 7 Metabolic Maturation)",
"cuts": 0,
"base_edits": 0,
"genes": [],
"description": "0 extra cuts. Avoids the human iPSC-beta RNLS-/- elevated basal OCR / metabolic precaution prior (noting that poor dynamic GSIS persisted in both WT and RNLS KO in MacDonald et al. 2025 Fig. 6, PMID:39988068).",
},
"ER_RNLS_KO": {
"label": "Biallelic RNLS-/- Knockout (1 cut)",
"cuts": 1,
"base_edits": 0,
"genes": ["RNLS"],
"description": "1 chromosomal cut (RNLS KO). Protects beta-cells against thapsigargin ER stress and CTL killing in mouse NIT-1 / SC-beta screens (Cai et al. 2020 PMID:32719542), while carrying a conservative human iPSC-beta basal OCR / metabolic precaution prior (poor dynamic GSIS persisted in both WT and RNLS KO in MacDonald et al. 2025 Fig. 6, PMID:39988068).",
},
"ER_RNLS_KO_PLUS_IAPP_PRAMLINTIDE": {
"label": "RNLS-/- (1 cut) + IAPP (A25P/S28P/S29P) Prime-Edit (1 base/prime edit)",
"cuts": 1,
"base_edits": 1,
"genes": ["RNLS", "IAPP"],
"description": "1 cut (RNLS KO) + 1 prime-edit locus (IAPP proline conversion, PMID:18753660).",
},
"ER_IAPP_PRAMLINTIDE_RNLS_WT": {
"label": "RNLS+/+ (WT) + Non-Amyloidogenic IAPP (A25P/S28P/S29P) Prime-Edit (0 cuts, 1 prime edit)",
"cuts": 0,
"base_edits": 1,
"genes": ["IAPP"],
"description": "0 chromosomal DSB cuts + 1 scarless prime-edit converting amyloidogenic human IAPP20-29 to non-amyloidogenic proline-substituted pramlintide-like IAPP(A25P/S28P/S29P) while preserving wild-type RNLS metabolic fitness (eliminating the human iPSC-beta RNLS-/- OCR/GSIS precaution prior in MacDonald et al. 2025 PMID:39988068 while directly blocking human IAPP oligomer toxicity in primary/SC-islets per Potter et al. 2010 PMID:20160085 and Thorngren et al. 2024 PMID:38603470, and noting that A25P/S28P/S29P converts soluble monomers while seeding/conformational effects require empirical Thioflavin-T/Congo-red qualification per Wang et al. 2014 PMID:25140605; AUDIT-REF & AUDIT-REF).",
"molecular_and_immunological_qualification_gate_kimi31_r4": {
"mature_iapp_residues_modified": "Mature human IAPP residues A25P, S28P, S29P (precursor preproIAPP positions 58, 61, 62 on chr12p12.1)",
"required_assays": [
"pegRNA spacer/PBS/RTT sequence registration and off-target rhAmpSeq/amplicon-seq verification",
"Intact-mass LC-MS verification of C-terminally amidated mature 37-aa IAPP(A25P/S28P/S29P) processing by PC1/3, PC2, CPE, and PAM",
"Thioflavin-T and Congo-red amyloid fibril inhibition assay under 7-day 16.7 mM high-glucose challenge (accounting for residual seeding kinetics in Wang et al. 2014 PMID:25140605)",
"Host HLA-DQ2/DQ8/DR4 dendritic-cell indirect presentation screen confirming no de novo neo-epitope CD4+ T-cell priming from the 3-proline substitution",
],
"gate4_scoring_note": "In the 46-entry structural prior registry, ER_IAPP_PRAMLINTIDE_RNLS_WT shares the +0.25 NICHE_TRIHORMONAL_120UM_MVF_CAO2 Gate-4 baseline when paired with the Stage-7 120-um niche while avoiding ER_RNLS_KO's -0.38 Gate-1 precaution prior (incurring only the B=1 prime-edit factor 0.9650); empirical promotion of the IAPP base edit requires positive ΔGate4 in Stage-0 high-glucose amyloid challenge.",
},
},
}
NICHE_VASCULAR_MODULES = {
"NICHE_TRIHORMONAL_120UM_MVF_CAO2": {
"label": "Stage 7 Tri-Hormonal (60/30/10, <=120 um) + iEC Microvessels + 14d Pre-Vasc Pouch + 72h PDMS-CaO2/Catalase",
"cuts": 0,
"base_edits": 0,
"genes": [],
"description": "Vascularized (non-retrievable without surgical excision / iCasp9 ablation) micro-pocket with <=120 um clusters (R <= 60 um, strictly below both the conservative rat islet 74.6 um R_crit and the Stage 7 human SC-islet R_crit = sqrt(6*D*C_0/V_max) = 92.6 um [185.2 um diameter] at V_max = 0.034 mol/m^3/s; PMID:35241836, PMID:34480863) and hydrophobic PDMS-CaO2 (OxySite) + catalase oxygen bridge (noting that 0.7915 g [791.5 mg / 10.981 mmol] is the total loaded pure CaO2 inventory across 200 cm^2 [of which 0.4116 g / 52.0% hydrolyzes over the 72-h window at t_1/2 = 68 h, embedded in 3.166 g / 2.533 g / 1.706 g total PDMS-CaO2 composite mass at 25.0 / 31.25 / 46.39 wt% for Layouts A / B / Design X; delivering 0.4116 g reacted CaO2 at an empirical 72-h utilization fraction f_72h = 0.45 requires 0.915 g pure CaO2 [2.033 g composite at 45 wt%], whereas Pedraza et al. 2012 PMID:22371586 validated multi-week bulk PDMS-CaO2 disk release [f_72h ~= 0.0888 -> 4.635 g pure CaO2 for 0.4116 g reacted, or 8.91 g if scaling the full 0.7915 g inventory by 1/0.0888] and Montazeri et al. 2016 PMID:26970510 used PVP/H2O2-PLGA microparticles, so 72-h burst-matched <=150 um PDMS-CaO2 kinetics require Stage-1 empirical calibration; DEC-078]).",
},
"NICHE_NAKED_AVASCULAR_TRANSPLANT": {
"label": "Standard Avascular Islet Cluster Transplant (~150-250 um, No Pre-Vasc or O2 Bridge)",
"cuts": 0,
"base_edits": 0,
"genes": [],
"description": "Acute avascular injection suffering 50-70% 72h ischemic core loss.",
},
"NICHE_UNEDITED_MACRODEVICE_ENCAPSULATION": {
"label": "Avascular Cell-Impermeable Macro-Encapsulation Device (VX-264 / PEC-Encap style)",
"cuts": 0,
"base_edits": 0,
"genes": [],
"description": "Retrievable physical barrier (>150-200 um diffusion distance) causing central hypoxia and fibrotic foreign-body reaction.",
},
}
SAFETY_SWITCH_MODULES = {
"SAF_AAVS1_CAG_ICASP9_BIALLELIC": {
"label": "Biallelic AAVS1-[455bp HNRNPA2B1-proximal candidate (legacy CBX3-A2UCOE)]-EEF1A1-core-iCasp9 (or AAVS1-CAG-iCasp9 / GAPDH-P2A-iCasp9) Pan-Lineage Safe-Harbor Switch (1 locus)",
"cuts": 1,
"base_edits": 0,
"genes": ["CASP9"],
"description": "1 safe-harbor locus knocked in biallelically (3,457 bp donor / 3,747 bp with ITRs <= 4,700 bp single-AAV6 limit; insulated with 455 bp HNRNPA2B1-proximal candidate (legacy CBX3-A2UCOE alias; insulation function pending) + cHS4 boundaries driving EEF1A1-core-iCasp9; Muller-Kuller et al. 2015 PMID:25605798; Zhang et al. 2017 PMID:28860464; Pfaff et al. 2013 PMID:23307570; Ordovas et al. 2015 PMID:26455413) so undifferentiated iPSCs, endocrine cells, and off-target SLC18A1+ cells are erasable by AP1903/rimiducid (<10^-8 target escape bound per colony-forming proliferating cell; Wunderlich et al. 2022 PMID:35795779).",
},
"SAF_G6PC2_ENDOGENOUS_ICASP9": {
"label": "G6PC2::iCasp9 Mature-Beta-Restricted Switch (1 locus — Graveyard 002 Escape Risk)",
"cuts": 1,
"base_edits": 0,
"genes": ["CASP9", "G6PC2"],
"description": "1 locus (G6PC2 KO + iCasp9 KI). Fails to ablate dedifferentiated, teratoma, or SLC18A1+ off-target cells (Yagyu 2016 PMID:27626039).",
},
"SAF_NONE": {
"label": "No Suicide Switch",
"cuts": 0,
"base_edits": 0,
"genes": [],
"description": "Zero pharmacological erasability in the event of viral infection or oncogenic transformation.",
},
}
def load_inputs():
prepare_wetlab_evaluation_context()
with open(GRAPH_PATH, "r", encoding="utf-8") as f:
graph = json.load(f)
studies = []
for p in sorted(EXTRACTED_DIR.glob("*.json")):
if not p.stem.isdigit():
continue
with open(p, "r", encoding="utf-8") as f:
studies.append(json.load(f))
with open(OMICS_DIR / "target_prior_table.json", "r", encoding="utf-8") as f:
omics_raw = json.load(f)
omics = {t["gene_symbol"]: t for t in omics_raw["targets"]}
return graph, studies, omics
def get_endpoint_orientation_sign(quote_and_var: str) -> float:
"""
Returns -1.0 if the measured variable in the text is a lower-is-better hazard metric
(e.g., specific lysis, cell death, apoptosis, rejection, hyperglycemia) without a
positive survival/viability/GSIS term, so that a negative LRR (reduction in lysis)
maps to a positive welfare gain, while multiplying lrr by -1 (Sol's sign_flip probe)
always negates the resulting welfare contribution.
"""
ql = quote_and_var.lower()
is_hazard = any(
k in ql
for k in (
"specific lysis",
"cytotoxicity",
"apoptosis",
"cell death",
"apoptotic",
"necrotic core",
"blood glucose",
"hyperglycemia",
"amyloid area",
"thioflavin",
)
)
has_pos_metric = any(
k in ql
for k in (
"survival",
"viability",
"gsis",
"stimulation index",
"c-peptide",
"insulin secretion",
"normoglycemia",
"vascular density",
)
)
if is_hazard and not has_pos_metric:
return -1.0
return 1.0
def strict_gene_match(sym: str, text: str) -> bool:
"""Word-boundary gene-symbol match (prevents INS/CAR/HLA substring false positives)."""
s = sym.upper()
t = text.upper()
if s == "CAR":
return bool(re.search(r"(?<![A-Z0-9])CAR(?![A-Z0-9])", t)) and "COXSACKIE" in t
if s == "INS":
return bool(
re.search(
r"(?<!0\.005\s)\[INS\]|\bINS\s*\((?:SIGNAL|BASE|CRISPR|KO|KNOCK)|\bINS\s*(?:KO\b|KNOCKOUT\b|KNOCK-OUT\b|-/-|−/−|BASE[ -]EDIT|LEADER\b|SIGNAL\s+PEPTIDE|DRIP\b|3'UTR|FUNCTIONAL\s+EVALUATION)|^INS$",
t,
)
)
if s.startswith("HLA-"):
return bool(re.search(r"(?<![A-Z0-9])" + re.escape(s) + r"(?:W(?=[\d*])|(?![A-Z]))", t))
return bool(re.search(r"(?<![A-Z0-9])" + re.escape(s) + r"(?![A-Z0-9])", t))
def MATCH(g: str, fx: str, fx_upper: str) -> bool:
return strict_gene_match(g, fx)
def AMATCH(alias: str, fx: str, fx_upper: str) -> bool:
return strict_gene_match(alias, fx)
def expand_gene_symbol_tokens(raw_g: str) -> list[str]:
if not raw_g:
return []
if raw_g == "HLA-B_HLA-C_HLA-A24":
return ["HLA-B", "HLA-C", "HLA-A"]
if raw_g == "IL10_TGFB1_IL2_N88D":
return ["IL10", "TGFB1", "IL2"]
if raw_g == "JAK1_JAK2":
return ["JAK1", "JAK2"]
if raw_g.strip().upper() == "MULTI_LOCUS_SAFE_HARBOR" or raw_g.strip().startswith("[REDACTED_"):
return []
if "_" in raw_g:
return [tok for tok in raw_g.split("_") if tok and not re.match(r"^[A-Z]\d+[A-Z]$", tok)]
return [raw_g]
def build_target_evidence_profiles(studies: list[dict], omics: dict) -> dict:
"""
Computes sign-sensitive, counter-evidence-penalized, omics-constrained, and
non-broadcasting target profiles.
- Attribution Rule (Audit §5.2.1): Effects are attributed ONLY to genes
explicitly named in `focal_factor_X` or `verbatim_evidence_quote`, or to the
sole edited gene if `len(study_genes) == 1`. Multi-gene studies never broadcast
unmatched effects across all study genes.
"""
if not isinstance(studies, list) or any(not isinstance(study, dict) for study in studies) or not isinstance(omics, dict):
raise TypeError("Evidence profiles require a study list and omics mapping")
# These declared masses, weights and dispersions cannot be negative or
# truthy-coerced: a negative harm weight reverses adverse evidence, while
# NaN can otherwise leave a seemingly complete profile with unknown scores.
def profile_parameters(group: str, defaults: dict, *, nonnegative: bool = True) -> dict:
raw = _aux_param(group, {})
if not isinstance(raw, dict):
raise ValueError(f"Profile parameter group {group} must be a mapping")
values = {key: _finite_real(raw.get(key, default), f"{group}.{key}")
for key, default in defaults.items()}
if nonnegative and any(value < 0 for value in values.values()):
raise ValueError(f"Profile parameter group {group} requires nonnegative values")
return values
direction_weights = profile_parameters("effect_direction_weights", {
"deleterious": 0.75, "secretome_or_differentiation_penalty_addon": 0.35,
"protective": 0.50, "shrunk_lrr_multiplier": 1.50,
})
shrink_parameters = profile_parameters("lrr_shrinkage_hyperparameters", {
"prior_weight": 4.50, "per_empirical_study_slope": 0.50,
})
omics_weights = profile_parameters("omics_constraint_weights", {
"gnomad_pli_ko_slope": -0.45, "gnomad_loeuf_ko_slope": 0.12,
"opentargets_t1d_slope": 0.15,
}, nonnegative=False)
dispersion_parameters = profile_parameters("lower_10pct_cred_bound_hyperparameters", {
"default_gene_se": 0.35,
})
def accumulate(st: dict, key: str, amount: float) -> None:
# Finite input coefficients can overflow after repeated additions.
# Reject the arithmetic failure instead of emitting an infinite score.
st[key] = _finite_real(st[key] + amount, f"{st['gene_symbol']}.{key} accumulation")
source_types = {
"FullText_XML_or_PDF",
"FullText_Plus_Supplement_or_GEO",
"Abstract_Only",
"Citation_Only_No_Abstract_Indexed",
"Project_Summary",
"Preprint_Superseded_By_Peer_Reviewed",
"Review_or_Commentary",
}
pmids = []
for study in studies:
metadata = study.get("study_metadata")