scripts/run_layer2_perturbation_and_regulatory_plane.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/run_layer2_perturbation_and_regulatory_plane.py · SHA-256: 3220e68f97203dbc…
cd274p_ov_bp = next(c["max_overlapping_direct_repeat_bp"] for c in construct_entries if c["construct_id"] == "L2_V3_CD274P_ZERO_TATATA")
max_outside_bp = max(c["max_overlapping_direct_repeat_outside_canonical_tandems_bp"] for c in construct_entries)
total_ki_8_11 = sum(v["knockin_created_non_native_8_11mers"] for v in ciita_isoform_summary_by_acc.values())
total_ki_15 = sum(v["knockin_created_non_native_15mers"] for v in ciita_isoform_summary_by_acc.values())
return {
"proposal_id": "IIP-0031",
"decision_id": "DEC-110",
"rule_id": "S11_Locus2_CIITA_ModeB_Vascular_Complement_and_Efferocytosis_Gate",
"graveyard_card_id": "GY-025",
"provenance_computation_mode": "DYNAMICALLY_RECOMPUTED_END_TO_END_FROM_BUNDLED_FASTA_AND_REFERENCE_JSON",
"mode_b_comparator_fasta": fasta_rel,
"mode_b_comparator_fasta_sha256": file_sha256,
"grch38_chr16_2001bp_reference_sha256": chr16_obj["sha256"],
"record_count": len(construct_entries),
"execution_supported": False,
"layer1_pareto_artifact_verified": layer1_pareto_verified,
"layer1_pareto_artifact_sha256": layer1_pareto_sha256,
"layer1_and_oq016_score_delta_pp": layer1_score_delta_pp,
"canonical_fastas_verified_count": len(verified_preexisting_fastas),
"canonical_fastas_untouched": canonical_fastas_untouched,
"descriptive_6pwm_jaspar_spatial_audit": {
"wholly_non_promoter_6pwm_hits": wholly_non_prom_total,
"promoter_boundary_irf1_nt538_558_6pwm_hits_count": len(boundary_irf1_6pwm_donors),
"promoter_boundary_irf1_nt538_558_1pwm_hits_count": len(boundary_irf1_1pwm_donors),
"promoter_boundary_irf1_6pwm_hits": boundary_irf1_6pwm_donors,
"promoter_boundary_irf1_1pwm_hits": boundary_irf1_1pwm_donors,
"co_primary_cd200_ctcf_insulator_hits": co_cd200_ctcf,
},
"repeat_summary": {
"max_disjoint_dr_across_8_bp": max(c["max_disjoint_direct_repeat_bp"] for c in construct_entries),
"overlapping_dr_syn5xisre_bp": syn_ov_bp,
"overlapping_dr_cd274p_maz4_bp": cd274p_ov_bp,
"max_dr_outside_canonical_tandems_bp": max_outside_bp,
"max_disjoint_ir_range_bp": [
min(c["max_disjoint_inverted_repeat_bp"] for c in construct_entries),
max(c["max_disjoint_inverted_repeat_bp"] for c in construct_entries),
],
"disjoint_ir_ge_16bp_total_across_8": sum(c["disjoint_inverted_repeats_ge_16bp_count"] for c in construct_entries),
"disjoint_ir_ge_20bp_le_1mm_total_across_8": sum(c["disjoint_inverted_repeats_ge_20bp_le_1mm_count"] for c in construct_entries),
},
"barrier_chs4_250_disclosure": {
"construct_id": "L2_V3_BARRIER_CHS4_250",
"classification": "COMBINED_LENGTH_AND_SEQUENCE_CHANGE_250BP_PLUS_U78775_2_C79T_C80A",
"shared_80bp_alignment_1based_in_250bp": [best_off + 1, best_off + 80],
"shared_80bp_diffs": chs4_diffs,
"interpretation_note": (
"L2_V3_BARRIER_CHS4_250 replaces the 80-bp FII element with the 250-bp cHS4 core carrying U78775.2 C79T/C80A "
"(cHS4 core positions 72..73, differing at 2 bases inside the shared 80-bp FII region as well as length); "
"therefore any difference vs L2_V3_CO_PRIMARY_CD200 is a combined length-and-sequence effect, not a pure length contrast."
),
},
"ciita_all_8_refseq_isoforms_audit": {
"isoforms_audited_count": len(ciita_isoform_summary_by_acc),
"refseq_accessions": list(ciita_isoform_summary_by_acc.keys()),
"knockin_created_non_native_8_11mers": total_ki_8_11,
"knockin_created_non_native_15mers": total_ki_15,
"by_refseq_accession": ciita_isoform_summary_by_acc,
"mandatory_stage0_controls": [
"Informative transcript recovery of both CIITA alleles (KI and KO)",
"Cis sentinels SOCS1, DEXI, and CLEC16A equivalence",
"Demonstrated HLA-DR/DP/DQ inducibility in lineage-matched wild-type Stage-7 controls",
],
},
"intronic_mir_and_rnai_attribution_scope": {
"candidate_seed_pairs_screened": replayed_pair_count,
"strands_screened_count": total_strands_screened,
"targets_screened_count": total_targets_screened,
"openislet_proxy_targets_count": len(oi_15_proxies),
"bundled_refseq_3utr_targets_count": len(utr22_3utrs),
"replayed_8mer_hits_total": total_8mer_hits,
"replayed_7mer_m8_hits_total": total_7m8_hits,
"disclosed_7mer_a1_hits": hits_7a1_disclosed,
"disclosed_22gene_cds_7mer_m8_genes": sorted(cds_7m8_genes),
"disclosed_22gene_5utr_7mer_m8_genes": sorted(utr5_7m8_genes),
"disclosed_22gene_full_mrna_7mer_m8_genes": sorted(full_mrna_7m8_genes),
"lead_guides_per_target": min(verified_pvr_leads, verified_cd276_leads),
"backup_guides_per_target": min(verified_pvr_backups, verified_cd276_backups),
"total_screened_guides_per_target": min(verified_pvr_guides, verified_cd276_guides),
"verified_pvr_guides_4of4_isoforms": verified_pvr_guides,
"verified_cd276_guides_4of4_isoforms": verified_cd276_guides,
"backup_guides_screened_against_all_15_openislet_proxies_and_22_utrs": True,
"backup_guide_screen_ledger_15oi_22utr": backup_guide_screen_ledger,
"active_mir_targets": ["CD276", "PVR"],
"design_b_active_mir_policy": "BARRED_ON_DESIGN_B_HLAC_INTACT",
"attribution_rule": (
"Claiming an RNAi-specific benefit requires same-background intronless and scramble controls linked to the tested cargo; "
"within the staged 8-donor FASTA, RNAi-specific attribution is therefore restricted to the matched CD200 comparison "
"(L2_V3_CO_PRIMARY_CD200 vs L2_V3_CTRL_NT_SCRAMBLE, paired with same-background intronless CD200 when RNAi benefit is claimed)."
),
},
"constructs": construct_entries,
"primary_citations": [
"PMID:19503104",
"PMID:28671664",
"PMID:21266852",
"PMID:19549636",
"PMID:21989056",
"PMID:12011446",
"PMID:15544620",
"PMID:28723575",
"PMID:24332856",
"PMID:35880017",
"PMID:28462820",
"PMID:32775498",
"PMID:36055241",
"PMID:37996616",
"PMID:40251154",
"PMID:2570734",
"PMID:34050011",
"PMID:30010673",
],
}
def main() -> None:
with REF_PATH.open("r", encoding="utf-8") as f:
ref = json.load(f)
promoters = ref["ensembl_promoter_sequences"]
pwms = ref["jaspar_pwms"]
n_pwms = len(pwms)
# 1. Scan JASPAR PWMs with background null calibration across endogenous regulatory windows
motif_scans: Dict[str, Any] = {}
for region_key, region_obj in promoters.items():
seq = region_obj["sequence"]
region_hits = {}
for mid, pwm_entry in pwms.items():
region_hits[f"{mid}_{pwm_entry['tf_name']}"] = scan_jaspar_pwm(seq, pwm_entry, top_k=2, n_matrices_in_scan=n_pwms)
cpg_cnt, gc_pct, oe_ratio = count_cpg(seq)
motif_scans[region_key] = {
"length_bp": len(seq),
"cpg_dinucleotide_count": cpg_cnt,
"gc_percent": gc_pct,
"cpg_observed_over_expected": oe_ratio,
"top_jaspar_pwm_hits": region_hits,
}
# 2. Publish only honest quarantine metadata; unverified scores are not model inputs
avi_summary = recompute_avi_summaries_from_full_archive()
# 3. Assemble and audit authentic HDR donor constructs
construct_verification = build_constructs(ref, avi_summary)
construct_verification["hlae_0101_vs_0103_gly107arg_and_cd47_daf_omega_site_sequence_audit_sonnet55_r5"] = {
"finding_ids": ["AUDIT-REF", "AUDIT-REF", "AUDIT-REF"],
"decision_id": "DEC-047",
"primary_citations": ["PMID:12411439", "PMID:38508139", "PMID:11504275", "PMID:22047558"],
"hlae_0101_gly107_vs_0103_arg107_audit": {
"crystal_template_origin": "PDB:3CDG Chain A (Petrie et al. 2008 PMID:18332182; and PDB:3BZE / PDB:1MHE) resolves HLA-E*01:01 (Arg107 at mature heavy-chain residue 107 in CELGPDRRFLRGY), whereas the engineered OpenIslet SCT donors encode HLA-E*01:03 (Gly107 at mature heavy-chain residue 107 in CELGPDGRFLRGY, codon GGC; mature cleaved SCT residue 250 [15-aa L1] or 255 [20-aa L1], precursor SCT residue 270 [500-aa canonical_arm1b_3974bp] or 275 [505-aa embodiment_a_star_4143bp]).",
"hlae_0103_canonical_substitution": "HLA-E*01:03 (HLA-E^G) differs from HLA-E*01:01 (HLA-E^R) by a single heavy-chain amino acid substitution at mature residue 107: Arg107Gly (R107G, codon CGG/CGC -> GGC; Strong et al. 2003 J Biol Chem PMID:12411439; UniProt P13747), which relieves unfavorable electrostatic/steric packing in the alpha2-domain loop (GPD-G107-R108-FLR vs GPD-R107-R108-FLR) and increases thermal stability (Tm +4.5 C) and steady-state cell-surface density.",
"backward_compatible_pinned_donors": "Both pinned donors — canonical_arm1b_3974bp (SHA-256 f74728767987c18b...) and embodiment_a_star_4143bp (SHA-256 0995f8e35791d219...) — already encode the true HLA-E*01:03 Gly107 (codon GGC) allele at precursor SCT residue 270 / 275 (mature cleaved SCT residue 250 / 255), while Stage-0 Gate 0A includes the PDB:3CDG-matched HLA-E*01:01 (Arg107, codon CGC) crystal-reference comparator to verify the +4.5 C Tm and steady-state surface-density advantage in the covalent SCT format.",
},
"hlae_0101_arg107_vs_0103_gly107_audit": {
"crystal_template_allele": "HLA-E*01:01 (Arg107, codon CGC/CGG in PDB:3CDG / 1MHE / 3BZE)",
"engineered_donor_allele": "HLA-E*01:03 (Gly107, codon GGC in canonical_arm1b_3974bp and embodiment_a_star_4143bp)",
"canonical_substitution": "Arg107Gly (R107G, mature heavy-chain residue 107; Strong et al. 2003 PMID:12411439)",
},
"cd47_igv_daf_175aa_omega_site_numbering_reconciliation": {
"precursor_length_aa": 175,
"signal_peptide_1_to_18": "MWPLVAALLLGSACCGSA",
"mature_cd47_igv_ectodomain_19_to_138_120aa": "QLLFNKTKSVEFTFCNDTVVIPCFVTNMEAQNTTEVYVKWKFKGRDIYTFDGALNKSTVPTDFSSAKIEVSQLLKGDASLKMDKSDAVSHTGNYTCEVTELTREGETIIELKYRVVSWFS",
"daf_cd55_retained_stalk_139_to_147_9aa": "PNKGSGTTS",
"daf_cd55_cleaved_gpi_propeptide_148_to_175_28aa": "GTTRLLSGHTCFTLTGLLGTLVTMGLLT",
"daf_cd55_c_terminal_gpi_signal_139_to_175_37aa": "PNKGSGTTSGTTRLLSGHTCFTLTGLLGTLVTMGLLT",
"omega_cleavage_site_residue": "Precursor Ser147 (native CD55/DAF Ser353 at the C-terminus of the 9-aa retained stalk PNKGSGTTS^GTTR...; Moran et al. 1991 J Biol Chem PMID:1824699; Xu et al. 2024 PMID:38508139), NOT Ser141 and NOT Ser152.",
"cleaved_mature_gpi_anchored_polypeptide_length_aa": 129,
"uncleaved_gpi_signal_retention_assay": "Gate 0A/0E Triton X-114 phase partitioning + PI-PLC release (>= 90% surface MFI release by PI-PLC confirms complete Ser147 [native CD55 Ser353] omega-site transamidation without ER retention of the 28-aa hydrophobic propeptide 148..175).",
},
"pulsed_human_pk_mimetic_ap1903_qualification_protocol": {
"clinical_pk_reference": "Human 0.4 mg/kg 2-h IV infusion of AP1903 (rimiducid; Iuliucci et al. 2001 J Clin Pharmacol PMID:11504275; Di Stasi et al. 2011 NEJM PMID:22047558) reaches plasma Cmax ~250-500 nM (~10-50 nM free drug in interstitial tissue) and decays to ~18%, 7%, and 1% of Cmax at 0.5, 2, and 10 h post-infusion.",
"stage0_gate_0s_pulsed_washout_regimen": (
"Replace static 24-72 h 10 nM bath as the sole primary Gate 0S readout with a human-PK-mimetic pulsed washout regimen: two 2-h pulses of 10-50 nM free AP1903 spaced 48 h apart (with drug-free media washout between pulses) under combined 2% O2 hypoxia + 0.5 uM thapsigargin, "
"requiring >= 4-log10 bulk kill and 0/299,573,228 clonogenic survivors with clinical-grade AP1903 monotherapy alone (obs_ap1903_monotherapy_pulsed_pk_log10_kill >= 4.0 and obs_ap1903_pulsed_pk_log10_kill >= 4.0; "
"100 nM birinapant SMAC mimetic is evaluated strictly as an exploratory in vitro mechanistic XIAP-depletion control and preclinical salvage comparator, not assumed in the human clinical monotherapy release gate; AUDIT-REF [DEC-050])."
),
},
}
# 4. Run data-linked Stage 0->7 perturbation simulator
perturbation_plane = simulate_stage0_to_stage7_perturbation_plane(ref, construct_verification, motif_scans)
ucoe_overlap_bp = int(
construct_verification["regulatory_element_audits"]["CBX3_A2UCOE_core_455bp_R17"]["avi_coordinate_overlap_bp"]
)
all_ha_non_overlapping = all(
int(c.get("homology_arm_overlap_bp", 0)) == 0 for c in construct_verification["constructs"]
)
all_orfs_clean = all(
int(c.get("internal_stop_codons", 0)) == 0
and int(c.get("internal_cryptic_splice_donors_GTAAGT_GTGAGT", 0)) == 0
for c in construct_verification["constructs"]
)
_canonical_fasta = {
blk.splitlines()[0].split()[0]: "".join(blk.splitlines()[1:]).strip().upper()
for blk in FASTA_OUT.read_text(encoding="utf-8").strip().split(">")[1:]
}
atlas = {
"schema_version": "0.8.0",
"layer": "Layer 2 — Single-Cell Perturbation & Regulatory Sequence Plane",
"status": "COMPUTATIONALLY_VERIFIED_REFERENCE_DESIGNS_AND_PRIOR_PERTURBATION_PLANE",
"summary": {
"ensembl_grch38_loci_mapped": len(ref["ensembl_grch38_loci"]),
"jaspar_pwms_scanned": len(pwms),
"ucsc_encode_chip_seq_regions_verified": len(ref["ucsc_encode_tfbs_summary"]),
"alphagenome_avi_snvs_archived_and_recomputed": None,
"archival_table_supplied_rows_private_quarantine": 3118,
"avi_model_predictions_available": False,
"alphagenome_avi_26_seed_anchors_verified": None,
"archival_highlighted_rows_count": 26,
"perturbation_profiles_total": len(perturbation_plane["perturbation_profiles"]),
"construct_cassettes_synthesized_and_audited": len(construct_verification["constructs"]),
"cbx3_a2ucoe_455bp_avi_coordinate_overlap_bp": ucoe_overlap_bp,
"all_homology_arms_non_overlapping_grch38_verified": all_ha_non_overlapping,
"all_construct_orfs_in_frame_and_canonical_donor_free": all_orfs_clean,
},
"ensembl_gencode_release_pairing": ref.get("ensembl_gencode_release_pairing", "Ensembl release 112 / GENCODE v46 (GRCh38.p14, 1-based closed coordinates; ENST00000309268.11 reconciled)"),
"ensembl_grch38_target_loci": ref["ensembl_grch38_loci"],
"gtex_v8_v10_human_tissue_expression": ref.get("gtex_v8_v10_human_tissue_expression", {}),
"human_protein_atlas_subcellular_localization": ref.get("human_protein_atlas_subcellular_localization", {}),
"encode_screen_2456_biosample_expression": ref.get("encode_screen_2456_biosample_expression", {}),
"encode_primary_human_islet_epigenomic_experiments": ref.get("encode_primary_human_islet_epigenomic_experiments", []),
"alphagenome_avi_saturation_mutagenesis_and_variants": avi_summary,
"alphagenome_atlas_locus_and_variant_deep_links": {
"B2M_locus1_promoter_and_exon1": "https://deepmind.google.com/science/alphagenome/atlas?q=chr15%3A44711000-44713000&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"CIITA_locus2_exons": "https://deepmind.google.com/science/alphagenome/atlas?q=chr16%3A10876500-10879000&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"CIITA_locus2_pan_isoform_exon5": "https://deepmind.google.com/science/alphagenome/atlas?q=chr16%3A10898500-10899500&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"CXCL10_locus3_isre_nfkb_promoter": "https://deepmind.google.com/science/alphagenome/atlas?q=chr4%3A76022500-76024500&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"AAVS1_PPP1R12C_locus4_intron1": "https://deepmind.google.com/science/alphagenome/atlas?q=chr19%3A55115000-55117000&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"HNRNPA2B1_CBX3_455bp_A2UCOE_insulator": "https://deepmind.google.com/science/alphagenome/atlas?q=chr7%3A26200580-26201034&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"CBX3_HNRNPA2B1_455bp_A2UCOE_insulator": "https://deepmind.google.com/science/alphagenome/atlas?q=chr7%3A26200580-26201034&m=locus&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
"TYK2_rs34536443_P1104A_protective_missense": "https://deepmind.google.com/science/alphagenome/atlas?q=chr19%3A10352442%3AG%3EC&m=variant&lItems=avi%2Csection%3ARNA_SEQ%2Csection%3ADNASE%2Csection%3ACHIP_TF",
},
"ucsc_encode_chip_seq_tf_clusters": ref["ucsc_encode_tfbs_summary"],
"ucsc_phylop100way_and_phastcons100way_conservation": ref["ucsc_conservation_summary"],
"jaspar_pwm_regulatory_motif_scans": motif_scans,
"construct_sequence_and_grammar_verification": construct_verification,
"stage0_to_stage7_perturbation_plane": perturbation_plane,
"stage0_core_construct_and_secretion_guardrails_iip_0011": {
"decision_id": "DEC-090",
"proposal_id": "IIP-0011",
"donor_slc30a8_znt8_precautionary_hold": {
"status": "EXCLUDED_FROM_LEAN_CORE_HOLD_FOR_ALLELE_AND_PROTOCOL_SPECIFIC_CHALLENGER_QUALIFICATION",
"context_stratified_evidence_summary": [
{
"citation": "Lamarche et al. 2025 PMID:41020949",