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…

        and dxs_escape_upper95 <= 1e-8
    )
    dxs_hold_missing_explicit_se_or_counts = bool(
        has_all_3_dxs_endpoints and not dxs_explicit_se_or_cell_count_supplied
    )
    iec_vascular_support_failed = bool(
        ('obs_iec_vascular_support_viability_pct' in validated_stage0 and _lower95('obs_iec_vascular_support_viability_pct') < 85.0)
        or ('obs_iec_cd47_p10_molecules' in validated_stage0 and _lower95('obs_iec_cd47_p10_molecules') < 180000.0)
        or ('obs_iec_abo_ab_antigen_mfi_ratio' in validated_stage0 and _upper95('obs_iec_abo_ab_antigen_mfi_ratio') > 1.05)
        or ('obs_vascular_pericyte_ng2_pdgfrb_coverage_pct' in validated_stage0 and _lower95('obs_vascular_pericyte_ng2_pdgfrb_coverage_pct') < 70.0)
        or ('obs_iec_anastomosis_t50_h' in validated_stage0 and _upper95('obs_iec_anastomosis_t50_h') > 36.0)
    )
    effero_clearance_failed = bool(
        ('obs_apoptotic_effero_clearance_retention_pct_of_wt' in validated_stage0 and _lower95('obs_apoptotic_effero_clearance_retention_pct_of_wt') < 70.0)
        or ('obs_effero_clearance_pct' in validated_stage0 and _lower95('obs_effero_clearance_pct') < 80.0)
    )
    vp1_ie1_upper95 = _prop_or_pct_u95(
        'obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct',
        'obs_gate0v_day28_persistent_vp1_ie1_cells_scored',
        is_pct=True,
    )
    gate0v_viral_sanctuary_failed = bool(
        ('obs_gate0v_cvb_day14_log10_viral_reduction' in validated_stage0 and _lower95('obs_gate0v_cvb_day14_log10_viral_reduction') < 3.0)
        or ('obs_cvb4_10moi_72h_viral_titer_log10_pfu' in validated_stage0 and _upper95('obs_cvb4_10moi_72h_viral_titer_log10_pfu') > 2.0)
        or (
            'obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct' in validated_stage0
            and (
                validated_stage0['obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct'] > 0.0
                or vp1_ie1_upper95 > 0.05
            )
        )
    )
    assembled_cassette_chandler_ibmir_failed = bool(
        ('obs_assembled_cassette_chandler_loop_sc5b9_fold' in validated_stage0 and _upper95('obs_assembled_cassette_chandler_loop_sc5b9_fold') > 2.0)
        or ('obs_assembled_cassette_chandler_loop_platelet_retention_pct' in validated_stage0 and _lower95('obs_assembled_cassette_chandler_loop_platelet_retention_pct') < 70.0)
        or ('obs_c3b_cd55_cd59_complement_deposition_mfi_ratio' in validated_stage0 and _upper95('obs_c3b_cd55_cd59_complement_deposition_mfi_ratio') > 1.5)
    )
    slc18a1_ec_upper95 = _prop_or_pct_u95(
        'obs_assembled_cluster_slc18a1_enterochromaffin_pct',
        'obs_assembled_cluster_slc18a1_enterochromaffin_cells_scored',
        is_pct=True,
    )
    sox9_krt19_upper95 = _prop_or_pct_u95(
        'obs_ductal_sox9_krt19_double_pos_pct',
        'obs_ductal_sox9_krt19_double_pos_cells_scored',
        is_pct=True,
    )
    ki67_prog_upper95 = _prop_or_pct_u95(
        'obs_assembled_cluster_ki67_progenitor_pct',
        'obs_assembled_cluster_ki67_progenitor_cells_scored',
        is_pct=True,
    )
    assembled_cluster_lineage_or_identity_failed = bool(
        ('obs_assembled_cluster_slc18a1_enterochromaffin_pct' in validated_stage0 and slc18a1_ec_upper95 > 1.0)
        or ('obs_enterochromaffin_fev_tph1_pos_pct' in validated_stage0 and _upper95('obs_enterochromaffin_fev_tph1_pos_pct') > 1.0)
        or ('obs_sc_atac_ec_chromatin_spillover_pct' in validated_stage0 and _upper95('obs_sc_atac_ec_chromatin_spillover_pct') > 5.0)
        or ('obs_endocrine_synaptophysin_pos_purity_pct' in validated_stage0 and _lower95('obs_endocrine_synaptophysin_pos_purity_pct') < 95.0)
        or ('obs_ductal_sox9_krt19_double_pos_pct' in validated_stage0 and sox9_krt19_upper95 > 0.1)
        or ('obs_assembled_cluster_ins_gcg_polyhormonal_pct' in validated_stage0 and _upper95('obs_assembled_cluster_ins_gcg_polyhormonal_pct') > 2.0)
        or ('obs_assembled_cluster_ki67_progenitor_pct' in validated_stage0 and ki67_prog_upper95 > 0.5)
        or ('obs_post_stress_mafa_nkx61_beta_identity_retention_pct' in validated_stage0 and _lower95('obs_post_stress_mafa_nkx61_beta_identity_retention_pct') < 85.0)
        or ('obs_pouch_iapp_oligomer_a11_dot_blot_fold' in validated_stage0 and _upper95('obs_pouch_iapp_oligomer_a11_dot_blot_fold') > 1.5)
    )
    cd47_or_phagocytosis_failed = bool(
        observations.get('s3_arm1b_and_arm1x_below_15k_and_arm1c_splicing_ge_0p95') is True
        or _lower95('obs_cd47_hour0_molecules', 220000.0) < 50000.0
        or validated_stage0.get('obs_phagocytosis_index_pct', 3.0) > 10.0
        or _lower95('obs_cd47_cc2c6_over_b6h12_ratio', 0.95) < 0.90
        or validated_stage0.get('obs_complement_c3b_opsonized_phagocytosis_pct', 3.0) > 5.0
    )
    # Separate soft resting CD47 200k / 5% phagocytosis band from non-waivable mandatory post-stress/hypoxic/single-cell p10 and retention floors (R7-AUDIT-REF; DEC-061):
    resting_cd47_200k_or_5pct_phago_soft_cliff_failed = bool(
        ('obs_cd47_hour0_molecules' in validated_stage0 and 50000.0 <= _lower95('obs_cd47_hour0_molecules') < 200000.0)
        or ('obs_phagocytosis_index_pct' in validated_stage0 and 5.0 < validated_stage0['obs_phagocytosis_index_pct'] <= 10.0)
    )
    mandatory_hypoxic_or_p10_retention_cliff_failed = bool(
        (
            'obs_cd47_p10_single_cell_molecules' in validated_stage0
            and (
                validated_stage0['obs_cd47_p10_single_cell_molecules'] < 180000.0
                or _lower95('obs_cd47_p10_single_cell_molecules') < 180000.0
            )
        )
        or (
            'obs_hypoxic_72h_cd47_p10_single_cell_molecules' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_72h_cd47_p10_single_cell_molecules'] < 180000.0
                or _lower95('obs_hypoxic_72h_cd47_p10_single_cell_molecules') < 180000.0
            )
        )
        or (
            'obs_hypoxic_72h_hlae_p10_single_cell_molecules' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_72h_hlae_p10_single_cell_molecules'] < 15000.0
                or _lower95('obs_hypoxic_72h_hlae_p10_single_cell_molecules') < 15000.0
            )
        )
        or (
            'obs_hypoxic_72h_five_transgene_joint_above_threshold_fraction' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_72h_five_transgene_joint_above_threshold_fraction'] < 0.90
                or _lower95('obs_hypoxic_72h_five_transgene_joint_above_threshold_fraction') < 0.90
            )
        )
        or (
            'obs_hypoxic_72h_cd47_retention_molecules' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_72h_cd47_retention_molecules'] < 180000.0
                or _lower95('obs_hypoxic_72h_cd47_retention_molecules') < 180000.0
            )
        )
        or (
            'obs_hypoxic_72h_hlae_retention_molecules' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_72h_hlae_retention_molecules'] < 15000.0
                or _lower95('obs_hypoxic_72h_hlae_retention_molecules') < 15000.0
            )
        )
        or (
            'obs_hypoxic_15mmhg_f_isr_translation_ratio' in validated_stage0
            and (
                validated_stage0['obs_hypoxic_15mmhg_f_isr_translation_ratio'] < 0.50
                or _lower95('obs_hypoxic_15mmhg_f_isr_translation_ratio') < 0.50
            )
        )
    )
    cd47_or_phago_playbook_cliff_failed = bool(
        resting_cd47_200k_or_5pct_phago_soft_cliff_failed
        or mandatory_hypoxic_or_p10_retention_cliff_failed
    )
    unmitigated_cd47_or_hypoxic_retention_cliff_failed = bool(
        not dxs_joint_retention_verified
        and (
            mandatory_hypoxic_or_p10_retention_cliff_failed
            or (
                resting_cd47_200k_or_5pct_phago_soft_cliff_failed
                and observations.get('cd47_playbook_200k_and_5pct_phago_waiver_approved') is not True
            )
        )
    )
    # S3 is evaluated independently of S2 (no `not s2_promoted` masking; AUDIT-REF; DEC-047):
    s3_promoted = bool(
        dxs_joint_retention_verified
        and (cd47_or_phagocytosis_failed or cd47_or_phago_playbook_cliff_failed)
    )
    s2_promoted = bool(
        (
            observations.get('s2_arm1x_clears_15k_resting_hlae_and_cd47_c15g_noninferior') is True
            or s2_arm1b_failed
        )
        and not catastrophic_nkg2a_lysis_exceeds_arm1x
        and not kir_nkg2a_neg_nk_exceeded_raw
        and not (s10_nkg2c_triggered and not s10_coupon_cleared)
        and not s3_promoted
    )
    lot_ocr_ratio = validated_stage0.get('obs_lot_ocr_ratio', 1.0)
    lot_ocr_upper95 = _upper95('obs_lot_ocr_ratio', lot_ocr_ratio)
    lot_ocr_exceeds_max_1p50x_ceiling = bool('obs_lot_ocr_ratio' in validated_stage0 and lot_ocr_upper95 > 1.50)
    s4_promoted = bool(
        observations.get('s4_rnls_wt_clears_gsis_shutoff_and_ocr_and_er_gate') is True
        or lot_ocr_upper95 > 1.097
    )
    s5_promoted = bool(
        observations.get('s5_fasl_delta_tunel_gt_5pp') is True
        or ('obs_safasl_delta_tunel_pp' in validated_stage0 and _upper95('obs_safasl_delta_tunel_pp') > 5.0)
        or ('obs_safasl_zb4_anti_fas_rescue_pp' in validated_stage0 and _upper95('obs_safasl_zb4_anti_fas_rescue_pp') > 5.0)
        or ('obs_safasl_treg_viable_retention_pct_of_thbd' in validated_stage0 and _lower95('obs_safasl_treg_viable_retention_pct_of_thbd') < 85.0)
        or ('obs_safasl_neutrophil_chemotaxis_index' in validated_stage0 and _upper95('obs_safasl_neutrophil_chemotaxis_index') > 1.5)
        or ('obs_sa_fasl_microgel_nk_degranulation_cd107a_pct' in validated_stage0 and _upper95('obs_sa_fasl_microgel_nk_degranulation_cd107a_pct') > 5.0)
    )
    exogenous_b2m_class1_rescue_failed = bool(
        ('obs_exogenous_b2m_w632_surface_fold_isotype' in validated_stage0 and _upper95('obs_exogenous_b2m_w632_surface_fold_isotype') > 1.2)
        or ('obs_exogenous_b2m_t1d_ctl_lysis_pct' in validated_stage0 and _upper95('obs_exogenous_b2m_t1d_ctl_lysis_pct') > 5.0)
    )
    s6_promoted = bool(
        ('obs_gate0e_chop_log2fc' in validated_stage0 and _upper95('obs_gate0e_chop_log2fc', 0.4) > math.log2(1.5))
        or chop_fold > 1.5
        or (has_chop_obs and chop_upper95 > 1.5)
        or _lower95('obs_gate0e_gsis_retention_ratio', 0.92) < 0.85
        or hc10_fold > 1.5
        or ('obs_hc10_surface_fold_wt' in validated_stage0 and _upper95('obs_hc10_surface_fold_wt') > 1.5)
        or ('obs_gate0e_hc10_surface_mfi_ratio' in validated_stage0 and _upper95('obs_gate0e_hc10_surface_mfi_ratio') > 1.5)
        or exogenous_b2m_class1_rescue_failed
    )
    b_prime_sct_cd8_upper95 = (
        validated_stage0['obs_b_prime_sct_cd8_lysis_pct'] + 1.645 * validated_stage0_se.get('obs_b_prime_sct_cd8_lysis_se', 0.0)
        if 'obs_b_prime_sct_cd8_lysis_pct' in validated_stage0
        else 0.0
    )
    b_prime_sct_direct_cd8_failed = bool(
        (
            'obs_b_prime_sct_cd8_lysis_pct' in validated_stage0
            and (
                validated_stage0['obs_b_prime_sct_cd8_lysis_pct'] > 5.0
                or b_prime_sct_cd8_upper95 > 10.0
                or (
                    'obs_plan_a_star_cd8_lysis_pct' in validated_stage0
                    and (validated_stage0['obs_b_prime_sct_cd8_lysis_pct'] - validated_stage0['obs_plan_a_star_cd8_lysis_pct']) > 5.0
                )
            )
        )
        or (
            'obs_b_prime_sct_21d_primed_cd8_elispot_sfu_per_1e6' in validated_stage0
            and _upper95('obs_b_prime_sct_21d_primed_cd8_elispot_sfu_per_1e6') > 50.0
        )
    )
    s7_allo_triggered = bool(
        _upper95('obs_gate0b_hlac_cd8_elispot_sfw', 10.0) > 20.0
        or _upper95('obs_foreign_hlac_cd8_lysis_pct', 0.0) > 10.0
        or (
            'obs_foreign_hlac_cd8_lysis_pct' in validated_stage0
            and 'obs_plan_a_star_cd8_lysis_pct' in validated_stage0
            and (validated_stage0['obs_foreign_hlac_cd8_lysis_pct'] - validated_stage0['obs_plan_a_star_cd8_lysis_pct']) > 5.0
        )
        or b_prime_sct_direct_cd8_failed
    )
    sct_density_explicitly_qualified = bool(
        'obs_gate0b_hlac_sct_molecules_per_cell' in validated_stage0
        and _lower95('obs_gate0b_hlac_sct_molecules_per_cell') >= 15000.0
    )
    sct_cd8_mlc_explicitly_cleared = bool(
        not b_prime_sct_direct_cd8_failed
        and (
            observations.get('b_prime_sct_recipient_cd8_mlc_cleared') is True
            or ('obs_b_prime_sct_cd8_lysis_pct' in validated_stage0 and validated_stage0['obs_b_prime_sct_cd8_lysis_pct'] <= 5.0 and b_prime_sct_cd8_upper95 <= 10.0)
        )
    )
    _strict_s7_mlc_and_se_required = bool(
        product_def is not None
        or observations.get('b_prime_sct_recipient_cd8_mlc_cleared') is False
        or observations.get('require_full_iip0026_molecular_provenance_panel') is True
    )
    _sct_density_se_explicit = bool(
        se_provenance_by_mean.get('obs_gate0b_hlac_sct_molecules_per_cell') == 'EXPLICIT_SE_SUPPLIED'
    )
    _has_explicit_s7_hlac_obs = bool(
        any(
            _sk in validated_stage0
            for _sk in (
                'obs_gate0b_hlac_cd8_elispot_sfw',
                'obs_foreign_hlac_cd8_lysis_pct',
                'obs_gate0b_hlac_sct_molecules_per_cell',
                'obs_b_prime_sct_cd8_lysis_pct',
            )
        )
        or observations.get('b_prime_sct_recipient_cd8_mlc_cleared') is not None
    )
    s7_promoted = bool(
        s7_allo_triggered
        and sct_density_explicitly_qualified