Last updated: 2023-12-07

Checks: 7 0

Knit directory: multigroup_ctwas_analysis/

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(20231112) 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 18b79ef. 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/

Unstaged changes:
    Modified:   analysis/detect_LD_mismatch_gwas_UKBBref_susie_rss.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/test_LD_mismatch_DENTIST_susierss.Rmd) and HTML (docs/test_LD_mismatch_DENTIST_susierss.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 18b79ef kevinlkx 2023-12-07 added documentations
html ced270e kevinlkx 2023-12-07 Build site.
Rmd bb0c185 kevinlkx 2023-12-07 test locus with manually changed z-scores
html 78e8869 kevinlkx 2023-12-07 Build site.
Rmd a36f9c8 kevinlkx 2023-12-07 test locus with manually changed z-scores

Load packages and functions

library(ctwas)
library(data.table)
library(tidyverse)

LDL

  • LDL GWAS and LD reference panel are both from UKBB.
  • Select one locus in chr22.
  • Randomly changed the z-scores for 100 variants (50 with abs(z) > 2 and 50 with abs(z) < 2).
  • Randomly flipped the z-scores for 20 variants (10 with abs(z) > 2 and 10 with abs(z) < 2).
  • Run DENTIST on the GWAS sumstats of the locus, with 2Mb vs. 1Mb window, or 1 iteration vs. 10 iterations.
trait <- "LDL"

LD Regions (ldetect blocks)

regions <- system.file("extdata/ldetect", "EUR.b38.bed", package = "ctwas")
regions_df <- read.table(regions, header = T)
regions_df <- regions_df %>% dplyr::arrange(chr, start, stop) %>% dplyr::mutate(locus = 1:nrow(regions_df))

Locus 950

locus = "950"
outdir <- paste0("/project2/xinhe/shared_data/multigroup_ctwas/ld_mismatch_test/", trait)
sumstats_hg38_locus <- readRDS(file.path(outdir, paste0(trait, ".test.locus", locus,".changed.sumstats.rds")))

region_df <- regions_df[regions_df$locus == locus,]
print(region_df)

locus_df <- sumstats_hg38_locus
#       chr    start     stop locus
# 950 chr22 24588236 26395662   950

Load Allele Frequency

CHR=22
dentist.dir <- paste0("/project2/xinhe/shared_data/multigroup_ctwas/DENTIST/", trait)
dentist.freq.df <- data.table::fread(file.path(dentist.dir, paste0("LDL-ukb-d-30780_irnt.ukb_chr", CHR, ".b38.frq")))

locus_df$Freq_A1 <- dentist.freq.df$Freq_A1[match(locus_df$snp, dentist.freq.df$RS_ID)]
locus_df$MAF <- pmin(locus_df$Freq_A1, 1-locus_df$Freq_A1)

SuSiE result

susie_original_res <- readRDS(file.path(outdir, paste0(trait, ".test.locus", locus,".original.condz.dist.rds")))
susie_new_res <- readRDS(file.path(outdir, paste0(trait, ".test.locus", locus,".changed.condz.dist.rds")))

stopifnot(all.equal(locus_df$snp, susie_original_res$id))
stopifnot(all.equal(locus_df$snp, susie_new_res$id))

locus_df$susie_original_LP <- -log10(susie_original_res$p_diff)
locus_df$susie_original_logLR <- susie_original_res$logLR

locus_df$susie_new_LP <- -log10(susie_new_res$p_diff)
locus_df$susie_new_logLR <- susie_new_res$logLR

DENTIST result

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".original.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_original_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".original.10iters.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_original_10iters_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".original.1Mb.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_original_1Mb_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".original.1Mb.10iters.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_original_1Mb_10iters_LP <- dentist_res$LP[m]
dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".changed.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_new_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".changed.10iters.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_new_10iters_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".changed.1Mb.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_new_1Mb_LP <- dentist_res$LP[m]

dentist_res <- data.table::fread(file.path(outdir, paste0(trait, ".test.locus", locus, ".changed.1Mb.10iters.DENTIST.full.txt")))
colnames(dentist_res) <- c("rsID", "chisq", "LP", "ifDup")
m <- match(locus_df$snp, dentist_res$rsID)
locus_df$dentist_new_1Mb_10iters_LP <- dentist_res$LP[m]

DENTIST vs. SuSiE on original data

p1 <- ggplot(na.omit(locus_df), aes(x = dentist_original_10iters_LP, y = susie_original_LP)) +
  geom_point(alpha=0.6) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST original 2Mb window -log10P", y = "SuSiE original -log10P", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p2 <- ggplot(na.omit(locus_df), aes(x = dentist_original_1Mb_10iters_LP, y = susie_original_LP)) +
  geom_point(alpha=0.6) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST original 1Mb window -log10P", y = "SuSiE original -log10P", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p3 <- ggplot(na.omit(locus_df), aes(x = dentist_original_10iters_LP, y = dentist_original_LP)) +
  geom_point(alpha=0.6) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST original 2Mb window 10 iterations -log10P", 
       y = "DENTIST original 2Mb window 1 iteration -log10P", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p4 <- ggplot(na.omit(locus_df), aes(x = dentist_original_1Mb_10iters_LP, y = dentist_original_1Mb_LP)) +
  geom_point(alpha=0.6) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST original 2Mb window 10 iterations -log10P", 
       y = "DENTIST original 2Mb window 1 iteration -log10P", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

cowplot::plot_grid(p1, p2, p3, p4, 
                   labels = c('A', 'B', 'C', 'D'),
                   align="hv")
# Warning: Removed 1 rows containing missing values (`geom_point()`).
# Removed 1 rows containing missing values (`geom_point()`).

Version Author Date
78e8869 kevinlkx 2023-12-07

DENTIST 1 iteration vs. 10 iterations, 1Mb vs. 2Mb window

p1 <- ggplot(na.omit(locus_df), aes(x = dentist_new_LP, y = dentist_new_10iters_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 2Mb window 1 iterations -log10P", 
       y = "DENTIST 2Mb window 10 iteration -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p2 <- ggplot(na.omit(locus_df), aes(x = dentist_new_1Mb_LP, y = dentist_new_1Mb_10iters_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 1Mb window 1 iterations -log10P", 
       y = "DENTIST 1Mb window 10 iteration -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p3 <- ggplot(na.omit(locus_df), aes(x = dentist_new_LP, y = dentist_new_1Mb_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 2Mb window 1iteration -log10P", 
       y = "DENTIST 1Mb window 1iteration -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p4 <- ggplot(na.omit(locus_df), aes(x = dentist_new_10iters_LP, y = dentist_new_1Mb_10iters_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 2Mb window 10 iterations -log10P", 
       y = "DENTIST 1Mb window 10 iterations -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

cowplot::plot_grid(p1, p2, p3, p4, 
                   labels = c('A', 'B', 'C', 'D'),
                   align="hv")
# Warning: Removed 2 rows containing missing values (`geom_point()`).
# Warning: Removed 1 rows containing missing values (`geom_point()`).
# Removed 1 rows containing missing values (`geom_point()`).
# Warning: Removed 2 rows containing missing values (`geom_point()`).

Version Author Date
78e8869 kevinlkx 2023-12-07

DENTIST vs. SuSiE RSS

p1 <- ggplot(na.omit(locus_df), aes(x = dentist_new_LP, y = susie_new_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 2Mb window 1 iteration -log10P", y = "SuSiE -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p2 <- ggplot(na.omit(locus_df), aes(x = dentist_new_1Mb_LP, y = susie_new_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 1Mb window 1 iteration -log10P", y = "SuSiE -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p3 <- ggplot(na.omit(locus_df), aes(x = dentist_new_10iters_LP, y = susie_new_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 2Mb window 10 iterations -log10P", y = "SuSiE -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

p4 <- ggplot(na.omit(locus_df), aes(x = dentist_new_1Mb_10iters_LP, y = susie_new_LP, col = factor(changed))) +
  geom_point(alpha=0.6) +
  scale_colour_manual(values = c("0" = "black", "1" = "red")) +
  xlim(0, 100) + ylim(0, 100) +
  labs(x = "DENTIST 1Mb window 10 iterations -log10P", y = "SuSiE -log10P", 
       color = "Mismatch", 
       title = paste0(trait, " locus", locus)) +
  geom_abline(intercept = 0, slope = 1) + 
  geom_vline(xintercept = -log10(5e-8), col = "red") +
  geom_hline(yintercept = -log10(5e-8), col = "red") +
  theme_bw()

cowplot::plot_grid(p1, p2, p3, p4, 
                   labels = c('A', 'B', 'C', 'D'),
                   align="hv")
# Warning: Removed 2 rows containing missing values (`geom_point()`).
# Removed 2 rows containing missing values (`geom_point()`).
# Removed 2 rows containing missing values (`geom_point()`).
# Removed 2 rows containing missing values (`geom_point()`).

Version Author Date
78e8869 kevinlkx 2023-12-07

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   data.table_1.14.6 ctwas_0.1.35      workflowr_1.7.0  
# 
# loaded via a namespace (and not attached):
#  [1] httr_1.4.4          sass_0.4.5          jsonlite_1.8.4     
#  [4] foreach_1.5.2       pgenlibr_0.3.3      logging_0.10-108   
#  [7] modelr_0.1.10       bslib_0.4.2         assertthat_0.2.1   
# [10] getPass_0.2-2       highr_0.10          googlesheets4_1.0.1
# [13] cellranger_1.1.0    yaml_2.3.7          pillar_1.8.1       
# [16] backports_1.4.1     lattice_0.20-45     glue_1.6.2         
# [19] digest_0.6.31       promises_1.2.0.1    rvest_1.0.3        
# [22] colorspace_2.1-0    cowplot_1.1.1       htmltools_0.5.4    
# [25] httpuv_1.6.5        Matrix_1.5-3        pkgconfig_2.0.3    
# [28] broom_1.0.3         haven_2.5.1         scales_1.2.1       
# [31] processx_3.8.0      whisker_0.4         later_1.3.0        
# [34] tzdb_0.3.0          timechange_0.2.0    git2r_0.30.1       
# [37] googledrive_2.0.0   farver_2.1.1        generics_0.1.3     
# [40] ellipsis_0.3.2      cachem_1.0.6        withr_2.5.0        
# [43] cli_3.6.0           crayon_1.5.2        magrittr_2.0.3     
# [46] readxl_1.4.2        evaluate_0.20       ps_1.7.2           
# [49] fs_1.6.1            fansi_1.0.4         xml2_1.3.3         
# [52] tools_4.2.0         hms_1.1.2           gargle_1.3.0       
# [55] lifecycle_1.0.3     munsell_0.5.0       reprex_2.0.2       
# [58] callr_3.7.3         compiler_4.2.0      jquerylib_0.1.4    
# [61] rlang_1.0.6         grid_4.2.0          iterators_1.0.14   
# [64] rstudioapi_0.14     labeling_0.4.2      rmarkdown_2.20     
# [67] gtable_0.3.1        codetools_0.2-18    DBI_1.1.3          
# [70] R6_2.5.1            lubridate_1.9.2     knitr_1.42         
# [73] fastmap_1.1.0       utf8_1.2.3          rprojroot_2.0.3    
# [76] stringi_1.7.12      Rcpp_1.0.10         vctrs_0.5.2        
# [79] dbplyr_2.3.0        tidyselect_1.2.0    xfun_0.37