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…
'obs_rest_depot_release_half_life_h',
'obs_rest_post_washout_gsis_si',
'obs_rest_post_washout_gsis_output_retention_pct',
'obs_rest_post_washout_alpha_glucagon_fold',
)
_iip0021_cond_keys = (
'obs_cond_sc_beta_viable_yield_pct',
'obs_cond_iec_viable_yield_pct',
'obs_cond_final_wash_supernatant_nM',
'obs_cond_pellet_residual_over_loq_ratio',
'obs_cond_pellet_extraction_recovery_pct',
'obs_cond_endocrine_nqo1_activity_pct',
'obs_cond_vascular_nqo1_activity_pct',
'obs_cond_post_washout_gsis_si',
)
_iip0021_rest_active = bool(
_req_iip0021_full
or _rest_arm is not None
or observations.get('rest_120h_longitudinal_simultaneous_coverage_verified') is not None
or observations.get('rest_120h_viable_lineage_yield_and_during_exposure_function_verified') is not None
or any(_mk in validated_stage0 for _mk in _iip0021_rest_keys)
)
_iip0021_cond_active = bool(
_req_iip0021_full
or _cond_arm is not None
or _cond_scope is not None
or observations.get('conditioning_pellet_loq_and_extraction_recovery_verified') is not None
or observations.get('conditioning_orthogonal_pathway_controls_verified') is not None
or any(_mk in validated_stage0 for _mk in _iip0021_cond_keys)
)
iip0021_rest_status: str | None = None
iip0021_cond_status: str | None = None
iip0021_hold_status: str | None = None
if _iip0021_rest_active:
if _rest_arm == 'VEHICLE_791P5MG_CAO2_BASELINE':
iip0021_rest_status = 'BASELINE_791P5MG_CAO2_RETAINED_NO_METABOLIC_REST_DERATING'
elif _rest_arm == 'UNENCAPSULATED_FREE_DRUG_REJECTED':
iip0021_rest_status = 'HOLD_REST_OCR_UNENCAPSULATED_FREE_DRUG_RAPID_SLAB_WASHOUT_BARRED'
else:
_rest_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0021_rest_keys
)
if _rest_arm != 'ENCAPSULATED_KATP_MICRODEPOT_CHALLENGER' or not _rest_quant_ok:
iip0021_rest_status = 'HOLD_REST_OCR_INCOMPLETE_OR_DEFAULT_SE_120H_COUPON_PANEL'
elif (
observations.get('rest_120h_longitudinal_simultaneous_coverage_verified') is not True
or observations.get('rest_120h_viable_lineage_yield_and_during_exposure_function_verified') is not True
):
iip0021_rest_status = 'HOLD_REST_OCR_MISSING_LONGITUDINAL_COVERAGE_OR_VIABLE_LINEAGE_FUNCTION_CHECK'
elif _lower95('obs_rest_depot_release_half_life_h') < 72.0 or _upper95('obs_rest_120h_graft_ocr_ratio') > 0.80:
iip0021_rest_status = 'HOLD_REST_OCR_120H_RATIO_GT_0P80_OR_DEPOT_HALFLIFE_LT_72H_KEEP_791P5MG_CAO2'
elif (
_lower95('obs_rest_post_washout_gsis_si') < 3.0
or _lower95('obs_rest_post_washout_gsis_output_retention_pct') < 85.0
or _lower95('obs_rest_post_washout_alpha_glucagon_fold') < 2.0
):
iip0021_rest_status = 'HOLD_REST_OCR_POST_WASHOUT_GSIS_ABSOLUTE_OUTPUT_OR_GLUCAGON_FAILED'
else:
iip0021_rest_status = 'CLEARED_REST_120H_OCR_COUPON_ELIGIBLE_FOR_STAGE2_COUPLED_CAO2_QUALIFICATION_ONLY'
if iip0021_rest_status not in (
'BASELINE_791P5MG_CAO2_RETAINED_NO_METABOLIC_REST_DERATING',
'CLEARED_REST_120H_OCR_COUPON_ELIGIBLE_FOR_STAGE2_COUPLED_CAO2_QUALIFICATION_ONLY',
):
iip0021_hold_status = iip0021_rest_status
if _iip0021_cond_active:
if _cond_arm in ('NEC1S_100UM_BENCHMARK_COMPARATOR', 'NEC1_100UM_ANTIFERROPTOTIC_COMPARATOR'):
iip0021_cond_status = 'HOLD_CONDITIONING_BENCHMARK_OR_NEC1_ANTIFERROPTOTIC_COMPARATOR_NOT_RELEASE_ARM'
elif _cond_scope == 'AQUEOUS_SUPERNATANT_ONLY_INSUFFICIENT':
iip0021_cond_status = 'HOLD_CONDITIONING_AQUEOUS_SUPERNATANT_ONLY_REQUIRES_WASHED_CELL_PELLET_LCMS'
else:
_cond_quant_ok = all(
_mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
for _mk in _iip0021_cond_keys
)
if _cond_arm is None or _cond_scope != 'SUPERNATANT_AND_CELL_PELLET_PARENT_PLUS_METABOLITES' or not _cond_quant_ok:
iip0021_cond_status = 'HOLD_CONDITIONING_INCOMPLETE_OR_DEFAULT_SE_4ARM_PELLET_NQO1_PANEL'
elif (
observations.get('conditioning_pellet_loq_and_extraction_recovery_verified') is not True
or observations.get('conditioning_orthogonal_pathway_controls_verified') is not True
or _lower95('obs_cond_pellet_extraction_recovery_pct') < 80.0
):
iip0021_cond_status = 'HOLD_CONDITIONING_PELLET_LOQ_EXTRACTION_RECOVERY_OR_PATHWAY_CONTROLS_UNVERIFIED'
elif (
_upper95('obs_cond_final_wash_supernatant_nM') >= 10.0
or _upper95('obs_cond_pellet_residual_over_loq_ratio') > 1.0
or _lower95('obs_cond_endocrine_nqo1_activity_pct') < 90.0
or _lower95('obs_cond_vascular_nqo1_activity_pct') < 90.0
):
iip0021_cond_status = 'HOLD_CONDITIONING_RESIDUAL_DRUG_OR_NQO1_INHIBITION_DETECTED'
elif (
_lower95('obs_cond_sc_beta_viable_yield_pct') < 85.0
or _lower95('obs_cond_iec_viable_yield_pct') < 85.0
or _lower95('obs_cond_post_washout_gsis_si') < 3.0
):
iip0021_cond_status = 'HOLD_CONDITIONING_LINEAGE_VIABLE_YIELD_OR_POST_WASHOUT_GSIS_SI3_FAILED'
else:
iip0021_cond_status = 'CLEARED_CONDITIONING_4ARM_PELLET_LOQ_NQO1_AND_LINEAGE_GSIS_GATE'
if iip0021_cond_status != 'CLEARED_CONDITIONING_4ARM_PELLET_LOQ_NQO1_AND_LINEAGE_GSIS_GATE' and iip0021_hold_status is None:
iip0021_hold_status = iip0021_cond_status
iip0021_eval_summary: dict[str, object] | None = None
if _iip0021_rest_active or _iip0021_cond_active:
iip0021_eval_summary = {
'gate_pass': iip0021_hold_status is None,
'hold_status': iip0021_hold_status,
'rest_ocr_coupon_arm': _rest_arm,
'rest_120h_ocr_status': iip0021_rest_status,
'conditioning_4arm_arm': _cond_arm,
'conditioning_washout_analyte_scope': _cond_scope,
'conditioning_pellet_nqo1_status': iip0021_cond_status,
}
# Stage-0 Track-2 B'-SCT vs HLA-G1 split, B2M-null PVR/CD226 NK check, and lineage-separated necroptosis guardrail evaluation (IIP-0022; DEC-101):
_req_iip0022_full = observations.get('require_full_iip0022_track2_and_guardrail_panel') is True
_iip0022_active = bool(
_req_iip0022_full
or _t2_route is not None
or _bsct_flag
or _hlag1_flag
or _bsct_quant_present
or _hlag1_quant_present
or 'obs_b2m_null_pvr_cd226_nk_lysis_pct' in validated_stage0
or observations.get('lineage_necroptosis_time_resolved_viability_and_rescue_verified') is not None
)
iip0022_hold_status: str | None = None
iip0022_track2_status: str | None = None
if _iip0022_active:
if _bsct_flag and _hlag1_flag:
iip0022_track2_status = 'HOLD_TRACK2_MUTUALLY_EXCLUSIVE_BSCT_AND_HLAG1_FLAGS_BOTH_SET'
iip0022_hold_status = iip0022_track2_status
elif _legacy_conflated_t2 and (_t2_route is not None or _req_iip0022_full):
iip0022_track2_status = 'HOLD_TRACK2_DEPRECATED_CONFLATED_RESCUE_FLAG_REQUIRES_EXPLICIT_SPLIT_ROUTE'
iip0022_hold_status = iip0022_track2_status
elif track2_hlag1_route_attempted:
if not _hlag1_quant_cleared_uniform_8pct:
iip0022_track2_status = 'HOLD_TRACK2_HLAG1_LILRB1_NEG_KIR_NK_EXCEEDS_8PCT_OR_UNDERPOWERED_DONOR_PANEL'
else:
# Even if sorted LILRB1- NKG2A- KIR+ primary NK clears <= 8.0% across n >= 6 donors, HLA-G1 remains HELD until registered in islet1_product_definitions_v0.8.0.json:
iip0022_track2_status = 'HOLD_TRACK2_HLAG1_CLEARED_UNIFORM_8PCT_COUPON_PENDING_PRODUCT_DEFINITION_REGISTRATION'
iip0022_hold_status = iip0022_track2_status
elif _bsct_flag or _t2_route == 'TRACK2_HLAC_B_SCT_KIR_RESCUE' or _bsct_quant_present:
if not _bsct_quant_cleared:
iip0022_track2_status = 'HOLD_TRACK2_BSCT_KIR_NK_EXCEEDS_8PCT_OR_MISSING_EXPLICIT_6DONOR_PANEL'
iip0022_hold_status = iip0022_track2_status
else:
iip0022_track2_status = 'CLEARED_TRACK2_BSCT_KIR_6DONOR_8PCT_COUPON'
else:
iip0022_track2_status = 'TRACK1_MHC_NULL_ACTIVE_NO_TRACK2_SWITCH'
if iip0022_hold_status is None and ('obs_b2m_null_pvr_cd226_nk_lysis_pct' in validated_stage0 or _req_iip0022_full):
if (
'obs_b2m_null_pvr_cd226_nk_lysis_pct' not in validated_stage0
or se_provenance_by_mean.get('obs_b2m_null_pvr_cd226_nk_lysis_pct') != 'EXPLICIT_SE_SUPPLIED'
or _upper95('obs_b2m_null_pvr_cd226_nk_lysis_pct') > 8.0
):
iip0022_hold_status = 'HOLD_B2M_NULL_TIGIT_LOW_CD226_HIGH_NK_LYSIS_EXCEEDS_8PCT_OR_MISSING_EXPLICIT_SE'
if iip0022_hold_status is None and (observations.get('lineage_necroptosis_time_resolved_viability_and_rescue_verified') is False or (_req_iip0022_full and observations.get('lineage_necroptosis_time_resolved_viability_and_rescue_verified') is not True)):
iip0022_hold_status = 'HOLD_LINEAGE_NECROPTOSIS_TIME_RESOLVED_VIABILITY_AND_RESCUE_UNVERIFIED'
iip0022_eval_summary: dict[str, object] | None = None
if _iip0022_active:
iip0022_eval_summary = {
'gate_pass': iip0022_hold_status is None,
'hold_status': iip0022_hold_status,
'track2_rescue_route': _t2_route,
'track2_route_status': iip0022_track2_status,
'deprecated_conflated_flag_supplied': _legacy_conflated_t2,
}
# Stage-0 Design Y wildcard fail-closed Y-01..Y-04 evaluation (IIP-0023; DEC-102):
# Completely inactive when no design_y_* / obs_design_y* key is supplied so A/B/X behavior is 100% preserved.
_dy_int_mod = observations.get('design_y_integrase_modality')
if isinstance(_dy_int_mod, str):
_dy_int_mod = _dy_int_mod.strip()
_dy_sil_mod = observations.get('design_y_silencing_modality')
if isinstance(_dy_sil_mod, str):
_dy_sil_mod = _dy_sil_mod.strip()
_dy_pay_arm = observations.get('design_y_payload_arm')
if isinstance(_dy_pay_arm, str):
_dy_pay_arm = _dy_pay_arm.strip()
_dy_bool_keys = (
'design_y_attlr_outside_orf_5p3p_race_verified',
'design_y_zero_2a_scar_proteomics_verified',
'design_y_dpcpx_adora1_antagonist_control_run',
'design_y_anti_cd200_blockade_reversal_verified',
'design_y_y04_full_coculture_and_clonogenic_confirmed',
)
_dy_quant_keys = (
'obs_design_y01_max_lineage_escape_pct',
'obs_design_y01_lineage_cells_scored',
'obs_design_y01_cbe_offtarget_pct',
'obs_design_y02_pre_enrichment_ki_pct',
'obs_design_y02_clonal_ddpcr_cn',
'obs_design_y02_wt_b2m_residual_allele_frac',
'obs_design_y02_backbone_kanr_vaf',
'obs_design_y02_wgs_pseudosite_k',
'obs_design_y03_iec_beta_selectivity_ratio',
'obs_design_y03_beta_mir375_retention_pct',
'obs_design_y03_coculture_gsis_si',
'obs_design_y03_gsis_retention_pct',
'obs_design_y03_supernatant_adenosine_nM',
'obs_design_y03_dpcpx_gsis_delta_pct',
'obs_design_y04_multicistron_retention_pct',
'obs_design_y04_nhs20_c5b9_mac_pct',
'obs_design_y04_indirect_apc_cd4_si',
'obs_design_y04_ap1903_clonogenic_survival_frac',
'obs_design_y_sampling_age_days',
'obs_design_y02_ont_intact_homolog_pct',
'obs_design_y04_all4_lineages_scored_count',
'obs_design_y04_ap1903_survivor_count_k',
'obs_design_y04_ap1903_effective_trials',
)
_iip0023_dy_active = bool(
_dy_int_mod is not None
or _dy_sil_mod is not None
or _dy_pay_arm is not None
or any(observations.get(_bk) is not None for _bk in _dy_bool_keys)
or any(_qk in validated_stage0 for _qk in _dy_quant_keys)
)
iip0023_dy_status = 'NOT_TESTED'
iip0023_hold_status: str | None = None
if _iip0023_dy_active:
if _dy_int_mod == 'LEGACY_ATTB_GENOME_ATTP_PLASMID_REJECTED':
iip0023_dy_status = 'HOLD_DESIGN_Y02_LEGACY_ATTB_IN_GENOME_POLARITY_OT4_PSEUDOSITE_RISK_REJECTED'
elif _dy_pay_arm == 'DESIGN_Y_CD39_IEC_COMPARATOR_12555BP':
iip0023_dy_status = 'HOLD_DESIGN_Y03_CD39_ECTONUCLEOTIDASE_COMPARATOR_NOT_PRIMARY_PAYLOAD'
elif (
_dy_int_mod != 'EEPASSIGE_B2M_ATTP_GENOME_ATTB_MINICIRCLE'
or _dy_sil_mod is None
or _dy_pay_arm is None
or not all(observations.get(_bk) is True for _bk in _dy_bool_keys)
or not all(_qk in validated_stage0 and se_provenance_by_mean.get(_qk) == 'EXPLICIT_SE_SUPPLIED' for _qk in _dy_quant_keys)
):
iip0023_dy_status = 'HOLD_DESIGN_Y_INCOMPLETE_OR_DEFAULT_SE_Y01_TO_Y04_PANEL'
elif (
validated_stage0['obs_design_y_sampling_age_days'] < 60.0
or abs(validated_stage0['obs_design_y04_all4_lineages_scored_count'] - 4.0) > 1e-9
or _lower95('obs_design_y01_lineage_cells_scored') < 10000.0
or _upper95('obs_design_y01_max_lineage_escape_pct') > 1.0
or _upper95('obs_design_y01_cbe_offtarget_pct') > 0.10
):
iip0023_dy_status = 'HOLD_DESIGN_Y01_60D_4LINEAGE_SILENCE_OR_TADCBED_HAPLOTYPE_FAILED'
elif (
_lower95('obs_design_y02_pre_enrichment_ki_pct') < 3.0
or _lower95('obs_design_y02_clonal_ddpcr_cn') < 1.90
or _upper95('obs_design_y02_clonal_ddpcr_cn') > 2.10
or _lower95('obs_design_y02_ont_intact_homolog_pct') < 99.0