scripts/verify_iip0044_foundry_v1_3_biologics.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0044_foundry_v1_3_biologics.py · SHA-256: 1d6c53a0817f6254…
donor_group_sets: dict[str, set[str]],
) -> list[list[str]]:
"""Deterministic Union-Find partition of fixed roster_ids merging any two donors that share
at least one batch or assay-run token into one conservative independent cluster.
Submitted donors retain their validated batch/run dependency edges even when unrelated
outcome or CI fields fail; pre-assay-excluded unmeasured donors remain singletons.
"""
parent: dict[str, str] = {did: did for did in roster_ids}
def _find(x: str) -> str:
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return x
def _union(a: str, b: str) -> None:
ra, rb = _find(a), _find(b)
if ra != rb:
if ra < rb:
parent[rb] = ra
else:
parent[ra] = rb
token_owner: dict[str, str] = {}
for did in roster_ids:
for tok in sorted(donor_group_sets.get(did, ())):
if tok in token_owner:
_union(did, token_owner[tok])
else:
token_owner[tok] = did
comps: dict[str, list[str]] = {}
for did in roster_ids:
comps.setdefault(_find(did), []).append(did)
return [comps[k] for k in sorted(comps)]
def build_valid_shield_spr_observation(
*,
n_eff_per_donor: int = 60,
donor_k_obs: tuple[int, ...] | None = None,
donor_suppressions: tuple[float, ...] | None = None,
include_optional_1jk8: bool = True,
planned_t1d_donor_family_n: int | None = None,
include_preregistered_roster: bool = True,
roster_donor_ids: list[str] | tuple[str, ...] | None = None,
roster_id: str = "ROSTER_SHIELD_T1D_PREREG_V1",
preregistration_timestamp_utc: str = "2026-11-28T00:00:00Z",
excluded_donor_records: list[dict[str, Any]] | None = None,
shared_expression_batches_n: int | None = None,
shared_assay_runs_n: int | None = None,
sampling_design_class: str = "SIMPLE_RANDOM_OR_CONSECUTIVE_INDEPENDENT_T1D_COHORT",
separate_comp1_comp2_batches: bool = False,
) -> dict[str, Any]:
"""Build a complete typed Gate 30-SHIELD-SPR PASS record with all mandatory evidence blocks,
mandatory hash-pinned outcome-blind preregistered_donor_family_roster committing donor membership,
fixed per-donor cytotoxicity sample size N, and single-look fixed horizon (defaulting to 9 confirmatory
T1D donors across 9 disjoint physical co-formulation mixtures MIX_SHIELD_01..09 and 9 disjoint
assay_run_ids so cluster-conservative exact Clopper-Pearson responder L95(9/9) = 71.687116% >= 70.0%
achieves calibrated PASS), typed donor_sampling_and_independence_design, construct-bound
expression_batches (cocktail leads + dedicated comparator batches), full Comp1+Comp2 off-target controls,
WT15 reagent-lot linkage, per-mixture quantitative SEC-MALS/DLS co-formulation qualification, typed T1D
donor eligibility provenance, qualifying donor hla_genotype, authorization-grade typed GY-018 independence
evidence record, and GY-018-compliant cytotoxicity denominators (exact deff == 1.0, n_eff == raw_independent_units_n >= 60).
"""
if donor_k_obs is None and donor_suppressions is None:
k_seq: tuple[int, ...] = tuple(0 for _ in range(_SHIELD_MIN_CONFIRMATORY_DONORS_N))
sup_seq: tuple[float, ...] = (82.0, 84.0, 86.0, 81.0, 83.0, 85.0, 82.5, 84.5, 83.5)
elif donor_k_obs is not None and donor_suppressions is None:
k_seq = tuple(int(x) for x in donor_k_obs)
sup_seq = tuple(84.0 for _ in range(len(k_seq)))
elif donor_k_obs is None and donor_suppressions is not None:
sup_seq = tuple(float(x) for x in donor_suppressions)
k_seq = tuple(0 for _ in range(len(sup_seq)))
else:
k_seq = tuple(int(x) for x in donor_k_obs)
sup_seq = tuple(float(x) for x in donor_suppressions)
n_donors = max(len(k_seq), len(sup_seq))
n_lead_batches = (
int(shared_expression_batches_n)
if shared_expression_batches_n is not None
else max(_SHIELD_MIN_BATCHES_N, n_donors)
)
n_assay_runs = (
int(shared_assay_runs_n)
if shared_assay_runs_n is not None
else max(1, n_donors)
)
if separate_comp1_comp2_batches:
c1_lead_batch_ids = [f"BATCH_C1_{i:02d}" for i in range(1, n_lead_batches + 1)]
c2_lead_batch_ids = [f"BATCH_C2_{i:02d}" for i in range(1, n_lead_batches + 1)]
spr_c1_batch_ids = c1_lead_batch_ids[: max(_SHIELD_MIN_BATCHES_N, min(3, len(c1_lead_batch_ids)))]
spr_c2_batch_ids = c2_lead_batch_ids[: max(_SHIELD_MIN_BATCHES_N, min(3, len(c2_lead_batch_ids)))]
sec_all_lead_batch_ids = c1_lead_batch_ids + c2_lead_batch_ids
rqc_parent_batch_ids = spr_c1_batch_ids + spr_c2_batch_ids
expression_batches: list[dict[str, Any]] = (
[{"batch_id": bid, "construct_ids": [_SHIELD_COMP1_LEAD], "qc_passed": True} for bid in c1_lead_batch_ids]
+ [{"batch_id": bid, "construct_ids": [_SHIELD_COMP2_LEAD], "qc_passed": True} for bid in c2_lead_batch_ids]
)
else:
lead_batch_ids = [f"BATCH_ECOLI_{i:02d}" for i in range(1, n_lead_batches + 1)]
c1_lead_batch_ids = list(lead_batch_ids)
c2_lead_batch_ids = list(lead_batch_ids)
spr_c1_batch_ids = lead_batch_ids[: max(_SHIELD_MIN_BATCHES_N, min(3, len(lead_batch_ids)))]
spr_c2_batch_ids = list(spr_c1_batch_ids)
sec_all_lead_batch_ids = list(lead_batch_ids)
rqc_parent_batch_ids = list(spr_c1_batch_ids)
expression_batches = [
{"batch_id": bid, "construct_ids": list(_SHIELD_COCKTAIL_LEADS), "qc_passed": True}
for bid in lead_batch_ids
]
hip11_reagent_lot_id = "REAGENT_HIP11_EXCHANGE_LOT01"
wt15_reagent_lot_id = "REAGENT_WT15_INSB9_23_LOT01"
r6dfx_reagent_lot_id = "REAGENT_6DFX_P8E9E_LOT01"
comparator_batch_map: dict[str, str] = {
cid: f"BATCH_COMP_{cid}"
for cid in _SHIELD_MANDATORY_COMP2_COMPARATORS
if cid != _SHIELD_COMP2_LEAD
}
for cid, cbid in comparator_batch_map.items():
expression_batches.append(
{"batch_id": cbid, "construct_ids": [cid], "qc_passed": True}
)
qualified_mixtures: list[dict[str, Any]] = [
{
"mixture_id": f"MIX_SHIELD_{m_idx + 1:02d}",
"comp1_expression_batch_id": c1_lead_batch_ids[m_idx],
"comp2_expression_batch_id": c2_lead_batch_ids[m_idx],
"monomer_pct": 96.8,
"dls_pdi": 0.08,
"no_aggregates_or_precipitation": True,
"qc_passed": True,
"equimolar_1to1_molar_ratio_attested": True,
"ratio_basis_attestation": "LAB_ATTESTED_1TO1_MOLAR_COFORMULATION_MIXING_PROTOCOL",
}
for m_idx in range(n_lead_batches)
]
donors: list[dict[str, Any]] = []
for i in range(n_donors):
k_i = k_seq[i] if i < len(k_seq) else 0
s_i = sup_seq[i] if i < len(sup_seq) else 84.0
run_idx = (i % n_assay_runs) + 1
mix_idx = i % n_lead_batches
donor_batches = (
[c1_lead_batch_ids[mix_idx], c2_lead_batch_ids[mix_idx]]
if separate_comp1_comp2_batches
else [c1_lead_batch_ids[mix_idx]]
)
donors.append(
{
"donor_id": f"T1D_DONOR_{i + 1:02d}",
"t1d_diagnosis_confirmed": True,
"donor_clinical_cohort": _SHIELD_REQUIRED_DONOR_CLINICAL_COHORT,
"t1d_prequalification_ref": f"PREQUAL_T1D_DONOR_{i + 1:02d}",
"hla_genotype": "HLA-DQ2.5/HLA-DQ8",
"assay_run_id": f"SHIELD_ASSAY_RUN_{run_idx:02d}",
"cocktail_mixture_id": f"MIX_SHIELD_{mix_idx + 1:02d}",
"expression_batch_ids": donor_batches,
"suppression_pct": float(s_i),
"raw_independent_units_n": int(n_eff_per_donor),
"design_effect_deff": 1.0,
"cytotoxicity_independence_model": _SHIELD_CYTO_INDEPENDENCE_MODEL,
"gy018_independence_justification": {
"independent_unit_class": "INDEPENDENT_REPLICATE_WELLS",
"within_donor_units_physically_independent": True,
"clustering_controls_present_and_verified": True,
"shared_well_technical_reads_excluded": True,
"independence_evidence_record_id": f"GY018-REC-T1D-DONOR-{i + 1:02d}",
"independent_experimental_unit": (
"Single pre-aliquoted independent primary T1D APC assay well "
"(distinct physically isolated well per unit prior to dosing)"
),
"predeclared_per_donor_unit_count_n": int(n_eff_per_donor),
"clustering_controls": (
"Randomized plate layout across physically separated wells with independent "
"dosing aliquots and zero cross-well pooling"
),
},
"apc_cytotoxicity_k_obs": int(k_i),
"apc_cytotoxicity_n_eff": int(n_eff_per_donor),
}
)
register_qc: dict[str, Any] = {
"expression_batch_ids": list(rqc_parent_batch_ids),
"hip11_dq25_dq8t_dq22_exchange_qc_passed": True,
"hip11_peptide_reagent_lot_id": hip11_reagent_lot_id,
"native_wt_insb9_23_15aa": {
"sequence": "SHLVEALYLVCGERG",
"peptide_reagent_lot_id": wt15_reagent_lot_id,
"lcms_identity_passed": True,
"register2_occupancy_qc_passed": True,
},
"engineered_6dfx_p8e9e_12aa": {
"sequence": "VEELYLVAGEEG",
"peptide_reagent_lot_id": r6dfx_reagent_lot_id,
"qc_passed": True,
},
}
if include_optional_1jk8:
register_qc["crystal_ref_1jk8_14aa"] = {
"sequence": "LVEALYLVCGERGG",
"qc_passed": True,
"expression_batch_ids": list(spr_c2_batch_ids),
}
obs_out: dict[str, Any] = {
"expression_batches": expression_batches,
"donor_sampling_and_independence_design": {
"sampling_design_class": sampling_design_class,
"independent_donor_sampling_attested": True,
"between_donor_shared_shock_controls_verified": True,
"sampling_protocol_ref": "PROTOCOL:GATE30-SHIELD-COHORT-INDEP-V1",
"between_donor_independence_justification": (
"STRATIFIED_DISJOINT_BATCH_AND_RUN_T1D_DONOR_COHORT"
if sampling_design_class == "STRATIFIED_INDEPENDENT_T1D_HLA_DQ_COHORT"
else (
"Simple random or consecutive independent T1D HLA-DQ donors executed across disjoint "
"expression batches and separate assay runs with independent reagent preparations"
)
),
},
"on_target_analytes": [
{
"analyte_id": "HLA-DQ2.5 + HIP11",
"peptide_reagent_lot_id": hip11_reagent_lot_id,
"replicates_n": 3,
"expression_batch_ids": list(spr_c1_batch_ids),
"ic50_l95_nm": 18.0,
"ic50_u95_nm": 42.0,
"selectivity_l95_fold": 95.0,
"selectivity_u95_fold": 160.0,
},
{
"analyte_id": "HLA-DQ8-trans + HIP11",
"peptide_reagent_lot_id": hip11_reagent_lot_id,
"replicates_n": 3,
"expression_batch_ids": list(spr_c1_batch_ids),
"ic50_l95_nm": 22.0,
"ic50_u95_nm": 48.0,
"selectivity_l95_fold": 85.0,
"selectivity_u95_fold": 140.0,
},
{
"analyte_id": "HLA-DQ2.2 + HIP11",
"peptide_reagent_lot_id": hip11_reagent_lot_id,
"replicates_n": 3,
"expression_batch_ids": list(spr_c1_batch_ids),