scripts/run_layer5_personalized_patient_compiler.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/run_layer5_personalized_patient_compiler.py · SHA-256: 0b285369ac6e4409…
},
"wgs_only_denominators": {
"pass_wgs_alleles": wgs_pass,
"flagged_wgs_alleles": wgs_flagged,
"unresolved_wgs_alleles": wgs_unresolved,
},
"exome_only_denominators": {
"pass_exome_alleles": exome_pass,
"flagged_exome_alleles": exome_flagged,
"unresolved_exome_alleles": exome_unresolved,
},
"guides_with_pass_wgs_non_target_global_af_ge_0_0001": guides_with_pass_wgs_non_target_ge_1e4,
"hlac_sentinel_variants": hlac_sentinels,
"per_guide_receipts": per_guide_69,
},
"hlac_17_record_and_hla_ab_exon23_candidate_audit": {
"total_sequence_records_evaluated": 17,
"grch38_reference_records_count": 1,
"insdc_sampled_records_count": 16,
"zero_ipd_imgt_hla_cc_by_nd_used": True,
"exon_boundary_counting_conventions": {
"HLA_A": hla_a_conv,
"HLA_B": hla_b_conv,
"convention_note": (
"Nominal SpCas9 cut inside canonical Ensembl Exon 2 or 3 yields 114 HLA-A and 115 HLA-B NGG guides "
"(used for the 17->11 HLA-A and 10->6 HLA-B < 0.05 WT-CFD screen across 17 HLA-C records and 64 NNN PAMs), "
"whereas requiring the entire 23-mer (20-nt spacer + 3-nt PAM) wholly inside Exon 2 or 3 yields 106 HLA-A and 108 HLA-B guides."
),
},
"hla_a_exon23_all_nnn_audit": r3_cfd["hla_a_exon23_all_nnn_audit"],
"hla_b_exon23_all_nnn_audit": r3_cfd["hla_b_exon23_all_nnn_audit"],
"full_record_10_to_11_mismatch_non_exon_hits": r3_cfd["full_record_non_exon_hits"],
"dt9_hlae_crossreactivity_specificity_control_rule": (
"Per Corrah et al. 2011 (PMID:21248048), mAb DT9 cross-reacts with HLA-E; therefore DT9 + 3D12 co-staining "
"requires a matched HLA-E-only (HLA-C-null) specificity control (delta ratio >= 2.0x) or orthogonal allele-specific "
"HLA-C surface/phased mRNA verification before clearing endogenous HLA-C retention."
),
"per_record_callable_coverage_ledger": coverage_ledger_17,
},
"mode_a_vs_held_mode_b_pam_shields_and_12_alignments": {
"cxcl10_locus3_ha_r": r5_cfd["cxcl10_locus3_ha_r"],
"aavs1_locus4_ha_r": r5_cfd["aavs1_locus4_ha_r"],
"nominated_grch38_alignments_12_across_11_windows": {
"total_alignments": 12,
"unique_genomic_windows": 11,
"cbe08_tet1_pam_reconciliation": "19-bp 1-bp-RNA-bulged + 1-mm target + 3' GGT SpG PAM followed by TTC (NOT GGG)",
"alignments_doench2016_cfd": r5_cfd["alignments_doench2016_cfd"],
},
"segmented_phased_haplotype_baf_rule": {
"segment_mean_interval": [0.45, 0.55],
"min_phased_het_snps": 50,
"per_snp_50_independent_100x_false_pass_prob": round((sum(math.comb(100, k) for k in range(45, 56)) / (2 ** 100)) ** 50, 12),
"phased_50snp_100x_segment_mean_sd": round(0.5 / math.sqrt(5000.0), 6),
},
},
"tyk2_pe2max_lead_vs_held_pe4max_and_7c_classes": {
"combinatorial_7c_subsets_total": 127,
"other_missense_classes_count": other_missense_cnt,
"unchanged_synonymous_wt_spp_classes": unchanged_spp,
"desired_sap_classes": desired_sap,
"conditioned_on_c7_other_missense_and_sap": [cond_c7_other, cond_c7_sap],
"pam_creating_pe3b_guides_count": 0,
"overlapping_minus_ngg_wt_cfd": r4_cfd,
"alphamissense_v3_zenodo_10813168_p29597_bgzf_verification": am_bgzf,
"pe4max_fail_msi_distinct_from_hold_missing_msi": True,
"pe4max_piecewise_repeat_indel_cap": {
"c_ctrl_le_25_additive_allowance": 5,
"c_ctrl_gt_25_relative_multiplier": 1.2,
"coding_or_splice_de_novo_indels_allowed": 0,
},
},
"held_design_y_gt_preserving_ddpcr_and_twinpe_comparators": {
"deployment_status": "HELD_EXPLORATORY_TEMPLATE_SPECIFICATION_NOT_ACTIVE_RELEASE_GATE",
"gt_preserving_6site_amplicon_lengths_bp": [163, 142, 142, 167, 135, 142],
"active_attb_donor_pseudo_attp_sites_count": 2,
"inverted_attp_donor_pseudo_attb_nominations_count": 4,
"ddpcr_poisson_lod_sizing": {
"single_30000_ge_well_prob_k_ge_3": round(_poisson_ge3(3.0), 6),
"single_30000_ge_is_95pct_lod": False,
"single_analytical_unit_exact_min_ge_for_95pct": 62958,
"single_analytical_unit_protocol_floor_ge": 63000,
"single_analytical_unit_63000_ge_prob_k_ge_3": round(_poisson_ge3(6.3), 6),
"pooled_3x30000_ge_total_ge": 90000,
"pooled_90000_ge_prob_k_total_ge_3": round(_poisson_ge3(9.0), 6),
},
"b2m_twinpe_local_200bp_window_wt_cfd": r2_cfd,
},
"oq016_2pow12_portfolio_invariance": {
"design_a_standalone_pct": round(100.0 * math.prod(pa_vec), 4),
"design_b_standalone_pct": round(100.0 * math.prod(pb_vec), 4),
"design_x_standalone_pct": round(100.0 * math.prod(px_vec), 4),
"shared_ax_locked_pct": base_ax_pct,
"three_slot_locked_pct": base_3_pct,
"single_arm_pb1_0p55_hypothetical_downside": {
"scope_note": "Single-arm pb1 = 0.55 sensitivity outside shared-H1 (A and X held at 0.88; active baseline unchanged)",
"design_b_standalone_pct": round(100.0 * math.prod(pb_eroded), 3),
"shared_ax_locked_pct": round(erod_ax_pct, 3),
"three_slot_locked_pct": round(erod_3_pct, 3),
},
},
}
def build_layer5_atlas() -> Dict[str, Any]:
"""Build the complete report from the same current objects used for every numeric summary."""
part_a = build_part_a_crispr_grna_and_polymorphism_atlas()
part_b = simulate_10000_patient_global_population_trial()
part_a["alphamissense_v3_ccby4_provenance_iip_0017"] = _build_alphamissense_v3_ccby4_provenance_iip_0017()
part_b["design_b2_tyk2_p1104a_hlac_neoantigen_qualification_note_iip_0017"] = _build_design_b2_tyk2_hlac_qualification_note_iip_0017()
part_b["product_scoped_precedence_and_stealth_axes_audit_iip_0024"] = _build_product_scoped_precedence_audit_iip_0024()
iip0026_audit = _build_variant_aware_gnomad_hlac_pe4max_and_designy_audit_iip_0026()
part_a["variant_aware_gnomad_hlac_pe4max_and_designy_audit_iip_0026"] = iip0026_audit
_g_ov_block = next((v for k, v in part_a.items() if k.startswith("gnomad_v4_1_and_dbsnp_guide_overlap_audit")), {})
for _gid_k, _g_rec in iip0026_audit["gnomad_v4_1_69key_normalized_join"]["per_guide_receipts"].items():
if _gid_k in _g_ov_block.get("per_guide_interval_polymorphism_summary", {}):
_g_ov_block["per_guide_interval_polymorphism_summary"][_gid_k][
"normalized_69key_gnomad_r4_receipt_iip_0026"
] = _g_rec
atlas = {
"schema_version": "0.8.0",
"layer": "Layer 5 — Personalized Patient-DNA & Multiplex CRISPR Compiler + 10,000-Patient Global Population Trial",
"status": "AUTHENTIC_GRCH38_GRNA_THERMODYNAMICS_DBSNP_CLINVAR_AND_10K_POPULATION_SIMULATION",
"evidence_class": "in_silico_crispr_compiler_and_illustrative_population_scenario_simulation_requiring_wetlab_validation",
"summary": {
"total_guides_compiled": len(part_a["guides"]),
"all_guides_verified_0_mismatch_to_grch38": all(
g["grch38_reference_exact_match_verified"] for g in part_a["guides"]
),
"coding_off_targets_0_to_2_mismatches": (
sum(g["grch38_0_1_2_mismatch_coding_off_targets"] for g in part_a["guides"])
if all(g["grch38_0_1_2_mismatch_coding_off_targets"] is not None for g in part_a["guides"])
else None
),
"genomewide_off_target_enumeration_status": "NOT_ENUMERATED",
"any_intact_target_in_hdr_donors": any(
g["intact_target_present_in_any_hdr_donor_plasmid"] for g in part_a["guides"]
),
"any_intact_target_in_post_hdr_edited_alleles": any(
g["intact_target_present_in_post_hdr_edited_allele_either_strand"] for g in part_a["guides"]
),
"total_virtual_patients_simulated": part_b["total_virtual_patients_simulated"],
"global_5yr_survival_hla_e_only_pct": part_b["global_5yr_survival_hla_e_only_pct"],
"global_5yr_survival_standardized_plan_a_pct": part_b["global_5yr_survival_standardized_openislet_plan_a_pct"],
"global_5yr_survival_personalized_compiled_pct": part_b[
"global_5yr_survival_personalized_dna_compiled_openislet_pct"
],
"global_5yr_survival_ablated_compiler_control_pct": part_b[
"global_5yr_survival_ablated_compiler_control_pct"
],
"global_analytic_expected_5yr_survival_personalized_compiled_pct": part_b["global_analytic_expected_5yr_survival_personalized_compiled_pct"],
"global_analytic_expected_5yr_survival_standardized_plan_a_pct": part_b["global_analytic_expected_5yr_survival_standardized_plan_a_pct"],
"analytic_max_ancestry_disparity_gap_personalized_pct": part_b["analytic_max_ancestry_disparity_gap_personalized_pct_v80_065"],
"sampled_max_ancestry_disparity_gap_personalized_pct": part_b["sampled_max_ancestry_disparity_gap_personalized_pct"],
"sampled_ancestry_gap_method": {
"seed": 20261023,
"n_per_cohort": 2000,
"method": (
"hybrid deterministic low-discrepancy HWE stratification (coprime multiplier 997 mod 10000 for TYK2 rs34536443 "
"and 7919 mod 1000 for KIR C1/C2 ligand group, paired with np.random.default_rng(20261023) binomial/Gaussian draws "
"for SIRPA, IFIH1, PTPN22, HLA-E, BMI, and continuous NK/autoantigen/IFN-I covariates); analytic_expected_* metrics "
"average exact survival probabilities p_i over the 2,000 sampled covariate profiles per cohort prior to Bernoulli indicator sampling (AUDIT-REF)"
),
},
},
"part_a_crispr_grna_compiler_and_polymorphism_audit": part_a,
"part_b_personalized_patient_compiler_and_10k_population_trial": part_b,
"alphamissense_v3_ccby4_provenance_iip_0017": part_a["alphamissense_v3_ccby4_provenance_iip_0017"],
"variant_aware_gnomad_hlac_pe4max_and_designy_audit_iip_0026": iip0026_audit,
}
return atlas
def main() -> None:
atlas = build_layer5_atlas()
part_a = atlas["part_a_crispr_grna_compiler_and_polymorphism_audit"]
part_b = atlas["part_b_personalized_patient_compiler_and_10k_population_trial"]
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
with OUT_PATH.open("w", encoding="utf-8") as f:
json.dump(atlas, f, indent=2)
f.write("\n")
print(f"[Layer 5 v0.8.0] Wrote {OUT_PATH}")
for g in part_a["guides"]:
print(
f" [gRNA] {g['guide_id']}: {g['target_locus_grch38']} | PAM={g['pam_sequence_5to3']} | "
f"GC={g['gc_percent']}% | Sugimoto_dG37={g['sugimoto_1995_rna_dna_hybrid_dg37_kcal_mol']} kcal/mol | "
f"in_donor={g['intact_target_present_in_any_hdr_donor_plasmid']} | "
f"in_post_hdr={g['intact_target_present_in_post_hdr_edited_allele_either_strand']}"
)
print(
f" [10k Trial] Unedited={part_b['global_5yr_survival_unedited_allogeneic_pct']}% | "
f"HLA-E-Only={part_b['global_5yr_survival_hla_e_only_pct']}% | "
f"Standardized Plan A={part_b['global_5yr_survival_standardized_openislet_plan_a_pct']}% | "
f"Personalized Compiled={part_b['global_5yr_survival_personalized_dna_compiled_openislet_pct']}% | "
f"Ablated Control={part_b['global_5yr_survival_ablated_compiler_control_pct']}% "
f"(Analytic ancestry gap={part_b['analytic_max_ancestry_disparity_gap_personalized_pct_v80_065']} pp; "
f"sampled secondary={part_b['sampled_max_ancestry_disparity_gap_personalized_pct']} pp)"
)
if __name__ == "__main__":
main()