-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathggplot2_heatmap.xml
More file actions
executable file
·182 lines (155 loc) · 6.62 KB
/
ggplot2_heatmap.xml
File metadata and controls
executable file
·182 lines (155 loc) · 6.62 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<tool id="ggplot2_heatmap" name="Heatmap w ggplot" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
<macros>
<import>macros.xml</import>
</macros>
<expand macro="bio_tools"/>
<requirements>
<requirement type="package" version="1.2.0">r-cowplot</requirement>
<requirement type="package" version="0.4.5">r-egg</requirement>
<requirement type="package" version="0.2.0">r-ggdendro</requirement>
<requirement type="package" version="1.2.1">r-dplyr</requirement>
<requirement type="package" version="1.4.5">r-reshape2</requirement>
<requirement type="package" version="2.2.2">r-svglite</requirement>
</requirements>
<command detect_errors="exit_code"><![CDATA[
cat '$script' &&
Rscript '$script'
]]></command>
<configfiles>
<configfile name="script"><![CDATA[
@R_INIT@
## Import library
library(ggplot2)
library(cowplot)
library(egg)
library(dplyr)
library(ggdendro)
library(reshape2)
input <- '$input1'
header <- ${inputdata.header}
rowname_index <- as.integer('$inputdata.row_names_index')
transform <- '$adv.transform'
## read table with or with out header or row_names
if(rowname_index > 0){
df <- read.table(input, header = header, row.names = rowname_index, sep = "\t")
}else{
df <- read.table(input, header = header, sep = "\t")
}
hclust_fun = function(x) hclust(x, method="complete")
dist_fun = function(x) dist(x, method="maximum")
distfun=dist_fun
hclustfun=hclust_fun
plot_mat <- df
## transform dataset
if(transform == "log2"){
plot_mat <- log2(plot_mat)
cat("\n ", transform, " transformed")
}else if(transform == "log2plus1"){
plot_mat <- log2(plot_mat+1)
cat("\n ", transform, " transformed")
}else if(transform == "log10"){
plot_mat <- log10(plot_mat)
cat("\n ", transform, " transformed")
}else if(transform == "log10plus1"){
plot_mat <- log10(plot_mat+1)
cat("\n ", transform, " transformed")
}else{
plot_mat <- plot_mat
}
#if $adv.colorscheme == "whrd"
colorscale = scale_fill_gradient(low="white", high="red", guide="colorbar")
#elif $adv.colorscheme == "whblu"
colorscale = scale_fill_gradient(low="white", high="blue", guide="colorbar")
#elif $adv.colorscheme == "blwhre"
colorscale = scale_fill_gradient2(low="blue", mid="white", high="red", guide="colorbar")
#end if
plot_mat["rows"] <- row.names(plot_mat)
plot_mat.melt <- melt(plot_mat, id.vars = "rows")
names(plot_mat.melt)[2] <- "cols"
#if $adv.cluster:
plot_mat.dendo <- as.dendrogram(hclust(d = dist(x = subset(plot_mat, select = -rows))))
plot_mat.dendo.order <- order.dendrogram(plot_mat.dendo)
gg_rows = ggdendrogram(data = plot_mat.dendo, rotate = FALSE) +
theme(axis.text.y = element_text(size = 6), axis.text.x = element_blank())
plot_mat.melt[,"rows"] <- factor(x = plot_mat.melt[,"rows"],
levels = unique(plot_mat.melt[,"rows"])[plot_mat.dendo.order],
ordered = TRUE)
plot_mat.dendo <- as.dendrogram(hclust(d = dist(x = t(subset(plot_mat, select = -rows)))))
plot_mat.dendo.order <- order.dendrogram(plot_mat.dendo)
gg_cols = ggdendrogram(data = plot_mat.dendo, rotate = TRUE) +
theme(axis.text.x = element_text(size = 6), axis.text.y = element_blank())
plot_mat.melt[,"cols"] <- factor(x = plot_mat.melt[,"cols"],
levels = unique(plot_mat.melt[,"cols"])[plot_mat.dendo.order],
ordered = TRUE)
## plot the heatmap
gg_hm = plot_mat.melt %>%
ggplot(aes(x = rows, y = cols, fill = value)) +
geom_tile() +
theme(legend.position = "bottom", axis.title.x = element_blank(), axis.title.y = element_blank(),
axis.text.x = element_text(angle = 90, hjust = 1)) +
colorscale
gg_empty = plot_mat.melt %>%
ggplot(aes(x = cols, y = value)) +
geom_blank() +
theme(axis.text = element_blank(),
axis.title = element_blank(),
line = element_blank(),
panel.background = element_blank())
plot_out <- ggarrange(
gg_rows, gg_empty, gg_hm, gg_cols,
nrow = 2, ncol = 2, widths = c(3, 1), heights = c(1, 3), newpage =F)
#else
## plot the heatmap
gg_hm = plot_mat.melt %>%
ggplot(aes(x = rows, y = cols, fill = value)) +
geom_tile() + ggtitle('$title') +
theme(legend.position = "bottom", axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x = element_text(angle = 90, hjust = 1)) +
colorscale
plot_out <- gg_hm
#end if
@SAVE_OUTPUT@
]]></configfile>
</configfiles>
<inputs>
<expand macro="read_complex_input"/>
<expand macro="title"/>
<!-- Advanced Options -->
<section name="adv" title="Advanced Options" expanded="false">
<expand macro="transform" />
<param name="cluster" type="boolean" truevalue="true" falsevalue="false" checked="false" label="Enable data clustering" />
<param name="colorscheme" type="select" label="Heatmap colorscheme" >
<option value="whrd" selected="true">White to red</option>
<option value="whblu">White to blue</option>
<option value="blwhre">Blue to white to red</option>
</param>
</section>
<!-- Output Options -->
<section name="out" title="Output Options" expanded="true">
<expand macro="dimensions" />
</section>
</inputs>
<outputs>
<expand macro="additional_output" />
</outputs>
<tests>
<test expect_num_outputs="2">
<param name="input1" value="mtcars.txt" ftype="tabular"/>
<conditional name="inputdata">
<param name="input_type" value="with_header_rownames"/>
<param name="header" value="TRUE"/>
<param name="row_names_index" value="1"/>
<param name="sample_name_orientation" value="TRUE"/>
</conditional>
<param name="transform" value="log10plus1"/>
<param name="cluster" value="true"/>
<param name="colorscheme" value="blwhre"/>
<param name="additional_output_format" value="pdf"/>
<output name="output2" file="ggplot_heatmap_result1.pdf" ftype="pdf" compare="sim_size"/>
</test>
</tests>
<help><![CDATA[
This tool will generate a clustered heatmap of your data. More customization options will be added, for now the heatmap uses a red coloring scheme and clustering is performed using the "maximum" similarity measure and the "complete" hierarchical clustering measure.
Input data should have row labels in the first column and column labels. For example, the row labels (the first column) should represent gene IDs and the column labels should represent sample IDs.
]]></help>
<expand macro="citations"/>
</tool>