OpenIslet

scripts/verify_iip0044_foundry_v1_3_biologics.py

IIP-0044 / DEC-123 (CAND-035 / EXP-032): OpenIslet Foundry v1.3 Clean-Room

script Release v0.8.0 gen-eb955f8266035aba 619 KB · 44 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_iip0044_foundry_v1_3_biologics.py · SHA-256: 1d6c53a0817f6254…

                        "min_replicates_n": 3,
                        "ic50_pass_u95_max_nm": 100.0,
                        "ic50_fail_l95_gt_nm": 500.0,
                        "selectivity_pass_l95_min_fold": 50.0,
                        "selectivity_fail_u95_lt_fold": 10.0,
                    },
                    {
                        "analyte_id": "HLA-DQ2.2 + HIP11",
                        "required": True,
                        "min_replicates_n": 3,
                        "ic50_pass_u95_max_nm": 100.0,
                        "ic50_fail_l95_gt_nm": 500.0,
                        "selectivity_pass_l95_min_fold": 50.0,
                        "selectivity_fail_u95_lt_fold": 10.0,
                    },
                    {
                        "analyte_id": "HLA-DQ8 + native WT InsB:9-23",
                        "peptide_sequence": "SHLVEALYLVCGERG",
                        "required": True,
                        "min_replicates_n": 3,
                        "ic50_pass_u95_max_nm": 100.0,
                        "ic50_fail_l95_gt_nm": 500.0,
                        "selectivity_pass_l95_min_fold": 50.0,
                        "selectivity_fail_u95_lt_fold": 10.0,
                    },
                ],
                "mandatory_component1_off_target_spr_analytes_iip0044": list(_SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS),
                "typed_evidence_contract": {
                    "scalar_summaries_without_typed_records_rejected": True,
                    "expression_batch_linkage_required_every_assay_block": True,
                    "construct_bound_expression_batch_provenance_enforced": True,
                    "empty_construct_batches_rejected": True,
                    "invalid_or_unregistered_spr_rows_excluded_from_bio_fail": True,
                    "order_independent_canonical_key_uniqueness_enforced": True,
                    "mandatory_typed_t1d_donor_eligibility_enforced": True,
                    "preregistered_donor_family_roster_mandatory": True,
                    "preregistered_donor_family_roster_sha256_verified": True,
                    "gy018_independence_justification_mandatory": True,
                    "suppression_student_t_authorizing": False,
                    "suppression_confirmatory_min_donors_n": _SHIELD_MIN_CONFIRMATORY_DONORS_N,
                    "required_donor_clinical_cohort": "T1D",
                    "min_distinct_referenced_expression_batches_n": 3,
                    "min_distinct_linked_comp1_batches_n": 3,
                    "min_distinct_linked_comp2_batches_n": 3,
                    "qualifying_t1d_donor_hla_dq_allowlist": ["HLA-DQ2.5", "HLA-DQ8", "HLA-DQ8-trans", "HLA-DQ2.2"],
                    "sec_mals_dls_quantitative_pass_thresholds": {
                        "comp1_monomer_pct_min": 95.0,
                        "comp2_monomer_pct_min": 95.0,
                        "cocktail_1to1_monomer_pct_min": 95.0,
                        "dls_pdi_max": 0.15,
                        "no_aggregates_or_precipitation_required": True,
                    },
                    "physical_1jk8_reagent_policy": "Physical 14-aa 1JK8 synthetic control reagent is optional in register_qc_records (omitting crystal_ref_1jk8_14aa OR setting crystal_ref_1jk8_14aa to JSON null both PASS; any non-null value is validated strictly).",
                },
                "mandatory_reagent_qc": "QC covering HLA-DQ2.5 / HLA-DQ8-trans / HLA-DQ2.2 + HIP11 and HLA-DQ8 + WT InsB:9-23 (SHLVEALYLVCGERG), 14-aa 1JK8 (LVEALYLVCGERGG), and 12-aa 6DFX p8E9E (VEELYLVAGEEG).",
                "register_and_peptide_identity_spec": {
                    "deposited_crystal_reference_1jk8": {
                        "pdb_id": "1JK8",
                        "chain": "C",
                        "sequence": "LVEALYLVCGERGG",
                        "length_aa": 14,
                        "role": "DEPOSITED_CRYSTAL_REFERENCE_INSB11_23_PLUS_G",
                    },
                    "modeled_native_target_wt_insb9_23": {
                        "uniprot_anchor": "P01308[33..47]",
                        "sequence": "SHLVEALYLVCGERG",
                        "length_aa": 15,
                        "role": "NATIVE_HUMAN_WT_INSB9_23_TARGET",
                    },
                    "engineered_register3_comparator_6dfx": {
                        "pdb_id": "6DFX",
                        "sequence": "VEELYLVAGEEG",
                        "length_aa": 12,
                        "role": "ENGINEERED_REGISTER3_MIMOTOPE_COMPARATOR",
                    },
                },
                "mandatory_component2_bench_controls_iip0044": {
                    "control_1_off_target_spr_analytes": [
                        "HLA-DQ8 + CLIP1",
                        "HLA-DQ8 + DQ8-glia-gamma1a",
                        "HLA-DQ8-trans + WT InsB:9-23",
                    ],
                    "control_2_secmals_dls_monomer_and_coformulation": (
                        "SEC-MALS / DLS monomer and 1:1 co-formulation homodimer screen (Protenix-v1 0.6691) "
                        "for IsletSHIELD_Comp2_T006 and IsletSHIELD_QF09_pI2."
                    ),
                    "control_3_parallel_comparator_and_register_screen": {
                        "parallel_comparators": [
                            "IsletSHIELD_Comp2_T006",
                            "SHIELD2_QQ",
                            "R3_shv2_stk1",
                            "SH2_MP01",
                            "SH2_MP06",
                            "SH2_MP08",
                        ],
                        "register_controls": [
                            "15-aa WT InsB:9-23 (SHLVEALYLVCGERG)",
                            "14-aa 1JK8 chain C (LVEALYLVCGERGG)",
                            "12-aa 6DFX p8E9E (VEELYLVAGEEG)",
                        ],
                    },
                },
                "decision_precedence_table": {
                    "pre_adjudication_nonfinite_rejection": "Non-finite inputs raise ValueError before decision precedence.",
                    "precedence_order": list(_EXPECTED_SHIELD_SPR_PRECEDENCE_LIST),
                },
                "cytotoxicity_confidence_unit_specification": {
                    "min_n_eff_per_donor": 60,
                    "exact_deff_equality_zero_tolerance": True,
                    "exact_deff_preserved_as_decimal_from_json": True,
                    "invalid_donors_excluded_from_confidence_bounds": True,
                    "cytotoxicity_estimand": _SHIELD_CYTO_ESTIMAND,
                    "simultaneous_fwer_alpha": 0.05,
                    "per_donor_bonferroni_alpha_formula": "0.05 / N_roster",
                    "fixed_preexclusion_family_denominator_enforced": True,
                    "preregistered_donor_roster_mandatory": True,
                    "preregistered_donor_roster_sha256_verified": True,
                    "gy018_independence_justification_mandatory": True,
                    "suppression_estimand": _SHIELD_SUPPRESSION_ESTIMAND,
                    "suppression_inference_method": _SHIELD_SUPPRESSION_INFERENCE_METHOD,
                    "suppression_student_t_authorizing": False,
                    "cohort_t_lower_authorizing": False,
                    "gy018_denominator_compliance_rule": "Under GY-018, require exact design_effect_deff == 1.0 (zero tolerance, preserved as exact Decimal through strict JSON decoding), structured gy018_independence_justification, and n_eff == raw_independent_units_n >= 60, gating invalid/ineligible donors out of confidence bounds without shrinking N_roster.",
                    "observational_unit": "Primary human T1D donor APC biological replicate reconciled 100% against mandatory SHA-256-pinned preregistered_donor_family_roster",
                    "method": "Exact one-sided Clopper-Pearson Bonferroni lower bounds under fixed-roster global null H0_all: max_i p_i <= 5.0% at alpha_donor = 0.05 / N_roster (distribution-free FWER <= 0.05 conditional on external outcome-blind custody; Student-t is non-authorizing diagnostic only) over N_eff >= 60 effective APC events per donor",
                },
                "endpoints_and_3state_rules": [
                    {
                        "endpoint_id": "SHIELD_AFFINITY_AND_SELECTIVITY",
                        "thresholds_spec": {
                            "ic50_pass_u95_max_nm": 100.0,
                            "ic50_fail_l95_gt_nm": 500.0,
                            "selectivity_pass_l95_min_fold": 50.0,
                            "selectivity_fail_u95_lt_fold": 10.0,
                        },
                        "pass_rule": "U95(IC50) <= 100.0 nM AND L95(off_target_selectivity_ratio) >= 50.0x",
                        "fail_rule": "L95(IC50) > 500.0 nM OR U95(selectivity) < 10.0x",
                        "hold_rule": "HOLD for post-SPR v1.4 affinity/selectivity maturation",
                    },
                    {
                        "endpoint_id": "SHIELD_HUMAN_TCELL_BLOCKADE",
                        "pass_rule_spec": {
                            "logical_operator": "AND",
                            "suppression_estimand": _SHIELD_SUPPRESSION_ESTIMAND,
                            "suppression_inference_method": _SHIELD_SUPPRESSION_INFERENCE_METHOD,
                            "suppression_student_t_authorizing": False,
                            "suppression_confirmatory_min_donors_n": _SHIELD_MIN_CONFIRMATORY_DONORS_N,
                            "suppression_responder_l95_clopper_pearson_min_pct": 70.0,
                            "suppression_anti_enhancement_min_pct": 0.0,
                            "suppression_cohort_mean_min_pct": 70.0,
                            "observed_offtarget_apc_cytotoxicity_exact_pct": 0.0,
                            "offtarget_apc_cytotoxicity_u95_max_pct": 5.0,
                            "min_n_eff_per_donor": 60,
                            "fail_logical_operator": "OR",
                            "fail_suppression_nonresponder_lt_40pct_l95_clopper_pearson_gt_pct": 60.0,
                            "fail_offtarget_apc_cytotoxicity_l95_gt_pct": 5.0,
                            "preregistered_donor_roster_mandatory": True,
                            "per_donor_bonferroni_alpha_formula": "0.05 / N_roster",
                            "nonzero_u95_gt_5pct_hold_state": "HOLD_CYTOTOXICITY_U95_EXCEEDS_5PCT",
                            "nonzero_cytotoxicity_hold_state": "HOLD_OBSERVED_NONZERO_CYTOTOXICITY",
                        },
                        "pass_rule": "100% reconciled SHA-256-pinned preregistered_donor_family_roster AND exact Clopper-Pearson suppression responder L95_CP(k_ge_70, N_roster) >= 70.0% (min N_roster=9) AND anti-enhancement min_donor_suppression >= 0.0% AND cohort mean >= 70.0% AND 0% observed off-target APC cytotoxicity AND off-target APC cytotoxicity U95 <= 5.0%",
                        "fail_rule": "exact Clopper-Pearson suppression non-responder L95_CP(k_lt_40, N_roster) > 60.0% OR off-target APC cytotoxicity fixed-roster Bonferroni lower bound simultaneous_worst_donor_bonferroni_lower_pct > 5.0% (H0_all: max_i p_i <= 5.0%, FWER <= 0.05 at alpha_donor = 0.05 / N_roster; Student-t is non-authorizing diagnostic only)",
                        "hold_rule": "If no FAIL: observed off-target APC cytotoxicity > 0% with calibrated simultaneous lower <= 5.0% AND U95 > 5.0% -> HOLD_CYTOTOXICITY_U95_EXCEEDS_5PCT; observed off-target APC cytotoxicity > 0% while U95 <= 5.0% -> HOLD_OBSERVED_NONZERO_CYTOTOXICITY",
                    },
                ],
            }
        }
    }
    md = (
        "### 2.2 `Gate 30-SHIELD-SPR` (2-component Islet-SHIELD cocktail: IsletSHIELD_QF09_pI2 + IsletSHIELD_Comp2_T006)\n"
        "- `n >= 3` independent E. coli expression batches with non-empty `construct_ids` and construct-bound `expression_batch_ids` linkage requiring `>= 3` distinct linked passing Comp1 batches and `>= 3` distinct linked passing Comp2 batches across all four mandatory on-target complexes: HLA-DQ2.5 + HIP11, HLA-DQ8-trans + HIP11, HLA-DQ2.2 + HIP11, HLA-DQ8 + 15-aa native WT InsB:9-23 (SHLVEALYLVCGERG).\n"
        "- Separated reagents: optional physical 14-aa PDB 1JK8 chain C (LVEALYLVCGERGG, omitting `crystal_ref_1jk8_14aa` or setting JSON `null` both PASS; non-null validated strictly), 15-aa native WT InsB:9-23 (SHLVEALYLVCGERG), 12-aa 6DFX p8E9E (VEELYLVAGEEG).\n"
        "- Mandatory Comp1 + Comp2 controls (with construct-bound expression_batch_ids linkage): HLA-DQ2.5 + CLIP1, HLA-DQ2.5 + Self_IGKV2_EAED, HLA-DQ2.5 + cel_glutenin_L1, HLA-DQ8-trans + Cpep_Nterm_EAED; "
        "HLA-DQ8 + CLIP1, HLA-DQ8 + DQ8-glia-gamma1a, HLA-DQ8-trans + WT InsB:9-23; "
        "SEC-MALS / DLS monomer (>= 95.0%, dls_pdi <= 0.15) & 1:1 co-formulation homodimer test (Protenix-v1 0.6691); "
        "parallel screen of IsletSHIELD_Comp2_T006, SHIELD2_QQ, R3_shv2_stk1, SH2_MP01, SH2_MP06, SH2_MP08.\n"
        "- 0. Pre-adjudication non-finite inputs raise ValueError before decision precedence.\n"
        "- 1. `FAIL`: `L95(IC50) > 500.0 nM` OR `U95(off-target selectivity) < 10.0x` OR `L95_CP(k_lt_40, N_roster) > 60.0%` OR off-target APC cytotoxicity fixed-roster Bonferroni lower bound `simultaneous_worst_donor_bonferroni_lower_pct > 5.0%` under `H0_all: max_i p_i <= 5.0%` (distribution-free FWER <= 0.05 at `alpha_donor = 0.05 / N_roster` bound to mandatory SHA-256-pinned `preregistered_donor_family_roster` with `roster_sha256`; Student-t is non-authorizing diagnostic only).\n"
        "- 2. `HOLD_INVALID_OR_MISSING_INPUT`: missing typed evidence, missing/tampered/incomplete `preregistered_donor_family_roster` (`roster_sha256`), duplicate/conflicting canonical keys, invalid/unregistered SPR rows, missing/contradictory typed T1D donor eligibility (`t1d_diagnosis_confirmed=True`, `donor_clinical_cohort='T1D'`, non-empty unpadded `t1d_prequalification_ref`), missing hla_genotype, missing `gy018_independence_justification`, GY-018 violation (exact `design_effect_deff == 1.0` with zero tolerance preserved as exact `Decimal` from JSON), or `N_eff < 60`.\n"
        "- 3. `HOLD_CYTOTOXICITY_U95_EXCEEDS_5PCT`: observed off-target APC cytotoxicity `> 0%` with calibrated simultaneous lower `<= 5.0%` AND conservative `U95 > 5.0%`.\n"
        "- 4. `HOLD_OBSERVED_NONZERO_CYTOTOXICITY`: observed off-target APC cytotoxicity `> 0%` while `U95 <= 5.0%`.\n"
        "- 5. `HOLD`: post-SPR v1.4 maturation.\n"
        "- 6. `PASS`: `U95(IC50) <= 100.0 nM` AND `L95(off-target selectivity) >= 50.0x`; `L95_CP(k_ge_70, N_roster) >= 70.0%` AND `min_donor_suppression >= 0.0%` AND `0%` observed off-target APC cytotoxicity AND `U95 <= 5.0%`.\n"
        "- Confidence unit: exact Clopper-Pearson over `N_eff >= 60` per donor under GY-018 (exact `design_effect_deff == 1.0`, zero tolerance preserved as exact `Decimal` through JSON decoding; structured `gy018_independence_justification`; mandatory SHA-256-pinned `preregistered_donor_family_roster` with `alpha_donor = 0.05 / N_roster` and `H0_all`; Student-t is non-authorizing diagnostic only).\n"
    )
    return sc, md


def run_iip0042_alignment_self_tests() -> dict[str, Any]:
    unaligned_sc = json.dumps({"hold_rule": "Intermediate affinity (100-500 nM) -> HOLD for v1.3 affinity maturation"})
    unaligned_md = "### 2.2 Gate 30-SHIELD-SPR\nTest HLA-DQ2.5/HIP11 and 3 off-target look-alikes.\n"
    res_unaligned = evaluate_iip0042_alignment(unaligned_sc, unaligned_md)
    require_cond(res_unaligned["aligned"] is False, "Alignment checker must reject unaligned pre-S5 IIP-0042 payload")

    sc_good, md_good = _sample_aligned_iip0042_pair()
    res_aligned = evaluate_iip0042_alignment(json.dumps(sc_good), md_good)
    require_cond(res_aligned["aligned"] is True, f"Alignment checker must accept aligned payload: {res_aligned['gaps']}")

    # Independent mutation test 1: remove Comp2 controls from side-contract JSON ONLY -> MUST FAIL!
    sc_drop_ctrl = json.loads(json.dumps(sc_good))
    sc_drop_ctrl["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_component2_bench_controls_iip0044"]["control_1_off_target_spr_analytes"] = []
    res_drop_sc = evaluate_iip0042_alignment(json.dumps(sc_drop_ctrl), md_good)
    require_cond(res_drop_sc["aligned"] is False and "sc_ctrl1_all_3_offtarget_analytes" in res_drop_sc["gaps"], "Must fail when Comp2 controls are deleted from side contract JSON only")

    # Independent mutation test 2: remove 0% observed cytotoxicity from protocol MD ONLY -> MUST FAIL!
    md_drop_cyto = md_good.replace("`0%` observed off-target APC cytotoxicity AND ", "")
    res_drop_md = evaluate_iip0042_alignment(json.dumps(sc_good), md_drop_cyto)
    require_cond(res_drop_md["aligned"] is False and "md_unified_cytotoxicity_pass_and_hold_tiebreak" in res_drop_md["gaps"], "Must fail when 0% cytotoxicity rule is deleted from protocol MD only")

    # Independent mutation test 3: omit HLA-DQ2.2 from side contract -> MUST FAIL!
    sc_drop_dq22 = json.loads(json.dumps(sc_good))
    sc_drop_dq22["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_on_target_spr_analytes"] = [
        "HLA-DQ2.5 + HIP11", "HLA-DQ8-trans + HIP11", "HLA-DQ8 + native WT InsB:9-23 (15-aa SHLVEALYLVCGERG)"
    ]
    res_drop_dq22 = evaluate_iip0042_alignment(json.dumps(sc_drop_dq22), md_good)
    require_cond(res_drop_dq22["aligned"] is False and "sc_all_4_mandatory_on_target_analytes_and_qc" in res_drop_dq22["gaps"], "Must fail when HLA-DQ2.2 is omitted")

    # Independent mutation test 4: omit HLA-DQ2.5 + HIP11 from JSON -> MUST FAIL!
    sc_drop_dq25 = json.loads(json.dumps(sc_good))
    sc_drop_dq25["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_on_target_spr_analytes"] = [
        "HLA-DQ8-trans + HIP11", "HLA-DQ2.2 + HIP11", "HLA-DQ8 + native WT InsB:9-23 (15-aa SHLVEALYLVCGERG)"
    ]
    res_drop_dq25 = evaluate_iip0042_alignment(json.dumps(sc_drop_dq25), md_good)
    require_cond(res_drop_dq25["aligned"] is False and "sc_all_4_mandatory_on_target_analytes_and_qc" in res_drop_dq25["gaps"], "Must fail when HLA-DQ2.5 + HIP11 is omitted from JSON")

    # Independent mutation test 5: flip AND -> OR in JSON alone -> MUST FAIL!
    sc_or_json = json.loads(json.dumps(sc_good))