This repository contains code and materials from a project I've done as a part of my PhD at the University of Bristol.
Publication in Communications Biology: https://www.nature.com/articles/s42003-022-03272-5
Related blogpost about setting up multivariable MR the way it was done in this project: https://marinalearning.netlify.app/2021/03/22/setting-up-multivariable-mendelian-randomization-analysis/
If you are using this codebase, please cite: https://www.nature.com/articles/s42003-022-03272-5
This README contains:
Multiple observational studies and a recent MR study (Richardson et al., 2020) have shown that early life adiposity may be protective against later-life breast cancer. The biological mechanism underlying this effect is unclear but is likely to independent of adiposity in adulthood. In this project, the aim is to identify potential mediators of the protective effect of high childhood BMI on breast cancer risk.
As a part of this project I have performed the following (depending on data availability):
The five main categories of potential mediators considered:
Main analysis scripts and metadata (see details below):
├── set_paths.R
├── 01_process_gwas_summary.Rmd
├── 02_mr_BMI_to_mediators.Rmd
├── 03_mr_mediators-to-BC.Rmd
├── 04_mvmr_run_analysis.Rmd
├── 05_mvmr_create_plots.Rmd
├── 06_mediation_analysis.Rmd
├── functions.R
├── functions_mvmr.R
├── metadata
│ └── data_lookup.csv
│ └── pheno_correlations.csv
Supplementary scripts:
├── code_supplementary
│ ├── extract_from_GWAScatalog.Rmd
│ └── review_mediators_in_MRBase.Rmd
│ └── create_pheno_covariance_matrix.Rmd
Script set_paths.R
is imported by all other scripts, and is used to set the environment of where the project is run.
Rmd 01_process_gwas_summary.Rmd
is required for processing data that comes as text files (i.e. GWAS summary stats) from the IEU GWAS pipeline or other sources. This script has to be run to convert raw data into outcome
data frames and to extract instruments from each GWAS (in exposure
format) and save them to be used directly in MR analysis in subsequent scripts. The names of raw files, tidy outcome data frames, and exposure instruments are all get saved in the metadata file data_lookup.csv
upon generation. (NB the metadata file has to contain raw file names and the desired output prefixes before running this Rmd).
Rmd 02_mr_BMI_to_mediators.Rmd
runs univariable MR of Childhood and Adult BMI on all mediators specified in metadata file (data_lookup.csv
). The code has to be run interactively per trait category. The results merged by trait category will be stored in Results
directory outside the codebase. After the analysis, forest plots can be created for each trait category. To recreate the plots, don't need to rerun the full analysis, can just read in the merged files. The plots will be saved in the codebase in figures/
.
Rmd 03_mr_mediators-to-BC.Rmd
is used to run univariable MR of all mediators (and BMI) on Breast cancer (ieu-a-1126
). The code has to be run interactively per trait category, the results are stored in Results
outside the codebase. After the analysis, forest plots can be created for each trait category. To recreate the plots, don't need to rerun the full analysis, can just read in the merged files. The plots will be saved in the codebase in figures/
.
Rmd 04_mvmr_run_analysis.Rmd
runs four types of MVMR with each mediator, but first we run MVMR with BMIs only (Analysis 0).
The code has to be run interactively per trait category, the results are stored in Results/trair_category/mediator/
outside the codebase. The analysis is structured as a large for-loop that will perform all four MVMR for each mediator in the selected trait category when individually specified T/F outside the loop. After all analyses have been performed, the mediators within each trait category are collated into a single dataframe and saved in Results/trait_category/merged/
directory.
MVMR analysis is performed using modified code from TwoSampleMR
package and also MVMR
package for comparison. MVMR sensitivity tests are done using MVMR
package and phenotypic correlations estimated using metaCCA
package (see code_supplementary/create_pheno_covariance_matrix.Rmd
)
Rmd 05_mvmr_create_plots.Rmd
creates forest plots from all MVMR analyses for each trait category separately and by trait category. The plots are saved to figures
within the codebase. The code also creates summary plot of all direct Childhood BMI estimates from Analyses 2 & 3.
Rmd 06_mediation_analysis.Rmd
contains a workflow for performing MR mediation analysis using Difference and Product method, with CIs calculation using Delta and Propagation of Errors methods. The script also contains methods for plotting the calculated indirect estimates (+CIs) as forest plots.
Supplementary scripts
extract_from_GWAScatalog.Rmd
was used for looking up traits (breast size and mammographic density) in GWAS catalogue to extract the SNPs to use as instruments fro this traits. However, for most studies it ended up bbeing easier (more reliable) to just get the data from supplementary information provided with the papers. The code loads raw data, cleans it, and saves in the format that is ready to be used as instruments in MR analysis.
create_pheno_covariance_matrix.Rmd
contains the workflow for applying the phenotypic correlation function from metaCCA
package to calculate pheno_cor scores between any two GWAS traits. Tho pheno_cor score is required for MVMR sensitivity tests (F-statistics calculation). The process is time intensive, so all pheno_cor values needed for this project have been pre-calculated and are now stored in metadata/pheno_correlations.csv
.