-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.R
More file actions
54 lines (43 loc) · 2.42 KB
/
test.R
File metadata and controls
54 lines (43 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(readr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(patchwork)
type_colours <- c("C>T" = "red", "G>A" = "blue", "A>C" = "grey", "A>G" = "grey", "A>T" = "grey", "C>A" = "grey", "C>G" = "grey", "G>C" = "grey", "G>T" = "grey", "T>A" = "grey", "T>C" = "grey", "T>G" = "grey", "insertion" = "grey", "deletion" = "grey")
raw_5p_single_stranded <- readr::read_tsv("assets/data/single-stranded/5p_freq_misincorporations.txt", comment = "#")
raw_3p_single_stranded <- readr::read_tsv("assets/data/single-stranded/3p_freq_misincorporations.txt", comment = "#")
pivot_longer_freqmisincorporation <- function(x, reverse, type_colours) {
result <- x %>%
dplyr::rename(insertion = `->ACGT`, deletion = `ACGT>-`, Position = Pos) %>%
tidyr::pivot_longer(tidyr::contains(c(">", "insertion", "deletion")), names_to = "Mutation Type", values_to = "Frequency") %>%
dplyr::mutate(`Mutation Type` = factor(`Mutation Type`, levels = rev(names(type_colours))))
if (reverse) {
result <- result %>%
dplyr::mutate(Position = Position * -1)
}
result
}
plot_longer_freqmisincorporation <- function(x, reverse, type_colours) {
result <- ggplot2::ggplot(x, aes(x = Position, y = Frequency, colour = `Mutation Type`)) +
ggplot2::geom_line() +
ggplot2::scale_colour_manual(values = type_colours, guide = ggplot2::guide_legend(reverse = TRUE)) +
ggplot2::facet_wrap(~end, ncol = 2) +
ggplot2::theme_classic() +
ggplot2::theme(legend.position = "none") +
ggplot2::coord_cartesian(ylim = c(0, 0.3))
if (reverse) {
result <- result +
ggplot2::scale_x_continuous(breaks = seq(0, -14, -1)) +
ggplot2::scale_y_continuous(breaks = seq(0, 0.30, 0.05), position = "right")
} else {
result <- result +
ggplot2::scale_x_continuous(breaks = seq(0, 14, 1)) +
ggplot2::scale_y_continuous(breaks = seq(0, 0.30, 0.05))
}
result
}
long_5p_single_stranded <- pivot_longer_freqmisincorporation(raw_5p_single_stranded, reverse = FALSE, type_colours = type_colours) %>% mutate(end = "5p")
long_3p_single_stranded <- pivot_longer_freqmisincorporation(raw_3p_single_stranded, reverse = TRUE, type_colours = type_colours) %>% mutate(end = "3p")
smiley_5p_single_stranded <- plot_longer_freqmisincorporation(long_5p_single_stranded, reverse = FALSE, type_colours)
smiley_3p_single_stranded <- plot_longer_freqmisincorporation(long_3p_single_stranded, reverse = TRUE, type_colours)
smiley_5p_single_stranded