OpenIslet

scripts/extract_ring1_corpus.py

Step 5B (v0.3 Deep Quantitative & Canonical Graph Upgrade):

script Release v0.8.0 gen-eb955f8266035aba 296 KB · 22 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/extract_ring1_corpus.py · SHA-256: eee6ac565ed0fb16…

    if re.search(rf"(?i)\b{tok}-free\b", clause):
        return True
    return False


def _match_carrier_family(
    text: str,
    family: str,
    patterns: tuple[re.Pattern[str], ...],
    exclusion_re: re.Pattern[str] | None = None,
) -> tuple[bool, str]:
    for clause in _split_carrier_clauses(text):
        if exclusion_re is not None and exclusion_re.search(clause):
            continue
        if _clause_negates_family(clause, family):
            continue
        for pat in patterns:
            if pat.search(clause):
                return True, clause[:160]
    return False, ""


def classify_oxygen_bridge_carrier_hardened(text: str) -> tuple[str, str]:
    hit, sn = _match_carrier_family(text, "cao2", _HARDENED_CAO2_PATTERNS)
    if hit:
        return "CaO2_PDMS_Oxygen_Microbeads", sn
    hit, sn = _match_carrier_family(text, "pfc", _HARDENED_PFC_PATTERNS, _PFC_EXCLUSION_RE)
    if hit:
        return "Perfluorocarbon_O2_Carrier", sn
    hit, sn = _match_carrier_family(text, "exog_o2", _HARDENED_EXOG_O2_PATTERNS)
    if hit:
        return "Exogenous_O2_Chamber_or_Bioelectronic", sn
    hit, sn = _match_carrier_family(text, "hb", _HARDENED_HB_PATTERNS)
    if hit:
        return "Hemoglobin_or_Myoglobin_Hydrogel", sn
    return "None", ""


def _infer_comparator_oxygen_carrier(base_o2: str | None, comp_arm_label: str) -> str | None:
    """Prevent unoxygenated or unspecified comparator arms from inheriting study-level O2 carrier labels."""
    if base_o2 in (None, "None"):
        return base_o2
    if _COMPARATOR_EXPLICIT_NO_O2_RE.search(comp_arm_label or ""):
        return "None"
    comp_o2, _ = classify_oxygen_bridge_carrier_hardened(comp_arm_label or "")
    if comp_o2 != "None":
        return comp_o2
    # Schema permits null to preserve uncertainty when the comparator omits oxygenation methods
    return None


def _apply_part_a1_curated_overrides(record: dict[str, Any], dossier: dict[str, Any]) -> None:
    """Apply individually source-verified, strictly schema-clean IIP-0030 (DEC-109) curated overrides."""
    pmid = str(record.get("study_metadata", {}).get("pmid") or "")
    dossier_sha = _compute_dossier_sha256(pmid, dossier)
    arms = record.get("arms") or []
    effects = record.get("atomic_effects") or []

    if pmid == "39326417":
        # Wang S et al., Cell 2024 Oct 31;187(22):6152-6164.e18 (DOI:10.1016/j.cell.2024.09.004; ChiCTR2300072200)
        record["study_metadata"]["nct_id"] = "ChiCTR2300072200"
        for arm in arms:
            arm["arm_label"] = (
                "Autologous CiPSC-islets implanted beneath abdominal anterior rectus sheath "
                "in Wang S (2024) [full text, absent from PubMed abstract: 1,488,283 IEQ / "
                "19,843 IEQ/kg, hydrogel-free non-en-bloc injection, pre-existing liver-transplant "
                "tacrolimus systemic IS, and chronic liver-disease HbA1c interpretation caveat]"
            )
            g1 = arm["gate1_substrate_and_differentiation"]
            g1["cell_source_class"] = "CiPSC_chemically_induced"
            g1["canonical_differentiation_stage_evaluated"] = "InVivo_Engrafted_Maturation"
            g5 = arm["gate5_engraftment_niche"]
            g5["transplant_site"] = "Intramuscular_Forearm_or_Rectus"
            g5["oxygen_bridge_72h_carrier"] = "None"
            g5["systemic_immunosuppression_regimen"] = (
                "Pre-existing tacrolimus-based systemic immunosuppression (prior liver transplant) "
                "continued and adapted peri-transplant; chronic liver disease noted as potential HbA1c "
                "confounder (Wang et al. Cell 2024 full text, DOI:10.1016/j.cell.2024.09.004; "
                "absent from PubMed abstract)"
            )
        for eff in effects:
            eid = eff.get("effect_id")
            if eid == "pmid39326417_eff1":
                eff["focal_factor_X"] = "Sub_ARS_Autologous_CiPSC_Islet_Transplantation"
                eff["outcome_domain"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff["outcome_variable_Y"] = (
                    "[Endpoint: Time-in-target glycemic range and HbA1c at month 4] "
                    "TIR rose from 43.18% baseline to 96.21% at month 4 with non-diabetic HbA1c "
                    "(full-text caveats: systemic tacrolimus IS; chronic liver disease may affect HbA1c)"
                )
                eff["effect_direction"] = "Protective_or_Improved"
            elif eid == "pmid39326417_eff2":
                eff["focal_factor_X"] = "Sub_ARS_Autologous_CiPSC_Islet_Transplantation"
                eff["outcome_domain"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff["outcome_variable_Y"] = (
                    "[Endpoint: Stable glycemic control (TIR >98% and HbA1c ~5%)] "
                    "Sustained TIR >98% and HbA1c ~5% under pre-existing liver-transplant tacrolimus IS "
                    "(full-text caveat: chronic liver disease may affect HbA1c)"
                )
                eff["effect_direction"] = "Protective_or_Improved"
            eff["conditioning_context_Z"]["Z1_developmental_stage_and_timing"] = "InVivo_Engrafted_Maturation"
            eff["conditioning_context_Z"]["Z2_genetic_background_and_allelic_dose"] = "CiPSC_chemically_induced"
            eff["conditioning_context_Z"]["Z3_immune_effector_and_stressor_pathway"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
            eff["conditioning_context_Z"]["Z6_microenvironment_oxygen_and_vascular_niche"] = "Intramuscular_Forearm_or_Rectus"
            _populate_effect_provenance(eff, dossier, dossier_sha, "Intramuscular_Forearm_or_Rectus")
            eff["direction_adjudication_method"] = "source_adjudicated_curated_override"
        # Clear 2 garbled heuristic edges induced by bare "hemoglobin" substring match
        record["causal_mechanism_edges"] = []

    elif pmid == "36624157":
        # Liang Z et al., Nat Metab 2023 Jan;5(1):29-40 (DOI:10.1038/s42255-022-00713-7)
        for arm in arms:
            arm["arm_label"] = (
                "Chemically induced hPSC-islets (hCiPSC-8# / hPSC-8) placed beneath abdominal "
                "anterior rectus sheath (distinct from intramuscular comparator; n=4 diabetic macaques "
                "for post-meal C-peptide/HbA1c efficacy within n=8 [5M/3F] study total across experiments) "
                "in Liang Z (2023) [full text, absent from PubMed abstract: hCiPSC-8#/hPSC-8 line "
                "(Methods & Reporting Summary p. 5), n=4 diabetic efficacy cohort (Extended Data Fig. 5), "
                "hydrogel-free free injection, sub-ARS vs intramuscular comparator]"
            )
            g1 = arm["gate1_substrate_and_differentiation"]
            g1["cell_source_class"] = "CiPSC_chemically_induced"
            g1["cell_line_id"] = "hCiPSC-8# (hPSC-8)"
            g1["protocol_backbone"] = (
                "Chemically induced pluripotent stem-cell-derived islets (hCiPSC-8# / hPSC-8) "
                "beneath abdominal anterior rectus sheath, distinguished from intramuscular comparator "
                "[full text Methods & Reporting Summary p. 5, DOI:10.1038/s42255-022-00713-7, "
                "absent from PubMed abstract]"
            )
            g1["canonical_differentiation_stage_evaluated"] = "InVivo_Engrafted_Maturation"
            g5 = arm["gate5_engraftment_niche"]
            g5["transplant_site"] = "Intramuscular_Forearm_or_Rectus"
            g5["oxygen_bridge_72h_carrier"] = "None"
            g5["systemic_immunosuppression_regimen"] = (
                "Chronic systemic immunosuppression in diabetic macaques (n=4 diabetic efficacy cohort "
                "within n=8 study total across experiments; xenogeneic human CiPSC-islet transplantation; "
                "Liang et al. Nat Metab 2023 full text & Extended Data Fig. 5, "
                "DOI:10.1038/s42255-022-00713-7; absent from PubMed abstract)"
            )
        new_effects: list[dict[str, Any]] = []
        for eff in effects:
            eid = eff.get("effect_id")
            if eid == "pmid36624157_eff1":
                eff["focal_factor_X"] = "Sub_ARS_CiPSC_Islet_Transplantation"
                eff["outcome_domain"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff["conditioning_context_Z"]["Z1_developmental_stage_and_timing"] = "InVivo_Engrafted_Maturation"
                eff["conditioning_context_Z"]["Z2_genetic_background_and_allelic_dose"] = "CiPSC_chemically_induced"
                eff["conditioning_context_Z"]["Z3_immune_effector_and_stressor_pathway"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff["conditioning_context_Z"]["Z6_microenvironment_oxygen_and_vascular_niche"] = "Intramuscular_Forearm_or_Rectus"
                _populate_effect_provenance(eff, dossier, dossier_sha, "Intramuscular_Forearm_or_Rectus")
                eff["contrast_metadata"]["population_or_model"] = (
                    "CiPSC_chemically_induced (Tier_2A_Human_Cells_InVivo_NHP_or_HumanizedMouse)"
                )
                eff["direction_adjudication_method"] = "source_adjudicated_curated_override"
                new_effects.append(eff)
            elif eid == "pmid36624157_eff2":
                # Atomic split: separate C-peptide (2.0 ng/mL from 8 wpt, Higher_Is_Better) from
                # glycated hemoglobin (-44% / 44% relative decrease at 12 wpt, Lower_Is_Better).
                q_cpep = (
                    "The average post-prandial C-peptide level reaches approximately 2.0\u2009ng\u2009ml-1 "
                    "from 8 wpt, which is five times higher than the peak value we previously obtained "
                    "after portal vein infusion of hPSC islets"
                )
                q_hba1c = "was associated with a decrease of glycated hemoglobin levels by 44% at 12 wpt."

                eff_cpep = copy.deepcopy(eff)
                eff_cpep["effect_id"] = "pmid36624157_eff2"
                eff_cpep["focal_factor_X"] = "Sub_ARS_CiPSC_Islet_Transplantation"
                eff_cpep["comparator_X0"] = (
                    "Single-arm post-transplant observation in diabetic macaques (n=4 diabetic efficacy "
                    "cohort under systemic IS beneath anterior rectus sheath, distinct from intramuscular "
                    "comparator; 5x higher than historical portal-vein peak; no concurrent control arm in sentence)"
                )
                eff_cpep["outcome_variable_Y"] = (
                    "[Endpoint: Post-prandial C-peptide concentration] Average post-meal C-peptide "
                    "~2.0 ng/mL from 8 wpt in diabetic macaques (n=4 sub-ARS under systemic IS; "
                    "5x higher than historical portal-vein peak)"
                )
                eff_cpep["outcome_domain"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff_cpep["treatment_mean"] = 2.0
                eff_cpep["treatment_sd_or_sem"] = None
                eff_cpep["control_mean"] = None
                eff_cpep["control_sd_or_sem"] = None
                eff_cpep["measurement_unit"] = "ng/mL"
                eff_cpep["log_response_ratio_or_smd"] = None
                eff_cpep["comparator_arm_id"] = None
                eff_cpep["effect_direction"] = "Protective_or_Improved"
                eff_cpep["secretome_or_differentiation_penalty_observed"] = False
                eff_cpep["verbatim_evidence_quote"] = q_cpep
                eff_cpep["conditioning_context_Z"]["Z1_developmental_stage_and_timing"] = "InVivo_Engrafted_Maturation"
                eff_cpep["conditioning_context_Z"]["Z2_genetic_background_and_allelic_dose"] = "CiPSC_chemically_induced"
                eff_cpep["conditioning_context_Z"]["Z3_immune_effector_and_stressor_pathway"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff_cpep["conditioning_context_Z"]["Z6_microenvironment_oxygen_and_vascular_niche"] = "Intramuscular_Forearm_or_Rectus"
                _populate_effect_provenance(eff_cpep, dossier, dossier_sha, "Intramuscular_Forearm_or_Rectus")
                eff_cpep["direction_adjudication_method"] = "source_adjudicated_curated_override"
                eff_cpep["endpoint_polarity_registry"] = {
                    "polarity_class": "Higher_Is_Better_Protective_Endpoint",
                    "orientation_sign": 1,
                    "matched_lexicon_term": "c-peptide",
                }
                eff_cpep["contrast_metadata"]["timepoint"] = "8 wpt"
                eff_cpep["contrast_metadata"]["units"] = "ng/mL"
                eff_cpep["contrast_metadata"]["population_or_model"] = (
                    "CiPSC_chemically_induced (Tier_2A_Human_Cells_InVivo_NHP_or_HumanizedMouse)"
                )
                new_effects.append(eff_cpep)

                eff_hba1c = copy.deepcopy(eff)
                eff_hba1c["effect_id"] = "pmid36624157_eff3"
                eff_hba1c["focal_factor_X"] = "Sub_ARS_CiPSC_Islet_Transplantation"
                eff_hba1c["comparator_X0"] = (
                    "Within-arm pre- to post-transplant change in diabetic macaques (n=4 diabetic efficacy "
                    "cohort under systemic IS beneath anterior rectus sheath; 44% relative decrease [-44%] "
                    "in HbA1c at 12 wpt; historical portal comparator noted; no concurrent control arm in sentence)"
                )
                eff_hba1c["outcome_variable_Y"] = (
                    "[Endpoint: Glycated hemoglobin (HbA1c) relative change] -44% (44% relative decrease "
                    "from baseline) at 12 wpt in diabetic macaques (n=4 sub-ARS under systemic IS)"
                )
                eff_hba1c["outcome_domain"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff_hba1c["treatment_mean"] = 44.0
                eff_hba1c["treatment_sd_or_sem"] = None
                eff_hba1c["control_mean"] = None
                eff_hba1c["control_sd_or_sem"] = None
                eff_hba1c["measurement_unit"] = "%_relative_decrease"
                eff_hba1c["log_response_ratio_or_smd"] = None
                eff_hba1c["comparator_arm_id"] = None
                eff_hba1c["effect_direction"] = "Protective_or_Improved"
                eff_hba1c["secretome_or_differentiation_penalty_observed"] = False
                eff_hba1c["verbatim_evidence_quote"] = q_hba1c
                eff_hba1c["conditioning_context_Z"]["Z1_developmental_stage_and_timing"] = "InVivo_Engrafted_Maturation"
                eff_hba1c["conditioning_context_Z"]["Z2_genetic_background_and_allelic_dose"] = "CiPSC_chemically_induced"
                eff_hba1c["conditioning_context_Z"]["Z3_immune_effector_and_stressor_pathway"] = "InVivo_Glycemic_Cure_and_Graft_Longevity"
                eff_hba1c["conditioning_context_Z"]["Z6_microenvironment_oxygen_and_vascular_niche"] = "Intramuscular_Forearm_or_Rectus"
                _populate_effect_provenance(eff_hba1c, dossier, dossier_sha, "Intramuscular_Forearm_or_Rectus")
                eff_hba1c["direction_adjudication_method"] = "source_adjudicated_curated_override"
                eff_hba1c["endpoint_polarity_registry"] = {
                    "polarity_class": "Lower_Is_Better_Hazard_Endpoint",
                    "orientation_sign": -1,
                    "matched_lexicon_term": "glycated hemoglobin",
                }
                eff_hba1c["contrast_metadata"]["timepoint"] = "12 wpt"
                eff_hba1c["contrast_metadata"]["units"] = "%_relative_decrease"
                eff_hba1c["contrast_metadata"]["population_or_model"] = (
                    "CiPSC_chemically_induced (Tier_2A_Human_Cells_InVivo_NHP_or_HumanizedMouse)"
                )
                new_effects.append(eff_hba1c)
            else:
                new_effects.append(eff)
        record["atomic_effects"] = new_effects