Last updated: 2022-05-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 d62fc99. 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/sldsc_annot_generic_baselineLD_separate.sbatch
    Untracked:  scripts/

Unstaged changes:
    Modified:   analysis/sldsc_example_GTEx_QTLs.Rmd

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 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(dplyr)
data.dir <- '/project2/gca/Heart_Atlas/reorganized_data/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'))
head(gwas.sumstats)

Prepare annotations for TORUS

annotation_bed_files <- list.files(path = 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'))

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

sig.loci <- gwas.sumstats %>% group_by(locus) %>% summarise(max_mlogP = max(pval)) %>% filter(max_mlogP > -log10(5e-8)) %>% pull(locus)
gwas.sumstats.sigloci <- gwas.sumstats[gwas.sumstats$locus %in% sig.loci, ]
print(length(unique(gwas.sumstats.sigloci$locus)))

Add Torus priors to GWAS summary statistics

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

Run finemapping using SuSiE

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

We can annotate our summary statistics with this information using merge_susie_sumstats()

gwas_finemapped <- merge_susie_sumstats(susie_results = susie_finemap_L1, sumstats = sumstats.sigloci)
saveRDS(gwas_finemapped, paste0(data.dir, '/finemapping/AF_finemapping_result_torusprior_122loci.rds'))

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

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              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] dplyr_1.0.8     mapgen_0.3.8    workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.2       xfun_0.30              bslib_0.3.1           
 [4] purrr_0.3.4            generics_0.1.2         colorspace_2.0-3      
 [7] vctrs_0.4.1            htmltools_0.5.2        stats4_4.0.4          
[10] yaml_2.3.5             utf8_1.2.2             rlang_1.0.2           
[13] jquerylib_0.1.4        later_1.3.0            pillar_1.7.0          
[16] DBI_1.1.2              glue_1.6.2             BiocGenerics_0.36.1   
[19] GenomeInfoDbData_1.2.4 lifecycle_1.0.1        stringr_1.4.0         
[22] zlibbioc_1.36.0        munsell_0.5.0          gtable_0.3.0          
[25] evaluate_0.15          knitr_1.38             callr_3.7.0           
[28] IRanges_2.24.1         fastmap_1.1.0          httpuv_1.6.5          
[31] ps_1.6.0               GenomeInfoDb_1.26.7    parallel_4.0.4        
[34] fansi_1.0.3            Rcpp_1.0.8.3           scales_1.2.0          
[37] promises_1.2.0.1       S4Vectors_0.28.1       jsonlite_1.8.0        
[40] XVector_0.30.0         fs_1.5.2               ggplot2_3.3.5         
[43] digest_0.6.29          stringi_1.7.6          processx_3.5.3        
[46] getPass_0.2-2          grid_4.0.4             GenomicRanges_1.42.0  
[49] rprojroot_2.0.2        cli_3.2.0              tools_4.0.4           
[52] bitops_1.0-7           magrittr_2.0.3         sass_0.4.1            
[55] RCurl_1.98-1.6         tibble_3.1.6           crayon_1.5.1          
[58] whisker_0.4            pkgconfig_2.0.3        ellipsis_0.3.2        
[61] assertthat_0.2.1       rmarkdown_2.13         httr_1.4.2            
[64] rstudioapi_0.13        R6_2.5.1               git2r_0.30.1          
[67] compiler_4.0.4