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…

                }
                for idx, rp in enumerate(sorted(EXPECTED_TIER2_CARVEOUT_RELPATHS))
            ]
        }
    }
    nested_rejected = False
    try:
        strip_verified_tier2_exclusion_manifest(json.dumps(bad_carve), "probe:nested_carveout")
    except RuntimeError:
        nested_rejected = True
    require_cond(nested_rejected, "Carve-out validator failed to reject nested dict in carveout_rationale")
    rejected["carveout_nested_dict_probe"] = nested_rejected
    return {"total_negative_probes": len(rejected), "all_rejected_fail_closed": True, "probes": rejected}


# =============================================================================
# Executable Typed Fail-First Gate 30-SHIELD-SPR Adjudicator (IIP-0042 B3-B4 / IIP-0044 B1-B4)
# Synchronized 100% IDENTICALLY with scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py::evaluate_gate30_shield_spr
# =============================================================================
_SHIELD_SPR_PRECEDENCE: dict[str, int] = {
    "PASS": 0,
    "HOLD": 1,
    "HOLD_OBSERVED_NONZERO_CYTOTOXICITY": 2,
    "HOLD_CYTOTOXICITY_U95_EXCEEDS_5PCT": 3,
    "HOLD_INVALID_OR_MISSING_INPUT": 4,
    "FAIL": 5,
}
_SHIELD_SPR_PRECEDENCE_ORDER: list[str] = [
    "FAIL",
    "HOLD_INVALID_OR_MISSING_INPUT",
    "HOLD_CYTOTOXICITY_U95_EXCEEDS_5PCT",
    "HOLD_OBSERVED_NONZERO_CYTOTOXICITY",
    "HOLD",
    "PASS",
]
_SHIELD_MANDATORY_ON_TARGET_ANALYTES: tuple[str, ...] = (
    "HLA-DQ2.5 + HIP11",
    "HLA-DQ8-trans + HIP11",
    "HLA-DQ2.2 + HIP11",
    "HLA-DQ8 + native WT InsB:9-23",
)
_SHIELD_COMP1_ON_TARGET_ANALYTES: frozenset[str] = frozenset({
    "HLA-DQ2.5 + HIP11",
    "HLA-DQ8-trans + HIP11",
    "HLA-DQ2.2 + HIP11",
})
_SHIELD_COMP2_ON_TARGET_ANALYTES: frozenset[str] = frozenset({
    "HLA-DQ8 + native WT InsB:9-23",
})
_SHIELD_ANALYTE_ALIASES: dict[str, str] = {
    "HLA-DQ2.5 + HIP11": "HLA-DQ2.5 + HIP11",
    "HLA-DQ8-trans + HIP11": "HLA-DQ8-trans + HIP11",
    "HLA-DQ2.2 + HIP11": "HLA-DQ2.2 + HIP11",
    "HLA-DQ8 + native WT InsB:9-23": "HLA-DQ8 + native WT InsB:9-23",
    "HLA-DQ8 + native WT InsB:9-23 (15-aa SHLVEALYLVCGERG)": "HLA-DQ8 + native WT InsB:9-23",
}
_SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS: tuple[str, ...] = (
    "HLA-DQ2.5 + CLIP1",
    "HLA-DQ2.5 + Self_IGKV2_EAED",
    "HLA-DQ2.5 + cel_glutenin_L1",
    "HLA-DQ8-trans + Cpep_Nterm_EAED",
)
_SHIELD_MANDATORY_COMP2_OFF_TARGET_CONTROLS: tuple[str, ...] = (
    "HLA-DQ8 + CLIP1",
    "HLA-DQ8 + DQ8-glia-gamma1a",
    "HLA-DQ8-trans + WT InsB:9-23",
)
_SHIELD_MANDATORY_OFF_TARGET_CONTROLS: tuple[str, ...] = (
    _SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS + _SHIELD_MANDATORY_COMP2_OFF_TARGET_CONTROLS
)
_SHIELD_OFF_TARGET_ALIASES: dict[str, str] = {
    "HLA-DQ8 + DQ8_glia_gamma1a": "HLA-DQ8 + DQ8-glia-gamma1a",
}
_SHIELD_COMP1_LEAD = "IsletSHIELD_QF09_pI2"
_SHIELD_COMP2_LEAD = "IsletSHIELD_Comp2_T006"
_SHIELD_MANDATORY_COMP2_COMPARATORS: tuple[str, ...] = (
    "IsletSHIELD_Comp2_T006",
    "SHIELD2_QQ",
    "R3_shv2_stk1",
    "SH2_MP01",
    "SH2_MP06",
    "SH2_MP08",
)
_SHIELD_COCKTAIL_LEADS: tuple[str, ...] = (
    _SHIELD_COMP1_LEAD,
    _SHIELD_COMP2_LEAD,
)
_SHIELD_CONSTRUCT_CANONICAL_MAP: dict[str, str] = {
    "IsletSHIELD_QF09_pI2": "IsletSHIELD_QF09_pI2",
    "IsletSHIELD_Comp2_T006": "IsletSHIELD_Comp2_T006",
    "SHIELD2_QQ": "SHIELD2_QQ",
    "IsletSHIELD_Comp2_SHIELD2_QQ": "SHIELD2_QQ",
    "R3_shv2_stk1": "R3_shv2_stk1",
    "IsletSHIELD_Comp2_R3_shv2_stk1": "R3_shv2_stk1",
    "SH2_MP01": "SH2_MP01",
    "IsletSHIELD_Comp2_SH2_MP01": "SH2_MP01",
    "SH2_MP06": "SH2_MP06",
    "IsletSHIELD_Comp2_SH2_MP06": "SH2_MP06",
    "SH2_MP08": "SH2_MP08",
    "IsletSHIELD_Comp2_SH2_MP08": "SH2_MP08",
}
_SHIELD_QUALIFYING_HLA_DQ_TOKENS: frozenset[str] = frozenset({
    "HLA-DQ2.5",
    "HLA-DQ8",
    "HLA-DQ8-TRANS",
    "HLA-DQ2.2",
    "DQ2.5",
    "DQ8",
    "DQ8-TRANS",
    "DQ2.2",
    "DQA1*05:01/DQB1*02:01",
    "DQA1*03:01/DQB1*03:02",
    "DQA1*05:01/DQB1*03:02",
    "DQA1*02:01/DQB1*02:02",
})
_SHIELD_CYTO_INDEPENDENCE_MODEL = "EXACT_BINOMIAL_INDEPENDENT_UNITS"
_SHIELD_MIN_BATCHES_N = 3
_SHIELD_MIN_SPR_REPLICATES_N = 3
_SHIELD_MIN_DONORS_N = 3
_SHIELD_MIN_CYTO_N_EFF_PER_DONOR = 60
_SHIELD_MIN_MONOMER_PCT = 95.0
_SHIELD_MAX_DLS_PDI = 0.15
_SHIELD_CYTO_CI_TOL_PP = 0.05
_SHIELD_CYTO_SIMULTANEOUS_FWER_ALPHA = 0.05
_SHIELD_CYTO_DONOR_FAMILY_ALPHA_ONE_SIDED = 0.05
_SHIELD_CYTO_ESTIMAND = "TESTED_DONOR_FAMILY_GLOBAL_NULL_MAX_P_I_LE_5PCT"
_SHIELD_REQUIRED_DONOR_CLINICAL_COHORT = "T1D"
_SHIELD_FORBIDDEN_NON_T1D_DONOR_RE = re.compile(
    r"(?i)(?:HEALTHY[_ -]?CONTROL|CONTROL[_ -]?HEALTHY|NON[_ -]?T1D|HEALTHY[_ -]?DONOR|NON[_ -]?DIABETIC|HEALTHY(?:[_ -]|\d|$)|CONTROL[_ -]?DONOR)"
)
_SHIELD_MIN_CONFIRMATORY_DONORS_N = 9
_SHIELD_SUPPRESSION_ESTIMAND = "POPULATION_DONOR_RESPONDER_PROPORTION_GE_70PCT"
_SHIELD_SUPPRESSION_INFERENCE_METHOD = "EXACT_ONE_SIDED_CLOPPER_PEARSON_RESPONDER_PROPORTION"
_SHIELD_SUPPRESSION_PASS_THRESHOLD_PCT = 70.0
_SHIELD_SUPPRESSION_FAIL_THRESHOLD_PCT = 40.0
_SHIELD_SUPPRESSION_FAIL_L95_GT_PCT = 60.0
_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MIN_PCT = -1000.0
_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MAX_PCT = 100.0
_SHIELD_STRICT_ID_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:-]{1,63}$")
_SHIELD_EVIDENCE_REF_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:/-]{3,127}$")
_SHIELD_ISO8601_UTC_RE = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?Z$")
_SHIELD_SHA256_HEX_RE = re.compile(r"^[0-9a-f]{64}$")
_SHIELD_AUTHORIZING_DONOR_SAMPLING_DESIGNS: frozenset[str] = frozenset({
    "SIMPLE_RANDOM_OR_CONSECUTIVE_INDEPENDENT_T1D_COHORT",
})
_SHIELD_NON_AUTHORIZING_STRATIFIED_SAMPLING_DESIGNS: frozenset[str] = frozenset({
    "STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT",
})
_SHIELD_ALLOWED_DONOR_SAMPLING_DESIGNS: frozenset[str] = (
    _SHIELD_AUTHORIZING_DONOR_SAMPLING_DESIGNS
    | _SHIELD_NON_AUTHORIZING_STRATIFIED_SAMPLING_DESIGNS
)
_SHIELD_ALLOWED_INDEPENDENT_EXPERIMENTAL_UNITS: dict[str, frozenset[str]] = {
    "INDEPENDENT_REPLICATE_WELLS": frozenset({
        "Single pre-aliquoted independent primary T1D APC assay well "
        "(distinct physically isolated well per unit prior to dosing)",
        "INDEPENDENT_PRIMARY_T1D_APC_ASSAY_WELL",
    }),
    "INDEPENDENT_DROPLET_PARTITIONS": frozenset({
        "Single physically isolated microfluidic droplet partition "
        "(one independent primary T1D APC partition per unit prior to dosing)",
        "INDEPENDENT_DROPLET_PARTITION",
    }),
    "INDEPENDENT_CLONAL_COLONIES": frozenset({
        "Single physically separated clonal primary T1D APC colony unit "
        "(one independent isolated colony per unit prior to dosing)",
        "INDEPENDENT_CLONAL_COLONY",
    }),
}
_SHIELD_ALLOWED_CLUSTERING_CONTROLS: dict[str, frozenset[str]] = {
    "INDEPENDENT_REPLICATE_WELLS": frozenset({
        "Randomized plate layout across physically separated wells with independent "
        "dosing aliquots and zero cross-well pooling",
        "RANDOMIZED_SEPARATE_WELLS_INDEPENDENT_ALIQUOTS_NO_POOLING",
    }),
    "INDEPENDENT_DROPLET_PARTITIONS": frozenset({
        "Physically isolated independent droplet partitions with independent "
        "reagent loading and zero cross-droplet pooling",
        "ISOLATED_DROPLET_PARTITIONS_INDEPENDENT_LOADING_NO_POOLING",
    }),
    "INDEPENDENT_CLONAL_COLONIES": frozenset({
        "Physically separated independent clonal colony units with independent "
        "dosing aliquots and zero cross-colony pooling",
        "SEPARATED_CLONAL_COLONIES_INDEPENDENT_ALIQUOTS_NO_POOLING",
    }),
}
_SHIELD_ALLOWED_GY018_UNIT_CLASSES: frozenset[str] = frozenset(
    _SHIELD_ALLOWED_INDEPENDENT_EXPERIMENTAL_UNITS.keys()
)
_SHIELD_FWER_EXTERNAL_CUSTODY_CONDITION = (
    "Exact distribution-free FWER <= 0.05 Boole bound applies strictly to the fixed-roster, fixed-per-donor-N, "
    "single-look donor cytotoxicity family (H0_all: max_{i=1..N_roster} p_i <= 5.0%, NOT the union with SPR or "
    "suppression failure routes) and holds mathematically conditional on external outcome-blind custody and "
    "pre-readout commitment receipt of the FULL preregistered analysis plan inside preregistered_donor_family_roster "
    "(roster membership, fixed per-donor sample size N, and single-look fixed horizon planned_analysis_looks == 1) "
    "prior to assay readouts; unpinned, tampered, multi-look, sample-size-mismatched, or incompletely reconciled "
    "submissions fail closed to non-authorizing HOLD_INVALID_OR_MISSING_INPUT for overall PASS and donor-based "
    "FAIL (independent valid non-donor SPR failures remain fail-first FAIL, while out-of-spec physicochemical "
    "SEC-MALS/DLS measurements route to HOLD_INVALID_OR_MISSING_INPUT as unqualified material inputs)."
)
_SHIELD_SUPPRESSION_STATISTICAL_BOUNDARY_NOTE = (
    "Exact <= 5% finite-sample Clopper-Pearson suppression error control applies to the HLA-DQ-eligible "
    "(HLA-DQ2.5, HLA-DQ8, HLA-DQ8-trans, or HLA-DQ2.2) T1D donor sampling frame and is computed conservatively "
    "over donor, expression-batch, assay-run, and joint (batch U run) connected-component clusters "
    "(requiring >= 9 disjoint batch/run units for confirmatory PASS and >= 6 disjoint batch/run units "
    "for suppression FAIL) strictly for simple random or consecutive independent cohorts "
    "(sampling_design_class == 'SIMPLE_RANDOM_OR_CONSECUTIVE_INDEPENDENT_T1D_COHORT'); stratified/quota "
    "cohorts such as 'STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT' are non-authorizing for unweighted "
    "population-suppression inference and route to HOLD "
    "(STRATIFIED_COHORT_REQUIRES_TARGET_WEIGHTED_SUPPRESSION_ESTIMATOR). Only the one-sided lower bounds "
    "(suppression_responder_l95_clopper_pearson_pct and suppression_nonresponder_lt40_l95_clopper_pearson_pct) "
    "drive PASS/FAIL adjudication; suppression_responder_u95_clopper_pearson_pct is a descriptive diagnostic "
    "only with no general marginal upper-coverage guarantee under cluster-all-positive events. For each "
    "independent connected component C_j, the cluster-level all-positive event probability P(all donors in "
    "C_j meet threshold) is bounded above by the applicable single-donor marginal probability p_donor ONLY "
    "under independent components with non-informative cluster sizes and identical marginal response "
    "distributions across assay conditions; informative cluster sizes or systematically differing batch/run "
    "assay conditions are external sampling and laboratory QA assumptions not verified by ID graph topology "
    "alone, and external pre-readout custody of preregistered_donor_family_roster remains mandatory."
)
_SHIELD_LOCAL_JSON_REPLAY_SCOPE_NOTE = (
    "Local JSON replay verifies cryptographic digest calculation over the full pre-registered analysis plan "
    "(roster membership, fixed per-donor sample size N, and single-look fixed horizon planned_analysis_looks == 1), "
    "per-mixture physical co-formulation SEC-MALS/DLS binding, matched shared comparator expression-batch coverage "
    "across WT15 and 6DFX, complete raw roster accounting, strict canonical allowlist schemas for GY-018 and "
    "sampling-design declarations (zero free-text prose accepted), complete donor batch/run dependency topology "
    "retention, and cluster-conservative Clopper-Pearson/Bonferroni bounds only; an independent external pre-readout "
    "commitment receipt covering the full analysis plan and a laboratory QA audit verifying physical unit "
    "independence and target-population sampling are required before relying on the conditional statistical "
    "error-rate interpretation."
)

# Exact complete two-sided 95% Student-t critical values (alpha = 0.05; one-sided 97.5% quantile) for EVERY integer df = 1..30 (zero interpolation!)
_SHIELD_STUDENT_T_95_TWO_SIDED: dict[int, float] = {
    1: 12.706204736432095,
    2: 4.302652729911275,
    3: 3.182446305284263,
    4: 2.7764451051977987,
    5: 2.5705818366147395,
    6: 2.4469118487916806,
    7: 2.3646242510102993,
    8: 2.3060041350333704,
    9: 2.2621571627409915,
    10: 2.2281388519649385,
    11: 2.200985160082949,
    12: 2.1788128296634177,
    13: 2.1603686564610127,
    14: 2.1447866879169273,
    15: 2.131449545559323,
    16: 2.1199052992210112,