comparison ggplot2_heatmap.xml @ 0:f44dc95928aa draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ggplot2 commit f9fb73a88ab8b52ce11c25a966d4fe99e67c9fbf
author iuc
date Mon, 11 Jun 2018 16:04:51 -0400
parents
children 391a4cc45fea
comparison
equal deleted inserted replaced
-1:000000000000 0:f44dc95928aa
1 <tool id="ggplot2_heatmap" name="Heatmap w ggplot" version="@VERSION@">
2 <macros>
3 <import>macros.xml</import>
4 </macros>
5 <requirements>
6 <requirement type="package" version="0.9.2">r-cowplot</requirement>
7 <requirement type="package" version="0.2.0">r-egg</requirement>
8 <requirement type="package" version="0.1_20">r-ggdendro</requirement>
9 <requirement type="package" version="0.7.4">r-dplyr</requirement>
10 <requirement type="package" version="1.4.3">r-reshape2</requirement>
11 <requirement type="package" version="1.2.1">r-svglite</requirement>
12 </requirements>
13 <command detect_errors="exit_code"><![CDATA[
14 cat '$script' &&
15 Rscript '$script'
16 ]]></command>
17 <configfiles>
18 <configfile name="script"><![CDATA[
19 @R_INIT@
20
21 ## Import library
22
23 library(ggplot2)
24 library(cowplot)
25 library(egg)
26 library(dplyr)
27 library(ggdendro)
28 library(reshape2)
29
30 input <- '$input1'
31 header <- ${inputdata.header}
32 rowname_index <- as.integer('$inputdata.row_names_index')
33
34 transform <- '$adv.transform'
35
36 ## read table with or with out header or row_names
37 if(rowname_index > 0){
38 df <- read.table(input, header = header, row.names = rowname_index, sep = "\t")
39 }else{
40 df <- read.table(input, header = header, sep = "\t")
41 }
42
43 hclust_fun = function(x) hclust(x, method="complete")
44 dist_fun = function(x) dist(x, method="maximum")
45 distfun=dist_fun
46 hclustfun=hclust_fun
47
48 plot_mat <- df
49
50 ## transform dataset
51 if(transform == "log2"){
52 plot_mat <- log2(plot_mat)
53 cat("\n ", transform, " transformed")
54 }else if(transform == "log2plus1"){
55 plot_mat <- log2(plot_mat+1)
56 cat("\n ", transform, " transformed")
57 }else if(transform == "log10"){
58 plot_mat <- log10(plot_mat)
59 cat("\n ", transform, " transformed")
60 }else if(transform == "log10plus1"){
61 plot_mat <- log10(plot_mat+1)
62 cat("\n ", transform, " transformed")
63 }else{
64 plot_mat <- plot_mat
65 }
66
67 #if $adv.colorscheme == "whrd"
68 colorscale = scale_fill_gradient(low="white", high="red", guide="colorbar")
69 #elif $adv.colorscheme == "whblu"
70 colorscale = scale_fill_gradient(low="white", high="blue", guide="colorbar")
71 #elif $adv.colorscheme == "blwhre"
72 colorscale = scale_fill_gradient2(low="blue", mid="white", high="red", guide="colorbar")
73 #end if
74
75 plot_mat["rows"] <- row.names(plot_mat)
76 plot_mat.melt <- melt(plot_mat, id.vars = "rows")
77 names(plot_mat.melt)[2] <- "cols"
78
79 #if $adv.cluster:
80
81 plot_mat.dendo <- as.dendrogram(hclust(d = dist(x = subset(plot_mat, select = -rows))))
82
83 plot_mat.dendo.order <- order.dendrogram(plot_mat.dendo)
84
85 gg_rows = ggdendrogram(data = plot_mat.dendo, rotate = FALSE) +
86 theme(axis.text.y = element_text(size = 6), axis.text.x = element_blank())
87
88 plot_mat.melt[,"rows"] <- factor(x = plot_mat.melt[,"rows"],
89 levels = unique(plot_mat.melt[,"rows"])[plot_mat.dendo.order],
90 ordered = TRUE)
91
92 plot_mat.dendo <- as.dendrogram(hclust(d = dist(x = t(subset(plot_mat, select = -rows)))))
93 plot_mat.dendo.order <- order.dendrogram(plot_mat.dendo)
94
95 gg_cols = ggdendrogram(data = plot_mat.dendo, rotate = TRUE) +
96 theme(axis.text.x = element_text(size = 6), axis.text.y = element_blank())
97
98 plot_mat.melt[,"cols"] <- factor(x = plot_mat.melt[,"cols"],
99 levels = unique(plot_mat.melt[,"cols"])[plot_mat.dendo.order],
100 ordered = TRUE)
101
102 ## plot the heatmap
103 gg_hm = plot_mat.melt %>%
104 ggplot(aes(x = rows, y = cols, fill = value)) +
105 geom_tile() +
106 theme(legend.position = "bottom", axis.title.x = element_blank(), axis.title.y = element_blank(),
107 axis.text.x = element_text(angle = 90, hjust = 1)) +
108 colorscale
109
110 gg_empty = plot_mat.melt %>%
111 ggplot(aes(x = cols, y = value)) +
112 geom_blank() +
113 theme(axis.text = element_blank(),
114 axis.title = element_blank(),
115 line = element_blank(),
116 panel.background = element_blank())
117
118 plot_out <- ggarrange(
119 gg_rows, gg_empty, gg_hm, gg_cols,
120 nrow = 2, ncol = 2, widths = c(3, 1), heights = c(1, 3), newpage =F)
121
122 #else
123
124 ## plot the heatmap
125 gg_hm = plot_mat.melt %>%
126 ggplot(aes(x = rows, y = cols, fill = value)) +
127 geom_tile() + ggtitle('$title') +
128 theme(legend.position = "bottom", axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x = element_text(angle = 90, hjust = 1)) +
129 colorscale
130
131 plot_out <- gg_hm
132
133 #end if
134
135 @SAVE_OUTPUT@
136 ]]></configfile>
137 </configfiles>
138 <inputs>
139 <expand macro="read_complex_input"/>
140 <expand macro="title"/>
141 <!-- Advanced Options -->
142 <section name="adv" title="Advanced Options" expanded="false">
143 <expand macro="transform" />
144 <param name="cluster" type="boolean" truevalue="true" falsevalue="false" checked="false" label="Enable data clustering" />
145 <param name="colorscheme" type="select" label="Heatmap colorscheme" >
146 <option value="whrd" selected="true">White to red</option>
147 <option value="whblu">White to blue</option>
148 <option value="blwhre">Blue to white to red</option>
149 </param>
150 </section>
151 <!-- Output Options -->
152 <section name="out" title="Output Options" expanded="true">
153 <expand macro="dimensions" />
154 </section>
155 </inputs>
156 <outputs>
157 <expand macro="additional_output" />
158 </outputs>
159 <tests>
160 <test>
161 <param name="input1" value="mtcars.txt" ftype="tabular"/>
162 <conditional name="inputdata">
163 <param name="input_type" value="with_header_rownames"/>
164 <param name="header" value="TRUE"/>
165 <param name="row_names_index" value="1"/>
166 <param name="sample_name_orientation" value="TRUE"/>
167 </conditional>
168 <param name="transform" value="log10plus1"/>
169 <param name="cluster" value="true"/>
170 <param name="colorscheme" value="blwhre"/>
171 <param name="additional_output_format" value="pdf"/>
172 <output name="output2" file="ggplot_heatmap_result1.pdf" compare="sim_size"/>
173 </test>
174 </tests>
175 <help><![CDATA[
176 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.
177
178 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.
179 ]]></help>
180 <citations>
181 </citations>
182 </tool>