comparison visualize_pore_diameter_aqp.R @ 2:c574ada16e76 draft

"planemo upload for repository https://github.com/mesocentre-clermont-auvergne/aubi_piaf commit 48a10de1b21f94ab8019d9d0e4a43e0bd9d0c31e-dirty"
author agpetit
date Wed, 25 May 2022 09:42:17 +0000
parents
children e5cf7698a2af
comparison
equal deleted inserted replaced
1:658c6ec58e91 2:c574ada16e76
1 #!/usr/bin/env Rscript
2
3 # install and/or load necessary packages
4 useful_packages <- c("conflicted", "getopt", "tidyverse", "ggplot2", "ggpubr")
5 uninstalled_packages <- setdiff(useful_packages, rownames(installed.packages()))
6 invisible(lapply(useful_packages, require, character.only = TRUE, warn.conflicts = TRUE, quietly = TRUE))
7
8 spec <- matrix(c(
9 "input_file", "i", 1, "character",
10 "aqp_distribution", "a", 2, "logical",
11 "protomer_distribution", "p", 2, "logical",
12 "all_distribution", "d", 2, "logical",
13 "pdf", "f", 2, "logical"
14 ), byrow = TRUE, ncol = 4)
15 opt <- getopt(spec)
16
17 if (is.null(opt$input_file)) {
18 print("A file containing an array must be given as input with the -f argument")
19 quit(status = 1)
20 }
21
22 if (is.null(opt$aqp_distribution)) {
23 opt$aqp_distribution <- TRUE
24 }
25
26 if (is.null(opt$protomer_distribution)) {
27 opt$protomer_distribution <- TRUE
28 }
29
30 if (is.null(opt$all_distribution)) {
31 opt$all_distribution <- TRUE
32 }
33
34 if (is.null(opt$pdf)) {
35 opt$pdf <- TRUE
36 }
37
38 tibble_sort <- read.delim(opt$input_file)
39 tibble_sort <- as_tibble(tibble_sort)
40 colnames(tibble_sort) <- colnames(tibble_sort) %>%
41 as_tibble() %>%
42 mutate(value = str_replace_all(value, "\\.", "_"), value = gsub("_+Angstroms_", "", value), value = str_replace(value, "Time__ps_", "time"), value = str_replace(value, "_", "."), value = str_replace(value, "_", ".")) %>%
43 unlist()
44 tibble_sort$time <- as.numeric(gsub("-[0-9]+.[0-9]+", "", tibble_sort$time))
45
46 tibble_sort_mean <- tibble_sort[, 1:9]
47 tibble_sort_std <- tibble_sort[, c(1, 10:17)]
48 colnames(tibble_sort_mean) <- gsub("_mean", "", colnames(tibble_sort_mean))
49 colnames(tibble_sort_std) <- gsub("_std", "", colnames(tibble_sort_std))
50
51 tibble_sort_mean_long <- tibble_sort_mean %>%
52 pivot_longer(cols = contains("AQP"), values_to = "distance") %>%
53 separate(name, into = c("aqp", "protomer", "Couple"), sep = "[.]") %>%
54 mutate(protomer = str_replace(protomer, "P", "Protomer "))
55
56 tibble_sort_std_long <- tibble_sort_std %>%
57 pivot_longer(cols = contains("AQP"), values_to = "distance") %>%
58 separate(name, into = c("aqp", "protomer", "Couple"), sep = "[.]") %>%
59 mutate(protomer = str_replace(protomer, "P", "Protomer "))
60
61 create_ggplot <- function(tibble_mean, tibble_std, group, color, wrap, title) {
62 tibble_mean_distance <- tibble_mean %>%
63 group_by_at(group) %>%
64 summarise(mean_distance = (mean(distance)))
65 tibble_std_distance <- tibble_std %>%
66 group_by_at(group) %>%
67 summarise(std_distance = (mean(distance)))
68 tibble_mean_std_distance <- inner_join(tibble_mean_distance, tibble_std_distance, by = group)
69 g_distribution <- ggplot(tibble_mean_std_distance, aes(x = time / 1000, y = mean_distance)) +
70 geom_line(aes(color = .data[[color]])) +
71 geom_ribbon(aes(ymin = mean_distance - std_distance, ymax = mean_distance
72 + std_distance, fill = .data[[color]]), alpha = 0.3) +
73 facet_wrap(wrap) + theme(legend.position = "top") + guides(color = "none", fill = "none") +
74 ggtitle(label = title, subtitle = "The envelope represents the standard deviation") +
75 ylab(label = "ArR-ArR distance (Ångströms)") + xlab(label = "Time (ns)")
76 return(g_distribution)
77 }
78
79 list_ggplot <- list()
80
81 if (opt$aqp_distribution == TRUE) {
82 group_aqp <- c("time", "aqp")
83 color_aqp <- "aqp"
84 wrap_aqp <- c("aqp")
85 title_aqp <- "Average distance ArR-ArR by AQP (4 protomers)"
86 g_aqp_distribution <- create_ggplot(tibble_sort_mean_long, tibble_sort_std_long, group_aqp, color_aqp, wrap_aqp, title_aqp)
87 ggsave("Distance_distribution_by_aquaporin.png", g_aqp_distribution, width = 20, height = 18, units = "cm")
88 list_ggplot[[1]] <- g_aqp_distribution
89 }
90
91 if (opt$protomer_distribution == TRUE) {
92 group_protomer <- c("time", "protomer")
93 color_protomer <- "protomer"
94 wrap_protomer <- c("protomer")
95 title_protomer <- "Average distance ArR-ArR by by protomer (2 aquaporins)"
96 g_protomer_distribution <- create_ggplot(tibble_sort_mean_long, tibble_sort_std_long, group_protomer, color_protomer, wrap_protomer, title_protomer)
97 ggsave("Distance_distribution_by_protomer.png", g_protomer_distribution, width = 20, height = 18, units = "cm")
98 list_ggplot[[2]] <- g_protomer_distribution
99 }
100
101 if (opt$all_distribution == TRUE) {
102 group_all <- c("time", "aqp", "protomer")
103 color_all <- "protomer"
104 wrap_all <- c("aqp", "protomer")
105 title_all <- "Average distance ArR-ArR by protomer anq AQP"
106 g_all_distribution <- create_ggplot(tibble_sort_mean_long, tibble_sort_std_long, group_all, color_all, wrap_all, title_all)
107 ggsave("Distance_distribution_on_all_protomers.png", g_all_distribution, width = 20, height = 18, units = "cm")
108 list_ggplot[[3]] <- g_all_distribution
109 }
110
111 if (opt$pdf == TRUE) {
112 ggexport(list_ggplot, filename = "all_graphics_distribution.pdf")
113 }