comparison ggplot2_boxplot.xml @ 0:653803fab921 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ggplot2 commit 57b86418a4f032a5664b8dc1c9585a11be629158
author iuc
date Thu, 15 May 2025 13:02:31 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:653803fab921
1 <tool id="ggplot2_boxplot" name="Boxplot w ggplot2" version="@TOOL_VERSION@+galaxy0" profile="23.0">
2 <description>Boxplot visualization tool using ggplot2</description>
3 <macros>
4 <import>macros.xml</import>
5 </macros>
6 <expand macro="requirements">
7 <requirement type="package" version="1.3.1">r-tidyr</requirement>
8 <requirement type="package" version="19.0.0">r-arrow</requirement>
9 <requirement type="package" version="1.1.5">r-rlang</requirement>
10 </expand>
11 <required_files>
12 <include path="utils.r" />
13 </required_files>
14 <creator>
15 <person
16 givenName="Kristina"
17 familyName="Gomoryova"
18 url="https://github.com/KristinaGomoryova"
19 identifier="0000-0003-4407-3917" />
20 <person
21 givenName="Helge"
22 familyName="Hecht"
23 url="https://github.com/hechth"
24 identifier="0000-0001-6744-996X" />
25 <organization
26 url="https://www.recetox.muni.cz/"
27 email="GalaxyToolsDevelopmentandDeployment@space.muni.cz"
28 name="RECETOX MUNI" />
29 </creator>
30
31 <command detect_errors="exit_code"><![CDATA[
32 Rscript -e 'source("${__tool_directory__}/utils.r")' -e 'source("${run_script}")'
33 #if $export_R_script
34 && cat ${run_script} >> $script
35 #end if
36 ]]></command>
37
38 <configfiles>
39 <configfile name="run_script"><![CDATA[
40 file_name <- "$input_data"
41 file_extension <- "$input_data.ext"
42 data_input <- load_data(file_name, file_extension)
43
44 #if $has_rownames
45 rownames(data_input) <- data_input[, 1]
46 data_input <- data_input[ ,-1]
47 #end if
48
49 y_colname <- "intensity"
50 data_long <- tidyr::pivot_longer(data_input,
51 cols = c(1:ncol(data_input)),
52 names_to = "samples",
53 values_to = y_colname)
54
55 #if $transform_data == "replace_zero"
56 data_long[data_long == 0] <- NA
57 #else if $transform_data == "log2"
58 data_long[[y_colname]] <- log2(data_long[[y_colname]])
59 #else if $transform_data == "log10"
60 data_long[[y_colname]] <- log10(data_long[[y_colname]])
61 #end if
62
63 #if $grouping_boxplot.use_grouping == "yes"
64 metadata_input <- read.delim("$grouping_boxplot.input_metadata", sep="\t", check.names = "false")
65 sampleID_column <- colnames(metadata_input)[$grouping_boxplot.sampleID]
66 plotting_column <- colnames(metadata_input)[$grouping_boxplot.groupingCol]
67 metadata_input <- data.frame(lapply(metadata_input, as.factor))
68
69 data_long <- dplyr::left_join(data_long, metadata_input, by = c("samples" = sampleID_column), keep = TRUE)
70
71 #if $grouping_boxplot.facet_x
72 facet_x <- rlang::sym(colnames(metadata_input)[$grouping_boxplot.facet_x])
73 #else
74 facet_x <- NULL
75 #end if
76
77 #if $grouping_boxplot.facet_y
78 facet_y <- rlang::sym(colnames(metadata_input)[$grouping_boxplot.facet_y])
79 #else
80 facet_y <- NULL
81 #end if
82
83 plot_boxplot <- ggplot2::ggplot(
84 data_long, ggplot2::aes(
85 x = !!rlang::sym(plotting_column),
86 y = intensity,
87 #if $grouping_boxplot.colorCol
88 fill = !!rlang::sym(colnames(metadata_input)[$grouping_boxplot.colorCol])
89 #end if
90 )) + ggplot2::geom_boxplot() +
91 ggplot2::theme_bw()+
92 ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust=1)) +
93 ggplot2::facet_grid(rows = if(!is.null(facet_y)) dplyr::vars(!!facet_y) else NULL,
94 cols = if(!is.null(facet_x)) dplyr::vars(!!facet_x) else NULL,
95 scales = "free")
96
97
98 #else
99
100 plot_boxplot <- ggplot2::ggplot(
101 data_long,
102 ggplot2::aes(x = samples, y = intensity)
103 ) + ggplot2::geom_boxplot() +
104 ggplot2::theme_bw()+
105 ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust=1))
106
107 #end if
108
109 #if $xlab
110 plot_boxplot <- plot_boxplot + ggplot2::xlab("$xlab")
111 #end if
112
113 #if $ylab
114 plot_boxplot <- plot_boxplot + ggplot2::ylab("$ylab")
115 #end if
116
117 #if $flip_axes == "true"
118 plot_boxplot <- plot_boxplot + ggplot2::coord_flip()
119 #end if
120
121 ggplot2::ggsave(filename = "boxplot.png", plot_boxplot)
122 ]]></configfile>
123 </configfiles>
124
125 <inputs>
126 <expand macro="data_input"/>
127 <param name="has_rownames" type="boolean" checked="false" truevalue="TRUE" falsevalue="FALSE" label="Does the first column of input table contain rownames?" help="Whether the first column of the input data table identifies the rownames (e.g. proteinID) - i.e. it is not a part of data matrix to be plotted."/>
128 <param name="transform_data" type="select" display="radio" label="Should the quantitative variable be transformed?" optional="false" help="Whether to transform the quantitative variable (e.g. intensity, counts, etc.)">
129 <option value="none" selected="true">No transformation</option>
130 <option value="replace_zero">Replace zeroes with NA values</option>
131 <option value="log2">Log2 transformation</option>
132 <option value="log10">Log10 transformation</option>
133 </param>
134 <param name="flip_axes" type="boolean" checked="false" truevalue="TRUE" falsevalue="FALSE" label="Plot the boxplots horizontally? (flip the axes)" help="Whether to flip the axes, so the boxplots will be horizontal instead of vertical."/>
135 <conditional name="grouping_boxplot">
136 <param type="select" name="use_grouping" label="Plot boxplot based on a column from the metadata table?" help="Whether to base the boxplot on a different variable than column names (usually corresponding to the samples) from the input table.">
137 <option value="no" selected="true">no</option>
138 <option value="yes">yes</option>
139 </param>
140 <when value="yes">
141 <param name="input_metadata" type="data" format="tabular" label="Input metadata table" help= "Input metadata file in a tabular format"/>
142 <param name="sampleID" type="data_column" data_ref="input_metadata" use_header_names="true" label="Sample identification column in metadata table" help="Column containing sample names - it should correspond to the colNames in the data table."/>
143 <param name="groupingCol" type="data_column" data_ref="input_metadata" use_header_names="true" label="Which variable column to plot on the x-axis?" help="Which column from the metadata table should be plotted on x axis?"/>
144 <param name="colorCol" type="data_column" data_ref="input_metadata" use_header_names="true" label="Color the boxplot based on a variable?" help="Which column from the metadata table should be used for coloring?" optional = "true"/>
145 <param name="facet_x" type="data_column" data_ref="input_metadata" use_header_names="true" label="Column to use as facet on x-axis" optional="true" help="If using faceting, which column should be plotted on x-axis? Default 'Nothing selected' means no faceting will be done on x-axis."/>
146 <param name="facet_y" type="data_column" data_ref="input_metadata" use_header_names="true" label="Column to use as facet on y-axis" optional="true" help="If using faceting, which column should be plotted on y-axis? Default 'Nothing selected' means no faceting will be done on y-axis."/>
147 </when>
148 <when value="no"/>
149 </conditional>
150 <expand macro="axes_labels"/>
151 <expand macro="export_data"/>
152 </inputs>
153
154 <outputs>
155 <data name="boxplot" format="png" label="Boxplot on ${on_string}" from_work_dir="boxplot.png"/>
156 <data name="script" format="txt" label="R script">
157 <filter>export_R_script</filter>
158 </data>
159 </outputs>
160
161 <tests>
162 <test expect_num_outputs="1">
163 <param name="input_data" value="boxplot_test_data.txt" ftype="tabular"/>
164 <param name="has_rownames" value="true"/>
165 <output name="boxplot" ftype="png">
166 <assert_contents>
167 <has_image_channels channels="1"/>
168 <has_image_height height="2100"/>
169 <has_image_width width="2100" />
170 <has_image_center_of_mass center_of_mass="1048.15, 1051.40" eps="0.1"/>
171 </assert_contents>
172 </output>
173 </test>
174 <test expect_num_outputs="2">
175 <param name="input_data" value="boxplot_test_data.txt" ftype="tabular"/>
176 <param name="has_rownames" value="true"/>
177 <param name="use_grouping" value="yes"/>
178 <param name="input_metadata" value="boxplot_test_expDesign.txt"/>
179 <param name="sampleID" value="1"/>
180 <param name="groupingCol" value="1"/>
181 <param name="export_R_script" value="TRUE"/>
182 <output name="boxplot" ftype="png">
183 <assert_contents>
184 <has_image_channels channels="1"/>
185 <has_image_height height="2100"/>
186 <has_image_width width="2100" />
187 <has_image_center_of_mass center_of_mass="1048.14, 1051.30" eps="0.1"/>
188 </assert_contents>
189 </output>
190 </test>
191 </tests>
192
193 <help><![CDATA[
194 recetox-boxplot help
195 =====================
196
197 Overview
198 --------
199
200 recetox-boxplot tool can be used to plot boxplots for the tabular data. On the input, a dataframe in tabular/csv/parquet format, containing only columns to be plotted (the pre-filtering can be achieved e.g. using the `Cut` Galaxy tool) is expected. If the data contains as the first column the rownames - meaning identificators, ProteinID, etc., please do set the `Does the first column of input table contain rownames?` to TRUE.
201
202 Typically, a table where rows are features and columns are samples is expected - if one wishes to plot the boxplots for the features, we recommend to transpose the table beforehand.
203
204 Sometimes, it is better to transform the data for the visualization (or processing) purposes (`Should the quantitative variable be transformed?`). If no transformation option is selected, the data will be plotted as it is. Otherwise, one can choose from replacing all zero values by NA, log2 transformation or log10 transformation. Please note, that NA values are omitted while plotting.
205
206 `Plot the boxplots horizontally?` option means flipping the axes: a categorical variable (e.g. samples) would be on y-axis, whereas quantitative variable (e.g. intensity) would be on x-axis. This improves the legibility in case of larger datasets.
207
208 It is possible to use also a different variable for the plotting and coloring - in that case, a metadata table (in a tabular format) can be supplied. The metadata table must contain a column which will map to the data table column names (e.g. SampleName).
209
210 It is also possible to use faceting, meaning splitting the plot based on multiple variables. One can then choose which variable to split the x axis and y axis on.
211
212 Example data table
213 -------------------
214
215 +----------------------+-------------------+-----------------------+--------------------+
216 | RowID | sample1 | sample2 | sample3 |
217 +======================+===================+=======================+====================+
218 | 1 | 350.58 | 211.33 | 288.90 |
219 +----------------------+-------------------+-----------------------+--------------------+
220 | 2 | 130.17 | 287.54 | 100.11 |
221 +----------------------+-------------------+-----------------------+--------------------+
222 | 3 | 134.80 | 683.15 | 112.34 |
223 +----------------------+-------------------+-----------------------+--------------------+
224 | 4 | 183.99 | 920.57 | 590.44 |
225 +----------------------+-------------------+-----------------------+--------------------+
226 | ... | ... | ... | ... |
227 +----------------------+-------------------+-----------------------+--------------------+
228
229
230 Example metadata table
231 -----------------------
232
233 +----------------------+-------------------+-----------------------+--------------------+
234 | SampleName | replicate | condition | batch |
235 +======================+===================+=======================+====================+
236 | sample1 | 1 | control | A |
237 +----------------------+-------------------+-----------------------+--------------------+
238 | sample2 | 1 | treatment | A |
239 +----------------------+-------------------+-----------------------+--------------------+
240 | sample3 | 2 | treatment | A |
241 +----------------------+-------------------+-----------------------+--------------------+
242 ]]></help>
243 <expand macro="citations"/>
244 </tool>