-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot-bw-correlation.R
More file actions
executable file
·57 lines (50 loc) · 2.06 KB
/
Copy pathplot-bw-correlation.R
File metadata and controls
executable file
·57 lines (50 loc) · 2.06 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
#!/usr/bin/env Rscript
# Parsing command line arguments and create output subdirectories# {{{
# Make library loading silent
library = function (...) suppressMessages(base::library(...))
library(argparse)
library(tools)
parser = ArgumentParser(description="Get exons, introns, intergenic for given annotation")
parser$add_argument('-s', '--sample', metavar= "file", required='True', type= "character",
help= ".sample-correlation file generated in ChIP Makefile with bigWigCorrelate")
args = parser$parse_args()
# }}}
library(dplyr)
library(corrplot)
lines = readLines(args$sample)
files = lines[seq(1,length(lines),2)]
files = as.data.frame(files) %>% tidyr::separate(files, into = c('file_1', 'file_2'), sep=" ") %>%
dplyr::mutate(file_1 = basename(file_1),
file_2 = basename(file_2))
files$corr = lines[seq(2,length(lines),2)]
len = length(unique(c(files[[1]], files[[2]])))
mat = matrix(nrow = len, ncol = len)
colnames(mat) = rownames(mat) = unique(c(files[[1]], files[[2]]))
head(mat)
for(i in colnames(mat)){
for(j in rownames(mat)){
if(i==j){
tmp = 1
} else{
tmp = files %>% filter((file_1 == i & file_2 == j) | (file_1 == j & file_2 == i)) %>%
dplyr::select(corr) %>% .[[1]] %>% as.numeric()
if(length(tmp) != 1){
print('Comparison found more than one time. Ensuring value is the same.')
if(length(unique(tmp)) !=1) stop('Same comparisons do not give the same value.')
tmp = unique(tmp)
}
}
mat[j,i] = tmp
}
}
col = rev(c("#67001F", "#B2182B", "#D6604D",
"#F4A582", "#FDDBC7","#FFFFFF",
"#D1E5F0", "#92C5DE", "#4393C3",
"#2166AC", "#053061"))
pdf(gsub(".sample-correlation", ".pdf", args$sample))
corrplot(mat, method="color", type="lower",
order="hclust", tl.col="black", tl.cex=1,
tl.srt=90, number.digits = 2, number.cex = 0.5, cl.cex = 1,
addCoef.col="grey",
addrect=4, col=colorRampPalette(col)(200))
dev.off()