Last updated: 2025-09-03

Checks: 7 0

Knit directory: DXR_continue/

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(20250701) 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 c572b2b. 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:    .Rproj.user/
    Ignored:    analysis/figure/
    Ignored:    data/Cormotif_data/
    Ignored:    data/DER_data/
    Ignored:    data/alignment_summary.txt
    Ignored:    data/all_peak_final_dataframe.txt
    Ignored:    data/cell_line_info_.tsv
    Ignored:    data/full_summary_QC_metrics.txt
    Ignored:    data/motif_lists/
    Ignored:    data/number_frag_peaks_summary.txt

Untracked files:
    Untracked:  analysis/proteomics.Rmd
    Untracked:  code/corMotifcustom.R
    Untracked:  code/making_analysis_file_summary.R

Unstaged changes:
    Modified:   analysis/Cormotif_analysis.Rmd
    Modified:   analysis/Cormotif_outlier_removal.Rmd
    Modified:   analysis/multiQC_cut_tag.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/Motif_cluster_analysis.Rmd) and HTML (docs/Motif_cluster_analysis.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 c572b2b reneeisnowhere 2025-09-03 wflow_publish("analysis/Motif_cluster_analysis.Rmd")

library(tidyverse)
library(readr)
library(edgeR)
library(ComplexHeatmap)
library(data.table)
library(dplyr)
library(stringr)
library(ggplot2)
library(viridis)
library(DT)
library(kableExtra)
library(genomation)
library(GenomicRanges)
library(ggpubr) ## For customizing figures
library(corrplot) ## For correlation plot
library(ggpmisc)
library(gcplyr)
library(Rsubread)
library(limma)
library(ggrastr)
library(cowplot)
library(smplot2)
library(ggVennDiagram)
library(ggsignif)
library(BiocParallel)
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(ChIPseeker)
# sampleinfo <- read_delim("data/sample_info.tsv", delim = "\t")
H3K27ac_set1 <- read_delim("data/motif_lists/H3K27ac_set1.txt",delim="\t")
H3K27ac_set2 <- read_delim("data/motif_lists/H3K27ac_set2.txt",delim="\t")
H3K27ac_set3 <- read_delim("data/motif_lists/H3K27ac_set3.txt",delim="\t")

H3K27me3_set1 <- read_delim("data/motif_lists/H3K27me3_set1.txt",delim="\t")
H3K27me3_set2 <- read_delim("data/motif_lists/H3K27me3_set2.txt",delim="\t")

H3K36me3_set1 <- read_delim("data/motif_lists/H3K36me3_set1.txt",delim="\t")
H3K36me3_set2 <- read_delim("data/motif_lists/H3K36me3_set2.txt",delim="\t")

H3K9me3_set1 <- read_delim("data/motif_lists/H3K9me3_set1.txt",delim="\t")
H3K9me3_set2 <- read_delim("data/motif_lists/H3K9me3_set2.txt",delim="\t")
H3K9me3_set3 <- read_delim("data/motif_lists/H3K9me3_set3.txt",delim="\t")

### loading filtered raw counts for visualization
H3K27ac_filt_raw_counts <- read_delim("data/DER_data/H3K27ac_filtered_raw_counts.txt",delim = "\t") %>% column_to_rownames("Peakid")
H3K27me3_filt_raw_counts <- read_delim("data/DER_data/H3K27me3_filtered_raw_counts.txt",delim = "\t")%>% column_to_rownames("Peakid")

H3K36me3_filt_raw_counts <- read_delim("data/DER_data/H3K36me3_filtered_raw_counts.txt",delim = "\t")%>% column_to_rownames("Peakid")
H3K9me3_filt_raw_counts <- read_delim( "data/DER_data/H3K9me3_filtered_raw_counts.txt",delim = "\t")%>% column_to_rownames("Peakid")

all_H3K27ac_regions <- H3K27ac_filt_raw_counts %>% rownames_to_column("Peakid") %>% distinct(Peakid)
all_H3K27me3_regions <- H3K27me3_filt_raw_counts %>% rownames_to_column("Peakid") %>% distinct(Peakid)
all_H3K36me3_regions <- H3K36me3_filt_raw_counts %>% rownames_to_column("Peakid") %>% distinct(Peakid)
all_H3K9me3_regions <- H3K9me3_filt_raw_counts %>% rownames_to_column("Peakid") %>% distinct(Peakid)

H3K27ac_filt_lcpm <- cpm(H3K27ac_filt_raw_counts, log = TRUE)
H3K27me3_filt_lcpm <- cpm(H3K27me3_filt_raw_counts, log = TRUE)
H3K36me3_filt_lcpm <- cpm(H3K36me3_filt_raw_counts, log = TRUE)
H3K9me3_filt_lcpm <- cpm(H3K9me3_filt_raw_counts, log = TRUE)

H3K9me3_toplist <- readRDS( "data/DER_data/H3K9me3_toplist_nooutlier.RDS")
H3K36me3_toplist <- readRDS( "data/DER_data/H3K36me3_toplist_nooutlier.RDS")
H3K27me3_toplist <- readRDS( "data/DER_data/H3K27me3_toplist.RDS")
H3K27ac_toplist <- readRDS( "data/DER_data/H3K27ac_toplist.RDS")

H3K27ac_toptable_list <- bind_rows(H3K27ac_toplist, .id = "group")
H3K27me3_toptable_list <- bind_rows(H3K27me3_toplist, .id = "group")
H3K36me3_toptable_list <- bind_rows(H3K36me3_toplist, .id = "group")
H3K9me3_toptable_list <- bind_rows(H3K9me3_toplist, .id = "group")

H3K27ac motifs samples

Set 1

examp_H3K27ac_1 <-#slice_sample(H3K27ac_set1,n = 3, replace=FALSE)
    c("chr1:77923740-77924468","chr20:25484622-25485357","chr1:229148017-229149226")
examp_H3K27ac_2 <-#slice_sample(H3K27ac_set2,n = 3, replace=FALSE)
  c("chr5:85451856-85453893","chr10:114271262-114272616", "chr3:63343167-63344341" )
examp_H3K27ac_3 <- #slice_sample(H3K27ac_set3,n = 3, replace=FALSE)
  c("chr8:8664034-8666371","chr3:141152796-141154087","chr21:43701994-43704465")


H3K27ac_filt_lcpm %>% 
  as.data.frame() %>% 
   rownames_to_column("Peakid") %>%
  dplyr::filter(Peakid %in% examp_H3K27ac_1) %>% 
  ###pivot and add additional information from dataframe
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K27ac_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 1 H3K27ac samples")

Set 2

H3K27ac_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K27ac_filt_lcpm) %in% examp_H3K27ac_2) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K27ac_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 2 H3K27ac samples")

Set 3

H3K27ac_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K27ac_filt_lcpm) %in% examp_H3K27ac_3) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K27ac_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 3 H3K27ac samples")

Genomic regions

txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene

all_H3K27ac_regions_gr <- all_H3K27ac_regions %>% 
    tidyr::separate(., col = "Peakid", into=c("seqnames","range"), sep = ":", remove=FALSE) %>%
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>%
  GRanges()


H3K27ac_set1_gr <- H3K27ac_set1 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>%
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>%
  dplyr::rename("Peakid"=".") %>%
  GRanges()

H3K27ac_set2_gr <- H3K27ac_set2 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()

H3K27ac_set3_gr <- H3K27ac_set3 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()
H3K27ac_list <- list("Set_1"=H3K27ac_set1_gr,"Set_2"=H3K27ac_set2_gr,"Set_3"=H3K27ac_set3_gr,"all_H3K27ac"=all_H3K27ac_regions_gr)


# peakAnnoList_H3K27ac <- lapply(H3K27ac_list, annotatePeak, tssRegion =c(-2000,2000), TxDb=txdb)

# saveRDS(peakAnnoList_H3K27ac, "data/motif_lists/H3K27ac_annotated_peaks.RDS")
peakAnnoList_H3K27ac <- readRDS("data/motif_lists/H3K27ac_annotated_peaks.RDS")

plotAnnoBar(peakAnnoList_H3K27ac[c(4,1,2,3)])+
  ggtitle("H3K27ac Feature Distribution")

# pie_plots_H3K27ac <-   map(peakAnnoList_H3K27ac, ~ plotAnnoPie(.x))
for(nm in names(peakAnnoList_H3K27ac)) {
  plotAnnoPie(peakAnnoList_H3K27ac[[nm]])
  title(main = nm)  # base R title
}

LFC H3K27ac

Set1

# H3K27ac_toptable_list %>%
#   dplyr::filter(genes %in% H3K27ac_set1$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
#                                  c("H3K27ac_24T","H3K27ac_24R"),
#                                  c("H3K27ac_24R", "H3K27ac_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K27ac set1")


H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
                                 c("H3K27ac_24T","H3K27ac_24R"),
                                 c("H3K27ac_24R", "H3K27ac_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K27ac set1")

  set1_27ac <- H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set1=median(logFC),.groups="drop")

set2

# H3K27ac_toptable_list %>%
#   dplyr::filter(genes %in% H3K27ac_set2$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
#                                  c("H3K27ac_24T","H3K27ac_24R"),
#                                  c("H3K27ac_24R", "H3K27ac_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K27ac set2")


H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
                                 c("H3K27ac_24T","H3K27ac_24R"),
                                 c("H3K27ac_24R", "H3K27ac_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K27ac set2")

  set2_27ac <- H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set2=median(logFC),.groups="drop")

set3

# H3K27ac_toptable_list %>%
#   dplyr::filter(genes %in% H3K27ac_set3$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
#                                  c("H3K27ac_24T","H3K27ac_24R"),
#                                  c("H3K27ac_24R", "H3K27ac_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K27ac set3")


H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set3$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K27ac_24T", "H3K27ac_144R"),
                                 c("H3K27ac_24T","H3K27ac_24R"),
                                 c("H3K27ac_24R", "H3K27ac_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K27ac set3")

  H3K27ac_toptable_list %>%
  dplyr::filter(genes %in% H3K27ac_set3$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27ac_24T","H3K27ac_24R","H3K27ac_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set3=median(logFC),.groups="drop") %>% 
  left_join(set1_27ac, by="group") %>% 
  left_join(set2_27ac, by="group") %>% 
  pivot_longer(cols=!group, values_to = "median_LFC", names_to = "set") %>% 
  ggplot(., aes(x=group, y=median_LFC, group=set, color=set))+
  geom_point()+
  geom_line(aes(alpha = 0.3))+
  theme_bw()+
  ggtitle("LFC across time for H3K27ac sets")

Toptable top 100

This is the calculation of Top 100 in each category, then united

Sets_H3K27ac <- H3K27ac_toptable_list %>% 
  mutate(cluster=case_when(genes %in% H3K27ac_set1$. ~ "Set1",
                           genes %in% H3K27ac_set2$. ~ "Set2",
                           genes %in% H3K27ac_set3$. ~ "Set3",
                           TRUE ~ "not_assigned"))
Sets_H3K27ac %>% 
  dplyr::filter(cluster != "not_assigned") %>% 
  group_by(group) %>% 
  slice_min(.,order_by=adj.P.Val,n = 100) %>% 
  ungroup() %>% 
  group_by(cluster) %>% tally()
  


H3K27ac_toptable_list %>% 
  group_by(group) %>% 
  slice_min(.,order_by=adj.P.Val,n = 100) %>% 
  ungroup() %>% 
  distinct(genes)


### Emma's way

Sets_H3K27ac %>% 
  dplyr::filter(cluster != "not_assigned") %>%
  group_by(group, genes) %>% 
  summarise("min.adj.P"= min(adj.P.Val), .groups="drop", cluster=unique(cluster)) %>% 
  arrange(cluster, min.adj.P) %>%
  group_by(cluster) %>%
  slice_head(n = 100) %>% 
  distinct (genes)

H3K27me3 motifs samples

Set 1

# slice_sample(H3K27me3_set2,n = 3, replace=FALSE)
examp_H3K27me3_1 <-#slice_sample(H3K27me3_set1,n = 3, replace=FALSE)
  c("chr17:8878023-8878923", "chr2:23436468-23436797","chr10:132830096-132830712")
examp_H3K27me3_2 <-#slice_sample(H3K27me3_set2,n = 3, replace=FALSE)
  c("chr5:141004122-141004627" ,  "chr6:101195726-101195968",  "chr3:139117155-139117784")



H3K27me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K27me3_filt_lcpm) %in% examp_H3K27me3_1) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K27me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 1 H3K27me3 samples")

Set 2

H3K27me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K27me3_filt_lcpm) %in% examp_H3K27me3_2) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K27me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 2 H3K27me3 samples")

all_H3K27me3_regions_gr <- all_H3K27ac_regions %>% 
    tidyr::separate(., col = "Peakid", into=c("seqnames","range"), sep = ":", remove=FALSE) %>%
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>%
  GRanges()

H3K27me3_set1_gr <- H3K27me3_set1 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()

H3K27me3_set2_gr <- H3K27me3_set2 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()


H3K27me3_list <- list("Set_1"=H3K27me3_set1_gr,"Set_2"=H3K27me3_set2_gr,"all_H3K27me3_regions"=all_H3K27me3_regions_gr)


# peakAnnoList_H3K27me3 <- lapply(H3K27me3_list, annotatePeak, tssRegion =c(-2000,2000), TxDb=txdb)

# saveRDS(peakAnnoList_H3K27me3, "data/motif_lists/H3K27me3_annotated_peaks.RDS")
peakAnnoList_H3K27me3 <- readRDS("data/motif_lists/H3K27me3_annotated_peaks.RDS")

plotAnnoBar(peakAnnoList_H3K27me3[c(3,1,2)])+
  ggtitle("H3K27me3 Feature Distribution")

# pie_plots_H3K27me3 <-   map(peakAnnoList_H3K27me3, ~ plotAnnoPie(.x))
for(nm in names(peakAnnoList_H3K27me3)) {
  plotAnnoPie(peakAnnoList_H3K27me3[[nm]])
  title(main = nm)  # base R title
}

LFC H3K27me3

Set1

# H3K27me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K27me3_set1$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K27me3_24T", "H3K27me3_144R"),
#                                  c("H3K27me3_24T","H3K27me3_24R"),
#                                  c("H3K27me3_24R", "H3K27me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K27me3 set1")


H3K27me3_toptable_list %>%
  dplyr::filter(genes %in% H3K27me3_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K27me3_24T", "H3K27me3_144R"),
                                 c("H3K27me3_24T","H3K27me3_24R"),
                                 c("H3K27me3_24R", "H3K27me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K27me3 set1")

  set1_27me3 <- H3K27me3_toptable_list %>%
  dplyr::filter(genes %in% H3K27me3_set1$.) %>% 
   dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set1=median(logFC),.groups="drop")

set2

# H3K27me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K27me3_set2$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K27me3_24T", "H3K27me3_144R"),
#                                  c("H3K27me3_24T","H3K27me3_24R"),
#                                  c("H3K27me3_24R", "H3K27me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K27me3 set2")


H3K27me3_toptable_list %>%
  dplyr::filter(genes %in% H3K27me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K27me3_24T", "H3K27me3_144R"),
                                 c("H3K27me3_24T","H3K27me3_24R"),
                                 c("H3K27me3_24R", "H3K27me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K27me3 set2")

  H3K27me3_toptable_list %>%
  dplyr::filter(genes %in% H3K27me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K27me3_24T","H3K27me3_24R","H3K27me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set2=median(logFC),.groups="drop") %>% 
  left_join(set1_27me3,by = "group") %>% 
  pivot_longer(cols=!group, values_to = "median_LFC", names_to = "set") %>% 
  ggplot(., aes(x=group, y=median_LFC, group=set, color=set))+
  geom_point()+
  geom_line(aes(alpha = 0.3))+
  theme_bw()+
  ggtitle("LFC across time for H3K27me3 sets")

H3K36me3 motifs samples

Set 1

# slice_sample(H3K36me3_set1,n = 3, replace=FALSE)
examp_H3K36me3_1 <-#slice_sample(H3K36me3_set1,n = 3, replace=FALSE)
  c("chr6:106975625-106975872","chr17:17259340-17260414","chr14:91506581-91506995")
examp_H3K36me3_2 <-#slice_sample(H3K36me3_set2,n = 3, replace=FALSE)
  # c("chr2:191013033-191013351","chr5:66597066-66597500","chr16:22232346-22233214")
c("chr17:3656403-3665271","chr6:118573949-118574870","chr1:164799555-164800172")



H3K36me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K36me3_filt_lcpm) %in% examp_H3K36me3_1) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K36me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 1 H3K36me3 samples")

Set 2

H3K36me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K36me3_filt_lcpm) %in% examp_H3K36me3_2) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K36me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 2 H3K36me3 samples")

all_H3K36me3_regions_gr <- all_H3K36me3_regions %>% 
    tidyr::separate(., col = "Peakid", into=c("seqnames","range"), sep = ":", remove=FALSE) %>%
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>%
  GRanges()

H3K36me3_set1_gr <- H3K36me3_set1 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()

H3K36me3_set2_gr <- H3K36me3_set2 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()


H3K36me3_list <- list("Set_1"=H3K36me3_set1_gr,"Set_2"=H3K36me3_set2_gr, "all_H3K36me3_regions"=all_H3K36me3_regions_gr)


# peakAnnoList_H3K36me3 <- lapply(H3K36me3_list, annotatePeak, tssRegion =c(-2000,2000), TxDb=txdb)
# # 
# saveRDS(peakAnnoList_H3K36me3, "data/motif_lists/H3K36me3_annotated_peaks.RDS")
peakAnnoList_H3K36me3 <- readRDS("data/motif_lists/H3K36me3_annotated_peaks.RDS")

plotAnnoBar(peakAnnoList_H3K36me3[c(3,1,2)])+
  ggtitle("H3K36me3 Feature Distribution")

# pie_plots_H3K36me3 <-   map(peakAnnoList_H3K36me3, ~ plotAnnoPie(.x))
for(nm in names(peakAnnoList_H3K36me3)) {
  plotAnnoPie(peakAnnoList_H3K36me3[[nm]])
  title(main = nm)  # base R title
}

LFC H3K36me3

Set1

# H3K36me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K36me3_set1$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K36me3_24T", "H3K36me3_144R"),
#                                  c("H3K36me3_24T","H3K36me3_24R"),
#                                  c("H3K36me3_24R", "H3K36me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K36me3 set1")


H3K36me3_toptable_list %>%
  dplyr::filter(genes %in% H3K36me3_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K36me3_24T", "H3K36me3_144R"),
                                 c("H3K36me3_24T","H3K36me3_24R"),
                                 c("H3K36me3_24R", "H3K36me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K36me3 set1")

 set1_36me3 <- H3K36me3_toptable_list %>%
  dplyr::filter(genes %in% H3K36me3_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set1=median(logFC),.groups="drop") 

set2

# 
# H3K36me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K36me3_set2$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K36me3_24T", "H3K36me3_144R"),
#                                  c("H3K36me3_24T","H3K36me3_24R"),
#                                  c("H3K36me3_24R", "H3K36me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K36me3 set2")


H3K36me3_toptable_list %>%
  dplyr::filter(genes %in% H3K36me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K36me3_24T", "H3K36me3_144R"),
                                 c("H3K36me3_24T","H3K36me3_24R"),
                                 c("H3K36me3_24R", "H3K36me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K36me3 set2")

 H3K36me3_toptable_list %>%
  dplyr::filter(genes %in% H3K36me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K36me3_24T","H3K36me3_24R","H3K36me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set2=median(logFC),.groups="drop") %>% 
  left_join(set1_36me3,by = "group") %>% 
  pivot_longer(cols=!group, values_to = "median_LFC", names_to = "set") %>% 
  ggplot(., aes(x=group, y=median_LFC, group=set, color=set))+
  geom_point()+
  geom_line(aes(alpha = 0.3))+
  theme_bw()+
  ggtitle("LFC across time for H3K36me3 sets")

H3K9me3 motifs samples

Set 1

# slice_sample(H3K9me3_set3,n = 3, replace=FALSE)
examp_H3K9me3_1 <-#slice_sample(H3K9me3_set1,n = 3, replace=FALSE)
  c("chr7:101406339-101407813","chr6:147512995-147514238","chr10:66432792-66433011")
examp_H3K9me3_2 <-#slice_sample(H3K9me3_set2,n = 3, replace=FALSE)
  c("chr2:120985518-120985865" ,   "chr7:926998-927207","chr12:108895126-108895841")

examp_H3K9me3_3 <- #slice_sample(H3K9me3_set3,n = 3, replace=FALSE)
  c("chr6:44276324-44278629","chr7:906806-907939"  ,"chr20:63682374-63682947")



H3K9me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K9me3_filt_lcpm) %in% examp_H3K9me3_1) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K9me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 1 H3K9me3 samples")

Set 2

H3K9me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K9me3_filt_lcpm) %in% examp_H3K9me3_2) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K9me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 2 H3K9me3 samples")

Set 3

H3K9me3_filt_lcpm %>% 
  as.data.frame() %>% 
  dplyr::filter(row.names(H3K9me3_filt_lcpm) %in% examp_H3K9me3_3) %>% 
  ###pivot and add additional information from dataframe
  rownames_to_column("Peakid") %>% 
  pivot_longer(., cols = !Peakid, names_to = "sample", values_to = "lcpm" ) %>% 
  separate_wider_delim(., cols=sample, delim="_", names=c("ind","tx","time")) %>% 
  mutate(ind=factor(ind, levels=c("Ind1", "Ind2", "Ind3", "Ind4","Ind5")),
         tx=factor(tx,levels = c("DOX","VEH")),
         time=factor(time, levels=c("24T","24R","144R")),
         group_graph= paste0(tx, "_", time),
         group=paste0("H3K9me3_",time),
      group_graph = factor(group_graph, levels = c(
        "DOX_24T",  "VEH_24T",
        "DOX_24R",  "VEH_24R",
        "DOX_144R",  "VEH_144R"))) %>% 
  
  ggplot(., aes(x=group_graph, y=lcpm)) +
  geom_boxplot(aes(fill=tx))+
  facet_wrap(~Peakid, scales="free")+
  theme_bw()+
  theme(axis.text.x=element_text(angle = 90))+
  ggtitle("set 3 H3K9me3 samples")

all_H3K9me3_regions_gr <- all_H3K9me3_regions %>% 
    tidyr::separate(., col = "Peakid", into=c("seqnames","range"), sep = ":", remove=FALSE) %>%
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>%
  GRanges()


H3K9me3_set1_gr <- H3K9me3_set1 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()

H3K9me3_set2_gr <- H3K9me3_set2 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()

H3K9me3_set3_gr <- H3K9me3_set3 %>% 
  tidyr::separate(., col = ".", into=c("seqnames","range"), sep = ":", remove=FALSE) %>% 
  tidyr::separate(., col = "range", into=c("start","end"), sep = "-") %>% 
  dplyr::rename("Peakid"=".") %>% 
  GRanges()
H3K9me3_list <- list("Set_1"=H3K9me3_set1_gr,"Set_2"=H3K9me3_set2_gr,"Set_3"=H3K9me3_set3_gr,"all_H3K9me3_regions"=all_H3K9me3_regions_gr)


# peakAnnoList_H3K9me3 <- lapply(H3K9me3_list, annotatePeak, tssRegion =c(-2000,2000), TxDb=txdb)
# # 
# saveRDS(peakAnnoList_H3K9me3, "data/motif_lists/H3K9me3_annotated_peaks.RDS")
peakAnnoList_H3K9me3 <- readRDS("data/motif_lists/H3K9me3_annotated_peaks.RDS")

plotAnnoBar(peakAnnoList_H3K9me3[c(4,1,2,3)])+
  ggtitle("H3K9me3 Feature Distribution")

# pie_plots_H3K9me3 <-   map(peakAnnoList_H3K9me3, ~ plotAnnoPie(.x))
for(nm in names(peakAnnoList_H3K9me3)) {
  plotAnnoPie(peakAnnoList_H3K9me3[[nm]])
  title(main = nm)  # base R title
}

LFC H3K9me3

Set1

# H3K9me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K9me3_set1$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
#                                  c("H3K9me3_24T","H3K9me3_24R"),
#                                  c("H3K9me3_24R", "H3K9me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K9me3 set1")


H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
                                 c("H3K9me3_24T","H3K9me3_24R"),
                                 c("H3K9me3_24R", "H3K9me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K9me3 set1")

  set1_9me3 <- H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set1$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set1=median(logFC),.groups="drop")

set2

# H3K9me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K9me3_set2$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
#                                  c("H3K9me3_24T","H3K9me3_24R"),
#                                  c("H3K9me3_24R", "H3K9me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K9me3 set2")


H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
                                 c("H3K9me3_24T","H3K9me3_24R"),
                                 c("H3K9me3_24R", "H3K9me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K9me3 set2")

  set2_9me3 <- H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set2$.) %>% 
  dplyr::select(group,genes,logFC) %>%
   mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set2=median(logFC),.groups="drop")

set3

# H3K9me3_toptable_list %>%
#   dplyr::filter(genes %in% H3K9me3_set3$.) %>% 
#   dplyr::select(group,genes,logFC) %>%
#   mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R"))) %>% 
#   ggplot(., aes(x=group, y=logFC))+
#   geom_boxplot(aes(fill=group))+
#   geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
#                                  c("H3K9me3_24T","H3K9me3_24R"),
#                                  c("H3K9me3_24R", "H3K9me3_144R")),
#                               step_increase = 0.1, 
#               map_signif_level = FALSE, 
#               test = "wilcox.test")+
#   theme_bw()+
#   ggtitle("LFC across time for H3K9me3 set3")


H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set3$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  ggplot(., aes(x=group, y=logFC))+
  geom_boxplot(aes(fill=group))+
  geom_signif(comparisons = list(c("H3K9me3_24T", "H3K9me3_144R"),
                                 c("H3K9me3_24T","H3K9me3_24R"),
                                 c("H3K9me3_24R", "H3K9me3_144R")),
                              step_increase = 0.1, 
              map_signif_level = FALSE, 
              test = "wilcox.test")+
  theme_bw()+
  ggtitle("Absolute LFC across time for H3K9me3 set3")

  H3K9me3_toptable_list %>%
  dplyr::filter(genes %in% H3K9me3_set3$.) %>% 
  dplyr::select(group,genes,logFC) %>%
  mutate(group=factor(group, levels = c("H3K9me3_24T","H3K9me3_24R","H3K9me3_144R")),
         logFC=abs(logFC)) %>% 
  group_by(group) %>% 
  summarize(med_Set3=median(logFC),.groups="drop") %>% 
  left_join(set1_9me3, by="group") %>% 
  left_join(set2_9me3, by="group") %>% 
  pivot_longer(cols=!group, values_to = "median_LFC", names_to = "set") %>% 
  ggplot(., aes(x=group, y=median_LFC, group=set, color=set))+
  geom_point()+
  geom_line(aes(alpha = 0.3))+
  theme_bw()+
  ggtitle("LFC across time for H3K9me3 sets")


sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
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] stats4    grid      stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] ChIPseeker_1.42.1                       
 [2] TxDb.Hsapiens.UCSC.hg38.knownGene_3.20.0
 [3] GenomicFeatures_1.58.0                  
 [4] AnnotationDbi_1.68.0                    
 [5] Biobase_2.66.0                          
 [6] BiocParallel_1.40.2                     
 [7] ggsignif_0.6.4                          
 [8] ggVennDiagram_1.5.4                     
 [9] smplot2_0.2.5                           
[10] cowplot_1.2.0                           
[11] ggrastr_1.0.2                           
[12] Rsubread_2.20.0                         
[13] gcplyr_1.12.0                           
[14] ggpmisc_0.6.2                           
[15] ggpp_0.5.9                              
[16] corrplot_0.95                           
[17] ggpubr_0.6.1                            
[18] GenomicRanges_1.58.0                    
[19] GenomeInfoDb_1.42.3                     
[20] IRanges_2.40.1                          
[21] S4Vectors_0.44.0                        
[22] BiocGenerics_0.52.0                     
[23] genomation_1.38.0                       
[24] kableExtra_1.4.0                        
[25] DT_0.33                                 
[26] viridis_0.6.5                           
[27] viridisLite_0.4.2                       
[28] data.table_1.17.8                       
[29] ComplexHeatmap_2.22.0                   
[30] edgeR_4.4.2                             
[31] limma_3.62.2                            
[32] lubridate_1.9.4                         
[33] forcats_1.0.0                           
[34] stringr_1.5.1                           
[35] dplyr_1.1.4                             
[36] purrr_1.1.0                             
[37] readr_2.1.5                             
[38] tidyr_1.3.1                             
[39] tibble_3.3.0                            
[40] ggplot2_3.5.2                           
[41] tidyverse_2.0.0                         
[42] workflowr_1.7.1                         

loaded via a namespace (and not attached):
  [1] fs_1.6.6                               
  [2] matrixStats_1.5.0                      
  [3] bitops_1.0-9                           
  [4] enrichplot_1.26.6                      
  [5] httr_1.4.7                             
  [6] RColorBrewer_1.1-3                     
  [7] doParallel_1.0.17                      
  [8] tools_4.4.2                            
  [9] backports_1.5.0                        
 [10] R6_2.6.1                               
 [11] lazyeval_0.2.2                         
 [12] GetoptLong_1.0.5                       
 [13] withr_3.0.2                            
 [14] gridExtra_2.3                          
 [15] quantreg_6.1                           
 [16] cli_3.6.5                              
 [17] textshaping_1.0.1                      
 [18] labeling_0.4.3                         
 [19] sass_0.4.10                            
 [20] Rsamtools_2.22.0                       
 [21] systemfonts_1.2.3                      
 [22] yulab.utils_0.2.1                      
 [23] foreign_0.8-90                         
 [24] DOSE_4.0.1                             
 [25] svglite_2.2.1                          
 [26] R.utils_2.13.0                         
 [27] dichromat_2.0-0.1                      
 [28] plotrix_3.8-4                          
 [29] BSgenome_1.74.0                        
 [30] pwr_1.3-0                              
 [31] rstudioapi_0.17.1                      
 [32] impute_1.80.0                          
 [33] RSQLite_2.4.3                          
 [34] generics_0.1.4                         
 [35] gridGraphics_0.5-1                     
 [36] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
 [37] shape_1.4.6.1                          
 [38] BiocIO_1.16.0                          
 [39] vroom_1.6.5                            
 [40] gtools_3.9.5                           
 [41] car_3.1-3                              
 [42] GO.db_3.20.0                           
 [43] Matrix_1.7-3                           
 [44] ggbeeswarm_0.7.2                       
 [45] abind_1.4-8                            
 [46] R.methodsS3_1.8.2                      
 [47] lifecycle_1.0.4                        
 [48] whisker_0.4.1                          
 [49] yaml_2.3.10                            
 [50] carData_3.0-5                          
 [51] SummarizedExperiment_1.36.0            
 [52] gplots_3.2.0                           
 [53] qvalue_2.38.0                          
 [54] SparseArray_1.6.2                      
 [55] blob_1.2.4                             
 [56] promises_1.3.3                         
 [57] crayon_1.5.3                           
 [58] ggtangle_0.0.7                         
 [59] lattice_0.22-7                         
 [60] KEGGREST_1.46.0                        
 [61] pillar_1.11.0                          
 [62] knitr_1.50                             
 [63] fgsea_1.32.4                           
 [64] rjson_0.2.23                           
 [65] boot_1.3-31                            
 [66] codetools_0.2-20                       
 [67] fastmatch_1.1-6                        
 [68] glue_1.8.0                             
 [69] getPass_0.2-4                          
 [70] ggfun_0.2.0                            
 [71] treeio_1.30.0                          
 [72] vctrs_0.6.5                            
 [73] png_0.1-8                              
 [74] gtable_0.3.6                           
 [75] cachem_1.1.0                           
 [76] xfun_0.52                              
 [77] S4Arrays_1.6.0                         
 [78] survival_3.8-3                         
 [79] iterators_1.0.14                       
 [80] statmod_1.5.0                          
 [81] nlme_3.1-168                           
 [82] ggtree_3.14.0                          
 [83] bit64_4.6.0-1                          
 [84] rprojroot_2.1.0                        
 [85] bslib_0.9.0                            
 [86] vipor_0.4.7                            
 [87] KernSmooth_2.23-26                     
 [88] rpart_4.1.24                           
 [89] colorspace_2.1-1                       
 [90] DBI_1.2.3                              
 [91] Hmisc_5.2-3                            
 [92] seqPattern_1.38.0                      
 [93] nnet_7.3-20                            
 [94] tidyselect_1.2.1                       
 [95] processx_3.8.6                         
 [96] bit_4.6.0                              
 [97] compiler_4.4.2                         
 [98] curl_7.0.0                             
 [99] git2r_0.36.2                           
[100] htmlTable_2.4.3                        
[101] SparseM_1.84-2                         
[102] xml2_1.4.0                             
[103] DelayedArray_0.32.0                    
[104] rtracklayer_1.66.0                     
[105] caTools_1.18.3                         
[106] checkmate_2.3.3                        
[107] scales_1.4.0                           
[108] callr_3.7.6                            
[109] rappdirs_0.3.3                         
[110] digest_0.6.37                          
[111] rmarkdown_2.29                         
[112] XVector_0.46.0                         
[113] htmltools_0.5.8.1                      
[114] pkgconfig_2.0.3                        
[115] base64enc_0.1-3                        
[116] MatrixGenerics_1.18.1                  
[117] fastmap_1.2.0                          
[118] rlang_1.1.6                            
[119] GlobalOptions_0.1.2                    
[120] htmlwidgets_1.6.4                      
[121] UCSC.utils_1.2.0                       
[122] farver_2.1.2                           
[123] jquerylib_0.1.4                        
[124] zoo_1.8-14                             
[125] jsonlite_2.0.0                         
[126] GOSemSim_2.32.0                        
[127] R.oo_1.27.1                            
[128] RCurl_1.98-1.17                        
[129] magrittr_2.0.3                         
[130] polynom_1.4-1                          
[131] Formula_1.2-5                          
[132] GenomeInfoDbData_1.2.13                
[133] ggplotify_0.1.2                        
[134] patchwork_1.3.1                        
[135] Rcpp_1.1.0                             
[136] ape_5.8-1                              
[137] stringi_1.8.7                          
[138] zlibbioc_1.52.0                        
[139] MASS_7.3-65                            
[140] plyr_1.8.9                             
[141] ggrepel_0.9.6                          
[142] parallel_4.4.2                         
[143] Biostrings_2.74.1                      
[144] splines_4.4.2                          
[145] hms_1.1.3                              
[146] circlize_0.4.16                        
[147] locfit_1.5-9.12                        
[148] ps_1.9.1                               
[149] igraph_2.1.4                           
[150] reshape2_1.4.4                         
[151] XML_3.99-0.18                          
[152] evaluate_1.0.4                         
[153] tzdb_0.5.0                             
[154] foreach_1.5.2                          
[155] httpuv_1.6.16                          
[156] MatrixModels_0.5-4                     
[157] clue_0.3-66                            
[158] gridBase_0.4-7                         
[159] broom_1.0.9                            
[160] restfulr_0.0.16                        
[161] tidytree_0.4.6                         
[162] rstatix_0.7.2                          
[163] later_1.4.2                            
[164] aplot_0.2.8                            
[165] memoise_2.0.1                          
[166] beeswarm_0.4.0                         
[167] GenomicAlignments_1.42.0               
[168] cluster_2.1.8.1                        
[169] timechange_0.3.0