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…
iip0025_hold_status: str | None = None
if _is_design_z_product and (
observations.get('p05_two_timepoint_same_lot_envelope_verified') is not None
or any(_k in validated_stage0 for _k in _iip0025_p05_new_keys)
):
iip0025_hold_status = 'HOLD_BIDIRECTIONAL_PRODUCT_PHYSICAL_ROUTE_MISMATCH'
if _iip0025_p05_env_active and iip0025_hold_status is None:
_p05_25_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0025_p05_all_req_keys
)
if _p05_cat_acc != 'P04040' or observations.get('p05_recombinant_human_catalase_verified') is not True:
iip0025_p05_env_status = 'HOLD_P05_XENO_OR_UNVERIFIED_CATALASE_SPECIES_REQUIRES_HUMAN_P04040'
elif stage0_replicates_below_6_hold:
iip0025_p05_env_status = 'HOLD_STAGE0_INDEPENDENT_LOT_REPLICATES_BELOW_6_STUDENT_T_MINIMUM'
elif p05_z70_interface_h2o2_hard_stop_veto:
iip0025_p05_env_status = 'HOLD_P05_Z70_GEL_INTERFACE_H2O2_EXCEEDS_5P0UM_HARD_STOP'
elif 'obs_p05_z70_gel_interface_h2o2_max_uM' in validated_stage0 and _upper95_student_t('obs_p05_z70_gel_interface_h2o2_max_uM') > 2.5:
iip0025_p05_env_status = 'HOLD_P05_Z70_GEL_INTERFACE_H2O2_EXCEEDS_2P5UM_TIER1_TARGET'
elif observations.get('p05_two_timepoint_same_lot_envelope_verified') is not True or not _p05_25_quant_ok:
iip0025_p05_env_status = 'HOLD_P05_TWO_TIMEPOINT_ENVELOPE_INCOMPLETE_OR_DEFAULT_SE'
else:
_u_pre = validated_stage0['obs_p05_precure_active_catalase_input_u_333cm2']
_u_post0 = validated_stage0['obs_p05_postcure_t0_active_catalase_iu_333cm2']
_y_cure = validated_stage0['obs_p05_cure_immobilization_yield_pct']
_r_d7 = validated_stage0['obs_p05_day7_catalase_retention_pct']
_s_d7 = validated_stage0['obs_p05_day7_shed_catalase_mass_pct']
_r_336 = validated_stage0['obs_p05_336h_catalase_retention_pct']
_u_336 = validated_stage0['obs_p05_336h_retained_catalase_iu_333cm2']
_m_cat_25 = validated_stage0['obs_p05_total_loaded_catalase_protein_mg']
if _u_pre > 158300.0 or _upper95_student_t('obs_p05_precure_active_catalase_input_u_333cm2') > 158300.0:
iip0025_p05_env_status = 'HOLD_P05_PRECURE_CATALASE_INPUT_EXCEEDS_158300U_CAP'
elif (
_u_pre <= 0.0
or _u_post0 <= 0.0
or _m_cat_25 <= 0.0
or abs(_u_post0 - _u_pre * (_y_cure / 100.0)) > max(150.0, 0.02 * _u_post0)
or abs(_u_336 - _u_post0 * (_r_336 / 100.0)) > max(150.0, 0.02 * max(1.0, _u_336))
or _r_336 > _r_d7 + 1e-6
or (_r_d7 + _s_d7) > 102.0
):
iip0025_p05_env_status = 'HOLD_P05_TWO_TIMEPOINT_ALGEBRAIC_YIELD_OR_RETENTION_INCONSISTENT'
elif (
_lower95_student_t('obs_p05_day7_catalase_retention_pct') < 70.0
or _upper95_student_t('obs_p05_day7_shed_catalase_mass_pct') > 30.0
or _lower95_student_t('obs_p05_336h_retained_catalase_iu_333cm2') < 73800.0
):
iip0025_p05_env_status = 'HOLD_P05_TWO_TIMEPOINT_DAY7_70PCT_OR_336H_73800IU_FAILED'
else:
_unrounded_eu_cap = min(0.10, 0.50 / _m_cat_25)
_exp_tot_eu_25 = _m_cat_25 * validated_stage0['obs_p05_catalase_endotoxin_eu_per_mg']
if _upper95_student_t('obs_p05_catalase_endotoxin_eu_per_mg') > _unrounded_eu_cap:
iip0025_p05_env_status = 'HOLD_P05_MASS_COUPLED_CATALASE_ENDOTOXIN_CAP_EXCEEDED'
elif _upper95_student_t('obs_p05_total_implant_catalase_endotoxin_eu') > 0.50:
iip0025_p05_env_status = 'HOLD_P05_TOTAL_IMPLANT_CATALASE_ENDOTOXIN_GT_0P50EU'
elif abs(validated_stage0['obs_p05_total_implant_catalase_endotoxin_eu'] - _exp_tot_eu_25) > max(0.015, 0.05 * _exp_tot_eu_25):
iip0025_p05_env_status = 'HOLD_P05_COUPLED_TOTAL_ENDOTOXIN_MASS_PRODUCT_INCONSISTENT'
else:
iip0025_p05_env_status = 'CLEARED_P05_TWO_TIMEPOINT_P04040_ENVELOPE_AND_Z70_H2O2_GATE'
if iip0025_p05_env_status != 'CLEARED_P05_TWO_TIMEPOINT_P04040_ENVELOPE_AND_Z70_H2O2_GATE':
iip0025_hold_status = iip0025_p05_env_status
if _iip0025_b1_active:
_b1_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0025_b1_keys
)
if _b1_arm not in ALLOWED_CONTRAST_B1_GEOMETRY_ARMS or not _b1_quant_ok:
iip0025_b1_status = 'HOLD_CONTRAST_B1_INCOMPLETE_OR_DEFAULT_SE_PANEL'
elif observations.get('s6_dose_matched_1500_ieq_verified') is not True:
iip0025_b1_status = 'HOLD_CONTRAST_B1_REQUIRES_DOSE_MATCHED_1500IEQ_PITCH'
elif (
_lower95_student_t('obs_contrast_b1_80um_worst_face_po2_mmhg') < 15.0
or _lower95_student_t('obs_contrast_b1_paired_min_face_po2_gain_mmhg') <= 0.0
or _lower95_student_t('obs_contrast_b1_80um_perifusion_gsis_si') < 3.0
):
iip0025_b1_status = 'HOLD_CONTRAST_B1_DOSE_MATCHED_80UM_MIN_FACE_OR_GSIS_FAILED'
else:
iip0025_b1_status = 'CLEARED_CONTRAST_B1_DOSE_MATCHED_80UM_VS_100UM_CHALLENGER'
if iip0025_b1_status != 'CLEARED_CONTRAST_B1_DOSE_MATCHED_80UM_VS_100UM_CHALLENGER' and iip0025_hold_status is None:
iip0025_hold_status = iip0025_b1_status
if _iip0025_b2_active:
_b2_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0025_b2_keys
)
if _b2_arm != 'PAIRED_HUMAN_EXVIVO_AND_PORCINE_DAY30_90':
iip0025_b2_status = 'HOLD_CONTRAST_B2_INCOMPLETE_EXVIVO_PERFUSION_OR_PORCINE_RETRIEVAL_ARM'
elif observations.get('contrast_b2_route_qualification_distinct_from_portfolio_credit_verified') is not True:
iip0025_b2_status = 'HOLD_CONTRAST_B2_ROUTE_QUALIFICATION_CONFLATED_WITH_PORTFOLIO_CREDIT'
elif not _b2_quant_ok:
iip0025_b2_status = 'HOLD_CONTRAST_B2_INCOMPLETE_OR_DEFAULT_SE_PANEL'
elif (
_lower95_student_t('obs_contrast_b2_human_exvivo_viable_window_h') < 24.0
or _lower95_student_t('obs_contrast_b2_omental_vs_suprafascial_po2_gain_mmhg') <= 0.0
or _lower95_student_t('obs_contrast_b2_porcine_day90_en_bloc_recovery_fraction') < 0.99
):
iip0025_b2_status = 'HOLD_CONTRAST_B2_PERFUSION_WINDOW_PO2_GAIN_OR_PORCINE_RETRIEVAL_FAILED'
else:
iip0025_b2_status = 'CLEARED_CONTRAST_B2_OMENTAL_VS_SUPRAFASCIAL_ZERO_PRIMATE_ROUTE_GATE'
if iip0025_b2_status != 'CLEARED_CONTRAST_B2_OMENTAL_VS_SUPRAFASCIAL_ZERO_PRIMATE_ROUTE_GATE' and iip0025_hold_status is None:
iip0025_hold_status = iip0025_b2_status
if _iip0025_b3_active:
if _b3_arm not in ALLOWED_CONTRAST_B3_DONOR_IEC_ARMS:
iip0025_b3_status = 'HOLD_CONTRAST_B3_MISSING_OR_INVALID_DONOR_IEC_ARM'
elif observations.get('contrast_b3_zero_primate_host_ingrowth_verified') is not True:
iip0025_b3_status = 'HOLD_CONTRAST_B3_HOST_VESSEL_INGROWTH_UNVERIFIED'
elif _b3_arm == 'OMIT_DONOR_IEC_8E8_CHALLENGER':
_b3_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0025_b3_keys
)
if not _b3_quant_ok:
iip0025_b3_status = 'HOLD_CONTRAST_B3_INCOMPLETE_OR_DEFAULT_SE_PANEL'
elif (
_lower95_student_t('obs_contrast_b3_iec_omitted_surface_po2_mmhg') < 15.0
or _lower95_student_t('obs_contrast_b3_iec_omitted_outer_kperf_s_inv') < 0.10
or _lower95_student_t('obs_contrast_b3_iec_omitted_perifusion_gsis_si') < 3.0
):
iip0025_b3_status = 'HOLD_CONTRAST_B3_DONOR_IEC_OMITTED_INGROWTH_PO2_OR_GSIS_FAILED'
else:
iip0025_b3_status = 'CLEARED_CONTRAST_B3_OMIT_DONOR_IEC_8E8_CHALLENGER'
else:
iip0025_b3_status = 'CLEARED_CONTRAST_B3_BASELINE_WITH_DONOR_IEC_9E8_REFERENCE'
if not str(iip0025_b3_status).startswith('CLEARED_') and iip0025_hold_status is None:
iip0025_hold_status = iip0025_b3_status
iip0025_eval_summary: dict[str, object] | None = None
if _iip0025_p05_env_active or _iip0025_b1_active or _iip0025_b2_active or _iip0025_b3_active or _iip0025_day30_90_active:
iip0025_eval_summary = {
'gate_pass': iip0025_hold_status is None and not explant_retrieval_failed,
'hold_status': iip0025_hold_status,
'status': (
iip0025_hold_status
if iip0025_hold_status is not None
else (
'HOLD_S9_EXPLANT_EN_BLOC_RECOVERY_BELOW_99PCT'
if explant_retrieval_failed
else 'CLEARED_IIP0025_HURDLE4_SPATIAL_OXYGEN_CATALASE_AND_CHALLENGERS'
)
),
'p05_two_timepoint_envelope_status': iip0025_p05_env_status,
'contrast_b1_status': iip0025_b1_status,
'contrast_b2_status': iip0025_b2_status,
'contrast_b3_status': iip0025_b3_status,
'student_t_critical_multiplier_used': round(_student_t_mult_df5_default, 8),
}
# Stage-0 molecular provenance, 4-state Design B c1+c5 registry binding, Corrah 2011 DT9/HLA-E control, per-locus segmented BAF, Locus-5 RACE/UMI >=3,689, & TYK2 PE4max MSI/piecewise guardrails (IIP-0026; DEC-105):
_iip0026_obs_keys = (
'obs_design_b_hlac_phased_guide_cfd_max',
'obs_design_b_hlac_dt9_matched_hlae_only_control_delta_ratio',
'obs_post_edit_segmented_baf_chr19q',
'obs_post_edit_segmented_baf_chr11p15',
'obs_post_edit_segmented_baf_chr6p21',
'obs_design_b_locus5_5prime_race_coord_bp',
'obs_design_b_locus5_3prime_race_coord_bp',
'obs_design_b_locus5_race_umi_n_eff',
'obs_design_b_locus5_aberrant_umi_k',
'obs_tyk2_pe4max_pentaplex_msi_shifts_k',
'obs_tyk2_pe4max_wgs_repeat_indels_clone',
'obs_tyk2_pe4max_wgs_repeat_indels_ctrl',
'obs_tyk2_pe4max_coding_or_splice_de_novo_indels',
)
_iip0026_bool_or_meta_keys = (
'require_full_iip0026_molecular_provenance_panel',
'donor_seed_gnomad_target_site_wgs_verified',
'post_edit_reciprocal_mosaic_sv_or_clonal_zygosity_verified',
'design_b_hla_ab_separated_pass_delivery_verified',
'design_b_chr6p21_1p41mb_loh_sv_cleared',
'design_b_hlac_dt9_positive',
'design_b_hlae_3d12_positive',
'design_b_hlac_allele_specific_surface_or_phased_mrna_verified',
'b_sct_ciita_exon5_and_trimer_verified',
'tyk2_phased_haplotype_sap_verified',
'bound_c1_c5_pair_sha256',
'tyk2_pe_modality',
'iip0026_schema_era',
)
_req_iip0026_full = bool(observations.get('require_full_iip0026_molecular_provenance_panel') is True)
_iip0026_active = bool(
_req_iip0026_full
or any(_k in validated_stage0 for _k in _iip0026_obs_keys)
or any(observations.get(_k) is not None for _k in _iip0026_bool_or_meta_keys)
)
_pvid_s0_26 = str(product_def['product_variant_id']) if product_def is not None else ''
_is_endogenous_hlac_b_26 = _pvid_s0_26 in ('ISLET1_B2_5LOCUS_BASE', 'ISLET1_B2_5LOCUS_TYK2_PE', 'ISLET1_B1_6LOCUS_TYK2_KO_INS')
_is_bsct_26 = _pvid_s0_26.startswith('ISLET1_B_SCT_')
_is_tyk2_pe_26 = (_pvid_s0_26 == 'ISLET1_B2_5LOCUS_TYK2_PE') or ('TYK2_PE' in _pvid_s0_26)
iip0026_hold_status: str | None = None
iip0026_hlac_status: str | None = None
if _iip0026_active:
_expected_b2_sha = (
str(product_def.get('staged_design_b_donor_reference_binding', {}).get('bound_c1_c5_pair_sha256', '')).strip()
if isinstance(product_def, dict) and isinstance(product_def.get('staged_design_b_donor_reference_binding'), dict)
else ''
)
if observations.get('iip0026_schema_era') == 'LEGACY_PRE_IIP0026':
iip0026_hold_status = 'HOLD_PROVISIONAL_LEGACY_SCHEMA_MISSING_IIP0026_EVIDENCE'
elif _expected_b2_sha:
_sup_sha = observations.get('bound_c1_c5_pair_sha256')
if _sup_sha is None:
if _req_iip0026_full:
iip0026_hold_status = 'HOLD_MISSING_BOUND_C1_C5_DONOR_PAIR_DIGEST'
elif _sup_sha.strip() != _expected_b2_sha:
iip0026_hold_status = 'HOLD_DONOR_REGISTRY_DIGEST_MISMATCH'
if iip0026_hold_status is None and (
_req_iip0026_full or observations.get('donor_seed_gnomad_target_site_wgs_verified') is False
):
if observations.get('donor_seed_gnomad_target_site_wgs_verified') is not True:
iip0026_hold_status = 'HOLD_MISSING_DONOR_TARGET_WGS'
if iip0026_hold_status is None and (
_req_iip0026_full
or any(_bk in validated_stage0 for _bk in ('obs_post_edit_segmented_baf_chr19q', 'obs_post_edit_segmented_baf_chr11p15', 'obs_post_edit_segmented_baf_chr6p21'))
or observations.get('post_edit_reciprocal_mosaic_sv_or_clonal_zygosity_verified') is not None
):
_req_baf_keys = (
('obs_post_edit_segmented_baf_chr19q', 'obs_post_edit_segmented_baf_chr11p15', 'obs_post_edit_segmented_baf_chr6p21')
if _is_endogenous_hlac_b_26
else ('obs_post_edit_segmented_baf_chr19q', 'obs_post_edit_segmented_baf_chr11p15')
)
if (
any(_bk not in validated_stage0 for _bk in _req_baf_keys)
or observations.get('post_edit_reciprocal_mosaic_sv_or_clonal_zygosity_verified') is not True
):
iip0026_hold_status = 'HOLD_MISSING_SEGMENTED_PHASED_BAF_SURVEILLANCE'
elif max(abs(validated_stage0[_bk] - 0.50) for _bk in _req_baf_keys) > 0.05:
iip0026_hold_status = 'HOLD_DISCORDANT_PER_LOCUS_SEGMENTED_BAF'
if _is_endogenous_hlac_b_26:
_cfd_26 = validated_stage0.get('obs_design_b_hlac_phased_guide_cfd_max')
_dt9_26 = validated_stage0.get('obs_design_b_hlac_dt9_matched_hlae_only_control_delta_ratio')
_orth_26 = observations.get('design_b_hlac_allele_specific_surface_or_phased_mrna_verified')
if (
_cfd_26 is None
or not (0.0 <= _cfd_26 < 0.05)
or observations.get('design_b_hla_ab_separated_pass_delivery_verified') is not True
or observations.get('design_b_chr6p21_1p41mb_loh_sv_cleared') is not True
or observations.get('design_b_hlac_dt9_positive') is not True
or observations.get('design_b_hlae_3d12_positive') is not True
):
iip0026_hlac_status = 'HOLD_MISSING_ENDOGENOUS_DESIGNB_HLAC_PHASED_CLEARANCE'
elif _dt9_26 is None and _orth_26 is not True:
iip0026_hlac_status = 'HOLD_MISSING_HLAC_SPECIFICITY_CONTROL_FOR_DT9_HLAE_CROSSREACTIVITY'
elif _dt9_26 is not None and _dt9_26 <= 0.0 and _orth_26 is not True:
iip0026_hlac_status = 'HOLD_MISSING_HLAC_SPECIFICITY_CONTROL_FOR_DT9_HLAE_CROSSREACTIVITY'
elif _dt9_26 is not None and _dt9_26 < 2.0 and _orth_26 is not True: