Last updated: 2023-10-20

Checks: 7 0

Knit directory: analysis_pipelines/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200524) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 429745c. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/test_sldsc_splicingAnnot.Rmd
    Untracked:  code/compute_ldscore_generic_annot.sbatch
    Untracked:  code/extract_baselineLD_generic_annot.R
    Untracked:  code/ldsc_make_binary_annot_compute_ldscores_bedfiles.sbatch
    Untracked:  code/make_ldsc_binary_annots_from_bedfiles.R
    Untracked:  code/sldsc_annot_generic_baselineLD_separate.sbatch
    Untracked:  scripts/tmp.R

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/mapgen_torus_enrichment_heart_atlas.Rmd
    Modified:   analysis/sldsc_example_GTEx_QTLs.Rmd
    Modified:   analysis/sldsc_pipeline.Rmd
    Modified:   code/extract_baselineLDv2.2_generic_annot.R
    Modified:   code/mapgen_trackplots.R
    Modified:   scripts/run_finemapping.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/mapgen_torus_susie_AF.Rmd) and HTML (docs/mapgen_torus_susie_AF.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 429745c kevinlkx 2023-10-20 wflow_publish("analysis/mapgen_torus_susie_AF.Rmd")
html 1e5ba5a kevinlkx 2023-10-20 Build site.
Rmd c299df6 kevinlkx 2023-10-20 wflow_publish("analysis/mapgen_torus_susie_AF.Rmd")
html 5090878 kevinlkx 2022-05-20 Build site.
Rmd c1dd3bd kevinlkx 2022-05-20 minor edits
html cd7e5e0 kevinlkx 2022-05-20 Build site.
Rmd 5217355 kevinlkx 2022-05-20 added session info
html f8e55e4 kevinlkx 2022-05-20 Build site.
Rmd bf4b90d kevinlkx 2022-05-20 minor edits
html 6dcc25c kevinlkx 2022-05-20 Build site.
Rmd 5e151d4 kevinlkx 2022-05-20 Edited the documentation
html efc1951 kevinlkx 2022-05-20 Build site.
Rmd d62fc99 kevinlkx 2022-05-20 a tutorial for AF finemapping

Here we show an example of performing enrichment analysis on AFib GWAS data using mapgen with TORUS.

library(mapgen)
library(tidyverse)
data.dir <- '/project2/xinhe/shared_data/mapgen/example_data'

We use a reference genotype panel from European population (1KG).

bigSNP <- bigsnpr::snp_attach(rdsfile = '/project2/xinhe/1kg/bigsnpr/EUR_variable_1kg.rds')

Load GWAS summary statistics of AFib

gwas.sumstats <- readRDS(paste0(data.dir, '/GWAS/ebi-a-GCST006414_aFib.df.rds'))
gwas.sumstats <- gwas.sumstats %>% dplyr::rename(ss_index = og_index)
head(gwas.sumstats)

Prepare annotations for TORUS

annotation_bed_files <- list.files(paste0(data.dir, '/finemapping/annotations_for_finemapping_hg19'), 
                                   pattern = '*.bed', full.names = T)
torus.files <- prepare_torus_input_files(gwas.sumstats, 
                                         annotation_bed_files, 
                                         torus_input_dir = paste0(data.dir, '/finemapping/torus_input'))

Run TORUS to estimate enrichment (joint annotations) and compute SNP-level prior

run_torus() with option = “est-prior” returns a list with: enrichment estimates (log odds ratio) and 95% confidence intervals of each annotation, and SNP-level priors using the enrichment estimates.

torus.result <- run_torus(torus.files$torus_annot_file, 
                          torus.files$torus_zscore_file,
                          option = "est-prior",
                          torus_path = "torus") # set the path to 'torus' executable.
torus.enrich <- torus.result$enrich
torus.prior <- torus.result$snp_prior
saveRDS(torus.result, paste0(data.dir, '/finemapping/Torus_Enrichment_Results_Joint.rds'))
torus.result <- readRDS(paste0(data.dir, '/finemapping/Torus_Enrichment_Results_Joint.rds'))
torus.enrich <- torus.result$enrich
torus.prior <- torus.result$snp_prior

Select GWAS significant loci with -log10(pval) < 5e-8

sig.loci <- gwas.sumstats %>% dplyr::filter(pval > -log10(5e-8)) %>% dplyr::pull(locus) %>% unique()
gwas.sumstats.sigloci <- gwas.sumstats[gwas.sumstats$locus %in% sig.loci, ]

Add Torus priors to GWAS summary statistics

sumstats.sigloci <- prepare_susie_data_with_torus_result(sumstats = gwas.sumstats.sigloci, 
                                                         torus_prior = torus.prior)
cat("Finemap",length(unique(sumstats.sigloci$locus)), "loci.\n")
saveRDS(sumstats.sigloci, paste0(data.dir, '/finemapping/sumstats.sigloci.rds'))

Run finemapping using SuSiE

sumstats.sigloci <- readRDS(paste0(data.dir, '/finemapping/sumstats.sigloci.rds'))
cat("Finemapping",length(unique(sumstats.sigloci$locus)), "loci...\n")
# susie_finemap_L1 is a list of SuSiE results, one for each chunk/LD block. 
susie.res <- run_finemapping(sumstats.sigloci, bigSNP, priortype = 'torus', L = 1)

# add susie PIP information to GWAS summary stats
finemap.sumstats <- merge_susie_sumstats(susie.res, sumstats.sigloci)

saveRDS(finemap.sumstats, paste0(data.dir, '/finemapping/AF_finemapping_result_torusprior_122loci.rds'))

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.3.13-el7-x86_64/lib/libopenblas_haswellp-r0.3.13.so

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C           
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_1.0.0   stringr_1.5.0   dplyr_1.1.0     purrr_1.0.1    
 [5] readr_2.1.4     tidyr_1.3.0     tibble_3.1.8    ggplot2_3.4.1  
 [9] tidyverse_1.3.2 mapgen_0.5.6    workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] bitops_1.0-7           fs_1.6.1               lubridate_1.9.2       
 [4] httr_1.4.4             rprojroot_2.0.3        GenomeInfoDb_1.34.9   
 [7] tools_4.2.0            backports_1.4.1        bslib_0.4.2           
[10] utf8_1.2.3             R6_2.5.1               DBI_1.1.3             
[13] BiocGenerics_0.44.0    colorspace_2.1-0       withr_2.5.0           
[16] tidyselect_1.2.0       processx_3.8.0         compiler_4.2.0        
[19] git2r_0.30.1           cli_3.6.0              rvest_1.0.3           
[22] xml2_1.3.3             sass_0.4.5             scales_1.2.1          
[25] callr_3.7.3            digest_0.6.31          rmarkdown_2.20        
[28] XVector_0.38.0         pkgconfig_2.0.3        htmltools_0.5.4       
[31] dbplyr_2.3.0           fastmap_1.1.0          rlang_1.0.6           
[34] readxl_1.4.2           rstudioapi_0.14        jquerylib_0.1.4       
[37] generics_0.1.3         jsonlite_1.8.4         googlesheets4_1.0.1   
[40] RCurl_1.98-1.10        magrittr_2.0.3         GenomeInfoDbData_1.2.9
[43] Rcpp_1.0.10            munsell_0.5.0          S4Vectors_0.36.1      
[46] fansi_1.0.4            lifecycle_1.0.3        stringi_1.7.12        
[49] whisker_0.4            yaml_2.3.7             zlibbioc_1.44.0       
[52] grid_4.2.0             promises_1.2.0.1       crayon_1.5.2          
[55] haven_2.5.1            hms_1.1.2              knitr_1.42            
[58] ps_1.7.2               pillar_1.8.1           GenomicRanges_1.48.0  
[61] stats4_4.2.0           reprex_2.0.2           glue_1.6.2            
[64] evaluate_0.20          getPass_0.2-2          modelr_0.1.10         
[67] vctrs_0.5.2            tzdb_0.3.0             httpuv_1.6.5          
[70] cellranger_1.1.0       gtable_0.3.1           assertthat_0.2.1      
[73] cachem_1.0.6           xfun_0.37              broom_1.0.3           
[76] later_1.3.0            googledrive_2.0.0      gargle_1.3.0          
[79] IRanges_2.32.0         timechange_0.2.0       ellipsis_0.3.2