Last updated: 2025-06-03
Checks: 6 1
Knit directory: CX5461_Project/
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(20250129)
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 8d1b366. 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: .RData
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: 0.1 box.svg
Ignored: Rplot04.svg
Ignored: analysis/Corrmotif_Conc.html
Untracked files:
Untracked: 0.1 density.svg
Untracked: 0.1.emf
Untracked: 0.1.svg
Untracked: 0.5 box.svg
Untracked: 0.5 density.svg
Untracked: 0.5.svg
Untracked: Additional/
Untracked: Autosome factors.svg
Untracked: CX_5461_Pattern_Genes_24hr.csv
Untracked: CX_5461_Pattern_Genes_3hr.csv
Untracked: Cell viability box plot.svg
Untracked: DEG GO terms.svg
Untracked: DNA damage associated GO terms.svg
Untracked: DRC1.svg
Untracked: Figure 1.jpeg
Untracked: Figure 1.pdf
Untracked: Figure_CM_Purity.pdf
Untracked: G Quadruplex DEGs.svg
Untracked: PC2 Vs PC3 Autosome.svg
Untracked: PCA autosome.svg
Untracked: Rplot 18.svg
Untracked: Rplot.svg
Untracked: Rplot01.svg
Untracked: Rplot02.svg
Untracked: Rplot03.svg
Untracked: Rplot05.svg
Untracked: Rplot06.svg
Untracked: Rplot07.svg
Untracked: Rplot08.jpeg
Untracked: Rplot08.svg
Untracked: Rplot09.svg
Untracked: Rplot10.svg
Untracked: Rplot11.svg
Untracked: Rplot12.svg
Untracked: Rplot13.svg
Untracked: Rplot14.svg
Untracked: Rplot15.svg
Untracked: Rplot16.svg
Untracked: Rplot17.svg
Untracked: Rplot18.svg
Untracked: Rplot19.svg
Untracked: Rplot20.svg
Untracked: Rplot21.svg
Untracked: Rplot22.svg
Untracked: Rplot23.svg
Untracked: Rplot24.svg
Untracked: TOP2B.bed
Untracked: TS HPA (Violin).svg
Untracked: TS HPA.svg
Untracked: TS_HA.svg
Untracked: TS_HV.svg
Untracked: Violin HA.svg
Untracked: Violin HV (CX vs DOX).svg
Untracked: Violin HV.svg
Untracked: data/AF.csv
Untracked: data/AF_Mapped.csv
Untracked: data/AF_genes.csv
Untracked: data/Annotated_DOX_Gene_Table.csv
Untracked: data/BP/
Untracked: data/CAD_genes.csv
Untracked: data/Cardiotox.csv
Untracked: data/Cardiotox_mapped.csv
Untracked: data/Corrmotif_GO/
Untracked: data/DOX_Vald.csv
Untracked: data/DOX_Vald_Mapped.csv
Untracked: data/DOX_alt.csv
Untracked: data/Entrez_Cardiotox.csv
Untracked: data/Entrez_Cardiotox_Mapped.csv
Untracked: data/GWAS.xlsx
Untracked: data/GWAS_SNPs.bed
Untracked: data/HF.csv
Untracked: data/HF_Mapped.csv
Untracked: data/HF_genes.csv
Untracked: data/Hypertension_genes.csv
Untracked: data/MI_genes.csv
Untracked: data/P53_Target_mapped.csv
Untracked: data/Sample_annotated.csv
Untracked: data/Samples.csv
Untracked: data/Samples.xlsx
Untracked: data/TOP2A.bed
Untracked: data/TOP2A_target.csv
Untracked: data/TOP2A_target_lit.csv
Untracked: data/TOP2A_target_lit_mapped.csv
Untracked: data/TOP2A_target_mapped.csv
Untracked: data/TOP2B.bed
Untracked: data/TOP2B_target.csv
Untracked: data/TOP2B_target_heatmap.csv
Untracked: data/TOP2B_target_heatmap_mapped.csv
Untracked: data/TOP2B_target_mapped.csv
Untracked: data/TS.csv
Untracked: data/TS_HPA.csv
Untracked: data/TS_HPA_mapped.csv
Untracked: data/Toptable_CX_0.1_24.csv
Untracked: data/Toptable_CX_0.1_3.csv
Untracked: data/Toptable_CX_0.1_48.csv
Untracked: data/Toptable_CX_0.5_24.csv
Untracked: data/Toptable_CX_0.5_3.csv
Untracked: data/Toptable_CX_0.5_48.csv
Untracked: data/Toptable_DOX_0.1_24.csv
Untracked: data/Toptable_DOX_0.1_3.csv
Untracked: data/Toptable_DOX_0.1_48.csv
Untracked: data/Toptable_DOX_0.5_24.csv
Untracked: data/Toptable_DOX_0.5_3.csv
Untracked: data/Toptable_DOX_0.5_48.csv
Untracked: data/count.tsv
Untracked: data/ts_data_mapped
Untracked: results/
Untracked: run_bedtools.bat
Unstaged changes:
Deleted: analysis/Actox.Rmd
Modified: analysis/DDR_Gquad.Rmd
Modified: analysis/DDR_Gquad_Corr.Rmd
Modified: data/DOX_0.5_48 (Combined).csv
Modified: data/Total_number_of_Mapped_reads_by_Individuals.csv
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/DDR_Gquad.Rmd
) and HTML
(docs/DDR_Gquad.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 |
---|---|---|---|---|
html | 8d1b366 | sayanpaul01 | 2025-06-03 | Commit |
Rmd | 3bfb399 | sayanpaul01 | 2025-06-03 | Commit |
html | 3bfb399 | sayanpaul01 | 2025-06-03 | Commit |
Rmd | b07a3be | sayanpaul01 | 2025-06-01 | Commit |
html | b07a3be | sayanpaul01 | 2025-06-01 | Commit |
Rmd | e9c6af4 | sayanpaul01 | 2025-06-01 | Commit |
html | e9c6af4 | sayanpaul01 | 2025-06-01 | Commit |
Rmd | 69a0b92 | sayanpaul01 | 2025-06-01 | Commit |
html | 55b5edc | sayanpaul01 | 2025-06-01 | Commit |
### 📦 Load Required Libraries
library(tidyverse)
library(data.table)
library(ComplexHeatmap)
library(circlize)
library(grid)
### 📁 Input GO Enrichment Files (First Set)
go_files <- list(
"CX_0.1_3" = "data/BP/All_Terms/GO_BP_CX_0.1_3.csv",
"CX_0.1_24" = "data/BP/All_Terms/GO_BP_CX_0.1_24.csv",
"CX_0.1_48" = "data/BP/All_Terms/GO_BP_CX_0.1_48.csv",
"CX_0.5_3" = "data/BP/All_Terms/GO_BP_CX_0.5_3.csv",
"CX_0.5_24" = "data/BP/All_Terms/GO_BP_CX_0.5_24.csv",
"CX_0.5_48" = "data/BP/All_Terms/GO_BP_CX_0.5_48.csv",
"DOX_0.1_3" = "data/BP/All_Terms/GO_BP_DOX_0.1_3.csv",
"DOX_0.1_24"= "data/BP/All_Terms/GO_BP_DOX_0.1_24.csv",
"DOX_0.1_48"= "data/BP/All_Terms/GO_BP_DOX_0.1_48.csv",
"DOX_0.5_3" = "data/BP/All_Terms/GO_BP_DOX_0.5_3.csv",
"DOX_0.5_24"= "data/BP/All_Terms/GO_BP_DOX_0.5_24.csv",
"DOX_0.5_48"= "data/BP/All_Terms/GO_BP_DOX_0.5_48.csv"
)
### 🧬 Define GO parent terms of interest and map their children
parent_terms <- list(
"GO:0006974" = "DNA damage response",
"GO:0141112" = "broken chromosome clustering",
"GO:0006281" = "DNA repair",
"GO:0140861" = "DNA repair-dependent chromatin remodeling",
"GO:0008630" = "intrinsic apoptotic signaling pathway in response to DNA damage",
"GO:0042770" = "signal transduction in response to DNA damage",
"GO:0009432" = "SOS response",
"GO:0043247" = "telomere maintenance in response to DNA damage"
)
child_map <- list(
"GO:0006281" = c("GO:0006284", "GO:0006307", "GO:0006302", "GO:0006298", "GO:0043504",
"GO:0006289", "GO:0006301", "GO:0006290", "GO:0000725", "GO:0000012"),
"GO:0008630" = c("GO:0042771", "GO:1902230", "GO:1902231", "GO:1902229"),
"GO:0042770" = c("GO:0000077", "GO:0030330", "GO:0042772", "GO:0044773",
"GO:2000002", "GO:2000003", "GO:2000001"),
"GO:0043247" = c("GO:1904506", "GO:1904507", "GO:0031848", "GO:1904505", "GO:0097698")
)
ddr_descriptions <- unname(unlist(parent_terms))
### 🔁 Step 1: Retrieve best p-values across all conditions
go_matrix_df <- map_dfr(names(go_files), function(cond) {
file <- go_files[[cond]]
df <- tryCatch(fread(file), error = function(e) return(data.table()))
if (nrow(df) == 0 || !all(c("ID", "Description", "pvalue", "p.adjust") %in% colnames(df))) {
message("⚠️ Skipping or padding malformed file: ", cond)
return(tibble(Description = ddr_descriptions, pvalue = NA, p.adjust = NA, log10p = NA, Condition = cond))
}
df <- as_tibble(df) %>% dplyr::select(ID, Description, pvalue, p.adjust)
results <- lapply(names(parent_terms), function(parent_id) {
all_ids <- c(parent_id, child_map[[parent_id]])
df_sub <- df %>% filter(ID %in% all_ids)
if (nrow(df_sub) == 0) {
tibble(Description = parent_terms[[parent_id]], pvalue = NA, p.adjust = NA, log10p = NA, Condition = cond)
} else {
best_row <- df_sub %>% slice_min(pvalue, n = 1)
tibble(Description = parent_terms[[parent_id]],
pvalue = best_row$pvalue,
p.adjust = best_row$p.adjust,
log10p = -log10(best_row$pvalue),
Condition = cond)
}
})
bind_rows(results)
})
### 🧱 Step 2: Build heatmap matrix and p-value matrix
heatmap_data <- go_matrix_df %>%
dplyr::select(Description, Condition, log10p) %>%
pivot_wider(names_from = Condition, values_from = log10p) %>%
column_to_rownames("Description") %>%
as.matrix()
pval_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, pvalue) %>%
pivot_wider(names_from = Condition, values_from = pvalue) %>%
column_to_rownames("Description") %>%
as.matrix()
p_adj_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, p.adjust) %>%
pivot_wider(names_from = Condition, values_from = p.adjust) %>%
column_to_rownames("Description") %>%
as.matrix()
### ✅ Step 3: Ensure all conditions are included
all_conditions <- names(go_files)
missing_cols <- setdiff(all_conditions, colnames(heatmap_data))
if (length(missing_cols) > 0) {
for (cond in missing_cols) {
heatmap_data[, cond] <- NA
pval_matrix[, cond] <- NA
}
heatmap_data <- heatmap_data[, all_conditions]
pval_matrix <- pval_matrix[, all_conditions]
}
### 🎨 Step 4: Define color palette
breaks <- seq(0, 20, by = 2.5)
palette <- colorRampPalette(c("white", "#fde0dd", "#fa9fb5", "#f768a1", "#c51b8a", "#7a0177", "#49006a"))(length(breaks))
col_fun <- colorRamp2(breaks, palette)
### 🔥 Step 5: Plot Heatmap
ht <- Heatmap(
heatmap_data,
name = "-log10(p)",
col = col_fun,
na_col = "white",
rect_gp = gpar(col = "black", lwd = 0.5),
cluster_rows = FALSE,
cluster_columns = FALSE,
row_names_gp = gpar(fontsize = 9),
column_names_gp = gpar(fontsize = 9),
column_names_rot = 45,
row_names_max_width = max_text_width(rownames(heatmap_data), gp = gpar(fontsize = 9)),
cell_fun = function(j, i, x, y, width, height, fill) {
adj_p <- p_adj_matrix[i, j] # Use p.adjust matrix for significance check
if (!is.na(adj_p) && adj_p < 0.05) {
grid.text("*", x, y, gp = gpar(fontsize = 12))
}
},
heatmap_legend_param = list(
title = "-log10(p value)",
at = breaks,
labels = as.character(breaks),
legend_width = unit(5, "cm"),
direction = "horizontal",
title_gp = gpar(fontsize = 10, fontface = "bold"),
labels_gp = gpar(fontsize = 9)
)
)
### 🖼 Final Draw
draw(ht, heatmap_legend_side = "top")
### 📦 Load Required Libraries
library(tidyverse)
library(data.table)
library(ComplexHeatmap)
library(circlize)
library(grid)
### 📁 Define Input Files (All 12 Conditions)
go_files <- list(
"CX_0.1_3" = "data/BP/All_Terms/GO_BP_CX_0.1_3.csv",
"CX_0.1_24" = "data/BP/All_Terms/GO_BP_CX_0.1_24.csv",
"CX_0.1_48" = "data/BP/All_Terms/GO_BP_CX_0.1_48.csv",
"CX_0.5_3" = "data/BP/All_Terms/GO_BP_CX_0.5_3.csv",
"CX_0.5_24" = "data/BP/All_Terms/GO_BP_CX_0.5_24.csv",
"CX_0.5_48" = "data/BP/All_Terms/GO_BP_CX_0.5_48.csv",
"DOX_0.1_3" = "data/BP/All_Terms/GO_BP_DOX_0.1_3.csv",
"DOX_0.1_24"= "data/BP/All_Terms/GO_BP_DOX_0.1_24.csv",
"DOX_0.1_48"= "data/BP/All_Terms/GO_BP_DOX_0.1_48.csv",
"DOX_0.5_3" = "data/BP/All_Terms/GO_BP_DOX_0.5_3.csv",
"DOX_0.5_24"= "data/BP/All_Terms/GO_BP_DOX_0.5_24.csv",
"DOX_0.5_48"= "data/BP/All_Terms/GO_BP_DOX_0.5_48.csv"
)
### 🧬 Ribosome Biogenesis GO Terms
parent_terms <- list(
"GO:0042254" = "ribosome biogenesis",
"GO:0090071" = "negative regulation of ribosome biogenesis",
"GO:0042273" = "ribosomal large subunit biogenesis",
"GO:0042274" = "ribosomal small subunit biogenesis",
"GO:0000054" = "ribosomal subunit export from nucleus",
"GO:0042255" = "ribosome assembly",
"GO:0006364" = "rRNA processing"
)
child_map <- list(
"GO:0090071" = c("GO:2000201", "GO:2000233"),
"GO:0042273" = c("GO:0000470", "GO:0000027"),
"GO:0042274" = c("GO:0030490", "GO:0000028", "GO:0140638"),
"GO:0000054" = c("GO:2000201", "GO:2000202", "GO:2000200", "GO:0000055", "GO:0000056"),
"GO:0042255" = c("GO:0042256", "GO:0061668", "GO:0000027", "GO:0000028"),
"GO:0006364" = c(
"GO:1901259", "GO:0000450", "GO:0000483", "GO:0002103", "GO:0000479", "GO:0000449",
"GO:0000475", "GO:0000476", "GO:0000460", "GO:0000481", "GO:0000470", "GO:0030490",
"GO:2000233", "GO:2000234", "GO:2000232", "GO:0031125", "GO:0000967", "GO:0000154", "GO:1990417"
)
)
### 🔁 Extract –log10(pvalue) per condition for Ribosome Biogenesis terms
go_descriptions <- unname(unlist(parent_terms))
go_matrix_df <- map_dfr(names(go_files), function(cond) {
file <- go_files[[cond]]
df <- tryCatch(fread(file), error = function(e) return(data.table()))
if (nrow(df) == 0 || !all(c("ID", "Description", "pvalue", "p.adjust") %in% colnames(df))) {
message("⚠️ Skipping or padding malformed file: ", cond)
return(tibble(Description = go_descriptions, pvalue = NA, p.adjust = NA, log10p = NA, Condition = cond))
}
df <- as_tibble(df) %>% dplyr::select(ID, Description, pvalue, p.adjust)
results <- lapply(names(parent_terms), function(parent_id) {
all_ids <- c(parent_id, child_map[[parent_id]])
df_sub <- df %>% filter(ID %in% all_ids)
if (nrow(df_sub) == 0) {
tibble(Description = parent_terms[[parent_id]], pvalue = NA, p.adjust = NA, log10p = NA, Condition = cond)
} else {
best_row <- df_sub %>% slice_min(pvalue, n = 1)
tibble(Description = parent_terms[[parent_id]],
pvalue = best_row$pvalue,
p.adjust = best_row$p.adjust,
log10p = -log10(best_row$pvalue),
Condition = cond)
}
})
bind_rows(results)
})
### 🧱 Build matrices
heatmap_data <- go_matrix_df %>%
dplyr::select(Description, Condition, log10p) %>%
pivot_wider(names_from = Condition, values_from = log10p) %>%
column_to_rownames("Description") %>%
as.matrix()
pval_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, pvalue) %>%
pivot_wider(names_from = Condition, values_from = pvalue) %>%
column_to_rownames("Description") %>%
as.matrix()
p_adj_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, p.adjust) %>%
pivot_wider(names_from = Condition, values_from = p.adjust) %>%
column_to_rownames("Description") %>%
as.matrix()
### 🔧 Ensure all conditions are included
all_conditions <- names(go_files)
for (cond in setdiff(all_conditions, colnames(heatmap_data))) {
heatmap_data[, cond] <- NA
pval_matrix[, cond] <- NA
}
heatmap_data <- heatmap_data[, all_conditions]
pval_matrix <- pval_matrix[, all_conditions]
### 🎨 Color Palette
breaks <- seq(0, 20, by = 2.5)
palette <- colorRampPalette(c("white", "#fde0dd", "#fa9fb5", "#f768a1", "#c51b8a", "#7a0177", "#49006a"))(length(breaks))
col_fun <- colorRamp2(breaks, palette)
### 🔥 Plot Heatmap
ht <- Heatmap(
heatmap_data,
name = "-log10(p)",
col = col_fun,
na_col = "white",
rect_gp = gpar(col = "black", lwd = 0.5),
cluster_rows = FALSE,
cluster_columns = FALSE,
row_names_gp = gpar(fontsize = 9),
column_names_gp = gpar(fontsize = 9),
column_names_rot = 45,
row_names_max_width = max_text_width(rownames(heatmap_data), gp = gpar(fontsize = 9)),
cell_fun = function(j, i, x, y, width, height, fill) {
adj_p <- p_adj_matrix[i, j] # Use p.adjust matrix for significance check
if (!is.na(adj_p) && adj_p < 0.05) {
grid.text("*", x, y, gp = gpar(fontsize = 12))
}
},
heatmap_legend_param = list(
title = "-log10(p value)",
at = breaks,
labels = as.character(breaks),
legend_width = unit(5, "cm"),
direction = "horizontal",
title_gp = gpar(fontsize = 10, fontface = "bold"),
labels_gp = gpar(fontsize = 9)
)
)
### 🖼 Final Draw
draw(ht, heatmap_legend_side = "top")
Version | Author | Date |
---|---|---|
e9c6af4 | sayanpaul01 | 2025-06-01 |
library(tidyverse)
library(data.table)
library(ComplexHeatmap)
library(circlize)
library(grid)
# 📁 Define GO enrichment input files
go_files <- list(
"CX_0.1_3" = "data/BP/Combined_Terms/GO_All_CX_0.1_3.csv",
"CX_0.1_24" = "data/BP/Combined_Terms/GO_All_CX_0.1_24.csv",
"CX_0.1_48" = "data/BP/Combined_Terms/GO_All_CX_0.1_48.csv",
"CX_0.5_3" = "data/BP/Combined_Terms/GO_All_CX_0.5_3.csv",
"CX_0.5_24" = "data/BP/Combined_Terms/GO_All_CX_0.5_24.csv",
"CX_0.5_48" = "data/BP/Combined_Terms/GO_All_CX_0.5_48.csv",
"DOX_0.1_3" = "data/BP/Combined_Terms/GO_All_DOX_0.1_3.csv",
"DOX_0.1_24" = "data/BP/Combined_Terms/GO_All_DOX_0.1_24.csv",
"DOX_0.1_48" = "data/BP/Combined_Terms/GO_All_DOX_0.1_48.csv",
"DOX_0.5_3" = "data/BP/Combined_Terms/GO_All_DOX_0.5_3.csv",
"DOX_0.5_24" = "data/BP/Combined_Terms/GO_All_DOX_0.5_24.csv",
"DOX_0.5_48" = "data/BP/Combined_Terms/GO_All_DOX_0.5_48.csv"
)
# 🧬 Define G4-related GO terms
g4_terms <- list(
"GO:0051880" = "G-quadruplex DNA binding",
"GO:0002151" = "G-quadruplex RNA binding",
"GO:0071919" = "G-quadruplex DNA formation",
"GO:1905493" = "Regulation of G-quadruplex DNA binding",
"GO:0160225" = "G-quadruplex unwinding activity",
"GO:0061849" = "Telomeric G-quadruplex DNA binding"
)
# 🔍 Function to extract values
get_go_values <- function(file_path) {
df <- fread(file_path)
df <- df[, .(ID, p.adjust, pvalue)]
log10pval <- sapply(names(g4_terms), function(go_id) {
row <- df[ID == go_id]
if (nrow(row) == 0) return(NA)
return(-log10(row$pvalue))
})
adj_p <- sapply(names(g4_terms), function(go_id) {
row <- df[ID == go_id]
if (nrow(row) == 0) return(NA)
return(row$p.adjust)
})
return(list(log10pval = log10pval, adj_p = adj_p))
}
# 🧊 Matrix generation
matrix_list <- map(go_files, get_go_values)
go_matrix <- sapply(matrix_list, function(x) x$log10pval)
padj_matrix <- sapply(matrix_list, function(x) x$adj_p)
rownames(go_matrix) <- unname(unlist(g4_terms))
rownames(padj_matrix) <- rownames(go_matrix)
# 🎨 Colors
breaks <- seq(0, 20, by = 2.5)
palette <- colorRampPalette(c("white", "#fde0dd", "#fa9fb5", "#f768a1", "#c51b8a", "#7a0177", "#49006a"))(length(breaks))
col_fun <- colorRamp2(breaks, palette)
# 🔥 Heatmap with correct cell color and stars for adj p < 0.05
ht <- Heatmap(
go_matrix,
name = "-log10(p value)",
col = col_fun,
na_col = "white",
rect_gp = gpar(col = "black", lwd = 0.5),
cluster_rows = FALSE,
cluster_columns = FALSE,
row_names_gp = gpar(fontsize = 9),
column_names_gp = gpar(fontsize = 9),
column_names_rot = 45,
row_names_max_width = max_text_width(rownames(go_matrix), gp = gpar(fontsize = 9)),
cell_fun = function(j, i, x, y, width, height, fill) {
adj_p <- padj_matrix[i, j]
if (!is.na(adj_p) && adj_p < 0.05) {
grid.text("*", x, y, gp = gpar(fontsize = 12))
}
},
heatmap_legend_param = list(
title = "-log10(p value)",
at = breaks,
labels = as.character(breaks),
legend_width = unit(5, "cm"),
direction = "horizontal",
title_gp = gpar(fontsize = 10, fontface = "bold"),
labels_gp = gpar(fontsize = 9)
)
)
# 🖼 Draw
draw(ht, heatmap_legend_side = "top")
Version | Author | Date |
---|---|---|
e9c6af4 | sayanpaul01 | 2025-06-01 |
library(tidyverse)
library(data.table)
library(ComplexHeatmap)
library(circlize)
library(grid)
### 📁 Define Input GO Enrichment Files for DEG Conditions
go_files <- list(
"CX_0.1_3" = "data/BP/Combined_Terms/GO_All_CX_0.1_3.csv",
"CX_0.1_24" = "data/BP/Combined_Terms/GO_All_CX_0.1_24.csv",
"CX_0.1_48" = "data/BP/Combined_Terms/GO_All_CX_0.1_48.csv",
"CX_0.5_3" = "data/BP/Combined_Terms/GO_All_CX_0.5_3.csv",
"CX_0.5_24" = "data/BP/Combined_Terms/GO_All_CX_0.5_24.csv",
"CX_0.5_48" = "data/BP/Combined_Terms/GO_All_CX_0.5_48.csv",
"DOX_0.1_3" = "data/BP/Combined_Terms/GO_All_DOX_0.1_3.csv",
"DOX_0.1_24" = "data/BP/Combined_Terms/GO_All_DOX_0.1_24.csv",
"DOX_0.1_48" = "data/BP/Combined_Terms/GO_All_DOX_0.1_48.csv",
"DOX_0.5_3" = "data/BP/Combined_Terms/GO_All_DOX_0.5_3.csv",
"DOX_0.5_24" = "data/BP/Combined_Terms/GO_All_DOX_0.5_24.csv",
"DOX_0.5_48" = "data/BP/Combined_Terms/GO_All_DOX_0.5_48.csv"
)
### 🔧 Parent GO Terms and their Children
parent_terms <- list(
"GO:0006360" = "transcription by RNA polymerase I",
"GO:0016479" = "negative regulation of transcription by RNA polymerase I",
"GO:0042790" = "nucleolar large rRNA transcription by RNA polymerase I",
"GO:0045943" = "positive regulation of transcription by RNA polymerase I",
"GO:0006356" = "regulation of transcription by RNA polymerase I",
"GO:0006363" = "termination of RNA polymerase I transcription",
"GO:0006361" = "transcription initiation at RNA polymerase I promoter",
"GO:0005736" = "RNA polymerase I complex"
)
child_map <- list(
"GO:0016479" = c("GO:2000731", "GO:2001208", "GO:1901837"),
"GO:0042790" = c("GO:1901837", "GO:1901838", "GO:1901836", "GO:0006362"),
"GO:0045943" = c("GO:0110016", "GO:2000732", "GO:2001209", "GO:1901838"),
"GO:0006356" = c("GO:2000730", "GO:1903357", "GO:1901836"),
"GO:0006363" = c("GO:2000731", "GO:2000732", "GO:2000730"),
"GO:0006361" = c("GO:1903357", "GO:0001188")
)
### 🔁 Compile –log10(p) matrix for parent groups
go_matrix_df <- map_dfr(names(go_files), function(cond) {
file <- go_files[[cond]]
df <- tryCatch(fread(file), error = function(e) return(data.table()))
if (nrow(df) == 0 || !all(c("ID", "Description", "pvalue", "p.adjust") %in% colnames(df))) {
message("⚠️ Skipping malformed: ", cond)
return(tibble(Description = unname(unlist(parent_terms)), pvalue = NA, log10p = NA, Condition = cond))
}
df <- df %>% as_tibble() %>% dplyr::select(ID, Description, pvalue, p.adjust)
results <- lapply(names(parent_terms), function(pid) {
all_ids <- c(pid, child_map[[pid]])
df_sub <- df %>% filter(ID %in% all_ids)
if (nrow(df_sub) == 0) {
tibble(Description = parent_terms[[pid]], pvalue = NA, log10p = NA, Condition = cond)
} else {
best <- df_sub %>% slice_min(pvalue, n = 1)
tibble(Description = parent_terms[[pid]],
pvalue = best$pvalue,
p.adjust = best$p.adjust,
log10p = -log10(best$pvalue),
Condition = cond)
}
})
bind_rows(results)
})
### 🧱 Build Heatmap Matrices
heatmap_data <- go_matrix_df %>%
dplyr::select(Description, Condition, log10p) %>%
pivot_wider(names_from = Condition, values_from = log10p) %>%
column_to_rownames("Description") %>%
as.matrix()
pval_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, pvalue) %>%
pivot_wider(names_from = Condition, values_from = pvalue) %>%
column_to_rownames("Description") %>%
as.matrix()
p_adj_matrix <- go_matrix_df %>%
dplyr::select(Description, Condition, p.adjust) %>%
pivot_wider(names_from = Condition, values_from = p.adjust) %>%
column_to_rownames("Description") %>%
as.matrix()
### 🧼 Pad missing columns (if any)
all_conditions <- names(go_files)
missing_cols <- setdiff(all_conditions, colnames(heatmap_data))
if (length(missing_cols) > 0) {
for (cond in missing_cols) {
heatmap_data[, cond] <- NA
pval_matrix[, cond] <- NA
}
heatmap_data <- heatmap_data[, all_conditions]
pval_matrix <- pval_matrix[, all_conditions]
}
### 🎨 Define Color Palette
breaks <- seq(0, 20, by = 2.5)
palette <- colorRampPalette(c("white", "#fde0dd", "#fa9fb5", "#f768a1", "#c51b8a", "#7a0177", "#49006a"))(length(breaks))
col_fun <- colorRamp2(breaks, palette)
### 🔥 Plot Heatmap with Stars for p.adjust < 0.05
ht <- Heatmap(
heatmap_data,
name = "-log10(p)",
col = col_fun,
na_col = "white",
rect_gp = gpar(col = "black", lwd = 0.5),
cluster_rows = FALSE,
cluster_columns = FALSE,
row_names_gp = gpar(fontsize = 9),
column_names_gp = gpar(fontsize = 9),
column_names_rot = 45,
row_names_max_width = max_text_width(rownames(heatmap_data), gp = gpar(fontsize = 9)),
cell_fun = function(j, i, x, y, width, height, fill) {
adj_p <- p_adj_matrix[i, j] # Use p.adjust matrix for significance check
if (!is.na(adj_p) && adj_p < 0.05) {
grid.text("*", x, y, gp = gpar(fontsize = 12))
}
},
heatmap_legend_param = list(
title = "-log10(p value)",
at = breaks,
labels = as.character(breaks),
legend_width = unit(5, "cm"),
direction = "horizontal",
title_gp = gpar(fontsize = 10, fontface = "bold"),
labels_gp = gpar(fontsize = 9)
)
)
### 🖼 Draw
draw(ht, heatmap_legend_side = "top")
sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 26100)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: America/Chicago
tzcode source: internal
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] circlize_0.4.16 ComplexHeatmap_2.18.0 data.table_1.17.0
[4] lubridate_1.9.4 forcats_1.0.0 stringr_1.5.1
[7] dplyr_1.1.4 purrr_1.0.4 readr_2.1.5
[10] tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.2
[13] tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] shape_1.4.6.1 gtable_0.3.6 rjson_0.2.23
[4] xfun_0.52 bslib_0.9.0 GlobalOptions_0.1.2
[7] tzdb_0.5.0 Cairo_1.6-2 vctrs_0.6.5
[10] tools_4.3.0 generics_0.1.3 stats4_4.3.0
[13] parallel_4.3.0 cluster_2.1.8.1 pkgconfig_2.0.3
[16] RColorBrewer_1.1-3 S4Vectors_0.40.2 lifecycle_1.0.4
[19] compiler_4.3.0 git2r_0.36.2 munsell_0.5.1
[22] codetools_0.2-20 clue_0.3-66 httpuv_1.6.15
[25] htmltools_0.5.8.1 sass_0.4.10 yaml_2.3.10
[28] later_1.3.2 pillar_1.10.2 crayon_1.5.3
[31] jquerylib_0.1.4 whisker_0.4.1 cachem_1.1.0
[34] magick_2.8.6 iterators_1.0.14 foreach_1.5.2
[37] tidyselect_1.2.1 digest_0.6.34 stringi_1.8.3
[40] rprojroot_2.0.4 fastmap_1.2.0 colorspace_2.1-0
[43] cli_3.6.1 magrittr_2.0.3 withr_3.0.2
[46] scales_1.3.0 promises_1.3.2 timechange_0.3.0
[49] rmarkdown_2.29 matrixStats_1.5.0 workflowr_1.7.1
[52] png_0.1-8 GetoptLong_1.0.5 hms_1.1.3
[55] evaluate_1.0.3 knitr_1.50 IRanges_2.36.0
[58] doParallel_1.0.17 rlang_1.1.3 Rcpp_1.0.12
[61] glue_1.7.0 BiocGenerics_0.48.1 rstudioapi_0.17.1
[64] jsonlite_2.0.0 R6_2.6.1 fs_1.6.3