OpenIslet

scripts/run_layer2_perturbation_and_regulatory_plane.py

Layer 2: Single-Cell Perturbation & Regulatory Sequence Plane (v0.8.0)

script Release v0.8.0 gen-eb955f8266035aba 1.13 MB · 71 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/run_layer2_perturbation_and_regulatory_plane.py · SHA-256: 3220e68f97203dbc…

                        "CpG-core candidate (part_name CBX3_A2UCOE_455bp_exact) is 455 bp."
                    ),
                    "delivery_modality": "Single AAV6 capsid (3,747 bp including 2x145 bp ITRs; +953 bp headroom) or non-viral ssDNA HDR",
                    "cbx3_a2ucoe_length_bp": len(cbx3_a2ucoe_455),
                    "cbx3_a2ucoe_avi_window_match": ucoe_avi_match_str,
                    "ctcf_ma0139_1_footprint_fii_scan_note": (
                        f"Direct JASPAR MA0139.1 CTCF scan on cHS4_core_insulator_250bp locates the canonical FII footprint at local 1-based positions "
                        f"{chs4_top1['start_1based_in_window']}..{chs4_top1['end_1based_in_window']} ({chs4_top1['strand']} strand, kmer={chs4_top1['matched_kmer']}, "
                        f"log2_odds={chs4_top1['log2_odds_score']} bits, rel_score={chs4_top1['relative_score_0_to_1']}, "
                        f"1-PWM Bonferroni p={chs4_top1['bonferroni_window_p_value']}, 6-PWM family Bonferroni p={chs4_top6['bonferroni_region_across_all_matrices_p_value']}, "
                        f"passes_rel_score_0p80_and_p_le_0p05={chs4_top1['passes_rel_score_0p80_and_p_le_0p05']}; exact sequence match to Gallus U78775.2:55..73)."
                    ),
                    "common_mode_epigenetic_silencing_and_en_bloc_retrieval_audit_sol61_r5": {
                        "finding_id": "AUDIT-REF",
                        "decision_id": "DEC-044",
                        "primary_citations": ["PMID:35795779", "PMID:26455413"],
                        "correlated_common_mode_escape_mixture_formula": "P_escape_cell = p_common + (1 - p_common) * (p_ind ** 2)",
                        "single_allele_silencing_or_mutation_rate_p_ind": 1.0e-4,
                        "independent_two_hit_term_p_ind_squared": 1.0e-8,
                        "correlated_trans_epigenetic_silencing_floor_range_p_common": [1.0e-6, 1.0e-5],
                        "curative_dose_proliferating_cells_n_prolif_endocrine": 80000,
                        "curative_dose_proliferating_cells_n_prolif_pan_lineage": 93350,
                        "expected_surviving_clonogenic_cells_per_dose_if_p_common_1e_6_to_1e_5": [0.0808, 0.8008],
                        "expected_surviving_clonogenic_cells_per_dose_endocrine_80000_if_p_common_1e_6_to_1e_5": [0.0808, 0.8008],
                        "expected_surviving_clonogenic_cells_per_dose_pan_lineage_93350_if_p_common_1e_6_to_1e_5": [0.0943, 0.9344],
                        "poisson_prob_at_least_1_proliferating_survivor_pan_lineage_93350_if_p_common_1e_6_to_1e_5": [
                            round(1.0 - math.exp(-93350.0 * (1.0e-6 + (1.0 - 1.0e-6) * 1.0e-8)), 6),
                            round(1.0 - math.exp(-93350.0 * (1.0e-5 + (1.0 - 1.0e-5) * 1.0e-8)), 6),
                        ],
                        "per_cell_vs_per_graft_common_mode_parameter_reconciliation_astra6_r5": (
                            "Distinguishes two distinct common-mode parameters (AUDIT-REF [DEC-046]): "
                            "(a) Layer-2 p_common_cell in [10^-6, 10^-5] is a per-proliferating-cell trans-epigenetic/apoptotic resistance rate (giving p_cell = p_common_cell + (1 - p_common_cell)*10^-8, "
                            "expected surviving proliferating cells E = 93,350 * p_cell = 0.0943 to 0.9344 per dose, and Poisson dose-level escape probability P(>=1 survivor) = 1 - exp(-E) = 8.9975% to 60.7192%, which exceeds the 0.1% patient-level target by 90x-607x); "
                            "whereas (b) Layer-1 q_common_graft <= 6.6998e-5 is a per-graft/per-batch catastrophic failure probability in P_escape_graft = q_common_graft + (1 - q_common_graft)*(1 - (1 - p_cell)^93350) <= 10^-3, "
                            "which at q_common_graft = 6.6998e-5 matches the 10^-3 total dose-level ceiling when per-cell escape is at the two-independent-allele floor p_cell = p_ind^2 = 10^-8 (leaving remaining cell-level headroom p_cell <= 1.00000094e-8, i.e. p_common_cell <= 9.4e-16 when q_common_graft = 6.6998e-5 is simultaneously active, whereas under a pure cell-level budget q_common_graft = 0 the 10^-3 dose-level ceiling allows p_cell <= 1.0718e-8, i.e. per-cell p_common_cell <= 7.18e-10; DEC-078). "
                            "This 90x-607x gap under realistic per-cell trans-silencing is why pharmacological suicide switches (iCasp9 / RQR8) cannot be claimed as a standalone <= 10^-3 patient-level guarantee and why primary physical containment + en-bloc surgical retrievability (Gate 0S-Retrieval) is mandatory."
                        ),
                        "mcb_effective_clonogenic_trial_floor_for_95pct_1e8_bound": 299573228,
                        "dual_orthogonal_suicide_switch_challenger_sol61_r5": {
                            "challenger_id": "DUAL_SAFE_HARBOR_AAVS1_ICASP9_PLUS_GAPDH_RQR8_OR_HSVTK_SR39",
                            "locus4_aavs1_switch": "AAVS1::cHS4-A2UCOE-EEF1A1-iCasp9 (AP1903 dimerizer -> Caspase-9 intrinsic apoptosis)",
                            "orthogonal_second_switch": "GAPDH::EEF1A1-RQR8 (extrinsic rituximab CDC/ADCC surface epitope, bypassing intracellular XIAP/BCL-xL/APAF1 blocks) or HSV-TK(SR39) (ganciclovir DNA chain termination targeting dividing cells)",
                            "total_graft_cells_5e8_expected_survivors_under_naive_1e8": 5.0,
                            "total_graft_cells_5e8_prob_at_least_1_survivor_under_naive_1e8": round(1.0 - math.exp(-5.0), 6),
                            "pan_lineage_proliferating_93350_expected_survivors_under_p_common_1e6_to_1e5": [0.0943, 0.9344],
                            "why_gate_0s_surgical_retrieval_remains_mandatory": (
                                "Even with an orthogonal second suicide switch (RQR8/rituximab or HSV-TK/ganciclovir) at a second safe harbor, a 5e8-cell total graft still has E=5.0 surviving cells "
                                "(P(>=1)=99.33%) at a 10^-8 per-cell escape ceiling and 0.0943-0.9344 expected proliferating escapees across the 93,350 pan-lineage Ki67+ subpopulation under p_common = 10^-6-10^-5 "
                                "(plus macromolecular IgG/complement diffusion limits inside a fibrotic capsule for RQR8); therefore pharmacological suicide switches serve as >=4-5 log debulking adjuncts while primary physical containment and en-bloc surgical retrievability of the dual omental pouches (Gate 0S-Retrieval) provide the definitive clinical fail-safe (AUDIT-REF & AUDIT-REF [DEC-044/045])."
                            ),
                        },
                        "primary_containment_and_surgical_retrieval_architecture": (
                            "Because both alleles of biallelic AAVS1::cHS4-A2UCOE-EEF1A1-iCasp9 (or dual-safe-harbor AAVS1 + GAPDH) reside inside the same trans-acting nuclear "
                            "DNMT3A/3B/KAP1/HUSH and post-mitotic beta-cell XIAP/BCL-xL environment, single-cell AP1903 escape follows the common-mode mixture model "
                            "P_escape_cell = p_common + (1 - p_common) * p_ind^2 rather than a pure independent product p_ind^2 = 10^-8 (Wunderlich et al. 2022 PMID:35795779; Ordovas et al. 2015 PMID:26455413). "
                            "Consequently: (1) Stage-0 Gate S9 enforces a cumulative MCB clonogenic trial floor of N_eff >= ceil(-ln(0.05)/10^-8) = 299,573,228 effective clonogenic trials "
                            "(896,925,831 physical cells at eta = 0.334) after 35-day Stage 0->7 differentiation + 14-day cytokine/hypoxia culture with 0 surviving colonies; and "
                            "(2) for human translation, iCasp9 + AP1903 is positioned as an adjunct pharmacological debulking switch (>= 4-5 log reduction) paired with primary mechanical containment "
                            "and en-bloc surgical retrievability of the dual pre-vascularized omental scaffold pouches (Gate 0S-Retrieval; AUDIT-REF & AUDIT-REF [DEC-044/045])."
                        ),
                    },
                    "decision_exp4_four_arm_ucoe_orientation_splicing_and_methylation_substudy_iip_0011": {
                        "decision_id": "DEC-090",
                        "proposal_id": "IIP-0011",
                        "aavs1_recipient_junction_grch38": "chr19:55115768|55115767 (PPP1R12C intron 1, minus-strand host transcription)",
                        "pinned_chr7_26201562_26201567_plus_strand_motif": ref["ensembl_promoter_sequences"]["CBX3_A2UCOE_chr7_26200650_26201850"]["sequence"][26201562 - 26200650 : 26201568 - 26200650],
                        "pinned_chr7_26201562_26201567_reverse_complement_motif": revcomp(
                            ref["ensembl_promoter_sequences"]["CBX3_A2UCOE_chr7_26200650_26201850"]["sequence"][26201562 - 26200650 : 26201568 - 26200650]
                        ),
                        "four_arm_comparison": [
                            {
                                "arm_id": "Window_A_Reference_HNRNPA2B1_Proximal_455bp",
                                "genomic_interval_grch38_1based_closed": "chr7:26200580-26201034",
                                "element_length_bp": 455,
                                "cargo_bp": 2257,
                                "donor_bp": 3457,
                                "packaged_aav6_with_2x145bp_itrs_bp": 3747,
                                "orientation_relative_to_donor_eef1a1_icasp9": "canonical reference orientation in LOCUS4_AAVS1_CHS4_455BP_CBX3_A2UCOE_ICASP9_R17",
                            },
                            {
                                "arm_id": "Window_B_Genome_Derived_CBX3_453bp_Antisense_Candidate",
                                "genomic_interval_grch38_1based_closed": "chr7:26201456-26201908",
                                "element_length_bp": 453,
                                "cargo_bp": 2255,
                                "donor_bp": 3455,
                                "packaged_aav6_with_2x145bp_itrs_bp": 3745,
                                "orientation_relative_to_donor_eef1a1_icasp9": (
                                    "Reverse-complemented relative to the donor's EEF1A1->iCasp9 direction (which follows minus-strand PPP1R12C transcription), "
                                    "inverting the plus-strand GTAAGT hexamer at chr7:26201562-26201567 out of the transcribed sense strand."
                                ),
                                "provenance_and_orientation_qualification_note": (
                                    "Consistent with the BglI/BsrBI restriction boundaries of Zhang et al. 2017 (PMID:28860464), designated a genome-derived "
                                    "candidate pending ligated-terminus sequence reconciliation against the published insert. Because Zhang et al. 2017 reported "
                                    "orientation-dependent UCOE activity and inverting a single GTAAGT motif does not exclude other cryptic splice sites or "
                                    "transcriptional interference, antisense orientation is an empirical test arm rather than pre-established safe or equally anti-silencing."
                                ),
                            },
                            {
                                "arm_id": "Window_B_Genome_Derived_CBX3_453bp_Sense_Candidate",
                                "genomic_interval_grch38_1based_closed": "chr7:26201456-26201908",
                                "element_length_bp": 453,
                                "cargo_bp": 2255,
                                "donor_bp": 3455,
                                "packaged_aav6_with_2x145bp_itrs_bp": 3745,
                                "orientation_relative_to_donor_eef1a1_icasp9": "Plus-strand sequence oriented colinearly with the donor's EEF1A1->iCasp9 transcription unit",
                            },
                            {
                                "arm_id": "No_UCOE_Control",
                                "genomic_interval_grch38_1based_closed": None,
                                "element_length_bp": 0,
                                "cargo_bp": 1802,
                                "donor_bp": 3002,
                                "packaged_aav6_with_2x145bp_itrs_bp": 3292,
                                "orientation_relative_to_donor_eef1a1_icasp9": "cHS4_core_insulator_250bp + EEF1A1_core_promoter_230bp + iCasp9 without UCOE",
                            },
                        ],
                        "required_readouts_and_authoritative_escape_gate": (
                            "Measure 5'/3' PPP1R12C-transgene fusion transcripts by RACE-seq, targeted/single-molecule bisulfite CpG methylation "
                            "(explicitly covering the native 230-bp EEF1A1 core promoter's 19 CpG dinucleotides alongside UCOE CpGs), single-cell "
                            "iCasp9 expression distributions, and 24-h/72-h 10 nM AP1903 killing under normoxia and 1% O2 hypoxia + cytokines across "
                            "residual hPSCs, Stage-7 endocrine (beta, alpha, delta), and proliferative vascular/stromal (iEC, iPericyte) lineages "
                            "(Ordovas et al. 2015 PMID:26455413; Muller-Kuller et al. 2015 PMID:25605798; Zhang et al. 2017 PMID:28860464; "
                            "Wunderlich et al. 2022 PMID:35795779). Mean CpG methylation and bulk killing cannot bound rare resistant cells; "
                            "Readout 6 Tier 6B effective-denominator clonogenic escape qualification remains authoritative (GY-002)."
                        ),
                        "locus1_arm1b_longitudinal_methylation_parallel_check": (
                            "If Locus 1 Arm 1B (Syn_5xISRE_minP + antisense 230-bp EEF1A1 core with 19 native CpGs) advances, perform parallel "
                            "longitudinal clonal bisulfite CpG sequencing and single-cell resting/IFN-induced HLA-E + Hour-0 CD47 surface-density "
                            "distribution checks across differentiation passages (GY-009)."
                        ),
                        "primary_citations": ["PMID:26455413", "PMID:25605798", "PMID:28860464", "PMID:35795779"],
                    },
                },
            ),
        ],
    }


def verify_construct_part_grammar(construct_verification: Dict[str, Any]) -> Dict[str, Any]:
    """
    Strictly validate construct part tiling, explicit strand orientations ('+'/'-'),
    non-overlapping GRCh38 homology-arm genomic intervals and sequences,
    pinned UCOE sequence SHA-256 and AVI window alignment,
    directional promoter -> Kozak -> CDS -> polyA ordering on both '+' and '-' strands,
    and canonical P2A GDVEENPGP motif integrity (closes AUDIT-REF & 069).
    """
    source_constructs = construct_verification.get("constructs", [])
    ids = [c.get("construct_id") for c in source_constructs]
    if len(ids) != len(set(ids)) or set(ids) != CANONICAL_CONSTRUCT_IDS:
        raise ValueError("Exactly the four canonical construct IDs are required; duplicates/subsets cannot verify all cassettes")
    constructs_by_id = {c["construct_id"]: c for c in source_constructs}
    def invalid_reference_grammar() -> Dict[str, Any]:
        return {
            "all_construct_grammars_verified": False, "all_construct_grammars_valid": False,
            "all_homology_arms_non_overlapping_verified": False,
            "construct_grammar_validation_status": "INVALID_CONSTRUCT_GRAMMAR_DETECTED",
            "arm1b_constitutive_cd47_verified": False, "arm1b_sense_hlae_verified": False,
            "arm1a_bicistronic_verified": False, "locus3_bicistronic_verified": False,
            "locus4_ucoe_icasp9_verified": False,
        }
    # These IDs designate fixed reference cassettes. A subset of recognizable
    # promoter/CDS names cannot certify the full cassette after a required
    # insulator, intron or WPRE has been replaced by unrelated filler.
    required_part_order = {
        "LOCUS1_ARM1A_TPT2A_BICISTRONIC": (
            "B2M_HA_L_800bp", "EEF1A1_core_promoter_230bp", "Chimeric_Intron_133bp", "Kozak_9bp",
            "HLAE_0103_VMAPRTLVL_SCT_full_tail_CDS_1500bp", "GSG_P2A_CDS_66bp",
            "CD47_IgV_CD55_GPI_CDS_528bp", "WPREmut6_589bp", "bGH_polyA_225bp", "B2M_HA_R_800bp"),
        "LOCUS1_ARM1B_2AFREE_BIDIRECTIONAL_R01": (
            "B2M_HA_L_600bp", "SV40_late_polyA_122bp_antisense", "CD47_IgV_CD55_GPI_CDS_528bp_antisense",
            "Kozak_9bp_antisense", "EEF1A1_core_promoter_230bp_antisense", "Syn_5xISRE_minP_148bp_sense",
            "Kozak_9bp_sense", "HLAE_0103_VMAPRTLVL_SCT_full_tail_stop_CDS_1503bp",
            "bGH_polyA_225bp_sense", "B2M_HA_R_600bp"),
        "LOCUS3_CXCL10_SERPINB9_TPT2A_PDL1_R01": (
            "CXCL10_HA_L_600bp_minus", "Kozak_9bp", "SERPINB9_CDS_1128bp", "GSG_P2A_CDS_66bp",
            "PDL1_full_stop_CDS_873bp", "WPREmut6_589bp", "bGH_polyA_225bp", "CXCL10_HA_R_600bp_minus"),
        "LOCUS4_AAVS1_CHS4_455BP_CBX3_A2UCOE_ICASP9_R17": (
            "AAVS1_HA_L_600bp_minus", "cHS4_core_insulator_250bp", "CBX3_A2UCOE_455bp_exact",
            "EEF1A1_core_promoter_230bp", "Kozak_9bp", "iCasp9_FKBP12F36V_dCasp9_stop_CDS_1191bp",
            "SV40_late_polyA_122bp", "AAVS1_HA_R_600bp_minus"),
    }
    # Require positive, complete tiling and the actual Kozak module adjacent to
    # each independently initiated ORF; names alone cannot certify translation.
    kozak_requirements = {
        "LOCUS1_ARM1A_TPT2A_BICISTRONIC": [("Kozak_9bp", "+", "HLAE_")],
        "LOCUS1_ARM1B_2AFREE_BIDIRECTIONAL_R01": [("Kozak_9bp_antisense", "-", "CD47_"), ("Kozak_9bp_sense", "+", "HLAE_")],
        "LOCUS3_CXCL10_SERPINB9_TPT2A_PDL1_R01": [("Kozak_9bp", "+", "SERPINB9_")],
        "LOCUS4_AAVS1_CHS4_455BP_CBX3_A2UCOE_ICASP9_R17": [("Kozak_9bp", "+", "iCasp9_")],
    }
    for cid, construct in constructs_by_id.items():
        total, parts = construct.get("total_length_bp"), construct.get("part_ledger")
        if type(total) is not int or total <= 0 or not isinstance(parts, list) or not parts:
            raise ValueError(f"Positive construct length and complete part ledger are required: {cid}")
        cursor, names = 1, set()
        for index, part in enumerate(parts):
            if not isinstance(part, dict):
                raise ValueError(f"Construct part must be an object: {cid}")