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…
else 'INACTIVE'
)
),
'S4_Metabolic_Demand_and_Autoreactive_Shield_Gate_0D': 'LOCK_RNLS_WT_TXNIP_WT_GY026_COMPLIANT' if s4_promoted else 'RETAIN_BASELINE_METABOLIC_CHASSIS',
'S5_Microgel_Boundary_Cuff_Gate_0G': 'DROP_SA_FASL_RETAIN_SA_THBD_PLUS_SA_FHL1' if s5_promoted else 'RETAIN_PERIMETER_SA_FASL_CUFF',
'S6_B2M_Orphan_Heavy_Chain_ERAD_Gate_0E': 'ACTIVATE_TYK2_P1104A_OR_RNLS_KO_OR_NLRC5_CRISPROFF' if s6_promoted else 'PASS_NO_ERAD_UPR_PENALTY',
'S7_Design_B_Prime_4Digit_Allo_vs_B_SCT_Gate_0B': (
'PROMOTE_ISLET1_B_SCT_C1_OR_C2_CIITA'
if s7_promoted
else (
'HOLD_B_PRIME_SCT_DIRECT_CD8_ALLOREACTIVITY_FAILED_RETAIN_PURE_MHC_NULL_TRACK1'
if b_prime_sct_direct_cd8_failed
else (
'HOLD_B_PRIME_ALLO_FAILED_PENDING_B_SCT_DENSITY_QUALIFICATION'
if s7_hold_unqualified_sct
else (
'HOLD_B_PRIME_ALLO_FAILED_REQUIRES_4DIGIT_MATCH_OR_SCT_CD8_MLC_CLEARANCE'
if s7_hold_unverified_sct_allo
else (
b2_tyk2_gate_status
if b2_tyk2_gate_status is not None
else (
(
iip0026_hlac_status
if iip0026_hlac_status is not None
else 'HOLD_MISSING_ENDOGENOUS_DESIGNB_HLAC_PHASED_CLEARANCE'
)
if _is_endogenous_hlac_b_26
else (
'UNMEASURED_EXTENDED_S7_GATE0B_HLAC_PANEL'
if not _has_explicit_s7_hlac_obs
else 'RETAIN_4DIGIT_MATCHED_HLAC'
)
)
)
)
)
)
),
'S8_SC_Islet_Paracrine_Maturity_Gate_0M': 'MANDATE_EXTENDED_S7W6_MATURATION_AND_80_100UM_CLUSTERS' if s8_promoted else 'PASS_MATURITY_GATE_0M',
'S8b_TYK2_Inducible_Promoter_Epistasis_Gate_0E': (
'COUPLE_TYK2_P1104A_STRICTLY_WITH_ARM1X_AND_L3_BFB_CONSTITUTIVE_BASAL_FLOOR'
if s8_tyk2_epistasis_triggered
else (
'HOLD_INCONCLUSIVE_UNDERPOWERED_TYK2_EPISTASIS_SE'
if s8_tyk2_epistasis_underpowered_hold
else 'PASS_TYK2_INDUCIBLE_PROMOTER_COMPATIBILITY'
)
),
'S9_Chronic_Fibrotic_Capsule_and_Mineralization_Gate_0F': 'ENFORCE_80UM_CLUSTER_CAP_AND_CITRATE_CHELATION' if s9_promoted else 'PASS_CHRONIC_CAPSULE_GATE_0F',
'S10_CMV_NKG2C_Adaptive_NK_Peptide_Selectivity_Gate_0A': (
(
str(s10_v3_eval['status'])
if not s10_v3_eval['gate_pass']
else (
'CLEARED_S10_FUNCTIONAL_SELECTIVITY_SCREENING_15K_V3'
if not s10_v3_release_qualified
else (
'CLEARED_S10_FUNCTIONAL_SELECTIVITY_SUB4_SCT_V3'
if (s10_kd_ratio_lower95_sub4 or float(s10_v3_eval['recorded_sct_kc_over_ka_mean']) < 4.0)
else 'CLEARED_S10_STATIC_RATIO_AND_PAIRED_FUNCTIONAL_GATE_V3'
)
)
)
if (_s10_v3_active and s10_v3_eval is not None)
else (
'CLEARED_SCT_SELECTIVITY_COUPON_KC_KA_GE_4'
if (s10_nkg2c_triggered and s10_coupon_cleared)
else (
'STRATIFY_CMV_NKG2C_RECIPIENTS_AND_EVALUATE_SCT_SELECTIVITY_MUTANT_COUPON'
if s10_nkg2c_triggered
else (
'UNMEASURED_EXTENDED_S10_PANEL'
if not _has_explicit_s10_obs
else 'PASS_CMV_NKG2C_SELECTIVITY_GATE_0A'
)
)
)
),
'S11_Locus2_CIITA_ModeB_Vascular_Complement_and_Efferocytosis_Gate': str(iip0031_s11_eval['status']),
}
canonical_json_switch_id_map = {
'JSON_S1_CD47_Split_Fallback_DX_S': decisions['S3_Locus1_Constitutive_Split_Fallback_DX_S'],
'JSON_S2_HLAE_Sense_Promoter_Gate_0A': decisions['S2_Locus1_Arm1B_vs_Arm1X_Gate_0A'],
'JSON_S3_Locus3_Hour0_Kinetic_Gate_0C': decisions['S1_Locus3_Kinetic_and_Topology_Gate_0C'],
'JSON_S4_Locus3_P2A_Tail_Biophysics_Gate_0C': decisions['S1_Locus3_Kinetic_and_Topology_Gate_0C'],
'JSON_S5_Plan_B_4Digit_Allo_vs_B_SCT_Gate_0B': decisions['S7_Design_B_Prime_4Digit_Allo_vs_B_SCT_Gate_0B'],
'JSON_S6_Chronic_Capsule_and_Mineralization_Gate_0F': decisions['S9_Chronic_Fibrotic_Capsule_and_Mineralization_Gate_0F'],
'JSON_S7_Lot_OCR_Ratio_and_RNLS_Gate_0D': decisions['S4_Metabolic_Demand_and_Autoreactive_Shield_Gate_0D'],
'JSON_S8_SC_Islet_Maturity_Gate_0M': decisions['S8_SC_Islet_Paracrine_Maturity_Gate_0M'],
'JSON_S8b_TYK2_Inducible_Promoter_Epistasis': decisions['S8b_TYK2_Inducible_Promoter_Epistasis_Gate_0E'],
'JSON_S9_Hard_Safety_Stop': safety_status,
'JSON_S10_CMV_NKG2C_Adaptive_NK_Selectivity_Gate_0A': decisions['S10_CMV_NKG2C_Adaptive_NK_Peptide_Selectivity_Gate_0A'],
'JSON_S11_Locus2_CIITA_ModeB_Vascular_Complement_and_Efferocytosis_Gate': decisions['S11_Locus2_CIITA_ModeB_Vascular_Complement_and_Efferocytosis_Gate'],
}
return {
'schema_version': tree_doc['schema_version'],
'strict_precedence_order': tree_doc['strict_precedence_order'],
'mandatory_s9_safety_panel_complete': mandatory_s9_safety_panel_complete,
'full_5endpoint_s9_panel_complete': full_5endpoint_s9_panel_complete,
's9_5endpoint_er_safety_panel_complete': full_5endpoint_s9_panel_complete,
's9_causal_failed_categories': s9_causal_failed_categories,
's9_panel_completeness_tier': s9_panel_completeness_tier,
's9_frequency_assay_holds': [
guard['status'] for guard in (
_vaf_guard if has_vaf_obs else {},
_cast_guard if has_cast_obs else {},
) if guard.get('status', '').startswith('HOLD_')
],
'lot_release_readiness_tier': lot_release_readiness_tier,
'safety_kill_s9_triggered': safety_kill_s9_triggered,
'sticky_cross_batch_s9_stop_active': sticky_prior_s9_stop,
'primary_biological_or_pouch_gate_failed': primary_biological_or_pouch_gate_failed,
'zero_event_proportion_missing_denominator_or_explicit_se': zero_event_proportion_missing_denominator_or_explicit_se,
'has_explicit_original_primary_obs': has_explicit_original_primary_obs,
'has_explicit_release_critical_molecule_and_rate_se': has_explicit_release_critical_molecule_and_rate_se,
'missing_original_primary_endpoints': missing_original_primary_endpoints,
'any_fallback_switch_triggered': any_fallback_switch_triggered,
'safety_kill_s9_status': safety_status,
'resolved_architecture_assignments': resolved_arch,
'validated_stage0_endpoints': validated_stage0,
'validated_stage0_se_endpoints': validated_stage0_se,
'stage0_se_provenance': se_provenance_by_mean,
's9_point_estimate_fallback_se_policy': 'SCALE_AWARE_DEFAULT_SE_IMPUTED_ON_SCALAR_OMISSION_TYPED_ATOM_REQUIRES_MEASURED_SE',
's9_se_imputed_endpoints': sorted(
mk for mk in (
'obs_icasp9_log10_kill',
'obs_tp53_ppm1d_bcor_vaf',
'obs_castseq_translocation_freq',
'obs_chop_coincidence_fold',
'obs_gate0e_chop_log2fc',
'obs_hc10_surface_fold_wt',
'obs_gate0e_hc10_surface_mfi_ratio',
)
if se_provenance_by_mean.get(mk) == 'DEFAULT_SE_IMPUTED_NOT_EXPLICIT'
),
'switch_decisions': decisions,
'canonical_json_switch_id_map': canonical_json_switch_id_map,
'pivotal_combined_stress_coupon_gate': combined_stress_spec,
**(
{'iip0026_molecular_provenance_evaluation': iip0026_eval_summary}
if iip0026_eval_summary is not None
else {}
),
**(
{'iip0028_postdepletion_adcc_mixture_and_iapp_evaluation': iip0028_eval_summary}
if iip0028_eval_summary is not None
else {}
),
**(
{'iip0027_promoter_origin_and_itr_evaluation': iip0027_eval_summary}
if iip0027_eval_summary is not None
else {}
),
**(
{'iip0029_twoclock_maturation_and_repeated_challenge_evaluation': iip0029_eval_summary}
if iip0029_eval_summary is not None
else {}
),
**(
{
'iip0031_locus2_and_tier6b_evaluation': {
's11_evaluation': iip0031_s11_eval,
**({'tier6b_sorted_lot_evaluation': iip0031_tier6b_eval} if iip0031_tier6b_eval is not None else {}),
}
}
if (iip0031_s11_eval.get('status') != 'NOT_APPLICABLE_NON_LOCUS2_MODEB_VARIANT' or iip0031_tier6b_eval is not None)
else {}
),
}
# ============================================================================
# Stage-0 Named Atomic Provenance Scopes, ENDPOINT_REGISTRY_SPEC, Exact
# Student-t / 6+6 Welch TOST, & Conjunctive DMR / XCI / mtDNA / MDM4 Validators
# (IIP-0024; DEC-103)
# ============================================================================
import dataclasses
import hashlib
from types import MappingProxyType
from typing import Any
def _is_strict_int_iip0024(val: Any) -> bool:
return isinstance(val, int) and not isinstance(val, bool)
def _is_strict_finite_number_iip0024(val: Any) -> bool:
if isinstance(val, bool) or not isinstance(val, (int, float)):
return False
try:
return math.isfinite(val)
except OverflowError:
return False
def _deep_freeze_iip0024(obj: Any) -> Any:
if isinstance(obj, (dict, MappingProxyType)):
for k in obj.keys():
if not isinstance(k, str):
raise TypeError(f'AtomicObservation mapping keys must be strings, got {type(k).__name__} (IIP-0024; DEC-103)')
return MappingProxyType({k: _deep_freeze_iip0024(v) for k, v in sorted(obj.items(), key=lambda kv: kv[0])})
if isinstance(obj, (list, tuple)):
return tuple(_deep_freeze_iip0024(x) for x in obj)
if isinstance(obj, (set, frozenset)):
return frozenset(_deep_freeze_iip0024(x) for x in obj)
if isinstance(obj, (str, int, float, bool)) or obj is None:
return obj
raise TypeError(f'Unsupported mutable type inside AtomicObservation: {type(obj).__name__} (IIP-0024; DEC-103)')
def _deep_to_jsonable_iip0024(obj: Any) -> Any:
if isinstance(obj, MappingProxyType) or isinstance(obj, dict):
return {str(k): _deep_to_jsonable_iip0024(obj[k]) for k in sorted(obj.keys(), key=str)}
if isinstance(obj, (list, tuple)):
return [_deep_to_jsonable_iip0024(x) for x in obj]
if isinstance(obj, frozenset):
return sorted(_deep_to_jsonable_iip0024(x) for x in obj)
return obj
class MCBScopeKey:
"""4-key Master Cell Bank provenance scope tuple (IIP-0024; DEC-103)."""
__slots__ = ('product_variant_id', 'construct_sha256', 'donor_seedline_id', 'mcb_id')
def __init__(self, product_variant_id: str, construct_sha256: str, donor_seedline_id: str, mcb_id: str) -> None:
for fname, val in (
('product_variant_id', product_variant_id),
('construct_sha256', construct_sha256),
('donor_seedline_id', donor_seedline_id),
('mcb_id', mcb_id),
):
if not isinstance(val, str) or not val.strip() or val != val.strip():
raise ValueError(f'MCBScopeKey.{fname} must be a canonical non-whitespace-padded string (IIP-0024; DEC-103)')
object.__setattr__(self, fname, val)
def __setattr__(self, name: str, value: Any) -> None:
raise TypeError('MCBScopeKey is immutable (IIP-0024; DEC-103)')
def __delattr__(self, name: str) -> None:
raise TypeError('MCBScopeKey is immutable (IIP-0024; DEC-103)')
def as_tuple(self) -> tuple[str, str, str, str]:
return (self.product_variant_id, self.construct_sha256, self.donor_seedline_id, self.mcb_id)
def __eq__(self, other: object) -> bool:
return isinstance(other, MCBScopeKey) and self.as_tuple() == other.as_tuple()
def __hash__(self) -> int:
return hash(('MCBScopeKey', self.as_tuple()))