|
a |
|
b/heatmap_scripts/heatmap_temporal.R |
|
|
1 |
library(gplots) |
|
|
2 |
library(RColorBrewer) |
|
|
3 |
|
|
|
4 |
args <- commandArgs(trailingOnly = TRUE) |
|
|
5 |
# print(args[1]) |
|
|
6 |
# print(args[2]) |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
######################################################### |
|
|
10 |
### reading in data and transform it to matrix format |
|
|
11 |
######################################################### |
|
|
12 |
|
|
|
13 |
data <- read.csv(args[1], comment.char="#") |
|
|
14 |
rnames <- data[,1] # assign labels in column 1 to "rnames" |
|
|
15 |
mat_data <- data.matrix(data[,2:ncol(data)]) # transform column 2-5 into a matrix |
|
|
16 |
rownames(mat_data) <- rnames # assign row names |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
######################################################### |
|
|
21 |
### customizing and plotting heatmap |
|
|
22 |
######################################################### |
|
|
23 |
|
|
|
24 |
# creates a own color palette from red to green |
|
|
25 |
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299) |
|
|
26 |
|
|
|
27 |
# (optional) defines the color breaks manually for a "skewed" color transition |
|
|
28 |
col_breaks = c(seq(-1,0,length=100), # for red |
|
|
29 |
seq(0.001,0.7,length=100), # for yellow |
|
|
30 |
seq(0.71,1,length=100)) # for green |
|
|
31 |
|
|
|
32 |
# creates a 5 x 5 inch image |
|
|
33 |
# png("h1_simple.png", |
|
|
34 |
# width = 5*300, # 5 x 300 pixels |
|
|
35 |
# height = 5*300, |
|
|
36 |
# res = 300, # 300 pixels per inch |
|
|
37 |
# pointsize = 8) # smaller font size |
|
|
38 |
|
|
|
39 |
# heatmap.2(t(mat_data), |
|
|
40 |
# cellnote = t(mat_data), # same data set for cell labels |
|
|
41 |
# #notecol="black", # change font color of cell labels to black |
|
|
42 |
# #density.info="none", # turns off density plot inside color legend |
|
|
43 |
# trace="none", # turns off trace lines inside the heat map |
|
|
44 |
# margins =c(12,9), # widens margins around plot |
|
|
45 |
# col=my_palette, # use on color palette defined earlier |
|
|
46 |
# breaks=col_breaks, # enable color transition at specified limits |
|
|
47 |
# dendrogram="none", # only draw a row dendrogram |
|
|
48 |
|
|
|
49 |
if(length(args) < 3){ |
|
|
50 |
offset <- -13 |
|
|
51 |
} else { |
|
|
52 |
offset <- as.integer(args[3]) |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
if(length(args) < 4){ |
|
|
56 |
color_map <- bluered |
|
|
57 |
colors = c(seq(0,0.5,length=20),seq(0.501,1,length=20)) #TODO change for certain graphs |
|
|
58 |
} else { |
|
|
59 |
color_map <- colorRampPalette(c("white","red"))(n = 39) |
|
|
60 |
# colors = c(seq(0,0.05,length=20),seq(0.501,1,length=20)) #TODO change for certain graphs |
|
|
61 |
colors=NULL |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
png(file = args[2], units="in", width=11, height=8.5, res=300) |
|
|
67 |
|
|
|
68 |
heatmap.2(t(mat_data), |
|
|
69 |
# cellnote = t(mat_data), |
|
|
70 |
Rowv=NULL, |
|
|
71 |
Colv="NA", |
|
|
72 |
srtCol=0, |
|
|
73 |
labRow = "", |
|
|
74 |
col = color_map, |
|
|
75 |
breaks = colors, |
|
|
76 |
scale="none", |
|
|
77 |
margins=c(3,0), # ("margin.Y", "margin.X") |
|
|
78 |
trace='none', |
|
|
79 |
symkey=FALSE, |
|
|
80 |
symbreaks=FALSE, |
|
|
81 |
dendrogram='none', |
|
|
82 |
offsetCol = offset, |
|
|
83 |
cexCol=0.9, |
|
|
84 |
key=FALSE, #change to turn on |
|
|
85 |
density.info=NULL, |
|
|
86 |
denscol="black", |
|
|
87 |
keysize=1, |
|
|
88 |
#( "bottom.margin", "left.margin", "top.margin", "left.margin" ) |
|
|
89 |
key.par=list(mar=c(3.5,0,3,0)), |
|
|
90 |
# lmat -- added 2 lattice sections (5 and 6) for padding |
|
|
91 |
lmat=rbind(c(5, 4, 2), c(6, 1, 3)), lhei=c(2.5, 5), lwid=c(1, 10, 1) |
|
|
92 |
) |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
dev.off() |