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…

        raise ValueError("Portfolio 9-boundary peptide window audit failed")

    l3_can_juncs = [{"junction_id": "SERPINB9_365_376__GSG_P2A_21aa_stub", "left_aa": serpinb9_aa, "linker_aa": "", "right_aa": gsg_p2a_stub_aa}]
    l4_juncs = [{"junction_id": "FKBP12F36V__SGGGSG__dCasp9", "left_aa": icasp9_aa[:108], "linker_aa": "SGGGSG", "right_aa": icasp9_aa[114:]}]
    l1_astar_juncs = [
        {"junction_id": "VMAPRTLVL__G4S4_L1", "left_aa": hlae_astar_aa[20:29], "linker_aa": "", "right_aa": hlae_astar_aa[29:49]},
        {"junction_id": "G4S4_L1__B2M_mature", "left_aa": hlae_astar_aa[29:49], "linker_aa": "", "right_aa": hlae_astar_aa[49:148]},
        {"junction_id": "B2M_mature__G4S4_L2", "left_aa": hlae_astar_aa[49:148], "linker_aa": "", "right_aa": hlae_astar_aa[148:168]},
        {"junction_id": "G4S4_L2__HLAE_alpha1", "left_aa": hlae_astar_aa[148:168], "linker_aa": "", "right_aa": hlae_astar_aa[168:]},
        {"junction_id": "CD47_IgV_19_138__CD55_stalk_139_147", "left_aa": cd47_aa[18:138], "linker_aa": "", "right_aa": cd47_aa[138:147]},
    ]

    construct_specs = [
        ("S3_L3_CAN_PDL1_SYN2_4090", "L3 canonical coding-only challenger: single synonymous PD-L1 C720T/G723C (intact WPRE & bGH)", l3_can_syn2, l3_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L3_CANONICAL_4090)",
         [{"name": "SERPINB9_nostop", "start_0based": 609, "end_0based": 1737, "strand": "+", "has_stop": False, "parent_cds": serpinb9_nostop, "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": True},
          {"name": "PDL1_stop", "start_0based": 1803, "end_0based": 2676, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         l3_can_juncs, 34, 14, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["SERPINB9_C_terminal_21aa_GSG_P2A_stub_requires_GzmB_kinetics_assay"]),
        ("S3_L3_CAN_PDL1_SYN4_4090", "L3 canonical dual-synonymous challenger: PD-L1 C720T/G723C/C858T/G861C (intact WPRE & bGH)", l3_can_syn4, l3_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L3_CANONICAL_4090)",
         [{"name": "SERPINB9_nostop", "start_0based": 609, "end_0based": 1737, "strand": "+", "has_stop": False, "parent_cds": serpinb9_nostop, "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": True},
          {"name": "PDL1_stop", "start_0based": 1803, "end_0based": 2676, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         l3_can_juncs, 34, 14, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["SERPINB9_C_terminal_21aa_GSG_P2A_stub_requires_GzmB_kinetics_assay"]),
        ("S3_L3_CAN_BGH_ONLY_4090", "Single-factor L3 non-coding control: bGH G140T/G143T/G144T only", l3_can_bgh_only, l3_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L3_CANONICAL_4090)",
         [{"name": "SERPINB9_nostop", "start_0based": 609, "end_0based": 1737, "strand": "+", "has_stop": False, "parent_cds": serpinb9_nostop, "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": True},
          {"name": "PDL1_stop", "start_0based": 1803, "end_0based": 2676, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         l3_can_juncs, 34, 14, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["bGH_proximal_downstream_edits_require_3RACE_cleavage_and_protein_verification"]),
        ("S3_L3_CAN_WPRE_ONLY_4090", "Single-factor L3 exploratory control: WPRE C261A (J04514.1:g.1353C>A) only; excluded from primary arms because it creates sense CAT|GTCAGC", l3_can_wpre_only, l3_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L3_CANONICAL_4090)",
         [{"name": "SERPINB9_nostop", "start_0based": 609, "end_0based": 1737, "strand": "+", "has_stop": False, "parent_cds": serpinb9_nostop, "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": True},
          {"name": "PDL1_stop", "start_0based": 1803, "end_0based": 2676, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         l3_can_juncs, 34, 14, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["WPRE_g1353C_to_A_excluded_from_primary_due_to_3UTR_and_neo_sense_donor"]),
        ("S3_L3_SF_PDL1_SYN4_3799", "Scar-free L3 coding-only challenger: dual synonymous PD-L1 C720T/G723C/C858T/G861C (intact bGH)", l3_sf_syn4_only, l3_sf_wt, "ISLET1_A4_L3_SCARFREE_3799",
         [{"name": "SERPINB9_scarfree_stop", "start_0based": 609, "end_0based": 1740, "strand": "+", "has_stop": True, "parent_cds": l3_sf_wt[609:1740], "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": False},
          {"name": "PDL1_stop", "start_0based": 2101, "end_0based": 2974, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         [], 0, 0, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["Dual_promoter_scarfree_expression_kinetics_pending_Readout4"]),
        ("S3_L3_SF_SYN4_1xFII80_3879", "Optional single-sided 80-bp cHS4 FII inserted as revcomp(U78775.2:24-103) at 601..680 + scar-free PD-L1 SYN4 (requires absolute resting and IFN-induced SERPINB9/PD-L1/CXCL9/CXCL11 gates)", l3_sf_syn4_1xfii80, l3_sf_wt, "ISLET1_A4_L3_SCARFREE_3799",
         [{"name": "SERPINB9_scarfree_stop", "start_0based": 689, "end_0based": 1820, "strand": "+", "has_stop": True, "parent_cds": l3_sf_wt[609:1740], "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": False},
          {"name": "PDL1_stop", "start_0based": 2181, "end_0based": 3054, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         [], 0, 0, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["Single_80bp_FII_revcomp_enhancer_blocker_not_barrier_insulator_pending_Readout4"]),
        ("S3_L3_SF_SYN4_BGH_1xFII80_3879", "Optional single-sided 80-bp cHS4 FII revcomp(U78775.2:24-103) + scar-free PD-L1 SYN4 + bGH G140T/G143T/G144T comparator", l3_sf_syn4_bgh_1xfii80, l3_sf_wt, "ISLET1_A4_L3_SCARFREE_3799",
         [{"name": "SERPINB9_scarfree_stop", "start_0based": 689, "end_0based": 1820, "strand": "+", "has_stop": True, "parent_cds": l3_sf_wt[609:1740], "topology_kind": "CYTOSOLIC_SERPINB9", "has_downstream_2a": False},
          {"name": "PDL1_stop", "start_0based": 2181, "end_0based": 3054, "strand": "+", "has_stop": True, "parent_cds": pdl1_wt, "topology_kind": "TYPE1_TM_PDL1", "has_downstream_2a": False}],
         [], 0, 0, 34, 14, ["1IAU", "4GA7", "8ZCR", "4ZQK"], ["Single_80bp_FII_revcomp_and_bGH_edits_pending_Readout4"]),
        ("S3_L4_WINA_ONLY_3457", "Single-factor L4 control: Window A A32T/G33C/A444T/G445C/G446C only (47 CpGs, intact EEF1A1, NO SPA)", l4_wina_only, l4_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L4_WINA_CODIR_3457)",
         [{"name": "iCasp9_stop", "start_0based": 1544, "end_0based": 2735, "strand": "+", "has_stop": True, "parent_cds": icasp9_wt, "topology_kind": "CYTOSOLIC_ICASP9", "has_downstream_2a": False}],
         l4_juncs, 58, 20, 58, 20, ["1BL4", "1JXQ", "1NW9"], ["FULL_FUSION_UNRESOLVED_IIP_0011", "WindowA_anti_silencing_transfer_pending_Readout6"]),
        ("S3_L4_EEF230C_ONLY_3457", "Single-factor L4 control: corrected EEF1A1 G223C/A229C/G230C only (19 part CpGs, +1 seam CpG, construct CpGs 203 vs 202, NO SPA)", l4_eef230c_only, l4_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L4_WINA_CODIR_3457)",
         [{"name": "iCasp9_stop", "start_0based": 1544, "end_0based": 2735, "strand": "+", "has_stop": True, "parent_cds": icasp9_wt, "topology_kind": "CYTOSOLIC_ICASP9", "has_downstream_2a": False}],
         l4_juncs, 58, 20, 58, 20, ["1BL4", "1JXQ", "1NW9"], ["FULL_FUSION_UNRESOLVED_IIP_0011", "EEF1A1_5UTR_edits_require_translation_and_Readout6_verification"]),
        ("S3_L4_SPLICE_230C_NOSPA_3457", "Co-directional L4 internal-intron-ablated challenger: Window A (5 nt) + EEF1A1[230C] (3 nt), NO SPA (retains 122-bp SV40pA 2736..2857 and iCasp9 CDS[11..12] AG on PPP1R12C strand)", l4_splice_230c, l4_can, "ISLET1_A4_ARM1A / ISLET1_A4_ARM1B (L4_WINA_CODIR_3457)",
         [{"name": "iCasp9_stop", "start_0based": 1544, "end_0based": 2735, "strand": "+", "has_stop": True, "parent_cds": icasp9_wt, "topology_kind": "CYTOSOLIC_ICASP9", "has_downstream_2a": False}],
         l4_juncs, 58, 20, 58, 20, ["1BL4", "1JXQ", "1NW9"], ["FULL_FUSION_UNRESOLVED_IIP_0011", "Co_directional_SV40pA_and_iCasp9_CDS13_acceptor_exposed_to_PPP1R12C_Ex1_requires_RACE_and_Tier6A_6B"]),
        ("S3_L4_CONVERGENT_2STRAND_230C_3457", "Convergent two-strand-hardened L4 challenger on GRCh38 chr19:+ (revcomp of 977495f1... on chr19:-): Window A (7 nt) + EEF1A1[230C] (3 nt), NO SPA", l4_conv_2strand_230c, l4_conv_wt_plus, "L4_WINA_CONVERGENT_3457",
         [{"name": "iCasp9_stop", "start_0based": 1544, "end_0based": 2735, "strand": "+", "has_stop": True, "parent_cds": icasp9_wt, "topology_kind": "CYTOSOLIC_ICASP9", "has_downstream_2a": False}],
         l4_juncs, 58, 20, 58, 20, ["1BL4", "1JXQ", "1NW9"], ["FULL_FUSION_UNRESOLVED_IIP_0011", "Convergent_PPP1R12C_transcriptional_interference_and_dsRNA_collision_gate_required"]),
        ("S3_L4_DXS_SPLICE_230C_NOSPA_4048", "DX-S Locus 4 splice-only comparator (Window A 5 nt + EEF1A1_5TOP G223C/A229C/G230C, NO SPA, 4,048 bp)", dxs_l4_splice_230c_nospa, dxs_l4_wt, "ISLET1_A4_DXS_ARM1C_L4CD47",
         [{"name": "iCasp9_nostop", "start_0based": 1544, "end_0based": 2732, "strand": "+", "has_stop": False, "parent_cds": dxs_l4_wt[1544:2732], "topology_kind": "CYTOSOLIC_ICASP9", "has_downstream_2a": True},
          {"name": "CD47_IgV_GPI_stop", "start_0based": 2798, "end_0based": 3326, "strand": "+", "has_stop": True, "parent_cds": dxs_l4_wt[2798:3326], "topology_kind": "GPI_ANCHORED_CD47_IGV", "has_downstream_2a": False}],
         l4_juncs + [{"junction_id": "iCasp9__GSG_P2A_21aa_stub", "left_aa": icasp9_aa, "linker_aa": "", "right_aa": gsg_p2a_stub_aa},
                     {"junction_id": "CD47_IgV_19_138__CD55_stalk_139_147", "left_aa": cd47_aa[18:138], "linker_aa": "", "right_aa": cd47_aa[138:147]}],
         58 + 34 + 33, 20 + 14 + 9, 58 + 34 + 33, 20 + 14 + 9, ["1BL4", "1JXQ", "1NW9", "2JJS", "4CMM", "4KJY"], ["FULL_FUSION_UNRESOLVED_IIP_0011", "DXS_co_located_CD47_iCasp9_joint_retention_required"]),
        ("S3_L1_ASTAR_STOP_ONLY_4143", "Primary L1 Embodiment A* coding-only challenger (505-aa SCT): HLA-E SCT G1515C/G1517A (CTC-TAA) ONLY (already S3 PAM+seed shielded)", astar_stop_only, astar_wt, "ISLET1_A4_ARM1B (ISLET1_A_STAR_4LOCUS)",
         [{"name": "CD47_IgV_GPI_antisense", "start_0based": 876, "end_0based": 1404, "strand": "-", "has_stop": True, "parent_cds": cd47_astar_wt, "topology_kind": "GPI_ANCHORED_CD47_IGV", "has_downstream_2a": False},
          {"name": "HLAE_SCT_20aaL1_sense", "start_0based": 1800, "end_0based": 3318, "strand": "+", "has_stop": True, "parent_cds": hlae_astar_wt, "topology_kind": "TYPE1_TM_HLAE_SCT", "has_downstream_2a": False}],
         l1_astar_juncs, 168, 60, 168, 60, ["3CDG", "1MHE", "3BZE", "2JJS", "4CMM", "4KJY"], ["GY-009_Hour0_HLAE_CD47_QuantiBRITE_surface_stoichiometry_pending", "NKG2A_vs_NKG2C_SCT_SPR_pending"]),
        ("S3_L1_ASTAR_FULL_230C_4143", "Combined L1 Embodiment A* comparator (505-aa SCT): SCT CTC-TAA + bGH G140T/G143T/G144T + antisense EEF1A1 G223C/A229C/G230C", astar_full_230c, astar_wt, "ISLET1_A4_ARM1B (ISLET1_A_STAR_4LOCUS)",
         [{"name": "CD47_IgV_GPI_antisense", "start_0based": 876, "end_0based": 1404, "strand": "-", "has_stop": True, "parent_cds": cd47_astar_wt, "topology_kind": "GPI_ANCHORED_CD47_IGV", "has_downstream_2a": False},
          {"name": "HLAE_SCT_20aaL1_sense", "start_0based": 1800, "end_0based": 3318, "strand": "+", "has_stop": True, "parent_cds": hlae_astar_wt, "topology_kind": "TYPE1_TM_HLAE_SCT", "has_downstream_2a": False}],
         l1_astar_juncs, 168, 60, 168, 60, ["3CDG", "1MHE", "3BZE", "2JJS", "4CMM", "4KJY"], ["GY-009_Hour0_HLAE_CD47_QuantiBRITE_surface_stoichiometry_pending", "bGH_and_antisense_EEF1A1_processing_pending"]),
    ]

    qualified_constructs = []
    for cid, desc, dseq, pseq_for_diff, parent_id, orfs, jspecs, p8, p15, r8, r15, pdbs, flags in construct_specs:
        gate_res = validate_p1_to_p4_fail_closed(cid, dseq, orfs, jspecs, p8, p15, r8, r15, pdbs, flags)
        gram_scan = scan_donors_and_acceptors_both_strands(dseq)
        rep_scan = longest_repeats(dseq)
        neos = diff_edit_created_neosites(pseq_for_diff, dseq) if len(pseq_for_diff) == len(dseq) else {"note": "length_changed_insulator_insertion"}
        qualified_constructs.append(
            {
                "construct_id": cid,
                "parent_product_and_donor_id": parent_id,
                "description": desc,
                "donor_length_bp": len(dseq),
                "packaged_aav6_bp": len(dseq) + 290,
                "donor_sha256": sha256_str(dseq),
                "donor_sequence": dseq,
                "repeat_scan": rep_scan,
                "open_grammar_motif_counts": {
                    "strong_donors_both_strands": gram_scan["total_donors"],
                    "strong_donors_cv_ge_74": gram_scan["donors_cv_ge_74"],
                    "cargo_donors": gram_scan["cargo_donors"],
                    "strong_acceptors_both_strands": gram_scan["total_acceptors"],
                    "cargo_acceptors": gram_scan["cargo_acceptors"],
                    "top_5_donors": gram_scan["donors"][:5],
                    "top_5_acceptors": gram_scan["acceptors"][:5],
                },
                "edit_created_neosite_check": neos,
                "p1_to_p4_fail_closed_gate": gate_res,
            }
        )

    parental_open_scans = {}
    for pid, pseq in [
        ("L1_ARM1A_CANONICAL_4880", arm1a_can),
        ("L1_ARM1B_CANONICAL_3974", arm1b_can),
        ("L1_EMBODIMENT_A_STAR_4143", astar_wt),
        ("L3_CANONICAL_4090", l3_can),
        ("L3_SCARFREE_3799", l3_sf_wt),
        ("L3_BFB_BASALFLOOR_4078", l3_bfb_wt),
        ("L4_WINA_CODIR_3457", l4_can),
        ("L4_DXS_CD47_ICASP9_4048", dxs_l4_wt),
        ("L1_DXS_ARM1C_CONSTITUTIVE_3300", dxs_arm1c_3300),
        ("L1_DXS_ARM1C_TRAPPED_3459", dxs_arm1c_3459),
    ]:
        g = scan_donors_and_acceptors_both_strands(pseq)
        parental_open_scans[pid] = {
            "donor_length_bp": len(pseq),
            "donor_sha256": sha256_str(pseq),
            "donor_cpg_count": pseq.count("CG"),
            "repeat_scan": longest_repeats(pseq),
            "census_summary": {
                "total_donors_cv74_or_u1_7": g["total_donors"],
                "donors_cv_ge_74": g["donors_cv_ge_74"],
                "cargo_donors_total": g["cargo_donors"],
                "cargo_donors_plus_strand": g["cargo_donors_plus_strand"],
                "cargo_donors_minus_strand": g["cargo_donors_minus_strand"],
                "total_acceptors_idx_ge_68": g["total_acceptors"],
                "cargo_acceptors_total": g["cargo_acceptors"],
            },
            "top_10_donors_both_strands": g["donors"][:10],
            "top_10_acceptors_both_strands": g["acceptors"][:10],
        }

    fwd_span = (850 + 380, 850 + 405)            # WindowA[380..405] -> donor 1230..1255 (26 nt)
    rev_matched_span = (1544 + 105, 1544 + 125)  # iCasp9[105..125]  -> donor 1649..1669 (21 nt, dTm = 0.01 C)
    rev_legacy_span = (1544 + 40, 1544 + 65)     # iCasp9[40..65]    -> donor 1584..1609 (26 nt, antisense)
    fwd_seq = l4_can[fwd_span[0] - 1 : fwd_span[1]]
    rev_matched_seq = revcomp(l4_can[rev_matched_span[0] - 1 : rev_matched_span[1]])
    rev_legacy_seq = revcomp(l4_can[rev_legacy_span[0] - 1 : rev_legacy_span[1]])
    unspl_matched = rev_matched_span[1] - fwd_span[0] + 1
    unspl_legacy = rev_legacy_span[1] - fwd_span[0] + 1
    if unspl_matched != 440 or unspl_legacy != 380:
        raise ValueError("Locus 4 targeted splice RT-PCR amplicon arithmetic mismatch")

    return {
        "proposal_id": "IIP-0015",
        "decision_id": "DEC-092",
        "mode_b_invariance_contract": {
            "reference_fasta_unchanged": True,
            "layer1_stack_ranking_unchanged": True,
            "existing_release_gates_unchanged": True,
            "family_b_materialization_scope": (
                "All 9 Family-B product entries in data/protocols/islet1_product_definitions_v0.8.0.json remain "
                "REQUIRES_DONOR_SEQUENCE_MATERIALIZATION (execution_supported=false) and are ineligible for synthesis "
                "until materialized donors pass this identical open two-strand splice/repeat census and fail-closed P1-P4 validator."
            ),
        },
        "scanner_methodology_and_scope_limits": {
            "donor_9mer_models": "Shapiro & Senapathy 1987 (PMID:3658675) CV, Yeo & Burge 2004 (PMID:15285897) log-odds bits, and Roca et al. 2013 (PMID:23348838) 9-nt U1 Watson-Crick + G:U/G:psi wobble base-pairing.",
            "acceptor_23mer_model": "Explicitly labelled heuristic 23-mer polypyrimidine/-3/+1 index (not a trained neural splice predictor).",
            "known_heuristic_limits": (
                "Because mammalian splicing also uses non-GT canonical GC-AG / AT-AC introns, bulged/shifted U1 registers "
                "(Roca et al. 2013 PMID:23348838), branchpoints, and exonic/intronic splicing enhancers/silencers, sequence "
                "scores prioritize Stage-0 edits while wet-lab 5'/3'-RACE and UMI-tagged long-read cDNA sequencing are decisive."
            ),
        },
        "genomic_boundary_provenance": {
            "locus3_art3_isoform_reconciliation": art3_model,
            "locus4_window_a_cbx3_isoform_parentage": cbx3_win_a_model,
            "locus4_spa_and_sv40pa_scope_rule": (
                "Levitt et al. 1989 (PMID:2570734) showed an intronic SPA placed inside rabbit beta-globin intron 2 caused "
                "no detectable premature cleavage while its intact upstream 5' splice donor outcompeted polyadenylation, and "
                "restored SPA cleavage only when the upstream donor was deleted; intronic SPA is therefore a context-dependent "
                "premature-cleavage hazard under weakened/distant splice competition rather than unconditional host-gene failure. "
                "Critically, co-directional SPA-free Locus 4 constructs still retain the 122-bp SV40 late poly(A) (donor 2736..2857) "
                "and iCasp9 CDS[11..12] AG acceptor on the PPP1R12C transcription strand, so Readout 6 explicitly profiles PPP1R12C "