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! 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
6e49457.
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:
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/parameters_apa_li.Rmd) and
HTML (docs/parameters_apa_li.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.
We estimated the parameters for the e+s+apa model in this analysis.
The apa component follows the approach described in this study https://www.nature.com/articles/s41588-021-00864-5. For
each gene, we used the lead QTL to construct a PredictDB model.
library(ctwas)
library(ggplot2)
library(tidyverse)
source("/project/xinhe/xsun/multi_group_ctwas/data/samplesize.R")
source("/project/xinhe/xsun/multi_group_ctwas/functions/0.functions.R")
folder_results_susieST <- "/project/xinhe/xsun/multi_group_ctwas/16.apa_li_weights/snakemake_outputs/"
folder_results_apaonly <- "/project/xinhe/xsun/multi_group_ctwas/16.apa_li_weights/snakemake_outputs_apaonly/"
folder_results_single <- "/project/xinhe/xsun/multi_group_ctwas/16.apa_li_weights/ctwas_output/apa/"
# 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)
colors <- c("#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf", "#f7b6d2", "#c5b0d5", "#9edae5", "#ffbb78", "#98df8a", "#ff9896" )
top_tissues <- c("Liver","Whole_Blood","Brain_Cerebellar_Hemisphere","Adipose_Subcutaneous","Brain_Cerebellum","Heart_Atrial_Appendage","Pituitary")
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")
names(top_tissues) <- traits
plot_piechart <- function(ctwas_parameters, colors, by, title) {
# Create the initial data frame
data <- data.frame(
category = names(ctwas_parameters$prop_heritability),
percentage = ctwas_parameters$prop_heritability
)
# Split the category into context and type
data <- data %>%
mutate(
context = sub("\\|.*", "", category),
type = sub(".*\\|", "", category)
)
# Aggregate the data based on the 'by' parameter
if (by == "type") {
data <- data %>%
group_by(type) %>%
summarize(percentage = sum(percentage)) %>%
mutate(category = type) # Use type as the new category
} else if (by == "context") {
data <- data %>%
group_by(context) %>%
summarize(percentage = sum(percentage)) %>%
mutate(category = context) # Use context as the new category
} else {
stop("Invalid 'by' parameter. Use 'type' or 'context'.")
}
# Calculate percentage labels for the chart
data$percentage_label <- paste0(round(data$percentage * 100, 1), "%")
# Create the pie chart
pie <- ggplot(data, aes(x = "", y = percentage, fill = category)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background and axes
geom_text(aes(label = percentage_label),
position = position_stack(vjust = 0.5), size = 3) + # Adjust size as needed
scale_fill_manual(values = colors) + # Custom colors
labs(fill = "Category") + # Legend title
ggtitle(title) # Title
return(pie)
}
plot_multi <- function(p1,p2,p3,title=NULL) {
fix_panel_size <- function(plot, width = 2.1, height = 2) {
set_panel_size(plot, width = unit(width, "in"), height = unit(height, "in"))
}
# Apply fixed panel size
pie1 <- fix_panel_size(p1)
pie2 <- fix_panel_size(p2)
pie3 <- fix_panel_size(p3)
# Compute natural widths
widths <- unit.c(grobWidth(pie1), grobWidth(pie2), grobWidth(pie3))
# Arrange
p <- grid.arrange(pie1, pie2, pie3,
ncol = 3,
widths = widths,
top = title)
return(p)
}