and rqc_6dfx_lot is not None and len(collided_reagents) == 0 ) derived_summary["register_qc_excluded_from_spr_assay_batch_counts"] = True # 2b. Quantitative SEC-MALS / DLS monomer & 1:1 co-formulation stability (cocktail-bound BOTH leads; >= 95.0% monomer, # PDI <= 0.15) evaluated STRICTLY BEFORE SPR and donor biological adjudication (R13 0039-B2 / 0037-M1 + R14 0039-B3 + R15 0037-B1/0039-B1)! # Out-of-spec physical protein material (< 95.0% monomer, PDI > 0.15, or detected aggregates) is an UNQUALIFIED # MATERIAL INPUT (HOLD_INVALID_OR_MISSING_INPUT, failure_domain=None), NOT a biological target FAIL, AND every # SPR and cocktail donor assay MUST positively link ALL of its expression batches to passing construct/cocktail # SEC-MALS/DLS material qualification before contributing to biological PASS/FAIL or batch-linkage credit! derived_summary["physicochemical_out_of_spec_disposition"] = "HOLD_INVALID_OR_MISSING_INPUT_UNQUALIFIED_MATERIAL" derived_summary["spr_material_qualification_reconciled_before_bio"] = True derived_summary["donor_material_qualification_reconciled_before_bio"] = True sec = observation.get("sec_mals_dls_monomer_coformulation") sec_comp1_qualified_batches: set[str] = set() sec_comp2_qualified_batches: set[str] = set() sec_cocktail_qualified = False sec_cocktail_qualified_batches: set[str] = set() sec_cocktail_qualified_comp1_batches: set[str] = set() sec_cocktail_qualified_comp2_batches: set[str] = set() qualified_passing_mixtures: dict[str, tuple[str, str]] = {} conflicted_mixture_ids: set[str] = set() if not isinstance(sec, dict): _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: Missing typed sec_mals_dls_monomer_coformulation record", ) derived_summary["sec_mals_dls"] = { "comp1_monomer_pct": None, "comp2_monomer_pct": None, "cocktail_1to1_monomer_pct": None, "dls_pdi": None, "no_aggregates_or_precipitation": None, "physicochemical_qc_classification": "MISSING_OR_MALFORMED_OR_CONTRADICTORY_INPUT_HOLD", "qualified_cocktail_batch_ids": [], "qualified_coformulation_mixtures": {}, "qualified_coformulation_mixtures_count": 0, "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": False, } else: sec_input_missing_or_malformed = False sec_valid_out_of_spec = False sec_top_qc_bad = False tmp_ref_sec: set[str] = set() tmp_c1_sec: set[str] = set() tmp_c2_sec: set[str] = set() sec_b_err = _shield_validate_batch_ids( sec.get("expression_batch_ids"), "sec_mals_dls_monomer_coformulation", passing_batch_constructs, tmp_ref_sec, require_cocktail_both_leads=True, role_comp1_batches=tmp_c1_sec, role_comp2_batches=tmp_c2_sec, ) if sec_b_err is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {sec_b_err}") hflag, hflag_err = _shield_check_num(sec.get("protenix_homodimer_flag_iptm_addressed"), "protenix_homodimer_flag_iptm_addressed", lo=0.0, hi=1.0) hflag_ok = bool(hflag_err is None and hflag is not None and abs(hflag - 0.6691) <= 1e-4) if not hflag_ok: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS record must explicitly address Comp2 " f"Protenix-v1 homodimer flag 0.6691 (got {sec.get('protenix_homodimer_flag_iptm_addressed')!r})", ) def _extract_sec_pct(primary_k: str, alias_k: str) -> float | None: nonlocal sec_input_missing_or_malformed has_p = primary_k in sec and sec[primary_k] is not None has_a = alias_k in sec and sec[alias_k] is not None if has_p and has_a: pv, perr = _shield_check_num(sec[primary_k], f"sec_mals_dls.{primary_k}", lo=0.0, hi=100.0) av, aerr = _shield_check_num(sec[alias_k], f"sec_mals_dls.{alias_k}", lo=0.0, hi=100.0) if perr is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {perr}") return None if aerr is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {aerr}") return None if pv is not None and av is not None and abs(pv - av) > 1e-9: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.{primary_k}={pv} disagrees with alias {alias_k}={av}", ) return None return pv if has_p: pv, perr = _shield_check_num(sec[primary_k], f"sec_mals_dls.{primary_k}", lo=0.0, hi=100.0) if perr is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {perr}") return None return pv if has_a: av, aerr = _shield_check_num(sec[alias_k], f"sec_mals_dls.{alias_k}", lo=0.0, hi=100.0) if aerr is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {aerr}") return None return av sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls missing required {primary_k} (or alias {alias_k})", ) return None c1_mon = _extract_sec_pct("comp1_monomer_pct", "comp1_qf09_pi2_monomer_fraction_pct") c2_mon = _extract_sec_pct("comp2_monomer_pct", "comp2_t006_monomer_fraction_pct") ck_mon = _extract_sec_pct("cocktail_1to1_monomer_pct", "cocktail_1to1_monomer_fraction_pct") dls_pdi, pdi_err = _shield_check_num(sec.get("dls_pdi"), "sec_mals_dls.dls_pdi", lo=0.0, hi=1.0) if pdi_err is not None: sec_input_missing_or_malformed = True _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: {pdi_err}") no_agg = sec.get("no_aggregates_or_precipitation") if type(no_agg) is not bool: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.no_aggregates_or_precipitation must be a strict boolean (got {no_agg!r})", ) c1_qc = sec.get("comp1_qf09_pi2_alone_monomer_qc_passed") c2_qc = sec.get("comp2_t006_alone_monomer_qc_passed") ck_qc = sec.get("cocktail_1to1_coformulation_qc_passed") for qc_lbl, qc_val in ( ("comp1_qf09_pi2_alone_monomer_qc_passed", c1_qc), ("comp2_t006_alone_monomer_qc_passed", c2_qc), ("cocktail_1to1_coformulation_qc_passed", ck_qc), ): if type(qc_val) is not bool: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.{qc_lbl} must be a strict boolean (got {qc_val!r})", ) quant_sec_failed = False c1_oos = bool(c1_mon is not None and c1_mon < _SHIELD_MIN_MONOMER_PCT) c2_oos = bool(c2_mon is not None and c2_mon < _SHIELD_MIN_MONOMER_PCT) ck_oos = bool(ck_mon is not None and ck_mon < _SHIELD_MIN_MONOMER_PCT) pdi_oos = bool(dls_pdi is not None and dls_pdi > _SHIELD_MAX_DLS_PDI) agg_oos = bool(no_agg is False) for mon_v, mon_oos, mon_qc, mon_lbl in ( (c1_mon, c1_oos, c1_qc, "comp1_monomer_pct"), (c2_mon, c2_oos, c2_qc, "comp2_monomer_pct"), (ck_mon, ck_oos, ck_qc, "cocktail_1to1_monomer_pct"), ): if mon_oos and mon_v is not None: quant_sec_failed = True if mon_qc is False: sec_valid_out_of_spec = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD: valid measured {mon_lbl}={mon_v:.2f}% " f"< {_SHIELD_MIN_MONOMER_PCT:.1f}% with consistent qc_flag=False (unqualified material input, " f"not biological target FAIL)", ) else: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS quantitative threshold/QC " f"contradiction: {mon_lbl}={mon_v:.2f}% < {_SHIELD_MIN_MONOMER_PCT:.1f}% contradicts qc_flag={mon_qc!r}", ) if pdi_oos and dls_pdi is not None: quant_sec_failed = True if ck_qc is False: sec_valid_out_of_spec = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD: valid measured dls_pdi={dls_pdi:.4f} " f"> {_SHIELD_MAX_DLS_PDI:.2f} with consistent cocktail qc_flag=False (unqualified material input, " f"not biological target FAIL)", ) else: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS/DLS polydispersity threshold/QC " f"contradiction: dls_pdi={dls_pdi:.4f} > {_SHIELD_MAX_DLS_PDI:.2f} contradicts qc_flag={ck_qc!r}", ) if agg_oos: quant_sec_failed = True if c1_qc is True or c2_qc is True or ck_qc is True: sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS/DLS boolean QC flag contradiction: " "qc_passed=True despite no_aggregates_or_precipitation=False", ) else: sec_valid_out_of_spec = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_OUT_OF_SPEC_MATERIAL_UNQUALIFIED_HOLD: valid measured aggregates or precipitation " "detected (no_aggregates_or_precipitation=False; unqualified material input, not biological target FAIL)", ) if c1_qc is False and not (c1_oos or agg_oos): sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS/DLS monomer QC flag for " "IsletSHIELD_QF09_pI2 alone is False without an out-of-spec measurement", ) if c2_qc is False and not (c2_oos or agg_oos): sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS/DLS monomer QC flag for " "IsletSHIELD_Comp2_T006 alone is False without an out-of-spec measurement", ) if ck_qc is False and not (ck_oos or pdi_oos or agg_oos): sec_input_missing_or_malformed = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", "PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: SEC-MALS/DLS 1:1 co-formulation QC flag " "(T006 + QF09_pI2) is False without an out-of-spec measurement", ) for gen_k in ("qc_pass", "qc_passed"): if gen_k in sec: if sec[gen_k] is True and quant_sec_failed: sec_input_missing_or_malformed = True sec_top_qc_bad = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.{gen_k}=True contradicts quantitative SEC-MALS/DLS threshold failure", ) elif sec[gen_k] is False and not quant_sec_failed: sec_input_missing_or_malformed = True sec_top_qc_bad = True _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"PHYSICOCHEMICAL_MISSING_OR_MALFORMED_INPUT_HOLD: sec_mals_dls.{gen_k}=False without quantitative out-of-spec measurement", ) elif type(sec[gen_k]) is not bool: sec_input_missing_or_malformed = True