-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDensity_plot.R
More file actions
72 lines (58 loc) · 2.65 KB
/
Copy pathDensity_plot.R
File metadata and controls
72 lines (58 loc) · 2.65 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
suppressMessages ({
library(tidyverse, verbose = F)
library(argparse, verbose = F)
#Read Args
parser <- ArgumentParser()
parser$add_argument("--input_table", help = "Main output of ProOvErlap")
parser$add_argument("--randomizations", help = "Tables_Intersect|Closest.txt")
parser$add_argument("--test", help = "intersect or closest", default = "intersect")
parser$add_argument("--outfile", help = "Name for output file, default: Plot", default = "Density_plot")
parser$add_argument("--format", help = "Format of plot file, default: png", default = "png")
parser$add_argument("--width", help = "4", default = "4", type="numeric")
parser$add_argument("--heigth", help = "3", default = "3", type="numeric")
args <- parser$parse_args()
try(if (!(args$test %in% c("intersect", "closest"))) stop("test argument should be intersect or closest"))
if (args$test == "intersect"){
Xlab = "Number of intersection"
}
if (args$test == "closest"){
Xlab = "Mean distance"
}
#Read files
randomizations <- read_delim(args$randomizations, col_names = T)
Results <- read_delim(args$input_table, col_names = T)
#Density plot function
makeDensityplot <- function(Zscore, Type, Pvalue, Real, Random, Name, Outfile, Format, width, heigth) {
#Select correct rows
random_df_name <- randomizations %>%
dplyr::filter(Target == !!Name & Name == !!Type & Type != "Real")
Random = mean(random_df_name$Count)
NPerm = nrow(random_df_name)
Plot <- random_df_name %>%
dplyr::rename("Simulated_overlaps" = "Count") %>%
ggplot() +
geom_density(aes(Simulated_overlaps,
after_stat(count)),
adjust = 2,
linewidth = 1) +
geom_vline(xintercept = Random,
colour = "black",
linewidth = 0.5,
linetype = "dashed") +
geom_vline(xintercept = Real,
colour = "#ef233c",
linetype = "dashed",
linewidth = 1) +
labs(x = NULL,
title = str_c(gsub("\\|\\|", " | ", Name)," | ",Type),
subtitle = str_c(
"Randomizations = ", NPerm,"\n",
"Z-score = ", round(Zscore, digits = 2),"\n",
"p-value = ", formatC(Pvalue, format = "e", digits = 2))) +
ylab("Density") +
xlab(Xlab) +
theme_bw(base_size = 10)
ggsave(plot = Plot, filename = str_c(Outfile,"_",Name,"_",Type,".",Format), dpi = 300, height = heigth, width = width)
}
apply(Results, 1, function(x) makeDensityplot(as.numeric(x["Zscore"]), x["Type"], as.numeric(x["P.value"]), as.numeric(x["Real"]), as.numeric(x["Random"]), x["Target"], args$outfile, args$format, args$width, args$heigth))
})