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 not b_prime_sct_direct_cd8_failed
and (not _strict_s7_mlc_and_se_required or (sct_cd8_mlc_explicitly_cleared and _sct_density_se_explicit))
)
# Design B2 (ISLET1_B2_5LOCUS_TYK2_PE) retained-HLA-C TYK2 p.Pro1104Ala (SAPTKFLEL) empirical OR-hold gate (IIP-0017; DEC-095):
_b2_tyk2_product_selected = bool(
product_def is not None
and str(product_def.get('product_variant_id', '')) == 'ISLET1_B2_5LOCUS_TYK2_PE'
)
_b2_tyk2_stratum = (
observations['b2_tyk2_recipient_genotype_stratum'].strip()
if isinstance(observations.get('b2_tyk2_recipient_genotype_stratum'), str)
else None
)
_b2_tyk2_allele = (
observations['b2_tyk2_hlac_allele'].strip()
if isinstance(observations.get('b2_tyk2_hlac_allele'), str)
else None
)
_b2_tyk2_gate_active = bool(
_b2_tyk2_product_selected
or _b2_tyk2_stratum is not None
or _b2_tyk2_allele is not None
or any(
observations.get(_bk) is not None
for _bk in (
'b2_tyk2_saptkflel_allele_assigned_ms_detected',
'b2_tyk2_peptide_pulsed_positive_control_verified',
'b2_tyk2_hlac_blockade_abrogation_verified',
)
)
or any(
_bmk in validated_stage0
for _bmk in (
'obs_b2_tyk2_p1104a_isogenic_cd8_lysis_delta_vs_bwt_pp',
'obs_b2_tyk2_p1104a_primed_cd8_elispot_sfu_per_1e6',
'obs_b2_tyk2_p1104a_iec_cd8_lysis_delta_vs_bwt_pp',
)
)
)
b2_tyk2_gate_status: str | None = None
b2_tyk2_hold_status: str | None = None
b2_tyk2_eval_summary: dict[str, object] | None = None
if _b2_tyk2_gate_active:
_b2_sc_hazard = bool(
'obs_b2_tyk2_p1104a_isogenic_cd8_lysis_delta_vs_bwt_pp' in validated_stage0
and _upper95('obs_b2_tyk2_p1104a_isogenic_cd8_lysis_delta_vs_bwt_pp') > 5.0
)
_b2_iec_hazard = bool(
'obs_b2_tyk2_p1104a_iec_cd8_lysis_delta_vs_bwt_pp' in validated_stage0
and _upper95('obs_b2_tyk2_p1104a_iec_cd8_lysis_delta_vs_bwt_pp') > 5.0
)
_b2_elispot_hazard = bool(
'obs_b2_tyk2_p1104a_primed_cd8_elispot_sfu_per_1e6' in validated_stage0
and _upper95('obs_b2_tyk2_p1104a_primed_cd8_elispot_sfu_per_1e6') > 50.0
)
_b2_ms_flag = observations.get('b2_tyk2_saptkflel_allele_assigned_ms_detected')
_b2_pos_ctrl = observations.get('b2_tyk2_peptide_pulsed_positive_control_verified')
_b2_block_ok = observations.get('b2_tyk2_hlac_blockade_abrogation_verified')
_b2_quant_powered_complete = bool(
_b2_tyk2_stratum in ALLOWED_B2_TYK2_RECIPIENT_GENOTYPE_STRATA
and _b2_tyk2_allele in ALLOWED_B2_TYK2_HLAC_ALLELES
and _b2_ms_flag is False
and all(
_bmk in validated_stage0 and se_provenance_by_mean.get(_bmk) == 'EXPLICIT_SE_SUPPLIED'
for _bmk in (
'obs_b2_tyk2_p1104a_isogenic_cd8_lysis_delta_vs_bwt_pp',
'obs_b2_tyk2_p1104a_primed_cd8_elispot_sfu_per_1e6',
'obs_b2_tyk2_p1104a_iec_cd8_lysis_delta_vs_bwt_pp',
)
)
and validated_stage0_se.get('obs_b2_tyk2_p1104a_isogenic_cd8_lysis_delta_vs_bwt_se', 999.0) <= 2.5
and validated_stage0_se.get('obs_b2_tyk2_p1104a_iec_cd8_lysis_delta_vs_bwt_se', 999.0) <= 2.5
and validated_stage0_se.get('obs_b2_tyk2_p1104a_primed_cd8_elispot_se', 999.0) <= 20.0
)
if _b2_sc_hazard or _b2_iec_hazard or _b2_elispot_hazard:
b2_tyk2_gate_status = 'HOLD_DESIGN_B2_TYK2_P1104A_HLAC_NEOANTIGEN_HAZARD_DETECTED'
b2_tyk2_hold_status = b2_tyk2_gate_status
elif _b2_ms_flag is True:
b2_tyk2_gate_status = 'HOLD_DESIGN_B2_TYK2_P1104A_HLAC_MS_DETECTED_OR_DISCORDANT_REQUIRES_STRATIFIED_REVIEW'
b2_tyk2_hold_status = b2_tyk2_gate_status
elif _b2_pos_ctrl is False or _b2_block_ok is False:
b2_tyk2_gate_status = 'HOLD_DESIGN_B2_TYK2_P1104A_POSITIVE_CONTROL_OR_CAUSAL_RESTRICTION_UNVERIFIED'
b2_tyk2_hold_status = b2_tyk2_gate_status
elif not _b2_quant_powered_complete:
b2_tyk2_gate_status = 'HOLD_DESIGN_B2_TYK2_P1104A_INCOMPLETE_OR_UNDERPOWERED_STRATIFIED_PANEL'
b2_tyk2_hold_status = b2_tyk2_gate_status
elif _b2_pos_ctrl is not True or _b2_block_ok is not True:
b2_tyk2_gate_status = 'HOLD_DESIGN_B2_TYK2_P1104A_POSITIVE_CONTROL_OR_CAUSAL_RESTRICTION_UNVERIFIED'
b2_tyk2_hold_status = b2_tyk2_gate_status
else:
b2_tyk2_gate_status = 'CLEARED_DESIGN_B2_TYK2_P1104A_STRATIFIED_HLAC_GATE'
b2_tyk2_eval_summary = {
'gate_pass': b2_tyk2_hold_status is None,
'status': b2_tyk2_gate_status,
'recipient_genotype_stratum': _b2_tyk2_stratum,
'hlac_allele': _b2_tyk2_allele,
'saptkflel_allele_assigned_ms_detected': _b2_ms_flag,
'peptide_pulsed_positive_control_verified': _b2_pos_ctrl,
'hlac_blockade_abrogation_verified': _b2_block_ok,
}
s7_hold_unqualified_sct = bool(s7_allo_triggered and not sct_density_explicitly_qualified)
s7_hold_unverified_sct_allo = bool(
(
s7_allo_triggered
and sct_density_explicitly_qualified
and (not sct_cd8_mlc_explicitly_cleared or (_strict_s7_mlc_and_se_required and not _sct_density_se_explicit))
)
or b_prime_sct_direct_cd8_failed
)
glucagon_2mM_lower95 = _lower95('obs_gate0m_glucagon_2mM_fold_increase', 2.5)
prolonged_insulin_clearance_failed = bool(
'obs_recipient_insulin_clearance_tau_min' in validated_stage0
and _upper95('obs_recipient_insulin_clearance_tau_min') >= 8.0
and observations.get('s8_staged_dose_and_omental_portal_drainage_qualified') is not True
)
s8_promoted = bool(
_upper95('obs_gate0m_shutoff_t90_min', 2.4) > 3.0
or ('obs_gate0m_8mM_to_2mM_insulin_shutoff_ratio' in validated_stage0 and _upper95('obs_gate0m_8mM_to_2mM_insulin_shutoff_ratio') > 0.20)
or _upper95('obs_basal_insulin_frac_peak', 0.10) > 0.15
or _lower95('obs_glucose_threshold_mM', 5.0) < 4.5
or _lower95('obs_immaturity_corner_min_glucose_mM', 3.6) < 3.5
or _lower95('obs_alpha_glucagon_low_glc_fold', 2.5) < 2.0
or validated_stage0.get('obs_gate0m_glucagon_2mM_fold_increase', 2.5) < 2.0
or glucagon_2mM_lower95 < 2.0
or _lower95('obs_alpha_counterregulatory_gain_ratio', 1.0) < 0.80
or _lower95('obs_ucn3_maturity_ratio', 1.0) < 0.70
or prolonged_insulin_clearance_failed
or observations.get('s8_fasting_leak_or_ucn3_failed') is True
)
_adj_arm_raw = observations.get('adjunct_conditioning_history_arm')
adjunct_conditioning_history_arm = (
_adj_arm_raw.strip() if isinstance(_adj_arm_raw, str) else 'ARM3_CONTINUOUSLY_ACTIVE'
)
adjunct_depletion_mode = (
observations['adjunct_depletion_mode'].strip()
if isinstance(observations.get('adjunct_depletion_mode'), str)
else None
)
adjunct_sa_fhl1_status = (
observations['adjunct_sa_fhl1_status'].strip()
if isinstance(observations.get('adjunct_sa_fhl1_status'), str)
else None
)
adjunct_immune_responder_history = (
observations['adjunct_immune_responder_history'].strip()
if isinstance(observations.get('adjunct_immune_responder_history'), str)
else None
)
arm1_never_conditioned_reference_hold = bool(adjunct_conditioning_history_arm == 'ARM1_NEVER_CONDITIONED')
arm3_ongoing_bioactivity_explicit_false = bool(
adjunct_conditioning_history_arm == 'ARM3_CONTINUOUSLY_ACTIVE'
and observations.get('obs_arm3_ongoing_adjunct_bioactivity_verified') is False
)
has_complete_arm2_6endpoint_panel = bool(
'obs_indirect_apc_dq2_dq8_cd4_stimulation_index' in validated_stage0
and 'obs_indirect_apc_cd4_ifng_si' in validated_stage0
and 'obs_gate0d_transwell_beta_annexin_v_pct' in validated_stage0
and 'obs_arm2_post_depletion_viable_beta_recovery_pct' in validated_stage0
and 'obs_arm2_post_depletion_perifusion_gsis_si' in validated_stage0
and 'obs_arm2_post_depletion_nhs_c5b9_mac_pct' in validated_stage0
)
if adjunct_conditioning_history_arm == 'ARM2_CONDITIONED_DEPLETED':
# Exempt active-FasL >=80% CD4 apoptosis requirement on verified functionally depleted Arm 2 while enforcing shared post-depletion injury, activation, complement, recovery, and dynamic perifusion GSIS gates (IIP-0012; DEC-091):
indirect_apc_cd4_failed = False
arm2_depletion_verification_incomplete = not (
observations.get('obs_arm2_bound_and_supernatant_fasl_bioactivity_depleted_verified') is True
and observations.get('obs_arm2_sa_thbd_bioactivity_depleted_verified') is True
and observations.get('obs_arm2_contemporaneous_sham_handling_matched') is True
and observations.get('obs_arm3_ongoing_adjunct_bioactivity_verified') is True
and adjunct_depletion_mode in ('NATURAL_AGING_DECAY', 'PHYSICAL_WASHOUT')
and adjunct_sa_fhl1_status in ALLOWED_ADJUNCT_SA_FHL1_STATUSES
and adjunct_immune_responder_history in ALLOWED_ADJUNCT_IMMUNE_RESPONDER_HISTORIES
)
arm2_rebound_injury_or_function_failed = bool(
('obs_indirect_apc_dq2_dq8_cd4_stimulation_index' in validated_stage0 and _upper95('obs_indirect_apc_dq2_dq8_cd4_stimulation_index') > 1.5)
or ('obs_indirect_apc_cd4_ifng_si' in validated_stage0 and _upper95('obs_indirect_apc_cd4_ifng_si') > 2.0)
or ('obs_gate0d_transwell_beta_annexin_v_pct' in validated_stage0 and _upper95('obs_gate0d_transwell_beta_annexin_v_pct') > 15.0)
or ('obs_arm2_post_depletion_viable_beta_recovery_pct' in validated_stage0 and _lower95('obs_arm2_post_depletion_viable_beta_recovery_pct') < 85.0)
or ('obs_arm2_post_depletion_perifusion_gsis_si' in validated_stage0 and _lower95('obs_arm2_post_depletion_perifusion_gsis_si') < 2.5)
or ('obs_arm2_post_depletion_nhs_c5b9_mac_pct' in validated_stage0 and _upper95('obs_arm2_post_depletion_nhs_c5b9_mac_pct') > 5.0)
)
arm2_post_depletion_panel_incomplete = bool(
not arm2_depletion_verification_incomplete
and not arm2_rebound_injury_or_function_failed
and not has_complete_arm2_6endpoint_panel
)
else:
arm2_depletion_verification_incomplete = False
arm2_rebound_injury_or_function_failed = False
arm2_post_depletion_panel_incomplete = False
indirect_apc_cd4_failed = bool(
('obs_indirect_apc_dq2_dq8_cd4_stimulation_index' in validated_stage0 and _upper95('obs_indirect_apc_dq2_dq8_cd4_stimulation_index') > 1.5)
or ('obs_indirect_apc_cd4_ifng_si' in validated_stage0 and _upper95('obs_indirect_apc_cd4_ifng_si') > 2.0)
or (
adjunct_conditioning_history_arm == 'ARM3_CONTINUOUSLY_ACTIVE'
and 'obs_gate0d_activated_cd4_fasl_apoptosis_pct' in validated_stage0
and _lower95('obs_gate0d_activated_cd4_fasl_apoptosis_pct') < 80.0
)
or ('obs_gate0d_transwell_beta_annexin_v_pct' in validated_stage0 and _upper95('obs_gate0d_transwell_beta_annexin_v_pct') > 15.0)
)
# Two-strand knock-in splice-challenger Stage-0 gate evaluation (IIP-0015; DEC-092):
_chall_arm_raw = observations.get('knockin_splice_challenger_arm')
knockin_splice_challenger_arm = (
_chall_arm_raw.strip() if isinstance(_chall_arm_raw, str) else 'PARENTAL_REFERENCE'
)
knockin_locus4_orientation = (
observations['knockin_locus4_orientation'].strip()
if isinstance(observations.get('knockin_locus4_orientation'), str)
else None
)
_chall_any_input = bool(
_chall_arm_raw is not None
or knockin_locus4_orientation is not None
or any(
observations.get(_ck) is not None
for _ck in (
'obs_challenger_ivt_rna_recovery_standard_verified',
'obs_challenger_pam_seed_shield_coconversion_verified',
'obs_challenger_host_isoforms_above_loq_verified',
'obs_challenger_sv40pa_and_host_3prime_cleavage_checked',
)
)
or any(
_ck in validated_stage0
for _ck in (
'obs_challenger_ivt_relative_recovery_eta',
'obs_challenger_umi_molecules_profiled',
'obs_challenger_aberrant_splice_umi_count_k',
'obs_challenger_host_exon_splice_retention_ratio',
'obs_challenger_dsrna_j2_or_isg_fold_wt',
)
)
)
challenger_umi_eff = (
validated_stage0['obs_challenger_umi_molecules_profiled']
* min(1.0, validated_stage0['obs_challenger_ivt_relative_recovery_eta'])
if (
'obs_challenger_umi_molecules_profiled' in validated_stage0
and 'obs_challenger_ivt_relative_recovery_eta' in validated_stage0
)
else 0.0
)
challenger_hold_status: str | None = None
if knockin_splice_challenger_arm != 'PARENTAL_REFERENCE' or _chall_any_input:
_is_active_chall = bool(knockin_splice_challenger_arm != 'PARENTAL_REFERENCE')
_tost_z95 = 1.6448536269514722
_host_ret_mean = validated_stage0.get('obs_challenger_host_exon_splice_retention_ratio')
_host_ret_se = _explicit_se('obs_challenger_host_exon_splice_retention_ratio')
_host_ret_se_supplied = (