upstream-extended/iuc/tools/table_compute/table_compute.xml
1<tool id="table_compute" name="Table Compute" version="@VERSION@+galaxy@WRAPPER_VERSION@" profile="25.1">
2 <description>computes operations on table data</description>
3 <macros>
4 <token name="@VERSION@">1.2.4</token>
5 <token name="@WRAPPER_VERSION@">3</token>
6 <token name="@COPEN@"><![CDATA[<code>]]></token>
7 <token name="@CCLOSE@"><![CDATA[</code>]]></token>
8 <import>allowed_functions.xml</import>
9 <!-- text field validators -->
10 <macro name="validator_text" >
11 <validator type="regex" message="No special characters allowed">^(?:\w+)?$</validator>
12 <sanitizer sanitize="false" />
13 </macro>
14 <macro name="validator_text_required" >
15 <validator type="regex" message="No special characters allowed">^(?:\w+)?$</validator>
16 <validator type="empty_field" />
17 </macro>
18 <macro name="validator_index_identifiers" >
19 <validator type="regex" message="Specify a comma-separated list of index names without special characters">^(?:\w+(?:, *\w+)*)?$</validator>
20 <sanitizer sanitize="false" />
21 </macro>
22 <macro name="validator_index_ranges">
23 <validator type="regex" message="Specify a comma-separated list index numbers or ranges">^(?:-?\d+(?::-?\d+)*(?:, *-?\d+(?::-?\d+)*)*)?$</validator>
24 <sanitizer sanitize="false" />
25 </macro>
26 <macro name="validator_functiondef">
27 <validator type="regex" message="An expression is required and is allowed to contain only letters, numbers and the characters _ !-+=/*%.<>()">^[\w !\-+=/*%,.<>()]+$</validator>
28 <sanitizer sanitize="false" />
29 </macro>
30 <!-- macro for main input tests -->
31 <macro name="test_inputs_single" >
32 <conditional name="singtabop" >
33 <param name="use_type" value="single" />
34 <param name="input" value="small.tsv" />
35 <conditional name="user" >
36 <yield />
37 </conditional>
38 </conditional>
39 </macro>
40 <macro name="test_inputs_ranges" >
41 <conditional name="singtabop" >
42 <param name="use_type" value="single" />
43 <param name="input" value="examples.1.tsv" />
44 <conditional name="user" >
45 <param name="mode" value="select" />
46 <yield />
47 </conditional>
48 </conditional>
49 </macro>
50 <!-- macro for umi to transcript tests -->
51 <macro name="umi2trans" >
52 <yield />
53 <conditional name="user" >
54 <param name="mode" value="element" />
55 <conditional name="elem_val">
56 <param name="element_op" value="None" />
57 </conditional>
58 <conditional name="element" >
59 <param name="mode" value="custom" />
60 <param name="custom_expr" value="-math.log(1 - elem/4096) * 4096 if elem != 4096 else elem - 0.5" />
61 </conditional>
62 </conditional>
63 </macro>
64 <!-- macro for file inputs -->
65 <macro name="file_opts">
66 <param name="input" type="data" format="tsv,tabular" label="Table" />
67 <param name="col_row_names" type="select" display="checkboxes" multiple="true" optional="true"
68 label="Input data has">
69 <option value="has_col_names" selected="true">Column names on the first row</option>
70 <option value="has_row_names" selected="true">Row names on the first column</option>
71 </param>
72 <section name="adv" title="Advanced File Options " expanded="false" >
73 <param name="header" type="integer" min="0" optional="true" label="Header begins at line N" help="All lines before line N will be skipped. If a value is set, this will override the above 'Column names on the first row' parameter." />
74 <param name="nrows" type="integer" min="0" optional="true" label="Read N lines only" help="Parses only N lines after the header line." />
75 <param name="skipfooter" type="integer" min="0" optional="true" label="Skip N lines from bottom" help="Do not use this in conjunction with the 'Read N lines only' parameter." />
76 <param name="skip_blank_lines" type="boolean" checked="true" falsevalue="False" truevalue="True" label="Skip blank lines" help="Otherwise it will insert NaN values for every blank line detected." />
77 </section>
78 </macro>
79 <!-- element value macro -->
80 <macro name="elem_val_macro" token_when="@WHEN@" >
81 <when value="@WHEN@" >
82 <param name="element_value" type="text" optional="true" label="Filter value" help="This value is converted to numeric if possible, otherwise it is treated as a string" />
83 </when>
84 </macro>
85 <!-- Row/Col macro -->
86 <macro name="select_rowcols" >
87 <param name="select_cols_wanted" type="text" optional="true" label="List of columns to select" help="Comma separated. (e.g. @COPEN@3:5,10,-1,2:-2@CCLOSE@ will select columns @COPEN@3,4,5,10,-1,2,1,0,-1,-2@CCLOSE@, where negative indices refer to the offset from the last index). Columns can be duplicated by specifying them multiple times. Leave blank to retain all columns. See Example #1 for an example of using this mode." >
88 <expand macro="validator_index_ranges" />
89 </param>
90 <param name="select_rows_wanted" type="text" optional="true" label="List of rows to select" help="The same rules apply as above" >
91 <expand macro="validator_index_ranges" />
92 </param>
93 </macro>
94 </macros>
95 <requirements>
96 <requirement type="package" version="1.2.4">pandas</requirement>
97 <requirement type="package" version="1.19.2">numpy</requirement>
98 </requirements>
99
100 <required_files>
101 <include path="scripts/safety.py" />
102 <include path="scripts/table_compute.py" />
103 </required_files>
104
105 <version_command><![CDATA[
106 python '$__tool_directory__/scripts/table_compute.py' --version
107 ]]></version_command>
108
109 <command detect_errors="exit_code"><![CDATA[
110 ## Can only import generated userconfig.py if calling
111 ## script is in the same directory. Soft-linking does
112 ## not satisfy importing, so we copy everything.
113 cp '$userconf' ./userconfig.py &&
114 cp '$__tool_directory__/scripts/safety.py' ./safety.py &&
115 cp '$__tool_directory__/scripts/table_compute.py' ./table_compute.py &&
116 python ./table_compute.py
117 ]]></command>
118 <configfiles>
119 <configfile name="userconf"><![CDATA[
120Default = {
121 "reader_skip": 0,
122 "precision": $precision,
123 #if 'ignore_nas' in str($out_opts):
124 "narm": True,
125 #else:
126 "narm": False,
127 #end if
128 #if 'output_headers_row' in str($out_opts):
129 "out_headers_row": True,
130 #else:
131 "out_headers_row": False,
132 #end if
133 #if 'output_headers_col' in str($out_opts):
134 "out_headers_col": True,
135 #else:
136 "out_headers_col": False,
137 #end if
138 "user_mode": '$singtabop.use_type',
139 "outtable": '$table'
140}
141
142#if str($singtabop.use_type) == "single":
143 #set $op_mode = str($singtabop.user.mode)
144Data = {
145 "tables": [
146 {
147 "file": '$singtabop.input',
148 #if $singtabop.adv.header:
149 "header": int('$singtabop.adv.header'),
150 #elif 'has_col_names' in str($singtabop.col_row_names):
151 "header": 0,
152 #else:
153 "header": None,
154 #end if
155 "row_names": #if ('has_row_names' in str($singtabop.col_row_names)) then 0 else False#,
156 "skipfooter": #if $singtabop.adv.skipfooter then int($singtabop.adv.skipfooter) else 0#,
157 #if $singtabop.adv.skip_blank_lines
158 "skip_blank_lines": $singtabop.adv.skip_blank_lines,
159 #else
160 "skip_blank_lines": None,
161 #end if
162 #if $singtabop.adv.nrows
163 "nrows": int('$singtabop.adv.nrows'),
164 #else
165 "nrows": None,
166 #end if
167 }
168 ],
169 "params": {
170 "user_mode_single": '$op_mode',
171 #if $op_mode == 'precision':
172 ## Literally do nothing, the user just sets the precision slider
173 ## at the top default level
174 }
175 #elif $op_mode == 'select':
176 "select_cols_unique": #echo 'select_cols_keepdupe' in str($singtabop.user.select_keepdupe)#,
177 "select_rows_unique": #echo 'select_rows_keepdupe' in str($singtabop.user.select_keepdupe)#,
178 #if $singtabop.user.select_cols_wanted:
179 "select_cols_wanted": '$singtabop.user.select_cols_wanted',
180 #else
181 "select_cols_wanted": None,
182 #end if
183 #if $singtabop.user.select_rows_wanted:
184 "select_rows_wanted": '$singtabop.user.select_rows_wanted',
185 #else
186 "select_rows_wanted": None,
187 #end if
188 }
189 #elif $op_mode == 'filtersumval':
190 #set $filter_type = str($singtabop.user.filtersumval_mode.use)
191 "filtersumval_mode": '$filter_type',
192 "filtersumval_axis": $singtabop.user.axis,
193 #if $filter_type == 'operation':
194 "filtersumval_compare": '$singtabop.user.filtersumval_mode.compare_op',
195 "filtersumval_op": '$singtabop.user.filtersumval_mode.operation',
196 "filtersumval_against": $singtabop.user.filtersumval_mode.against,
197 "filtersumval_minmatch": None,
198 #elif $filter_type == 'element':
199 "filtersumval_compare": None,
200 "filtersumval_op": '$singtabop.user.filtersumval_mode.operation',
201 ## against could be string or float, so we parse this in the code
202 "filtersumval_against": '$singtabop.user.filtersumval_mode.against',
203 "filtersumval_minmatch": $singtabop.user.filtersumval_mode.minmatch,
204 #end if
205 }
206 #elif $op_mode == 'matrixapply':
207 "matrixapply_dimension": $singtabop.user.dimension,
208 #if str($singtabop.user.matrixapply_func.vector_op) == 'custom':
209 #set $custom_func = str($singtabop.user.matrixapply_func.custom_func).strip()
210 "matrixapply_custom": True,
211 "matrixapply_custom_func": '$custom_func',
212 "matrixapply_op": None,
213 #else
214 "matrixapply_custom": False,
215 "matrixapply_custom_func": None,
216 "matrixapply_op": '$singtabop.user.matrixapply_func.vector_op',
217 #end if
218 }
219 #elif $op_mode == 'element':
220 #set $filter_type = str($singtabop.user.elem_val.element_op)
221 #set $element_mode = str($singtabop.user.element.mode)
222 #if $filter_type == "None":
223 "element_op": None,
224 #elif $filter_type == "rowcol":
225 "element_op": "rowcol",
226 #if $singtabop.user.elem_val.select_rows_wanted
227 "element_rows": '$singtabop.user.elem_val.select_rows_wanted',
228 #end if
229 #if $singtabop.user.elem_val.select_cols_wanted
230 "element_cols": '$singtabop.user.elem_val.select_cols_wanted',
231 #end if
232 "element_inclusive": $singtabop.user.elem_val.inclusive_selection,
233 #else:
234 "element_op": '$filter_type',
235 ## Value is string or float, parsed in code later
236 "element_value" : '$singtabop.user.elem_val.element_value',
237 #end if
238 "element_mode": '$element_mode',
239 #if $element_mode == "replace":
240 "element_replace": '$singtabop.user.element.replace_value',
241 #elif $element_mode == "modify":
242 "element_modify_op": '$singtabop.user.element.modify_op',
243 #elif $element_mode == "scale":
244 "element_scale_op": '$singtabop.user.element.scale_op',
245 "element_scale_value": $singtabop.user.element.scale_value,
246 #elif $element_mode == "custom":
247 #set $custom_func = str($singtabop.user.element.custom_expr).strip()
248 "element_customop": '$custom_func',
249 #end if
250 }
251 #elif $op_mode == 'fulltable':
252 "mode": '$singtabop.user.general.use',
253 #if str($singtabop.user.general.use) == 'melt':
254 #if str($singtabop.user.general.id_vars).strip():
255 #set $melt_ids = [i.strip() for i in str($singtabop.user.general.id_vars).split(',')]
256 #else
257 #set $melt_ids = 'None'
258 #end if
259 #if str($singtabop.user.general.value_vars).strip():
260 #set $melt_values = [i.strip() for i in str($singtabop.user.general.value_vars).split(',')]
261 #else
262 #set $melt_values = 'None'
263 #end if
264 "MELT": {
265 "melt_ids": $melt_ids,
266 "melt_values": $melt_values,
267 },
268 #elif str($singtabop.user.general.use) == 'pivot':
269 #set $pivot_index = None
270 #set $pivot_columns = None
271 #set $pivot_values = None
272 #set $pivot_aggfunc = None
273
274 #if str($singtabop.user.general.index).strip()
275 #set $pivot_index = [i.strip() for i in str($singtabop.user.general.index).split(',')]
276 #if len($pivot_index)==1
277 #set $pivot_index = "'"+$pivot_index[0]+"'"
278 #end if
279 #else
280 #set $pivot_index = 'None'
281 #end if
282 #if str($singtabop.user.general.column).strip()
283 #set $pivot_columns = [i.strip() for i in str($singtabop.user.general.column).split(',')]
284 #if len($pivot_columns)==1
285 #set $pivot_columns = "'"+$pivot_columns[0]+"'"
286 #end if
287 #else
288 #set $pivot_columns = 'None'
289 #end if
290 #if str($singtabop.user.general.values).strip()
291 #set $pivot_values = [i.strip() for i in str($singtabop.user.general.values).split(',')]
292 #if len($pivot_values)==1
293 #set $pivot_values = "'"+$pivot_values[0]+"'"
294 #end if
295 #else
296 #set $pivot_values = 'None'
297 #end if
298
299 ## The aggfunc is either a - column : [array] map
300 ## or just an [array]
301 #if str($singtabop.user.general.aggfunc).strip() == 'None'
302 #set $pivot_aggfunc = 'None'
303 #end if
304 #if not($pivot_aggfunc)
305 #set $pivot_aggfunc = [i.strip() for i in str($singtabop.user.general.aggfunc).split(',')]
306 #if len($pivot_aggfunc)==1
307 #set $pivot_aggfunc = "'"+$pivot_aggfunc[0]+"'"
308 #end if
309 #end if
310
311 "PIVOT": {
312 "pivot_index": $pivot_index,
313 "pivot_columns": $pivot_columns,
314 "pivot_values": $pivot_values,
315 #if $pivot_aggfunc == 'None':
316 "pivot_aggfunc": {
317 #for $i, $s in enumerate($singtabop.user.general.colfun_map)
318 #echo 16*' ' + "'" + str($s.column) + "'" + ' : ['
319 #echo ','.join([ "'%s'" % $t.aggfunc for $j, $t in enumerate($s.functions) ])
320 #echo '],\n'
321 #end for
322 }
323 #else
324 "pivot_aggfunc": $pivot_aggfunc
325 #end if
326 },
327
328 #elif str($singtabop.user.general.use) == 'custom':
329 #set $custom_func = str($singtabop.user.general.fulltable_custom_expr).strip()
330 "fulltable_customop": '$custom_func',
331 #end if
332 },
333 #end if
334}
335
336#elif str($singtabop.use_type) == "multiple":
337 #set $custom_func = str($singtabop.fulltable_custom_expr).strip()
338Data = {
339 "tables": [
340 #for $i, $s in enumerate($singtabop.tables)
341 {
342 "file": '${s.input}',
343 #if $s.adv.header:
344 "header": int('${s.adv.header}'),
345 #elif 'has_col_names' in str($s.col_row_names):
346 "header": 0,
347 #else:
348 "header": None,
349 #end if
350 "row_names": #if ('has_row_names' in str($s.col_row_names)) then 0 else False#,
351 "skipfooter": #if $s.adv.skipfooter then int('$s.adv.skipfooter') else 0#,
352 #if $s.adv.skip_blank_lines:
353 "skip_blank_lines": $s.adv.skip_blank_lines,
354 #else
355 "skip_blank_lines": None,
356 #end if
357 #if $s.adv.nrows:
358 "nrows": int('${s.adv.nrows}'),
359 #else
360 "nrows": None,
361 #end if
362
363 },
364 #end for
365 ],
366 'params': {
367 "fulltable_customop" : '$custom_func',
368 }
369}
370#end if
371
372]]>
373 </configfile>
374 </configfiles>
375 <inputs>
376 <conditional name="singtabop" >
377 <param name="use_type" type="select" label="Input Single or Multiple Tables" help="Operations on single tables are better tailored towards more general use-cases. For multiple tables usage, all tables should ideally be of the same dimensions for simple operations, although complex operations are also supported for unequally sized tables (see Help section)." >
378 <option value="single">Single Table</option>
379 <option value="multiple">Multiple Tables</option>
380 </param>
381 <when value="single">
382 <expand macro="file_opts" />
383 <conditional name="user" >
384 <param name="mode" type="select" label="Type of table operation" >
385 <option value="precision">No operation (just reformat on output)</option>
386 <option value="select">Drop, keep or duplicate rows and columns</option>
387 <option value="filtersumval">Filter rows or columns by their properties</option>
388 <option value="matrixapply">Compute expression across rows or columns</option>
389 <option value="element">Manipulate selected table elements</option>
390 <option value="fulltable">Perform a full table operation</option>
391 </param>
392 <when value="precision" />
393 <when value="select">
394 <expand macro="select_rowcols" />
395 <param name="select_keepdupe" type="select" display="checkboxes" multiple="true" label="Duplicate Indices" help="Keep duplicates when specifying ranges (e.g. if unset, @COPEN@1:3,2:4@CCLOSE@ will yield @COPEN@1,2,3,4@CCLOSE@ instead of @COPEN@1,2,3,2,3,4@CCLOSE@)" >
396 <option value="select_cols_keepdupe" selected="true" >Keep duplicate columns</option>
397 <option value="select_rows_keepdupe" selected="true" >Keep duplicate rows</option>
398 </param>
399 </when>
400 <when value="filtersumval" >
401 <param name="axis" type="select" display="radio"
402 label="Filter" >
403 <option value="1">Rows</option>
404 <option value="0">Columns</option>
405 </param>
406 <conditional name="filtersumval_mode" >
407 <param name="use" type="select" label="Filter criterion" help="See Example #2 for an example of using this mode." >
408 <option value="operation" >Result of function applied to columns/rows</option>
409 <option value="element" >Number of column/row elements passing filter</option>
410 </param>
411 <when value="operation">
412 <param name="operation" type="select" label="Keep column/row if its observed" >
413 <expand macro="select_vectorops" />
414 </param>
415 <param name="compare_op" type="select" label="is" >
416 <expand macro="select_twovaluebooleanops" />
417 </param>
418 <param name="against" type="float" label="this value" value="0" />
419 </when>
420 <when value="element">
421 <param name="minmatch" type="integer" min="1" value="0" label="Keep column/row if at least" />
422 <param name="operation" type="select" label="of its element are" >
423 <expand macro="select_twovaluebooleanops" >
424 <option value="str_eq" >~ (Matching)</option>
425 <option value="str_ne" >!~ (not Matching)</option>
426 </expand>
427 </param>
428 <param name="against" type="text" label="this value">
429 <expand macro="validator_functiondef" />
430 </param>
431 </when>
432 </conditional>
433 </when>
434 <when value="matrixapply" >
435 <conditional name="matrixapply_func">
436 <param name="vector_op" type="select" label="Calculate">
437 <option value="custom">Custom Function</option>
438 <expand macro="select_vectorops" >
439 <option value="rank">Ranks</option>
440 <option value="cumsum" >Cumulative Sum</option>
441 <option value="cumprod" >Cumulative Product</option>
442 <option value="cummin" >Cumulative Minimum</option>
443 <option value="cummax" >Cumulative Maximum</option>
444 </expand>
445 </param>
446 <when value="custom">
447 <param name="custom_func" type="text"
448 label="Custom function on 'vec'"
449 help="The parameter name is @COPEN@vec@CCLOSE@, referring to a vector of a specific row or column being operated on. Numpy and Pandas DataFrame operators are supported. e.g. @COPEN@np.sum(vec) + np.median(vec)@CCLOSE@, and @COPEN@vec.sum() + vec.median()@CCLOSE@ are equivalent operations." >
450 <expand macro="validator_functiondef" />
451 </param>
452 </when>
453 <when value="min" />
454 <when value="max" />
455 <when value="sum" />
456 <when value="count" />
457 <when value="nunique" />
458 <when value="mean" />
459 <when value="median" />
460 <when value="std" />
461 <when value="sem" />
462 <when value="var" />
463 <when value="mad" />
464 <when value="product" />
465 <when value="rank" />
466 <when value="cumsum" />
467 <when value="cumprod" />
468 <when value="cummin" />
469 <when value="cummax" />
470 </conditional>
471 <param name="dimension" type="select" label="For each">
472 <option value="0">Column</option>
473 <option value="1">Row</option>
474 </param>
475 </when>
476 <when value="fulltable">
477 <conditional name="general" >
478 <param name="use" type="select" label="Operation" help="See Examples 5, 7, and 8 for usage" >
479 <option value="transpose">Transpose</option>
480 <option value="melt">Melt</option>
481 <option value="pivot">Pivot</option>
482 <option value="custom">Custom</option>
483 </param>
484 <when value="transpose" />
485 <when value="melt" >
486 <param name="id_vars" type="text" value="" label="Variable IDs"
487 help="Comma-delimited list of column names to use as identifiers" >
488 <expand macro="validator_index_identifiers" />
489 </param>
490 <param name="value_vars" type="text" value="" label="Unpivoted IDs"
491 help="Comma-delimited list of column names to un-pivot. Leave blank to use all." >
492 <expand macro="validator_index_identifiers" />
493 </param>
494 </when>
495 <when value="pivot" >
496 <param name="index" type="text" value=""
497 label="Index"
498 help="Name of the column to use as new index" >
499 <expand macro="validator_text" />
500 </param>
501 <param name="column" type="text" value=""
502 label="Column"
503 help="Name of the column to use to generate the columns of the new table from.
504 Cannot be used in conjunction with the Column-Function Mapping parameter."
505 optional="true">
506 <expand macro="validator_text_required" />
507 </param>
508 <param name="values" type="text" value=""
509 label="Values"
510 help="Names of the columns to use for populating the cells of the new table. Leave blank to use all." >
511 <expand macro="validator_index_identifiers" />
512 </param>
513 <param name="aggfunc" type="select" optional="true"
514 label="Aggregator Function"
515 help="The function used to aggregate the values for each unique index.
516 Cannot be used with the Column-Function Mapping parameter below.
517 By default this value is np.mean. Leave blank for default behaviour.
518 See Example 10 for more information on its usage." >
519 <expand macro="select_vectorops">
520 <option value="all">All</option>
521 <option value="any">Any</option>
522 </expand>
523 </param>
524 <repeat name="colfun_map" title="Column-Function Mapping" min="0">
525 <param name="column" type="text" label="Value Column"
526 help="Either a numeric index, or a value column name." />
527 <repeat name="functions" title="Aggregator Function" min="0" >
528 <!-- if zero, then this defaults to np.mean -->
529 <param name="aggfunc" type="select" label="Function"
530 help="The function used to aggregate the values for each unique index.
531 By default this is np.mean. See Example 11 for more information on its usage." >
532 <expand macro="select_vectorops">
533 <option value="all">All</option>
534 <option value="any">Any</option>
535 </expand>
536 </param>
537 </repeat>
538 </repeat>
539 </when>
540 <when value="custom" >
541 <param name="fulltable_custom_expr" type="text"
542 label="Custom expression on 'table', along 'axis' (0 or 1)"
543 help="The parameter name is @COPEN@table@CCLOSE@ and @COPEN@axis@CCLOSE@, referring to the table being acted on and the column (@COPEN@0@CCLOSE@) or row (@COPEN@1@CCLOSE@) to perform the operation on. Numpy, math, Pandas DataFrame operators, and inline @COPEN@if else@CCLOSE@ are supported (e.g. @COPEN@np.log(table) - table.mean(0) / table.std(1)@CCLOSE@). See Example #5 in the Help section. ">
544 <expand macro="validator_functiondef" />
545 </param>
546 </when>
547 </conditional>
548 </when>
549 <when value="element">
550 <conditional name="element" >
551 <param name="mode" type="select"
552 label="Operation to perform" >
553 <option value="replace">Replace values</option>
554 <option value="modify">Transform</option>
555 <option value="scale">Arithmetic operation</option>
556 <option value="custom">Custom</option>
557 </param>
558 <when value="replace" >
559 <param name="replace_value" type="text" label="Replacement value" help="If you want to reuse the current value of each element as part of the replacement value, you can refer to it using the special @COPEN@{elem}@CCLOSE@ placeholder (see Example #9 in the Help section).">
560 <sanitizer>
561 <valid>
562 <add value="{" />
563 <add value="}" />
564 </valid>
565 </sanitizer>
566 </param>
567 </when>
568 <when value="modify" >
569 <param name="modify_op" type="select" label="Transformation function" help="Example: to transform values to their square root, select @COPEN@Square Root@CCLOSE@ here.">
570 <expand macro="select_onevalueoperator" />
571 </param>
572 </when>
573 <when value="scale">
574 <param name="scale_op" type="select" label="Operation" help="The selected operation will be applied to the table elements as the first operand. The value of the second operand can be provided in the next box. Example: to raise all values to the power of 5, select @COPEN@Power@CCLOSE@ here and type @COPEN@5@CCLOSE@ in the box below." >
575 <expand macro="select_twovaluenumericoperator" />
576 </param>
577 <param name="scale_value" type="float" value="0" label="Second operand value" />
578 </when>
579 <when value="custom">
580 <param name="custom_expr" type="text" label="Custom expression on 'elem'"
581 help="The parameter name is @COPEN@elem@CCLOSE@, referring to the element being acted on. Most operators and @COPEN@if@CCLOSE@ @COPEN@else@CCLOSE@ statements are supported. See Examples #3 and #4 in the Help section.">
582 <expand macro="validator_functiondef" />
583 </param>
584 </when>
585 </conditional>
586 <conditional name="elem_val" >
587 <param name="element_op" type="select" label="Operate on elements"
588 help="Only selected elements will be manipulated. Other elements will retain their original value." >
589 <expand macro="select_twovaluebooleanops" >
590 <option value="None" selected="true">All</option>
591 <option value="rowcol" >Specific Rows and/or Columns</option>
592 </expand>
593 </param>
594 <when value="None" />
595 <expand macro="elem_val_macro" when="lt" />
596 <expand macro="elem_val_macro" when="le" />
597 <expand macro="elem_val_macro" when="gt" />
598 <expand macro="elem_val_macro" when="ge" />
599 <expand macro="elem_val_macro" when="eq" />
600 <expand macro="elem_val_macro" when="ne" />
601 <when value="rowcol" >
602 <expand macro="select_rowcols" />
603 <param name="inclusive_selection" type="boolean" truevalue="True" falsevalue="False" checked="true" label="Inclusive Selection" help="If enabled, all elements that match ANY row or column given above will be acted on. Otherwise, only the elements that match BOTH a row or column given above will be acted on." />
604 </when>
605 </conditional>
606 </when>
607 </conditional>
608 </when>
609 <when value="multiple">
610 <repeat name="tables" title="Tables" min="1" default="1">
611 <expand macro="file_opts" />
612 </repeat>
613 <param name="fulltable_custom_expr" type="text"
614 label="Custom expression on 'tableN'"
615 help="The parameter name is @COPEN@tableN@CCLOSE@, where @COPEN@N@CCLOSE@ refers to a specific table. e.g. @COPEN@table1 + table3 - table2@CCLOSE@, will add the first and third input tables and then subtract the second. Most operators and @COPEN@if@CCLOSE@ @COPEN@else@CCLOSE@ statements are supported. See Example #6 in the Help section for further examples.">
616 <expand macro="validator_functiondef" />
617 </param>
618 </when>
619 </conditional>
620 <param name="out_opts" type="select" display="checkboxes" multiple="true" optional="true"
621 label="Output formatting options">
622 <option value="ignore_nas" selected="true">Ignore NA values</option>
623 <option value="output_headers_col" selected="true">Output column headers</option>
624 <option value="output_headers_row" selected="true">Output row headers</option>
625 </param>
626 <param name="precision" type="integer" min="0" max="20" value="6" label="Output decimal precision" />
627 </inputs>
628 <outputs>
629 <data name="table" format="tabular" label="${tool.name} on ${on_string}" />
630 </outputs>
631 <tests>
632 <test expect_num_outputs="1">
633 <!-- Test 1: Select -->
634 <expand macro="test_inputs_single" >
635 <param name="mode" value="select" />
636 <param name="select_cols_wanted" value="2:4,2,2" />
637 <param name="select_rows_wanted" value="2:5,3,3" />
638 <param name="select_keepdupe" value="select_cols_keepdupe" />
639 </expand>
640 <param name="precision" value="2" />
641 <output name="table" value="small.select.tsv" />
642 </test>
643 <test expect_num_outputs="1">
644 <!-- Test 2: Select, cols only -->
645 <expand macro="test_inputs_single" >
646 <param name="mode" value="select" />
647 <param name="select_cols_wanted" value="2:4,2,2" />
648 <param name="select_keepdupe" value="select_cols_keepdupe,select_rows_keepdupe" />
649 </expand>
650 <param name="precision" value="2" />
651 <output name="table" value="small.select.colsonly.tsv" />
652 </test>
653 <test expect_num_outputs="1">
654 <!-- Test 3: Select, rows only -->
655 <expand macro="test_inputs_single" >
656 <param name="mode" value="select" />
657 <param name="select_rows_wanted" value="2:5,3,3" />
658 <param name="select_keepdupe" value="select_cols_keepdupe" />
659 </expand>
660 <param name="precision" value="2" />
661 <output name="table" value="small.select.rowsonly.tsv" />
662 </test>
663 <test expect_num_outputs="1">
664 <!-- Test 4: Filtersumval, row -->
665 <expand macro="test_inputs_single" >
666 <param name="mode" value="filtersumval" />
667 <param name="axis" value="1" />
668 <conditional name="filtersumval_mode" >
669 <param name="use" value="operation" />
670 <param name="operation" value="sum" />
671 <param name="compare_op" value="gt" />
672 <param name="against" value="50" />
673 </conditional>
674 </expand>
675 <param name="precision" value="2" />
676 <output name="table" value="small.fs.rowsum.gt.50.tsv" />
677 </test>
678 <test expect_num_outputs="1">
679 <!-- Test 5: Filtersumval, col neq 0 -->
680 <expand macro="test_inputs_single" >
681 <param name="mode" value="filtersumval" />
682 <param name="axis" value="0" />
683 <conditional name="filtersumval_mode" >
684 <param name="use" value="operation" />
685 <param name="operation" value="sum" />
686 <param name="compare_op" value="ne" />
687 <param name="against" value="0" />
688 </conditional>
689 </expand>
690 <param name="precision" value="2" />
691 <output name="table" value="small.fs.colsum.neq0.tsv" />
692 </test>
693 <test expect_num_outputs="1">
694 <!-- Test 6: Filtersumval, col val gt 10 -->
695 <expand macro="test_inputs_single" >
696 <param name="mode" value="filtersumval" />
697 <param name="axis" value="0" />
698 <conditional name="filtersumval_mode" >
699 <param name="use" value="operation" />
700 <param name="operation" value="sum" />
701 <param name="compare_op" value="gt" />
702 <param name="against" value="10" />
703 </conditional>
704 </expand>
705 <param name="precision" value="2" />
706 <output name="table" value="small.fs.colsum.gt10.tsv" />
707 </test>
708 <test expect_num_outputs="1">
709 <!-- Test 7: Filtersumval, median val col >= 2 -->
710 <expand macro="test_inputs_single" >
711 <param name="mode" value="filtersumval" />
712 <param name="axis" value="0" />
713 <conditional name="filtersumval_mode" >
714 <param name="use" value="operation" />
715 <param name="operation" value="median" />
716 <param name="compare_op" value="ge" />
717 <param name="against" value="2" />
718 </conditional>
719 </expand>
720 <param name="precision" value="5" />
721 <output name="table" value="small.fs.medvalcol.ge2.tsv" />
722 </test>
723 <test expect_num_outputs="1">
724 <!-- Test 8: Filtersumval, keep rows with at least
725 two values > 2 -->
726 <expand macro="test_inputs_single" >
727 <param name="mode" value="filtersumval" />
728 <param name="axis" value="1" />
729 <conditional name="filtersumval_mode" >
730 <param name="use" value="element" />
731 <param name="operation" value="gt" />
732 <param name="against" value="2" />
733 <param name="minmatch" value="2" />
734 </conditional>
735 </expand>
736 <param name="precision" value="5" />
737 <output name="table" value="small.fs.elemgt2.mm2.tsv" />
738 </test>
739 <test expect_num_outputs="1">
740 <!-- Test 9: Filtersumval, keep cols with at least
741 4 string values matching "0" -->
742 <expand macro="test_inputs_single" >
743 <param name="mode" value="filtersumval" />
744 <param name="axis" value="0" />
745 <conditional name="filtersumval_mode" >
746 <param name="use" value="element" />
747 <param name="operation" value="str_ne" />
748 <param name="against" value="0" />
749 <param name="minmatch" value="4" />
750 </conditional>
751 </expand>
752 <param name="precision" value="3" />
753 <output name="table" value="small.fs.elemnmatch0.mm4.tsv" />
754 </test>
755 <test expect_num_outputs="1">
756 <!-- Test 10: Matrix Apply, row max -->
757 <expand macro="test_inputs_single" >
758 <param name="mode" value="matrixapply" />
759 <param name="dimension" value="1" />
760 <conditional name="matrixapply_func" >
761 <param name="vector_op" value="max" />
762 </conditional>
763 </expand>
764 <param name="precision" value="0" />
765 <param name="out_opts" value="ignore_nas,output_headers_row" />
766 <output name="table" value="small.matapp.rowmax.tsv" />
767 </test>
768 <test expect_num_outputs="1">
769 <!-- Test 11: Element, all, scale, remainder 5 -->
770 <expand macro="test_inputs_single" >
771 <param name="mode" value="element" />
772 <conditional name="elem_val">
773 <param name="element_op" value="None" />
774 </conditional>
775 <conditional name="element" >
776 <param name="mode" value="scale" />
777 <param name="scale_op" value="mod" />
778 <param name="scale_value" value="5" />
779 </conditional>
780 </expand>
781 <param name="precision" value="2" />
782 <output name="table" value="small.element.scalerem5.tsv" />
783 </test>
784 <test expect_num_outputs="1">
785 <!-- Test 12: Matrix Apply, column custom -->
786 <expand macro="test_inputs_single" >
787 <param name="mode" value="matrixapply" />
788 <param name="dimension" value="0" />
789 <conditional name="matrixapply_func" >
790 <param name="vector_op" value="custom" />
791 <param name="custom_func" value="vec.sum()+vec.median()" />
792 </conditional>
793 </expand>
794 <param name="precision" value="2" />
795 <param name="out_opts" value="ignore_nas,output_headers_row" />
796 <output name="table" value="small.matapp.colcust.tsv" />
797 </test>
798 <test expect_num_outputs="1">
799 <!-- Test 13: Element, non-zero, custom -->
800 <expand macro="test_inputs_single" >
801 <param name="mode" value="element" />
802 <conditional name="elem_val">
803 <param name="element_op" value="gt" />
804 <param name="element_value" value="0" />
805 </conditional>
806 <conditional name="element" >
807 <param name="mode" value="custom" />
808 <!-- valid complex expression for non-zero vals -->
809 <param name="custom_expr" value="(math.log10(elem)+elem)/elem if (elem < math.inf) else 1.0" />
810 </conditional>
811 </expand>
812 <output name="table" value="small.element.custom.tsv" />
813 </test>
814 <test expect_num_outputs="1">
815 <!-- Test 14: umi2transcript test1 -->
816 <conditional name="singtabop">
817 <param name="use_type" value="single" />
818 <param name="input" value="mat1.umi.tsv" />
819 <expand macro="umi2trans" >
820 <output name="table" value="mat1.trans.tsv" />
821 </expand>
822 </conditional>
823 </test>
824 <test expect_num_outputs="1">
825 <!-- Test 15: umi2transcript test2 -->
826 <conditional name="singtabop">
827 <param name="use_type" value="single" />
828 <param name="input" value="mat2.umi.tsv" />
829 <expand macro="umi2trans" >
830 <output name="table" value="mat2.trans.tsv" />
831 </expand>
832 </conditional>
833 </test>
834 <test expect_num_outputs="1">
835 <!-- Test 16: B-test - mean and sd in custom func -->
836 <expand macro="test_inputs_single" >
837 <param name="mode" value="fulltable" />
838 <conditional name="general" >
839 <param name="use" value="custom" />
840 <param name="fulltable_custom_expr"
841 value="table - table.mean(0) / table.std(0)" />
842 </conditional>
843 </expand>
844 <output name="table" value="small.fulltable.tsv" />
845 </test>
846 <test expect_num_outputs="1">
847 <!-- Test 17: Multiple table test -->
848 <conditional name="singtabop" >
849 <param name="use_type" value="multiple" />
850 <repeat name="tables">
851 <param name="input" value="small.tsv" />
852 </repeat>
853 <repeat name="tables">
854 <param name="input" value="small.tsv" />
855 </repeat>
856 <repeat name="tables">
857 <param name="input" value="small.tsv" />
858 </repeat>
859 <param name="fulltable_custom_expr" value="(3 * table1) + np.log(table3 + 20) - table2" /> </conditional>
860 <output name="table" value="small.multiple.tsv" />
861 </test>
862 <!-- User tests that failed previously -->
863 <test expect_num_outputs="1">
864 <!-- Test 18 -->
865 <expand macro="test_inputs_single" >
866 <param name="mode" value="fulltable" />
867 <conditional name="general" >
868 <param name="use" value="custom" />
869 <param name="fulltable_custom_expr" value="table * 2" />
870 </conditional>
871 </expand>
872 <output name="table" >
873 <assert_contents>
874 <has_n_columns n="10" />
875 <has_line_matching expression="^gene1\s20\.000000\s0\s12\s-20\.200000\s20\s2\.200000\s0\.000000\s0\s0\.000000$" />
876 <has_line_matching expression="gene5\s2\.000000\s0\s0\s-20\.000000\s880\s12\.000000\s0\.000000\s0\s3\.800000" />
877 </assert_contents>
878 </output>
879 </test>
880 <test expect_num_outputs="1">
881 <!-- Test 19 -->
882 <expand macro="test_inputs_single" >
883 <param name="mode" value="fulltable" />
884 <conditional name="general" >
885 <param name="use" value="custom" />
886 <param name="fulltable_custom_expr" value="table == 5" />
887 </conditional>
888 </expand>
889 <output name="table" >
890 <assert_contents>
891 <has_n_columns n="10" />
892 <has_line_matching expression="^gene1(\sFalse)+$" />
893 <has_line_matching expression="gene5(\sFalse)+$" />
894 </assert_contents>
895 </output>
896 </test>
897 <test expect_num_outputs="1">
898 <!-- Test 20: Transpose -->
899 <expand macro="test_inputs_single" >
900 <param name="mode" value="fulltable" />
901 <conditional name="general" >
902 <param name="use" value="transpose" />
903 </conditional>
904 </expand>
905 <param name="out_opts" value="ignore_nas,output_headers_col" />
906 <output name="table" >
907 <assert_contents>
908 <has_n_columns n="5" />
909 </assert_contents>
910 </output>
911 </test>
912 <test expect_num_outputs="1">
913 <!-- Test 21: Melt -->
914 <expand macro="test_inputs_single" >
915 <param name="mode" value="fulltable" />
916 <conditional name="general" >
917 <param name="use" value="melt" />
918 <param name="id_vars" value="cell1,cell3" />
919 <param name="value_vars" value="cell5,cell6" />
920 </conditional>
921 </expand>
922 <param name="out_opts" value="ignore_nas,output_headers_col" />
923 <output name="table" >
924 <assert_contents>
925 <has_n_columns n="4" />
926 <has_line_matching expression="^cell1\scell3\svariable\svalue$" />
927 <has_line_matching expression="^1\.0+\s0+\scell6\s6\.0+$" />
928 </assert_contents>
929 </output>
930 </test>
931 <test expect_num_outputs="1">
932 <!-- Test 22: Pivot -->
933 <expand macro="test_inputs_single" >
934 <param name="mode" value="fulltable" />
935 <conditional name="general" >
936 <param name="use" value="pivot" />
937 <param name="index" value="cell1" />
938 <param name="column" value="cell2" />
939 <param name="values" value="cell3,cell7,cell9" />
940 </conditional>
941 </expand>
942 <output name="table" >
943 <assert_contents>
944 <has_n_columns n="4" />
945 <has_line_matching expression="^\scell3\scell7\scell9$" />
946 <has_line_matching expression="^1\.0+\s0\.0+\s0\.0+\s1\.90+$" />
947 <has_line_matching expression="^10\.0+\s6\.0+\s0\.0+\s0\.0+$" />
948 </assert_contents>
949 </output>
950 </test>
951 <!-- Add Example Text Tests -->
952 <test expect_num_outputs="1" >
953 <!-- Test 23: Ex 1 -->
954 <conditional name="singtabop" >
955 <param name="use_type" value="single" />
956 <param name="input" value="examples.1.tsv" />
957 <param name="col_row_names" value="has_col_names,has_row_names" />
958 <conditional name="user" >
959 <param name="mode" value="select" />
960 <param name="select_cols_wanted" value="1,1,3" />
961 <param name="select_rows_wanted" value="1:3,2" />
962 <param name="select_keepdupe" value="select_cols_keepdupe,select_rows_keepdupe" />
963 </conditional>
964 </conditional>
965 <output name="table" >
966 <assert_contents>
967 <has_n_columns n="4" />
968 <has_line_matching expression="^\s+c1\s+c1\s+c3$" />
969 <has_line_matching expression="^g2\s+3\s+3\s+9$" />
970 </assert_contents>
971 </output>
972 </test>
973 <test expect_num_outputs="1" >
974 <!-- Test 24: Ex 2 -->
975 <conditional name="singtabop" >
976 <param name="use_type" value="single" />
977 <param name="input" value="examples.2.tsv" />
978 <param name="col_row_names" value="has_col_names,has_row_names" />
979 <conditional name="user" >
980 <param name="mode" value="filtersumval" />
981 <param name="axis" value="1" />
982 <conditional name="filtersumval_mode" >
983 <param name="use" value="operation" />
984 <param name="operation" value="sum" />
985 <param name="compare_op" value="lt" />
986 <param name="against" value="50" />
987 </conditional>
988 </conditional>
989 </conditional>
990 <output name="table" >
991 <assert_contents>
992 <has_n_columns n="4" />
993 <has_line_matching expression="^\s+c1\s+c2\s+c3$" />
994 <has_line_matching expression="^g3\s+4\s+8\s+12$" />
995 </assert_contents>
996 </output>
997 </test>
998 <test expect_num_outputs="1" >
999 <!-- Test 25: Ex 3_P1 -->
1000 <conditional name="singtabop" >
1001 <param name="use_type" value="single" />
1002 <param name="input" value="examples.3p1.tsv" />
1003 <param name="col_row_names" value="has_col_names,has_row_names" />
1004 <conditional name="user" >
1005 <param name="mode" value="element" />
1006 <conditional name="element" >
1007 <param name="mode" value="custom" />
1008 <param name="custom_expr" value="elem < 10" />
1009 </conditional>
1010 <conditional name="elem_val" >
1011 <param name="element_op" value="None" />
1012 </conditional>
1013 </conditional>
1014 </conditional>
1015 <output name="table" >
1016 <assert_contents>
1017 <has_n_columns n="4" />
1018 <has_line_matching expression="^g1\s+False\s+False\s+False$" />
1019 <has_line_matching expression="^g4\s+False\s+True\s+True$" />
1020 </assert_contents>
1021 </output>
1022 </test>
1023 <test expect_num_outputs="1" >
1024 <!-- Test 26: Ex 3_P2 -->
1025 <conditional name="singtabop" >
1026 <param name="use_type" value="single" />
1027 <param name="input" value="examples.3p2.tsv" />
1028 <param name="col_row_names" value="has_col_names,has_row_names" />
1029 <conditional name="user" >
1030 <param name="mode" value="matrixapply" />
1031 <param name="dimension" value="1" />
1032 <conditional name="matrixapply_func" >
1033 <param name="vector_op" value="sum" />
1034 </conditional>
1035 </conditional>
1036 </conditional>
1037 <output name="table" >
1038 <assert_contents>
1039 <has_n_columns n="2" />
1040 <has_line_matching expression="^g1\s+0$" />
1041 <has_line_matching expression="^g4\s+2$" />
1042 </assert_contents>
1043 </output>
1044 </test>
1045 <test expect_num_outputs="1" >
1046 <!-- Test 27: Ex 4 -->
1047 <conditional name="singtabop" >
1048 <param name="use_type" value="single" />
1049 <param name="input" value="examples.4.tsv" />
1050 <param name="col_row_names" value="has_col_names,has_row_names" />
1051 <conditional name="user" >
1052 <param name="mode" value="element" />
1053 <conditional name="element" >
1054 <param name="mode" value="custom" />
1055 <param name="custom_expr" value="(math.log(elem) / elem) if (elem > 5) else 1" />
1056 </conditional>
1057 <conditional name="elem_val" >
1058 <param name="element_op" value="None" />
1059 </conditional>
1060 </conditional>
1061 </conditional>
1062 <output name="table" >
1063 <assert_contents>
1064 <has_n_columns n="4" />
1065 <has_line_matching expression="^g1\s+1\.00\d+\s+0\.149\d+\s+0\.113\d+$" />
1066 <has_line_matching expression="^g4\s+0\.05\d+\s+1\.000\d+\s+1\.000\d+$" />
1067 </assert_contents>
1068 </output>
1069 </test>
1070 <test expect_num_outputs="1" >
1071 <!-- Test 28: Ex 5 -->
1072 <conditional name="singtabop" >
1073 <param name="use_type" value="single" />
1074 <param name="input" value="examples.5.tsv" />
1075 <param name="col_row_names" value="has_col_names,has_row_names" />
1076 <conditional name="user" >
1077 <param name="mode" value="fulltable" />
1078 <conditional name="general" >
1079 <param name="use" value="custom" />
1080 <param name="fulltable_custom_expr" value="table - table.mean(0)/table.std(0)" />
1081 </conditional>
1082 </conditional>
1083 </conditional>
1084 <output name="table" >
1085 <assert_contents>
1086 <has_n_columns n="4" />
1087 <has_line_matching expression="^g1\s+9\.\d+\s+17\.\d+\s+28\.\d+$" />
1088 <has_line_matching expression="^g4\s+80\.\d+\s+7\.\d+\s+8\.\d+$" />
1089 </assert_contents>
1090 </output>
1091 </test>
1092 <test expect_num_outputs="1" >
1093 <!-- Test 29: Ex 6 -->
1094 <conditional name="singtabop" >
1095 <param name="use_type" value="multiple" />
1096 <repeat name="tables" >
1097 <param name="input" value="examples.6p1.tsv" />
1098 <param name="col_row_names" value="has_col_names,has_row_names" />
1099 </repeat>
1100 <repeat name="tables" >
1101 <param name="input" value="examples.6p2.tsv" />
1102 <param name="col_row_names" value="has_col_names,has_row_names" />
1103 </repeat>
1104 <repeat name="tables" >
1105 <param name="input" value="examples.6p3.tsv" />
1106 <param name="col_row_names" value="has_col_names,has_row_names" />
1107 </repeat>
1108 <param name="fulltable_custom_expr" value="table1 / min(np.max(np.max(table2)), np.max(np.max(table3)))" />
1109 </conditional>
1110 <output name="table" >
1111 <assert_contents>
1112 <has_n_columns n="4" />
1113 <has_line_matching expression="^g1\s+3\.3\d+\s+6\.6\d+\s+10\.0\d+$" />
1114 <has_line_matching expression="^g3\s+1\.3\d+\s+2\.6\d+\s+3\.3\d+$" />
1115 </assert_contents>
1116 </output>
1117 </test>
1118 <test expect_num_outputs="1" >
1119 <!-- Test 30: Ex 7 -->
1120 <conditional name="singtabop" >
1121 <param name="use_type" value="single" />
1122 <param name="input" value="examples.7.tsv" />
1123 <param name="col_row_names" value="has_col_names,has_row_names" />
1124 <conditional name="user">
1125 <param name="mode" value="fulltable" />
1126 <conditional name="general" >
1127 <param name="use" value="melt" />
1128 <param name="id_vars" value="A" />
1129 <param name="value_vars" value="B,C" />
1130 </conditional>
1131 </conditional>
1132 </conditional>
1133 <output name="table" >
1134 <assert_contents>
1135 <has_n_columns n="4" />
1136 <has_line_matching expression="^0\s+a\s+B\s+B\s*$" />
1137 <has_line_matching expression="^5\s+c\s+C\s+5\s*$" />
1138 </assert_contents>
1139 </output>
1140 </test>
1141 <test expect_num_outputs="1" >
1142 <!-- Test 31: Ex 8 -->
1143 <conditional name="singtabop" >
1144 <param name="use_type" value="single" />
1145 <param name="input" value="examples.8.tsv" />
1146 <param name="col_row_names" value="has_col_names,has_row_names" />
1147 <conditional name="user" >
1148 <param name="mode" value="fulltable" />
1149 <conditional name="general" >
1150 <param name="use" value="pivot" />
1151 <param name="index" value="foo" />
1152 <param name="column" value="bar" />
1153 <param name="values" value="baz" />
1154 </conditional>
1155 </conditional>
1156 </conditional>
1157 <output name="table" >
1158 <assert_contents>
1159 <has_n_columns n="4" />
1160 <has_line_matching expression="^one\s+1\s+2\s+3$" />
1161 <has_line_matching expression="^two\s+4\s+5\s+6$" />
1162 </assert_contents>
1163 </output>
1164 </test>
1165 <test expect_num_outputs="1" >
1166 <!-- Test 32: Negative range test #1 -->
1167 <expand macro="test_inputs_ranges" >
1168 <param name="select_cols_wanted" value="-2:2,1,-1" />
1169 <param name="select_rows_wanted" value="1,3:-3,1" />
1170 </expand>
1171 <output name="table" >
1172 <assert_contents>
1173 <has_n_columns n="7" />
1174 <has_line_matching expression="^\s*c2\s+c3\s+c1\s+c2\s+c1\s+c3$" />
1175 <has_line_matching expression="^g1\s+20\s+30\s+10\s+20\s+10\s+30$" />
1176 </assert_contents>
1177 </output>
1178 </test>
1179 <test expect_num_outputs="1" >
1180 <!-- Test 33: Negative range test #2 -->
1181 <expand macro="test_inputs_ranges" >
1182 <param name="select_cols_wanted" value="-1,-3,3:-3,2" />
1183 <param name="select_rows_wanted" value="3:-1" />
1184 <param name="select_keepdupe" value_json="[]" />
1185 </expand>
1186 <output name="table" >
1187 <assert_contents>
1188 <has_n_columns n="7" />
1189 <has_line_matching expression="^\s*c3\s+c1\s+c3\s+c2\s+c1\s+c2$" />
1190 <has_line_matching expression="^g4\s+3\s+81\s+3\s+6\s+81\s+6$" />
1191 </assert_contents>
1192 </output>
1193 </test>
1194 <test expect_num_outputs="1">
1195 <!-- Test 34: Skip first 3 lines -->
1196 <conditional name="singtabop" >
1197 <param name="use_type" value="single" />
1198 <param name="input" value="skiplines.tsv" ftype="tabular" />
1199 <section name="adv" >
1200 <param name="header" value="2" />
1201 <param name="nrows" value="4" />
1202 <param name="skip_blank_lines" value="true" />
1203 </section>
1204 <conditional name="user" >
1205 <param name="mode" value="precision" />
1206 </conditional>
1207 </conditional>
1208 <param name="precision" value="2" />
1209 <output name="table" >
1210 <assert_contents>
1211 <has_n_columns n="4" />
1212 <has_line_matching expression="^\s+c1\s+c2\s+c3$" />
1213 <has_line_matching expression="^g4\s+81\s+6\s+3$" />
1214 </assert_contents>
1215 </output>
1216 </test>
1217 <test expect_num_outputs="1">
1218 <!-- Test 35: Skip first 3 lines -->
1219 <conditional name="singtabop" >
1220 <param name="use_type" value="single" />
1221 <param name="input" value="skiplines.tsv" ftype="tabular" />
1222 <section name="adv" >
1223 <param name="header" value="2" />
1224 <param name="skipfooter" value="2" />
1225 <param name="skip_blank_lines" value="false" />
1226 </section>
1227 <conditional name="user" >
1228 <param name="mode" value="precision" />
1229 </conditional>
1230 </conditional>
1231 <param name="precision" value="2" />
1232 <param name="out_opts" value_json="[]" />
1233 <output name="table" >
1234 <assert_contents>
1235 <has_n_columns n="3" />
1236 <has_line_matching expression="^10.00\s+20.00\s+30.00$" />
1237 <has_line_matching expression="^\s+$" />
1238 </assert_contents>
1239 </output>
1240 </test>
1241 <test expect_num_outputs="1" >
1242 <!-- Test 36: Row Col replace with format spec #1 -->
1243 <conditional name="singtabop" >
1244 <param name="use_type" value="single" />
1245 <param name="input" value="examples.1.tsv" />
1246 <param name="col_row_names" value="has_col_names,has_row_names" />
1247 <conditional name="user" >
1248 <param name="mode" value="element" />
1249 <conditional name="element" >
1250 <param name="mode" value="replace" />
1251 <param name="replace_value" value="chr{elem:.0f}" />
1252 </conditional>
1253 <conditional name="elem_val" >
1254 <param name="element_op" value="rowcol" />
1255 <param name="select_cols_wanted" value="2" />
1256 <param name="select_rows_wanted" value="2,4" />
1257 <param name="inclusive_selection" value="True" />
1258 </conditional>
1259 </conditional>
1260 </conditional>
1261 <output name="table" >
1262 <assert_contents>
1263 <has_n_columns n="4" />
1264 <has_line_matching expression="^g2\s+chr3\s+chr6\s+chr9$" />
1265 <has_line_matching expression="^g4\s+chr81\s+chr6\s+chr3$" />
1266 </assert_contents>
1267 </output>
1268 </test>
1269 <test expect_num_outputs="1" >
1270 <!-- Test 37: Row Col replace with format spec #2 -->
1271 <conditional name="singtabop" >
1272 <param name="use_type" value="single" />
1273 <param name="input" value="examples.1.tsv" />
1274 <param name="col_row_names" value="has_col_names,has_row_names" />
1275 <conditional name="user" >
1276 <param name="mode" value="element" />
1277 <conditional name="element" >
1278 <param name="mode" value="replace" />
1279 <param name="replace_value" value="chr{elem:.0f}" />
1280 </conditional>
1281 <conditional name="elem_val" >
1282 <param name="element_op" value="rowcol" />
1283 <param name="select_cols_wanted" value="2" />
1284 <param name="select_rows_wanted" value="2,4" />
1285 <param name="inclusive_selection" value="False" />
1286 </conditional>
1287 </conditional>
1288 </conditional>
1289 <output name="table" >
1290 <assert_contents>
1291 <has_n_columns n="4" />
1292 <has_line_matching expression="^g2\s+3\s+chr6\s+9$" />
1293 <has_line_matching expression="^g4\s+81\s+chr6\s+3$" />
1294 </assert_contents>
1295 </output>
1296 </test>
1297 <test expect_num_outputs="1">
1298 <!-- Test 38: Test safety of Replacement value free text
1299 Tries to escape/reenter config file quoting.
1300 If the test fails, this shows that Python has performed
1301 string concatenation upon importing the config file. -->
1302 <conditional name="singtabop" >
1303 <param name="use_type" value="single" />
1304 <param name="input" value="examples.1.tsv" />
1305 <param name="col_row_names" value="has_col_names,has_row_names" />
1306 <conditional name="user" >
1307 <param name="mode" value="element" />
1308 <conditional name="elem_val">
1309 <param name="element_op" value="None" />
1310 </conditional>
1311 <conditional name="element" >
1312 <param name="mode" value="replace" />
1313 <param name="replace_value" value="a'+'b" />
1314 </conditional>
1315 </conditional>
1316 </conditional>
1317 <output name="table" >
1318 <assert_contents>
1319 <has_n_columns n="4" />
1320 <not_has_text text="g1	ab" />
1321 <not_has_text text="g2	ab" />
1322 <not_has_text text="g3	ab" />
1323 <not_has_text text="g4	ab" />
1324 </assert_contents>
1325 </output>
1326 </test>
1327 <test expect_num_outputs="1" >
1328 <!-- Pivot aggregator operations -->
1329 <conditional name="singtabop" >
1330 <param name="use_type" value="single" />
1331 <param name="input" value="pivot.tsv" />
1332 <param name="col_row_names" value="has_col_names,has_row_names" />
1333 <conditional name="user" >
1334 <param name="mode" value="fulltable" />
1335 <conditional name="general" >
1336 <param name="use" value="pivot" />
1337 <param name="index" value="Position" />
1338 <repeat name="colfun_map" >
1339 <param name="column" value="Age" />
1340 <repeat name="functions"><param name="aggfunc" value="mean" /></repeat>
1341 </repeat>
1342 <repeat name="colfun_map" >
1343 <param name="column" value="Random" />
1344 <repeat name="functions"><param name="aggfunc" value="mean" /></repeat>
1345 <repeat name="functions"><param name="aggfunc" value="std" /></repeat>
1346 </repeat>
1347 </conditional>
1348 </conditional>
1349 </conditional>
1350 <output name="table" >
1351 <assert_contents>
1352 <has_n_columns n="4" />
1353 <has_line_matching expression="^Manager\s+34.3\d+\s+0.325\d+\s+0.306\d+" />
1354 <has_line_matching expression="^Programmer\s+32.3\d+\s+0.423\d+\s+0.477\d+" />
1355 </assert_contents>
1356 </output>
1357 </test>
1358 <test expect_num_outputs="1" >
1359 <!-- Pivot table operations from PR 3480 -->
1360 <conditional name="singtabop" >
1361 <param name="use_type" value="single" />
1362 <param name="input" value="table1.tsv" />
1363 <param name="col_row_names" value="has_col_names" />
1364 <conditional name="user" >
1365 <param name="mode" value="fulltable" />
1366 <conditional name="general" >
1367 <param name="use" value="pivot" />
1368 <param name="index" value="A" />
1369 <param name="column" value="C" />
1370 <param name="values" value="D" />
1371 <param name="aggfunc" value="max" />
1372 </conditional>
1373 </conditional>
1374 </conditional>
1375 <output name="table" >
1376 <assert_contents>
1377 <has_text_matching expression="bar\t7\t6" />
1378 </assert_contents>
1379 </output>
1380 </test>
1381 </tests>
1382 <help><![CDATA[
1383Table Compute
1384-------------
1385
1386This tool is a Galaxy wrapper for the `Pandas Data Analysis Library <https://pandas.pydata.org/>`_ in Python,
1387for manipulating and computing expressions upon tabular data and matrices. It can perform functions on the
1388element, row, and column basis, as well as sub-select, duplicate, replace, and perform general and custom
1389expressions on rows, columns, and elements.
1390
1391
1392.. class:: infomark
1393
1394 Only a single operation can be performed on the data. Multiple operations
1395 can be performed by chaining successive runs of this tool. This is to
1396 provide a more transparent workflow for complex operations.
1397
1398
1399Many of the examples given below relate to common research use-cases such as filtering large matrices for
1400specific values, counting unique instances of elements, conditionally manipulating the data, and replacing
1401unwanted values. Full table operations such as normalisation can be easily performed by scaling the data via
1402mean/median/min/max (and many other) metrics, and general expressions can even be computed across multiple
1403tables.
1404
1405
1406Examples
1407========
1408
1409Example 1: Sub-selecting from a table
1410~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1411
1412We have the following table:
1413
1414 === === === ===
1415 . c1 c2 c3
1416 === === === ===
1417 g1 10 20 30
1418 g2 3 6 9
1419 g3 4 8 12
1420 g4 81 6 3
1421 === === === ===
1422
1423and we want to duplicate c1 and remove c2. Also select g1 to g3 and add g2 at the end as well. This
1424 would result in the output table:
1425
1426 === === === ===
1427 . c1 c1 c3
1428 === === === ===
1429 g1 10 10 30
1430 g2 3 3 9
1431 g3 4 4 12
1432 g2 3 3 9
1433 === === === ===
1434
1435In Galaxy we would select the following:
1436
1437 * *Input Single or Multiple Tables* → **Single Table**
1438 * *Column names on first row?* → **Yes**
1439 * *Row names on first column?* → **Yes**
1440 * *Type of table operation* → **Drop, keep or duplicate rows and columns**
1441
1442 * *List of columns to select* → ``1,1,3``
1443 * *List of rows to select* → ``1:3,2``
1444 * *Keep duplicate columns* → **Yes**
1445 * *Keep duplicate rows* → **Yes**
1446
1447Example 2: Filter for rows with row sums less than 50
1448~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1449
1450We have the following table:
1451
1452 === === === ===
1453 . c1 c2 c3
1454 === === === ===
1455 g1 10 20 30
1456 g2 3 6 9
1457 g3 4 8 12
1458 g4 81 6 3
1459 === === === ===
1460
1461and we want:
1462
1463 === === === ===
1464 . c1 c2 c3
1465 === === === ===
1466 g2 3 6 9
1467 g3 4 8 12
1468 === === === ===
1469
1470In Galaxy we would select the following:
1471
1472 * *Input Single or Multiple Tables* → **Single Table**
1473 * *Column names on first row?* → **Yes**
1474 * *Row names on first column?* → **Yes**
1475 * *Type of table operation* → **Filter rows or columns by their properties**
1476
1477 * *Filter* → **Rows**
1478 * *Filter Criterion* → **Result of function applied to columns/rows**
1479
1480 * *Keep column/row if its observed* → **Sum**
1481 * *is* → **< (Less Than)**
1482 * *this value* → ``50``
1483
1484
1485Example 3: Count the number of values per row smaller than a specified value
1486~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1487
1488We have the following table:
1489
1490 === === === ===
1491 . c1 c2 c3
1492 === === === ===
1493 g1 10 20 30
1494 g2 3 6 9
1495 g3 4 8 12
1496 g4 81 6 3
1497 === === === ===
1498
1499and we want to count how many elements in each row are smaller than 10, i.e.,
1500we want to obtain the following results table:
1501
1502 === ===
1503 . vec
1504 === ===
1505 g1 0
1506 g2 3
1507 g3 2
1508 g4 2
1509 === ===
1510
1511In Galaxy we would select the following:
1512
1513 * *Input Single or Multiple Tables* → **Single Table**
1514 * *Column names on first row?* → **Yes**
1515 * *Row names on first column?* → **Yes**
1516 * *Type of table operation* → **Manipulate selected table elements**
1517
1518 * *Operation to perform* → **Custom**
1519
1520 * *Custom Expression on 'elem'* → ``elem < 10``
1521
1522 * *Operate on elements* → **All**
1523
1524**Note:** *There are actually simpler ways to achieve our purpose, but here we are demonstrating
1525the use of a custom expression.*
1526
1527After executing, we would then be presented with a table like so:
1528
1529 === ===== ===== =====
1530 . c1 c2 c3
1531 === ===== ===== =====
1532 g1 False False False
1533 g2 True True True
1534 g3 True True False
1535 g4 False True True
1536 === ===== ===== =====
1537
1538To get to our desired table, we would then process this table with the tool again:
1539
1540 * *Input Single or Multiple Tables* → **Single Table**
1541 * *Column names on first row?* → **Yes**
1542 * *Row names on first column?* → **Yes**
1543 * *Type of table operation* → **Compute Expression across Rows or Columns**
1544
1545 * *Calculate* → **Sum**
1546 * *For each* → **Row**
1547
1548Executing this will sum all the 'True' values in each row. Note that the values must have no
1549extra whitespace in them for this to work (e.g. 'True ' or ' True' will not be parsed correctly).
1550
1551
1552Example 4: Perform a scaled log-transformation conditionally
1553~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1554
1555We want to perform a scaled log transformation on all values greater than 5, and set all
1556other values to 1.
1557
1558We have the following table:
1559
1560 === === === ===
1561 . c1 c2 c3
1562 === === === ===
1563 g1 0 20 30
1564 g2 3 0 9
1565 g3 4 8 0
1566 g4 81 0 0
1567 === === === ===
1568
1569and we want:
1570
1571 === ========== ========= =========
1572 . c1 c2 c3
1573 === ========== ========= =========
1574 g1 1.00000000 0.1497866 0.1133732
1575 g2 1.00000000 1.0000000 0.2441361
1576 g3 1.00000000 0.2599302 1.0000000
1577 g4 0.05425246 1.0000000 1.0000000
1578 === ========== ========= =========
1579
1580In Galaxy we would select the following:
1581
1582 * *Input Single or Multiple Tables* → **Single Table**
1583 * *Column names on first row?* → **Yes**
1584 * *Row names on first column?* → **Yes**
1585 * *Type of table operation* → **Manipulate selected table elements**
1586
1587 * *Operation to perform* → **Custom**
1588
1589 * *Custom Expression* → ``(math.log(elem) / elem) if (elem > 5) else 1``
1590
1591 * *Operate on elements* → **All**
1592
1593
1594Example 5: Perform a Full table operation
1595~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1596
1597We have the following table:
1598
1599 === === === ===
1600 . c1 c2 c3
1601 === === === ===
1602 g1 10 20 30
1603 g2 3 10 9
1604 g3 4 8 10
1605 g4 81 10 10
1606 === === === ===
1607
1608and we want to subtract from each column the mean of that column divided by the standard
1609 deviation of it to yield:
1610
1611
1612 === ========= ========= =========
1613 . c1 c2 c3
1614 === ========= ========= =========
1615 g1 9.351737 17.784353 28.550737
1616 g2 2.351737 7.784353 7.550737
1617 g3 3.351737 5.784353 8.550737
1618 g4 80.351737 7.784353 8.550737
1619 === ========= ========= =========
1620
1621In Galaxy we would select the following:
1622
1623 * *Input Single or Multiple Tables* → **Single Table**
1624 * *Column names on first row?* → **Yes**
1625 * *Row names on first column?* → **Yes**
1626 * *Type of table operation* → **Perform a Full Table Operation**
1627
1628 * *Operation* → **Custom**
1629 * *Custom Expression on 'table' along axis (0 or 1)* → ``table - table.mean(0)/table.std(0)``
1630
1631
1632Example 6: Perform operations on multiple tables
1633~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1634
1635We have the following three input tables:
1636
1637Table 1
1638
1639 === === === ===
1640 . c1 c2 c3
1641 === === === ===
1642 g1 10 20 30
1643 g2 3 10 9
1644 g3 4 8 10
1645 === === === ===
1646
1647Table 2
1648
1649 === === ===
1650 . c1 c2
1651 === === ===
1652 g1 1 2
1653 g2 3 4
1654 g3 6 5
1655 === === ===
1656
1657Table 3
1658
1659 === === === ===
1660 . c1 c2 c3
1661 === === === ===
1662 g1 1 2 3
1663 g2 1 2 3
1664 === === === ===
1665
1666
1667*Note that the dimensions of these tables do not match.*
1668
1669Dimensions:
1670 * Table1 [3,3]
1671 * Table2 [3,2]
1672 * Table3 [2,3]
1673
1674In order to perform simple operations between Tables, they must be of the same dimensions.
1675
1676To add Table2 to Table3 we would have to transpose one of the tables using the in-built `T` method::
1677
1678 table2 + table3.T
1679
1680or::
1681
1682 table2.T + table3
1683
1684We can also perform more general operations using all 3 tables, such as taking the minimum value of
1685the maximum values of Table2 and Table3, and dividing the Table1 values by it::
1686
1687 table1 / min(table2.values.max(), table3.values.max())
1688
1689
1690To perform these types of operations in Galaxy we would select the following:
1691
1692 * *Input Single or Multiple Tables* → **Multiple Tables**
1693 * *(For each inserted table)*
1694 * *Column names on first row?* → **Yes**
1695 * *Row names on first column?* → **Yes**
1696 * *Custom Expression* → ::
1697
1698 <insert your desired function>
1699
1700Please note that the last example shown above was chosen to illustrate the
1701limitations of the tool. Nested attributes like `table2.values.max` are
1702disallowed in expressions in the tool so the above would have to be replaced
1703with the harder to read workaround::
1704
1705 table1 / min(np.max(np.max(table2)), np.max(np.max(table3)))
1706
1707.. class:: infomark
1708
1709 Complex operations (like ones that would benefit from specifying nested
1710 attributes) can often be broken into subsequent runs ot the tool, in
1711 which the first run generates an intermediate table representing the result
1712 of the "inner" operation that the second run can then use as input to
1713 perform the "outer" operation.
1714
1715Also note that, currently `min()`, `max()` and `sum()` are the only built-in
1716Python functions that can be used inside expressions. If you want to use
1717additional functions, these have to be qualified functions from the `math`,
1718`np` or `pd` libraries.
1719
1720
1721Example 7: Melt
1722~~~~~~~~~~~~~~~
1723
1724We have the following table
1725
1726 === === === ===
1727 . A B C
1728 === === === ===
1729 0 a B 1
1730 1 b B 3
1731 2 c B 5
1732 === === === ===
1733
1734and we want:
1735
1736 === === ======== =====
1737 . A variable value
1738 === === ======== =====
1739 0 a B B
1740 1 b B B
1741 2 c B B
1742 3 a C 1
1743 4 b C 3
1744 5 c C 5
1745 === === ======== =====
1746
1747
1748In Galaxy we would select the following:
1749
1750 * *Input Single or Multiple Tables* → **Single Table**
1751 * *Column names on first row?* → **Yes**
1752 * *Row names on first column?* → **Yes**
1753 * *Type of table operation* → **Perform a Full Table Operation**
1754
1755 * *Operation* → **Melt**
1756 * *Variable IDs* → ``A``
1757 * *Unpivoted IDs* → ``B,C``
1758
1759This converts the "B" and "C" columns into variables.
1760
1761
1762Example 8: Pivot
1763~~~~~~~~~~~~~~~~
1764
1765We have the following table
1766
1767 === === === === ===
1768 . foo bar baz zoo
1769 === === === === ===
1770 0 one A 1 x
1771 1 one B 2 y
1772 2 one C 3 z
1773 3 two A 4 q
1774 4 two B 5 w
1775 5 two C 6 t
1776 === === === === ===
1777
1778and we want:
1779
1780 === === === ===
1781 . A B C
1782 === === === ===
1783 one 1 2 3
1784 two 4 5 6
1785 === === === ===
1786
1787In Galaxy we would select the following:
1788
1789 * *Input Single or Multiple Tables* → **Single Table**
1790 * *Column names on first row?* → **Yes**
1791 * *Row names on first column?* → **Yes**
1792 * *Type of table operation* → **Perform a Full Table Operation**
1793
1794 * *Operation* → **Pivot**
1795 * *Index* → ``foo``
1796 * *Column* → ``bar``
1797 * *Values* → ``baz``
1798
1799This splits the matrix using "foo" and "bar" using only the values from "baz". Header values
1800 may contain extra information.
1801
1802
1803Example 9: Replacing text in specific rows or columns
1804~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1805
1806We have the following table
1807
1808 === === === ===
1809 . c1 c2 c3
1810 === === === ===
1811 g1 10 20 30
1812 g2 3 3 9
1813 g3 4 8 12
1814 g4 81 6 3
1815 === === === ===
1816
1817and we want to add "chr" to the elements in column 2 AND rows 2 and 4:
1818
1819 === === ==== ===
1820 . c1 c2 c3
1821 === === ==== ===
1822 g1 10 20 30
1823 g2 3 chr3 9
1824 g3 4 8 12
1825 g4 81 chr6 3
1826 === === ==== ===
1827
1828In Galaxy we would select the following:
1829
1830 * *Input Single or Multiple Tables* → **Single Table**
1831 * *Column names on first row?* → **Yes**
1832 * *Row names on first column?* → **Yes**
1833
1834 * *Type of table operation* → **Manipulate selected table elements**
1835
1836 * *Operation to perform* → **Replace values**
1837
1838 * *Replacement value* → ``chr{elem:.0f}``
1839
1840 Here, the placeholder ``{elem}`` lets us refer to each element's current value,
1841 while the ``:.0f`` part is a format specifier that makes sure numbers are printed
1842 without decimals (for a complete description of the available syntax see the
1843 `Python Format Specification Mini-Language <https://docs.python.org/3/library/string.html#formatspec>`_).
1844
1845 * *Operate on elements* → **Specific Rows and/or Columns**
1846 * *List of columns to select* → ``2``
1847 * *List of rows to select* → ``2,4``
1848 * *Inclusive Selection* → ``No``
1849
1850
1851If we wanted to instead add "chr" to the ALL elements in column 2 and rows 2 and 4, we
1852 would repeat the steps above but set the *Inclusive Selection* to "Yes", to give:
1853
1854 === ===== ===== =====
1855 . c1 c2 c3
1856 === ===== ===== =====
1857 g1 10 chr20 30
1858 g2 chr3 chr3 chr9
1859 g3 4 8 12
1860 g4 chr81 chr6 chr3
1861 === ===== ===== =====
1862
1863
1864Example 10: Pivot Table with unified Aggregator
1865~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1866
1867For an input table of:
1868
1869=== === ===== === ===
1870 A B C D E
1871=== === ===== === ===
1872foo one small 1 2
1873foo one large 2 4
1874foo one large 2 5
1875foo two small 3 5
1876foo two small 3 6
1877bar one large 4 6
1878bar one small 5 8
1879bar two small 6 9
1880bar two large 7 9
1881=== === ===== === ===
1882
1883we wish to pivot the table with the 'A' column as the new row index and use the values of the column 'C' as the new column indexes, based on the aggregated values of 'D'. By default the aggregator function is the mean, but here we will instead pick the max, to yield:
1884
1885=== == ==
1886C l s
1887A
1888=== == ==
1889bar 7 6
1890foo 2 3
1891=== == ==
1892
1893In Galaxy we would select the following:
1894
1895 * *Input Single or Multiple Tables* → **Single Table**
1896 * *Column names on first row?* → **Yes**
1897 * *Row names on first column?* → **Yes**
1898 * *Type of table operation* → **Perform a Full Table Operation**
1899
1900 * *Operation* → **Pivot**
1901 * *Index* → ``A``
1902 * *Column* → ``C``
1903 * *Values* → ``D``
1904 * *Aggregator Function* → ``max``
1905
1906
1907Example 11: Pivot Table with custom Aggregrator
1908~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1909
1910For an input table of:
1911
1912
1913==== ========== =========== === ========
1914Name Position City Age Random
1915==== ========== =========== === ========
1916Mary Manager Boston 34 0.678577
1917Josh Programmer New York 37 0.973168
1918 Jon Manager Chicago 29 0.146668
1919Lucy Manager Los Angeles 40 0.150120
1920Jane Programmer Chicago 29 0.112769
1921 Sue Programmer Boston 31 0.185198
1922==== ========== =========== === ========
1923
1924we wish to pivot the table with the 'Position' column as the new index and transform the 'Age' and 'Random' columns to have mean and standard deviation values
1925
1926========== ========= ======== ========
1927Position Age Random Random
1928. mean mean std
1929========== ========= ======== ========
1930Manager 34.333333 0.325122 0.306106
1931Programmer 32.333333 0.423712 0.477219
1932========== ========= ======== ========
1933
1934In Galaxy we would select the following:
1935
1936 * *Input Single or Multiple Tables* → **Single Table**
1937 * *Column names on first row?* → **Yes**
1938 * *Row names on first column?* → **Yes**
1939 * *Type of table operation* → **Perform a Full Table Operation**
1940
1941 * *Operation* → **Pivot**
1942 * *Index* → ``Position``
1943 * *Column-Function Mapping*
1944
1945 * *Value Column* → ``Age``
1946
1947 * *Function* → ``mean``
1948
1949 * *Value Column* → ``Random``
1950
1951 * *Function* → ``mean``
1952 * *Function* → ``std``
1953
1954
1955This splits the matrix using "foo" and "bar" using only the values from "baz". Header values
1956 may contain extra information.
1957
1958
1959
1960]]></help>
1961 <citations>
1962 <citation type="doi">10.25080/Majora-92bf1922-00a</citation>
1963 </citations>
1964</tool>