OpenIslet

scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py

W6-C3 (Provisional Next-Free IIP-0057 / DEC-138 / GATE-36 / GY-035; staging slot iip0057,

script Release v0.8.0 gen-eb955f8266035aba 412 KB · 32 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/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py · SHA-256: 1c63dcf649c42be4…

            "mercodia_spec_note": (
                "Mercodia C-peptide ELISA (10-1136-01) has a published operating range of 0.10-4.00 nmol/L "
                "(100-4,000 pmol/L). Covering both ends of the 0.05-5.00 nmol/L candidate interval requires "
                "demonstrated low-end coverage at 0.05 nmol/L (below 0.10 nmol/L) AND validated sample-dilution "
                "linearity at 5.00 nmol/L (above 4.00 nmol/L), with pinned kit_catalog_id and kit_lot_id."
            ),
            "must_pass_before_ipsc_editing": True,
        },
        "honest_solo_c3_lift_pp_range": [0.5, 0.8],
        "honest_solo_c3_lift_pp_central": 0.6,
    }


# ---------------------------------------------------------------------------
# PART C: Pruned Viral-Receptor-Avoidance Cuff v2.0 (Honest Disulfide Bookkeeping & 7AL7 Nuance)
# ---------------------------------------------------------------------------
def verify_part_c(fasta_path: Path, fasta_records: dict[str, tuple[str, str]]) -> dict[str, Any]:
    actual_sha = sha256_file(fasta_path)
    require_cond(actual_sha == EXPECTED_FASTA_SHA256, f"FASTA SHA-256 mismatch: {actual_sha} != {EXPECTED_FASTA_SHA256}")
    require_cond(len(fasta_records) == EXPECTED_FASTA_RECORD_COUNT, f"Expected {EXPECTED_FASTA_RECORD_COUNT} FASTA records, got {len(fasta_records)}")

    for rid, (_, seq) in fasta_records.items():
        require_cond("fasl" not in rid.lower() and "adipoq" not in rid.lower(), f"Retired ADIPOQ-Hexa-FasL found: {rid}")
        require_cond("IIPNKHDAL" not in seq, f"Banned GY-026 IIPNKHDAL found in {rid}")
        require_cond(all(ch in AA_WEIGHTS for ch in seq), f"Invalid AA residue in {rid}")

    disulfide_specs: dict[str, dict[str, Any]] = {
        "sCR1_v2_CSL040_LHR_ABC_Intein0aa": {"len": 1351, "ss": 42, "unp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_0AA_INTEIN", "peg_kda": 3.4},
        "sCR1_v2_CSL040_LHR_ABC_GGS_LPETG": {"len": 1359, "ss": 42, "unp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_ESRTA", "peg_kda": 3.4},
        "THBD_363_497_M406L_S490A_S492A_Intein0aa": {"len": 135, "ss": 9, "unp": 0, "max_met": 0, "max_trp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_0AA_INTEIN", "peg_kda": 3.4},
        "THBD_363_497_M406L_S490A_S492A_GGS_LPETG_CSnull": {"len": 143, "ss": 9, "unp": 0, "max_met": 0, "max_trp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_ESRTA", "peg_kda": 3.4},
        "THBD_363_497_M406L_GGS_LPETG_CSplus_comparator": {"len": 143, "ss": 9, "unp": 0, "max_met": 0, "max_trp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2_COMPARATOR", "role": "COMPARATOR_CS_PLUS", "peg_kda": 3.4},
        "CD200_ECD_Intein0aa": {"len": 202, "ss": 3, "unp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_0AA_INTEIN", "peg_kda": 20.0},
        "CD200_ECD_GGS_LPETG": {"len": 210, "ss": 3, "unp": 0, "group": "CORE_IMMOBILIZED_CUFF_V2", "role": "CORE_PRUNED_CUFF_CO_LEAD_ESRTA", "peg_kda": 20.0},
        "CFH_19_445_GGS_LPETG_Archived_Backup": {"len": 435, "ss": 14, "unp": 0, "group": "RETIRED_ARCHIVED_BACKUP", "role": "PERMANENTLY_RETIRED_FROM_PRIMARY_CUFF", "peg_kda": 3.4},
        "CCL22_Mature_O00626": {"len": 69, "ss": 2, "unp": 0, "group": "NONCORE_OPTIONAL_COMPARATOR", "role": "GRAFT_INTRINSIC_TREG_CHEMOKINE"},
        "IL1RN_Mature_P18510": {
            "len": 152, "ss": 0, "unp": 4, "group": "NONCORE_SOLUBLE_COMPANION_WITH_FREE_THIOLS",
            "role": "SOLUBLE_IL1RA_COMPANION_EXCLUDED_FROM_ZERO_UNPAIRED_CLAIM",
            "cys_note": "4 Cys monomeric free thiols per UniProt P18510 / PDB 1ILR (optional C91-C141 disulfide noted in UniProt -> 2-4 free thiols); EXCLUDED from covalent zero-unpaired Cuff v2.0.",
        },
        "IL18BP_Mature_O95998": {
            "len": 164, "ss": 2, "unp": 2, "max_met": 0,
            "group": "NONCORE_SOLUBLE_COMPANION_PENDING_MONOMER_LCMS",
            "role": "SOLUBLE_IL18BP_COMPANION_0MET_EXCLUDED_FROM_ZERO_UNPAIRED_CLAIM",
            "disulfide_status": "PARTIAL_CRYSTAL_7AL7_START_RES63_OMITS_CYS51_CYS131_INTERMOLECULAR_2P21A_FULL_LENGTH_MONOMER_PENDING_INTACT_LCMS",
            "cys_note": (
                "6 Cys in mature O95998[31..194] (Cys51, Cys64, Cys86, Cys89, Cys131, Cys150). Crystal structure PDB:7AL7 "
                "(PMC9111989) confirms 2 intramolecular disulfides, starts at residue 63 (omitting Cys51), and shows Cys131 "
                "forming a 2.21 A intermolecular disulfide with IL-18 Cys74; therefore PDB:7AL7 does NOT establish two free "
                "thiols in full-length isolated monomeric IL-18BP, and full-length monomeric free-thiol count awaits intact-protein LC-MS. "
                "Explicitly EXCLUDED from covalent zero-unpaired Cuff v2.0."
            ),
        },
    }

    profiles: dict[str, Any] = {}
    for rid, spec in disulfide_specs.items():
        require_cond(rid in fasta_records, f"Missing required FASTA record: {rid}")
        seq = fasta_records[rid][1]
        dstat = spec.get("disulfide_status", "EXPECTED_TOPOLOGY_PENDING_EXPRESSED_LCMS_ELLMAN_QC")
        bp = biophysical_profile(seq, n_disulfides=spec["ss"], disulfide_status=dstat)
        require_cond(bp["length_aa"] == spec["len"], f"{rid} length mismatch: {bp['length_aa']} != {spec['len']}")
        require_cond(bp["expected_unpaired_cys"] == spec["unp"], f"{rid} expected unpaired Cys mismatch: {bp['expected_unpaired_cys']} != {spec['unp']}")
        if "max_met" in spec:
            require_cond(bp["met_count"] <= spec["max_met"], f"{rid} Met violation: {bp['met_count']}")
        if "max_trp" in spec:
            require_cond(bp["trp_count"] <= spec["max_trp"], f"{rid} Trp violation: {bp['trp_count']}")
        entry: dict[str, Any] = {"group": spec["group"], "role": spec["role"], "sha256": sha256_str(seq), "biophysics": bp}
        if "cys_note" in spec:
            entry["cys_bookkeeping_note"] = spec["cys_note"]
        profiles[rid] = entry

    intein_vs_esrta = {}
    for label, core_id, lpet_id in (
        ("sCR1_v2", "sCR1_v2_CSL040_LHR_ABC_Intein0aa", "sCR1_v2_CSL040_LHR_ABC_GGS_LPETG"),
        ("THBD_M406L_CSnull", "THBD_363_497_M406L_S490A_S492A_Intein0aa", "THBD_363_497_M406L_S490A_S492A_GGS_LPETG_CSnull"),
        ("CD200_ECD", "CD200_ECD_Intein0aa", "CD200_ECD_GGS_LPETG"),
    ):
        core_seq = fasta_records[core_id][1]
        lpet_seq = fasta_records[lpet_id][1]
        require_cond(lpet_seq == core_seq + "GGSLPETG", f"{lpet_id} must equal {core_id} + GGSLPETG")
        post_esrta = core_seq + "GGSLPETGGG"
        n_lpet_foreign = count_non_native_junction_kmers(core_seq, post_esrta)
        n_intein_foreign = count_non_native_junction_kmers(core_seq, core_seq)
        require_cond(n_lpet_foreign == 40 and n_intein_foreign == 0, f"{label} junction kmer audit mismatch: {n_lpet_foreign}/{n_intein_foreign}")
        intein_vs_esrta[label] = {
            "esrta_LPET_GGG_foreign_8_11mers": n_lpet_foreign,
            "split_intein_0aa_foreign_8_11mers": n_intein_foreign,
            "scope_note": "Sequence-level specification only; conjugation yield, residual unreacted species, and orientation require wet-lab CMC.",
        }

    return {
        "fasta_relpath": "data/constructs/openislet_foundry_v2_cuff_v2_and_shield_fc_v0.9.0.fasta",
        "fasta_sha256": actual_sha,
        "record_count": len(fasta_records),
        "cmc_pruned_core_covalent_cuff_proteins": 3,
        "core_3_proteins": [
            "sCR1_v2 (3.4 kDa PEG)",
            "THBD-M406L (3.4 kDa PEG; CS-null lead + CS+ comparator)",
            "CD200-ECD (20 kDa PEG spacer; steric reach vs ~70 nm sCR1 rod pending functional co-immobilization assay)",
        ],
        "peg_20kda_steric_reach_disclosure": (
            "A 20 kDa PEG chain contour length (~126 nm fully extended) does NOT establish a 70 nm functional reach in solution "
            "(Flory/random-coil radius ~7-10 nm); co-immobilized CD200R accessibility alongside sCR1_v2 is a mandatory Gate-34 functional requirement."
        ),
        "cfh_19_445_permanently_retired_from_primary_cuff": True,
        "adipoq_hexa_fasl_permanently_retired": True,
        "zero_expected_unpaired_ecd_cys_scope": (
            "STRICTLY SCOPED to the 2 Fc heterodimer chains (14 Cys = 7 expected SS in dimer) + 3 core immobilized Cuff v2.0 proteins "
            "(sCR1_v2: 84 Cys = 42 SS; THBD-M406L: 18 Cys = 9 SS; CD200-ECD: 6 Cys = 3 SS; plus archived CFH[19-445] & optional CCL22) "
            "as reference-domain topology expectations pending expressed non-reducing LC-MS / Ellman free-thiol QC. "
            "Explicitly EXCLUDES non-core soluble companions IL1RN (4 Cys monomeric free thiols) and IL18BP (6 Cys: PDB:7AL7 starts at "
            "residue 63 omitting Cys51, shows 2 intramolecular SS, and forms a 2.21 A intermolecular disulfide between Cys131 and IL-18 Cys74 — "
            "full-length monomeric free-thiol count awaits intact-protein LC-MS)."
        ),
        "split_intein_0aa_co_lead_vs_esrta_kmer_audit": intein_vs_esrta,
        "construct_profiles": profiles,
    }


# ---------------------------------------------------------------------------
# PART D: InvVax Evidence Fidelity, Clean H3 Sensitivity, & Exact <1e-12 Parity
# ---------------------------------------------------------------------------
def biv_bern(p1: float, p2: float, phi: float) -> dict[tuple[int, int], float]:
    require_cond(0.0 <= p1 <= 1.0 and 0.0 <= p2 <= 1.0 and 0.0 <= phi <= 1.0, f"Invalid biv_bern inputs: {p1},{p2},{phi}")
    p11 = (1.0 - phi) * (p1 * p2) + phi * min(p1, p2)
    out = {
        (0, 0): max(0.0, 1.0 - p1 - p2 + p11),
        (1, 0): max(0.0, p1 - p11),
        (0, 1): max(0.0, p2 - p11),
        (1, 1): max(0.0, p11),
    }
    require_cond(abs(sum(out.values()) - 1.0) < 1e-12, "biv_bern mass conservation error")
    return out


def frechet_joint(probs: list[float], phi: float) -> list[float]:
    m = len(probs)
    require_cond(0.0 <= phi <= 1.0 and all(0.0 <= p <= 1.0 for p in probs), "Invalid frechet_joint inputs")
    n_states = 1 << m
    d_ind = [0.0] * n_states
    for mask in range(n_states):
        w = 1.0
        for i in range(m):
            w *= probs[i] if (mask & (1 << i)) else (1.0 - probs[i])
        d_ind[mask] = w
    if phi == 0.0:
        return d_ind
    order = sorted(range(m), key=lambda i: probs[i])
    d_pos = [0.0] * n_states
    prev = 0.0
    for idx, i in enumerate(order):
        w = probs[i] - prev
        if w > 0.0:
            d_pos[sum(1 << j for j in order[idx:])] += w
        prev = probs[i]
    d_pos[0] += 1.0 - prev
    out = [(1.0 - phi) * d_ind[s] + phi * d_pos[s] for s in range(n_states)]
    require_cond(abs(sum(out) - 1.0) < 1e-12, "frechet_joint mass conservation error")
    return out


def frechet_couple(base_dist: list[float], u_new: float, phi: float, event_fn: Callable[[int], bool]) -> list[float]:
    n0 = len(base_dist)
    require_cond(0.0 <= u_new <= 1.0 and 0.0 <= phi <= 1.0, "Invalid frechet_couple inputs")
    p_e1 = sum(base_dist[mi] for mi in range(n0) if event_fn(mi))
    p_e0 = 1.0 - p_e1
    d_ind = [0.0] * (2 * n0)
    for mi in range(n0):
        w = base_dist[mi]
        d_ind[mi] = w * (1.0 - u_new)
        d_ind[mi | n0] = w * u_new
    d_pos = [0.0] * (2 * n0)
    p11 = min(p_e1, u_new)
    p10 = p_e1 - p11
    p01 = max(0.0, u_new - p_e1)
    p00 = p_e0 - p01
    for mi in range(n0):
        w = base_dist[mi]
        if w == 0.0:
            continue
        if event_fn(mi):
            frac = w / p_e1 if p_e1 > 0 else 0.0
            d_pos[mi] = p10 * frac
            d_pos[mi | n0] = p11 * frac
        else:
            frac = w / p_e0 if p_e0 > 0 else 0.0
            d_pos[mi] = p00 * frac
            d_pos[mi | n0] = p01 * frac
    out = [(1.0 - phi) * d_ind[k] + phi * d_pos[k] for k in range(2 * n0)]
    require_cond(abs(sum(out) - 1.0) < 1e-12, "frechet_couple mass conservation error")
    return out


def strassen_bipartite_bounds(
    v_h123: list[float],
    dh4: list[float],
    routes: tuple[str, ...],
    cell_classes: tuple[str, ...],
    compat_map: dict[str, frozenset[str]],
) -> tuple[float, float]:
    n = len(routes)
    all_routes = sorted(set(routes))
    r_idx = {r: k for k, r in enumerate(all_routes)}
    cell_groups: dict[int, float] = {}
    for mc, wc in enumerate(v_h123):
        if wc == 0.0:
            continue
        rmask = 0
        for i in range(n):
            if (mc >> i) & 1:
                for r in compat_map[cell_classes[i]]:
                    if r in r_idx:
                        rmask |= 1 << r_idx[r]
        cell_groups[rmask] = cell_groups.get(rmask, 0.0) + wc
    route_groups: dict[int, float] = {}
    for mh, wh in enumerate(dh4):
        if wh == 0.0:
            continue
        rmask = 0
        for j in range(n):
            if (mh >> j) & 1:
                rmask |= 1 << r_idx[routes[j]]
        route_groups[rmask] = route_groups.get(rmask, 0.0) + wh
    c_keys, r_keys = list(cell_groups.keys()), list(route_groups.keys())
    c_vals, r_vals = [cell_groups[k] for k in c_keys], [route_groups[k] for k in r_keys]
    max_def_e = 0.0
    max_def_ec = 0.0
    for sm in range(1 << len(c_keys)):
        p_s = 0.0
        neigh_e = [False] * len(r_keys)
        neigh_ec = [False] * len(r_keys)
        for i in range(len(c_keys)):
            if (sm >> i) & 1:
                p_s += c_vals[i]
                cm = c_keys[i]
                for j, rm in enumerate(r_keys):
                    if (cm & rm) != 0:
                        neigh_e[j] = True
                    else:
                        neigh_ec[j] = True
        p_ne = sum(r_vals[j] for j in range(len(r_keys)) if neigh_e[j])
        p_nec = sum(r_vals[j] for j in range(len(r_keys)) if neigh_ec[j])
        if p_s - p_ne > max_def_e:
            max_def_e = p_s - p_ne
        if p_s - p_nec > max_def_ec:
            max_def_ec = p_s - p_nec
    return max(0.0, max_def_ec) * 100.0, min(1.0, 1.0 - max_def_e) * 100.0