Last updated: 2025-05-01

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 a742ef4. 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:    cv/

Unstaged changes:
    Modified:   analysis/comparing_differnt_settings_csindex.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_csindex.Rmd) and HTML (docs/comparing_differnt_settings_csindex.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 a742ef4 XSun 2025-04-30 update
html a742ef4 XSun 2025-04-30 update
Rmd 3b4edbe XSun 2025-04-28 update
html 3b4edbe XSun 2025-04-28 update

library(dplyr)
library(scales)
library(tidyr)
library(ggplot2)
library(eulerr)
library(patchwork)

traits_silver <- c("T2D","LDL","BMI","RBC","IBD","SCZ","aFib")
names(traits_silver) <- c("T2D-panukb","LDL-ukb-d-30780_irnt","BMI-panukb","RBC-panukb","IBD-ebi-a-GCST004131","SCZ-ieu-b-5102","aFib-ebi-a-GCST006414")

traits <- c("LDL-ukb-d-30780_irnt","IBD-ebi-a-GCST004131","BMI-panukb","RBC-panukb","SCZ-ieu-b-5102","aFib-ebi-a-GCST006414","T2D-panukb")
db <- "GO_Biological_Process_2023"

folder_results <- "/project/xinhe/xsun/multi_group_ctwas/15.susie_weights/snakemake_outputs/"

create_summary_plot_withTP <- function(df, columns_to_plot, x_var = "setting", x_order = NULL, title = NULL) {

  # Reshape data
  df_long <- df %>%
    pivot_longer(
      cols = all_of(columns_to_plot),
      names_to = "variable",
      values_to = "value"
    )
  
  # Convert to factor with specified order if x_order is provided
  if (!is.null(x_order)) {
    df_long <- df_long %>%
      mutate(across(all_of(x_var), ~factor(., levels = x_order)))
  }
  
  # Identify the max value for scaling
  max_main <- max(df_long$value[df_long$variable != "TP_rate"], na.rm = TRUE)
  max_tp_rate <- max(df_long$value[df_long$variable == "TP_rate"], na.rm = TRUE)
  
  if(max_tp_rate ==0) {
    max_tp_rate <- 1
  }
  
  # Rescale TP_rate
  df_long <- df_long %>%
    mutate(scaled_value = ifelse(variable == "TP_rate", 
                                 value * (max_main / max_tp_rate), value))
  
  # Create plot
  ggplot(df_long, aes(x = .data[[x_var]], y = scaled_value, color = variable, shape = variable)) +
    #geom_point(size = 3, position = position_jitter(width = 0.2)) +
    geom_point(size = 3) + 
    scale_y_continuous(
      name = "Count",
      sec.axis = sec_axis(~ . * (max_tp_rate / max_main), name = "TP Rate")
    ) +
    labs(x = "Settings", title = title) +
    theme_minimal() +
    theme(
      axis.text.x = element_text(angle = 45, hjust = 1, size = 10),
      legend.position = "right",
      legend.title = element_blank()
    ) +
    scale_color_brewer(palette = "Set1")
}

DT::datatable(matrix())
thin <- 1
var_struc <- "shared_all"
L <- 5
st <- "with_susieST"

The number of genes at PIP > 0.8

setting_names <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
go_num_fdr005 <- c()
for (trait in traits) {
  for (cs in c("CS_filtered","CS_NOT_filtered")){

    if(cs == "CS_filtered"){
      cs_setting <- NULL
    }else{
      cs_setting <- "_csF"
    }

    setting_names <- c(setting_names, paste0(traits_silver[trait],"-",cs))

    # num_gene_pip08 -- cs filtered
    combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final",cs_setting,".RDS"))
    combined_pip_sig <- combined_pip_by_group[combined_pip_by_group$combined_pip > 0.8,]

    num_gene_pip08_all <- c(num_gene_pip08_all, nrow(combined_pip_sig))

    # silver_standard genes
    known <- readRDS(paste0("/project/xinhe/xsun/multi_group_ctwas/data/silverstandard/known_annotations_",traits_silver[trait],".RDS"))
    bystander <- readRDS(paste0("/project/xinhe/xsun/multi_group_ctwas/data/silverstandard/bystanders_",traits_silver[trait],".RDS"))

    num_silver_pip08_all <- c(num_silver_pip08_all,sum(combined_pip_sig$gene_name %in% known))
    num_bystander_pip08_all <- c(num_bystander_pip08_all,sum(combined_pip_sig$gene_name %in% bystander))

    file_go <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_",cs,".RDS")
    if(!file.exists(file_go)){
      go_num_fdr005 <- c(go_num_fdr005,0)
    }else{
      go <- readRDS(paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_",cs,".RDS"))
      go_num_fdr005 <- c(go_num_fdr005,nrow(go))
    }


  }
}

df <- data.frame(setting = setting_names,
                 num_gene_pip08 = num_gene_pip08_all,
                 num_silver_pip08 = num_silver_pip08_all,
                 num_bystander_pip08 = num_bystander_pip08_all,
                 TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all),
                 go_num_fdr005 = go_num_fdr005)

create_summary_plot_withTP(df,x_order = setting_names,
                    columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate"))

Version Author Date
3b4edbe XSun 2025-04-28
create_summary_plot_withTP(df,x_order = setting_names,
                    columns_to_plot = c("go_num_fdr005"), title = "Number of GO terms at p.adjust < 0.05")

Version Author Date
a742ef4 XSun 2025-04-30
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black;  font-size:150% ;',''),options = list(pageLength = 10) )

Number of GO terms at adjusted.p < 0.05

traits <- c("LDL-ukb-d-30780_irnt","IBD-ebi-a-GCST004131")

for (trait in traits) {

  file_go_filtered <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_CS_filtered.RDS")
  if(!file.exists(file_go_filtered)){
    go_filtered <- NULL
  }else{
    go_filtered <- readRDS(file_go_filtered)
  }



  file_go_nofiltered <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_CS_NOT_filtered.RDS")
  if(!file.exists(file_go_nofiltered)){
    go_nofiltered <- NULL
  }else{
    go_nofiltered <- readRDS(file_go_nofiltered)
  }

  set1 <- unique(go_filtered$Term)
  set2 <- unique(go_nofiltered$Term)

  venn_input <- list(
    Filtered = set1,
    NoFiltered = set2
  )

  fit <- euler(venn_input)

  print(plot(fit,
       fills = c("skyblue", "orange"),
       labels = TRUE,
       quantities = TRUE,
       main = trait))


}

Version Author Date
a742ef4 XSun 2025-04-30

Version Author Date
a742ef4 XSun 2025-04-30
traits <- c("LDL-ukb-d-30780_irnt","IBD-ebi-a-GCST004131")

for (trait in traits) {

  file_go_filtered <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_CS_filtered.RDS")
  if(!file.exists(file_go_filtered)){
    go_filtered <- NULL
  }else{
    go_filtered <- readRDS(file_go_filtered)
  }



  file_go_nofiltered <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,"_CS_NOT_filtered.RDS")
  if(!file.exists(file_go_nofiltered)){
    go_nofiltered <- NULL
  }else{
    go_nofiltered <- readRDS(file_go_nofiltered)
  }


  cat("\n\n")
  cat(knitr::knit_print(DT::datatable(go_filtered[!go_filtered$Term %in% go_nofiltered$Term,], caption = htmltools::tags$caption( style = 'font-size: 150%; caption-side: topleft; text-align = left; color:black;',paste0("Unique GO terms at p.adjust < 0.05 -- ",trait, "--CS_filtered")),options = list(pageLength = 5))))
  cat("\n\n")

  cat("\n\n")
  cat(knitr::knit_print(DT::datatable(go_nofiltered[!go_nofiltered$Term %in% go_filtered$Term,], caption = htmltools::tags$caption( style = 'font-size: 150%; caption-side: topleft; text-align = left; color:black;',paste0("Unique GO terms at p.adjust < 0.05 -- ",trait, "--CS_NOT_filtered")),options = list(pageLength = 5))))
  cat("\n\n")



}

Comparing PIPs at gene-level

traits <- c("LDL-ukb-d-30780_irnt","IBD-ebi-a-GCST004131","BMI-panukb","RBC-panukb","SCZ-ieu-b-5102","aFib-ebi-a-GCST006414","T2D-panukb")

p <- list()
for (trait in traits) {
  
  combined_pip_filtered <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final_csincluded.RDS"))
  combined_pip_filtered_plot <- combined_pip_filtered[,c("gene_name","combined_pip")]
  colnames(combined_pip_filtered_plot) <- c("gene_name","combined_pip_csfiltered")
  
  combined_pip_NOTfiltered <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final_csF.RDS"))
  combined_pip_NOTfiltered_plot <- combined_pip_NOTfiltered[,c("gene_name","combined_pip")]
  colnames(combined_pip_NOTfiltered_plot) <- c("gene_name","combined_pip_csNOTfiltered")

  combined_pip_filtered_sig <- combined_pip_filtered[combined_pip_filtered$combined_pip > 0.8,]
  combined_pip_NOTfiltered_sig <- combined_pip_NOTfiltered[combined_pip_NOTfiltered$combined_pip > 0.8,]
  combined_pip_NOTfiltered_sig_plot <- combined_pip_NOTfiltered_plot[combined_pip_NOTfiltered_plot$combined_pip > 0.8,]
  
  df_merge <- merge(combined_pip_NOTfiltered_sig_plot, combined_pip_filtered_plot, by = "gene_name", all.x = T)
  df_merge$combined_pip_csfiltered[is.na(df_merge$combined_pip_csfiltered)] <- 1.1
  
  p <-ggplot(data = df_merge,aes(x = combined_pip_csfiltered, y = combined_pip_csNOTfiltered)) +
  #p[[trait]] <-ggplot(data = df_merge,aes(x = combined_pip_csfiltered, y = combined_pip_csNOTfiltered)) +
    geom_point() + 
    labs(x = "Combined PIP -- CS filtered", y = "Combined PIP -- CS NOT filtered") +
    geom_abline(slope = 1, intercept = 0, col = "Red") +
    ggtitle(trait) +
    theme_minimal()
  
  print("PIP = 1.1 means PIP = NA when filtering CS")
  print(p)
  
  # Merge the two data frames by 'gene_name' with suffixes to distinguish columns
  merged_df <- merge(combined_pip_NOTfiltered_sig, combined_pip_filtered, 
                     by = "gene_name", suffixes = c("_NOTfiltered", "_filtered"),all.x=T)
  
  # List of columns to process (excluding 'gene_name')
  original_cols <- setdiff(names(combined_pip_NOTfiltered_sig), "gene_name")
  
  # Iterate over each column and concatenate values from both data frames
  for (col in original_cols) {
    notfiltered_col <- paste0(col, "_NOTfiltered")
    filtered_col <- paste0(col, "_filtered")
    merged_df[[col]] <- paste(round(merged_df[[notfiltered_col]],digits = 5), round(merged_df[[filtered_col]],digits = 5), sep = "-")
  }
  
  # Select the relevant columns to match the original structure
  df <- merged_df[, c("gene_name", original_cols)]
  
  cat("\n\n")
  cat(knitr::knit_print(DT::datatable(df, caption = htmltools::tags$caption( style = 'font-size: 150%; caption-side: topleft; text-align = left; color:black;', trait),options = list(pageLength = 5))))
  cat("\n\n")

  
}

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

[1] “PIP = 1.1 means PIP = NA when filtering CS”

#wrap_plots(lapply(p, wrap_elements), ncol = 4)

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.4 (Ootpa)

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] patchwork_1.1.1 eulerr_7.0.2    ggplot2_3.4.2   tidyr_1.3.0    
[5] scales_1.2.0    dplyr_1.1.2    

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