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…
return (False, 'HOLD_MISSING_OR_INVALID_obs_adcc_positive_control_lysis_pct')
if float(pos_adcc_m) - t_crit * float(pos_adcc_s) < 25.0:
return (False, 'HOLD_BELOW_LOWER95_obs_adcc_positive_control_lysis_pct')
if arm == 'ARM3_CONTINUOUSLY_ACTIVE':
if obs.get('obs_arm3_ongoing_adjunct_bioactivity_verified') is not True:
return (False, 'HOLD_GATE0D_ARM3_ONGOING_BIOACTIVITY_UNVERIFIED')
arm3_bounds = [
('obs_gate0d_activated_cd4_fasl_apoptosis_pct', ('obs_gate0d_activated_cd4_fasl_apoptosis_se', 'se_arm3_cd4_apoptosis'), 'lower', 80.0, 0.0, 100.0),
('obs_indirect_apc_dq2_dq8_cd4_stimulation_index', ('obs_indirect_apc_dq2_dq8_cd4_stimulation_index_se', 'obs_indirect_apc_dq2_dq8_cd4_stimulation_se', 'se_cd4_si'), 'upper', 1.5, 0.1, 100.0),
('obs_indirect_apc_cd4_ifng_si', ('obs_indirect_apc_cd4_ifng_si_se', 'obs_indirect_apc_cd4_ifng_se', 'se_ifng_si'), 'upper', 2.0, 0.1, 100.0),
('obs_gate0d_transwell_beta_annexin_v_pct', ('obs_gate0d_transwell_beta_annexin_v_se', 'se_annexin_v'), 'upper', 15.0, 0.0, 100.0),
('obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_pct', ('obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_se', 'se_net_adcc'), 'upper', 5.0, -20.0, 100.0),
('obs_adcc_isotype_background_lysis_pct', ('obs_adcc_isotype_background_lysis_se', 'se_isotype_adcc'), 'upper', 5.0, 0.0, 100.0),
]
for mk, sks, direction, thresh, lo, hi in arm3_bounds:
m = obs.get(mk)
s = _read_se_alias_iip0028(obs, sks[0], *sks[1:])
if not _valid_domain_scalar_iip0028(m, lo, hi) or not _valid_positive_se_iip0028(s):
return (False, f'HOLD_ARM3_INVALID_OR_MISSING_{mk}')
mf, sf = float(m), float(s)
if direction == 'upper' and (mf + t_crit * sf) > thresh:
return (False, f'HOLD_ARM3_EXCEEDED_UPPER95_{mk}')
if direction == 'lower' and (mf - t_crit * sf) < thresh:
return (False, f'HOLD_ARM3_BELOW_LOWER95_{mk}')
if prod_id == 'ISLET1_B2_5LOCUS_BASE':
return (True, 'RESEARCH_ONLY_PAIRED_STUDY_ARM3_CLEARED_B2_EXECUTION_SUPPORTED_FALSE')
return (True, 'CLEARED_ARM3_ACTIVE_ADJUNCT_AND_FCR_ADCC_PROFILE')
dep_mode = obs.get('adjunct_depletion_mode')
if dep_mode not in ('PHYSICAL_WASHOUT', 'NATURAL_AGING_DECAY'):
return (False, 'HOLD_GATE0D_POOLED_OR_UNSPECIFIED_DEPLETION_MODE')
if obs.get('washout_and_natural_decay_unpooled_verified') is not True:
return (False, 'HOLD_GATE0D_POOLED_WASHOUT_AND_AGING_ALIQUOTS')
if obs.get('carrier_and_soluble_adjunct_below_lod_verified') is not True:
return (False, 'HOLD_GATE0D_RESIDUAL_ADJUNCT_ABOVE_LOD')
if obs.get('obs_arm2_bound_and_supernatant_fasl_bioactivity_depleted_verified') is not True:
return (False, 'HOLD_GATE0D_FASL_DEPLETION_UNVERIFIED')
if obs.get('obs_arm2_sa_thbd_bioactivity_depleted_verified') is not True:
return (False, 'HOLD_GATE0D_SA_THBD_DEPLETION_UNVERIFIED')
if obs.get('obs_arm2_contemporaneous_sham_handling_matched') is not True:
return (False, 'HOLD_GATE0D_CONTEMPORANEOUS_SHAM_UNMATCHED')
if obs.get('obs_arm3_ongoing_adjunct_bioactivity_verified') is not True:
return (False, 'HOLD_GATE0D_PARALLEL_ARM3_BIOACTIVITY_CONTROL_UNVERIFIED')
arm2_sid = obs.get('arm2_depleted_sample_id')
arm3_ctrl_sid = obs.get('contemporaneous_arm3_control_sample_id')
if not _valid_strict_unpadded_id_iip0028(arm2_sid) or not _valid_strict_unpadded_id_iip0028(arm3_ctrl_sid) or arm2_sid == arm3_ctrl_sid:
return (False, 'HOLD_GATE0D_MISSING_OR_DUPLICATE_CONTEMPORANEOUS_ARM3_CONTROL_SAMPLE_ID')
resp_hist = obs.get('adjunct_immune_responder_history')
if resp_hist not in ('RETAINED_CONDITIONED_RESPONDERS', 'FRESH_RECIPIENT_RESPONDERS', 'PAIRED_BOTH'):
return (False, 'HOLD_GATE0D_MISSING_IMMUNE_RESPONDER_HISTORY')
fhl1_status = obs.get('adjunct_sa_fhl1_status')
if fhl1_status == 'RETAINED_ACTIVE':
return (False, 'HOLD_GATE0D_PARTIALLY_DEPLETED_SA_FHL1_RETAINED_ACTIVE_NOT_COMPLETE_DEPLETION')
if fhl1_status not in ('DEPLETED_VERIFIED', 'ABSENT_FROM_LOT'):
return (False, 'HOLD_GATE0D_INVALID_OR_MISSING_SA_FHL1_STATUS')
arm2_bounds = [
('obs_parallel_arm3_control_cd4_apoptosis_pct', ('obs_parallel_arm3_control_cd4_apoptosis_se', 'se_parallel_arm3_cd4_apoptosis'), 'lower', 80.0, 0.0, 100.0),
('obs_indirect_apc_dq2_dq8_cd4_stimulation_index', ('obs_indirect_apc_dq2_dq8_cd4_stimulation_index_se', 'obs_indirect_apc_dq2_dq8_cd4_stimulation_se', 'se_cd4_si'), 'upper', 1.5, 0.1, 100.0),
('obs_indirect_apc_cd4_ifng_si', ('obs_indirect_apc_cd4_ifng_si_se', 'obs_indirect_apc_cd4_ifng_se', 'se_ifng_si'), 'upper', 2.0, 0.1, 100.0),
('obs_gate0d_transwell_beta_annexin_v_pct', ('obs_gate0d_transwell_beta_annexin_v_se', 'se_annexin_v'), 'upper', 15.0, 0.0, 100.0),
('obs_arm2_post_depletion_nhs_c5b9_mac_pct', ('obs_arm2_post_depletion_nhs_c5b9_mac_se', 'se_c5b9'), 'upper', 5.0, 0.0, 100.0),
('obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_pct', ('obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_se', 'se_net_adcc'), 'upper', 5.0, -20.0, 100.0),
('obs_adcc_isotype_background_lysis_pct', ('obs_adcc_isotype_background_lysis_se', 'se_isotype_adcc'), 'upper', 5.0, 0.0, 100.0),
('obs_arm2_post_depletion_viable_beta_recovery_pct', ('obs_arm2_post_depletion_viable_beta_recovery_se', 'se_beta_rec'), 'lower', 85.0, 0.0, 150.0),
('obs_arm2_post_depletion_perifusion_gsis_si', ('obs_arm2_post_depletion_perifusion_gsis_si_se', 'se_gsis_si'), 'lower', 2.5, 0.1, 100.0),
('obs_post_depletion_input_normalized_cpep_ratio', ('obs_post_depletion_input_normalized_cpep_ratio_se', 'se_cpep_ratio'), 'lower', 0.85, 0.01, 5.0),
]
for mk, sks, direction, thresh, lo, hi in arm2_bounds:
m = obs.get(mk)
s = _read_se_alias_iip0028(obs, sks[0], *sks[1:])
if not _valid_domain_scalar_iip0028(m, lo, hi) or not _valid_positive_se_iip0028(s):
return (False, f'HOLD_MISSING_OR_INVALID_{mk}')
mf, sf = float(m), float(s)
if direction == 'upper' and (mf + t_crit * sf) > thresh:
return (False, f'HOLD_EXCEEDED_UPPER95_{mk}')
if direction == 'lower' and (mf - t_crit * sf) < thresh:
return (False, f'HOLD_BELOW_LOWER95_{mk}')
if prod_id == 'ISLET1_B2_5LOCUS_BASE':
return (True, 'RESEARCH_ONLY_PAIRED_STUDY_ARM2_CLEARED_B2_EXECUTION_SUPPORTED_FALSE')
return (True, 'CLEARED_ARM2_COMPLETE_DEPLETION_GATE0D_AND_FCR_ADCC_OVERLAY')
def evaluate_paired_adcc_and_postdepletion_report_iip_0028(
obs: dict[str, Any],
*,
root: Path | str | None = None,
upstream_b2_authorization_record: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""Structured report wrapper around `evaluate_paired_adcc_and_postdepletion_gate_iip_0028` preserving `execution_supported` (IIP-0028; DEC-106)."""
ok, code = evaluate_paired_adcc_and_postdepletion_gate_iip_0028(
obs,
root=root,
upstream_b2_authorization_record=upstream_b2_authorization_record,
)
prod_id = obs.get('product_variant_id') if isinstance(obs, dict) else None
is_b2 = prod_id == 'ISLET1_B2_5LOCUS_BASE'
return {
'gate_pass': ok,
'status': code,
'product_variant_id': prod_id if isinstance(prod_id, str) else None,
'execution_supported': False if (not ok or is_b2) else True,
'paired_study_research_only': bool(ok and is_b2),
}
def evaluate_dec084_measured_potency_mixture_gate_iip_0028(
obs: dict[str, Any],
) -> dict[str, Any]:
"""
Measured-potency equal-output DEC-084 mixture (70:20:10 / 70:25:5 vs 60:30:10) evaluator (IIP-0028; DEC-106):
- Requires n >= 8 independent confirmation blocks disjoint from n >= 3 fixed-input selection blocks;
- Requires measured starting lineage fractions, viable counts, and fresh-lot equal-output dose-response;
- Enforces implanted loading == (6/7) * (out_A / out_B) * 1500.0 IEQ/cm^2, U95_t(OCR_B/A) <= 0.90,
dual-mesh (40x40x70 & 60x60x105) worst-face pO2 >= 15.0 mmHg, L95_t(Cpep_AUC_B/A) >= 0.85,
L95_t(GCG_AUC_B/A) >= 0.85, Day-28 L95_t(beta_recovery) >= 0.80, and Readout 2 insulin/glucagon bounds.
"""
if not isinstance(obs, dict):
return {'gate_pass': False, 'status': 'HOLD_DEC084_INVALID_PAYLOAD'}
if obs.get('selection_blocks_excluded_from_confirmation') is not True:
return {'gate_pass': False, 'status': 'HOLD_DEC084_SELECTION_BLOCKS_NOT_EXCLUDED'}
if obs.get('measured_starting_composition_and_viable_counts_verified') is not True:
return {'gate_pass': False, 'status': 'HOLD_DEC084_UNVERIFIED_STARTING_COMPOSITION_OR_VIABLE_COUNTS'}
n_conf = obs.get('n_confirmation_blocks')
if not _is_strict_int_iip0024(n_conf) or n_conf < 8:
return {'gate_pass': False, 'status': 'HOLD_DEC084_CONFIRMATION_BLOCKS_LT_8'}
t_crit = student_t_ppf(0.95, n_conf - 1)
pot = obs.get('obs_dec084_starting_potency_ratio_out_b_over_out_a')
pot_se = _read_se_alias_iip0028(obs, 'obs_dec084_starting_potency_ratio_out_b_over_out_a_se', 'se_starting_potency_ratio')
load = obs.get('implanted_areal_loading_ieq_cm2')
if not _valid_domain_scalar_iip0028(pot, 0.2, 5.0) or not _valid_positive_se_iip0028(pot_se) or not _valid_domain_scalar_iip0028(load, 100.0, 5000.0):
return {'gate_pass': False, 'status': 'HOLD_DEC084_MISSING_OR_INVALID_POTENCY_OR_LOADING'}
expected_load = (6.0 / 7.0) * (1.0 / float(pot)) * 1500.0
if abs(float(load) - expected_load) > 0.25:
return {'gate_pass': False, 'status': 'HOLD_DEC084_LOADING_DOES_NOT_MATCH_MEASURED_POTENCY_FORMULA'}
po2_nx40 = obs.get('dual_band_worst_face_po2_nx40_mmhg')
po2_nx60 = obs.get('dual_band_worst_face_po2_nx60_mmhg')
if not _valid_domain_scalar_iip0028(po2_nx40, 0.0, 120.0) or not _valid_domain_scalar_iip0028(po2_nx60, 0.0, 120.0):
return {'gate_pass': False, 'status': 'HOLD_DEC084_MISSING_MULTIMESH_WORST_FACE_OXYGEN'}
if min(float(po2_nx40), float(po2_nx60)) < 15.0:
if max(float(po2_nx40), float(po2_nx60)) >= 15.0:
return {'gate_pass': False, 'status': 'HOLD_DEC084_NUMERICALLY_MESH_SENSITIVE_WORST_FACE_OXYGEN_BELOW_15MMHG'}
return {'gate_pass': False, 'status': 'HOLD_DEC084_WORST_FACE_OXYGEN_BELOW_15MMHG'}
bounds = [
('obs_dec084_ocr_ratio_b_over_a', ('obs_dec084_ocr_ratio_b_over_a_se', 'se_ocr_ratio'), 'upper', 0.90, 0.1, 5.0),
('obs_dec084_cpep_auc_ratio_b_over_a', ('obs_dec084_cpep_auc_ratio_b_over_a_se', 'se_cpep_auc_ratio'), 'lower', 0.85, 0.1, 5.0),
('obs_dec084_gcg_auc_ratio_b_over_a', ('obs_dec084_gcg_auc_ratio_b_over_a_se', 'se_gcg_auc_ratio'), 'lower', 0.85, 0.1, 5.0),
('obs_day28_beta_recovery_ratio', ('obs_day28_beta_recovery_se', 'se_day28_beta_recovery'), 'lower', 0.80, 0.0, 2.0),
('obs_readout2_perifusion_gsis_si', ('obs_readout2_perifusion_gsis_se', 'se_readout2_si'), 'lower', 3.0, 0.1, 50.0),
('obs_readout2_first_phase_peak_to_basal_ratio', ('obs_readout2_first_phase_peak_to_basal_se', 'se_readout2_peak_basal'), 'lower', 4.5, 0.1, 100.0),
('obs_readout2_first_phase_time_to_peak_min', ('obs_readout2_first_phase_time_to_peak_se', 'se_readout2_tpeak'), 'upper', 8.0, 0.1, 60.0),
('obs_readout2_stepdown_shutoff_t50_min', ('obs_readout2_stepdown_shutoff_t50_se', 'se_readout2_t50'), 'upper', 3.0, 0.05, 60.0),
('obs_gate0m_glucagon_2mM_fold_increase', ('obs_gate0m_glucagon_2mM_fold_se', 'se_readout2_gcg_fold'), 'lower', 2.0, 0.1, 50.0),
]
for mk, sks, direction, thresh, lo, hi in bounds:
m = obs.get(mk)
s = _read_se_alias_iip0028(obs, sks[0], *sks[1:])
if not _valid_domain_scalar_iip0028(m, lo, hi) or not _valid_positive_se_iip0028(s):
return {'gate_pass': False, 'status': f'HOLD_DEC084_MISSING_OR_INVALID_{mk}'}
mf, sf = float(m), float(s)
if direction == 'upper' and (mf + t_crit * sf) > thresh:
return {'gate_pass': False, 'status': f'HOLD_DEC084_EXCEEDED_UPPER95_{mk}'}
if direction == 'lower' and (mf - t_crit * sf) < thresh:
return {'gate_pass': False, 'status': f'HOLD_DEC084_BELOW_LOWER95_{mk}'}
return {
'gate_pass': True,
'status': 'CLEARED_DEC084_MEASURED_POTENCY_LOW_OCR_AND_GLUCAGON_CONFIRMATION',
'computed_equal_output_loading_ieq_cm2': round(expected_load, 4),
}
def _validate_iapp_control_block_iip0028(rec: dict[str, Any], sample_id: str, tp_label: str) -> tuple[bool, str]:
loq = rec.get('loq_signal')
if not _is_strict_finite_number_iip0024(loq) or float(loq) <= 0.0:
return (False, f'HOLD_INCONCLUSIVE_IAPP_INVALID_LOQ_{tp_label}')
loq_f = float(loq)
ko_id = rec.get('ko_blank_id')
ko_sig = rec.get('ko_blank_signal')
ins_sig = rec.get('insulin_fibril_blank_signal')
if not _valid_strict_unpadded_id_iip0028(ko_id):
return (False, f'HOLD_INCONCLUSIVE_IAPP_MISSING_KO_BLANK_ID_{tp_label}')
if not _is_strict_finite_number_iip0024(ko_sig) or not (0.0 <= float(ko_sig) < loq_f):
return (False, f'HOLD_INCONCLUSIVE_IAPP_BLANK_ABOVE_LOQ_{tp_label}')
if not _is_strict_finite_number_iip0024(ins_sig) or not (0.0 <= float(ins_sig) < loq_f):
return (False, f'HOLD_INCONCLUSIVE_IAPP_INSULIN_FIBRIL_BLANK_ABOVE_LOQ_{tp_label}')
ref_id = rec.get('age_matched_ref_control_id')
ref_sig = rec.get('ref_signal')
if not _valid_strict_unpadded_id_iip0028(ref_id) or ref_id in (ko_id, sample_id):
return (False, f'HOLD_INCONCLUSIVE_IAPP_INVALID_OR_KO_REUSED_REF_ID_{tp_label}')
if not _is_strict_finite_number_iip0024(ref_sig) or not (float(ref_sig) > loq_f > 0.0):
return (False, f'HOLD_INCONCLUSIVE_IAPP_REFERENCE_NOT_ABOVE_LOQ_{tp_label}')
spike_pct = rec.get('spike_recovery_iapp_1_37_pct')
if not _valid_domain_scalar_iip0028(spike_pct, 80.0, 120.0):
return (False, f'HOLD_INCONCLUSIVE_IAPP_SPIKE_RECOVERY_OUT_OF_RANGE_{tp_label}')
return (True, 'OK')
def evaluate_orthogonal_iapp_3way_gate_iip_0028(
obs: dict[str, Any],
*,
root: Path | str | None = None,
) -> dict[str, Any]:
"""
Visit/lot/sister-bound & concordance/replication-gated 72-h / Day-28 / Day-84 dual-modality IAPP evaluator (IIP-0028; DEC-106):
- Validates product_variant_id against the versioned product registry;
- Derives n >= 6 strictly from distinct verified contributing_lot_ids (rejecting free integer n);
- Binds 72h (timepoint_h == 72) and d28 (timepoint_d == 28) to LOT_SCOPE and destructive d84 (timepoint_d == 84)
to TERMINAL_SISTER_DEVICE_SCOPE on an authorized_sister_assembly_id != implant_device_assembly_id, rejecting
duplicate sample_ids OR copied raw measurement vectors across visits as HOLD_DUPLICATE_OR_WRONG_TIMEPOINT_SAMPLE;
- Evaluates viable beta mass (>= 80.0% L95_t) and stimulated GSIS SI (>= 2.5 L95_t) alongside IAPP so a falling
amyloid signal caused by beta-cell attrition cannot clear as clean proteostasis;
- Requires within-lot dual-modality L95_t co-exceedance OR disjoint >= 6-lot repeat confirmation before emitting
CONFIRMED_CHRONIC_P2_ELIGIBLE, holding archival NM_021999.5 ITM2B at 0% active weight.
"""
def _fail(disp: str, **extra: Any) -> dict[str, Any]:
return {
'core_cleared': False,
'disposition': disp,
'p2_itm2b_reserve_eligible': False,
'p2_active_weight_pct': 0.0,
**extra,
}
if not isinstance(obs, dict):
return _fail('HOLD_INCONCLUSIVE_IAPP_INVALID_PAYLOAD')
root_path = Path(root) if root is not None else Path(__file__).resolve().parents[1]
p_mod = _load_product_contract_module(root_path)
prod_doc = p_mod.load_product_contracts(root_path)
reg_ids = {str(p['product_variant_id']) for p in prod_doc['products']}
prod_id = obs.get('product_variant_id')
if not _valid_strict_unpadded_id_iip0028(prod_id) or prod_id not in reg_ids:
return _fail('HOLD_INCONCLUSIVE_IAPP_UNREGISTERED_OR_MISSING_PRODUCT_ID')
lot_list = obs.get('contributing_lot_ids')
if not isinstance(lot_list, (list, tuple)) or len(lot_list) < 6:
return _fail('HOLD_IAPP_UNVERIFIED_INDEPENDENT_LOTS_LT_6')
if not all(_valid_strict_unpadded_id_iip0028(x) for x in lot_list) or len(set(lot_list)) != len(lot_list):
return _fail('HOLD_IAPP_DUPLICATE_OR_INVALID_LOT_IDS')
n_rep = len(lot_list)