"gate_resp1_flow_ul_min": 200.0, "gate_resp1_dose_ieq": 200.0, "gate_resp1_ocr_pmol_min_ieq": 3.45, "gate_resp1_flow_dose_record_sha256": "8" * 64, "gate_resp1_snr": 16.5, "gate_resp1_po2_drop_mmhg": 3.4, "gate_resp1_blank_drift_mmhg": 0.18, "gate_resp1_dna_recovery_pct": 93.0, "gate_resp1_ocr_ratio": 1.02, "gate_resp1_ocr_cv_pct": 2.1, "gate_resp1_replicates_n": 6, "gate_resp1_whole_prep_ocr_record": (lambda _b: {**_b, "record_sha256": sha256_bytes(canonical_json_bytes(_b))})({ "specimen_id": f"SPEC-WP-{block_prefix}-{lot_id}", "lot_id": lot_id, "exposure_id": f"EXP-{block_prefix}-{lot_id}", "inlet_po2_mmhg": 35.65, "flow_ul_min": 200.0, "dose_ieq": 200.0, "ocr_pmol_min_ieq": 3.45, "ocr_ratio": 1.02, "ocr_cv_pct": 2.1, "replicates_n": 6, }), "gate_resp1_pure_endocrine_ocr_record": (lambda _b: {**_b, "record_sha256": sha256_bytes(canonical_json_bytes(_b))})({ "specimen_id": f"SPEC-PE-{block_prefix}-{lot_id}", "lot_id": lot_id, "exposure_id": f"EXP-{block_prefix}-{lot_id}", "inlet_po2_mmhg": 35.65, "flow_ul_min": 200.0, "dose_ieq": 200.0, "ocr_pmol_min_ieq": pure_endocrine_ocr, "ocr_ratio": 0.98, "ocr_cv_pct": 1.9, "replicates_n": 6, }), "cluster_surface_o2_and_morphometry_record": (lambda _b: {**_b, "record_sha256": sha256_bytes(canonical_json_bytes(_b))})({ "lot_id": lot_id, "cluster_surface_po2_mmhg": 18.4, "cluster_surface_f_gsis": 0.912, "outer_band_z_min_um": 50.0, "outer_band_z_max_um": 175.0, "outer_band_d_p90_um": 92.0, "outer_band_sphericity_3d": 0.84, }), "dec134_washout_time_min_series": [0.0, 1.8, 3.4, 5.8, 9.0, 15.0, 20.0], "dec134_washout_remaining_peak_pct_series": [100.0, 70.0, 50.0, 24.0, 10.0, 4.5, 2.5], "dec134_washout_raw_trace_sha256": sha256_bytes(canonical_json_bytes({"time_min": [0.0, 1.8, 3.4, 5.8, 9.0, 15.0, 20.0], "remaining_peak_pct": [100.0, 70.0, 50.0, 24.0, 10.0, 4.5, 2.5]})), "dec134_washout_trace_span_min": 20.0, "dec134_washout_tail_remaining_pct": 2.5, "dec134_washout_mass_recovery_pct": 98.0, "dec134_washout_t50_min": 3.4, "dec134_washout_mean_transit_min": 4.53, "dec134_washout_t90_min": 9.0, } if matched_comparator_id is not None: out["matched_comparator_id"] = matched_comparator_id if gate0s_receipt is not None: out["gate0s_escalation_receipt"] = gate0s_receipt if dec084_receipt is not None: out["dec084_matched_age_mixture_receipt"] = dec084_receipt if rule_s8: out["rule_s8_extended_clock_applicable"] = True out["rule_s8_locked_analysis_plan_id"] = "PLAN-S8-LOCKED-001" out["rule_s8_candidate_windows_k"] = rule_s8_k out["rule_s8_window_selection_design"] = rule_s8_design out["rule_s8_comparator_receipt_sha256"] = "c" * 64 t_hv_dt = parse_utc_iso_ts(out["dual_clocks_utc"]["assay_harvest_utc"]) t_eh_str = (t_hv_dt - timedelta(days=7)).strftime("%Y-%m-%dT%H:%M:%SZ") if t_hv_dt is not None else "2026-10-20T00:00:00Z" b40_l = out["o2_40_mmhg"]["blocks"] b100_l = out["o2_100_mmhg"]["blocks"] out["rule_s8_earlier_window_records"] = [ { "block_id_40mmhg": b40_l[i]["block_id"], "block_id_100mmhg": b100_l[i]["block_id"], "trace_id_40mmhg": f"TR-EARLY-{block_prefix}-{lot_id}-40-{i+1}", "trace_id_100mmhg": f"TR-EARLY-{block_prefix}-{lot_id}-100-{i+1}", "early_harvest_utc": t_eh_str, "z2_40mmhg": b40_l[i]["rule_s8_comparator_z2_increment"], "z2_100mmhg": b100_l[i]["rule_s8_comparator_z2_increment"], } for i in range(n_blocks) ] if rule_s8_design == "PILOT_SCREEN_THEN_DISJOINT_CONFIRMATION": out["rule_s8_pilot_block_ids"] = ["S8P-1", "S8P-2", "S8P-3"] if specimen_id is not None: all_tids = [b["trace_id"] for b in out["o2_40_mmhg"]["blocks"]] + [b["trace_id"] for b in out["o2_100_mmhg"]["blocks"]] reg_alq = [f"{specimen_id}-ALQ-{i+1}" for i in range(len(all_tids))] col_ts = trace_collected_at_utc or out["dual_clocks_utc"]["assay_harvest_utc"] r2_pb = { "specimen_id": specimen_id, "specimen_lot_id": lot_id, "intervention_cohort_id": intervention_cohort_id or "COHORT-UNKNOWN", "candidate_gene": candidate_gene or "PMAIP1+BCL2L11", "registered_aliquot_ids": reg_alq, "trace_aliquot_links": [ {"trace_id": tid, "aliquot_id": alq, "collected_at_utc": col_ts} for tid, alq in zip(all_tids, reg_alq) ], } out["readout2_specimen_provenance"] = {**r2_pb, "provenance_sha256": sha256_bytes(canonical_json_bytes(r2_pb))} return out def _mk_r8_readout3b( *, include_sirpa_low: bool = False, matched_vehicle_lot_id: Optional[str] = None, include_hla_e_spr: bool = True, specimen_id: Optional[str] = None, specimen_lot_id: Optional[str] = None, intervention_cohort_id: Optional[str] = None, ) -> dict[str, Any]: donors: list[dict[str, Any]] = [] aliquot_ids: list[str] = [] for i in range(6): d = 0.25 * (i - 2.5) r1: dict[str, Any] = { "nkg2a_pos_nkg2c_neg_kir_neg_lysis_pct": round(4.6 + d, 3), "nkg2a_pos_cd107a_degranulation_pct": round(5.8 + d, 3), "nkg2c_pos_nkg2a_neg_cd57_pos_lysis_pct": round(6.5 + d, 3), "adaptive_nkg2c_kir_pos_lysis_pct": round(6.2 + d, 3), "adaptive_nkg2c_kir_neg_lysis_pct": round(6.8 + d, 3), "nkg2a_neg_nkg2c_neg_kir_pos_lysis_pct": round(6.1 + d, 3), "positive_control_lysis_pct": round(48.0 + i, 3), "negative_control_lysis_pct": round(2.1 + 0.1 * i, 3), } r2: dict[str, Any] = { "nkg2a_pos_nkg2c_neg_kir_neg_lysis_pct": round(5.2 + d, 3), "nkg2a_pos_cd107a_degranulation_pct": round(6.4 + d, 3), "nkg2c_pos_nkg2a_neg_cd57_pos_lysis_pct": round(7.0 + d, 3), "adaptive_nkg2c_kir_pos_lysis_pct": round(6.7 + d, 3), "adaptive_nkg2c_kir_neg_lysis_pct": round(7.2 + d, 3), "nkg2a_neg_nkg2c_neg_kir_pos_lysis_pct": round(6.6 + d, 3), "positive_control_lysis_pct": round(52.0 + i, 3), "negative_control_lysis_pct": round(2.4 + 0.1 * i, 3), "allogeneic_cd8_ctl_lysis_pct": round(2.8 + 0.15 * (i - 2.5), 3), "continuous_0_24h_kinetic_trace_verified": True, "continuous_0_24h_kinetic_trace": (lambda _tb: {**_tb, "trace_sha256": sha256_bytes(canonical_json_bytes(_tb))})({ "assay_platform": "INCUCYTE_LIVE_0_24H_IMPEDANCE", "specimen_id": (aliquot_ids.append(f"{specimen_id}-ALIQ-D{i+1}") or f"{specimen_id}-ALIQ-D{i+1}") if specimen_id is not None else f"R3B-SPEC-D{i+1}", "timepoints_h": [0.0, 4.0, 8.0, 12.0, 18.0, 24.0], "target_lysis_pct_series": [0.0, round(1.8 + 0.1 * i, 3), round(3.1 + 0.1 * i, 3), round(4.2 + 0.1 * i, 3), round(4.8 + 0.1 * i, 3), round(5.2 + d, 3)], }), } if include_sirpa_low: r1["il12_il18_sirpa_low_lysis_pct"] = round(6.0 + d, 3) r2["il12_il18_sirpa_low_lysis_pct"] = round(6.7 + d, 3) if matched_vehicle_lot_id is not None: r1["veh_nkg2a_pos_lysis_pct"] = round(4.4 + d, 3) r1["veh_cd107a_pct"] = round(5.5 + d, 3) r1["veh_nkg2c_pos_lysis_pct"] = round(6.2 + d, 3) r1["veh_adaptive_kir_pos_lysis_pct"] = round(6.0 + d, 3) r1["veh_adaptive_kir_neg_lysis_pct"] = round(6.5 + d, 3) r1["veh_kir_pos_lysis_pct"] = round(5.9 + d, 3) r2["veh_nkg2a_pos_lysis_pct"] = round(5.0 + d, 3) r2["veh_cd107a_pct"] = round(6.1 + d, 3) r2["veh_nkg2c_pos_lysis_pct"] = round(6.7 + d, 3) r2["veh_adaptive_kir_pos_lysis_pct"] = round(6.4 + d, 3) r2["veh_adaptive_kir_neg_lysis_pct"] = round(6.9 + d, 3) r2["veh_kir_pos_lysis_pct"] = round(6.4 + d, 3) r2["veh_allogeneic_cd8_ctl_lysis_pct"] = round(2.6 + 0.15 * (i - 2.5), 3) if include_sirpa_low: r1["veh_sirpa_low_lysis_pct"] = round(5.7 + d, 3) r2["veh_sirpa_low_lysis_pct"] = round(6.4 + d, 3) donors.append({ "donor_id": f"NK-D{i+1}", "cmv_status": "CMV_POS" if i < 3 else "CMV_NEG", "regime_i_ifng_24h": r1, "regime_ii_t0_unpreinduced": r2, }) out: dict[str, Any] = { "canonical_readout3b_producer_sha256": "2" * 64, "hla_e_spr_affinity_evidence": ( {"kd_nkg2a_u95_uM": 2.45, "kd_nkg2a_se_uM": 0.18, "kd_nkg2c_mean_uM": 6.52, "kd_nkg2c_se_uM": 0.42, "spr_artifact_sha256": "7" * 64} if include_hla_e_spr else "N/A_NO_HLAE_MODULE" ), "covalent_hla_e_sct_comparator": ( (lambda _sb: {**_sb, "comparator_receipt_sha256": sha256_bytes(canonical_json_bytes(_sb))})({ "comparator_construct_id": "MODEB_COVALENT_HLAE_0103_VMAPRTLVL_REF", "hcmv_pos_donor_count": 6, "nkg2a_pos_lysis_u95_pct": 5.8, "adaptive_kir_pos_lysis_u95_pct": 6.9, "adaptive_kir_neg_lysis_u95_pct": 7.1, "cd107a_fold_u95": 1.12, "ul40_ctl_lysis_u95_pct": 3.2, "comparator_verdict": "PASS", }) if include_hla_e_spr else "N/A_NO_HLAE_MODULE" ), "donor_records": donors, } if matched_vehicle_lot_id is not None: out["matched_vehicle_lot_id"] = matched_vehicle_lot_id if specimen_id is not None: prov_b = { "specimen_id": specimen_id, "specimen_lot_id": specimen_lot_id or "LOT-UNKNOWN", "intervention_cohort_id": intervention_cohort_id or "COHORT-UNKNOWN", "registered_aliquot_ids": aliquot_ids, } out["assay_specimen_provenance"] = {**prov_b, "provenance_sha256": sha256_bytes(canonical_json_bytes(prov_b))} return out def _mk_r8_mat(prod: str, bank: str, lot: str, ts: str = "2026-10-08T08:00:00Z") -> dict[str, Any]: return _sign_receipt({ "stage": "BANK_MATERIALIZATION", "verdict": "PASS", "product_id": prod, "bank_id": bank, "lot_id": lot, "evidence_scope": "exact_product", "recorded_at_utc": ts, "edited_allele_qc_passed": True, }) def _mk_r8_switch( prod: str, bank: str, lot: str, route: str, mat_ev: Mapping[str, Any], ts: str = "2026-10-12T09:00:00Z", *, candidate_gene: Optional[str] = None, comparator_nt_lot_id: Optional[str] = None, coating_identity: Optional[Mapping[str, str]] = None, prereq_receipts: Optional[Mapping[str, str]] = None, transient_engagement: Optional[Mapping[str, Any]] = None, ) -> dict[str, Any]: sw_nm = CANONICAL_WAVE6_PRODUCTS[prod]["required_switch"] ctrl_lot = comparator_nt_lot_id or (coating_identity["matched_blank_vehicle_lot_id"] if coating_identity else f"CTRL-{lot}") body: dict[str, Any] = { "stage": "NATIVE_SAFETY_SWITCH", "verdict": "PASS", "product_id": prod, "bank_id": bank, "lot_id": lot, "route_id": route, "evidence_scope": "exact_product", "recorded_at_utc": ts, "parent_receipt_sha256": mat_ev["receipt_sha256"], "switch_name": sw_nm, "canonical_gate34_producer_sha256": "3" * 64, "canonical_gate34_verdict": "PASS", "gate34_passed": True, "oq012_clonogenic_block": _mk_r8_oq012(), "matched_control_switch_parity_evidence": _mk_r8_switch_parity(ctrl_lot), } if candidate_gene is not None: body["candidate_gene"] = candidate_gene if comparator_nt_lot_id is not None: body["comparator_nt_lot_id"] = comparator_nt_lot_id if coating_identity is not None: body.update(coating_identity) if prereq_receipts is not None: body["prerequisite_receipt_sha256s"] = dict(prereq_receipts) if transient_engagement is not None: body["transient_target_engagement_record"] = dict(transient_engagement) body["specimen_id"] = transient_engagement["specimen_id"] _t_es = parse_utc_iso_ts(transient_engagement["assay_window_start_utc"]) _t_ee = parse_utc_iso_ts(transient_engagement["assay_window_end_utc"]) _t_st_sw = (_t_es + timedelta(minutes=30)) if _t_es else None _t_en_sw = (_t_ee - timedelta(minutes=15)) if _t_ee else None body["assay_started_at_utc"] = _t_st_sw.strftime("%Y-%m-%dT%H:%M:%SZ") if _t_st_sw else transient_engagement["assay_window_start_utc"] body["assay_completed_at_utc"] = _t_en_sw.strftime("%Y-%m-%dT%H:%M:%SZ") if _t_en_sw else transient_engagement["assay_window_end_utc"] if _t_st_sw is not None: body["assay_24h_collection_utc"] = (_t_st_sw + timedelta(hours=24)).strftime("%Y-%m-%dT%H:%M:%SZ") body["assay_72h_collection_utc"] = (_t_st_sw + timedelta(hours=72)).strftime("%Y-%m-%dT%H:%M:%SZ") if sw_nm == "DUAL_TBP_ICASP9_PLUS_CDK1_HSVTK": body.update({ "primary_tbp_icasp9_oq012": _mk_r8_oq012(), "backup_cdk1_hsvtk_oq012": _mk_r8_oq012(), "orthogonal_gcv_cid_non_interference": True, }) return _sign_receipt(body) def _mk_r8_unit_part(k_total: int, n_total: int, n_units: int = 6) -> list[dict[str, Any]]: base_n, rem_n = divmod(n_total, n_units) base_k, rem_k = divmod(k_total, n_units) return [