) 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", ) raw_off_wt_lot = rec.get("peptide_reagent_lot_id") off_wt_lot_id: str | None = None if ( type(raw_off_wt_lot) is not str or not raw_off_wt_lot or raw_off_wt_lot != raw_off_wt_lot.strip() or not _SHIELD_STRICT_ID_RE.match(raw_off_wt_lot) ): off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: missing valid unpadded peptide_reagent_lot_id matching " f"{_SHIELD_STRICT_ID_RE.pattern} (got {raw_off_wt_lot!r}); excluded from biological " f"adjudication and batch-linkage credit", ) else: off_wt_lot_id = raw_off_wt_lot if not wt15_register_qc_valid or rqc_wt_lot is None: 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 mandatory register_qc_records WT15/6DFX QC or reagent lot is missing or failed", ) elif off_wt_lot_id is not None and rqc_wt_lot != off_wt_lot_id: off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: peptide_reagent_lot_id mismatch: off_target_controls=" f"{off_wt_lot_id!r} != register_qc_records={rqc_wt_lot!r}; " f"WT15 off-target row excluded from biological adjudication and batch-linkage credit", ) if b_err is None and (not tmp_c2_o or not tmp_c2_o.issubset(rqc_comp2_batches)): off_row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: Comp2 expression_batch_ids={sorted(tmp_c2_o)} are not covered by " f"parent register_qc_records Comp2 batches={sorted(rqc_comp2_batches)}; excluded from " f"biological adjudication and batch-linkage credit", ) else: off_row_valid = False b_err = None _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Unregistered off_target_control record rejected (excluded from biological FAIL adjudication): {oid_c!r}", ) if b_err is not None: off_row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", b_err) _, rep_err = _shield_check_strict_int( rec.get("replicates_n"), f"off_target[{oid_c}].replicates_n", min_val=_SHIELD_MIN_SPR_REPLICATES_N ) if rep_err is not None: off_row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", rep_err) sel_l, sel_l_err = _shield_check_num(rec.get("selectivity_l95_fold"), f"off_target[{oid_c}].selectivity_l95_fold", lo=0.0) sel_u, sel_u_err = _shield_check_num(rec.get("selectivity_u95_fold"), f"off_target[{oid_c}].selectivity_u95_fold", lo=0.0) if sel_l_err is not None: off_row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", sel_l_err) if sel_u_err is not None: off_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: off_row_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"off_target[{oid_c}]: inverted selectivity CI L95={sel_l} > U95={sel_u}") if off_row_valid and sel_l is not None and sel_u is not None: referenced_batches.update(tmp_ref_o) comp1_assay_batches.update(tmp_c1_o) comp2_assay_batches.update(tmp_c2_o) if sel_u < 10.0: spr_bio_fail = True if oid_c in _SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS: comp1_spr_bio_fail = True elif oid_c in _SHIELD_MANDATORY_COMP2_OFF_TARGET_CONTROLS: comp2_spr_bio_fail = True _escalate("FAIL", f"off_target[{oid_c}]: selectivity U95={sel_u:.2f}x < 10.0x FAIL bar") elif sel_l < 50.0: _escalate("HOLD", f"off_target[{oid_c}]: selectivity L95={sel_l:.2f}x < 50.0x PASS bar") elif oid_c in _SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS: comp1_off_target_passed_controls.add(oid_c) missing_comp1_off = [o for o in _SHIELD_MANDATORY_COMP1_OFF_TARGET_CONTROLS if o not in seen_off] missing_comp2_off = [o for o in _SHIELD_MANDATORY_COMP2_OFF_TARGET_CONTROLS if o not in seen_off] if missing_comp1_off: _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"Missing mandatory Component 1 off-target SPR controls: {missing_comp1_off}") if missing_comp2_off: _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"Missing mandatory Component 2 off-target SPR controls: {missing_comp2_off}") # 5. Comp2 parallel comparators screened (R08 B3 + R15 0039-B2: two-pass order-independent canonical key & # evidence_record_id uniqueness; all 6 required; EVERY comparator MUST carry closed-schema per-condition