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…
if use_plan_b_hla_c_retained and not kir_ligand_group_explicitly_supplied:
active_qualification_holds.append(
"HOLD_B_PRIME_SCT_REQUIRES_EXPLICIT_RECIPIENT_KIR_LIGAND_GROUP_TYPING"
)
clinical_override_warnings.append(
"HOLD_B_PRIME_SCT_REQUIRES_EXPLICIT_RECIPIENT_KIR_LIGAND_GROUP_TYPING: Track 2 HLA-C-bearing routing (B'-SCT or endogenous HLA-C) cannot rely on an imputed C1/C2 default "
"and requires explicit recipient KIR ligand genotyping (C1/C1, C2/C2, or C1/C2; AUDIT-REF & MW-R6-S2-R5 [DEC-051/053])."
)
if (
use_b_prime_sct_k4
and kir_ligand_group in {"C1/C2", "C2/C1"}
and not c1c2_heteroallelic_phased_verified
):
active_qualification_holds.append(
"HOLD_C1C2_HETEROALLELIC_CIITA_SCT_REQUIRES_PHASED_LONGREAD_AND_DDPCR_VERIFICATION"
)
if (
0.30 <= kir_licensed_nkg2a_neg_fraction < 0.48
and arm1b_cd47_sirpa_nk_cliff_unverified
and not track1_sorted_kir_nk_cleared
):
active_qualification_holds.append(
"HOLD_MODERATE_KIR_NK_REQUIRES_SORTED_KIR_NKG2A_NEG_NK_OR_TRACK2_B_SCT"
)
if single_200cm2_pouch_forced_without_modular_scaling and areal_loading_at_fixed_200cm2 > 1500.0:
active_qualification_holds.append(
"HOLD_SINGLE_POUCH_AREAL_OVERLOAD_EXCEEDS_1500_IEQ_CM2_CHRONIC_CAP"
)
orthogonal_autoimmune_gate_indicated = bool(
autoantigen_t_cell_titer >= 2.0 or tyk2_independent_ifng_tnfa_or_indirect_dr3_dq8_hazard
)
if orthogonal_autoimmune_gate_indicated and not gate0_indirect_dr3_dq8_and_ifng_tnfa_stress_cleared:
active_qualification_holds.append(
"HOLD_TYK2_INDEPENDENT_IFNG_TNFA_AND_INDIRECT_DR3_DQ8_CLEARANCE_REQUIRED"
)
clinical_override_warnings.append(
"HOLD_TYK2_INDEPENDENT_IFNG_TNFA_AND_INDIRECT_DR3_DQ8_CLEARANCE_REQUIRED: high pre-existing beta-cell autoantigen T-cell reactivity "
f"(z = {autoantigen_t_cell_titer:.2f} >= 2.0) or explicit TYK2-independent IFN-gamma/TNF-alpha + indirect HLA-DR3/DQ8 CD4+ T-cell hazard "
"requires Stage-0 Gate 0D-indirect / Gate 0E-cytokine orthogonal stress clearance (gate0_indirect_dr3_dq8_and_ifng_tnfa_stress_cleared=True) "
"because TYK2 P1104A catalytic attenuation covers Type-I IFN (IFNAR1/2) and IL-12/IL-23 signaling but not JAK1/JAK2-mediated IFN-gamma or "
"recipient APC-mediated indirect CD4+ presentation (AUDIT-REF & AUDIT-REF [DEC-050])."
)
if active_qualification_holds:
prod_qual_status = active_qualification_holds[0]
elif use_b_prime_sct_k4:
prod_qual_status = "SEQUENCE_COMPLETE_IN_SILICO_CANDIDATE_REQUIRING_WETLAB_RELEASE_QC"
elif use_plan_b_hla_c_retained:
prod_qual_status = "INVESTIGATIONAL_PLACEHOLDER_SEPARATE_HLAA_HLAB_DONOR_LEDGER_UNRESOLVED"
else:
prod_qual_status = "SEQUENCE_COMPLETE_IN_SILICO_CANDIDATE_REQUIRING_WETLAB_RELEASE_QC"
routing_holds_cleared = len(active_qualification_holds) == 0
product_exec_ok = bool(
product.get("execution_supported") is True
and not str(product.get("physical_qualification_status", "")).upper().startswith("RESEARCH")
)
in_silico_candidate_routing_cleared = bool(routing_holds_cleared and product_exec_ok)
required_recipient_hazard_keys = {
"recipient_anti_hla_e_dsa",
"cmv_nkg2c_adaptive_nk_fraction",
"recipient_bw4_kir3dl1_educated",
"exact_product_non_hla_and_sct_flow_crossmatch_negative",
}
if selected_track != "TRACK_3_PERSONALIZED_AUTOLOGOUS_PATIENT_IPSC":
required_recipient_hazard_keys.add("recipient_cpra_pct")
if orthogonal_autoimmune_gate_indicated:
required_recipient_hazard_keys.add("gate0_indirect_dr3_dq8_and_ifng_tnfa_stress_cleared")
if use_plan_b_hla_c_retained:
required_recipient_hazard_keys.update({"recipient_kir_ligand_group", "recipient_anti_hla_c_dsa", "hlac_4digit_relation"})
if kir_ligand_group in {"C2/C2", "C1/C2", "C2/C1"}:
required_recipient_hazard_keys.add("recipient_activating_kir2ds1_unlicensed_hazard")
if use_b_prime_sct_k4 and kir_ligand_group in {"C1/C2", "C2/C1"}:
required_recipient_hazard_keys.add("c1c2_heteroallelic_phased_longread_ddpcr_verified")
recipient_immune_hazard_panel_explicitly_measured = (
all(k in patient and patient.get(k) is not None for k in required_recipient_hazard_keys)
and not exact_product_crossmatch_explicit_false
and patient.get("exact_product_non_hla_and_sct_flow_crossmatch_negative") is True
and (
not orthogonal_autoimmune_gate_indicated
or patient.get("gate0_indirect_dr3_dq8_and_ifng_tnfa_stress_cleared") is True
)
)
wetlab_stage0_complete_lot_release_verified = _validate_strict_bool(
_get_opt(patient, "wetlab_stage0_complete_lot_release_verified", False),
"wetlab_stage0_complete_lot_release_verified",
)
lot_release_cleared = bool(
in_silico_candidate_routing_cleared
and product.get("execution_supported") is True
and product.get("physical_qualification_status") == "QUALIFIED"
and recipient_immune_hazard_panel_explicitly_measured
and wetlab_stage0_complete_lot_release_verified
)
product_execution_release_status = (
"ELIGIBLE_CANDIDATE_PENDING_STAGE0_LOT_RELEASE"
if product_exec_ok
else "HOLD_NON_EXECUTABLE_RESEARCH_OR_COMPARATOR_PRODUCT"
)
return {
"patient_id": patient_id,
"ancestry": ancestry,
"product_variant_id": variant_id,
"selected_product_id": variant_id,
"default_promoted_track2_subbank_product_id": default_promoted_track2_subbank_product_id,
"product_definition": product,
"product_execution_release_status": product_execution_release_status,
"score_qualification": "ASSIGNED_RULE_SCENARIO_NOT_COMPLETE_PRODUCT",
"selected_fda_deployment_track": selected_track,
"clinical_override_warnings": clinical_override_warnings,
"track3_autologous_vs_allogeneic_scope_note_v80_088": (
"In Track 3 (autologous patient iPSC), host-vs-graft alloreactive MHC mismatch is absent, but autoreactive "
"T1D memory CD8+ (PPI/IGRP/ZnT8/GAD65) and CD4+ T-cell protection still requires MHC-I/II + CXCL10::SERPINB9-P2A-PD-L1 "
"or selective autoimmune shielding (AUDIT-REF)."
),
"sequence_compiler_execution_supported": product["execution_supported"],
"physical_product_qualification_status": product["physical_qualification_status"],
"product_qualification_status": prod_qual_status,
"selected_product_qualification_status": prod_qual_status,
"all_active_qualification_holds": active_qualification_holds,
"routing_holds_cleared": routing_holds_cleared,
"in_silico_candidate_routing_cleared": in_silico_candidate_routing_cleared,
"recipient_immune_hazard_panel_explicitly_measured": recipient_immune_hazard_panel_explicitly_measured,
"wetlab_stage0_complete_lot_release_verified": wetlab_stage0_complete_lot_release_verified,
"lot_release_cleared": lot_release_cleared,
"regulatory_hypothesis_pending_qualified_assessment": (
"Investigational regulatory hypothesis: potential eligibility for FDA Platform Technology Designation "
"(21 U.S.C. 356k, subject to statutory prerequisite of an approved drug/biologic using the platform) "
"or CBER draft/nonbinding Individualized Plausible-Mechanism guidance (Feb 2026) requires formal FDA CBER INTERACT/pre-IND assessment (closing AUDIT-REF)."
),
"locus1_construct_prescribed": locus1_arm,
"mhc_locus_routing_contract_iip_0026": {
"class_i_routing_mode": (
"B2M_NULL_CIITA_EXON5_HLA_C_SCT"
if use_b_prime_sct_k4
else (
"ENDOGENOUS_HLA_C_RETAINED_SELECTIVE_HLA_AB_KO_PENDING_PHASED_DONOR_QC"
if use_plan_b_hla_c_retained
else "B2M_NULL_HLA_E_SCT_CD47_IGV_GPI"
)
),
"ciita_target_locus_id": "OI-GRNA-02_CIITA_EXON5_ASCAS12A",
"b2m_retained_wt": bool(use_plan_b_hla_c_retained and not use_b_prime_sct_k4),
"selective_hla_ab_ko_required": bool(use_plan_b_hla_c_retained and not use_b_prime_sct_k4),
"hla_ab_guide_qualification_state": (
"SCOPED_EXON23_CANDIDATE_POOL_11_HLAA_6_HLAB_REQUIRES_PHASED_DONOR_HLA_ABCE_QC"
if (use_plan_b_hla_c_retained and not use_b_prime_sct_k4)
else "NOT_APPLICABLE"
),
"intended_routing_decoupled_from_wetlab_release_supported": True,
},
"plan_architecture_prescribed": (
"Plan B-SCT (B2M::Arm1B + CIITA::HLA-C*03:04/04:01 Fixed-Peptide SCT)"
if use_b_prime_sct_k4
else (
"Plan B (Selective HLA-A/HLA-B KO + KIR-Matched Retained HLA-C1/C2 Sub-Bank + HLA-E SCT + CD47-IgV)"
if use_plan_b_hla_c_retained
else "Plan A (Core 4-Locus Tri-Modal B2M::HLA-E-CD47-IgV + CIITA-/- + CXCL10::SERPINB9-P2A-PD-L1 + AAVS1-iCasp9)"
)
),
"plan_b_chr6p21_cis_deletion_hazard_and_sequential_editing_gate_kimi_r3_001": (
"On GRCh38 chr6p21.3, physical gene order is HLA-A (29.94 Mb) -> HLA-E (30.49 Mb) -> HLA-C (31.27 Mb) -> HLA-B (31.35 Mb); "
"simultaneous DSB multiplexing of HLA-A and HLA-B is prohibited in Plan B due to the ~1.41 Mb interstitial cis-deletion/inversion "
"risk removing intervening HLA-E and retained HLA-C. Requires sequential clonal passes or non-DSB editing plus phased HLA-A/E/C/B ddPCR and OGM verification. "
"Note on HLA-C leader-peptide selection (Lin et al. 2023 Nat Immunol PMID:37264229, PMC10690437, DOI:10.1038/s41590-023-01523-z; AUDIT-REF, Q2-P1..P3, AUDIT-REF, & AUDIT-REF): "
"because HLA-C*07:02 encodes the non-functional SP-3C (VMAPRALLL, carrying P6=Ala [T6A, with P5=Arg]) leader peptide (24.49% of 1000G alleles) that fails to stabilize surface HLA-E, "
"Design B-prime upgrades the C1/C1 sub-bank anchor to functional SP-1C (VMAPRTLIL) HLA-C*01:02 or HLA-C*03:04 (alongside SP-1C C2 anchor HLA-C*04:01) "
"and co-integrates exogenous HLA-E*01:03(SCT) + CD47-IgV-GPI at AAVS1 Locus 4 (subject to physical FASTA materialization and complexity-discount accounting: "
"analytic personalized scenario index is 97.50% unpenalized, 92.84% under K/B complexity discounting vs 92.50% Plan A, and 91.37% unpenalized / 87.65% complexity-discounted if the unmaterialized safe-harbor cloak is omitted; AUDIT-REF & AUDIT-REF). "
"Note on K/B indexing (AUDIT-REF & AUDIT-REF [DEC-078]): Layer-5 Track-2 Plan B indexes the 5 DSB/indel loci (HLA-A, HLA-B, CIITA, CXCL10, AAVS1; K=5, B=0 or B=1 with optional TYK2 P1104A PE), "
"whereas Layer-1 Chassis B (ISLET1_B6, global Rank #25, K=6, B=1) indexes 6 DSB/indel loci (HLA-A, HLA-B, CIITA, CXCL10, AAVS1, plus TYK2 knock-out as the 6th DSB/indel locus) and the INS signal-peptide/DRiP base edit as B=1 "
"(and the separate K=5, B=1 TYK2 P1104A prime-edited variant is ISLET1_B2_5LOCUS_TYK2_PE)."
if use_plan_b_hla_c_retained
else None
),
"include_tyk2_p1104a_rs34536443_shield": include_tyk2_p1104a_edit,
"final_graft_tyk2_p1104a_protective_state": final_graft_tyk2_p1104a_protective_state,
"editing_complexity_and_manufacturing_accounting_v80_009": {
"k_dsb_or_indel_chromosomal_loci": k_dsb_loci,
"b_prime_or_base_edit_loci": b_prime_loci,
"tyk2_alleles_requiring_prime_edit_count": tyk2_alleles_to_edit,
"uncloned_simultaneous_pass_yield_prior": None,
"physical_manufacturing_yield_evidence_status": "NOT_MEASURED",
"ranker_engineering_complexity_discount_factor": ranker_utility_penalty_factor,
"engineering_utility_prior_parameters": {"lambda_K": params["lambda_K"], "gamma_B": params["gamma_B"]},
"gate_zero_donor_wgs_and_precloning_junction_recleavage_gate_muse_r1": (
"Gate 0 (prior to guide lock and HIP-Core clone generation): perform 30x whole-genome sequencing (WGS) + phased "
"HLA/KIR/SIRPA(V1/V2/V8) genotyping of the candidate Master Cell Bank hPSC line to confirm zero PAM/seed SNVs across all "
"5 guide target windows, followed by Cas-OFFinder + empirical GUIDE-seq/CAST-seq in the actual hPSC line and a pre-cloning "
"T7E1/amplicon-NGS junction re-cleavage assay on synthetic edited-allele amplicons across B2M, CIITA, CXCL10, and AAVS1 "
"(AUDIT-REF & D5-02)."
),
"two_pass_clonal_mcb_release_qc_policy": (
"Assigned-rule scenario values in evaluate_regimen_survival_probability are conditioned on a hypothetical "
"release-qualified Master Cell Bank (MCB) clone that has passed two-pass clonal screening (2 chromosomal loci x 2 "
"homologous alleles = 4 target alleles per pass), junction-spanning AAV6 ITR-capture ddPCR (<0.1% vector-backbone/ITR "
"concavemer or off-locus capture at CIITA/CXCL10/AAVS1; Hanlon et al. 2019 PMID:31570731; AUDIT-REF & D6-F03), "
">=63,000x TP53 duplex-seq (>=62,958 independent duplex molecules), and 20q11.21 ddPCR. Physical uncloned yield is unmeasured. "
"The separate dimensionless engineering utility discount is exp(-lambda_K * max(0, K - 4)) * gamma_B ** B; "
"it is not manufacturing yield or a fitted clinical probability."
),
},
"host_modifier_genotypes_and_dosing": {
"ifih1_rs1990760_genotype": ifih1_genotype,
"donor_ifih1_rs1990760_genotype": donor_ifih1_genotype,
"donor_ifih1_rs1990760_provenance": {
"input_status": (
"MEASURED_DONOR_INPUT"
if "donor_ifih1_rs1990760_genotype" in patient
and patient["donor_ifih1_rs1990760_genotype"] is not None
and donor_ifih1_genotype != "UNMEASURED"
else "UNMEASURED_PROVENANCE_ONLY"
),
"variant_provenance": (
"Provenance-only donor seed-line record for common GWAS IFIH1 rs1990760 (GRCh38 minus-strand coding c.2836G>A, "
"p.Ala946Thr; Smyth et al. 2006 PMID:16699517), explicitly separated from recipient IFIH1 risk scoring and from "
"rare loss-of-function rs35744605 (p.Glu627Ter / E627*; Nejentsev et al. 2009 PMID:19264985; SC-islet functional "
"comparison in Veronese-Paniagua et al. 2025 PMID:42787837). Zero effect on K, B, prescribed regimen, or survival."
),
"affects_k_b_regimen_or_survival": False,
"primary_citations": ["PMID:16699517", "PMID:19264985", "PMID:42787837"],
},
"ptpn22_rs2476601_genotype": ptpn22_genotype,
"recipient_hla_e_genotype": recipient_hla_e,
"tyk2_rs34536443_genotype": recipient_tyk2_genotype,
"recipient_tyk2_rs34536443_genotype": recipient_tyk2_genotype,
"donor_tyk2_rs34536443_genotype": donor_tyk2_genotype,
"starting_graft_tyk2_rs34536443_genotype": starting_graft_tyk2_genotype,
"tyk2_alleles_requiring_prime_edit_count": tyk2_alleles_to_edit,
"already_homozygous_tyk2_p1104a": already_homozygous_tyk2_p1104a,
"final_graft_tyk2_p1104a_protective_state": final_graft_tyk2_p1104a_protective_state,
"recipient_kir_ligand_group": kir_ligand_group,
"recipient_bmi_kg_m2": recipient_bmi,
"prescribed_curative_dose_ieq": prescribed_dose_ieq,
"prescribed_dose_source_mode": dose_source_mode,
"areal_loading_ieq_per_cm2_if_fixed_200cm2_pouch": areal_loading_at_fixed_200cm2,
"required_pouch_exchange_area_cm2_at_nominal_2500_ieq_cm2": required_pouch_area_cm2_at_2500_ieq_cm2,
"required_pouch_exchange_area_cm2_at_chronic_lowload_1500_ieq_cm2": required_pouch_area_cm2_at_1500_ieq_cm2,
"modular_100cm2_omental_cassette_count_at_1500_ieq_cm2": modular_100cm2_omental_cassette_count_at_1500_ieq_cm2,
"actual_areal_loading_ieq_per_cm2_across_modular_cassettes": actual_areal_loading_ieq_per_cm2_across_modular_cassettes,
"recipient_immunological_screen_completeness_status": recipient_immunological_screen_completeness_status,
"dosing_model_qualification_note": (
"Illustrative BMI-proportional scaling (500,000 IEQ * BMI / 24.0) or explicit prescribed_dose_ieq override; "
"clinical islet dosing requires actual recipient body weight (kg), baseline insulin requirement, and proportional "
"scaling of pouch exchange area (A = Dose / 2,500 IEQ/cm^2 nominal, or A = Dose / 1,500 IEQ/cm^2 = 333.33 cm^2 at "
"500,000 total IEQ under DX-B-LowLoad-1500 chronic zero-source encapsulation via modular 100 cm^2 omental cassettes)."
),
"optional_field_input_provenance": optional_field_provenance,
},