_escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: Comp1 expression_batch_ids={sorted(tmp_c1)} are not covered by parent " f"register_qc_records Comp1 batches={sorted(rqc_comp1_batches)}; excluded from " f"biological adjudication and batch-linkage credit", ) if b_err is None and (not tmp_c1 or not tmp_c1.issubset(sec_comp1_qualified_batches)): row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: excluded from biological adjudication and batch-linkage credit because " f"Comp1 expression_batch_ids={sorted(tmp_c1)} lack passing Comp1 SEC-MALS/DLS " f"physicochemical material qualification (qualified_comp1_batches={sorted(sec_comp1_qualified_batches)})", ) elif aid in _SHIELD_COMP2_ON_TARGET_ANALYTES: b_err = _shield_validate_batch_ids( rec.get("expression_batch_ids"), f"on_target[{aid}]", passing_batch_constructs, tmp_ref, required_construct_all=_SHIELD_COMP2_LEAD, role_comp2_batches=tmp_c2, ) if b_err is None and (not tmp_c2 or not tmp_c2.issubset(sec_comp2_qualified_batches)): row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: excluded from biological adjudication and batch-linkage credit because " f"Comp2 expression_batch_ids={sorted(tmp_c2)} lack passing Comp2 SEC-MALS/DLS " f"physicochemical material qualification (qualified_comp2_batches={sorted(sec_comp2_qualified_batches)})", ) else: row_valid = False b_err = None _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Unregistered on_target_analyte record rejected (excluded from biological FAIL adjudication): {aid!r}", ) if b_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", b_err) if aid == "HLA-DQ8 + native WT InsB:9-23": pseq = rec.get("peptide_sequence") if pseq != "SHLVEALYLVCGERG": row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Native WT InsB:9-23 analyte missing or wrong peptide_sequence={pseq!r} (expected 15-aa SHLVEALYLVCGERG)", ) raw_wt_lot = rec.get("peptide_reagent_lot_id") if ( type(raw_wt_lot) is not str or not raw_wt_lot or raw_wt_lot != raw_wt_lot.strip() or not _SHIELD_STRICT_ID_RE.match(raw_wt_lot) ): row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Native WT InsB:9-23 analyte missing valid unpadded peptide_reagent_lot_id matching " f"{_SHIELD_STRICT_ID_RE.pattern} (got {raw_wt_lot!r})", ) else: wt15_analyte_reagent_lot_id = raw_wt_lot # R12 0039-B1 + R14 0039-B2: Reconcile mandatory WT15 register-QC, parent batches & reagent lot # strictly BEFORE biological adjudication and BEFORE granting batch-linkage credit! if not wt15_register_qc_valid or rqc_wt_lot is None: row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "Native WT InsB:9-23 on-target row excluded from biological adjudication and " "batch-linkage credit because mandatory register_qc_records WT15/6DFX QC or " "reagent lot is missing or failed", ) elif wt15_analyte_reagent_lot_id is not None and rqc_wt_lot != wt15_analyte_reagent_lot_id: row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Native WT InsB:9-23 peptide_reagent_lot_id mismatch: on_target_analytes=" f"{wt15_analyte_reagent_lot_id!r} != register_qc_records={rqc_wt_lot!r}; " f"WT15 row excluded from biological adjudication and batch-linkage credit", ) if b_err is None and (not tmp_c2 or not tmp_c2.issubset(rqc_comp2_batches)): row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Native WT InsB:9-23 Comp2 expression_batch_ids={sorted(tmp_c2)} are not covered by " f"parent register_qc_records Comp2 batches={sorted(rqc_comp2_batches)}; excluded from " f"biological adjudication and batch-linkage credit", ) _, rep_err = _shield_check_strict_int( rec.get("replicates_n"), f"{aid}.replicates_n", min_val=_SHIELD_MIN_SPR_REPLICATES_N ) if rep_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", rep_err) ic50_l, ic50_l_err = _shield_check_num(rec.get("ic50_l95_nm"), f"{aid}.ic50_l95_nm", lo=0.0, strictly_gt_lo=True) ic50_u, ic50_u_err = _shield_check_num(rec.get("ic50_u95_nm"), f"{aid}.ic50_u95_nm", lo=0.0, strictly_gt_lo=True) if ic50_l_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", ic50_l_err) if ic50_u_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", ic50_u_err) if ic50_l is not None and ic50_u is not None and ic50_l > ic50_u: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: inverted IC50 CI L95={ic50_l} > U95={ic50_u}") sel_l, sel_l_err = _shield_check_num(rec.get("selectivity_l95_fold"), f"{aid}.selectivity_l95_fold", lo=0.0) sel_u, sel_u_err = _shield_check_num(rec.get("selectivity_u95_fold"), f"{aid}.selectivity_u95_fold", lo=0.0) if sel_l_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", sel_l_err) if sel_u_err is not None: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", sel_u_err) if sel_l is not None and sel_u is not None and sel_l > sel_u: row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: inverted selectivity CI L95={sel_l} > U95={sel_u}") # R07 B1 + R08 B3 + R12 0039-B1 + R13 0037-B2/B3: Credit batch linkage and adjudicate biological FAIL/HOLD strictly on valid, register-QC-reconciled, non-conflicted rows! if row_valid and ic50_l is not None and ic50_u is not None and sel_l is not None and sel_u is not None: referenced_batches.update(tmp_ref) comp1_assay_batches.update(tmp_c1) comp2_assay_batches.update(tmp_c2) row_bio_fail = False row_bio_hold = False if ic50_l > 500.0: spr_bio_fail = True row_bio_fail = True _escalate("FAIL", f"{aid}: SPR L95(IC50)={ic50_l:.2f} nM > 500.0 nM FAIL bar") elif ic50_u > 100.0: row_bio_hold = True _escalate("HOLD", f"{aid}: SPR U95(IC50)={ic50_u:.2f} nM > 100.0 nM PASS bar (post-SPR v1.4 maturation HOLD)") if sel_u < 10.0: spr_bio_fail = True row_bio_fail = True _escalate("FAIL", f"{aid}: SPR U95(selectivity)={sel_u:.2f}x < 10.0x FAIL bar") elif sel_l < 50.0: row_bio_hold = True _escalate("HOLD", f"{aid}: SPR L95(selectivity)={sel_l:.2f}x < 50.0x PASS bar (post-SPR v1.4 maturation HOLD)") if aid in _SHIELD_COMP1_ON_TARGET_ANALYTES: if row_bio_fail: comp1_spr_bio_fail = True elif not row_bio_hold: comp1_on_target_passed_analytes.add(aid) elif aid in _SHIELD_COMP2_ON_TARGET_ANALYTES and row_bio_fail: comp2_spr_bio_fail = True analyte_derived[aid] = { "ic50_l95_nm": ic50_l, "ic50_u95_nm": ic50_u, "selectivity_l95_fold": sel_l, "selectivity_u95_fold": sel_u, } missing_analytes = [a for a in _SHIELD_MANDATORY_ON_TARGET_ANALYTES if a not in seen_analytes] if missing_analytes: _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Missing mandatory on-target SPR analytes: {missing_analytes}", ) # 4. Off-target SPR controls (R08 B3 + R12 0039-B1: two-pass order-independent canonical key uniqueness BEFORE # bio adjudication; ALL 4 mandatory Comp1 + ALL 3 mandatory Comp2 controls = 7 total; construct-bound) off_raw = observation.get("off_target_controls") seen_off: set[str] = set() conflicted_off_target: set[str] = set() if not isinstance(off_raw, list) or len(off_raw) == 0: _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "Missing typed off_target_controls list (all 4 Comp1 + 3 Comp2 mandatory controls required)", ) else: off_target_counts: dict[str, int] = {} for rec in off_raw: if isinstance(rec, dict): oid = rec.get("analyte_id") if type(oid) is str and oid.strip(): oid_p = _SHIELD_OFF_TARGET_ALIASES.get(oid.strip(), oid.strip()) off_target_counts[oid_p] = off_target_counts.get(oid_p, 0) + 1 conflicted_off_target = {k for k, cnt in off_target_counts.items() if cnt > 1} for coid in sorted(conflicted_off_target): _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Duplicate/conflicting off_target_control canonical key: {coid!r} (count={off_target_counts[coid]}); " f"all occurrences excluded from biological adjudication and batch-linkage credit", ) for idx, rec in enumerate(off_raw): if not isinstance(rec, dict): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"off_target_controls[{idx}] must be an object") continue oid = rec.get("analyte_id") if type(oid) is not str or not oid.strip(): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"off_target_controls[{idx}] missing analyte_id") continue oid_c = _SHIELD_OFF_TARGET_ALIASES.get(oid.strip(), oid.strip()) seen_off.add(oid_c) if oid_c in conflicted_off_target: continue off_row_valid = True tmp_ref_o: set[str] = set() tmp_c1_o: set[str] = set() tmp_c2_o: set[str] = set() if oid_c in _SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS: b_err = _shield_validate_batch_ids( rec.get("expression_batch_ids"), f"off_target[{oid_c}]", passing_batch_constructs, tmp_ref_o, required_construct_all=_SHIELD_COMP1_LEAD, role_comp1_batches=tmp_c1_o, ) if b_err is None and (not tmp_c1_o or not tmp_c1_o.issubset(sec_comp1_qualified_batches)): off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: excluded from biological adjudication and batch-linkage credit " f"because Comp1 expression_batch_ids={sorted(tmp_c1_o)} lack passing Comp1 SEC-MALS/DLS " f"physicochemical material qualification (qualified_comp1_batches={sorted(sec_comp1_qualified_batches)})", ) elif oid_c in _SHIELD_MANDATORY_COMP2_OFF_TARGET_CONTROLS: b_err = _shield_validate_batch_ids( rec.get("expression_batch_ids"), f"off_target[{oid_c}]", passing_batch_constructs, tmp_ref_o, required_construct_all=_SHIELD_COMP2_LEAD, role_comp2_batches=tmp_c2_o, ) if b_err is None and (not tmp_c2_o or not tmp_c2_o.issubset(sec_comp2_qualified_batches)): off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: excluded from biological adjudication and batch-linkage credit " f"because Comp2 expression_batch_ids={sorted(tmp_c2_o)} lack passing Comp2 SEC-MALS/DLS " f"physicochemical material qualification (qualified_comp2_batches={sorted(sec_comp2_qualified_batches)})", ) if oid_c == "HLA-DQ8-trans + WT InsB:9-23": off_pseq = rec.get("peptide_sequence") if off_pseq != "SHLVEALYLVCGERG": off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: missing or wrong peptide_sequence={off_pseq!r} " f"(expected 15-aa SHLVEALYLVCGERG); excluded from biological adjudication and batch-linkage credit",