install.packages('gt')
install.packages("gt")
library(readxls)
library(readr)
library(readxl)
pkgs <- c("backports","tidyverse","here","skimr","dplyr", "ggplot2", "ggsci","ggforce",
"janitor","readxl","xlsx", "MetBrewer","ggrepel", "usethis", "ggpubr")
lapply(pkgs, library, character.only = TRUE)
central_mod_4models <- read.table(here("data","epinanoRMS","data_processed","central_mod_d_per_pos_4_models.txt"))
t <- theme(
legend.title = element_blank(),
legend.text = element_text( size = 15),
legend.position = "none",
axis.text = element_text(size=15),
axis.title=element_text(size=15),
axis.text.x = element_text(angle = 35, hjust = 1),
panel.grid.major.y = element_line(color = "grey70"),
panel.grid.minor.y = element_line(color = "grey80"),
panel.grid.major.x = element_line(color = "grey70"),
panel.grid.minor.x = element_line(color = "grey80"),
panel.border = element_rect(colour = "black", fill = NA),
strip.text.x = element_text(size = 15, face = "bold")
)
bp_DRACH <- function(df,index,col,zoom){
for (i in 1:length(index)){
ggbarplot(df, x = "base", y = index[[i]][1], fill = "model",
add = c("mean_se","point"), position = position_dodge()) +
labs(x="",y=expression(Delta*"SumErr")) +
scale_y_continuous(expand = c(0.01,0.01)) +
# Zoom in
coord_cartesian(ylim = c(index[[i]][3][[1]][1],index[[i]][3][[1]][2])) +
t +
scale_fill_manual(values = col) +
theme(legend.position = "right")
ggsave(filename = paste0(index[[i]][1],"_DRACH.pdf"),
plot = last_plot(),
path = index[[i]][2],
width = 20,
height = 6,
units = "in")
}
}
index_3mod <- list(list("d_SumErr_5mer", here("results_Gregor","plots","epinanoRMS","per_kmer","barplots_DRACH","3_models"),c(NULL,NULL)),
list("d_SumErr_pos_0", here("results_Gregor","plots","epinanoRMS","per_kmer","barplots_DRACH","3_models"),c(0,.8)))
col_3model <- c('#E64B35FF',"#00A087FF",'#4DBBD5FF')
index_4mod <- list(c("d_SumErr_5mer", here("results_Gregor","plots","epinanoRMS","per_kmer","barplots_DRACH", "4_models")),
c("d_SumErr_pos_0", here("results_Gregor","plots","epinanoRMS","per_kmer","barplots_DRACH", "4_models")))
col_4model <- c('#E64B35FF','#4DBBD5FF',"#00A087FF","#3C5488FF")
bp_DRACH(df = m6A_df_3models, index = index_3mod, col = col_3model)
bp_DRACH(df = m6A_df_4models, index = index_4mod, col = col_4model)
central_mod_4models <- read.table(here("data","epinanoRMS","data_processed","central_mod_d_per_pos_4_models.txt"))
pkgs <- c("backports","tidyverse","here","skimr","dplyr", "ggplot2", "ggsci","ggforce",
"janitor","readxl","xlsx", "MetBrewer","ggrepel", "usethis", "ggpubr", "rstatix")
lapply(pkgs, library, character.only = TRUE)
central_mod_3models <- read.table(here("data","epinanoRMS","data_processed","central_mod_d_per_pos_3_models.txt"))
central_mod_3models$modification <- factor(central_mod_3models$modification, levels = c("UNM","m6A","m5C","hm5C","ac4C","Y","m1Y","m5U"))
central_mod_3models$model <- factor(central_mod_3models$model, levels = c("default","ivt+default", "sup"))
filter_fun <- function(df){
temp_df <- df
temp_df <- df %>%
# Filter for modified central bases for each modification
filter(modification == "m6A" &
model %in% c("default","ivt+default")) %>%
# group-by X.Ref,base,model,ref_pos
group_by(X.Ref,base,ref_pos) %>%
# Calculate double-delta per position and generate per 5mer value
mutate(dd_SumErr_pos_minus_2 = d_SumErr_pos_minus_2 - d_SumErr_pos_minus_2[model == "default" ],
dd_SumErr_pos_minus_1 = d_SumErr_pos_minus_1 - d_SumErr_pos_minus_1[model == "default" ],
dd_SumErr_pos_0 = d_SumErr_pos_0 - d_SumErr_pos_0[model == "default" ],
dd_SumErr_pos_plus_1 = d_SumErr_pos_plus_1 - d_SumErr_pos_plus_1[model == "default" ],
dd_SumErr_pos_plus_2 = d_SumErr_pos_plus_2 - d_SumErr_pos_plus_2[model == "default" ]) %>%
mutate(dd_SumErr = rowSums(cbind(as.numeric(dd_SumErr_pos_minus_2), as.numeric(dd_SumErr_pos_minus_1), as.numeric(dd_SumErr_pos_0), as.numeric(dd_SumErr_pos_plus_1), as.numeric(dd_SumErr_pos_plus_2)))) %>%
# Filer for only ivt+default as this contains relevant dd values also reduced runtime on case_when
filter(model == "ivt+default") %>%
# Annotate DRACH_motifs
mutate(is_DRACH = case_when(
# Non-DRACH Single A
str_detect(base, "^[GT][G][A][C][CT]$") == F ~ "other",
# Single A DRACH
str_detect(base, "^[GT][G][A][C][CT]$") == T ~ "DRACH",
)) %>%
# Remove everything with more than one A
filter(str_detect(base, "^[GTC][GTC][A][GTC][GTC]$"))
}
plot_frame_dd <- filter_fun(central_mod_3models)
central_mod_3models <- read.table(here("data","epinanoRMS","data_processed","central_mod_d_per_pos_3_models.txt"))
