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…

        _rk in validated_stage0
        for _rk in (
            'obs_readout2_perifusion_gsis_si',
            'obs_readout2_first_phase_peak_to_basal_ratio',
            'obs_readout2_first_phase_time_to_peak_min',
            'obs_readout2_stepdown_shutoff_t50_min',
        )
    ):
        if (
            ('obs_readout2_perifusion_gsis_si' in validated_stage0 and _lower95('obs_readout2_perifusion_gsis_si') < 3.0)
            or ('obs_readout2_first_phase_peak_to_basal_ratio' in validated_stage0 and _lower95('obs_readout2_first_phase_peak_to_basal_ratio') < 4.5)
            or ('obs_readout2_first_phase_time_to_peak_min' in validated_stage0 and _upper95('obs_readout2_first_phase_time_to_peak_min') > 8.0)
            or ('obs_readout2_stepdown_shutoff_t50_min' in validated_stage0 and _upper95('obs_readout2_stepdown_shutoff_t50_min') > 3.0)
            or (
                'obs_readout2_stepdown_shutoff_t50_min' in validated_stage0
                and 'obs_gate0m_shutoff_t90_min' in validated_stage0
                and validated_stage0['obs_readout2_stepdown_shutoff_t50_min'] > validated_stage0['obs_gate0m_shutoff_t90_min']
            )
        ):
            iip0024_hold_status = 'HOLD_READOUT2_PERIFUSION_KINETICS_OR_SHUTOFF_MONOTONICITY_FAILED'
    if iip0024_hold_status is None and (
        'obs_exact_product_net_cd16_adcc_lysis_pct' in validated_stage0
        or 'obs_cd16_adcc_positive_control_lysis_pct' in validated_stage0
        or observations.get('cd16_adcc_igg_depletion_paired_control_verified') is not None
    ):
        _has_any_net_adcc = (
            'obs_exact_product_net_cd16_adcc_lysis_pct' in validated_stage0
            or 'obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_pct' in validated_stage0
        )
        if (
            observations.get('cd16_adcc_igg_depletion_paired_control_verified') is not True
            or not _has_any_net_adcc
            or 'obs_cd16_adcc_positive_control_lysis_pct' not in validated_stage0
            or (
                'obs_exact_product_net_cd16_adcc_lysis_pct' in validated_stage0
                and _upper95('obs_exact_product_net_cd16_adcc_lysis_pct') > 5.0
            )
            or (
                'obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_pct' in validated_stage0
                and _upper95('obs_fcr_cd16_net_adcc_lysis_vs_igg_depleted_pct') > 5.0
            )
            or _lower95('obs_cd16_adcc_positive_control_lysis_pct') < 25.0
        ):
            iip0024_hold_status = 'HOLD_PAIRED_IGG_DEPLETED_CD16_ADCC_GATE_FAILED_OR_UNVERIFIED'
    if iip0024_hold_status is None and 'obs_p05_total_loaded_catalase_protein_mg' in validated_stage0 and not _is_design_z_product:
        _m_cat = validated_stage0['obs_p05_total_loaded_catalase_protein_mg']
        if _m_cat <= 0.0:
            iip0024_hold_status = 'HOLD_P05_TOTAL_LOADED_CATALASE_MASS_NONPOSITIVE'
        elif 'obs_p05_catalase_endotoxin_eu_per_mg' in validated_stage0:
            _coupled_eu_cap = min(0.10, 0.50 / _m_cat)
            if _upper95_student_t('obs_p05_catalase_endotoxin_eu_per_mg') > _coupled_eu_cap:
                iip0024_hold_status = 'HOLD_P05_MASS_COUPLED_CATALASE_ENDOTOXIN_CAP_EXCEEDED'
            elif 'obs_p05_total_implant_catalase_endotoxin_eu' in validated_stage0:
                if _upper95_student_t('obs_p05_total_implant_catalase_endotoxin_eu') > 0.50:
                    iip0024_hold_status = 'HOLD_P05_TOTAL_IMPLANT_CATALASE_ENDOTOXIN_GT_0P50EU'
                else:
                    _exp_tot_eu = _m_cat * validated_stage0['obs_p05_catalase_endotoxin_eu_per_mg']
                    if abs(validated_stage0['obs_p05_total_implant_catalase_endotoxin_eu'] - _exp_tot_eu) > max(0.015, 0.05 * _exp_tot_eu):
                        iip0024_hold_status = 'HOLD_P05_COUPLED_TOTAL_ENDOTOXIN_MASS_PRODUCT_INCONSISTENT'
    if iip0024_hold_status is None and any(
        _sk in validated_stage0
        for _sk in (
            'obs_gate0s_shedding_ddpcr_events_k',
            'obs_gate0s_shedding_ddpcr_trials_n',
            'obs_gate0s_shedding_viable_events_k',
            'obs_gate0s_shedding_viable_trials_n',
        )
    ):
        if not all(
            _sk in validated_stage0
            for _sk in (
                'obs_gate0s_shedding_ddpcr_events_k',
                'obs_gate0s_shedding_ddpcr_trials_n',
                'obs_gate0s_shedding_viable_events_k',
                'obs_gate0s_shedding_viable_trials_n',
            )
        ):
            iip0024_hold_status = 'HOLD_GATE0S_DUAL_SHEDDING_PANEL_INCOMPLETE'
        else:
            _k_dd_f = validated_stage0['obs_gate0s_shedding_ddpcr_events_k']
            _n_dd_f = validated_stage0['obs_gate0s_shedding_ddpcr_trials_n']
            _k_vi_f = validated_stage0['obs_gate0s_shedding_viable_events_k']
            _n_vi_f = validated_stage0['obs_gate0s_shedding_viable_trials_n']
            if any(abs(_vf - round(_vf)) > 1e-9 for _vf in (_k_dd_f, _n_dd_f, _k_vi_f, _n_vi_f)):
                non_integer_scored_cell_or_trial_denominator = True
                iip0024_hold_status = 'HOLD_NON_INTEGER_SCORED_CELL_OR_TRIAL_DENOMINATOR'
            else:
                _spec_map_s0 = observations.get('specimen_or_clone_ids')
                if (
                    isinstance(_spec_map_s0, dict)
                    and 'obs_gate0s_shedding_ddpcr_events_k' in _spec_map_s0
                    and 'obs_gate0s_shedding_viable_events_k' in _spec_map_s0
                    and str(_spec_map_s0['obs_gate0s_shedding_ddpcr_events_k']).strip()
                    == str(_spec_map_s0['obs_gate0s_shedding_viable_events_k']).strip()
                ):
                    iip0024_hold_status = 'HOLD_GATE0S_DUAL_SHEDDING_REQUIRES_INDEPENDENT_SPECIMEN_UNITS'
                else:
                    _n_dd = int(round(_n_dd_f))
                    _n_vi = int(round(_n_vi_f))
                    if (
                        _n_dd < 2995731
                        or _n_vi < 2995731
                        or clopper_pearson_upper95_independent(0, _n_dd) >= 1e-6
                        or clopper_pearson_upper95_independent(0, _n_vi) >= 1e-6
                    ):
                        iip0024_hold_status = 'HOLD_GATE0S_DUAL_SHEDDING_TRIALS_BELOW_2995731_BINOMIAL_1E6_FLOOR'
    if iip0024_hold_status is None and (
        any(_ik in validated_stage0 for _ik in ('obs_iapp_3metric_thioflavin_s_area_pct', 'obs_iapp_3metric_soluble_oligomer_fold', 'obs_iapp_3metric_insoluble_fibril_fold'))
        or (
            observations.get('iapp_age_matched_reference_above_loq_verified') is not None
            and not any(
                _ik28 in validated_stage0
                for _ik28 in (
                    'obs_iapp_72h_immunocapture_oligomer_elisa_fold',
                    'obs_iapp_72h_colocalized_fibril_area_pct',
                    'obs_iapp_d28_immunocapture_oligomer_elisa_fold',
                    'obs_iapp_d28_colocalized_fibril_area_pct',
                    'obs_iapp_d84_immunocapture_oligomer_elisa_fold',
                    'obs_iapp_d84_colocalized_fibril_area_pct',
                )
            )
        )
    ):
        if (
            observations.get('iapp_age_matched_reference_above_loq_verified') is not True
            or 'obs_iapp_3metric_thioflavin_s_area_pct' not in validated_stage0
            or 'obs_iapp_3metric_soluble_oligomer_fold' not in validated_stage0
            or 'obs_iapp_3metric_insoluble_fibril_fold' not in validated_stage0
            or _upper95('obs_iapp_3metric_thioflavin_s_area_pct') > 1.0
            or _upper95('obs_iapp_3metric_soluble_oligomer_fold') > 1.5
            or _upper95('obs_iapp_3metric_insoluble_fibril_fold') > 1.5
        ):
            iip0024_hold_status = 'HOLD_IAPP_3METRIC_PANEL_OR_REFERENCE_LOQ_FAILED'
    if iip0024_hold_status is None:
        for _epi_flag_k, _epi_hold_code in (
            ('mcb_imprinting_ic1_ic2_igdmr_conjunctive_cleared', 'HOLD_MCB_CONJUNCTIVE_IMPRINTING_DMR_NOT_CLEARED'),
            ('stage7_lot_imprinting_ic1_ic2_igdmr_conjunctive_cleared', 'HOLD_STAGE7_LOT_CONJUNCTIVE_IMPRINTING_DMR_NOT_CLEARED'),
            ('mcb_and_lot_xci_46xx_3axis_cleared_or_46xy', 'HOLD_46XX_XCI_3AXIS_NOT_CLEARED'),
            ('mcb_and_lot_mtdna_1000x_numt_filtered_cleared', 'HOLD_SCOPED_1000X_NUMT_MTDNA_NOT_CLEARED'),
        ):
            if observations.get(_epi_flag_k) is False or (_req_iip0024_full and observations.get(_epi_flag_k) is not True):
                iip0024_hold_status = _epi_hold_code
                break
    if iip0024_hold_status is None and _req_iip0024_full:
        _req_24_keys = (
            'obs_mcb_donor_pairwise_ibd_pi_hat',
            'obs_mcb_1q32_mdm4_cnv_ratio',
            'obs_mcb_1q32_mdm4_single_cell_mosaic_fraction',
            'obs_mcb_1q32_mdm4_single_cell_mosaic_cells_scored',
            'obs_1q32_mdm4_cnv_ratio',
            'obs_1q32_mdm4_single_cell_mosaic_fraction',
            'obs_1q32_mdm4_single_cell_mosaic_cells_scored',
            'obs_readout2_perifusion_gsis_si',
            'obs_readout2_first_phase_peak_to_basal_ratio',
            'obs_readout2_first_phase_time_to_peak_min',
            'obs_readout2_stepdown_shutoff_t50_min',
            'obs_exact_product_net_cd16_adcc_lysis_pct',
            'obs_cd16_adcc_positive_control_lysis_pct',
            'obs_gate0s_shedding_ddpcr_events_k',
            'obs_gate0s_shedding_ddpcr_trials_n',
            'obs_gate0s_shedding_viable_events_k',
            'obs_gate0s_shedding_viable_trials_n',
            'obs_iapp_3metric_thioflavin_s_area_pct',
            'obs_iapp_3metric_soluble_oligomer_fold',
            'obs_iapp_3metric_insoluble_fibril_fold',
        )
        if not all(_k in validated_stage0 for _k in _req_24_keys) or (not _is_design_z_product and 'obs_p05_total_loaded_catalase_protein_mg' not in validated_stage0):
            iip0024_hold_status = 'HOLD_IIP0024_MANDATORY_ATOMIC_PROVENANCE_OR_BANK_PANEL_INCOMPLETE'
    iip0024_eval_summary: dict[str, object] | None = None
    if _iip0024_active:
        iip0024_eval_summary = {
            'gate_pass': iip0024_hold_status is None,
            'hold_status': iip0024_hold_status,
            'status': iip0024_hold_status if iip0024_hold_status is not None else 'CLEARED_IIP0024_STAGE0_ATOMIC_PROVENANCE_AND_BANK_GUARDRAILS',
            'student_t_critical_multiplier_used': round(crit_95_mult, 8),
        }

    # Stage-0 Hurdle-4 two-timepoint human P04040 catalase envelope hold, exact z=70.0 um gel-interface H2O2, separated Day-30/Day-90 Gate 0S retrieval, and zero-primate Contrasts B1, B2, B3 (IIP-0025; DEC-104):
    _b1_arm = observations.get('contrast_b1_geometry_arm')
    if isinstance(_b1_arm, str):
        _b1_arm = _b1_arm.strip()
    _b2_arm = observations.get('contrast_b2_perfusion_and_retrieval_arm')
    if isinstance(_b2_arm, str):
        _b2_arm = _b2_arm.strip()
    _b3_arm = observations.get('contrast_b3_donor_iec_arm')
    if isinstance(_b3_arm, str):
        _b3_arm = _b3_arm.strip()

    _iip0025_p05_new_keys = (
        'obs_p05_precure_active_catalase_input_u_333cm2',
        'obs_p05_postcure_t0_active_catalase_iu_333cm2',
        'obs_p05_cure_immobilization_yield_pct',
        'obs_p05_336h_catalase_retention_pct',
        'obs_p05_z70_gel_interface_h2o2_max_uM',
    )
    _iip0025_p05_all_req_keys = (
        *_iip0025_p05_new_keys,
        'obs_p05_day7_catalase_retention_pct',
        'obs_p05_day7_shed_catalase_mass_pct',
        'obs_p05_336h_retained_catalase_iu_333cm2',
        'obs_p05_total_loaded_catalase_protein_mg',
        'obs_p05_catalase_endotoxin_eu_per_mg',
        'obs_p05_total_implant_catalase_endotoxin_eu',
    )
    _iip0025_b1_keys = (
        'obs_contrast_b1_paired_min_face_po2_gain_mmhg',
        'obs_contrast_b1_80um_worst_face_po2_mmhg',
        'obs_contrast_b1_80um_perifusion_gsis_si',
    )
    _iip0025_b2_keys = (
        'obs_contrast_b2_human_exvivo_viable_window_h',
        'obs_contrast_b2_omental_vs_suprafascial_po2_gain_mmhg',
        'obs_contrast_b2_porcine_day90_en_bloc_recovery_fraction',
    )
    _iip0025_b3_keys = (
        'obs_contrast_b3_iec_omitted_surface_po2_mmhg',
        'obs_contrast_b3_iec_omitted_outer_kperf_s_inv',
        'obs_contrast_b3_iec_omitted_perifusion_gsis_si',
    )
    _iip0025_p05_env_active = bool(
        not _is_design_z_product
        and (
            _req_iip0025_full
            or observations.get('p05_two_timepoint_same_lot_envelope_verified') is not None
            or any(_k in validated_stage0 for _k in _iip0025_p05_new_keys)
        )
    )
    _iip0025_b1_active = bool(
        _b1_arm is not None
        or any(_k in validated_stage0 for _k in _iip0025_b1_keys)
    )
    _iip0025_b2_active = bool(
        _b2_arm is not None
        or observations.get('contrast_b2_route_qualification_distinct_from_portfolio_credit_verified') is not None
        or any(_k in validated_stage0 for _k in _iip0025_b2_keys)
    )
    _iip0025_b3_active = bool(
        _b3_arm is not None
        or observations.get('contrast_b3_zero_primate_host_ingrowth_verified') is not None
        or any(_k in validated_stage0 for _k in _iip0025_b3_keys)
    )
    _iip0025_day30_90_active = bool(
        'obs_gate0s_day30_en_bloc_recovery_fraction' in validated_stage0
        or 'obs_gate0s_day90_en_bloc_recovery_fraction' in validated_stage0
    )

    iip0025_p05_env_status: str | None = None
    iip0025_b1_status: str | None = None
    iip0025_b2_status: str | None = None
    iip0025_b3_status: str | None = None