Last updated: 2023-10-11

Checks: 7 0

Knit directory: meSuSie_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(20220530) 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 fbd46f6. 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:


Untracked files:
    Untracked:  data/GLGC_chr_22.txt
    Untracked:  data/MESuSiE_Example.RData
    Untracked:  data/UKBB_chr_22.txt

Unstaged changes:
    Deleted:    analysis/illustration.Rmd
    Deleted:    analysis/toy_example.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/Lipid_810.Rmd) and HTML (docs/Lipid_810.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 fbd46f6 borangao 2023-10-11 Update yml
html 78f00ea borangao 2023-10-11 Build site.
Rmd 1f54cb8 borangao 2023-10-11 Update my analysis
html 428bdf0 borangao 2023-10-09 Build site.
Rmd ba8db56 borangao 2023-10-09 Update my analysis
html 504f3a9 borangao 2023-10-09 Build site.
Rmd 62ce4b3 borangao 2023-10-09 Update my analysis

810 Regions of 4 lipid traits

Note: all the code and analysis reproduced here can be found in Repository

This analysis is done by relaxing the P-value threshold when constructing candidate regions.

Feature of 95% credible set

a. Set size and eQTL enrichment of 95% credible set

library(ggpubr)
library(data.table)
library(dplyr)
library(tidyr)
library(ggplot2)
library(patchwork)
library(ggpmisc)
library(VennDiagram)
library(gridExtra)
library(ggbreak)
library(DescTools)
library(coin)
library(susieR)
library(ggrepel)
library(stringr)


load("/net/fantasia/home/borang/Susie_Mult/Revision_Round_1/01_07_Real_Data/summary_res/res.RData")

#####################################################################
#
#     Plot directory and theme
#
####################################################################
plot_dir<-"/net/fantasia/home/borang/Susie_Mult/Revision_Round_1/Real_Data/Lipid_810/Figure/"
system(paste0("mkdir -p ",plot_dir))
custom_theme <- function() {
  theme(
    axis.text.x = element_text(size = 5),
    axis.text.y = element_text(size = 5),  
    axis.title.x = element_text(size = 7, face="bold"),
    axis.title.y = element_text(size = 7, face="bold"),
    strip.text.x = element_text(size = 5),
    strip.text.y = element_text(size = 5),
    strip.background = element_blank(),
    legend.text = element_text(size=7),
    legend.title = element_text(size=7, face="bold"),
    plot.title = element_text(size=7, hjust = 0.5),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.border = element_blank(), 
    axis.line = element_line(color = "black")
  )
}
################################################
#
#       Set Size/Z-score/eQTL 
#
#
###############################################
################################################
#
#       Set SiZe Part
#
###############################################     
###Median set size by Trait
all_sets_info<-data.frame(res_all%>%group_by(Trait,Region) %>% summarise(across(c("MESuSiE_cs", "SuSiE_cs","Paintor_cs"), ~ sum(.x, na.rm = TRUE))))%>%filter(MESuSiE_cs!=0, SuSiE_cs!=0, Paintor_cs!=0) ###Median Set Size across all locus
all_sets_info_long<-all_sets_info%>%pivot_longer(!(Trait|Region), names_to = "Method", values_to = "Count")
all_sets_info_long$Method<-factor(all_sets_info_long$Method,levels=c("MESuSiE_cs","SuSiE_cs","Paintor_cs"))
levels(all_sets_info_long$Method)<-c("MESuSiE","SuSiE","Paintor")

p_set = ggplot(data =all_sets_info_long,aes(x = Trait, y=Count,fill=Method))+geom_boxplot(aes(x = Trait,fill=Method),outlier.size = 0.1,fatten = 0.5,color = "darkgray")+scale_fill_manual(values=c("MESuSiE"="#023e8a","SuSiE"="#2a9d8f","Paintor"="#f4a261"),guide=FALSE)
p_set =p_set + theme_bw() + xlab("") +ylab("Set Size")+coord_cartesian(ylim=c(0,175))
p_set= p_set+custom_theme()

################################################
#
#       Z-score Part
#
###############################################     
MESuSiE_cs_Z<-res_all%>%group_by(Trait) %>%filter(MESuSiE_cs==1)%>%summarise(zmax = median(pmax(abs(zscore_WB),abs(zscore_BB))))
SuSiE_cs_Z<-res_all%>%group_by(Trait) %>%filter(SuSiE_cs==1)%>%summarise(zmax =median(pmax(abs(zscore_WB),abs(zscore_BB))))%>%pull(zmax)
Paintor_cs_Z<-res_all%>%group_by(Trait) %>%filter(Paintor_cs==1)%>%summarise(zmax = median(pmax(abs(zscore_WB),abs(zscore_BB))))%>%pull(zmax)
set_size_z_info<-data.frame(cbind(MESuSiE_cs_Z,SuSiE_cs_Z,Paintor_cs_Z))
colnames(set_size_z_info)<-c("Trait",c("MESuSiE","SuSiE","Paintor"))
set_size_z_info_long<-set_size_z_info %>%pivot_longer(!(Trait), names_to = "Method", values_to = "Z")%>%mutate(Method = factor(Method, levels=c("MESuSiE","SuSiE","Paintor")))

p_z = ggplot(data = set_size_z_info_long,aes(x = Trait, y=Z,fill=Method))+geom_bar( stat = "identity",position="dodge")+scale_fill_manual(values=c("MESuSiE"="#023e8a","SuSiE"="#2a9d8f","Paintor"="#f4a261"))
p_z = p_z + geom_text(label = round(set_size_z_info_long$Z,2),position = position_dodge(width = 1),vjust=-0.5,size = 5*5/14)
p_z = p_z + theme_bw() + xlab("") +ylab("Median |Z|")+ ylim(0,max(round(set_size_z_info_long$Z,2)+1))
p_z = p_z +custom_theme()
################################################
#
#       eQTL enrichment 
#
#
############################################### 
  ann_col_name<-c("missense", "synonymous", "utr_comb", "promotor", "CRE","liver_ind_eQTL")
  # Functions for calculating fold enrichment
  calc_fold_enrichment <- function(df, cs_col, ann_col_name) {
    df %>%
      group_by(Region) %>%
      filter(sum(!!sym(cs_col)) != 0) %>%
      group_by(Trait, !!sym(cs_col)) %>%
      summarise(across(ann_col_name, ~ sum(.x, na.rm = TRUE) / n())) %>%
      group_by(Trait) %>%
      summarise(across(ann_col_name, ~ .x[!!sym(cs_col) == 1] / .x[!!sym(cs_col) == 0]))
  }
  res_all<-res_all%>%mutate(utr_comb = ifelse((utr_5+utr_3)!=0,1,0))
  MESuSiE_PIP_ann <- calc_fold_enrichment(res_all, "MESuSiE_cs", ann_col_name)
  SuSiE_PIP_ann <- calc_fold_enrichment(res_all, "SuSiE_cs", ann_col_name)
  Paintor_PIP_ann <- calc_fold_enrichment(res_all, "Paintor_cs", ann_col_name)
  # Combine results
  Trait_CS_enrichment <- bind_rows(
    MESuSiE_PIP_ann %>% mutate(Method = "MESuSiE"),
    SuSiE_PIP_ann %>% mutate(Method = "SuSiE"),
    Paintor_PIP_ann %>% mutate(Method = "Paintor")
  ) %>% mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor")))%>%
    dplyr::select(Trait,liver_ind_eQTL ,Method )%>%dplyr::rename(eQTL = liver_ind_eQTL)
  # Pivot to long format
  Trait_CS_enrichment_long <- Trait_CS_enrichment %>%
    pivot_longer(cols = -c(Method, Trait), names_to = "Cat", values_to = "Prop") %>%
    mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor")))


  
p_eQTL <- ggplot(Trait_CS_enrichment_long, aes(x = Trait, y = Prop, fill = Method)) +
  geom_bar(stat = "identity", position = "dodge") +scale_fill_manual(values = c("MESuSiE" = "#023e8a", "SuSiE" = "#2a9d8f", "Paintor" = "#f4a261")) +
  geom_text(,label = round(Trait_CS_enrichment_long$Prop,2),position = position_dodge(width = 1),vjust=-0.5,size = 5*5/14)+
  xlab("") + ylab("eQTL Fold Enrichment") + ylim(0,max(round(Trait_CS_enrichment_long$Prop))+1)+
  theme_bw() + custom_theme()

p_out<-p_set/p_z/p_eQTL+plot_layout(guides = "collect",heights = c(1.5,1,1))+plot_annotation(tag_levels = 'a')&theme(legend.position = 'bottom',plot.tag = element_text(size = 7, face = "bold"))
p_out

Version Author Date
504f3a9 borangao 2023-10-09

b. Functional enrichment of 95% credible set and top signals

################################################################################
#
#
#     Functional Annotation enrichment for 95% credible set SNPS
#
#
################################################################################
# Enrichment of 95% credible set without by trait
  calc_fold_enrichment_marginal<-function(df, cs_col, ann_col_name) {
    df %>%group_by(Region) %>%
      filter(sum(!!sym(cs_col)) != 0) %>%
      group_by( !!sym(cs_col)) %>%
      summarise(across(ann_col_name, ~ sum(.x, na.rm = TRUE) / n())) %>%
      summarise(across(ann_col_name, ~ .x[!!sym(cs_col) == 1] / .x[!!sym(cs_col) == 0]))
  }
  MESuSiE_PIP_ann <- calc_fold_enrichment_marginal(res_all, "MESuSiE_cs", ann_col_name)
  SuSiE_PIP_ann <- calc_fold_enrichment_marginal(res_all, "SuSiE_cs", ann_col_name)
  Paintor_PIP_ann <- calc_fold_enrichment_marginal(res_all, "Paintor_cs", ann_col_name)
  
  CS_enrichment <- bind_rows(
    MESuSiE_PIP_ann %>% mutate(Method = "MESuSiE"),
    SuSiE_PIP_ann %>% mutate(Method = "SuSiE"),
    Paintor_PIP_ann %>% mutate(Method = "Paintor")
  ) %>% mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor")))%>% 
    dplyr::rename(Missense = missense ,Synonymous = synonymous,UTR = utr_comb,Promotor = promotor,eQTL = liver_ind_eQTL)
  # Pivot to long format
  CS_enrichment_long <- CS_enrichment %>%
    pivot_longer(cols = -c(Method), names_to = "Cat", values_to = "Prop") %>%
    mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor"))) %>%
    mutate(Cat = factor(Cat, levels = c("Missense", "Synonymous", "UTR", "Promotor", "CRE","eQTL")))%>%
    mutate(Prop = round(Prop, 2))
p_set <- ggplot(data = CS_enrichment_long,aes(x = Cat, y = Prop, fill = Method)) +
  geom_col(position = "dodge") + scale_fill_manual(values = c("MESuSiE" = "#023e8a", "SuSiE" = "#2a9d8f", "Paintor" = "#f4a261")) +
  geom_text(aes(x=Cat,group=Method,y=Prop,label=Prop),position = position_dodge(width = 1),vjust=-0.5,size = 5/14*5) + 
  geom_hline(yintercept = 1, linetype = "dashed") + 
  xlab("") + ylab("Fold Enrichment Credible Set") +ylim(0,round(max(CS_enrichment_long$Prop))+1) +
  theme_bw() + custom_theme()
################################################################################
#
#
#     Functional Annotation enrichment for top 500 PIP SNPs
#
#
################################################################################    
  # Enrichment of top 500 signal
  top_N_signal = 500
  bg_an<-res_all%>%summarise(across(ann_col_name,~ sum(.x, na.rm = TRUE)/n()))
  MESuSiE_Signal_ann<-res_all%>%filter(MESuSiE_PIP_Shared>0.5|MESuSiE_PIP_WB>0.5|MESuSiE_PIP_BB>0.5)%>% arrange(desc(MESuSiE_PIP_Either))%>%top_n(n = top_N_signal, wt = MESuSiE_PIP_Either)%>%summarise(across(ann_col_name,~ sum(.x, na.rm = TRUE)/n()))/bg_an
  SuSiE_Signal_ann<-res_all%>%filter(SuSiE_PIP>0.5)%>% arrange(desc(SuSiE_PIP))%>%top_n(n = top_N_signal, wt = SuSiE_PIP)%>%summarise(across(ann_col_name,~ sum(.x, na.rm = TRUE)/n()))/bg_an
  Paintor_Signal_ann<-res_all%>%filter(Paintor_PIP>0.5) %>% arrange(desc(Paintor_PIP))%>%top_n(n = top_N_signal, wt = Paintor_PIP)%>%summarise(across(ann_col_name,~ sum(.x, na.rm = TRUE)/n()))/bg_an
  
  Signal_enrichment <- bind_rows(
    MESuSiE_Signal_ann %>% mutate(Method = "MESuSiE"),
    SuSiE_Signal_ann %>% mutate(Method = "SuSiE"),
    Paintor_Signal_ann %>% mutate(Method = "Paintor")
  ) %>% mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor")))%>% 
    dplyr::rename(Missense = missense ,Synonymous = synonymous,UTR = utr_comb,Promotor = promotor,eQTL = liver_ind_eQTL)
  # Pivot to long format
  Signal_enrichment_long <- Signal_enrichment %>%
    pivot_longer(cols = -c(Method), names_to = "Cat", values_to = "Prop") %>%
    mutate(Method = factor(Method, levels = c("MESuSiE", "SuSiE", "Paintor"))) %>%
    mutate(Cat = factor(Cat, levels = c("Missense", "Synonymous", "UTR", "Promotor", "CRE","eQTL")))%>%
    mutate(Prop = round(Prop, 2))

p_signal <- ggplot(data = Signal_enrichment_long,aes(x = Cat, y = Prop, fill = Method)) +
  geom_col(position = "dodge") + scale_fill_manual(values = c("MESuSiE" = "#023e8a", "SuSiE" = "#2a9d8f", "Paintor" = "#f4a261")) +
  geom_text(aes(x=Cat,group=Method,y=Prop,label=Prop),position = position_dodge(width = 1),vjust=-0.5,size = 5/14*5) + 
  geom_hline(yintercept = 1, linetype = "dashed") + 
  xlab("") + ylab("Fold Enrichment Top Signal") +ylim(0,round(max(Signal_enrichment_long$Prop))+1) +
  theme_bw() + custom_theme()
p_out<-p_set/p_signal+plot_annotation(tag_levels = 'a')&theme(legend.position = 'bottom',plot.tag = element_text(size = 7, face = "bold"))
p_out

Version Author Date
504f3a9 borangao 2023-10-09

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3;  LAPACK version 3.9.0

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       

time zone: America/New_York
tzcode source: system (glibc)

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

other attached packages:
 [1] stringr_1.5.0       ggrepel_0.9.1       susieR_0.11.84     
 [4] coin_1.4-2          survival_3.3-1      DescTools_0.99.45  
 [7] ggbreak_0.1.1       gridExtra_2.3       VennDiagram_1.7.3  
[10] futile.logger_1.4.3 ggpmisc_0.4.7       ggpp_0.4.4         
[13] patchwork_1.1.1     tidyr_1.3.0         dplyr_1.1.2        
[16] data.table_1.14.8   ggpubr_0.6.0        ggplot2_3.4.2      
[19] workflowr_1.7.0    

loaded via a namespace (and not attached):
  [1] formatR_1.14         gld_2.6.5            sandwich_3.0-2      
  [4] readxl_1.4.2         rlang_1.1.1          magrittr_2.0.3      
  [7] git2r_0.32.0         multcomp_1.4-25      matrixStats_1.0.0   
 [10] e1071_1.7-13         compiler_4.3.1       getPass_0.2-2       
 [13] callr_3.7.3          vctrs_0.6.2          quantreg_5.95       
 [16] crayon_1.5.2         pkgconfig_2.0.3      fastmap_1.1.1       
 [19] backports_1.4.1      labeling_0.4.2       utf8_1.2.3          
 [22] promises_1.2.0.1     rmarkdown_2.22       ps_1.7.2            
 [25] MatrixModels_0.5-1   purrr_1.0.1          xfun_0.39           
 [28] modeltools_0.2-23    cachem_1.0.8         aplot_0.1.10        
 [31] jsonlite_1.8.3       highr_0.10           later_1.3.1         
 [34] reshape_0.8.9        irlba_2.3.5.1        broom_1.0.5         
 [37] parallel_4.3.1       R6_2.5.1             bslib_0.5.0         
 [40] stringi_1.7.12       car_3.1-2            boot_1.3-28.1       
 [43] jquerylib_0.1.4      cellranger_1.1.0     Rcpp_1.0.11         
 [46] knitr_1.39           zoo_1.8-12           httpuv_1.6.11       
 [49] Matrix_1.5-4.1       splines_4.3.1        tidyselect_1.2.0    
 [52] rstudioapi_0.14      abind_1.4-5          yaml_2.3.7          
 [55] codetools_0.2-19     processx_3.8.0       plyr_1.8.8          
 [58] lattice_0.20-45      tibble_3.2.1         withr_2.5.1         
 [61] evaluate_0.18        gridGraphics_0.5-1   lambda.r_1.2.4      
 [64] proxy_0.4-27         pillar_1.9.0         carData_3.0-5       
 [67] whisker_0.4.1        stats4_4.3.1         ggfun_0.0.9         
 [70] generics_0.1.3       rprojroot_2.0.3      munsell_0.5.0       
 [73] scales_1.2.1         rootSolve_1.8.2.3    class_7.3-20        
 [76] glue_1.6.2           lmom_2.8             tools_4.3.1         
 [79] SparseM_1.81         ggsignif_0.6.4       Exact_3.1           
 [82] fs_1.6.2             mvtnorm_1.1-3        libcoin_1.0-9       
 [85] colorspace_2.1-0     cli_3.6.1            futile.options_1.0.1
 [88] fansi_1.0.5          expm_0.999-7         mixsqp_0.3-48       
 [91] gtable_0.3.1         rstatix_0.7.2        yulab.utils_0.0.4   
 [94] sass_0.4.6           digest_0.6.30        TH.data_1.1-2       
 [97] ggplotify_0.1.0      farver_2.1.1         htmltools_0.5.5     
[100] lifecycle_1.0.3      httr_1.4.6           MASS_7.3-57