if type(m_qc) is not bool: mix_ok = False sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.qc_passed must be strict bool", ) m_mon_oos = bool(m_mon is not None and m_mon < _SHIELD_MIN_MONOMER_PCT) m_pdi_oos = bool(m_pdi is not None and m_pdi > _SHIELD_MAX_DLS_PDI) m_agg_oos = bool(m_no_agg is False) if m_mon_oos or m_pdi_oos or m_agg_oos: mix_ok = False quant_sec_failed = True if m_qc is False: sec_valid_out_of_spec = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD: {mlbl} (mixture_id={mid_s!r}) " f"failed per-mixture co-formulation QC (monomer_pct={m_mon}, dls_pdi={m_pdi}, " f"no_aggregates={m_no_agg}) with consistent qc_passed=False", ) else: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl} (mixture_id={mid_s!r}) " f"per-mixture SEC-MALS/DLS threshold failure contradicts qc_passed={m_qc!r}", ) elif m_qc is False: mix_ok = False sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.qc_passed=False without out-of-spec measurement", ) m_eq_attested: bool | None = None if "equimolar_1to1_molar_ratio_attested" in m_rec: raw_eq = m_rec.get("equimolar_1to1_molar_ratio_attested") if raw_eq is not True: mix_ok = False sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.equimolar_1to1_molar_ratio_attested " f"must be literal boolean True when supplied (got {raw_eq!r})", ) else: m_eq_attested = True m_ratio_basis: str | None = None if "ratio_basis_attestation" in m_rec: raw_rb = m_rec.get("ratio_basis_attestation") if type(raw_rb) is not str or raw_rb not in _allowed_mix_ratio_basis_tokens: mix_ok = False sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {mlbl}.ratio_basis_attestation " f"must be in {sorted(_allowed_mix_ratio_basis_tokens)} when supplied (got {raw_rb!r})", ) else: m_ratio_basis = raw_rb if mix_ok and mid_s is not None and type(c1_bid) is str and type(c2_bid) is str: candidate_passing_mixtures[mid_s] = (c1_bid, c2_bid) candidate_mixture_ratio_meta[mid_s] = { "equimolar_1to1_molar_ratio_attested": m_eq_attested, "ratio_basis_attestation": m_ratio_basis, } if valid_mix_monomers and ck_mon is not None and ck_mon > min(valid_mix_monomers) + 1e-9: top_sec_overstated = True sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: top-level cocktail_1to1_monomer_pct={ck_mon:.2f}% " f"overstates worst per-mixture monomer_pct={min(valid_mix_monomers):.2f}%", ) if valid_mix_pdis and dls_pdi is not None and dls_pdi < max(valid_mix_pdis) - 1e-9: top_sec_overstated = True sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: top-level dls_pdi={dls_pdi:.4f} " f"understates worst per-mixture dls_pdi={max(valid_mix_pdis):.4f}", ) if sec_valid_out_of_spec and sec_input_missing_or_malformed: sec_qc_cls = "BOTH_OUT_OF_SPEC_AND_MALFORMED_INPUT_HOLD" elif sec_valid_out_of_spec: 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