Abstract
Objective Erythropoietic protoporphyria (EPP) is a rare photodermatosis marked by multi-year diagnostic delays. We developed and externally validated machine learning models to identify patients with EPP earlier from longitudinal electronic health record (EHR) data and estimate undiagnosed disease burden.
Materials and Methods In a retrospective case–control study at two San Francisco health systems—an academic referral center (UCSF) and a safety-net hospital (ZSFG)—we identified 74 confirmed EPP cases using combined diagnostic coding, biochemical criteria, and specialty chart review. Symptom-enriched controls were sampled at a 40:1 ratio. Longitudinal diagnoses, laboratory results, medications, procedures, and encounters preceding the outcome date were modeled with a gradient-boosting classifier (CatBoost) and a state-space sequence model (MAMBA). The best model was deployed across the UCSF population and externally validated at ZSFG without retraining.
Results On the UCSF held-out test set (n=1,865; 43 cases), MAMBA outperformed CatBoost (AUC–ROC 0.91 vs 0.89; average precision 0.42 vs 0.27; precision 65% vs 20%), flagging cases a median of 229 days before documented diagnosis. Deployed across 297,967 symptom-compatible patients, it identified 310 high-risk individuals, implying a prevalence approaching genetic estimates. External validation at ZSFG showed attenuated performance (AUC–ROC 0.72; average precision 0.10) while preserving early detection (median 264 days).
Discussion A sequence model integrating temporal EHR signals detected EPP months before clinical recognition, corroborating genetic evidence of substantial underdiagnosis. Cross-site attenuation reflects population and documentation differences and underscores the need for local recalibration.
Conclusion Longitudinal EHR-based machine learning can shorten EPP diagnostic delay and prioritize patients for confirmatory testing, supporting proactive rare-disease case finding.
Competing Interest Statement
VAR has research funded by grants to UCSF from the following for-profit entities: Johnson and Johnson, Merck, Genentech, BeOne Medicines, and Sanofi. He is a scientific advisor to Data Unite and ZebraMD. BW received research support from: Alnylam Pharmaceuticals, Disc Medicine, Recordati Rare Diseases, and Tanabe Pharma. He is a scientific advisor to Portal Therapeutics.
Author Declarations
I confirm all relevant ethical guidelines have been followed, and any necessary IRB and/or ethics committee approvals have been obtained.
Yes
The details of the IRB/oversight body that provided approval or exemption for the research described are given below:
This study was approved by the University of California, San Francisco (UCSF) Institutional Review Board (IRB #24-42109), which granted a waiver of informed consent and HIPAA authorization for retrospective chart review. The research was determined to pose no greater than minimal risk to participants.
I confirm that all necessary patient/participant consent has been obtained and the appropriate institutional forms have been archived, and that any patient/participant/sample identifiers included were not known to anyone (e.g., hospital staff, patients or participants themselves) outside the research group so cannot be used to identify individuals.
Yes
I understand that all clinical trials and any other prospective interventional studies must be registered with an ICMJE-approved registry, such as ClinicalTrials.gov. I confirm that any such study reported in the manuscript has been registered and the trial registration ID is provided (note: if posting a prospective study registered retrospectively, please provide a statement in the trial ID field explaining why the study was not registered in advance).
Yes
I have followed all appropriate research reporting guidelines, such as any relevant EQUATOR Network research reporting checklist(s) and other pertinent material, if applicable.
Yes
Data availability
Deidentified electronic health records data from UCSF and ZSFG are available to support study reproducibility and extensions following the execution of a data use agreement with these health systems.





