OpenIslet

scripts/verify_iip0055_hygiene_safecell_minifh_orthogonality.py

OpenIslet Wave-6 W6-C1 (Provisional IIP-0055 / DEC-136 / GATE-34 / GY-033;

script Release v0.8.0 gen-eb955f8266035aba 417 KB · 30 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_iip0055_hygiene_safecell_minifh_orthogonality.py · SHA-256: d5b98e2ba1310333…

    # Construct-bound cHS4 FI VEZF1 bundles (unqualified HOLD vs archived-barrier-passed SYNTHETIC_SELF_TEST_PASS)
    chs4_hold_p, chs4_hold_s = make_valid_gate32_bundle("Y", evidence_tier="SYNTHETIC_FIXTURE", include_chs4_fi=True, include_chs4_barrier_pass=False, arm_manifest=arm_manifest)
    chs4_pass_p, chs4_pass_s = make_valid_gate32_bundle("Y", evidence_tier="SYNTHETIC_FIXTURE", include_chs4_fi=True, include_chs4_barrier_pass=True, arm_manifest=arm_manifest)
    chs4_lie_p = json.loads(json.dumps(chs4_hold_p))
    chs4_lie_p["uses_unqualified_chs4_fi_vezf1_variant"] = False

    # Authenticated archived wet-lab contract check (separate from synthetic fixtures!)
    wetlab_a, wetlab_store_a = make_valid_gate32_bundle("A", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", arm_manifest=arm_manifest)
    wetlab_y, wetlab_store_y = make_valid_gate32_bundle("Y", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", arm_manifest=arm_manifest)
    wetlab_d, wetlab_store_d = make_valid_gate32_bundle("D", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", arm_manifest=arm_manifest)
    wetlab_z, wetlab_store_z = make_valid_gate32_bundle("Z", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", arm_manifest=arm_manifest)
    wetlab_y_bank_only, wetlab_store_y_bank_only = make_valid_gate32_bundle(
        "Y", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", gate0v_scope="BANK_QUALIFICATION_ONLY", arm_manifest=arm_manifest
    )
    wetlab_chs4_p, wetlab_chs4_s = make_valid_gate32_bundle(
        "Y", evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", include_chs4_fi=True, include_chs4_barrier_pass=True, arm_manifest=arm_manifest
    )

    def _mut(src: Dict[str, Any], updates: Dict[str, Any]) -> Dict[str, Any]:
        c = json.loads(json.dumps(src))
        c.update(updates)
        return c

    def _drop(src: Dict[str, Any], key: str) -> Dict[str, Any]:
        c = json.loads(json.dumps(src))
        c.pop(key, None)
        return c

    def _with_resealed_record(src: Dict[str, Any], store: Dict[str, Dict[str, Any]], rec_key: str, rec_muts: Dict[str, Any]) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
        c = json.loads(json.dumps(src))
        s = json.loads(json.dumps(store))
        rec = dict(c[rec_key])
        rec.update(rec_muts)
        sealed = seal_upstream_evidence_record_v1(rec)
        c[rec_key] = sealed
        s[sealed["archive_sha256"]] = sealed
        return c, s

    def _with_resealed_func_assays(
        src: Dict[str, Any], store: Dict[str, Dict[str, Any]], mutate_fn: Callable[[Dict[str, Any]], None]
    ) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
        c = json.loads(json.dumps(src))
        s = json.loads(json.dumps(store))
        mutate_fn(c["functional_assays"])
        rec = json.loads(json.dumps(c["current_functional_assays_record"]))
        mutate_fn(rec["functional_assays"])
        sealed = seal_upstream_evidence_record_v1(rec)
        c["current_functional_assays_record"] = sealed
        s[sealed["archive_sha256"]] = sealed
        return c, s

    def _with_resealed_h2h(
        src: Dict[str, Any], store: Dict[str, Dict[str, Any]], mutate_fn: Callable[[Dict[str, Any], Dict[str, Any]], None]
    ) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
        c = json.loads(json.dumps(src))
        s = json.loads(json.dumps(store))
        h2h = c["functional_assays"]["hypoxic_kill_and_cleavage"]["head_to_head_switch_comparator"]
        arch = json.loads(json.dumps(h2h["archived_benchmark_record"]))
        mutate_fn(h2h, arch)
        sealed = seal_upstream_evidence_record_v1(arch)
        h2h["archived_benchmark_record"] = sealed
        s[sealed["archive_sha256"]] = sealed
        return c, s

    g0v_3lin_p, g0v_3lin_s = _with_resealed_record(base_d, store_d, "gate0v_5lineage_record", {"lineages_verified": ["beta", "alpha", "delta"]})
    g5_forged_p, g5_forged_s = _with_resealed_record(base_y, store_y, "gate5_panlineage_clonogenic_record", {"u95_exact": 1.0e-12})
    g5_k10_p, g5_k10_s = _with_resealed_record(
        base_y, store_y, "gate5_panlineage_clonogenic_record",
        {"tested_cells_n": 100_000, "survivor_count_k": 10, "clonogenic_fraction_f": 1.0, "spike_in_detection_efficiency_eta": 1.0, "effective_clonogenic_trials_n_eff": 100_000, "u95_exact": 1.0e-4},
    )
    g5_k5_p, g5_k5_s = _with_resealed_record(
        base_y, store_y, "gate5_panlineage_clonogenic_record",
        {"tested_cells_n": 100_000, "survivor_count_k": 5, "clonogenic_fraction_f": 1.0, "spike_in_detection_efficiency_eta": 1.0, "effective_clonogenic_trials_n_eff": 100_000, "u95_exact": 1.0e-4},
    )
    # 75-digit Decimal Clopper-Pearson 10^12 acute potency (U95 <= 1e-4) boundaries on hypoxic/normoxic assays
    u_1e12_52 = clopper_pearson_u95(99_983_552, 10**12, alpha=0.05)
    hk_1e12_pass_p, hk_1e12_pass_s = _with_resealed_func_assays(
        wetlab_y, wetlab_store_y,
        lambda fa_d: (
            fa_d["hypoxic_kill_and_cleavage"].update({"cells_assayed": 10**12, "survivors_observed": 99_983_552, "hypoxic_escape_u95": u_1e12_52}),
            fa_d["hypoxic_kill_and_cleavage"]["matched_normoxic_comparator"].update({"cells_assayed": 10**12, "survivors_observed": 99_983_552, "normoxic_escape_u95": u_1e12_52}),
        ),
    )
    hk_1e12_fail_p, hk_1e12_fail_s = _with_resealed_func_assays(
        wetlab_y, wetlab_store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"cells_assayed": 10**12, "survivors_observed": 99_983_553, "hypoxic_escape_u95": 1.0e-4}),
    )
    hk_1005m_fail_p, hk_1005m_fail_s = _with_resealed_func_assays(
        wetlab_y, wetlab_store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"cells_assayed": 1_005_216_927, "survivors_observed": 100_000, "hypoxic_escape_u95": 1.0e-4}),
    )
    g0v_zero_sha_p = json.loads(json.dumps(wetlab_d))
    g0v_zero_sha_p["gate0v_5lineage_record"]["archive_sha256"] = ZERO_SHA256
    d_allo_bank_p, d_allo_bank_s = _with_resealed_record(wetlab_d, wetlab_store_d, "gate0v_5lineage_record", {"bank_origin": "allogeneic_hiPSC"})
    d_cross_allo_g0v_p, d_cross_allo_g0v_s = _with_resealed_record(wetlab_d, wetlab_store_d, "gate0v_5lineage_record", {"decision": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE"})
    y_cross_auto_g0v_p, y_cross_auto_g0v_s = _with_resealed_record(wetlab_y, wetlab_store_y, "gate0v_5lineage_record", {"decision": "PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL"})

    # 3-way comparator negative probes (drop D315A & mismatched run_id)
    h2h_drop_d315a = json.loads(json.dumps(base_y))
    h2h_drop_d315a["functional_assays"]["hypoxic_kill_and_cleavage"]["head_to_head_switch_comparator"]["comparator_arms_benchmarked"] = ["TBP_iCasp9_WT", "ACTB_iCasp8"]
    h2h_bad_run = json.loads(json.dumps(base_y))
    h2h_bad_run["functional_assays"]["hypoxic_kill_and_cleavage"]["head_to_head_switch_comparator"]["per_arm_observations"]["TBP_iCasp9_D315A"]["run_id"] = "DIFFERENT_RUN_999"

    # Barrier construct-ID digest mismatch probe (Audit F2): tested_construct_id points to another construct whose registered digest != cHS4_0C9!
    chs4_wrong_cid_p, chs4_wrong_cid_s = _with_resealed_record(
        chs4_pass_p, chs4_pass_s, "chs4_barrier_assay_record",
        {"tested_construct_id": "V090_SAFECELL_TBP_CHR6_3UTR_IRES_ICASP9_WT_3380bp"},
    )

    hk_k10, hk_k10_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"survivors_observed": 10, "hypoxic_escape_u95": 1.0e-4}),
    )
    hk_2pct_o2, hk_2pct_o2_s = _with_resealed_func_assays(
        base_d, store_d,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"hypoxia_o2_pct": 2.0}),
    )
    hk_no_norm, hk_no_norm_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].pop("matched_normoxic_comparator", None),
    )
    hk_low_cleav, hk_low_cleav_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"caspase_cleavage_fold_vs_vehicle": 3.2}),
    )
    hk_high_basal, hk_high_basal_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["hypoxic_kill_and_cleavage"].update({"basal_leak_toxicity_pct": 4.5}),
    )
    pyro_fail, pyro_fail_s = _with_resealed_func_assays(
        base_d, store_d,
        lambda fa_d: fa_d["pyroptosis_and_cflip_clearance"].update({"il1beta_gsdmd_fold_vs_ctrl": 3.1}),
    )
    cflip_fail, cflip_fail_s = _with_resealed_func_assays(
        base_d, store_d,
        lambda fa_d: fa_d["pyroptosis_and_cflip_clearance"].update({"cflip_intact_kill_pct": 85.0}),
    )
    ms_fail, ms_fail_s = _with_resealed_func_assays(
        base_d, store_d,
        lambda fa_d: fa_d["pyroptosis_and_cflip_clearance"].update({"ms_immunopeptidomics_gmledgkkv_gssesqtl_clear": False}),
    )
    sb9_fail, sb9_fail_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["paired_dropin_functional_assays"].update({"serpinb9_h2o2_100uM_gzmb_inhibition_pct": 62.0}),
    )
    aav_hom_fail, aav_hom_fail_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["aav_vector_homogeneity"].update({"intact_itr_to_itr_homogeneity_pct": 91.5}),
    )
    lcms_fail, lcms_fail_s = _with_resealed_func_assays(
        base_y, store_y,
        lambda fa_d: fa_d["complement_expression_and_topology"].update({"disulfide_connectivity_lcms_verified": False}),
    )
    d_no_cohort, d_no_cohort_s = _with_resealed_func_assays(
        wetlab_d, wetlab_store_d,
        lambda fa_d: fa_d.pop("d1b_g32_04_autologous_cohort", None),
    )
    d_stage0_limited = json.loads(json.dumps(d_no_cohort))
    d_stage0_limited["evaluation_scope"] = "STAGE0_ONLY_NO_CLINICAL_PROMOTION"

    d_low_donors, d_low_donors_s = _with_resealed_func_assays(
        wetlab_d, wetlab_store_d,
        lambda fa_d: fa_d["d1b_g32_04_autologous_cohort"].update({"d1b_t1d_donor_count": 6}),
    )
    d_high_lysis, d_high_lysis_s = _with_resealed_func_assays(
        wetlab_d, wetlab_store_d,
        lambda fa_d: fa_d["d1b_g32_04_autologous_cohort"].update({"d1b_autologous_cd8_coculture_beta_lysis_pct": 22.0}),
    )

    # Mixed wet-lab top-level + synthetic upstream record MUST FAIL
    mixed_syn_p, mixed_syn_s = _with_resealed_record(
        wetlab_y, wetlab_store_y, "gate5_panlineage_clonogenic_record",
        {"evidence_tier": "SYNTHETIC_FIXTURE", "authority_scope": "SYNTHETIC_SELF_TEST", "bank_qualified": False, "promotion_authorized": False},
    )

    # Malformed R2-18 probes: list arm_id and 10**600 overflow int MUST return structured FAIL
    list_arm_p = _mut(base_y, {"arm_id": ["Y"]})
    overflow_int_p = _mut(base_y, {"modeled_phi_inc": 10**600})

    # Round-5 P0/P1/P2 closure probes (Review #1, #2, #3, #5, #10; Audit R4-01, R4-15)
    # 81. Registered TBP_iCasp9_WT fails (10/100k, 1x) while caller swaps uses_icasp9_d315a=True -> FAIL!
    def _fail_wt_obs(h2h_d: Dict[str, Any], arch_d: Dict[str, Any]) -> None:
        bad_wt = {
            "run_id": h2h_d["run_id"],
            "lot_id": h2h_d["lot_id"],
            "hypoxia_o2_pct": 1.0,
            "cells_assayed": 100_000,
            "survivors_observed": 10,
            "escape_u95": 0.00017,
            "caspase_cleavage_fold_vs_vehicle": 1.0,
        }
        h2h_d["per_arm_observations"]["TBP_iCasp9_WT"] = dict(bad_wt)
        arch_d["per_arm_observations"]["TBP_iCasp9_WT"] = dict(bad_wt)

    r5_swap_sw_p, r5_swap_sw_s = _with_resealed_h2h(wetlab_y, wetlab_store_y, _fail_wt_obs)
    r5_swap_sw_p["uses_icasp9_d315a"] = True
    r5_swap_sw_p["active_switch"] = "TBP_iCasp9_D315A"

    # 82. Arm A ISLET1_DESIGN_A_V090_TBP_CANDIDATE with chr19:AAVS1_iCasp9 locus in construct registry -> FAIL!
    a_bad_locus_reg = json.loads(json.dumps(wetlab_a["construct_manifest_record"]["switch_registry_by_id"]))
    a_bad_locus_reg["TBP::iCasp9"]["locus"] = "chr19:AAVS1_iCasp9"
    r5_a_aavs1_locus_p, r5_a_aavs1_locus_s = _with_resealed_record(
        wetlab_a, wetlab_store_a, "construct_manifest_record", {"switch_registry_by_id": a_bad_locus_reg}
    )

    # 83. Arm A ISLET1_DESIGN_A_V090_TBP_CANDIDATE declaring ACTB_CHR7_3UTR_IRES -> FAIL!
    r5_a_actb_p = _mut(wetlab_a, {"pan_lineage_switch_locus": "ACTB_CHR7_3UTR_IRES"})

    # 84. Lot registry containing only a non-switch item -> FAIL!
    nonsw_sha = sha256_str("SEQ:ONLY_NON_SWITCH_ITEM")
    r5_nonsw_p, r5_nonsw_s = _with_resealed_record(
        wetlab_y, wetlab_store_y, "construct_manifest_record",
        {
            "construct_ids": ["V090_NON_SWITCH_REPORTER_ONLY"],
            "sequence_sha256_by_construct_id": {"V090_NON_SWITCH_REPORTER_ONLY": nonsw_sha},
            "switch_registry_by_id": {},
        },
    )

    # 85. Dual-switch arm Y missing secondary B2M-/-_CDK1::HSV-TK in construct switch_registry_by_id -> FAIL!
    y_no_sec_reg = {k: v for k, v in wetlab_y["construct_manifest_record"]["switch_registry_by_id"].items() if v["role"] == "primary"}
    r5_y_nosec_p, r5_y_nosec_s = _with_resealed_record(
        wetlab_y, wetlab_store_y, "construct_manifest_record", {"switch_registry_by_id": y_no_sec_reg}
    )

    # 86. Dual-switch arm Z failing secondary CDK1::HSV-TK assay -> FAIL!
    r5_z_secfail_p, r5_z_secfail_s = _with_resealed_func_assays(
        wetlab_z, wetlab_store_z,
        lambda fa_d: fa_d["secondary_switch_cdk1_hsv_tk_assay"].update({"proliferating_ablation_pass": False}),
    )

    # 87-90. Supporting archive REJECTED_OR_HELD / BANK_QUALIFICATION_ONLY scopes MUST NEVER elevate to promotion!
    r5_cm_rej_p, r5_cm_rej_s = _with_resealed_record(wetlab_y, wetlab_store_y, "construct_manifest_record", {"authority_scope": "REJECTED_OR_HELD"})
    r5_cm_bank_p, r5_cm_bank_s = _with_resealed_record(wetlab_y, wetlab_store_y, "construct_manifest_record", {"authority_scope": "BANK_QUALIFICATION_ONLY"})
    r5_h2h_bank_p, r5_h2h_bank_s = _with_resealed_h2h(
        wetlab_y, wetlab_store_y, lambda _h, a: a.update({"authority_scope": "BANK_QUALIFICATION_ONLY"})
    )
    r5_bar_rej_p, r5_bar_rej_s = _with_resealed_record(wetlab_chs4_p, wetlab_chs4_s, "chs4_barrier_assay_record", {"authority_scope": "REJECTED_OR_HELD"})

    # 91-93. Contradictory adverse producer physical-qualification flags (Audit R4-01) -> immediate FAIL!
    r5_g0v_phys_p, r5_g0v_phys_s = _with_resealed_record(wetlab_y, wetlab_store_y, "gate0v_5lineage_record", {"physical_qualification_complete": False})
    r5_g0v_rel_p, r5_g0v_rel_s = _with_resealed_record(wetlab_y, wetlab_store_y, "gate0v_5lineage_record", {"release_authorizing": False})
    r5_g5_mod_p, r5_g5_mod_s = _with_resealed_record(wetlab_y, wetlab_store_y, "gate5_panlineage_clonogenic_record", {"modeled_qualification_only": True})

    # 94. Replacing inline functional-assay evidence_ref strings with unresolved string -> FAIL & all_required_archives_verified=False!
    r5_unref_fa_p = json.loads(json.dumps(wetlab_y))
    for _sec_k, _sec_v in r5_unref_fa_p["functional_assays"].items():
        if isinstance(_sec_v, dict) and "evidence_ref" in _sec_v:
            _sec_v["evidence_ref"] = "UNRESOLVED_SPOOFED_REF_999"