Last updated: 2024-09-13

Checks: 6 1

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.


The R Markdown is untracked by Git. 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 0384492. 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:    results/

Untracked files:
    Untracked:  analysis/compare_pip_func_LDL.Rmd

Unstaged changes:
    Modified:   analysis/index.Rmd
    Deleted:    multi_group_compare_predictdb_munro_updated.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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


library(ctwas)
library(EnsDb.Hsapiens.v86)
library(ggplot2)
library(RColorBrewer)
library(dplyr)
library(tidyr)
library(gridExtra)

load("/project2/xinhe/shared_data/multigroup_ctwas/weights/E_S_A_mapping_updated.RData")
colnames(E_S_A_mapping)[1] <- "molecular_id"

ens_db <- EnsDb.Hsapiens.v86

trait <- "LDL-ukb-d-30780_irnt"
gwas_n <- 343621

source("/project/xinhe/xsun/r_functions/combine_pip_old_ctwas.R")
source("/project/xinhe/xsun/r_functions/anno_finemap_res_old_ctwas.R")

palette <- c(brewer.pal(12, "Paired"), brewer.pal(12, "Set3"), brewer.pal(6, "Dark2"))

LDL – eQTL + sQTL from predictdb

results_dir_multi <- paste0("/project/xinhe/xsun/multi_group_ctwas/xxxintalk/results_predictdb_main_multi/",trait,"/")

finemap.res.multi <- readRDS(paste0(results_dir_multi,trait,".ctwas.res.RDS"))
snp_map.multi <- readRDS(paste0(results_dir_multi,trait,".snp_map.RDS"))
res.multi <- finemap.res.multi$finemap_res
res.multi <- res.multi %>%
  separate(id, into = c("molecular_id", "expression_info"), sep = "\\|", remove = FALSE)

res.multi <- anno_finemap_res(res.multi,
                                snp_map = snp_map.multi,
                                mapping_table = E_S_A_mapping,
                                add_gene_annot = TRUE,
                                map_by = "molecular_id",
                                drop_unmapped = TRUE,
                                add_position = TRUE,
                                use_gene_pos = "mid")
2024-09-13 16:25:08 INFO::Annotating fine-mapping result ...
2024-09-13 16:25:08 INFO::Map molecular traits to genes
2024-09-13 16:25:08 INFO::Split PIPs for molecular traits mapped to multiple genes
2024-09-13 16:25:13 INFO::Add gene positions
2024-09-13 16:25:13 INFO::Add SNP positions
combined_pip_cs <- combine_gene_pips(finemap_res = res.multi,
                                     group_by = "gene_name",
                                     by = "type",
                                     method = "combine_cs",
                                     filter_cs = TRUE)
2024-09-13 16:25:26 INFO::Limit gene results to credible sets
combined_pip_all <- combine_gene_pips(finemap_res = res.multi,
                                     group_by = "gene_name",
                                     by = "type",
                                     method = "combine_all",
                                     filter_cs = TRUE)
2024-09-13 16:25:27 INFO::Limit gene results to credible sets
combined_pip_sum <- combine_gene_pips(finemap_res = res.multi,
                                     group_by = "gene_name",
                                     by = "type",
                                     method = "sum",
                                     filter_cs = TRUE)
2024-09-13 16:25:27 INFO::Limit gene results to credible sets
merged_pip <- full_join(combined_pip_cs, combined_pip_all, by = "gene_name", suffix = c(".cs", ".all"))
merged_pip <- full_join(merged_pip, combined_pip_sum, by = "gene_name")

merged_pip <- merged_pip[,c("gene_name","eQTL_pip.cs", "sQTL_pip.cs","combined_pip.cs","combined_pip.all","combined_pip")]
colnames(merged_pip) <- c("gene_name","eQTL_pip", "sQTL_pip","combined_pip.cs", "combined_pip.all","combined_pip.sum")

DT::datatable(merged_pip,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Genes with PIP > 0.8'),options = list(pageLength = 10) )
sprintf("setting 1: adding up signals, we have %s genes with combined_pip > 0.8", sum(merged_pip$combined_pip.sum > 0.8))
[1] "setting 1: adding up signals, we have 64 genes with combined_pip > 0.8"
sprintf("setting 2: combining by CS, we have %s genes with combined_pip > 0.8", sum(merged_pip$combined_pip.cs > 0.8))
[1] "setting 2: combining by CS, we have 62 genes with combined_pip > 0.8"
sprintf("setting 3: combining all molecular signals with in a gene, we have %s genes with combined_pip > 0.8", sum(merged_pip$combined_pip.all > 0.8))
[1] "setting 3: combining all molecular signals with in a gene, we have 37 genes with combined_pip > 0.8"
print("comparing combined_pip.cs and combined_pip.sum, the two missed genes are PSRC1 and ASGR1")
[1] "comparing combined_pip.cs and combined_pip.sum, the two missed genes are PSRC1 and ASGR1"
p1 <- ggplot(merged_pip, aes(x = combined_pip.sum, y = combined_pip.cs)) +
  geom_point() +  # Scatter plot
  geom_abline(intercept = 0, slope = 1, color = "red", linetype = "dashed") +  # Add y = x line
  labs(x = "Combined PIP -- adding up all signals", y = "Combined by CS") +
  theme_minimal()

p2 <- ggplot(merged_pip, aes(x = combined_pip.sum, y = combined_pip.all)) +
  geom_point() +  # Scatter plot
  geom_abline(intercept = 0, slope = 1, color = "red", linetype = "dashed") +  # Add y = x line
  labs(x = "Combined PIP -- adding up all signals", y = "Combined by gene") +
  theme_minimal()

grid.arrange(p1, p2, ncol = 2)


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] C

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

other attached packages:
 [1] gridExtra_2.3             tidyr_1.3.0              
 [3] dplyr_1.1.4               RColorBrewer_1.1-3       
 [5] ggplot2_3.5.1             EnsDb.Hsapiens.v86_2.99.0
 [7] ensembldb_2.20.2          AnnotationFilter_1.20.0  
 [9] GenomicFeatures_1.48.3    AnnotationDbi_1.58.0     
[11] Biobase_2.56.0            GenomicRanges_1.48.0     
[13] GenomeInfoDb_1.39.9       IRanges_2.30.0           
[15] S4Vectors_0.34.0          BiocGenerics_0.42.0      
[17] ctwas_0.4.12             

loaded via a namespace (and not attached):
  [1] colorspace_2.0-3            rjson_0.2.21               
  [3] ellipsis_0.3.2              rprojroot_2.0.3            
  [5] XVector_0.36.0              locuszoomr_0.2.1           
  [7] fs_1.5.2                    rstudioapi_0.13            
  [9] farver_2.1.0                DT_0.22                    
 [11] ggrepel_0.9.1               bit64_4.0.5                
 [13] fansi_1.0.3                 xml2_1.3.3                 
 [15] codetools_0.2-18            logging_0.10-108           
 [17] cachem_1.0.6                knitr_1.39                 
 [19] jsonlite_1.8.0              workflowr_1.7.0            
 [21] Rsamtools_2.12.0            dbplyr_2.1.1               
 [23] png_0.1-7                   readr_2.1.2                
 [25] compiler_4.2.0              httr_1.4.3                 
 [27] assertthat_0.2.1            Matrix_1.5-3               
 [29] fastmap_1.1.0               lazyeval_0.2.2             
 [31] cli_3.6.1                   later_1.3.0                
 [33] htmltools_0.5.2             prettyunits_1.1.1          
 [35] tools_4.2.0                 gtable_0.3.0               
 [37] glue_1.6.2                  GenomeInfoDbData_1.2.8     
 [39] rappdirs_0.3.3              Rcpp_1.0.12                
 [41] jquerylib_0.1.4             vctrs_0.6.5                
 [43] Biostrings_2.64.0           rtracklayer_1.56.0         
 [45] crosstalk_1.2.0             xfun_0.41                  
 [47] stringr_1.5.1               lifecycle_1.0.4            
 [49] irlba_2.3.5                 restfulr_0.0.14            
 [51] XML_3.99-0.14               zlibbioc_1.42.0            
 [53] zoo_1.8-10                  scales_1.3.0               
 [55] gggrid_0.2-0                hms_1.1.1                  
 [57] promises_1.2.0.1            MatrixGenerics_1.8.0       
 [59] ProtGenerics_1.28.0         parallel_4.2.0             
 [61] SummarizedExperiment_1.26.1 LDlinkR_1.2.3              
 [63] yaml_2.3.5                  curl_4.3.2                 
 [65] memoise_2.0.1               sass_0.4.1                 
 [67] biomaRt_2.54.1              stringi_1.7.6              
 [69] RSQLite_2.3.1               highr_0.9                  
 [71] BiocIO_1.6.0                filelock_1.0.2             
 [73] BiocParallel_1.30.3         rlang_1.1.2                
 [75] pkgconfig_2.0.3             matrixStats_0.62.0         
 [77] bitops_1.0-7                evaluate_0.15              
 [79] lattice_0.20-45             purrr_1.0.2                
 [81] labeling_0.4.2              GenomicAlignments_1.32.0   
 [83] htmlwidgets_1.5.4           cowplot_1.1.1              
 [85] bit_4.0.4                   tidyselect_1.2.0           
 [87] magrittr_2.0.3              R6_2.5.1                   
 [89] generics_0.1.2              DelayedArray_0.22.0        
 [91] DBI_1.2.2                   withr_2.5.0                
 [93] pgenlibr_0.3.3              pillar_1.9.0               
 [95] KEGGREST_1.36.3             RCurl_1.98-1.7             
 [97] mixsqp_0.3-43               tibble_3.2.1               
 [99] crayon_1.5.1                utf8_1.2.2                 
[101] BiocFileCache_2.4.0         plotly_4.10.0              
[103] tzdb_0.4.0                  rmarkdown_2.25             
[105] progress_1.2.2              grid_4.2.0                 
[107] data.table_1.14.2           blob_1.2.3                 
[109] git2r_0.30.1                digest_0.6.29              
[111] httpuv_1.6.5                munsell_0.5.0              
[113] viridisLite_0.4.0           bslib_0.3.1