scripts/verify_wave7_cellgemma_2p24_rebase.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_wave7_cellgemma_2p24_rebase.py · SHA-256: 5f31a6369f25031d…
ep = (st + timedelta(hours=48 + i)).strftime("%Y-%m-%dT%H:%M:%SZ")
dp = (st + timedelta(days=28, hours=i)).strftime("%Y-%m-%dT%H:%M:%SZ")
early_recs.append({"animal_id": f"E-COAT-{i+1:02d}", "arm": "COATED", "implanted_at_utc": imp_ts, "assessed_at_utc": ep, "raw_lectin_perfusion_signal": round(104.0 + 1.0 * (i - 3.5), 3), "adverse_event_code": "NONE"})
early_recs.append({"animal_id": f"E-VEH-{i+1:02d}", "arm": "BLANK_VEHICLE", "implanted_at_utc": imp_ts, "assessed_at_utc": ep, "raw_lectin_perfusion_signal": round(100.0 + 0.9 * (i - 3.5), 3), "adverse_event_code": "NONE"})
d28_recs.append({"animal_id": f"D28-COAT-{i+1:02d}", "arm": "COATED", "implanted_at_utc": imp_ts, "assessed_at_utc": dp, "pericapsular_collagen_thickness_um": round(58.0 + 1.5 * (i - 3.5), 3), "raw_lectin_vessel_density": round(106.0 + 1.0 * (i - 3.5), 3), "adverse_event_code": "NONE"})
d28_recs.append({"animal_id": f"D28-VEH-{i+1:02d}", "arm": "BLANK_VEHICLE", "implanted_at_utc": imp_ts, "assessed_at_utc": dp, "pericapsular_collagen_thickness_um": round(100.0 + 1.8 * (i - 3.5), 3), "raw_lectin_vessel_density": round(100.0 + 0.9 * (i - 3.5), 3), "adverse_event_code": "NONE"})
return {
"early_assay_mode": "TERMINAL_HISTOLOGY",
"early_cohort_enrolled_coated_n": 8, "early_cohort_enrolled_vehicle_n": 8,
"early_cohort_exclusions": [], "early_cohort_records": early_recs,
"day28_cohort_enrolled_coated_n": 8, "day28_cohort_enrolled_vehicle_n": 8,
"day28_cohort_exclusions": [], "day28_cohort_records": d28_recs,
}
def _mk_r8_b2_donors() -> list[dict[str, Any]]:
rows: list[dict[str, Any]] = []
for i in range(6):
# Raw paired values giving TAT red ~34%, C3a red ~32%, Plt rec ~26 pp with robust LOO!
rows.append({
"donor_id": f"D{i+1}",
"pos_ctrl_tat_fold": round(4.0 + 0.1 * i, 3),
"pos_ctrl_c3a_fold": round(3.0 + 0.1 * i, 3),
"pos_ctrl_plt_drop_pct": round(42.0 + 1.5 * i, 3),
"neg_ctrl_tat_fold": round(1.02 + 0.03 * i, 3),
"neg_ctrl_plt_retention_pct": round(95.0 - 0.5 * i, 3),
"tat_vehicle_ng_ml": round(100.0 + 4.0 * i, 3),
"tat_coated_ng_ml": round((100.0 + 4.0 * i) * (0.66 - 0.015 * (i - 2.5)), 3),
"c3a_vehicle_ng_ml": round(200.0 + 8.0 * i, 3),
"c3a_coated_ng_ml": round((200.0 + 8.0 * i) * (0.68 - 0.015 * (i - 2.5)), 3),
"platelet_baseline_k_ul": 250.0,
"platelet_vehicle_k_ul": round(125.0 + 3.0 * (i - 2.5), 3),
"platelet_coated_k_ul": round(192.0 + 5.0 * (i - 2.5), 3),
})
return rows
def _mk_r8_b2b_replicates(
*, coating_article_id: str = "ART-DEUC-R3P-01", evidence_scope: str = "bench_unedited",
) -> dict[str, Any]:
# Time-indexed independent replicates across Burst -> Day 10 -> Day 21 washout (K=7, n=6 each) + parent-specific envelope!
def _tp(h: float, lp: float, lb: float, rb: float, sp: float, sb: float) -> dict[str, Any]:
lp_r = [round(lp * (1.0 + d), 4) for d in (-0.012, -0.007, -0.002, 0.002, 0.007, 0.012)]
lb_r = [round(lb * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
rb_r = [round(rb * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
sp_r = [round(sp * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
sb_r = [round(sb * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
_stage_pfx = "B2-BLD" if abs(h - 2.0) <= 1e-6 else "B1-ELU"
return {
"hour_h": h,
"source_sample_ids": [f"{_stage_pfx}-H{int(h)}-R{ri}" for ri in range(1, len(lp_r) + 1)],
"biological_unit_ids": [f"{_stage_pfx}-UNIT-{ri}" for ri in range(1, len(lp_r) + 1)],
"local_parent_total_replicates_nM": lp_r, "local_parent_blq_flags": [v < 0.05 for v in lp_r],
"local_bmt_total_replicates_nM": lb_r, "local_bmt_blq_flags": [v < 0.05 for v in lb_r],
"recirc_bmt_total_replicates_nM": rb_r, "recirc_bmt_blq_flags": [v < 0.05 for v in rb_r],
"systemic_parent_total_replicates_nM": sp_r, "systemic_parent_blq_flags": [v < 0.05 for v in sp_r],
"systemic_bmt_total_replicates_nM": sb_r, "systemic_bmt_blq_flags": [v < 0.05 for v in sb_r],
}
return {
"local_assay_matrix": "human_serum_100pct",
"recirc_assay_matrix": "human_serum_100pct",
"local_measurement_includes_recirculation": True,
"fu_parent_replicates": [0.138, 0.139, 0.140, 0.140, 0.141, 0.142],
"fu_bmt_replicates": [0.148, 0.149, 0.150, 0.150, 0.151, 0.152],
"intersample_pk_envelope": (lambda _eb: {**_eb, "envelope_receipt_sha256": sha256_bytes(canonical_json_bytes(_eb))})({
"k_elim_local_max_per_h": 0.018,
"k_rise_local_max_per_h": 0.003,
"k_elim_parent_max_per_h": 0.004,
"k_rise_parent_max_per_h": 0.002,
"k_elim_bmt_max_per_h": 0.018,
"k_rise_bmt_max_per_h": 0.003,
"k_elim_sys_max_per_h": 0.025,
"k_rise_sys_max_per_h": 0.003,
"efficacy_window_start_h": 0.0,
"envelope_model_sha256": "e" * 64,
"coating_article_id": coating_article_id,
"evidence_scope": evidence_scope,
"compartment_id": "BENCH_ELUTION_RECIRCULATION",
"envelope_qualification_method": "DENSE_PILOT_TIMECOURSE_BOUND",
"pilot_sampling_max_gap_h": 1.0,
"burst_phase_covered": True,
"washout_phase_covered": True,
"source_study_ids": ["PK-BENCH-ELUTION-001", "PK-BENCH-WASHOUT-001"],
}),
"timepoint_replicate_records": [
_tp(2.0, 110.0, 0.022, 0.018, 0.032, 0.012),
_tp(72.0, 90.0, 0.020, 0.016, 0.026, 0.010),
_tp(144.0, 76.0, 0.018, 0.015, 0.022, 0.010),
_tp(240.0, 63.0, 0.016, 0.014, 0.018, 0.009),
_tp(336.0, 26.8, 0.014, 0.012, 0.014, 0.008),
_tp(432.0, 10.4, 0.012, 0.011, 0.010, 0.008),
_tp(504.0, 3.3, 0.010, 0.010, 0.009, 0.008),
],
}
def _mk_r8_b4_replicates(
hours: Sequence[float],
lp_free: Sequence[float],
lb_free: Sequence[float],
sp_tot: Sequence[float],
sb_tot: Sequence[float],
) -> dict[str, Any]:
fp_r = [0.138, 0.139, 0.140, 0.140, 0.141, 0.142]
fb_r = [0.148, 0.149, 0.150, 0.150, 0.151, 0.152]
m_fp = sum(fp_r) / len(fp_r)
m_fb = sum(fb_r) / len(fb_r)
tps: list[dict[str, Any]] = []
for h, lpf, lbf, spt, sbt in zip(hours, lp_free, lb_free, sp_tot, sb_tot):
base_lp = lpf / m_fp
base_lb = lbf / m_fb
lp_reps = [round(base_lp * (1.0 + d), 4) for d in (-0.012, -0.007, -0.002, 0.002, 0.007, 0.012)]
lb_reps = [round(base_lb * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
sp_reps = [round(spt * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
sb_reps = [round(sbt * (1.0 + d), 5) for d in (-0.02, -0.01, 0.0, 0.0, 0.01, 0.02)]
tps.append({
"hour_h": float(h),
"animal_ids": [f"NSG-PK-{j+1:02d}" for j in range(len(lp_reps))],
"analyte_pairing_mode": "PAIRED_WITHIN_SAME_ANIMAL_SAMPLE",
"local_parent_total_replicates_nM": lp_reps,
"local_parent_blq_flags": [v < 0.05 for v in lp_reps],
"local_bmt_total_replicates_nM": lb_reps,
"local_bmt_blq_flags": [v < 0.05 for v in lb_reps],
"systemic_parent_total_replicates_nM": sp_reps,
"systemic_parent_blq_flags": [v < 0.05 for v in sp_reps],
"systemic_bmt_total_replicates_nM": sb_reps,
"systemic_bmt_blq_flags": [v < 0.05 for v in sb_reps],
})
loc_cal_b = {
"compartment_matrix_id": "PERI_GRAFT_INTERSTITIAL_FLUID",
"concentration_basis": "RECOVERY_CORRECTED_TOTAL_MATRIX_CONVERTED_BY_LOCAL_FU",
"pre_submission_recovery_correction_applied": True,
"species_id": "NSG_MOUSE",
"analytical_method_id": "LCMSMS-DEUC-ISF-V1",
"lloq_parent_nM": 0.05,
"lloq_bmt_nM": 0.05,
"probe_or_extraction_recovery_pct": 88.5,
"spike_accuracy_pct": 97.0,
"method_validated": True,
"fu_parent_replicates": fp_r,
"fu_bmt_replicates": fb_r,
}
sys_cal_b = {
"compartment_matrix_id": "SYSTEMIC_PLASMA",
"species_id": "NSG_MOUSE",
"analytical_method_id": "LCMSMS-DEUC-PLASMA-V1",
"lloq_parent_nM": 0.05,
"lloq_bmt_nM": 0.05,
"spike_accuracy_pct": 98.5,
"method_validated": True,
"fu_parent_replicates": [0.135, 0.138, 0.140, 0.141, 0.143, 0.145],
"fu_bmt_replicates": [0.145, 0.148, 0.150, 0.151, 0.153, 0.155],
}
env_b4 = {
"k_elim_local_max_per_h": 0.018,
"k_rise_local_max_per_h": 0.003,
"k_elim_parent_max_per_h": 0.012,
"k_rise_parent_max_per_h": 0.002,
"k_elim_bmt_max_per_h": 0.018,
"k_rise_bmt_max_per_h": 0.003,
"k_elim_sys_max_per_h": 0.0693,
"k_rise_sys_max_per_h": 0.003,
"efficacy_window_start_h": 0.0,
"envelope_model_sha256": "f" * 64,
"coating_article_id": "ART-DEUC-R3P-01",
"evidence_scope": "exact_product",
"compartment_id": "INVIVO_PERIGRAFT_AND_SYSTEMIC",
"envelope_qualification_method": "DENSE_PILOT_TIMECOURSE_BOUND",
"pilot_sampling_max_gap_h": 1.0,
"burst_phase_covered": True,
"washout_phase_covered": True,
"source_study_ids": ["PK-INVIVO-NSG-001", "PK-INVIVO-WASHOUT-001"],
}
return {
"b4_local_compartment_calibration": {**loc_cal_b, "calibration_sha256": sha256_bytes(canonical_json_bytes(loc_cal_b))},
"b4_systemic_compartment_calibration": {**sys_cal_b, "calibration_sha256": sha256_bytes(canonical_json_bytes(sys_cal_b))},
"intersample_pk_envelope": {**env_b4, "envelope_receipt_sha256": sha256_bytes(canonical_json_bytes(env_b4))},
"timepoint_replicate_records": tps,
}
def _mk_r8_c1_block(
*,
assay_record_id: str,
bids: list[str],
c9_vec: list[float],
ctrl_vec: list[float],
tr_vec: list[float],
veh_vec: list[float],
comp_vec: list[float],
target: str = "PMAIP1+BCL2L11",
stat_method: str = "PAIRED_T_TEST_NORMALITY_VERIFIED",
target_kd: float = 82.0,
nonbeta_surv: float = 95.0,
ctrl_nonbeta: float = 72.0,
jak2_shield_pct: Optional[float] = None,
assay_acquired_at_utc: str = "2026-09-19T12:00:00Z",
batch_prefix: str = "C1-NBAT",
product_id: str = "ISLET1_DESIGN_Y_V3",
specimen_lot_id: str = "LOT-Y-001",
intervention_cohort_id: str = "COHORT-GY032-Y-001",
) -> dict[str, Any]:
n = len(bids)
c9_ctrl_raw = [round(100.0 + 2.0 * (i % 4), 4) for i in range(n)]
c9_tr_raw = [round(c9_ctrl_raw[i] * (1.0 - c9_vec[i] / 100.0), 4) for i in range(n)]
c9_red_exact = [round(100.0 * (c9_ctrl_raw[i] - c9_tr_raw[i]) / c9_ctrl_raw[i], 4) for i in range(n)]
def _pct_to_counts(pvec: Sequence[float], plated: int = 10000) -> tuple[list[int], list[int]]:
return [plated for _ in pvec], [int(round(plated * float(x) / 100.0)) for x in pvec]
ctrl_p0_b, ctrl_sv_b = _pct_to_counts(ctrl_vec)
tr_p0_b, tr_sv_b = _pct_to_counts(tr_vec)
veh_p0_b, veh_sv_b = _pct_to_counts(veh_vec)
five_arms: dict[str, dict[str, Any]] = {}
for idx, gname in enumerate(sorted(C1_FAMILY_GENES)):
if gname == target:
five_arms[gname] = {
"treated_beta_plated_t0_by_block": list(tr_p0_b),
"treated_beta_surviving_by_block": list(tr_sv_b),
"treated_beta_t0_pct_by_block": list(tr_vec),
"casp9_treated_raw_by_block": list(c9_tr_raw),
"casp9_reduction_pct_by_block": list(c9_red_exact),
}
elif gname == "BCL2L11" and target == "PMAIP1+BCL2L11":
q_prof = [_std_normal_inv_cdf((i + 1.0 - 0.375) / (n + 0.25)) for i in range(n)]
red_b = [round(24.0 + 5.2 * q_prof[i], 3) for i in range(n)]
raw_b = [round(c9_ctrl_raw[i] * (1.0 - red_b[i] / 100.0), 4) for i in range(n)]
cp0, csv = _pct_to_counts(comp_vec)
five_arms[gname] = {
"treated_beta_plated_t0_by_block": cp0,
"treated_beta_surviving_by_block": csv,
"treated_beta_t0_pct_by_block": list(comp_vec),
"casp9_treated_raw_by_block": raw_b,
"casp9_reduction_pct_by_block": [round(100.0 * (c9_ctrl_raw[i] - raw_b[i]) / c9_ctrl_raw[i], 4) for i in range(n)],
}
else:
shift = 1.5 + 0.5 * idx
q_prof = [_std_normal_inv_cdf((i + 1.0 - 0.375) / (n + 0.25)) for i in range(n)]
red_o = [round(10.0 + 2.5 * idx + 9.0 * q_prof[(i + idx) % n], 3) for i in range(n)]
raw_o = [round(c9_ctrl_raw[i] * (1.0 - red_o[i] / 100.0), 4) for i in range(n)]
ab_o = [min(100.0, max(0.0, round(ctrl_vec[i] + shift + 2.6 * q_prof[(i + idx) % n], 3))) for i in range(n)]
op0, osv = _pct_to_counts(ab_o)
five_arms[gname] = {
"treated_beta_plated_t0_by_block": op0,
"treated_beta_surviving_by_block": osv,
"treated_beta_t0_pct_by_block": ab_o,
"casp9_treated_raw_by_block": raw_o,
"casp9_reduction_pct_by_block": [round(100.0 * (c9_ctrl_raw[i] - raw_o[i]) / c9_ctrl_raw[i], 4) for i in range(n)],
}
fam_b: dict[str, float] = {}
fam_c: dict[str, float] = {}