scripts/extract_ring1_corpus.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/extract_ring1_corpus.py · SHA-256: eee6ac565ed0fb16…
elif any(k in wl for k in ("inhibit", "small molecule", "pargyline", "verapamil", "bms-986165", "deucravacitinib")):
modality = "SmallMolecule_Pharmacological_Modulator"
elif any(k in wl for k in ("overexpress", "transduc", "lentivir")):
modality = "Lentiviral_or_Transposon_OE"
elif any(k in wl for k in ("knock-in", "knockin", "aavs1", "gapdh")):
modality = "SafeHarbor_KI_AAVS1_GAPDH_CLYBL"
elif re.search(r"\b(?:knockout|knock-out|ko|crispr[- /]?cas9|delet\w+|ablat\w+|deficien\w+|loss\s+of)\b|-/-|−/−", wl):
modality = "CRISPR_Cas9_KO"
if modality in ("CRISPR_Cas9_KO", "CRISPR_Cas12a_Multiplex_KO", "CRISPR_Cas12b_Multiplex_KO", "CRISPRi_or_shRNA_Knockdown"):
p_class = "Loss_of_Function_KO_or_KD"
elif modality in ("BaseEdit_ABE_or_CBE_Epitope_or_Splice", "PrimeEdit", "Signal_Peptide_or_Domain_Swap"):
p_class = "Precision_Epitope_or_Isoform_Edit"
elif modality == "Endogenous_SwapIn_KO_plus_KI":
p_class = "Bicistronic_Endogenous_Promoter_SwapIn_KO_plus_KI"
elif modality in ("SafeHarbor_KI_AAVS1_GAPDH_CLYBL", "Lentiviral_or_Transposon_OE", "CRISPRa_Activation", "Transient_mRNA_or_Surface_Tethering"):
p_class = "Gain_of_Function_or_Transgenic_Armoring"
else:
p_class = "Pharmacological_or_Small_Molecule_Modulator"
edits.append({
"gene_symbol_hgnc": sym,
"ensembl_gene_id": spec["ensembl"],
"sub_molecular_coordinate": {
"region_class": spec["region_class"],
"exact_variant_or_swap_description": matched_context[:180] if matched_context else f"Experimental perturbation of {sym}",
},
"functional_gate": spec["functional_gate"],
"target_autoantibody_or_tcr_evaded": spec["evaded"],
"edit_modality": modality,
"promoter_or_locus_context": spec["default_promoter"],
"zygosity_or_allelic_state": None,
"protein_or_surface_expression_fold_vs_wt": None,
"perturbation_class": p_class,
})
return edits
def classify_outcome_domain(sentence: str) -> str:
sl = sentence.lower()
if any(k in sl for k in ("nk cell", "macrophage", "sirp", "cd47", "missing self", "missing-self")):
return "NK_or_Macrophage_Innate_Survival"
if any(k in sl for k in ("autoreactive", "autoantibod", "cd8+ t", "tcr", "peptide-specific lysis", "ins-drip", "gad65", "znt8", "igrp")):
return "Autoimmune_TCR_or_AutoAb_Evasion"
if any(k in sl for k in ("allogeneic", "allograft", "dsa", "donor-specific antibod", "mhc mismatch", "foxp3", "treg")):
return "Allo_T_Cell_or_DSA_Survival"
if any(k in sl for k in ("complement", "ibmir", "thrombomodulin", "cd55", "cd59", "coagulation")):
return "Complement_or_IBMIR_Coagulation_Block"
if any(k in sl for k in ("granzyme", "perforin", "fasl", "fas-mediated", "serpinb9")):
return "Granzyme_or_Fas_Apoptosis_Resistance"
if any(k in sl for k in ("iapp", "amyloid", "coxsackie", "enterovirus", "cvb", "cxadr", "mda5", "ifih1")):
return "Amyloid_hIAPP_or_Enterovirus_Protection"
if any(k in sl for k in ("thapsigargin", "tunicamycin", "er stress", "upr", "chop", "txnip", "ifn", "cytokine", "il-1", "tnf", "stat1", "tyk2", "rnls")):
return "Cytokine_IFN_NFkB_or_ER_Stress_Survival"
if any(k in sl for k in ("hypoxia", "ischemia", "oxygen", "vascular", "inosculation", "microvessel", "vessel", "capillary")):
return "Hypoxia_72h_or_Vascular_Inosculation"
if any(k in sl for k in ("hla", "mhc class", "pd-l1 expression", "surface expression", "mfi")):
return "Surface_HLA_or_Transgene_Expression_Level"
if any(k in sl for k in ("normoglycemi", "diabetes reversal", "graft survival", "c-peptide in vivo", "blood glucose")):
return "InVivo_Glycemic_Cure_and_Graft_Longevity"
if any(k in sl for k in ("glucagon", "gcg", "somatostatin", "sst", "alpha cell", "delta cell", "paracrine")):
return "Alpha_Delta_Paracrine_CounterRegulation"
if any(k in sl for k in ("gsis", "insulin secretion", "perifusion", "biphasic", "respiration", "ocr", "glycoly", "oxphos", "calcium", "[ca2+]")):
return "Metabolic_and_Biphasic_GSIS_Maturation"
return "Differentiation_Yield_and_Lineage_Purity"
def _v063_classify_direction_for_sort(sentence: str) -> str:
"""Preserves exact v0.6.3 candidate sentence sort priority direction so all 2,794 effect_ids remain invariant."""
sl = sentence.lower()
if any(
k in sl
for k in (
"unchanged", "similar", "no significant difference", "not significantly",
"not statistically significant", "comparable", "did not affect",
"was not prolonged", "were not prolonged", "did not increase",
"did not prevent", "no protection", "failed to prolong",
)
):
return "Neutral_or_NonInferior"
has_non_cyto_toxic = bool(re.search(r"(?<!cyto)\btoxic\w*", sl))
has_harm_kw = has_non_cyto_toxic or any(
k in sl
for k in (
"impair", "compromis", "fail", "loss of", "destroyed", "rejected",
"hypoglycemi", "silenc", "translocation", "chromothripsis", "teratoma",
"exacerbat", "worsen", "blunt", "poor gsis", "poor dynamic", "off-target",
)
)
haz_pat = r"(lysis|killing|apoptosis|apoptotic|cell death|cytotoxic\w*|rejection|inflammation|er stress|fibrosis|necrosis|hyperglyc\w+|insulitis|infiltrat\w+)"
up_pat = r"(increas\w+|elevat\w+|higher|enhanc\w+|greater|upregulat\w+|induc\w+|exacerbat\w+|accelerat\w+|more)"
down_pat = r"(reduc\w+|decreas\w+|lower\w*|prevent\w*|protect\w*|attenuat\w+|inhibit\w+|abolish\w*|block\w*|suppress\w*|diminish\w*|ameliorat\w+|delay\w*|abrogat\w+|less|fewer|resist\w*|rescu\w+|spar\w+)"
haz_increase = bool(re.search(up_pat + r"[^.;]{0,50}" + haz_pat, sl) and not re.search(down_pat, sl))
has_down_verb = any(k in sl for k in ("reduc", "decreas", "lower", "diminish", "abolish", "suppressed", "inhibited"))
has_func_target = any(k in sl for k in ("gsis", "insulin secretion", "stimulated insulin", "c-peptide", "graft survival", "cell viability", "beta-cell mass"))
has_hazard_target = any(k in sl for k in ("lysis", "killing", "apoptosis", "cell death", "necrosis", "rejection", "hyperglycemi", "blood glucose", "amyloid", "fibrosis", "inflammation", "er stress", "oxidative stress"))
if has_harm_kw or haz_increase or (has_down_verb and has_func_target and not has_hazard_target):
return "Deleterious_or_Impaired"
if any(k in sl for k in ("increas", "improv", "enhanc", "protect", "prolong", "restor", "preserv", "prevent", "evad", "resist", "surviv", "revers", "normoglycemi", "reduc", "decreas", "inhibit", "attenuat", "block", "abolish", "fold", "vs", "compared")):
return "Protective_or_Improved"
return "Neutral_or_NonInferior"
def classify_sentence_direction_and_penalty(
sentence: str, outcome_cat: str | None = None, target_gene: str | None = None
) -> tuple[str, bool]:
"""
Endpoint-orientation-aware, clause-bound direction and independent secretome/differentiation penalty classifier (v0.6.8).
- Binds impairment/reduction modifiers to functional secretome/differentiation/viability targets within the same clause
(excluding beneficial reductions of blood glucose, HbA1c, cost, non-endocrine/off-target cells, pluripotency markers,
teratoma formation, and cytotoxicity, as well as rescue/amelioration of cytokine-induced impairment).
- Separates effect_direction from secretome_or_differentiation_penalty_observed (no penalty aliasing, AT-14).
- Does not match 'toxic' inside 'cytotoxic'/'cytotoxicity' (AT-10).
- Flags sentences where a hazard endpoint increases without a decrease verb as Deleterious_or_Impaired (AT-11).
"""
sl = sentence.lower().strip()
if re.search(
r"\b(?:not\s+(?:a\s+)?(?:statistically\s+)?significant\s+(?:increase|decrease|reduction|difference)|"
r"(?:did\s+not\s+(?:significantly\s+)?|failed\s+to\s+)(?:prolong|improve|increase|enhance|protect|reduce|decrease)|"
r"no\s+evidence\s+(?:that|of)|not\s+associated\s+with|neither\b[^.;]*\bnor)\b",
sl,
) and not re.search(r"[,;]\s*(?:but|however|whereas|loss\s+of)\b", sl):
return "Neutral_or_NonInferior", False
if re.search(
r"\b(?:the\s+aims?\s+(?:of\s+\w+\s+(?:study\s+)?)?(?:was|were|is)\s+to|(?:this\s+study|we)\s+(?:aimed|sought)\s+to|(?:our|the)\s+(?:objective|goal|purpose)\s+(?:of\s+this\s+study\s+)?(?:was|is)\s+to|we\s+sought\s+to\s+determine\s+whether|to\s+investigate\s+whether|to\s+determine\s+whether)\b",
sl,
):
return "Neutral_or_NonInferior", False
if re.match(
r"^(?:there\s+(?:was|were|is|are)\s+)?no\s+(?:significant\s+|statistically\s+significant\s+)?(?:increase|reduction|decrease|change|difference)\s+in\b",
sl,
) and not re.search(r",\s*(?:but|however|whereas)\b", sl):
return "Neutral_or_NonInferior", False
m_while_neutral = re.match(
r"^(?:while|whilst)\s+([^,;]+?\b(?:had\s+no\s+effect\s+on|did\s+not\s+affect|were\s+unaltered|was\s+unaltered)[^,;]*)(?:,\s*(.+))?$",
sl,
)
if m_while_neutral:
while_clause, main_clause = m_while_neutral.group(1), (m_while_neutral.group(2) or "").strip()
if (target_gene and re.search(rf"\b{re.escape(target_gene.lower())}\b", while_clause)) or not main_clause:
return "Neutral_or_NonInferior", False
return classify_sentence_direction_and_penalty(main_clause, target_gene=target_gene)
if target_gene and re.search(
rf"\b{re.escape(target_gene.lower())}\b[^,;.]{{0,45}}\b(?:had\s+no\s+effect\s+on|did\s+not\s+affect|did\s+not\s+impair|unchanged)\b",
sl,
):
return "Neutral_or_NonInferior", False
neg_impair = any(
k in sl
for k in (
"did not impair",
"do not impair",
"does not impair",
"were not impaired",
"was not impaired",
"not impaired",
"without impairing",
"without affecting",
"with no impact on",
"do not show impaired",
"did not compromise",
"does not compromise",
"without compromising",
"did not reduce",
"does not reduce",
"without reducing",
"did not decrease",
"does not decrease",
"did not affect",
"does not affect",
"does not alter",
"did not alter",
"does not impact",
"no reduction in",
"no significant reduction",
"no statistically significant reduction",
"no decrease in",
"no significant decrease",
"no change in",
"no significant change",
"no loss of",
)
)
neg_hypo = (
any(
k in sl
for k in (
"without hypoglycemi",
"without severe hypoglycemi",
"no hypoglycemi",
"no episodes of hypoglycemi",
"prevented hypoglycemi",
"prevent hypoglycemi",
"protection against hypoglycemi",
"protect against hypoglycemi",
"protected from hypoglycemi",
"free of hypoglycemi",
"freedom from hypoglycemi",
"absence of hypoglycemi",
"unawareness",
)
)
and "fell to 70 mg/dl or less" not in sl
)
neg_teratoma = any(
k in sl
for k in (
"no teratoma",
"without teratoma",
"prevented teratoma",
"prevent teratoma",
"eliminated teratoma",
"reduces proliferation and teratoma",
"reduced teratoma",
"reduces teratoma",
"inhibited teratoma",
"free of teratoma",
)
)
neg_off_target = bool(
re.search(
r"\b(?:reduc\w+|decreas\w+|eliminat\w+|prevent\w+|inhibit\w+|deplet\w+|no|without|free\s+of)\b[^.;]{0,45}\b(?:off-target|non-?endocrine|enterochromaffin|pluripotency\s+markers?)",
sl,
)
)
is_rnai_silenc = any(
k in sl
for k in (
"sirna",
"shrna",
"rnai",
"gene silencing",
"silencing of ",
"silenced by ",
)
)
is_benign_transloc = any(
k in sl
for k in (
"nuclear translocation",
"translocation to the nucleus",
"translocation into the nucleus",
"membrane translocation",
"glut4 translocation",
"ten-eleven translocation",
"protein translocation",
"bacterial translocation",
)
)
is_rescue_of_impairment = bool(