Last updated: 2025-02-28
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 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 7673ad0. 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
Unstaged changes:
Modified: analysis/comparing_differnt_settings.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.Rmd
) and HTML
(docs/comparing_differnt_settings.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 | 7673ad0 | XSun | 2025-02-28 | update |
html | 7673ad0 | XSun | 2025-02-28 | update |
Rmd | 4c80969 | XSun | 2025-02-24 | update |
html | 4c80969 | XSun | 2025-02-24 | update |
Settings are:
library(ctwas)
library(ggplot2)
library(dplyr)
library(tidyr)
library(scales)
source("/project/xinhe/xsun/multi_group_ctwas/data/samplesize.R")
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)
traits_silver <- c("T2D","LDL","BMI","RBC","IBD")
names(traits_silver) <- c("T2D-panukb","LDL-ukb-d-30780_irnt","BMI-panukb","RBC-panukb","IBD-ebi-a-GCST004131")
trait <- "LDL-ukb-d-30780_irnt"
folder_results <- "/project/xinhe/shengqian/ctwas_GWAS_analysis/snakemake_outputs/"
thins <- c("0.1", "0.5", "1")
var_strucs <- c("shared_all", "shared_type")
Ls <- c("5","1")
sts <- c("without_ST","with_ST")
# st <- "without_ST"
# var_struc <- "shared_all"
# L <- 5
# thin <- 0.1
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)
# 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")
}
create_summary_plot <- 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)))
}
# Create plot
ggplot(df_long, aes(x = .data[[x_var]], y = value, color = variable)) +
#geom_point(size = 3, position = position_jitter(width = 0.2)) +
geom_point(size = 3) +
labs(x = "Settings", y = "Count/Value", 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")
}
trait <- "LDL-ukb-d-30780_irnt"
setting_names <- c()
prop_h2g_nonsnp_all <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
imputable_known_all <- c()
imputable_bystander_all <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
# non-snp %h2g
param <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".param.RDS"))
ctwas_parameters <- summarize_param(param, samplesize[trait])
prop_h2g <- ctwas_parameters$prop_heritability
prop_h2g_nonsnp <- 1 - ctwas_parameters$prop_heritability["SNP"]
prop_h2g_nonsnp_all <- c(prop_h2g_nonsnp_all,prop_h2g_nonsnp)
# num_gene_pip08
combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final.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))
# imputable genes
z_gene <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".z_gene.RDS"))
z_gene <- z_gene %>%
mutate(molecular_id = sub("\\|.*", "", id)) %>% # Extract ENSG ID from id
left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")
imputable_known_all <- c(imputable_known_all,sum(unique(z_gene$gene_name) %in% known))
imputable_bystander_all <- c(imputable_bystander_all,sum(unique(z_gene$gene_name) %in% bystander))
}
}
}
}
df <- data.frame(setting = setting_names,prop_h2g_nonsnp = prop_h2g_nonsnp_all ,num_gene_pip08 = num_gene_pip08_all,
num_silver_total = rep(length(known),length(setting_names)), num_imputable_silver = imputable_known_all, num_silver_pip08 = num_silver_pip08_all,
num_bystander_total = rep(length(bystander),length(setting_names)), num_imputable_bystander = imputable_bystander_all, num_bystander_pip08 = num_bystander_pip08_all,
TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all))
## plot Non-SNP %h2g
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("prop_h2g_nonsnp"), title = "%h2g -- NON-SNP")
Version | Author | Date |
---|---|---|
4c80969 | XSun | 2025-02-24 |
#
# ## silver standard gene
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_imputable_silver","num_silver_pip08"),
# title = "Silver standard genes")
#
# ## bystander genes
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_bystander_pip08"),
# title = "Bystander genes")
#
# ## tp
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_silver_pip08"),
# title = "True positive rate")
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate","num_imputable_silver"))
Version | Author | Date |
---|---|---|
4c80969 | XSun | 2025-02-24 |
if(max(as.numeric(df$num_bystander_pip08)) != 0){
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_bystander_pip08","TP_rate"))
}
Version | Author | Date |
---|---|---|
4c80969 | XSun | 2025-02-24 |
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black; font-size:150% ;',trait),options = list(pageLength = 10) )
db <- "GO_Biological_Process_2023"
num_go_adj005 <- c()
setting_names <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
file_enrich <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,".RDS")
if(file.exists(file_enrich)) {
enrich_results <- readRDS(file_enrich)
num_go_adj005 <- c(num_go_adj005,nrow(enrich_results))
}else{
num_go_adj005 <- c(num_go_adj005,0)
}
}
}
}
}
df <- data.frame(setting = setting_names, num_go_adj005 = num_go_adj005)
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("num_go_adj005"), title = "Number of enriched GO terms, adj_p < 0.05")
trait <- "IBD-ebi-a-GCST004131"
setting_names <- c()
prop_h2g_nonsnp_all <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
imputable_known_all <- c()
imputable_bystander_all <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
# non-snp %h2g
param <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".param.RDS"))
ctwas_parameters <- summarize_param(param, samplesize[trait])
prop_h2g <- ctwas_parameters$prop_heritability
prop_h2g_nonsnp <- 1 - ctwas_parameters$prop_heritability["SNP"]
prop_h2g_nonsnp_all <- c(prop_h2g_nonsnp_all,prop_h2g_nonsnp)
# num_gene_pip08
combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final.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))
# imputable genes
z_gene <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".z_gene.RDS"))
z_gene <- z_gene %>%
mutate(molecular_id = sub("\\|.*", "", id)) %>% # Extract ENSG ID from id
left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")
imputable_known_all <- c(imputable_known_all,sum(unique(z_gene$gene_name) %in% known))
imputable_bystander_all <- c(imputable_bystander_all,sum(unique(z_gene$gene_name) %in% bystander))
}
}
}
}
df <- data.frame(setting = setting_names,prop_h2g_nonsnp = prop_h2g_nonsnp_all ,num_gene_pip08 = num_gene_pip08_all,
num_silver_total = rep(length(known),length(setting_names)), num_imputable_silver = imputable_known_all, num_silver_pip08 = num_silver_pip08_all,
num_bystander_total = rep(length(bystander),length(setting_names)), num_imputable_bystander = imputable_bystander_all, num_bystander_pip08 = num_bystander_pip08_all,
TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all))
## plot Non-SNP %h2g
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("prop_h2g_nonsnp"), title = "%h2g -- NON-SNP")
#
# ## silver standard gene
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_imputable_silver","num_silver_pip08"),
# title = "Silver standard genes")
#
# ## bystander genes
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_bystander_pip08"),
# title = "Bystander genes")
#
# ## tp
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_silver_pip08"),
# title = "True positive rate")
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate","num_imputable_silver"))
if(max(as.numeric(df$num_bystander_pip08)) != 0){
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_bystander_pip08","TP_rate"))
}
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black; font-size:150% ;',trait),options = list(pageLength = 10) )
db <- "GO_Biological_Process_2023"
num_go_adj005 <- c()
setting_names <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
file_enrich <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,".RDS")
if(file.exists(file_enrich)) {
enrich_results <- readRDS(file_enrich)
num_go_adj005 <- c(num_go_adj005,nrow(enrich_results))
}else{
num_go_adj005 <- c(num_go_adj005,0)
}
}
}
}
}
df <- data.frame(setting = setting_names, num_go_adj005 = num_go_adj005)
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("num_go_adj005"), title = "Number of enriched GO terms, adj_p < 0.05")
trait <- "T2D-panukb"
setting_names <- c()
prop_h2g_nonsnp_all <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
imputable_known_all <- c()
imputable_bystander_all <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
# non-snp %h2g
param <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".param.RDS"))
ctwas_parameters <- summarize_param(param, samplesize[trait])
prop_h2g <- ctwas_parameters$prop_heritability
prop_h2g_nonsnp <- 1 - ctwas_parameters$prop_heritability["SNP"]
prop_h2g_nonsnp_all <- c(prop_h2g_nonsnp_all,prop_h2g_nonsnp)
# num_gene_pip08
combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final.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))
# imputable genes
z_gene <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".z_gene.RDS"))
z_gene <- z_gene %>%
mutate(molecular_id = sub("\\|.*", "", id)) %>% # Extract ENSG ID from id
left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")
imputable_known_all <- c(imputable_known_all,sum(unique(z_gene$gene_name) %in% known))
imputable_bystander_all <- c(imputable_bystander_all,sum(unique(z_gene$gene_name) %in% bystander))
}
}
}
}
df <- data.frame(setting = setting_names,prop_h2g_nonsnp = prop_h2g_nonsnp_all ,num_gene_pip08 = num_gene_pip08_all,
num_silver_total = rep(length(known),length(setting_names)), num_imputable_silver = imputable_known_all, num_silver_pip08 = num_silver_pip08_all,
num_bystander_total = rep(length(bystander),length(setting_names)), num_imputable_bystander = imputable_bystander_all, num_bystander_pip08 = num_bystander_pip08_all,
TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all))
## plot Non-SNP %h2g
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("prop_h2g_nonsnp"), title = "%h2g -- NON-SNP")
#
# ## silver standard gene
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_imputable_silver","num_silver_pip08"),
# title = "Silver standard genes")
#
# ## bystander genes
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_bystander_pip08"),
# title = "Bystander genes")
#
# ## tp
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_silver_pip08"),
# title = "True positive rate")
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate","num_imputable_silver"))
if(max(as.numeric(df$num_bystander_pip08)) != 0){
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_bystander_pip08","TP_rate"))
}
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black; font-size:150% ;',trait),options = list(pageLength = 10) )
db <- "GO_Biological_Process_2023"
num_go_adj005 <- c()
setting_names <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
file_enrich <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,".RDS")
if(file.exists(file_enrich)) {
enrich_results <- readRDS(file_enrich)
num_go_adj005 <- c(num_go_adj005,nrow(enrich_results))
}else{
num_go_adj005 <- c(num_go_adj005,0)
}
}
}
}
}
df <- data.frame(setting = setting_names, num_go_adj005 = num_go_adj005)
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("num_go_adj005"), title = "Number of enriched GO terms, adj_p < 0.05")
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
trait <- "BMI-panukb"
setting_names <- c()
prop_h2g_nonsnp_all <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
imputable_known_all <- c()
imputable_bystander_all <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
# non-snp %h2g
param <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".param.RDS"))
ctwas_parameters <- summarize_param(param, samplesize[trait])
prop_h2g <- ctwas_parameters$prop_heritability
prop_h2g_nonsnp <- 1 - ctwas_parameters$prop_heritability["SNP"]
prop_h2g_nonsnp_all <- c(prop_h2g_nonsnp_all,prop_h2g_nonsnp)
# num_gene_pip08
combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final.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))
# imputable genes
z_gene <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".z_gene.RDS"))
z_gene <- z_gene %>%
mutate(molecular_id = sub("\\|.*", "", id)) %>% # Extract ENSG ID from id
left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")
imputable_known_all <- c(imputable_known_all,sum(unique(z_gene$gene_name) %in% known))
imputable_bystander_all <- c(imputable_bystander_all,sum(unique(z_gene$gene_name) %in% bystander))
}
}
}
}
df <- data.frame(setting = setting_names,prop_h2g_nonsnp = prop_h2g_nonsnp_all ,num_gene_pip08 = num_gene_pip08_all,
num_silver_total = rep(length(known),length(setting_names)), num_imputable_silver = imputable_known_all, num_silver_pip08 = num_silver_pip08_all,
num_bystander_total = rep(length(bystander),length(setting_names)), num_imputable_bystander = imputable_bystander_all, num_bystander_pip08 = num_bystander_pip08_all,
TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all))
## plot Non-SNP %h2g
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("prop_h2g_nonsnp"), title = "%h2g -- NON-SNP")
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
#
# ## silver standard gene
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_imputable_silver","num_silver_pip08"),
# title = "Silver standard genes")
#
# ## bystander genes
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_bystander_pip08"),
# title = "Bystander genes")
#
# ## tp
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_silver_pip08"),
# title = "True positive rate")
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate","num_imputable_silver"))
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
if(max(as.numeric(df$num_bystander_pip08)) != 0){
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_bystander_pip08","TP_rate"))
}
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black; font-size:150% ;',trait),options = list(pageLength = 10) )
db <- "GO_Biological_Process_2023"
num_go_adj005 <- c()
setting_names <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
file_enrich <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,".RDS")
if(file.exists(file_enrich)) {
enrich_results <- readRDS(file_enrich)
num_go_adj005 <- c(num_go_adj005,nrow(enrich_results))
}else{
num_go_adj005 <- c(num_go_adj005,0)
}
}
}
}
}
df <- data.frame(setting = setting_names, num_go_adj005 = num_go_adj005)
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("num_go_adj005"), title = "Number of enriched GO terms, adj_p < 0.05")
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
trait <- "RBC-panukb"
setting_names <- c()
prop_h2g_nonsnp_all <- c()
num_gene_pip08_all <- c()
num_silver_pip08_all <- c()
num_bystander_pip08_all <- c()
imputable_known_all <- c()
imputable_bystander_all <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
# non-snp %h2g
param <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".param.RDS"))
ctwas_parameters <- summarize_param(param, samplesize[trait])
prop_h2g <- ctwas_parameters$prop_heritability
prop_h2g_nonsnp <- 1 - ctwas_parameters$prop_heritability["SNP"]
prop_h2g_nonsnp_all <- c(prop_h2g_nonsnp_all,prop_h2g_nonsnp)
# num_gene_pip08
combined_pip_by_group <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".combined_pip_bygroup_final.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))
# imputable genes
z_gene <- readRDS(paste0(folder_results,"/",trait,"/",trait,".",st,".z_gene.RDS"))
z_gene <- z_gene %>%
mutate(molecular_id = sub("\\|.*", "", id)) %>% # Extract ENSG ID from id
left_join(mapping_two %>% dplyr::select(molecular_id, gene_name), by = "molecular_id")
imputable_known_all <- c(imputable_known_all,sum(unique(z_gene$gene_name) %in% known))
imputable_bystander_all <- c(imputable_bystander_all,sum(unique(z_gene$gene_name) %in% bystander))
}
}
}
}
df <- data.frame(setting = setting_names,prop_h2g_nonsnp = prop_h2g_nonsnp_all ,num_gene_pip08 = num_gene_pip08_all,
num_silver_total = rep(length(known),length(setting_names)), num_imputable_silver = imputable_known_all, num_silver_pip08 = num_silver_pip08_all,
num_bystander_total = rep(length(bystander),length(setting_names)), num_imputable_bystander = imputable_bystander_all, num_bystander_pip08 = num_bystander_pip08_all,
TP_rate = num_silver_pip08_all/(num_silver_pip08_all+num_bystander_pip08_all))
## plot Non-SNP %h2g
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("prop_h2g_nonsnp"), title = "%h2g -- NON-SNP")
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
#
# ## silver standard gene
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_imputable_silver","num_silver_pip08"),
# title = "Silver standard genes")
#
# ## bystander genes
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_gene_pip08","num_bystander_pip08"),
# title = "Bystander genes")
#
# ## tp
# create_summary_plot(df,x_order = setting_names,
# columns_to_plot = c("num_silver_pip08"),
# title = "True positive rate")
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_gene_pip08","num_silver_pip08","TP_rate","num_imputable_silver"))
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
if(max(as.numeric(df$num_bystander_pip08)) != 0){
create_summary_plot_withTP(df,x_order = setting_names,
columns_to_plot = c("num_bystander_pip08","TP_rate"))
}
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
DT::datatable(df,caption = htmltools::tags$caption( style = 'caption-side: left; text-align: left; color:black; font-size:150% ;',trait),options = list(pageLength = 10) )
db <- "GO_Biological_Process_2023"
num_go_adj005 <- c()
setting_names <- c()
for (st in sts) {
for (thin in thins) {
for (var_struc in var_strucs) {
for (L in Ls) {
setting_names <- c(setting_names, paste0(st,"_thin",thin,"_",var_struc,"_L",L))
file_enrich <- paste0(folder_results,trait,"/",trait,".",st,".thin",thin,".",var_struc,".L",L, ".enrichr_",db,".RDS")
if(file.exists(file_enrich)) {
enrich_results <- readRDS(file_enrich)
num_go_adj005 <- c(num_go_adj005,nrow(enrich_results))
}else{
num_go_adj005 <- c(num_go_adj005,0)
}
}
}
}
}
df <- data.frame(setting = setting_names, num_go_adj005 = num_go_adj005)
create_summary_plot(df,x_order = setting_names,
columns_to_plot = c("num_go_adj005"), title = "Number of enriched GO terms, adj_p < 0.05")
Version | Author | Date |
---|---|---|
7673ad0 | XSun | 2025-02-28 |
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] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_1.3.0 tidyr_1.3.0 dplyr_1.1.4 ggplot2_3.5.1
[5] ctwas_0.5.4.9000
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] GenomicRanges_1.48.0 base64enc_0.1-3
[9] fs_1.5.2 rstudioapi_0.13
[11] farver_2.1.0 DT_0.22
[13] ggrepel_0.9.1 bit64_4.0.5
[15] AnnotationDbi_1.58.0 fansi_1.0.3
[17] xml2_1.3.3 codetools_0.2-18
[19] logging_0.10-108 cachem_1.0.6
[21] knitr_1.39 jsonlite_1.8.0
[23] workflowr_1.7.0 Rsamtools_2.12.0
[25] dbplyr_2.1.1 png_0.1-7
[27] readr_2.1.2 compiler_4.2.0
[29] httr_1.4.3 assertthat_0.2.1
[31] Matrix_1.5-3 fastmap_1.1.0
[33] lazyeval_0.2.2 cli_3.6.1
[35] later_1.3.0 htmltools_0.5.2
[37] prettyunits_1.1.1 tools_4.2.0
[39] gtable_0.3.0 glue_1.6.2
[41] GenomeInfoDbData_1.2.8 rappdirs_0.3.3
[43] Rcpp_1.0.12 Biobase_2.56.0
[45] jquerylib_0.1.4 vctrs_0.6.5
[47] Biostrings_2.64.0 rtracklayer_1.56.0
[49] crosstalk_1.2.0 xfun_0.41
[51] stringr_1.5.1 irlba_2.3.5
[53] lifecycle_1.0.4 restfulr_0.0.14
[55] ensembldb_2.20.2 XML_3.99-0.14
[57] zlibbioc_1.42.0 zoo_1.8-10
[59] gggrid_0.2-0 hms_1.1.1
[61] promises_1.2.0.1 MatrixGenerics_1.8.0
[63] ProtGenerics_1.28.0 parallel_4.2.0
[65] SummarizedExperiment_1.26.1 RColorBrewer_1.1-3
[67] AnnotationFilter_1.20.0 LDlinkR_1.2.3
[69] yaml_2.3.5 curl_4.3.2
[71] memoise_2.0.1 sass_0.4.1
[73] biomaRt_2.54.1 stringi_1.7.6
[75] RSQLite_2.3.1 highr_0.9
[77] S4Vectors_0.34.0 BiocIO_1.6.0
[79] GenomicFeatures_1.48.3 BiocGenerics_0.42.0
[81] filelock_1.0.2 BiocParallel_1.30.3
[83] repr_1.1.4 GenomeInfoDb_1.39.9
[85] rlang_1.1.2 pkgconfig_2.0.3
[87] matrixStats_0.62.0 bitops_1.0-7
[89] evaluate_0.15 lattice_0.20-45
[91] purrr_1.0.2 labeling_0.4.2
[93] GenomicAlignments_1.32.0 htmlwidgets_1.5.4
[95] cowplot_1.1.1 bit_4.0.4
[97] tidyselect_1.2.0 magrittr_2.0.3
[99] AMR_2.1.1 R6_2.5.1
[101] IRanges_2.30.0 generics_0.1.2
[103] DelayedArray_0.22.0 DBI_1.2.2
[105] withr_2.5.0 pgenlibr_0.3.3
[107] pillar_1.9.0 whisker_0.4
[109] mixsqp_0.3-43 KEGGREST_1.36.3
[111] RCurl_1.98-1.7 tibble_3.2.1
[113] crayon_1.5.1 utf8_1.2.2
[115] BiocFileCache_2.4.0 plotly_4.10.0
[117] tzdb_0.4.0 rmarkdown_2.25
[119] progress_1.2.2 grid_4.2.0
[121] data.table_1.14.2 blob_1.2.3
[123] git2r_0.30.1 digest_0.6.29
[125] httpuv_1.6.5 stats4_4.2.0
[127] munsell_0.5.0 viridisLite_0.4.0
[129] skimr_2.1.4 bslib_0.3.1