OpenIslet

scripts/wetlab_contract.py

One measurement contract for Python ingestion and generated MCP metadata.

script Release v0.8.0 gen-eb955f8266035aba 913 KB · 68 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/wetlab_contract.py · SHA-256: 6bb3955530f8f05d…

            se_provenance_by_mean.get('obs_challenger_host_exon_splice_retention_ratio') == 'EXPLICIT_SE_SUPPLIED'
        )
        _host_ret_tost_ok = bool(
            _host_ret_mean is not None
            and _host_ret_se_supplied
            and (_host_ret_mean - _tost_z95 * _host_ret_se) >= 0.80
            and (_host_ret_mean + _tost_z95 * _host_ret_se) <= 1.25
        )
        _orient_mismatch = bool(
            (
                knockin_splice_challenger_arm.startswith('S3_L4_CONVERGENT_')
                and knockin_locus4_orientation != 'CONVERGENT_PLUS'
            )
            or (
                knockin_splice_challenger_arm in (
                    'S3_L4_WINA_ONLY_3457',
                    'S3_L4_EEF230C_ONLY_3457',
                    'S3_L4_SPLICE_230C_3457',
                    'S3_L4_CODIR_7NT_230C_3457',
                )
                and knockin_locus4_orientation == 'CONVERGENT_PLUS'
            )
        )
        if (
            knockin_splice_challenger_arm in UNSHIELDED_REFERENCE_SPLICE_CHALLENGER_ARMS
            or observations.get('obs_challenger_pam_seed_shield_coconversion_verified') is False
            or (_is_active_chall and observations.get('obs_challenger_pam_seed_shield_coconversion_verified') is not True)
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_UNSHIELDED_OR_PAM_SEED_COCONVERSION_UNVERIFIED'
        elif _orient_mismatch:
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_LOCUS4_ORIENTATION_METADATA_MISMATCH'
        elif (
            observations.get('obs_challenger_ivt_rna_recovery_standard_verified') is False
            or (_is_active_chall and observations.get('obs_challenger_ivt_rna_recovery_standard_verified') is not True)
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_PREEXTRACTION_IVT_RNA_RECOVERY_STANDARD_UNVERIFIED'
        elif (
            observations.get('obs_challenger_host_isoforms_above_loq_verified') is False
            or (_is_active_chall and observations.get('obs_challenger_host_isoforms_above_loq_verified') is not True)
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_HOST_ISOFORM_BELOW_LOQ_OR_UNVERIFIED'
        elif (
            observations.get('obs_challenger_sv40pa_and_host_3prime_cleavage_checked') is False
            or (_is_active_chall and observations.get('obs_challenger_sv40pa_and_host_3prime_cleavage_checked') is not True)
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_SV40PA_AND_HOST_3PRIME_CLEAVAGE_UNCHECKED'
        elif (
            'obs_challenger_aberrant_splice_umi_count_k' in validated_stage0
            and validated_stage0['obs_challenger_aberrant_splice_umi_count_k'] > 0.0
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_ABERRANT_CHIMERIC_UMI_DETECTED'
        elif (
            ('obs_challenger_umi_molecules_profiled' in validated_stage0 or _is_active_chall)
            and (
                'obs_challenger_umi_molecules_profiled' not in validated_stage0
                or 'obs_challenger_ivt_relative_recovery_eta' not in validated_stage0
                or 'obs_challenger_aberrant_splice_umi_count_k' not in validated_stage0
                or challenger_umi_eff < 3689.0
            )
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_EFFECTIVE_UMI_BELOW_3689_RECOVERY_ADJUSTED_MINIMUM'
        elif ('obs_challenger_host_exon_splice_retention_ratio' in validated_stage0 or _is_active_chall) and not _host_ret_tost_ok:
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_HOST_EXON_RETENTION_OUTSIDE_90PCT_TOST_0P80_1P25'
        elif (
            ('obs_challenger_dsrna_j2_or_isg_fold_wt' in validated_stage0 or _is_active_chall)
            and (
                'obs_challenger_dsrna_j2_or_isg_fold_wt' not in validated_stage0
                or _upper95('obs_challenger_dsrna_j2_or_isg_fold_wt') > 1.5
            )
        ):
            challenger_hold_status = 'HOLD_CHALLENGER_SPLICE_CONVERGENT_DSRNA_J2_OR_ISG_EXCEEDS_1P5X_CEILING'

    # Locus 3 Mode-B Multi-miR(IL1R1+FAS) 6-arm challenger qualification gate (IIP-0018; DEC-096):
    _l3_multimir_mean_keys = (
        'obs_l3_multimir_spliced_fraction',
        'obs_l3_multimir_5prime_seed_fidelity_pct',
        'obs_l3_multimir_ago2_mir375_retention_pct',
        'obs_l3_multimir_shield_protein_retention_pct',
        'obs_l3_multimir_min_receptor_knockdown_pct',
        'obs_l3_multimir_matched_gsis_output_retention_pct',
    )
    _l3_multimir_gate_active = bool(
        knockin_splice_challenger_arm in LOCUS3_MULTIMIR_MODEB_ALL_ARMS
        or any(
            observations.get(_lmk) is not None
            for _lmk in (
                'l3_multimir_pre_aav6_2x2_transient_kd_falsifier_cleared',
                'l3_multimir_low_ifn_and_resting_shield_retention_verified',
                'l3_multimir_arm6_c341s_hlac_and_dq2_dq8_peptide_screen_cleared',
            )
        )
        or any(_lmk in validated_stage0 for _lmk in _l3_multimir_mean_keys)
    )
    l3_multimir_gate_status: str | None = None
    l3_multimir_hold_status: str | None = None
    l3_multimir_eval_summary: dict[str, object] | None = None
    if _l3_multimir_gate_active:
        _l3_is_arm6 = bool(knockin_splice_challenger_arm == 'ARM6_L3_V2_INTRON_DUPLEX_IL1R1_FAS_C341S_TCA_4398')
        _l3_is_design_b = bool(
            product_def is not None
            and str(product_def.get('family', 'A')).upper().startswith('B')
        )
        _l3_quant_complete = all(
            _lmk in validated_stage0 and se_provenance_by_mean.get(_lmk) == 'EXPLICIT_SE_SUPPLIED'
            for _lmk in _l3_multimir_mean_keys
        )
        if knockin_splice_challenger_arm in LOCUS3_MULTIMIR_MODEB_CONTROL_ARMS:
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_FACTORIAL_CONTROL_ARM_NOT_RELEASE_CHALLENGER'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif knockin_splice_challenger_arm not in LOCUS3_MULTIMIR_MODEB_DUPLEX_CHALLENGER_ARMS:
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_DUPLEX_CHALLENGER_ARM_ID_REQUIRED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif observations.get('l3_multimir_pre_aav6_2x2_transient_kd_falsifier_cleared') is not True:
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_PRE_AAV6_2X2_TRANSIENT_FALSIFIER_UNVERIFIED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif observations.get('l3_multimir_low_ifn_and_resting_shield_retention_verified') is not True:
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_RESTING_OR_LOW_IFN_SHIELD_RETENTION_UNVERIFIED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif (
            (_l3_is_arm6 or observations.get('l3_multimir_arm6_c341s_hlac_and_dq2_dq8_peptide_screen_cleared') is False)
            and observations.get('l3_multimir_arm6_c341s_hlac_and_dq2_dq8_peptide_screen_cleared') is not True
        ):
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_ARM6_C341S_HLAC_OR_DQ2_DQ8_PEPTIDE_SCREEN_UNVERIFIED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif not _l3_quant_complete:
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_INCOMPLETE_OR_DEFAULT_SE_QUALIFICATION_PANEL'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif (
            _lower95('obs_l3_multimir_spliced_fraction') < 0.85
            or _lower95('obs_l3_multimir_5prime_seed_fidelity_pct') < 85.0
            or _lower95('obs_l3_multimir_ago2_mir375_retention_pct') < 90.0
        ):
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_SPLICING_DROSHA_SEED_OR_AGO2_MIR375_FAILED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif (
            _lower95('obs_l3_multimir_shield_protein_retention_pct') < 85.0
            or _lower95('obs_l3_multimir_min_receptor_knockdown_pct') < 70.0
            or _lower95('obs_l3_multimir_matched_gsis_output_retention_pct') < 85.0
        ):
            l3_multimir_gate_status = 'HOLD_L3_MULTIMIR_RECEPTOR_KD_SHIELD_RETENTION_OR_MATCHED_GSIS_FAILED'
            l3_multimir_hold_status = l3_multimir_gate_status
        elif challenger_hold_status is not None:
            l3_multimir_gate_status = challenger_hold_status
            l3_multimir_hold_status = challenger_hold_status
        else:
            l3_multimir_gate_status = 'CLEARED_L3_MULTIMIR_MODEB_STAGE0_CHALLENGER_GATE'
        l3_multimir_eval_summary = {
            'gate_pass': l3_multimir_hold_status is None,
            'status': l3_multimir_gate_status,
            'challenger_arm': knockin_splice_challenger_arm,
            'design_b_retained_hlac_background': _l3_is_design_b,
            'arm6_c341s_peptide_screen_required': _l3_is_arm6,
        }

    # Stage-0 explicit-3D transport qualification gates for Rule S6 lateral spacing / dose-matched 80 um sizing, Readout 5 (Gate P05) wet-sieved microbeads + co-cast catalase barrier films, and Design Z two-stage empty-lumen + loaded closed-state confirmation (IIP-0019; DEC-097; product-bound Gate P05 fix IIP-0025; DEC-104):
    _is_design_z_product = bool(
        product_def is not None
        and str(product_def.get('product_variant_id', '')) == 'ISLET1_Z_X_MOL_140UM_ZERO_CAO2'
    )
    _req_iip0025_full = observations.get('require_full_iip0025_hurdle4_transport_and_challenger_panel') is True
    _s6_arm_val = observations.get('s6_cluster_size_arm')
    if isinstance(_s6_arm_val, str):
        _s6_arm_val = _s6_arm_val.strip()
    _p05_geom_val = observations.get('p05_barrier_slab_geometry_mode')
    if isinstance(_p05_geom_val, str):
        _p05_geom_val = _p05_geom_val.strip()
    _dz_arm_val = observations.get('design_z_divider_arm')
    if isinstance(_dz_arm_val, str):
        _dz_arm_val = _dz_arm_val.strip()

    _s6_mean_keys = (
        'obs_s6_p10_nearest_neighbor_edge_gap_um',
        'obs_s6_cluster_diam_p90_um',
    )
    _s6_divider_mean_keys = (
        'obs_s6_divider_14d_hydrated_po2_retention_pct',
        'obs_s6_hydrogel_shear_modulus_gprime_pa',
    )
    _p05_mean_keys = (
        'obs_p05_microbead_volume_d99_um',
        'obs_p05_catalase_barrier_film_um',
        'obs_p05_islet_plane_h2o2_max_uM',
        'obs_p05_day7_catalase_retention_pct',
        'obs_p05_336h_retained_catalase_iu_333cm2',
    )
    _dz_empty_mean_keys = (
        'obs_design_z_empty_lumen_5site_min_po2_mmhg',
        'obs_design_z_vessel_standoff_p90_um',
    )
    _dz_loaded_mean_keys = (
        'obs_design_z_loaded_surface_po2_mmhg',
        'obs_design_z_loaded_core_po2_mmhg',
        'obs_design_z_loaded_perifusion_gsis_si',
    )

    _divider_qc_active = bool(
        _dz_arm_val == 'EXPLORATORY_18PCT_DIVIDER_140UM'
        or observations.get('s6_divider_iso10993_leachables_cleared') is not None
        or any(_mk in validated_stage0 for _mk in _s6_divider_mean_keys)
    )
    _divider_qc_cleared = bool(
        observations.get('s6_divider_iso10993_leachables_cleared') is True
        and all(
            _mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
            for _mk in _s6_divider_mean_keys
        )
        and _lower95('obs_s6_divider_14d_hydrated_po2_retention_pct') >= 90.0
        and _upper95('obs_s6_hydrogel_shear_modulus_gprime_pa') <= 1000.0
    )

    _s6_active = bool(
        _s6_arm_val is not None
        or observations.get('s6_dose_matched_1500_ieq_verified') is not None
        or any(_mk in validated_stage0 for _mk in _s6_mean_keys)
        or (_divider_qc_active and _dz_arm_val is None)
    )
    _p05_active = bool(
        _p05_geom_val is not None
        or observations.get('p05_full_336h_coupled_o2_h2o2_ca_ph_qualified') is not None
        or any(_mk in validated_stage0 for _mk in _p05_mean_keys)
    )
    _dz_active = bool(
        (product_def is None or _is_design_z_product)
        and (
            _dz_arm_val is not None
            or observations.get('design_z_empty_lumen_14d_persistence_verified') is not None
            or observations.get('design_z_loaded_closed_state_confirmed') is not None
            or any(_mk in validated_stage0 for _mk in (*_dz_empty_mean_keys, *_dz_loaded_mean_keys))
        )
    )

    iip0019_s6_status: str | None = None
    iip0019_p05_status: str | None = None
    iip0019_dz_status: str | None = None
    iip0019_transport_hold_status: str | None = None

    if _s6_active:
        _s6_quant_ok = all(
            _mk in validated_stage0 and se_provenance_by_mean.get(_mk) == 'EXPLICIT_SE_SUPPLIED'
            for _mk in _s6_mean_keys
        )
        if _s6_arm_val is None or not _s6_quant_ok:
            iip0019_s6_status = 'HOLD_S6_INCOMPLETE_OR_DEFAULT_SE_LATERAL_SPACING_PANEL'
        elif _s6_arm_val == 'DERATED_80UM_768IEQ' or observations.get('s6_dose_matched_1500_ieq_verified') is not True:
            iip0019_s6_status = 'HOLD_S6_DOSE_DERATED_80UM_768IEQ_NOT_SINGLE_POUCH_EQUIVALENT_REQUIRES_DOSE_MATCHED_1500IEQ_OR_AREA_EXPANSION'
        elif _divider_qc_active and not _divider_qc_cleared:
            iip0019_s6_status = 'HOLD_S6_EXPLORATORY_DIVIDER_HYDRATED_PO2_LEACHABLES_OR_MODULUS_QC_FAILED'
        else:
            _diam_cap = 80.0 if _s6_arm_val == 'DOSE_MATCHED_80UM_1500IEQ' else 100.0
            _gap_floor = 55.0 if _s6_arm_val == 'DOSE_MATCHED_80UM_1500IEQ' else 85.0