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…
'ISLET1_B_SCT_C1_CIITA / ISLET1_B_SCT_C2_CIITA / ISLET1_B_SCT_C1C2_CIITA (Track-2 '
"B'-SCT with B2M-/-)"],
'routing_restriction': 'Population rs34536443 allele frequencies (2.7-4.2% C -> ~91.8-94.7% G/G) cannot classify '
'individual recipients, natural C/C or G/C genotype does not establish peripheral tolerance to '
'SAPTKFLEL across endocrine and vascular iEC/pericyte compartments, and an in-silico MHCflurry '
'affinity cutoff (e.g., HLA-C*04:01 448.93 nM) never auto-authorizes clinical routing. Any '
'evaluation of Design B2 (ISLET1_B2_5LOCUS_TYK2_PE) requires clearing the Stage-0 Gate 0B '
'empirical OR-hold presentation and CD8+ killing gate across unpooled recipient TYK2 genotype '
'strata (G_G, G_C, C_C) alongside preserved Rule S8 5xISRE/CXCL10 promoter-induction and Stage '
'0->7 yield checks (Boisson-Dupuis et al. 2018 PMID:30578352; Chandra et al. 2022 '
'PMID:36289205; GY-001).'}
def evaluate_product_scoped_routing_and_stealth_axes_iip_0024(
patient: Dict[str, Any],
*,
target_product_def: Dict[str, Any] | None = None,
) -> Dict[str, Any]:
"""
Evaluate target-product-scoped component-failure precedence and 3-valued
(True / False / 'UNKNOWN') independent stealth axes (CD47-SIRPA, HLA-E-NKG2A,
HLA-C-KIR) without allowing composite B'-SCT flags to override explicit
component failures or cross-contaminate inapplicable products (IIP-0024; DEC-103).
"""
from scripts.product_contract import get_product_definition
if target_product_def is not None:
prod = dict(target_product_def)
else:
raw_pvid = patient.get("product_variant_id")
if isinstance(raw_pvid, str) and raw_pvid.strip():
prod = get_product_definition(raw_pvid, root=REPO_ROOT)
else:
prod = get_product_definition("ISLET1_A4_ARM1B", root=REPO_ROOT)
pvid = str(prod["product_variant_id"])
is_b_sct = pvid.startswith("ISLET1_B_SCT_")
is_endo_b = pvid.startswith(("ISLET1_B1_", "ISLET1_B2_"))
is_plan_b = is_b_sct or is_endo_b
carries_exogenous_hlae_sct = pvid.startswith("ISLET1_A") or is_b_sct or pvid.startswith("ISLET1_Z_")
holds: List[str] = []
if is_b_sct:
if patient.get("b_prime_sct_recipient_cd8_mlc_negative") is False:
holds.append("HOLD_TARGET_BSCT_CD8_MLC_FAILED_OVERRIDES_COMPOSITE")
if patient.get("b_prime_sct_exact_product_serum_cdc_adcc_crossmatch_negative") is False:
holds.append("HOLD_TARGET_BSCT_SERUM_CROSSMATCH_FAILED")
if ("C2" in pvid or "C1C2" in pvid) and patient.get("b_prime_sct_kir2ds1_non_activation_cleared") is False:
holds.append("HOLD_TARGET_BSCT_KIR2DS1_NON_ACTIVATION_FAILED")
if carries_exogenous_hlae_sct:
if patient.get("exact_hlae_sct_serum_crossmatch_negative") is False:
holds.append("HOLD_TARGET_EXACT_HLAE_SCT_SERUM_CROSSMATCH_FAILED")
if patient.get("gate0a_nkg2c_adaptive_nk_cleared") is False:
holds.append("HOLD_TARGET_GATE0A_NKG2C_ADAPTIVE_NK_FAILED")
if patient.get("exact_product_non_hla_and_sct_flow_crossmatch_negative") is False:
holds.append("HOLD_TARGET_NON_HLA_FLOW_CROSSMATCH_FAILED")
raw_rel = patient.get("hlac_4digit_relation")
eff_rel = raw_rel.strip().upper() if isinstance(raw_rel, str) and raw_rel.strip() else ("UNSPECIFIED" if is_endo_b else "NOT_APPLICABLE")
if is_endo_b and eff_rel == "UNSPECIFIED":
holds.append("HOLD_ENDOGENOUS_HLAC_UNSPECIFIED_4DIGIT_ALLOTYPE_REQUIRES_TYPING_AND_MLC")
sirpa_raw = patient.get("sirpa_genotype")
cd47_comp = patient.get("cd47_sirpa_binding_compromised")
if cd47_comp is True:
cd47_axis: Any = False
elif sirpa_raw is None or "v8" in str(sirpa_raw).lower():
cd47_axis = "UNKNOWN"
holds.append("HOLD_UNMEASURED_STEALTH_AXIS:CD47_SIRPA")
else:
cd47_axis = True
if not carries_exogenous_hlae_sct:
if not is_endo_b:
hlae_axis: Any = False
elif patient.get("endogenous_sp1c_hlae_stabilization_verified") is None:
hlae_axis = "UNKNOWN"
holds.append("HOLD_UNMEASURED_STEALTH_AXIS:ENDOGENOUS_SP1C_HLAE_NKG2A")
else:
hlae_axis = bool(patient["endogenous_sp1c_hlae_stabilization_verified"])
else:
xm_val = patient.get("exact_hlae_sct_serum_crossmatch_negative")
if xm_val is False:
hlae_axis = False
elif xm_val is None:
hlae_axis = "UNKNOWN"
holds.append("HOLD_UNMEASURED_STEALTH_AXIS:HLAE_SCT_CROSSMATCH")
else:
hlae_axis = True
if not is_plan_b:
hlac_axis: Any = False
else:
rkir = patient.get("recipient_kir_ligand_group")
if rkir is None or (is_endo_b and eff_rel == "UNSPECIFIED"):
hlac_axis = "UNKNOWN"
holds.append("HOLD_UNMEASURED_STEALTH_AXIS:HLAC_KIR")
elif eff_rel == "KIR_LIGAND_MISMATCH":
hlac_axis = False
elif "C1C2" in pvid:
hlac_axis = True
elif "C1" in pvid and str(rkir).upper() == "C1/C1":
hlac_axis = True
elif "C2" in pvid and str(rkir).upper() == "C2/C2":
hlac_axis = True
elif is_endo_b and eff_rel in ("SELF_4DIGIT_MATCH", "KIR_MATCH_FOREIGN_4DIGIT_ALLO"):
hlac_axis = True
else:
hlac_axis = False
exec_ok = bool(
prod.get("execution_supported") is True
and not str(prod.get("physical_qualification_status", "")).upper().startswith("RESEARCH")
)
return {
"target_product_variant_id": pvid,
"execution_supported": exec_ok,
"independent_stealth_axes": {
"cd47_sirpa_axis": cd47_axis,
"hlae_nkg2a_axis": hlae_axis,
"hlac_kir_axis": hlac_axis,
},
"active_holds": holds,
"scheduler_routing_eligible": len(holds) == 0,
"clinical_release_eligible": bool(len(holds) == 0 and exec_ok and prod.get("physical_qualification_status") == "QUALIFIED"),
}
def _build_product_scoped_precedence_audit_iip_0024() -> Dict[str, Any]:
from scripts.product_contract import get_product_definition
prod_a = get_product_definition("ISLET1_A4_ARM1B", root=REPO_ROOT)
prod_bsct = get_product_definition("ISLET1_B_SCT_C1_CIITA", root=REPO_ROOT)
prod_z = get_product_definition("ISLET1_Z_X_MOL_140UM_ZERO_CAO2", root=REPO_ROOT)
sample_pt = {
"sirpa_genotype": "V1/V1",
"exact_hlae_sct_serum_crossmatch_negative": True,
"exact_product_non_hla_and_sct_flow_crossmatch_negative": True,
"recipient_kir_ligand_group": "C1/C1",
"hlac_4digit_relation": "KIR_MATCH_FOREIGN_4DIGIT_ALLO",
"b_prime_sct_recipient_crossmatch_and_mlc_cleared": True,
"b_prime_sct_recipient_cd8_mlc_negative": False,
}
res_a = evaluate_product_scoped_routing_and_stealth_axes_iip_0024(sample_pt, target_product_def=prod_a)
res_bsct = evaluate_product_scoped_routing_and_stealth_axes_iip_0024(sample_pt, target_product_def=prod_bsct)
res_z = evaluate_product_scoped_routing_and_stealth_axes_iip_0024(sample_pt, target_product_def=prod_z)
return {
"proposal_id": "IIP-0024",
"decision_id": "DEC-103",
"primary_citations": ["PMID:16034111", "PMID:24804568", "PMID:35323192", "PMID:10850706", "PMID:37264229", "PMID:28867344", "PMID:22862941"],
"design_a_eligible_when_bsct_mlc_fails": res_a["scheduler_routing_eligible"],
"bsct_blocked_when_explicit_cd8_mlc_false_despite_composite_true": not res_bsct["scheduler_routing_eligible"],
"bsct_active_holds": res_bsct["active_holds"],
"design_z_wildcard_clinical_release_eligible": res_z["clinical_release_eligible"],
}
_IIP_0026_RIGHTS_CLEAN_PINNED_JSON = (
'{"license_manifest":{"GRCh38_p14_and_NCBI_RefSeq_INSDC":{"rights_statement":"INSDC unrestricted public archival access a'
'nd redistribution policy (https://www.insdc.org/policy/) with explicit NCBI/GenBank third-party depositor rights caveat '
'(https://www.ncbi.nlm.nih.gov/genbank/about/); not claimed under a bl'
'anket CC0-1.0 dedication.","sources":["https://api.genome.ucsc.edu/getData/sequence?genome=hg38","https://eutils.ncbi.nl'
'm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore"],"ipd_imgt_hla_cc_by_nd_content_included":false,"ucsc_crispr_all_targets'
'_or_crispor_dumps_included":false},"GENCODE_v46_and_Ensembl_REST":{"rights_statement":"GENCODE v46 open genomic annotati'
'ons under EMBL-EBI open data-use policy (https://www.ebi.ac.uk/about/terms-of-use/, https://www.gencodegenes.org/pages/d'
'ata_access.html; GENCODE v46 file headers identify the release without asserting a file-specific CC-BY-4.0 grant) and En'
'sembl REST VEP lookup subject to the Ensembl content disclaimer (https://www.ensembl.org/about/articles/ensembl-content-'
'disclaimer; underlying third-party datasets keep their own source licenses and are not converted to CC0 by Ensembl)."},"'
'gnomAD_v4_1":{"release_version":"gnomAD v4.1 (gnomad_r4, April 2024 release, GRCh38)","license":"CC0-1.0 Public Domain D'
'edication (gnomAD primary allele/filter data; third-party annotations carry their own source terms)","pinned_export_arti'
'fact":"embedded_iip0026_rights_clean_pinned_snapshot (immutable SHA-256-pinned offline snapshot; never relies on moving '
'live API aliases)","source":"https://gnomad.broadinstitute.org/news/2024-04-gnomad-v4-1/"},"AlphaMissense_v3":{"license"'
':"CC-BY-4.0 on Zenodo v3 predictions dataset (https://doi.org/10.5281/zenodo.10813168, record 10813168) & AlphaFold DB m'
'irror; Cheng et al. 2023 Science article (PMID:37733863, DOI:10.1126/science.adg7492) carries separate publisher copyrig'
'ht and is cited factually only","zenodo_v3_record_url":"https://doi.org/10.5281/zenodo.10813168","zenodo_v3_doi":"10.528'
'1/zenodo.10813168","legacy_v1_non_commercial_record_cited_or_used":false,"zenodo_v3_file_checksums":{"AlphaMissense_gene'
'_hg38.tsv.gz":{"size":253636,"checksum":"md5:529e3b51cec079272c571affde6f0376"},"AlphaMissense_isoforms_hg38.tsv.gz":{"s'
'ize":1177361934,"checksum":"md5:018771baa0dcc7ef79772448f8b8c354"},"AlphaMissense_isoforms_aa_substitutions.tsv.gz":{"si'
'ze":2461351945,"checksum":"md5:112b1921cfcdb3a1047532abe449ad59"},"AlphaMissense_hg38.tsv.gz":{"size":642961469,"checksu'
'm":"md5:9fd167735f16a1b87da6eb3e4c25fcb5"},"AlphaMissense_hg19.tsv.gz":{"size":622293310,"checksum":"md5:3f14fba08c60b09'
'a90a2ae14b7802e4c"},"AlphaMissense_gene_hg19.tsv.gz":{"size":243943,"checksum":"md5:9a52a23bac9e4c8cfcf0f66688888e5e"},"'
'AlphaMissense_aa_substitutions.tsv.gz":{"size":1207278510,"checksum":"md5:b9ccb339e0de6cb0a8d1973ad2026576"}},"zenodo_v3'
'_p29597_bgzf_direct_verification":{"file_key":"AlphaMissense_aa_substitutions.tsv.gz","file_size_bytes":1207278510,"file'
'_zenodo_checksum":"md5:b9ccb339e0de6cb0a8d1973ad2026576","bgzf_range_bytes_inclusive":[279144564,279285119],"bgzf_range_'
'length_bytes":140556,"bgzf_range_sha256":"b67adc094983f7a4a628b9711c697db49df6314806d7dd7d3f9a55b41a273620","bgzf_block_'
'count":11,"bgzf_blocks":[{"byte_start":279144564,"byte_end_inclusive":279157646,"bsize":13083,"bgzf_block_sha256":"0976d'
'42686d3caf202a710b75b9e5db9d95c2356d4c29c62bf31a702d099d63f"},{"byte_start":279157647,"byte_end_inclusive":279170829,"bs'
'ize":13183,"bgzf_block_sha256":"5be29c6085968f6f44ce315b0de3bf44e8ae036c2bb44bfbf16a628cd857b8ec"},{"byte_start":2791708'
'30,"byte_end_inclusive":279183875,"bsize":13046,"bgzf_block_sha256":"ae7a0aa17e93a874b0dfa7383cd32088d71b65b5211dda15500'
'c94eadc3f0e6b"},{"byte_start":279183876,"byte_end_inclusive":279196722,"bsize":12847,"bgzf_block_sha256":"bf517cca4dbe7d'
'd57322ba88fa735eeb8336210f912522b93c19d61a21b4943b"},{"byte_start":279196723,"byte_end_inclusive":279209671,"bsize":1294'
'9,"bgzf_block_sha256":"f55ae2a83d2880f6531589cc2c68d6caf054909c20afd0ee22b8b45914e9f59e"},{"byte_start":279209672,"byte_'
'end_inclusive":279222595,"bsize":12924,"bgzf_block_sha256":"38574e40be2a0db8d6df31138250f8507893979ada9f4270eb51526e62c7'
'3156"},{"byte_start":279222596,"byte_end_inclusive":279235358,"bsize":12763,"bgzf_block_sha256":"1087b92a87559211eb8f475'
'01c6c20c1c1e323c95b1a28a925df14e08a1722dc"},{"byte_start":279235359,"byte_end_inclusive":279248347,"bsize":12989,"bgzf_b'
'lock_sha256":"e840d2d08a1f9c7f5b994a0909b89240e7560a4bf063e6e9f6ae35c0a813335f"},{"byte_start":279248348,"byte_end_inclu'
'sive":279260802,"bsize":12455,"bgzf_block_sha256":"8609bd0b5e30a9f1f99e8e6427a887765a87e6987297d4b6e100b926130c8b98"},{"'
'byte_start":279260803,"byte_end_inclusive":279272411,"bsize":11609,"bgzf_block_sha256":"5fa7255115ea04adb05069150b4501d2'
'afdf96359e387b3058c056aef373d284"},{"byte_start":279272412,"byte_end_inclusive":279285119,"bsize":12708,"bgzf_block_sha2'
'56":"e8c860f72f1b86a9970d366134c31916675dd093a4bce8be1fa69edbc35391d3"}],"total_p29597_rows_verified":22553,"printed_7_t'
'yk2_c_to_g_substitutions_direct_zenodo_tsv":{"S1103R":{"am_pathogenicity":0.9745,"am_class_zenodo_tsv":"pathogenic"},"P1'
'104A":{"am_pathogenicity":0.8292,"am_class_zenodo_tsv":"pathogenic"},"P1104R":{"am_pathogenicity":0.988,"am_class_zenodo'
'_tsv":"pathogenic"},"P1104G":{"am_pathogenicity":0.9926,"am_class_zenodo_tsv":"pathogenic"},"P1105A":{"am_pathogenicity"'
':0.2464,"am_class_zenodo_tsv":"benign"},"P1105R":{"am_pathogenicity":0.5841,"am_class_zenodo_tsv":"pathogenic"},"P1105G"'
':{"am_pathogenicity":0.7682,"am_class_zenodo_tsv":"pathogenic"}}},"alphafold_ebi_mirror_license":"CC-BY-4.0 (AlphaFold P'
'rotein Structure Database terms of use)"},"Pandey_et_al_2025_PMC11754103":{"license":"CC-BY-4.0 (Nat Biomed Eng 2025, DO'
'I 10.1038/s41551-024-01227-1)","moesm4_xlsx_url":"https://static-content.springer.com/esm/art%3A10.1038%2Fs41551-024-012'
'27-1/MediaObjects/41551_2024_1227_MOESM4_ESM.xlsx","moesm4_xlsx_sha256":"0e3b5a772727bc3208f97b69be8e7652acb736b352f9909'
'88c6b760dbe001f1e"},"Doench_2016_CFD_Weight_Matrix":{"origin_and_version":"Doench et al. 2016 (Nat Biotechnol 34:184-191'
', PMID:26780180, DOI:10.1038/nbt.3437) WT-SpCas9 specificity model (cited factually via locus-level summary scalars only'
')","quarantined_table_entries_bundled":0,"source_rights_status":"Springer Nature 2016 supplementary material (academic r'
'esearch terms; NOT CC0 or CC-BY-4.0; CRISPOR redistribution is GPL-3.0)","public_openislet_export_rule_c3_disposition":"'
'QUARANTINED_AND_PURGED_FROM_STAGED_INPUTS: Zero entries of the 240-cell mismatch matrix or 16-cell PAM table exist in em'
'bedded_iip0026_rights_clean_pinned_snapshot or any public/staged export; only attributed locus-specific WT-CFD summary s'
'calars (locus_wt_cfd_precomputed_summaries) plus parameter-free sequence/PAM checks and empirical cleavage gates are ret'
'ained."},"Literature_Citation_and_Verbatim_Quote_Audit":{"explicit_cc_by_4_0_articles_eligible_for_attributed_quotes":["'
'Chen et al. 2021 Cell (PMID:34653350 / PMC8584034, CC-BY-4.0)","Ferreira da Silva et al. 2022 Nat Commun (PMID:35140211 '
'/ PMC8828784, CC-BY-4.0 \\u2014 exact en-dash \'2\\u201317 fold\' preserved)","Pandey et al. 2025 Nat Biomed Eng (PMID:38858'
'586 / PMC11754103, CC-BY-4.0)","Daliri et al. 2024 Cells (PMID:38786078 / PMC11120019, CC-BY-4.0 \\u2014 REVIEW article, '
'not primary experimental evidence)"],"non_cc_by_4_0_articles_restricted_to_factual_paraphrase_only":["Cancellieri et al.'
' 2023 Nat Genet / author manuscript (PMID:36522432 / PMC10272994 \\u2014 PMC text-mining/fair-use notice, no CC-BY-4.0 li'
'cense displayed -> paraphrased)","Damaj et al. 2008 J Clin Endocrinol Metab (PMID:18796520 \\u2014 Endocrine Society copy'
'right -> paraphrased)","Cheng et al. 2023 Science (PMID:37733863 \\u2014 Science article text is publisher copyright; Zen'
'odo 10813168 v3 dataset is CC-BY-4.0)"]}},"grch38_pseudosite_windows":{"OT1_pseudo_attP_chr3":{"chrom":"chr3","start_1ba'
'sed":9447025,"end_1based":9447375,"reported_pos_1based":9447175,"dna":"CTACACCAGTACTATCTCTTTCTAGACCAGGGAAGATAGAAAGGTAGAA'
'GCCATCATGCATGCTTTTGAAAACTTAGAGAAAAGAAAGAAGCGGCGGGATCAGCCCTTGGAACAGAGCAACTCTGATGTAGAGATTACTACAACCACCTCAGAGACTCCTGTTGGTGAA'
'GAGACAAAAACTGAAGCCCCTGAATCTGAAGTTAGCAACTCTGTTTCAAATGTTACCATCCCAAGCACCCCACAGAGTGTTGGTGTGAATACCCGGAGGTCTTCCCAAGCAGGGGTAAGA'
'GTTGAAAAGACTTCAGCACTTAGACATCCTCACCTTTGCTAATGTCAATACCTAACTTTTGG"},"OT2_pseudo_attP_chr10":{"chrom":"chr10","start_1based"'
':93073892,"end_1based":93074242,"reported_pos_1based":93074042,"dna":"CGCTGGCGGCGGCGGCAGGTGGCGCGGGAGGTCGCGGCGCGCCATGGGGC'
'TCCCGGCGCTGCTGGCCAGTGCGCTCTGCACCTTCGTGCTGCCGCTGCTGCTCTTCCTGGCTGCGATCAAGCTCTGGGACCTGTACTGCGTGAGCGGCCGCGACCGCAGTTGTGCCCTCC'
'CATTGCCCCCCGGGACTATGGGCTTCCCCTTCTTTGGGGAAACCTTGCAGATGGTACTGCAGGTAAGGGAGGGTGGGGCGGGACAGGCTGCTTCCCCGGAGCCCGGCGCGGCTCTGGGCT'
'TCTGCTGAAGTCGGGGTAGGCGCCCCCGGGAGGCATGCTATTGCGGCTAGGAGCAGGGCTG"},"OT1_pseudo_attB_chr1":{"chrom":"chr1","start_1based":43'
'298781,"end_1based":43299131,"reported_pos_1based":43298931,"dna":"CTCTATCATTATCAATTCAGTTTGTTTTGGGTTTGGAGGTTAACCCTCCAATG'
'TGTAGAACTTCATATTTGCATTATTTTTGGCCTATAACTTTCGAGTGACTGAGACTTCAAGATGTGCATTATGGCTTAAGTCGTCTTATACATCTGCAACAGCAGATGTATACACAACCC'
'ACTCAAAATTTGTGTGTGCAGTAATATTTCATTTGGGACATATTGTTTGTAAACTGATGCTATTTAAATTACTTGCAGCATAATCTCAACACATGTAAAAATACTTTTACACTTGTAGGA'
'TATTGTTTTATAATACAAATTCTTGTGTACAAACTCCATTAACATTTTATTTATGTAC"},"OT2_st10_chr6_pseudo_attB":{"chrom":"chr6","start_1based":'
'14806125,"end_1based":14806475,"reported_pos_1based":14806275,"dna":"CAAATACGGACTGAGGATGCTACATGCCAGGTACAGGCAGGTACCAAAGAT'
'GCCAAGGTGAGAGAGTTGGTCCCCACCCTCCAAGGAGCTCATAGTTTTATAGATGATCACATAAGGAGAAAAACAAAAGCTCTATGTCTAGACCACAGACACCTCAGGGGCAGAAACACT'
'GTCTCATTTATTCTTGTACTGCCGTCATCTAGCCAGGGTCTAAGCAGAGTAGGCAATTATTAAATGTCTGTTGAATGAATACAGGGTGAAAAATGTGTGCCTCCACACATACAGTGGTGC'