Last updated: 2025-04-08

Checks: 6 1

Knit directory: multigroup_ctwas_analysis/

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


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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 2be4346. 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:    analysis/comparing_differnt_settings_ldmm.html
    Ignored:    cv/

Untracked files:
    Untracked:  knitrmd.sbatch
    Untracked:  render_rmd.R
    Untracked:  slurm-30301033.out
    Untracked:  slurm-30301042.out
    Untracked:  slurm-30301317.out

Unstaged changes:
    Modified:   analysis/comparing_differnt_settings_ldmm.Rmd
    Modified:   analysis/comparing_munro_susie_st.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/comparing_differnt_settings_ldmm.Rmd) and HTML (docs/comparing_differnt_settings_ldmm.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 4c80969 XSun 2025-02-24 update

Introduction

We compare different ld - mismatch settings

  • remove the ld-mismatched snp, recompute the z-scores and re-do the finemapping
  • re-finemap without LD
library(ggplot2)
folder_results_susieST <- "/project/xinhe/xsun/multi_group_ctwas/15.susie_weights/snakemake_outputs/"

IBD-ebi-a-GCST004131

Setting: shared_all, thin = 0.1, L = 5, susieST

trait <- "IBD-ebi-a-GCST004131"
thin <- 0.1
var_struc <- "shared_all"
st <- "with_susieST"
L <- 5

ctwas_res_origin <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".finemap_regions_res.RDS"))
finemap_res_origin <- ctwas_res_origin$finemap_res
finemap_res_gene_origin <- finemap_res_origin[finemap_res_origin$type != "SNP",]

ctwas_res_regionmerge <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".regionmerge_finemap_regions_res.RDS"))
finemap_res_regionmerge <- ctwas_res_regionmerge$finemap_res
finemap_res_gene_regionmerge <- finemap_res_regionmerge[finemap_res_regionmerge$type != "SNP",]

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.5, SNP p_diff = 5e-8

threshold_nonSNP_PIPs <- 0.5
threshold_SNP_p <- "5e-08"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.5, SNP p_diff = 5e-6

threshold_nonSNP_PIPs <- 0.5
threshold_SNP_p <- "5e-06"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-8

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-08"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-6

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-06"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4, 
                        ncol = 4, 
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))   

gene_weird <- finemap_res_gene_origin[abs(finemap_res_gene_origin$z)< 1 & finemap_res_gene_origin$susie_pip > 0.3,]$id
gene_weird_ldmismatch <- finemap_res_gene_ldmismatch[finemap_res_gene_ldmismatch$id %in% gene_weird,]


prob_gene <- finemap_res_gene_origin[finemap_res_gene_origin$id %in% problematic_genes,]

DT::datatable(gene_weird_ldmismatch,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;','Gene disappeared'),options = list(pageLength = 10) )
DT::datatable(prob_gene,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;','Problematic genes'),options = list(pageLength = 10) )

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-4

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-04"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4, 
                        ncol = 4, 
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))   

aFib-ebi-a-GCST006414

Setting: shared_all, thin = 0.1, L = 5, susieST

trait <- "aFib-ebi-a-GCST006414"
thin <- 0.1
var_struc <- "shared_all"
st <- "with_susieST"
L <- 5

ctwas_res_origin <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".finemap_regions_res.RDS"))
finemap_res_origin <- ctwas_res_origin$finemap_res
finemap_res_gene_origin <- finemap_res_origin[finemap_res_origin$type != "SNP",]

ctwas_res_regionmerge <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".regionmerge_finemap_regions_res.RDS"))
finemap_res_regionmerge <- ctwas_res_regionmerge$finemap_res
finemap_res_gene_regionmerge <- finemap_res_regionmerge[finemap_res_regionmerge$type != "SNP",]

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.5, SNP p_diff = 5e-8

threshold_nonSNP_PIPs <- 0.5
threshold_SNP_p <- "5e-08"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.5, SNP p_diff = 5e-6

threshold_nonSNP_PIPs <- 0.5
threshold_SNP_p <- "5e-06"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-8

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-08"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) +
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4,
                        ncol = 4,
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-6

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-06"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4, 
                        ncol = 4, 
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))   

Thresholds for ld mismatch diagnosis: nonSNP PIP = 0.2, SNP p_diff = 5e-4

threshold_nonSNP_PIPs <- 0.2
threshold_SNP_p <- "5e-04"
problematic_genes <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_problematic_genes_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))

finemap_res_gene_origin$highlight <- ifelse(finemap_res_gene_origin$id %in% problematic_genes, "problematic genes", "good genes")

p1 <- ggplot(data = finemap_res_gene_origin, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("Original ctwas results") +
  theme_minimal()

finemap_res_gene_regionmerge$highlight <- ifelse(finemap_res_gene_regionmerge$id %in% problematic_genes, "problematic genes", "good genes")

p2 <- ggplot(data = finemap_res_gene_regionmerge, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("After region merge") +
  theme_minimal()

ctwas_res_ldmismatch <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatch <- ctwas_res_ldmismatch$finemap_res
finemap_res_gene_ldmismatch <- finemap_res_ldmismatch[finemap_res_ldmismatch$type != "SNP",]
finemap_res_gene_ldmismatch$highlight <- ifelse(finemap_res_gene_ldmismatch$id %in% problematic_genes, "problematic genes", "good genes")

p3 <- ggplot(data = finemap_res_gene_ldmismatch, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

ctwas_res_ldmismatchnoLD <- readRDS(paste0(folder_results_susieST,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L,".ldmismatch_noLD_finemap_regions_res_genepip",threshold_nonSNP_PIPs,"_snpp_",threshold_SNP_p,".RDS"))
finemap_res_ldmismatchnoLD <- ctwas_res_ldmismatchnoLD$finemap_res
finemap_res_gene_ldmismatchnoLD <- finemap_res_ldmismatchnoLD[finemap_res_ldmismatchnoLD$type != "SNP",]
finemap_res_gene_ldmismatchnoLD$highlight <- ifelse(finemap_res_gene_ldmismatchnoLD$id %in% problematic_genes, "problematic genes", "good genes")

p4 <- ggplot(data = finemap_res_gene_ldmismatchnoLD, aes(x= abs(z), y= susie_pip, color = highlight)) + 
  geom_point() +
  scale_color_manual(values = c("problematic genes" = "red", "good genes" = "black")) +
  ggtitle("LD mismatch fixed -- remove the snp") +
  theme_minimal()

grid::grid.newpage()
gridExtra::grid.arrange(p1,p2,p3,p4, 
                        ncol = 4, 
                        top = paste0(trait,"-nonSNP_PIPs:",threshold_nonSNP_PIPs,"-SNP_p:",threshold_SNP_p))   


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

Matrix products: default
BLAS/LAPACK: /software/openblas-0.3.13-el8-x86_64/lib/libopenblas_skylakexp-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] ggplot2_3.4.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.14       highr_0.9         pillar_1.9.0      compiler_4.2.0   
 [5] bslib_0.3.1       later_1.3.0       jquerylib_0.1.4   git2r_0.30.1     
 [9] workflowr_1.7.1   tools_4.2.0       digest_0.6.29     jsonlite_1.8.9   
[13] evaluate_0.15     lifecycle_1.0.4   tibble_3.2.1      gtable_0.3.0     
[17] pkgconfig_2.0.3   rlang_1.1.2       cli_3.6.2         rstudioapi_0.14  
[21] crosstalk_1.2.0   yaml_2.3.5        xfun_0.38         fastmap_1.1.0    
[25] gridExtra_2.3     withr_2.5.0       dplyr_1.1.2       stringr_1.5.0    
[29] knitr_1.42        htmlwidgets_1.6.2 generics_0.1.3    fs_1.5.2         
[33] vctrs_0.6.1       sass_0.4.1        DT_0.22           tidyselect_1.2.0 
[37] rprojroot_2.0.3   grid_4.2.0        glue_1.6.2        R6_2.5.1         
[41] fansi_1.0.3       rmarkdown_2.21    farver_2.1.0      magrittr_2.0.3   
[45] whisker_0.4       ellipsis_0.3.2    scales_1.2.0      promises_1.2.0.1 
[49] htmltools_0.5.7   colorspace_2.0-3  httpuv_1.6.5      labeling_0.4.2   
[53] utf8_1.2.2        stringi_1.7.6     munsell_0.5.0