scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py · SHA-256: 16964a158458b5cf…
or not _SHIELD_STRICT_ID_RE.match(raw_mix_id)
):
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: missing or invalid mandatory cocktail_mixture_id referencing a passing "
f"physical mixture in sec_mals_dls_monomer_coformulation.qualified_coformulation_mixtures "
f"(got {raw_mix_id!r}); excluded from biological adjudication and batch-linkage credit",
)
elif not sec_cocktail_qualified or raw_mix_id not in qualified_passing_mixtures:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: excluded from biological adjudication and batch-linkage credit because "
f"cocktail_mixture_id={raw_mix_id!r} lacks a passing physical co-formulation SEC-MALS/DLS "
f"qualification record (qualified_mixtures={sorted(qualified_passing_mixtures.keys())})",
)
elif b_err is None:
mix_c1_bid, mix_c2_bid = qualified_passing_mixtures[raw_mix_id]
expected_mix_batches = {mix_c1_bid, mix_c2_bid}
if (
tmp_ref_d != expected_mix_batches
or mix_c1_bid not in tmp_ck1_d
or mix_c2_bid not in tmp_ck2_d
):
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: excluded from biological adjudication and batch-linkage credit because "
f"cocktail expression_batch_ids={sorted(tmp_ref_d)} do not match the exact physical "
f"co-formulation mixture {raw_mix_id!r} component lot pair "
f"(comp1={mix_c1_bid!r}, comp2={mix_c2_bid!r}); crossed or unqualified lot combination rejected",
)
has_hla = "hla_genotype" in d and d["hla_genotype"] is not None
has_hla_alias = "hla_dq_genotype" in d and d["hla_dq_genotype"] is not None
if has_hla and has_hla_alias and str(d["hla_genotype"]).strip() != str(d["hla_dq_genotype"]).strip():
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: hla_genotype={d['hla_genotype']!r} disagrees with hla_dq_genotype={d['hla_dq_genotype']!r}",
)
raw_hla = d["hla_genotype"] if has_hla else d.get("hla_dq_genotype")
_, hla_err = _shield_parse_qualifying_hla_genotype(raw_hla, f"donor[{did_c}]")
if hla_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", hla_err)
# R09 B3 + R10 B5 + R11 M1: Enforce suppression assay acceptance range [-1000.0, 100.0]% (100% blockade down to -1000% = 11x enhancement);
# out-of-range values (< -1000.0 or > 100.0, e.g. -1e200) fail closed to HOLD_INVALID_OR_MISSING_INPUT without OverflowError,
# while valid negative enhancement values in [-1000.0, 0.0) route to the anti-enhancement safety guard (min >= 0.0%) -> HOLD.
sup_v, sup_err = _shield_check_num(
d.get("suppression_pct"),
f"donor[{did_c}].suppression_pct",
lo=_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MIN_PCT,
hi=_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MAX_PCT,
)
if sup_err is not None or sup_v is None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", sup_err or f"Invalid donor[{did_c}].suppression_pct")
# GY-018-compliant denominator verification (EXACT deff == 1.0 with zero tolerance & n_eff == raw_n >= 60)
has_raw_u = "raw_independent_units_n" in d and d["raw_independent_units_n"] is not None
has_raw_alias = "cytotoxicity_n_raw_units" in d and d["cytotoxicity_n_raw_units"] is not None
if has_raw_u and has_raw_alias and d["raw_independent_units_n"] != d["cytotoxicity_n_raw_units"]:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: raw_independent_units_n disagrees with cytotoxicity_n_raw_units",
)
raw_units_in = d["raw_independent_units_n"] if has_raw_u else d.get("cytotoxicity_n_raw_units")
raw_units_n, raw_u_err = _shield_check_strict_int(
raw_units_in, f"donor[{did_c}].raw_independent_units_n", min_val=1
)
if raw_u_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", raw_u_err)
deff_v, deff_err = _shield_check_exact_deff(d.get("design_effect_deff"), f"donor[{did_c}].design_effect_deff")
if deff_err is not None or deff_v is None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", deff_err or f"Invalid donor[{did_c}].design_effect_deff")
indep_model = d.get("cytotoxicity_independence_model")
if type(indep_model) is not str or indep_model != _SHIELD_CYTO_INDEPENDENCE_MODEL:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: cytotoxicity_independence_model must be {_SHIELD_CYTO_INDEPENDENCE_MODEL!r} (got {indep_model!r})",
)
# R09 M1 + R10 B3 + R12 0037-B3: Mandatory authorization-grade strict closed-schema GY-018 independence
# evidence record bound 1:1 to canonical allowlisted unit/control tokens (ZERO free-text prose accepted!)
pd_n: int | None = None
gy018_just = d.get("gy018_independence_justification")
if not isinstance(gy018_just, dict):
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: missing mandatory authorization-grade gy018_independence_justification object "
f"(requires independent_unit_class, within_donor_units_physically_independent=True, "
f"clustering_controls_present_and_verified=True, shared_well_technical_reads_excluded=True, "
f"independence_evidence_record_id, independent_experimental_unit, predeclared_per_donor_unit_count_n, clustering_controls)",
)
else:
extra_gy_keys = sorted(set(gy018_just.keys()) - _allowed_gy018_keys)
if extra_gy_keys:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification contains unexpected/free-text keys "
f"{extra_gy_keys}; strict closed typed schema required",
)
unit_cls = gy018_just.get("independent_unit_class")
unit_cls_valid = type(unit_cls) is str and unit_cls in _SHIELD_ALLOWED_GY018_UNIT_CLASSES
if not unit_cls_valid:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification.independent_unit_class must be in "
f"{sorted(_SHIELD_ALLOWED_GY018_UNIT_CLASSES)} (got {unit_cls!r})",
)
for bkey in (
"within_donor_units_physically_independent",
"clustering_controls_present_and_verified",
"shared_well_technical_reads_excluded",
):
if gy018_just.get(bkey) is not True:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification.{bkey} must be literal boolean True "
f"(got {gy018_just.get(bkey)!r})",
)
ev_rec_id = gy018_just.get("independence_evidence_record_id")
if (
type(ev_rec_id) is not str
or not ev_rec_id
or ev_rec_id != ev_rec_id.strip()
or not _SHIELD_EVIDENCE_REF_RE.match(ev_rec_id)
):
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification.independence_evidence_record_id must be "
f"an unpadded audit ref matching {_SHIELD_EVIDENCE_REF_RE.pattern} (got {ev_rec_id!r})",
)
iu_txt = gy018_just.get("independent_experimental_unit")
allowed_units_for_cls = (
_SHIELD_ALLOWED_INDEPENDENT_EXPERIMENTAL_UNITS[unit_cls]
if unit_cls_valid and type(unit_cls) is str
else frozenset()
)
if type(iu_txt) is not str or iu_txt not in allowed_units_for_cls:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification.independent_experimental_unit must be a "
f"canonical allowlisted token compatible with independent_unit_class={unit_cls!r} "
f"(free-text prose rejected fail-closed; got {iu_txt!r})",
)
cc_txt = gy018_just.get("clustering_controls")
allowed_ctrls_for_cls = (
_SHIELD_ALLOWED_CLUSTERING_CONTROLS[unit_cls]
if unit_cls_valid and type(unit_cls) is str
else frozenset()
)
if type(cc_txt) is not str or cc_txt not in allowed_ctrls_for_cls:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}].gy018_independence_justification.clustering_controls must be a "
f"canonical allowlisted token compatible with independent_unit_class={unit_cls!r} "
f"(free-text prose rejected fail-closed; got {cc_txt!r})",
)
pd_n, pd_n_err = _shield_check_strict_int(
gy018_just.get("predeclared_per_donor_unit_count_n"),
f"donor[{did_c}].gy018_independence_justification.predeclared_per_donor_unit_count_n",
min_val=_SHIELD_MIN_CYTO_N_EFF_PER_DONOR,
)
if pd_n_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", pd_n_err)
elif raw_units_n is not None and pd_n != raw_units_n:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: gy018_independence_justification.predeclared_per_donor_unit_count_n={pd_n} "
f"disagrees with raw_independent_units_n={raw_units_n}",
)
n_eff_raw, neff_pos_err = _shield_check_strict_int(d.get("apc_cytotoxicity_n_eff"), f"donor[{did_c}].apc_cytotoxicity_n_eff", min_val=1)
k_obs_raw, kobs_err = _shield_check_strict_int(d.get("apc_cytotoxicity_k_obs"), f"donor[{did_c}].apc_cytotoxicity_k_obs", min_val=0)
if neff_pos_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", neff_pos_err)
if kobs_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", kobs_err)
if n_eff_raw is not None and raw_units_n is not None and n_eff_raw != raw_units_n:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: GY-018 denominator mismatch — apc_cytotoxicity_n_eff={n_eff_raw} != raw_independent_units_n={raw_units_n}",
)
if n_eff_raw is not None and n_eff_raw < _SHIELD_MIN_CYTO_N_EFF_PER_DONOR:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: apc_cytotoxicity_n_eff={n_eff_raw} < mandatory minimum {_SHIELD_MIN_CYTO_N_EFF_PER_DONOR}",
)
if n_eff_raw is not None and k_obs_raw is not None and k_obs_raw > n_eff_raw:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: apc_cytotoxicity_k_obs={k_obs_raw} > apc_cytotoxicity_n_eff={n_eff_raw}",
)
# R16 Shared Blocker #3 + Pre-Dedup Raw-Row Reconciliation (Pass 1c): Exclude any donor flagged
# for fixed-horizon sample-size mismatch across raw submitted rows from biological adjudication!
if roster_verified and did_c in roster_sample_size_plan_mismatched_donors:
donor_valid = False
# Gate ALL binomial Clopper-Pearson & caller CI calculations strictly on valid eligible rostered T1D donors!
if donor_valid and n_eff_raw is not None and k_obs_raw is not None and sup_v is not None:
rate_pct = 100.0 * k_obs_raw / float(n_eff_raw)
cp_l95, cp_u95 = _clopper_pearson_one_sided_95_pct(k_obs_raw, n_eff_raw, alpha=0.05)
# Two-sided validation of optional caller-supplied per-donor cytotoxicity intervals (<= 0.05 pp tolerance)
rep_obs_raw = d.get("apc_cytotoxicity_observed_pct")
rep_l95_raw = d.get("apc_cytotoxicity_l95_pct")
rep_u95_raw = d.get("apc_cytotoxicity_u95_pct")
rep_l95: float | None = None
rep_u95: float | None = None
if rep_obs_raw is not None:
rep_obs, ro_err = _shield_check_num(rep_obs_raw, f"donor[{did_c}].apc_cytotoxicity_observed_pct", lo=0.0, hi=100.0)
if ro_err is not None:
donor_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", ro_err)
elif rep_obs is not None and abs(rep_obs - rate_pct) > _SHIELD_CYTO_CI_TOL_PP:
donor_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"donor[{did_c}]: reported observed_pct={rep_obs:.3f}% disagrees with raw counts {k_obs_raw}/{n_eff_raw} ({rate_pct:.3f}%)",
)
if rep_l95_raw is not None:
rep_l95, rl_err = _shield_check_num(rep_l95_raw, f"donor[{did_c}].apc_cytotoxicity_l95_pct", lo=0.0, hi=100.0)