scripts/wetlab_contract.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/wetlab_contract.py · SHA-256: 6bb3955530f8f05d…
and (validated_stage0['obs_residual_psc_effective_fraction'] > 1e-8 or residual_psc_upper95 > 1e-8)
)
chr20q11_se = (
validated_stage0_se.get('obs_20q11_bcl2l1_cnv_se', 0.0)
if 'obs_20q11_bcl2l1_cnv_ratio' in validated_stage0
else 0.0
)
chr20q11_lower95 = validated_stage0.get('obs_20q11_bcl2l1_cnv_ratio', 2.0) - 1.644854 * chr20q11_se
chr20q11_upper95 = validated_stage0.get('obs_20q11_bcl2l1_cnv_ratio', 2.0) + 1.644854 * chr20q11_se
chr20q11_bulk_cnv_failed = bool(
'obs_20q11_bcl2l1_cnv_ratio' in validated_stage0
and (
validated_stage0['obs_20q11_bcl2l1_cnv_ratio'] < 1.85
or validated_stage0['obs_20q11_bcl2l1_cnv_ratio'] > 2.15
or chr20q11_lower95 < 1.85
or chr20q11_upper95 > 2.15
)
)
chr20q11_mosaic_upper95 = _prop_or_pct_u95(
'obs_20q11_bcl2l1_single_cell_mosaic_fraction',
'obs_20q11_bcl2l1_single_cell_mosaic_cells_scored',
is_pct=False,
)
chr20q11_single_cell_mosaic_failed = bool(
'obs_20q11_bcl2l1_single_cell_mosaic_fraction' in validated_stage0
and (
validated_stage0['obs_20q11_bcl2l1_single_cell_mosaic_fraction'] > 0.01
or chr20q11_mosaic_upper95 > 0.01
)
)
chr20q11_bcl2l1_cnv_failed = bool(chr20q11_bulk_cnv_failed or chr20q11_single_cell_mosaic_failed)
hazard_prolif_trials_supplied = 'obs_hazard_state_prolif_effective_trials' in validated_stage0
hazard_prolif_trials = validated_stage0.get('obs_hazard_state_prolif_effective_trials', 0.0)
hazard_prolif_trials_underpowered = bool(
(hazard_prolif_trials_supplied and hazard_prolif_trials < 299573228.0)
or (
'obs_hazard_state_prolif_survivor_count_k' in validated_stage0
and validated_stage0['obs_hazard_state_prolif_survivor_count_k'] == 0.0
and not hazard_prolif_trials_supplied
)
)
hazard_state_prolif_survivor_detected = bool(
('obs_hazard_state_prolif_survivor_count_k' in validated_stage0 and validated_stage0['obs_hazard_state_prolif_survivor_count_k'] > 0.0)
or (
'obs_hazard_state_prolif_survivor_count_k' in validated_stage0
and hazard_prolif_trials_supplied
and hazard_prolif_trials > 0.0
and _poisson_exact_upper95_rate(validated_stage0['obs_hazard_state_prolif_survivor_count_k'], hazard_prolif_trials) > 1e-8
and not hazard_prolif_trials_underpowered
)
)
ap1903_pulsed_pk_se = (
validated_stage0_se.get('obs_ap1903_pulsed_pk_log10_kill_se', 0.0)
if 'obs_ap1903_pulsed_pk_log10_kill' in validated_stage0
else 0.0
)
ap1903_pulsed_pk_lower95 = validated_stage0.get('obs_ap1903_pulsed_pk_log10_kill', 4.5) - 1.644854 * ap1903_pulsed_pk_se
ap1903_mono_pk_se = (
validated_stage0_se.get('obs_ap1903_monotherapy_pulsed_pk_log10_kill_se', 0.0)
if 'obs_ap1903_monotherapy_pulsed_pk_log10_kill' in validated_stage0
else 0.0
)
ap1903_mono_pk_lower95 = validated_stage0.get('obs_ap1903_monotherapy_pulsed_pk_log10_kill', 4.5) - 1.644854 * ap1903_mono_pk_se
ap1903_generic_pk_failed = bool(
(
'obs_ap1903_pulsed_pk_log10_kill' in validated_stage0
and (validated_stage0['obs_ap1903_pulsed_pk_log10_kill'] < 4.0 or ap1903_pulsed_pk_lower95 < 4.0)
)
or observations.get('obs_ap1903_pulsed_pk_washout_regimen_verified') is False
)
ap1903_mono_pk_failed = bool(
'obs_ap1903_monotherapy_pulsed_pk_log10_kill' in validated_stage0
and (validated_stage0['obs_ap1903_monotherapy_pulsed_pk_log10_kill'] < 4.0 or ap1903_mono_pk_lower95 < 4.0)
)
ap1903_pulsed_pk_kill_failed = bool(ap1903_generic_pk_failed or ap1903_mono_pk_failed)
ap1903_step1_trials_supplied = 'obs_ap1903_step1_effective_trials' in validated_stage0
ap1903_step1_trials = validated_stage0.get('obs_ap1903_step1_effective_trials', 0.0)
ap1903_step1_trials_underpowered = bool(
(ap1903_step1_trials_supplied and ap1903_step1_trials < 29957322.8)
or (
'obs_ap1903_step1_sublethal_survivor_count_k' in validated_stage0
and validated_stage0['obs_ap1903_step1_sublethal_survivor_count_k'] == 0.0
and not ap1903_step1_trials_supplied
)
)
ap1903_step1_sublethal_survivor_detected = bool(
('obs_ap1903_step1_sublethal_survivor_count_k' in validated_stage0 and validated_stage0['obs_ap1903_step1_sublethal_survivor_count_k'] > 0.0)
or (
'obs_ap1903_step1_sublethal_survivor_count_k' in validated_stage0
and ap1903_step1_trials_supplied
and ap1903_step1_trials > 0.0
and _poisson_exact_upper95_rate(validated_stage0['obs_ap1903_step1_sublethal_survivor_count_k'], ap1903_step1_trials) > 1e-7
and not ap1903_step1_trials_underpowered
)
)
vascularized_explant_recovery_failed_s9 = bool(
observations.get('obs_vascularized_explant_en_bloc_recovery_verified') is False
)
explant_retrieval_failed = bool(
('obs_explant_en_bloc_recovery_fraction' in validated_stage0 and _lower95_student_t('obs_explant_en_bloc_recovery_fraction') < 0.99)
or ('obs_gate0s_day30_en_bloc_recovery_fraction' in validated_stage0 and _lower95_student_t('obs_gate0s_day30_en_bloc_recovery_fraction') < 0.99)
or ('obs_gate0s_day90_en_bloc_recovery_fraction' in validated_stage0 and _lower95_student_t('obs_gate0s_day90_en_bloc_recovery_fraction') < 0.99)
or vascularized_explant_recovery_failed_s9
)
post_stress_20q11_outgrowth_failed = bool(
'obs_post_stress_20q11_bcl2l1_outgrowth_fold' in validated_stage0
and (
validated_stage0['obs_post_stress_20q11_bcl2l1_outgrowth_fold'] > 1.0
or _upper95('obs_post_stress_20q11_bcl2l1_outgrowth_fold') > 1.20
)
)
nutlin3a_p53_functional_failed = bool(
(
'obs_nutlin3a_p21_mdm2_fold_induction' in validated_stage0
and (
validated_stage0['obs_nutlin3a_p21_mdm2_fold_induction'] < 5.0
or _lower95('obs_nutlin3a_p21_mdm2_fold_induction') < 5.0
)
)
or (
'obs_nutlin3a_p21_cdkn1a_fold_induction' in validated_stage0
and (
validated_stage0['obs_nutlin3a_p21_cdkn1a_fold_induction'] < 5.0
or _lower95('obs_nutlin3a_p21_cdkn1a_fold_induction') < 5.0
)
)
)
s9_causal_failed_categories: list[str] = []
if (
(has_icasp9_obs and (validated_stage0['obs_icasp9_log10_kill'] < 4.0 or icasp9_lower95 < 4.0))
or (has_vaf_obs and (validated_stage0['obs_tp53_ppm1d_bcor_vaf'] >= 1e-4 or vaf_upper95 >= 1e-4))
or (has_cast_obs and (validated_stage0['obs_castseq_translocation_freq'] >= 1e-4 or cast_upper95 >= 1e-4))
):
s9_causal_failed_categories.append('CORE_S9_VAF_OR_CASTSEQ')
if (has_chop_obs and (chop_fold >= 2.0 or chop_upper95 >= 2.0)) or (has_hc10_obs and (hc10_fold > 2.0 or hc10_upper95 > 2.0)):
s9_causal_failed_categories.append('ER_CHOP_HC10')
if mcb_clonogenic_survivor_detected:
s9_causal_failed_categories.append('MCB_CLONOGENIC')
if residual_psc_failed:
s9_causal_failed_categories.append('RESIDUAL_PSC')
if chr20q11_bulk_cnv_failed:
s9_causal_failed_categories.append('CNV_20Q11')
if chr20q11_single_cell_mosaic_failed:
s9_causal_failed_categories.append('SINGLE_CELL_MOSAIC_20Q11')
if post_stress_20q11_outgrowth_failed:
s9_causal_failed_categories.append('POST_STRESS_20Q11_OUTGROWTH')
if nutlin3a_p53_functional_failed:
s9_causal_failed_categories.append('FUNCTIONAL_P53_NUTLIN3A')
if hazard_state_prolif_survivor_detected:
s9_causal_failed_categories.append('HAZARD_PROLIF_SURVIVOR')
if ap1903_generic_pk_failed:
s9_causal_failed_categories.append('PULSED_PK_KILL')
# Bank & Stage-7 lot 1q32.1 MDM4 diploid CN + >= 299-cell mosaicism and observed-zero vetoes on Day-28 Gate 0V & Day-90 Gate 0S dual shedding (IIP-0024; DEC-103):
mcb_mdm4_cnv_failed = bool(
'obs_mcb_1q32_mdm4_cnv_ratio' in validated_stage0
and (
validated_stage0['obs_mcb_1q32_mdm4_cnv_ratio'] < 1.85
or validated_stage0['obs_mcb_1q32_mdm4_cnv_ratio'] > 2.15
or _lower95('obs_mcb_1q32_mdm4_cnv_ratio') < 1.85
or _upper95('obs_mcb_1q32_mdm4_cnv_ratio') > 2.15
)
)
lot_mdm4_cnv_failed = bool(
'obs_1q32_mdm4_cnv_ratio' in validated_stage0
and (
validated_stage0['obs_1q32_mdm4_cnv_ratio'] < 1.85
or validated_stage0['obs_1q32_mdm4_cnv_ratio'] > 2.15
or _lower95('obs_1q32_mdm4_cnv_ratio') < 1.85
or _upper95('obs_1q32_mdm4_cnv_ratio') > 2.15
)
)
mcb_mdm4_mosaic_u95 = _prop_or_pct_u95(
'obs_mcb_1q32_mdm4_single_cell_mosaic_fraction',
'obs_mcb_1q32_mdm4_single_cell_mosaic_cells_scored',
is_pct=False,
)
lot_mdm4_mosaic_u95 = _prop_or_pct_u95(
'obs_1q32_mdm4_single_cell_mosaic_fraction',
'obs_1q32_mdm4_single_cell_mosaic_cells_scored',
is_pct=False,
)
mdm4_mosaic_failed = bool(
('obs_mcb_1q32_mdm4_single_cell_mosaic_fraction' in validated_stage0 and (validated_stage0['obs_mcb_1q32_mdm4_single_cell_mosaic_fraction'] > 0.01 or mcb_mdm4_mosaic_u95 > 0.01))
or ('obs_1q32_mdm4_single_cell_mosaic_fraction' in validated_stage0 and (validated_stage0['obs_1q32_mdm4_single_cell_mosaic_fraction'] > 0.01 or lot_mdm4_mosaic_u95 > 0.01))
)
gate0v_day28_observed_positive_veto = bool(
'obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct' in validated_stage0
and validated_stage0['obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct'] > 0.0
)
gate0s_shedding_observed_positive_veto = bool(
('obs_gate0s_shedding_ddpcr_events_k' in validated_stage0 and validated_stage0['obs_gate0s_shedding_ddpcr_events_k'] > 0.0)
or ('obs_gate0s_shedding_viable_events_k' in validated_stage0 and validated_stage0['obs_gate0s_shedding_viable_events_k'] > 0.0)
)
p05_z70_interface_h2o2_hard_stop_veto = bool(
'obs_p05_z70_gel_interface_h2o2_max_uM' in validated_stage0
and (
validated_stage0['obs_p05_z70_gel_interface_h2o2_max_uM'] > 5.0
or _upper95_student_t('obs_p05_z70_gel_interface_h2o2_max_uM') > 5.0
)
)
if ap1903_mono_pk_failed:
s9_causal_failed_categories.append('MONOTHERAPY_PULSED_PK_KILL')
if ap1903_step1_sublethal_survivor_detected:
s9_causal_failed_categories.append('STEP1_SUBLETHAL_SURVIVOR')
if explant_retrieval_failed:
s9_causal_failed_categories.append('EXPLANT_RECOVERY')
if mcb_mdm4_cnv_failed or lot_mdm4_cnv_failed:
s9_causal_failed_categories.append('CNV_1Q32_MDM4')
if mdm4_mosaic_failed:
s9_causal_failed_categories.append('SINGLE_CELL_MOSAIC_1Q32_MDM4')
if gate0v_day28_observed_positive_veto:
s9_causal_failed_categories.append('GATE0V_PERSISTENT_VIRAL_POSITIVE')
if gate0s_shedding_observed_positive_veto:
s9_causal_failed_categories.append('GATE0S_DUAL_SHEDDING_POSITIVE')
if p05_z70_interface_h2o2_hard_stop_veto:
s9_causal_failed_categories.append('P05_Z70_INTERFACE_H2O2_GT_5UM')
current_batch_s9_endpoint_failed = bool(s9_causal_failed_categories)
safety_kill_s9_triggered = bool(
sticky_prior_s9_stop
or current_batch_s9_endpoint_failed
)
nkg2a_explicit_se = _explicit_se('obs_nkg2a_lysis_pct')
kir_explicit_se = _explicit_se('obs_kir_nkg2a_neg_nk_lysis_pct')
nkg2c_explicit_se = _explicit_se('obs_nkg2c_adaptive_nk_lysis_pct')
il12_il18_explicit_se = _explicit_se('obs_il12_il18_sirpa_low_nk_lysis_pct')
phago_explicit_se = _explicit_se('obs_phagocytosis_index_pct')
receptor_neg_nkg2c_explicit_se = _explicit_se('obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct')
c3b_phago_explicit_se = _explicit_se('obs_complement_c3b_opsonized_phagocytosis_pct')
nkg2a_lysis_upper95 = _upper95('obs_nkg2a_lysis_pct', 2.0)
kir_nkg2a_neg_upper95 = _upper95('obs_kir_nkg2a_neg_nk_lysis_pct', 2.0)
nkg2c_adaptive_upper95 = _upper95('obs_nkg2c_adaptive_nk_lysis_pct', 2.0)
il12_il18_sirpa_low_upper95 = _upper95('obs_il12_il18_sirpa_low_nk_lysis_pct', 2.0)
phagocytosis_upper95 = _upper95('obs_phagocytosis_index_pct', 3.0)
receptor_neg_nkg2c_upper95 = _upper95('obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct', 2.0)
c3b_phagocytosis_upper95 = _upper95('obs_complement_c3b_opsonized_phagocytosis_pct', 3.0)
# Enforce explicit SE caps (<= 3.0% for NK lysis panels, <= 2.5% for macrophage phagocytosis) AND compare one-sided 95% UCBs directly against the biological release gates (8.0% lysis, 10.0% IL-12/IL-18 lysis, 5.0% Playbook phagocytosis; MW-R5-S2-F01 & AUDIT-REF; DEC-048/049):
immune_se_cap_exceeded = bool(
nkg2a_explicit_se > 3.0
or kir_explicit_se > 3.0
or nkg2c_explicit_se > 3.0
or il12_il18_explicit_se > 3.0
or receptor_neg_nkg2c_explicit_se > 3.0
or phago_explicit_se > 2.5
or c3b_phago_explicit_se > 2.5
)
excessive_immune_donor_variance_or_upper95_failed = bool(
immune_se_cap_exceeded