sec_qc_cls = "OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD" elif sec_input_missing_or_malformed: sec_qc_cls = "MISSING_OR_MALFORMED_OR_CONTRADICTORY_INPUT_HOLD" else: sec_qc_cls = "PASS_QUALIFIED_MATERIAL" if sec_b_err is None and hflag_ok and no_agg is True and not sec_top_qc_bad: if c1_mon is not None and not c1_oos and c1_qc is True: sec_comp1_qualified_batches = set(tmp_c1_sec) if c2_mon is not None and not c2_oos and c2_qc is True: sec_comp2_qualified_batches = set(tmp_c2_sec) if ( sec_b_err is None and hflag_ok and no_agg is True and not sec_top_qc_bad and not top_sec_overstated and ck_mon is not None and not ck_oos and ck_qc is True and dls_pdi is not None and not pdi_oos ): for mid_k, (mc1, mc2) in candidate_passing_mixtures.items(): if mc1 in sec_comp1_qualified_batches and mc2 in sec_comp2_qualified_batches: qualified_passing_mixtures[mid_k] = (mc1, mc2) sec_cocktail_qualified = bool(len(qualified_passing_mixtures) > 0) if sec_cocktail_qualified: sec_cocktail_qualified_comp1_batches = {mc1 for mc1, _ in qualified_passing_mixtures.values()} sec_cocktail_qualified_comp2_batches = {mc2 for _, mc2 in qualified_passing_mixtures.values()} sec_cocktail_qualified_batches = sec_cocktail_qualified_comp1_batches | sec_cocktail_qualified_comp2_batches if sec_qc_cls == "PASS_QUALIFIED_MATERIAL": referenced_batches.update(sec_cocktail_qualified_batches) cocktail_comp1_batches.update(sec_cocktail_qualified_comp1_batches) cocktail_comp2_batches.update(sec_cocktail_qualified_comp2_batches) derived_summary["sec_mals_dls"] = { "comp1_monomer_pct": c1_mon, "comp2_monomer_pct": c2_mon, "cocktail_1to1_monomer_pct": ck_mon, "dls_pdi": dls_pdi, "no_aggregates_or_precipitation": no_agg if type(no_agg) is bool else None, "physicochemical_qc_classification": sec_qc_cls, "qualified_cocktail_batch_ids": sorted(sec_cocktail_qualified_batches), "qualified_coformulation_mixtures": { mid_k: { "comp1_expression_batch_id": mc1, "comp2_expression_batch_id": mc2, "equimolar_1to1_molar_ratio_attested": candidate_mixture_ratio_meta.get(mid_k, {}).get( "equimolar_1to1_molar_ratio_attested" ), "ratio_basis_attestation": candidate_mixture_ratio_meta.get(mid_k, {}).get( "ratio_basis_attestation" ), } for mid_k, (mc1, mc2) in sorted(qualified_passing_mixtures.items()) }, "qualified_coformulation_mixtures_count": len(qualified_passing_mixtures), "per_mixture_coformulation_binding_enforced": True, "coformulation_1to1_molar_ratio_verification_scope": ( "LABORATORY_ATTESTED_NOT_INDEPENDENTLY_MEASURED_BY_SEC_MALS_OR_DLS" ), "all_qualified_mixtures_equimolar_1to1_attested": bool( len(qualified_passing_mixtures) > 0 and all( candidate_mixture_ratio_meta.get(mid_k, {}).get("equimolar_1to1_molar_ratio_attested") is True for mid_k in qualified_passing_mixtures ) ), } # 3. On-target SPR analytes (R08 B3 + R12 0039-B1 + R14 0039-B2/B3: two-pass order-independent canonical key # uniqueness AND mandatory register-QC/reagent-lot + SEC-MALS material qualification reconciliation strictly # BEFORE biological adjudication & batch credit; all 4 mandatory complexes; replicates_n >= 3) analytes_raw = observation.get("on_target_analytes") seen_analytes: set[str] = set() conflicted_on_target: set[str] = set() analyte_derived: dict[str, dict[str, float]] = {} wt15_analyte_reagent_lot_id: str | None = None if not isinstance(analytes_raw, list) or len(analytes_raw) == 0: _escalate("HOLD_INVALID_OR_MISSING_INPUT", "Missing typed on_target_analytes list (all 4 mandatory complexes required)") else: on_target_counts: dict[str, int] = {} for rec in analytes_raw: if isinstance(rec, dict): raw_aid = rec.get("analyte_id") if type(raw_aid) is str and raw_aid.strip(): aid_p = _SHIELD_ANALYTE_ALIASES.get(raw_aid.strip(), raw_aid.strip()) on_target_counts[aid_p] = on_target_counts.get(aid_p, 0) + 1 conflicted_on_target = {k for k, cnt in on_target_counts.items() if cnt > 1} for caid in sorted(conflicted_on_target): _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"Duplicate/conflicting on_target_analyte canonical key: {caid!r} (count={on_target_counts[caid]}); " f"all occurrences excluded from biological adjudication and batch-linkage credit", ) for idx, rec in enumerate(analytes_raw): if not isinstance(rec, dict): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"on_target_analytes[{idx}] must be an object") continue raw_aid = rec.get("analyte_id") if type(raw_aid) is not str or not raw_aid.strip(): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"on_target_analytes[{idx}] missing analyte_id") continue aid = _SHIELD_ANALYTE_ALIASES.get(raw_aid.strip(), raw_aid.strip()) seen_analytes.add(aid) if aid in conflicted_on_target: continue row_valid = True tmp_ref: set[str] = set() tmp_c1: set[str] = set() tmp_c2: set[str] = set() if aid in _SHIELD_COMP1_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_COMP1_LEAD, role_comp1_batches=tmp_c1, ) raw_hip_lot = rec.get("peptide_reagent_lot_id") row_hip_lot: str | None = None if ( type(raw_hip_lot) is not str or not raw_hip_lot or raw_hip_lot != raw_hip_lot.strip() or not _SHIELD_STRICT_ID_RE.match(raw_hip_lot) ): row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: missing valid unpadded peptide_reagent_lot_id matching " f"{_SHIELD_STRICT_ID_RE.pattern} (got {raw_hip_lot!r}); excluded from biological " f"adjudication and batch-linkage credit", ) else: row_hip_lot = raw_hip_lot if not hip11_exchange_qc_valid or rqc_hip11_lot is None: row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: excluded from biological adjudication and batch-linkage credit because " f"mandatory register_qc_records.hip11_dq25_dq8t_dq22_exchange_qc_passed, " f"hip11_peptide_reagent_lot_id, or parent register_qc_records Comp1 batch linkage is missing or failed", ) elif row_hip_lot is not None and row_hip_lot != rqc_hip11_lot: row_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"{aid}: HIP11 peptide_reagent_lot_id mismatch: on_target_analytes=" f"{row_hip_lot!r} != register_qc_records.hip11_peptide_reagent_lot_id={rqc_hip11_lot!r}; " f"excluded from biological adjudication and batch-linkage credit", ) if b_err is None and (not tmp_c1 or not tmp_c1.issubset(rqc_comp1_batches)): row_valid = False _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