forked from yal054/snATAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snATAC.plotH.R
73 lines (56 loc) · 1.79 KB
/
snATAC.plotH.R
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
#!/usr/bin/env Rscript
# read results from ksklearn
suppressPackageStartupMessages(library("argparse"))
# create parser object
parser <- ArgumentParser()
# specify our desired options
# by default ArgumentParser will add an help option
parser$add_argument("-i", "--input", required=TRUE, help="input matrix")
parser$add_argument("-o", "--output", required=TRUE, help="output file prefix")
# get command line options, if help option encountered print help and exit,
# otherwise if options not found on command line then set defaults,
args <- parser$parse_args()
library(data.table)
dataH <- fread(args$input,sep="\t")
library(pheatmap)
library(RColorBrewer)
library(viridis)
library(dendsort)
# scale by column
#mx <- apply(dataH,2,scale)
normUnity <- function(x){
sum <- sum(x)
out <- x / sum(x)
}
mx <- apply(dataH,2,normUnity)
sort_hclust <- function(...) as.hclust(dendsort(as.dendrogram(...)))
#mat_cluster_rows_H <- sort_hclust(hclust(dist(dataH)))
mat_cluster_cols_H <- sort_hclust(hclust(dist(t(mx))))
quantile_breaks <- function(xs, n = 30) {
breaks <- quantile(xs, probs = seq(0, 1, length.out = n))
breaks[!duplicated(breaks)]
}
# mat_breaks_H <- quantile_breaks(t(mx), n = 30)
pdf(paste(args$output,".pdf",sep=''))
pheatmap(
mat = mx,
scale = 'none',
color = viridis(30),
# color = viridis(length(mat_breaks_H) - 1),
# breaks = mat_breaks_H,
border_color = NA,
cluster_cols = mat_cluster_cols_H,
cluster_rows = F,
# cluster_rows = mat_cluster_rows_H,
show_colnames = FALSE,
show_rownames = FALSE,
drop_levels = TRUE,
fontsize = 14,
main = "decomp H"
)
dev.off()
nor01 <- function(x){
min <- min(x)
max <- max(x)
out <- (x - min) / (max - min)
}