This repository contains the code used to reproduce the analyses, results, and figures reported in "Deep learning aging marker from retinal images unveils sex-specific clinical and genetic signatures" (Nature Communications, 2026, https://doi.org/10.1038/s41467-026-77102-1). Scripts are organized by analysis stage below. Input data are not included: UK Biobank and Rotterdam Study data require approved access, and intermediate outputs (e.g. model checkpoints, prediction files) are produced by running the pipeline on those data.
1. Fine-tuning of RETFound to predict age from raw (cropped) fundus images from the UK Biobank
In from-images/retfound/:
finetune_age_continuous.py, linked toconfig.py, trains combined, female, and male models.
In post-pred/:
merge_pred.pymerges predictions from the five test folds of each model, averages left and right eye predictions, and computes retinal age gap (RAG) for all subjects.correct_age_bias.pyapplies correction for regression-to-the-mean bias.compare_sexes_delta.pycompares male to female RAG.
Age predictions were generated for RS participants based on the fine-tuned checkpoints using the eval_only mode in from-images/retfound/finetune_age_continuous.py.
In RS/:
Analysis RS Topcon2000does post-processing of age predictions and male-female RAG comparison.
GWAS was performed using Regenie and heritability was estimated using GREML.
In post-pred/:
gwas_phenofiles.pyprepares the phenofile and covariate file for Regenie.compare_sexes_effects.pycompares female to male RAG heritability with a z-test.pascalx_genescorer.py, linked topascalx_config.py, computes RAG gene-level association from GWAS summary statistics.pascalx_results.pyextracts significant gene lists from PascalX raw outputs.combined_manhattan_miami_fig.Rgenerates the annotated Manhattan/Miami plot (Figure 4).
In RS/:
gwas_replication.pyperforms the replication of SNPs and genes that were significant in the UKB.
In post-pred/:
rap_disease_data_prep.pyprepares the data for analysis on the UKB-RAP.rap_disease_assoc.pyruns the disease association on the UKB-RAP and creates plots (e.g. Figure 2).rap_surv_analysis.Rruns the survival analysis on the UKB-RAP, supported by the scripts instats/.plot_surv_results.pycreates plots for survival analysis results (e.g. Figure 3).
In from-images/retfound/:
copy_files.pygenerates temporary folder trees for saliency maps.
The code used to generate saliency maps is here.
The code used to generate attention maps is here.
In from-images/retfound/:
latent_extract.pyextracts the model latent variables for individual images.
In post-pred/:
compute_img_rgb.pycomputes the mean and standard deviation of RGB channels in fundus images.latent_tif_corr.pycomputes pairwise correlation between latents and image features.
NOTE: Extended and exploratory analyses that were not included in the paper are available on the extended-analyses branch.