Last updated: 2025-01-07

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 1ddb625. 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

Untracked files:
    Untracked:  analysis/LDL_silver_standard.Rmd
    Untracked:  analysis/multi_group_downstream_analysis.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.


Introduction

We used the LDL genes reported by multi-group analysis after postprocess to do some downstream analysiss.

library(ctwas)
library(dplyr)
library(EnsDb.Hsapiens.v86)
library(pheatmap)
ens_db <- EnsDb.Hsapiens.v86

mapping_predictdb <- readRDS("/project2/xinhe/shared_data/multigroup_ctwas/weights/mapping_files/PredictDB_mapping.RDS")
mapping_munro <- readRDS("/project2/xinhe/shared_data/multigroup_ctwas/weights/mapping_files/Munro_mapping.RDS")
mapping_two <- rbind(mapping_predictdb,mapping_munro)


plot_heatmap_byomics <- function(heatmap_data, main) {

  rownames(heatmap_data) <- heatmap_data$gene_name
  heatmap_data <- heatmap_data %>% dplyr::select(-gene_name, -combined_pip)

  if(nrow(heatmap_data) ==1){

    heatmap_data <- rbind(heatmap_data,rep(0,ncol(heatmap_data)))
    rownames(heatmap_data)[2] <- "fake_gene_for_plotting"

  }

  heatmap_matrix <- as.matrix(heatmap_data)

  p <- pheatmap(heatmap_matrix,
                cluster_rows = F,   # Cluster the rows (genes)
                cluster_cols = F,   # Cluster the columns (QTL types)
                color = colorRampPalette(c("white", "red"))(50), # Color gradient
                display_numbers = TRUE, # Display numbers in cells
                main = main,labels_row = rownames(heatmap_data), silent = T)

  return(p)
}

plot_heatmap_bytissue <- function(heatmap_data, main, tissues) {
  
  rownames(heatmap_data) <- heatmap_data$gene_name
  heatmap_data <- heatmap_data %>% dplyr::select(-gene_name, -combined_pip)
  
  pip_types <- c("|eQTL_pip", "|sQTL_pip", "|stQTL_pip")

  combinations <- expand.grid(pip_types, tissues)
  order <- paste0(combinations$Var2, combinations$Var1)
  
  heatmap_data <- heatmap_data[,order]
  
  if(nrow(heatmap_data) ==1){
    
    heatmap_data <- rbind(heatmap_data,rep(0,ncol(heatmap_data)))
    rownames(heatmap_data)[2] <- "fake_gene_for_plotting"
    
  }
  
  heatmap_matrix <- as.matrix(heatmap_data)
  
  p <- pheatmap(heatmap_matrix,
                cluster_rows = F,   # Cluster the rows (genes)
                cluster_cols = F,   # Cluster the columns (QTL types)
                color = colorRampPalette(c("white", "red"))(50), # Color gradient
                display_numbers = TRUE, # Display numbers in cells
                main = main,labels_row = rownames(heatmap_data), silent = T)
  
  return(p)
}


get_ctwas_file <- function(trait, tissue = NULL, folder_results) {
  # Build file paths
  if (is.null(tissue)) {
    file_ctwas_res_origin <- paste0(folder_results, "/", trait, "/", trait, ".finemap_regions_res.RDS")
    file_ctwas_res_regionmerge <- paste0(folder_results, "/", trait, "/", trait, ".regionmerge_finemap_regions_res.RDS")
    file_ctwas_res_ldmismatch <- paste0(folder_results, "/", trait, "/", trait, ".ldmismatch_finemap_regions_res.RDS")
  } else {
    file_ctwas_res_origin <- paste0(folder_results, "/", trait, "/", trait, "_", tissue, ".finemap_regions_res.RDS")
    file_ctwas_res_regionmerge <- paste0(folder_results, "/", trait, "/", trait, "_", tissue, ".regionmerge_finemap_regions_res.RDS")
    file_ctwas_res_ldmismatch <- paste0(folder_results, "/", trait, "/", trait, "_", tissue, ".ldmismatch_finemap_regions_res.RDS")
  }
  
  # Determine which file exists
  file_ctwas_result <- if (file.exists(file_ctwas_res_ldmismatch)) {
    file_ctwas_res_ldmismatch
  } else if (file.exists(file_ctwas_res_regionmerge)) {
    file_ctwas_res_regionmerge
  } else {
    file_ctwas_res_origin
  }
  
  return(file_ctwas_result)
}

Results

Single eQTL analysis results

trait <- "LDL-ukb-d-30780_irnt"
tissue <- "Liver"

folder_single_results <- "/project/xinhe/shengqian/single_tissue_screen/processed_weights/expression_weights/"

file_ctwas_result <- get_ctwas_file(trait, tissue, folder_single_results)

ctwas_res_single_post <- readRDS(file_ctwas_result)

z_gene_single <-readRDS(paste0(folder_single_results,"/",trait,"/",trait,"_",tissue,".z_gene.RDS"))

susie_alpha_res_single_post <- ctwas_res_single_post$susie_alpha_res
susie_alpha_res_single_post <- anno_susie_alpha_res(susie_alpha_res_single_post,
                                        mapping_table = mapping_two,
                                        map_by = "molecular_id",
                                        drop_unmapped = TRUE)
2025-01-07 12:45:41 INFO::Annotating susie alpha result ...
2025-01-07 12:45:41 INFO::Map molecular traits to genes
combined_pip_by_group_single <- combine_gene_pips(susie_alpha_res_single_post, 
                                             group_by = "gene_name",
                                             by = "group",
                                             method = "combine_cs",
                                             filter_cs = TRUE,
                                             include_cs_id = F)
combined_pip_sig_single <- subset(combined_pip_by_group_single, combined_pip > 0.8)

DT::datatable(combined_pip_sig_single,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;','Genes with PIP > 0.8 in single eQTL analysis, cs filtered'),options = list(pageLength = 10) )
z_gene_single <- z_gene_single %>%
  mutate(molecular_id = sub("\\|.*", "", id)) %>%  # Extract ENSG ID from id
  left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")

Multi-group analysis results

tissues <- c("Liver","Spleen","Esophagus_Gastroesophageal_Junction","Esophagus_Muscularis","Esophagus_Mucosa")

folder_multi_results <- "/project/xinhe/shengqian/ctwas_GWAS_analysis/results/"
folder_multi_post <- paste0("/project/xinhe/xsun/multi_group_ctwas/13.post_processing_0103/results_region_merge/",trait,"/")

file_ctwas_result <- get_ctwas_file(trait, tissue = NULL, folder_multi_results)


ctwas_res_multi_post <- readRDS(file_ctwas_result)


susie_alpha_res_multi_post <- ctwas_res_multi_post$susie_alpha_res
susie_alpha_res_multi_post <- anno_susie_alpha_res(susie_alpha_res_multi_post,
                                        mapping_table = mapping_two,
                                        map_by = "molecular_id",
                                        drop_unmapped = TRUE)
2025-01-07 12:45:48 INFO::Annotating susie alpha result ...
2025-01-07 12:45:48 INFO::Map molecular traits to genes
2025-01-07 12:45:49 INFO::Split PIPs for molecular traits mapped to multiple genes
combined_pip_by_group_multi <- combine_gene_pips(susie_alpha_res_multi_post, 
                                             group_by = "gene_name",
                                             by = "group",
                                             method = "combine_cs",
                                             filter_cs = TRUE,
                                             include_cs_id = F)
combined_pip_sig_multi <- subset(combined_pip_by_group_multi, combined_pip > 0.8)

DT::datatable(combined_pip_sig_multi,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;','Genes with PIP > 0.8 in multi-group analysis, cs filtered'),options = list(pageLength = 10) )
z_gene_multi <- readRDS(paste0(folder_multi_results,"/",trait,"/",trait,".z_gene.RDS"))
z_gene_multi <- z_gene_multi %>%
  mutate(molecular_id = sub("\\|.*", "", id)) %>%  # Extract ENSG ID from id
  left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")

Comparing with silver standard genes

We followed the analysis in ctwas paper. The silver standard genes for LDL are:

LDL_silver <- readxl::read_excel("/project/xinhe/xsun/multi_group_ctwas/data/LDL_silver.xlsx")
LDL_silver_known <- LDL_silver[LDL_silver$annotation == "known",]
LDL_silver_bystand <- LDL_silver[LDL_silver$annotation != "known",]

DT::datatable(LDL_silver,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;','The silver standard genes for LDL (from ctwas paper, table S2)'),options = list(pageLength = 10) )
stats <- data.frame(analysis = c("ctwas paper","ctwasV2 - single eQTL","ctwasV2 - multigroup"),
                    num_gene_pip08 = c(35, nrow(combined_pip_sig_single),nrow(combined_pip_sig_multi)),
                    num_gene_known_imputable = c("46 of 69 known",sum(LDL_silver_known$genename %in% z_gene_single$gene_name),sum(LDL_silver_known$genename %in% z_gene_multi$gene_name)),
                    num_gene_known_pip08 = c(6,sum(LDL_silver_known$genename %in% combined_pip_sig_single$gene_name),sum(LDL_silver_known$genename %in% combined_pip_sig_multi$gene_name)),
                   num_gene_bystander_imputable = c("539 of 539 bystander",sum(LDL_silver_bystand$genename %in% z_gene_single$gene_name),sum(LDL_silver_bystand$genename %in% z_gene_multi$gene_name)),
                    num_gene_bystander_pip08 = c(2,sum(LDL_silver_bystand$genename %in% combined_pip_sig_single$gene_name),sum(LDL_silver_bystand$genename %in% combined_pip_sig_multi$gene_name)))


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

PIP partition for the top genes

plot_heatmap_bytissue(heatmap_data = combined_pip_sig_multi, main = "PIP partition for genes with PIP > 0.8 from multi-group analysis",tissues = tissues)

plot_heatmap_byomics(heatmap_data = combined_pip_sig_multi, main = "PIP partition for genes with PIP > 0.8 from multi-group analysis")


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] pheatmap_1.0.12           EnsDb.Hsapiens.v86_2.99.0
 [3] ensembldb_2.20.2          AnnotationFilter_1.20.0  
 [5] GenomicFeatures_1.48.3    AnnotationDbi_1.58.0     
 [7] Biobase_2.56.0            GenomicRanges_1.48.0     
 [9] GenomeInfoDb_1.39.9       IRanges_2.30.0           
[11] S4Vectors_0.34.0          BiocGenerics_0.42.0      
[13] dplyr_1.1.4               ctwas_0.4.20.9001        

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] DT_0.22                     ggrepel_0.9.1              
 [11] bit64_4.0.5                 fansi_1.0.3                
 [13] xml2_1.3.3                  codetools_0.2-18           
 [15] logging_0.10-108            cachem_1.0.6               
 [17] knitr_1.39                  jsonlite_1.8.0             
 [19] workflowr_1.7.0             Rsamtools_2.12.0           
 [21] dbplyr_2.1.1                png_0.1-7                  
 [23] readr_2.1.2                 compiler_4.2.0             
 [25] httr_1.4.3                  assertthat_0.2.1           
 [27] Matrix_1.5-3                fastmap_1.1.0              
 [29] lazyeval_0.2.2              cli_3.6.1                  
 [31] later_1.3.0                 htmltools_0.5.2            
 [33] prettyunits_1.1.1           tools_4.2.0                
 [35] gtable_0.3.0                glue_1.6.2                 
 [37] GenomeInfoDbData_1.2.8      rappdirs_0.3.3             
 [39] Rcpp_1.0.12                 cellranger_1.1.0           
 [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 RColorBrewer_1.1-3         
 [63] LDlinkR_1.2.3               yaml_2.3.5                 
 [65] curl_4.3.2                  memoise_2.0.1              
 [67] ggplot2_3.5.1               sass_0.4.1                 
 [69] biomaRt_2.54.1              stringi_1.7.6              
 [71] RSQLite_2.3.1               highr_0.9                  
 [73] BiocIO_1.6.0                filelock_1.0.2             
 [75] BiocParallel_1.30.3         rlang_1.1.2                
 [77] pkgconfig_2.0.3             matrixStats_0.62.0         
 [79] bitops_1.0-7                evaluate_0.15              
 [81] lattice_0.20-45             purrr_1.0.2                
 [83] GenomicAlignments_1.32.0    htmlwidgets_1.5.4          
 [85] cowplot_1.1.1               bit_4.0.4                  
 [87] tidyselect_1.2.0            magrittr_2.0.3             
 [89] R6_2.5.1                    generics_0.1.2             
 [91] DelayedArray_0.22.0         DBI_1.2.2                  
 [93] withr_2.5.0                 pgenlibr_0.3.3             
 [95] pillar_1.9.0                KEGGREST_1.36.3            
 [97] RCurl_1.98-1.7              mixsqp_0.3-43              
 [99] tibble_3.2.1                crayon_1.5.1               
[101] utf8_1.2.2                  BiocFileCache_2.4.0        
[103] plotly_4.10.0               tzdb_0.4.0                 
[105] rmarkdown_2.25              progress_1.2.2             
[107] readxl_1.4.0                grid_4.2.0                 
[109] data.table_1.14.2           blob_1.2.3                 
[111] git2r_0.30.1                digest_0.6.29              
[113] tidyr_1.3.0                 httpuv_1.6.5               
[115] munsell_0.5.0               viridisLite_0.4.0          
[117] bslib_0.3.1