Last updated: 2024-06-02
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 96c8290. 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/multi_group_6traits_15weights_ukbb_summary.Rmd
Unstaged changes:
Modified: analysis/index.Rmd
Modified: analysis/multi_group_6traits_15weights_ukbb.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.
We summarize the results here: https://sq-96.github.io/multigroup_ctwas_analysis/multi_group_6traits_15weights_ukbb.html
library(ggplot2)
library(ctwas)
library(dplyr)
library(tidyr)
source("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/0.functions.R")
traits <- c("IBD-ebi-a-GCST004131", "LDL-ukb-d-30780_irnt", "SBP-ukb-a-360", "SCZ-ieu-b-5102", "WBC-ieu-b-30")
load("/project2/xinhe/shared_data/multigroup_ctwas/gwas/samplesize.rdata")
sum_pve_tissue_alltraits <- list()
sum_pve_modality_alltraits <- list()
for (i in 1:length(traits)) {
trait <- traits[i]
gwas_n <- samplesize[trait]
param <-readRDS(paste0("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/results_ukbb/",trait,"/",trait,".param.RDS"))
ctwas_parameters <- summarize_param(param, gwas_n)
sum_pve_tissue <- sum_pve_across_contexts(ctwas_parameters)
sum_pve_tissue_total <- sum_pve_tissue$total_pve
names(sum_pve_tissue_total) <- sum_pve_tissue$type
sum_pve_tissue_alltraits[[i]] <- sum_pve_tissue_total
sum_pve_modality <- sum_pve_across_types(ctwas_parameters)
sum_pve_modality_total <- sum_pve_modality$total_pve
names(sum_pve_modality_total) <- sum_pve_modality$type
sum_pve_modality_alltraits[[i]] <- sum_pve_modality_total
}
names(sum_pve_tissue_alltraits) <- traits
names(sum_pve_modality_alltraits) <- traits
Bubble plot: show %h2g explained by molecular QTLs of each tissue on each trait. Use union of five tissues across all traits.
Message: cTWAS is able to find the right tissues.
sum_pve_tissue_percentages <- lapply(sum_pve_tissue_alltraits, function(x) x / sum(x) * 100)
cluster_names <- names(sum_pve_tissue_percentages)
filtered_list <- lapply(sum_pve_tissue_percentages, function(x) x[!names(x) %in% c("SNP")])
# Calculate the sum of each vector in the filtered list
sum_values <- sapply(filtered_list, sum)
max_values <- sapply(filtered_list, max)
# Calculate the names of maximum values for each vector in the filtered list
max_names <- sapply(filtered_list, function(x) names(x)[which.max(x)])
df <- bind_rows(
lapply(names(filtered_list), function(x) {
data.frame(Trait = x, Tissue = names(filtered_list[[x]]), Expression = filtered_list[[x]], stringsAsFactors = FALSE)
}),
.id = "id"
) %>%
dplyr::select(-id) %>%
spread(Trait, Expression)
df_long <- reshape2::melt(df, id.vars = "Tissue", variable.name = "Trait", value.name = "Expression")
ggplot(df_long, aes(x = Trait, y = Tissue, size = Expression)) +
geom_point(alpha = 0.5, color = "blue") + # Using a fixed color for all bubbles
scale_size(range = c(1, 20), name = "%h2g") + # Customizing the size legend title
labs(x = "Trait", y = "Tissue") +
theme_minimal() +
theme(axis.text.x = element_text(size = 16, angle = 45, hjust = 1),
axis.text.y = element_text(size = 16),
axis.title.x = element_text(size = 16),
axis.title.y = element_text(size = 16),
legend.text = element_text(size = 16), # Increase legend text size
legend.title = element_text(size = 18))
Contributions of top tissue vs. all tissues together.
Bar plot of %h2g: two bars, top tissue vs. all tissues together, per trait. Use the top tissue from joint analysis.
Message: genetics of complex traits involve multiple tissues.
# Create the data frame including names of maximum values
data <- data.frame(
cluster = rep(cluster_names, times = 3),
value = c(max_values, sum_values, max_values),
type = c(rep("toptissue", times = length(cluster_names)),
rep("sum_alltissues", times = length(cluster_names)),
rep("max_name", times = length(cluster_names))),
label = c(rep("", times = length(cluster_names) * 2), max_names)
)
ggplot(data[data$type != "max_name", ], aes(x = cluster, y = value, fill = type)) +
geom_bar(stat = "identity", position = position_dodge(), width = 0.7) +
geom_text(data = data[data$type == "max_name", ], aes(label = label, y = value + 2),
position = position_dodge(width = 0.7), vjust = -0.5, hjust=-0.01) +
labs(x = "Traits", y = "%h2g", fill = "Group") +
theme_minimal() +
theme(axis.text.x = element_text(size = 16, angle = 45, hjust = 1),
axis.text.y = element_text(size = 16),
axis.title.x = element_text(size = 16),
axis.title.y = element_text(size = 16),
legend.text = element_text(size = 16), # Increase legend text size
legend.title = element_text(size = 18))
Contribution of different modalities: Bar plot of %h2g: eQTL, sQTL, APA-QTL, per trait.
Message: genetics involves multiple modalities
sum_pve_modality_percentages <- lapply(sum_pve_modality_alltraits, function(x) x / sum(x) * 100)
cluster_names <- names(sum_pve_modality_percentages)
filtered_list <- lapply(sum_pve_modality_percentages, function(x) x[!names(x) %in% c("SNP")])
# Calculate the sum of each vector in the filtered list
sum_values <- sapply(filtered_list, sum)
max_values <- sapply(filtered_list, max)
# Calculate the names of maximum values for each vector in the filtered list
max_names <- sapply(filtered_list, function(x) names(x)[which.max(x)])
df <- do.call(rbind, lapply(filtered_list, function(x) data.frame(Group = names(x), h2g = x)))
df$Trait <- rep(names(filtered_list), each = length(filtered_list[[1]]))
# Reshape data frame if necessary
df <- reshape2::melt(df, id.vars = c("Trait", "Group"))
ggplot(df, aes(x = Trait, y = value, fill = Group)) +
geom_bar(stat = "identity", position = "dodge") +
labs(x = "Trait", y = "%h2g") +
theme_minimal() +
theme(axis.text.x = element_text(size = 16, angle = 45, hjust = 1),
axis.text.y = element_text(size = 16),
axis.title.x = element_text(size = 16),
axis.title.y = element_text(size = 16),
legend.text = element_text(size = 16), # Increase legend text size
legend.title = element_text(size = 18))
Number of high PIP genes: all tissues vs. best tissue eQTL (from single tissue analysis).
Bar plot.
Message: increased power from multi-omics multi-tissue analysis.
data <- data.frame(
trait = traits,
num_single = c(16,40,35,23,109),
tissue_single = c("Cells_Cultured_fibroblasts","Liver","Artery_Tibial","Heart_Left_Ventricle","Whole_Blood"),
num_multi = c(32,67,84,28,220)
)
data_long <- pivot_longer(data, cols = c(num_single, num_multi), names_to = "category", values_to = "count")
ggplot(data_long, aes(x = trait, y = count, fill = category)) +
geom_bar(stat = "identity", position = position_dodge()) +
labs(x = "Trait", y = "number of sig genes") +
theme_minimal() +
theme(axis.text.x = element_text(size = 12, angle = 45, hjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14))
Overlap of high PIP genes: single tissue eQTL vs. all tissues.
Bar plot: percent of overlap, choose top 2 tissues per trait (by number of high PIP genes from single-tissue eQTL), one bar per trait-tissue pair.
Message: reduce FPs.
data <- data.frame(
trait = c("IBD-ebi-a-GCST004131","IBD-ebi-a-GCST004131", "LDL-ukb-d-30780_irnt", "LDL-ukb-d-30780_irnt","SBP-ukb-a-360", "SBP-ukb-a-360","SCZ-ieu-b-5102","SCZ-ieu-b-5102", "WBC-ieu-b-30", "WBC-ieu-b-30"),
num_single = c(16,14,40,24,35,29,23,22,109,68),
overlap = c(5,7,26,15,19,10,12,10,73,40),
tissue_single = c("Cells_Cultured_fibroblasts","Whole_Blood","Liver","Spleen","Artery_Tibial","Adipose_Subcutaneous","Heart_Left_Ventricle","Adrenal_Gland","Whole_Blood","Adipose_Subcutaneous"),
num_multi = c(32,32,67,67,84,84,28,28,220,220)
)
data$overlap_pct <- data$overlap/data$num_single*100
ggplot(data, aes(x = tissue_single, y = overlap_pct, fill = tissue_single)) +
geom_bar(stat = "identity", position = position_dodge()) +
facet_wrap(~ trait, nrow = 1, scales = "free_x") + # Display all facets in one row with free scales on x
labs(x = "Tissues", y = "Overlap Percentage") +
theme_minimal() +
theme(axis.text.x = element_text(size = 12,angle = 45, hjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"))
Percent of high PIP genes driven by single type (eQTL, sQTL, apa-QTL and apa+sQTL together).
Bar plot: Y-axis, percent of genes. Single bar per trait (sum to 1), color different types: 3 molecular QTLs, and un-specified.
Message: in the majority of cases, we can identify the molecular mechanisms.
df <- data.frame(
trait = c("IBD-ebi-a-GCST004131", "LDL-ukb-o-30780_irnt", "SBP-ukb-a-360", "SCZ-ieu-b-5102", "WBC-ieu-b-30"),
by_eQTL = c(16, 34, 33, 16, 129),
by_sQTL = c(10, 23, 39, 6, 49),
by_apaQTL = c(3, 3, 3, 2, 7),
by_sQTLapaQTL = c(0, 2, 0, 0, 3),
unspecified = c(3, 5, 9, 4, 32)
)
# Calculate the row sums for all columns except the first (trait)
row_totals <- rowSums(df[, -1])
# Convert counts to percentages
df_percent <- df
df_percent[, -1] <- sweep(df[, -1], 1, row_totals, FUN = "/") * 100
df_long <- tidyr::pivot_longer(df_percent, cols = -trait, names_to = "Category", values_to = "Percentage")
ggplot(df_long, aes(x = trait, y = Percentage, fill = Category)) +
geom_bar(stat = "identity", position = "dodge") +
theme_minimal() +
labs(x = "Trait",
y = "Percentage (%)",
fill = "Category") +
scale_fill_brewer(palette = "Paired") + # This sets nice colors, you can change the palette
theme(axis.text.x = element_text(size = 16, angle = 45, hjust = 1),
axis.text.y = element_text(size = 16),
axis.title.x = element_text(size = 16),
axis.title.y = element_text(size = 16),
legend.text = element_text(size = 16), # Increase legend text size
legend.title = element_text(size = 18))
Percent of high PIP genes driven by a single tissue
bar plot, one bar per trait.
Message: more uncertainty, but cTWAS still can resolve likely causal tissues in many cases.
df_new <- data.frame(
trait = c("IBD-ebi-a-GCST004131", "LDL-ukb-d-30780_irnt", "SBP-ukb-a-360", "SCZ-ieu-b-5102", "WBC-ieu-b-30"),
tissue1 = c(6, 7, 20, 3, 52),
tissue2 = c(2, 20, 8, 2, 18),
tissue3 = c(6, 12, 5, 0, 14),
tissue4 = c(3, 1, 11, 1, 18),
tissue5 = c(0, 2, 4, 3, 14),
unspecified = c(15, 25, 36, 19, 104)
)
# Calculate row totals
row_totals_new <- rowSums(df_new[, -1])
# Convert counts to percentages
df_percent_new <- df_new
df_percent_new[, -1] <- sweep(df_new[, -1], 1, row_totals_new, FUN = "/") * 100
# Convert the data frame from wide to long format for plotting
df_long_new <- tidyr::pivot_longer(df_percent_new, cols = -trait, names_to = "Tissue", values_to = "Percentage")
tissue_map <- list(
`IBD-ebi-a-GCST004131` = c("Adipose_Subcutaneous", "Esophagus_Mucosa", "Whole_Blood", "Heart_Left_Ventricle", "Cells_Cultured_fibroblasts","unspecified"),
`LDL-ukb-d-30780_irnt` = c("Esophagus_Mucosa", "Liver", "Spleen", "Adipose_Subcutaneous", "Adrenal_Gland","unspecified"),
`SBP-ukb-a-360` = c("Artery_Tibial", "Heart_Left_Ventricle", "Spleen", "Brain_Cortex", "Adipose_Subcutaneous","unspecified"),
`SCZ-ieu-b-5102` = c("Heart_Left_Ventricle", "Adrenal_Gland", "Artery_Coronary", "Stomach", "Brain_Cerebellum","unspecified"),
`WBC-ieu-b-30` = c("Whole_Blood", "Adipose_Subcutaneous", "Artery_Aorta", "Skin_Sun_Exposed_Lower_leg", "Spleen","unspecified")
)
tissue_map <- unlist(tissue_map)
df_long_new$Tissue <- tissue_map
ggplot(df_long_new, aes(x = Tissue, y = Percentage, fill = Tissue)) +
geom_bar(stat = "identity", position = position_dodge()) +
facet_wrap(~ trait, nrow = 1, scales = "free_x") + # Display all facets in one row with free scales on x
labs(x = "Tissues", y = "Percentage") +
theme_minimal() +
theme(axis.text.x = element_text(size = 12,angle = 45, hjust = 1),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
strip.background = element_blank(),
strip.text.x = element_text(size = 12, face = "bold"))
Table of novel genes: genes found by MG-cTWAS but not single-tissue eQTL (union). Total PIP, PIP from each molecular type, PIP from single tissue analysis.
load("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/analy_results/novelgenes_IBD-ebi-a-GCST004131.rdata")
DT::datatable(novelgenes,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Novel genes identified by MG-cTWAS, IBD-ebi-a-GCST004131'),options = list(pageLength = 5) )
load("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/analy_results/novelgenes_LDL-ukb-d-30780_irnt.rdata")
DT::datatable(novelgenes,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Novel genes identified by MG-cTWAS, LDL-ukb-o-30780_irnt'),options = list(pageLength = 5) )
load("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/analy_results/novelgenes_SBP-ukb-a-360.rdata")
DT::datatable(novelgenes,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Novel genes identified by MG-cTWAS, SBP-ukb-a-360'),options = list(pageLength = 5) )
load("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/analy_results/novelgenes_SCZ-ieu-b-5102.rdata")
DT::datatable(novelgenes,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Novel genes identified by MG-cTWAS, SCZ-ieu-b-5102'),options = list(pageLength = 5) )
load("/project/xinhe/xsun/multi_group_ctwas/5.multi_group_testing/analy_results/novelgenes_WBC-ieu-b-30.rdata")
DT::datatable(novelgenes,caption = htmltools::tags$caption( style = 'caption-side: topleft; text-align = left; color:black;','Novel genes identified by MG-cTWAS, WBC-ieu-b-30'),options = list(pageLength = 5) )
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] forcats_0.5.1 stringr_1.5.1 purrr_1.0.2 readr_2.1.2
[5] tibble_3.2.1 tidyverse_1.3.1 tidyr_1.3.0 dplyr_1.1.4
[9] ctwas_0.2.1.9000 ggplot2_3.5.1
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 fs_1.5.2
[9] rstudioapi_0.13 farver_2.1.0
[11] DT_0.22 ggrepel_0.9.1
[13] bit64_4.0.5 lubridate_1.8.0
[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] broom_0.8.0 dbplyr_2.1.1
[27] png_0.1-7 compiler_4.2.0
[29] httr_1.4.3 backports_1.4.1
[31] assertthat_0.2.1 Matrix_1.5-3
[33] fastmap_1.1.0 lazyeval_0.2.2
[35] cli_3.6.1 later_1.3.0
[37] htmltools_0.5.2 prettyunits_1.1.1
[39] tools_4.2.0 gtable_0.3.0
[41] glue_1.6.2 GenomeInfoDbData_1.2.8
[43] reshape2_1.4.4 rappdirs_0.3.3
[45] Rcpp_1.0.8.3 Biobase_2.56.0
[47] cellranger_1.1.0 jquerylib_0.1.4
[49] vctrs_0.6.5 Biostrings_2.64.0
[51] rtracklayer_1.56.0 crosstalk_1.2.0
[53] xfun_0.41 rvest_1.0.2
[55] lifecycle_1.0.4 irlba_2.3.5
[57] restfulr_0.0.14 ensembldb_2.20.2
[59] XML_3.99-0.14 zlibbioc_1.42.0
[61] zoo_1.8-10 scales_1.3.0
[63] gggrid_0.2-0 hms_1.1.1
[65] promises_1.2.0.1 MatrixGenerics_1.8.0
[67] ProtGenerics_1.28.0 parallel_4.2.0
[69] SummarizedExperiment_1.26.1 RColorBrewer_1.1-3
[71] AnnotationFilter_1.20.0 LDlinkR_1.2.3
[73] yaml_2.3.5 curl_4.3.2
[75] memoise_2.0.1 sass_0.4.1
[77] biomaRt_2.54.1 stringi_1.7.6
[79] RSQLite_2.3.1 highr_0.9
[81] S4Vectors_0.34.0 BiocIO_1.6.0
[83] GenomicFeatures_1.48.3 BiocGenerics_0.42.0
[85] filelock_1.0.2 BiocParallel_1.30.3
[87] GenomeInfoDb_1.39.9 rlang_1.1.2
[89] pkgconfig_2.0.3 matrixStats_0.62.0
[91] bitops_1.0-7 evaluate_0.15
[93] lattice_0.20-45 labeling_0.4.2
[95] GenomicAlignments_1.32.0 htmlwidgets_1.5.4
[97] cowplot_1.1.1 bit_4.0.4
[99] tidyselect_1.2.0 plyr_1.8.7
[101] magrittr_2.0.3 R6_2.5.1
[103] IRanges_2.30.0 generics_0.1.2
[105] DelayedArray_0.22.0 DBI_1.2.2
[107] haven_2.5.0 pgenlibr_0.3.3
[109] pillar_1.9.0 withr_2.5.0
[111] KEGGREST_1.36.3 RCurl_1.98-1.7
[113] mixsqp_0.3-43 modelr_0.1.8
[115] crayon_1.5.1 utf8_1.2.2
[117] BiocFileCache_2.4.0 plotly_4.10.0
[119] tzdb_0.4.0 rmarkdown_2.25
[121] progress_1.2.2 readxl_1.4.0
[123] grid_4.2.0 data.table_1.14.2
[125] blob_1.2.3 git2r_0.30.1
[127] reprex_2.0.1 digest_0.6.29
[129] httpuv_1.6.5 stats4_4.2.0
[131] munsell_0.5.0 viridisLite_0.4.0
[133] bslib_0.3.1