Last updated: 2025-02-09

Checks: 7 0

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.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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 72599ac. 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/

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/Cardiac_and_TOP2_Genes.Rmd) and HTML (docs/Cardiac_and_TOP2_Genes.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 72599ac sayanpaul01 2025-02-09 Build site.
Rmd 0e79f5b sayanpaul01 2025-02-09 Fix Timepoint Ordering in Boxplots
html a41bd50 sayanpaul01 2025-02-09 Build site.
Rmd 91f5f8f sayanpaul01 2025-02-09 Fix Timepoint Ordering in Boxplots
html bcc58f6 sayanpaul01 2025-02-09 Build site.
html 8c1912f sayanpaul01 2025-02-09 Build site.
Rmd c6b5ccd sayanpaul01 2025-02-09 Fixed boxplot significance issue for Cardiac and TOP2 genes

📌 Log2CPM Boxplots for Cardiac and TOP2 Genes

This analysis generates boxplots for cardiac genes and TOP2 genes across different treatments and timepoints.


📌 Load Required Libraries

library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.3.3
library(dplyr)
Warning: package 'dplyr' was built under R version 4.3.2
library(tidyr)
Warning: package 'tidyr' was built under R version 4.3.3

📌 Read Log2CPM Data

# Load feature count matrix
boxplot1 <- read.csv("data/Feature_count_Matrix_Log2CPM_filtered.csv") %>% as.data.frame()

# Ensure column names are cleaned
colnames(boxplot1) <- trimws(gsub("^X", "", colnames(boxplot1)))  

📌 Define Genes of Interest

# Define the genes of interest
top2_genes <- c("TOP2A", "TOP2B")
cardiac_genes <- c("ACTN2", "CALR", "MYBPC3", "MYH6", "MYH7", 
                   "MYL2", "RYR2", "SCN5A", "TNNI3", "TNNT2", "TTN")

📌 Read and Process DEGs Data

# Load Toptables
deg_files <- list.files("data/DEGs", pattern = "Toptable_.*\\.csv", full.names = TRUE)
deg_list <- lapply(deg_files, read.csv)
names(deg_list) <- gsub("data/DEGs/Toptable_|\\.csv", "", deg_files)  

# Function to check significance based on **Entrez_ID in the correct sample**
is_significant <- function(gene, drug, conc, timepoint) {
  condition <- paste(drug, conc, timepoint, sep = "_")
  if (!condition %in% names(deg_list)) return(FALSE)
  
  toptable <- deg_list[[condition]]
  gene_entrez <- boxplot1$ENTREZID[boxplot1$SYMBOL == gene]
  
  if (length(gene_entrez) == 0) return(FALSE)
  
  return(any(gene_entrez %in% toptable$Entrez_ID[toptable$adj.P.Val < 0.05]))
}

📌 Process Data for Plotting

process_gene_data <- function(gene) {
  # Filter log2CPM data for the gene
  gene_data <- boxplot1 %>% filter(SYMBOL == gene)
  
  # Reshape data
  long_data <- gene_data %>%
    pivot_longer(cols = -c(ENTREZID, SYMBOL, GENENAME), names_to = "Sample", values_to = "log2CPM") %>%
    mutate(
      Indv = case_when(
        grepl("75.1", Sample) ~ "1",
        grepl("78.1", Sample) ~ "2",
        grepl("87.1", Sample) ~ "3",
        grepl("17.3", Sample) ~ "4",
        grepl("84.1", Sample) ~ "5",
        grepl("90.1", Sample) ~ "6",
        TRUE ~ NA_character_
      ),
      Drug = case_when(
        grepl("CX.5461", Sample) ~ "CX",
        grepl("DOX", Sample) ~ "DOX",
        grepl("VEH", Sample) ~ "VEH",
        TRUE ~ NA_character_
      ),
      Conc. = case_when(
        grepl("_0.1_", Sample) ~ "0.1",
        grepl("_0.5_", Sample) ~ "0.5",
        TRUE ~ NA_character_
      ),
      Timepoint = case_when(
        grepl("_3$", Sample) ~ "3",
        grepl("_24$", Sample) ~ "24",
        grepl("_48$", Sample) ~ "48",
        TRUE ~ NA_character_
      ),
      Condition = paste(Drug, Conc., Timepoint, sep = "_")
    )

  # **Ensure Condition is Ordered Correctly**
  long_data$Condition <- factor(
    long_data$Condition, 
    levels = c(
      "CX_0.1_3", "CX_0.1_24", "CX_0.1_48", "CX_0.5_3", "CX_0.5_24", "CX_0.5_48",
      "DOX_0.1_3", "DOX_0.1_24", "DOX_0.1_48", "DOX_0.5_3", "DOX_0.5_24", "DOX_0.5_48",
      "VEH_0.1_3", "VEH_0.1_24", "VEH_0.1_48", "VEH_0.5_3", "VEH_0.5_24", "VEH_0.5_48"
    )
  )
  
  # Identify significant conditions **per Drug, Conc, and Timepoint**
  significance_labels <- long_data %>%
    distinct(Drug, Conc., Timepoint, Condition) %>%
    rowwise() %>%
    mutate(
      max_log2CPM = max(long_data$log2CPM[long_data$Condition == Condition], na.rm = TRUE),
      Significance = ifelse(is_significant(gene, Drug, Conc., Timepoint), "*", "")
    ) %>%
    filter(Significance != "") %>% ungroup()
  
  list(long_data = long_data, significance_labels = significance_labels)
}

📌Generate Boxplots for Cardiac Genes

for (gene in cardiac_genes) {
  data_info <- process_gene_data(gene)
  p <- ggplot(data_info$long_data, aes(x = Condition, y = log2CPM, fill = Drug)) +
    geom_boxplot(outlier.shape = NA) +
    scale_fill_manual(values = c("CX" = "#0000FF", "DOX" = "#e6d800", "VEH" = "#FF00FF")) +
    geom_point(aes(color = Indv), size = 2, alpha = 0.5, position = position_jitter(width = -1, height = 0)) +
    geom_text(data = data_info$significance_labels, aes(x = Condition, y = max_log2CPM + 0.5, label = Significance),
              inherit.aes = FALSE, size = 6, color = "black") +
    ggtitle(paste("Log2CPM Expression of", gene)) +
    labs(x = "Treatment", y = "log2CPM") +
    theme_bw() +
    theme(plot.title = element_text(size = rel(2), hjust = 0.5),
          axis.title = element_text(size = 15, color = "black"),
          axis.text.x = element_text(size = 10, color = "black", angle = 90, hjust = 1))
  
  print(p)
}

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

📌Generate Boxplots for TOP2 Genes

for (gene in top2_genes) {
  data_info <- process_gene_data(gene)
  p <- ggplot(data_info$long_data, aes(x = Condition, y = log2CPM, fill = Drug)) +
    geom_boxplot(outlier.shape = NA) +
    scale_fill_manual(values = c("CX" = "#0000FF", "DOX" = "#e6d800", "VEH" = "#FF00FF")) +
    geom_point(aes(color = Indv), size = 2, alpha = 0.5, position = position_jitter(width = -1, height = 0)) +
    geom_text(data = data_info$significance_labels, aes(x = Condition, y = max_log2CPM + 0.5, label = Significance),
              inherit.aes = FALSE, size = 6, color = "black") +
    ggtitle(paste("Log2CPM Expression of", gene)) +
    labs(x = "Treatment", y = "log2CPM") +
    theme_bw() +
    theme(plot.title = element_text(size = rel(2), hjust = 0.5),
          axis.title = element_text(size = 15, color = "black"),
          axis.text.x = element_text(size = 10, color = "black", angle = 90, hjust = 1))
  
  print(p)
}

Version Author Date
72599ac sayanpaul01 2025-02-09
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

Version Author Date
72599ac sayanpaul01 2025-02-09
a41bd50 sayanpaul01 2025-02-09
8c1912f sayanpaul01 2025-02-09

sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tidyr_1.3.1     dplyr_1.1.4     ggplot2_3.5.1   workflowr_1.7.1

loaded via a namespace (and not attached):
 [1] gtable_0.3.6      jsonlite_1.8.9    compiler_4.3.0    promises_1.3.0   
 [5] tidyselect_1.2.1  Rcpp_1.0.12       stringr_1.5.1     git2r_0.35.0     
 [9] callr_3.7.6       later_1.3.2       jquerylib_0.1.4   scales_1.3.0     
[13] yaml_2.3.10       fastmap_1.1.1     R6_2.5.1          labeling_0.4.3   
[17] generics_0.1.3    knitr_1.49        tibble_3.2.1      munsell_0.5.1    
[21] rprojroot_2.0.4   bslib_0.8.0       pillar_1.10.1     rlang_1.1.3      
[25] cachem_1.0.8      stringi_1.8.3     httpuv_1.6.15     xfun_0.50        
[29] getPass_0.2-4     fs_1.6.3          sass_0.4.9        cli_3.6.1        
[33] withr_3.0.2       magrittr_2.0.3    ps_1.8.1          digest_0.6.34    
[37] grid_4.3.0        processx_3.8.5    rstudioapi_0.17.1 lifecycle_1.0.4  
[41] vctrs_0.6.5       evaluate_1.0.3    glue_1.7.0        farver_2.1.2     
[45] whisker_0.4.1     colorspace_2.1-0  purrr_1.0.2       rmarkdown_2.29   
[49] httr_1.4.7        tools_4.3.0       pkgconfig_2.0.3   htmltools_0.5.8.1