Skip to content

About

Code for sex-specific retinal age gap analyses (UK Biobank + Rotterdam Study): RETFound fine-tuning, RAG, GWAS, disease associations, and model attention mapping.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

192 Commits

Folders and files

Repository files navigation

Sex-specific retinal age project

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 to config.py, trains combined, female, and male models.

2. Post-processing of age predictions

In post-pred/:

  • merge_pred.py merges 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.py applies correction for regression-to-the-mean bias.
  • compare_sexes_delta.py compares male to female RAG.

3. Model validation in the Rotterdam Study (RS)

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 Topcon2000 does post-processing of age predictions and male-female RAG comparison.

4. Genome-wide association study (GWAS) of RAG

GWAS was performed using Regenie and heritability was estimated using GREML.

In post-pred/:

  • gwas_phenofiles.py prepares the phenofile and covariate file for Regenie.
  • compare_sexes_effects.py compares female to male RAG heritability with a z-test.
  • pascalx_genescorer.py, linked to pascalx_config.py, computes RAG gene-level association from GWAS summary statistics.
  • pascalx_results.py extracts significant gene lists from PascalX raw outputs.
  • combined_manhattan_miami_fig.R generates the annotated Manhattan/Miami plot (Figure 4).

In RS/:

  • gwas_replication.py performs the replication of SNPs and genes that were significant in the UKB.

5. Disease association and survival analysis

In post-pred/:

  • rap_disease_data_prep.py prepares the data for analysis on the UKB-RAP.
  • rap_disease_assoc.py runs the disease association on the UKB-RAP and creates plots (e.g. Figure 2).
  • rap_surv_analysis.R runs the survival analysis on the UKB-RAP, supported by the scripts in stats/.
  • plot_surv_results.py creates plots for survival analysis results (e.g. Figure 3).

6. Model saliency and attention mapping (Figure 5)

In from-images/retfound/:

  • copy_files.py generates temporary folder trees for saliency maps.

The code used to generate saliency maps is here.
The code used to generate attention maps is here.

7. Correlation between model latent variables and interpretable image features (Figure 6)

In from-images/retfound/:

  • latent_extract.py extracts the model latent variables for individual images.

In post-pred/:

  • compute_img_rgb.py computes the mean and standard deviation of RGB channels in fundus images.
  • latent_tif_corr.py computes 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.

About

Code for sex-specific retinal age gap analyses (UK Biobank + Rotterdam Study): RETFound fine-tuning, RAG, GWAS, disease associations, and model attention mapping.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages