ev_tier = payload.get("evidence_tier") if ev_tier is None: holds.append("MISSING_evidence_tier") elif not _is_nonempty_str(ev_tier) or ev_tier not in _ALLOWED_EVIDENCE_TIERS: failures.append("INVALID_evidence_tier") valid_tier = ev_tier if (_is_nonempty_str(ev_tier) and ev_tier in _ALLOWED_EVIDENCE_TIERS) else None _verify_canonical_manifest_context(canonical_manifest, canonical_manifest_sha256, valid_tier, failures) valid_construct_sha = _verify_parent_manifest_digests(payload, holds, failures) lot_id = payload.get("lot_id") if lot_id is None: holds.append("MISSING_lot_id") elif not _is_nonempty_str(lot_id): failures.append("INVALID_lot_id") valid_lot = lot_id if _is_nonempty_str(lot_id) else None bank_id = payload.get("bank_id") if bank_id is None: holds.append("MISSING_bank_id") elif not _is_nonempty_str(bank_id): failures.append("INVALID_bank_id") valid_bank = bank_id if _is_nonempty_str(bank_id) else None origin = payload.get("starting_cell_origin") if origin is None: holds.append("MISSING_starting_cell_origin") elif not _is_nonempty_str(origin) or origin not in _ALLOWED_WAVE6_BANK_ORIGINS: failures.append("INVALID_starting_cell_origin") valid_origin = origin if (_is_nonempty_str(origin) and origin in _ALLOWED_WAVE6_BANK_ORIGINS) else None product_id = payload.get("product_id") if product_id is None: holds.append("MISSING_product_id") elif not _is_nonempty_str(product_id) or product_id not in _CANONICAL_ALL_PRODUCTS: failures.append("INVALID_OR_UNREGISTERED_product_id") elif valid_origin == "allogeneic_hiPSC" and product_id not in _CANONICAL_ALLO_HIPSC_PRODUCTS: failures.append("PRODUCT_ORIGIN_MISMATCH") elif valid_origin == "allogeneic_EnSC" and product_id not in _CANONICAL_ALLO_ENSC_PRODUCTS: failures.append("PRODUCT_ORIGIN_MISMATCH") elif valid_origin == "autologous_hiPSC" and product_id not in _CANONICAL_AUTO_PRODUCTS: failures.append("PRODUCT_ORIGIN_MISMATCH") valid_product = product_id if (_is_nonempty_str(product_id) and product_id in _CANONICAL_ALL_PRODUCTS) else None gp2_in = _check_pct(payload, "input_gp2_pos_pct", holds, failures, fail_code="INVALID_GP2_PCT") # Separate disposition for autologous lines: <25% -> explicit BYPASS (not PASS, promotion_authorized=False); >=25% -> FAIL! if valid_origin == "autologous_hiPSC": tot_opt = payload.get("input_total_loaded_cells") pos_opt = payload.get("input_gp2_pos_cells") if tot_opt is not None or pos_opt is not None: if not _is_strict_int(tot_opt) or tot_opt <= 0 or not _is_strict_int(pos_opt) or pos_opt < 0 or pos_opt > tot_opt: failures.append("INVALID_AUTOLOGOUS_INPUT_CELL_COUNTS") elif gp2_in is not None: calc_auto_pct = _safe_pct_ratio(float(pos_opt), float(tot_opt)) if calc_auto_pct is None: failures.append("FAIL_NONFINITE_AUTOLOGOUS_INPUT_GP2_PCT") else: if abs(calc_auto_pct - gp2_in) > 0.5: failures.append("FAIL_INPUT_GP2_PREVALENCE_COUNT_MISMATCH") if calc_auto_pct >= 25.0: failures.append("OUT_OF_SCOPE_AUTOLOGOUS_REJECTED_ON_ALLOGENEIC_ONLY_MCB_GATE") if gp2_in is not None and gp2_in >= 25.0: failures.append("OUT_OF_SCOPE_AUTOLOGOUS_REJECTED_ON_ALLOGENEIC_ONLY_MCB_GATE") _audit_canonical_identifier_fields(payload, label="GP2_PAYLOAD", failures=failures) if not failures and not holds and gp2_in is not None and 0.0 <= gp2_in < 25.0: return _enforce_strict_json_report({ "gate": "Gate 37-SORT-GP2", "evidence_tier": valid_tier, "verdict": "BYPASS_AUTOLOGOUS_LOW_GP2", "decision": "BYPASS_AUTOLOGOUS_LOW_GP2", "authority_scope": "STAGE_LIMITED_SORT_ONLY", "bank_qualified": False, "intermediate_bank_qualified": False, "promotion_authorized": False, "reason": "RT1_AUTOLOGOUS_BYPASS_LT_25PCT_SEPARATE_DISPOSITION", "failures": [], "holds": [], }) return _finalize_gate_verdict( "Gate 37-SORT-GP2", failures, holds, "PASS_GP2_INTERMEDIATE_BANK_QUALIFIED", "", evidence_tier=valid_tier, pass_authority_scope="BANK_QUALIFICATION_ONLY", bank_qualified_on_wetlab_pass=False, authorize_promotion_on_wetlab_pass=False, extra={"intermediate_bank_qualified": False}, ) if gp2_in is not None and 0.0 <= gp2_in < 40.0: failures.append("FAIL_LOW_ALLOGENEIC_GP2_INPUT_LT_40PCT") # Mature acinar exclusion (CPA1+/PRSS1+/PTF1A+ <= 2.0%), distinct from PDX1+/NKX6.1+ progenitors! acinar_pct = _check_pct(payload, "mature_acinar_cpa1_prss1_ptf1a_pct", holds, failures, max_pass=2.0, fail_code="FAIL_MATURE_ACINAR_CONTAMINATION_GT_2PCT") gpi_pct = _check_pct(payload, "gpi_post_dissociation_mfi_retention_pct", holds, failures, min_pass=85.0, fail_code="FAIL_GPI_SHEDDING") purity_pct = _check_pct(payload, "post_sort_pdx1_nkx61_pct", holds, failures, min_pass=85.0, fail_code="FAIL_LOW_PP_PURITY") # Strict integer-count reconciliation of BOTH input GP2+ prevalence AND conditional recovery! denom_type = payload.get("macs_recovery_denominator_type") if denom_type is None: holds.append("MISSING_macs_recovery_denominator_type") elif not _is_nonempty_str(denom_type) or denom_type not in ("CONDITIONAL_GP2_POS_INPUT", "TOTAL_LOADED_CELLS"): failures.append("INVALID_macs_recovery_denominator_type") eta_pct = _check_pct(payload, "macs_recovery_eta_pct", holds, failures, fail_code="FAIL_MACS_RECOVERY") if eta_pct is not None and denom_type == "CONDITIONAL_GP2_POS_INPUT" and eta_pct < 65.0: failures.append("FAIL_LOW_CONDITIONAL_MACS_RECOVERY_LT_65PCT") in_tot = payload.get("input_total_loaded_cells") in_gp2 = payload.get("input_gp2_pos_cells") rec_gp2 = payload.get("recovered_gp2_pos_cells") if in_tot is None: holds.append("MISSING_input_total_loaded_cells") elif not _is_strict_int(in_tot) or in_tot <= 0: failures.append("INVALID_input_total_loaded_cells") if in_gp2 is None: holds.append("MISSING_input_gp2_pos_cells") elif not _is_strict_int(in_gp2) or in_gp2 <= 0: failures.append("INVALID_input_gp2_pos_cells") if rec_gp2 is None: holds.append("MISSING_recovered_gp2_pos_cells") elif not _is_strict_int(rec_gp2) or rec_gp2 < 0: failures.append("INVALID_recovered_gp2_pos_cells") calc_input_gp2_pct: Optional[float] = None calc_cond_recovery_pct: Optional[float] = None if _is_strict_int(in_tot) and in_tot > 0 and _is_strict_int(in_gp2) and in_gp2 > 0: if in_gp2 > in_tot: failures.append("IMPOSSIBLE_INPUT_GP2_EXCEEDS_TOTAL_LOADED") else: calc_input_gp2_pct = _safe_pct_ratio(float(in_gp2), float(in_tot)) if calc_input_gp2_pct is None: failures.append("FAIL_NONFINITE_INPUT_GP2_PREVALENCE_PCT") else: if gp2_in is not None and abs(calc_input_gp2_pct - gp2_in) > 0.5: failures.append("FAIL_INPUT_GP2_PREVALENCE_COUNT_MISMATCH") if calc_input_gp2_pct < 40.0: failures.append("FAIL_CALC_INPUT_GP2_PREVALENCE_LT_40PCT") if _is_strict_int(rec_gp2) and rec_gp2 >= 0: if rec_gp2 > in_tot: failures.append("IMPOSSIBLE_RECOVERED_EXCEEDS_TOTAL_LOADED") if rec_gp2 > in_gp2: failures.append("IMPOSSIBLE_RECOVERED_EXCEEDS_INPUT_GP2") else: calc_cond_recovery_pct = _safe_pct_ratio(float(rec_gp2), float(in_gp2)) if calc_cond_recovery_pct is None: failures.append("FAIL_NONFINITE_CONDITIONAL_MACS_RECOVERY_PCT") else: if calc_cond_recovery_pct < 65.0: failures.append("FAIL_LOW_CONDITIONAL_MACS_RECOVERY_LT_65PCT") if eta_pct is not None and 0.0 <= eta_pct <= 100.0: if denom_type == "CONDITIONAL_GP2_POS_INPUT": if abs(calc_cond_recovery_pct - eta_pct) > 0.5: failures.append("RECOVERY_DENOMINATOR_ARITHMETIC_MISMATCH") elif denom_type == "TOTAL_LOADED_CELLS": calc_tot_pct = _safe_pct_ratio(float(rec_gp2), float(in_tot)) if calc_tot_pct is None: failures.append("FAIL_NONFINITE_TOTAL_RECOVERY_PCT") elif abs(calc_tot_pct - eta_pct) > 0.5: failures.append("RECOVERY_DENOMINATOR_ARITHMETIC_MISMATCH") # Affinity & paralog selectivity parent_aff: dict[str, Optional[float]] = {} for fld, lo_ok, hi_ok, fcode in [ ("kd_gp2_nM", 0.0, 5.0, "FAIL_WEAK_GP2_AFFINITY"), ("selectivity_vs_umod_fold", 100.0, None, "FAIL_UMOD_SELECTIVITY"), ]: if fld not in payload or payload[fld] is None: holds.append(f"MISSING_{fld}") parent_aff[fld] = None elif not _is_num(payload[fld]) or float(payload[fld]) <= 0.0: failures.append(f"INVALID_OR_NONPOSITIVE_{fld}") parent_aff[fld] = None else: v = float(payload[fld]) parent_aff[fld] = v if hi_ok is not None and v > hi_ok: failures.append(fcode) if lo_ok > 0.0 and v < lo_ok: failures.append(fcode) parent_kd = parent_aff["kd_gp2_nM"] parent_sel = parent_aff["selectivity_vs_umod_fold"] # Strict integer teratoma counts, denominator >= 12, follow-up >= 26 wk, host == SCID-Beige, # explicit challenge_dose_cells >= 10_000_000, AND complete per_animal_exposures with mandatory # per-animal tumor_detected (strict bool; None -> HOLD; True -> immediate FAIL) & followup_weeks >= 26.0 # reconciled via the common study-level alias validators against archived GATE-35-GP2 record (Audit R12-05). caller_ev_res = _audit_study_level_int_aliases( payload, role="CALLER", gate_tag="GP2", field_tag="TERATOMA_EVENTS", alias_keys=STUDY_TERATOMA_EVENTS_ALIASES, min_val=0, allow_zero=True, nonzero_event_fail_code="FAIL_TERATOMA_DETECTED", below_min_fail_code="INVALID_teratoma_events", missing_hold_code="MISSING_teratoma_events", invalid_fail_code="INVALID_teratoma_events", holds=holds, failures=failures, ) caller_n_res = _audit_study_level_int_aliases( payload, role="CALLER", gate_tag="GP2", field_tag="TERATOMA_N", alias_keys=STUDY_TERATOMA_N_ALIASES, min_val=12, allow_zero=False, below_min_fail_code="FAIL_TERATOMA_DENOMINATOR_LT_12", missing_hold_code="MISSING_teratoma_n", invalid_fail_code="INVALID_teratoma_n", holds=holds, failures=failures, ) caller_wk_res = _audit_study_level_followup_aliases( payload, role="CALLER", gate_tag="GP2", min_weeks=26.0, alias_keys=STUDY_TERATOMA_FOLLOWUP_ALIASES, holds=holds, failures=failures, ) caller_host_res = _audit_study_level_host_aliases( payload, role="CALLER", gate_tag="GP2", required_host="SCID-Beige", alias_keys=STUDY_TERATOMA_HOST_ALIASES, wrong_host_fail_code="FAIL_WRONG_TUMOR_HOST_STRAIN_REQUIRES_SCID_BEIGE", invalid_host_fail_code="INVALID_tumor_host_strain", missing_hold_code="MISSING_tumor_host_strain", holds=holds, failures=failures, ) caller_dose_res = _audit_study_level_int_aliases( payload, role="CALLER", gate_tag="GP2", field_tag="DOSE", alias_keys=STUDY_TERATOMA_DOSE_ALIASES, min_val=10_000_000, allow_zero=False, below_min_fail_code="FAIL_GP2_CHALLENGE_DOSE_LT_1E7_CELLS", missing_hold_code="MISSING_challenge_dose_cells", invalid_fail_code="INVALID_challenge_dose_cells", holds=holds, failures=failures,