comparison table_compute.xml @ 4:93a3ce78ce55 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit d741508e5ed912cdeee4f67ec8451b6e6865363c"
author iuc
date Tue, 20 Apr 2021 15:46:10 +0000
parents 60ff16842fcd
children 3bf5661c0280
comparison
equal deleted inserted replaced
3:60ff16842fcd 4:93a3ce78ce55
1 <tool id="table_compute" name="Table Compute" version="@VERSION@"> 1 <tool id="table_compute" name="Table Compute" version="@VERSION@+galaxy@WRAPPER_VERSION@">
2 <description>computes operations on table data</description> 2 <description>computes operations on table data</description>
3 <macros> 3 <macros>
4 <token name="@VERSION@">0.9.2</token> 4 <token name="@VERSION@">1.2.4</token>
5 <token name="@WRAPPER_VERSION@">0</token>
5 <token name="@COPEN@"><![CDATA[<code>]]></token> 6 <token name="@COPEN@"><![CDATA[<code>]]></token>
6 <token name="@CCLOSE@"><![CDATA[</code>]]></token> 7 <token name="@CCLOSE@"><![CDATA[</code>]]></token>
7 <import>allowed_functions.xml</import> 8 <import>allowed_functions.xml</import>
8 <!-- text field validators --> 9 <!-- text field validators -->
9 <macro name="validator_text" > 10 <macro name="validator_text" >
90 <expand macro="validator_index_ranges" /> 91 <expand macro="validator_index_ranges" />
91 </param> 92 </param>
92 </macro> 93 </macro>
93 </macros> 94 </macros>
94 <requirements> 95 <requirements>
95 <requirement type="package" version="0.25">pandas</requirement> 96 <requirement type="package" version="1.2.4">pandas</requirement>
96 <requirement type="package" version="1.17">numpy</requirement> 97 <requirement type="package" version="1.19.2">numpy</requirement>
97 </requirements> 98 </requirements>
98 99
99 <version_command><![CDATA[ 100 <version_command><![CDATA[
100 python '$__tool_directory__/scripts/table_compute.py' --version 101 python '$__tool_directory__/scripts/table_compute.py' --version
101 ]]></version_command> 102 ]]></version_command>
258 "MELT": { 259 "MELT": {
259 "melt_ids": $melt_ids, 260 "melt_ids": $melt_ids,
260 "melt_values": $melt_values, 261 "melt_values": $melt_values,
261 }, 262 },
262 #elif str($singtabop.user.general.use) == 'pivot': 263 #elif str($singtabop.user.general.use) == 'pivot':
263 #set $pivot_index = str($singtabop.user.general.index).strip() 264 #set $pivot_index = None
264 #if $pivot_index: 265 #set $pivot_columns = None
265 #set $pivot_index = "'" + $pivot_index + "'" 266 #set $pivot_values = None
266 #else: 267 #set $pivot_aggfunc = None
268
269 #if str($singtabop.user.general.index).strip()
270 #set $pivot_index = [i.strip() for i in str($singtabop.user.general.index).split(',')]
271 #if len($pivot_index)==1
272 #set $pivot_index = "'"+$pivot_index[0]+"'"
273 #end if
274 #else
267 #set $pivot_index = 'None' 275 #set $pivot_index = 'None'
268 #end if 276 #end if
269 #set $pivot_column = "'" + str($singtabop.user.general.column).strip() + "'" 277 #if str($singtabop.user.general.column).strip()
270 #if str($singtabop.user.general.values).strip(): 278 #set $pivot_columns = [i.strip() for i in str($singtabop.user.general.column).split(',')]
279 #if len($pivot_columns)==1
280 #set $pivot_columns = "'"+$pivot_columns[0]+"'"
281 #end if
282 #else
283 #set $pivot_columns = 'None'
284 #end if
285 #if str($singtabop.user.general.values).strip()
271 #set $pivot_values = [i.strip() for i in str($singtabop.user.general.values).split(',')] 286 #set $pivot_values = [i.strip() for i in str($singtabop.user.general.values).split(',')]
287 #if len($pivot_values)==1
288 #set $pivot_values = "'"+$pivot_values[0]+"'"
289 #end if
272 #else 290 #else
273 #set $pivot_values = 'None' 291 #set $pivot_values = 'None'
274 #end if 292 #end if
293
294 ## The aggfunc is either a - column : [array] map
295 ## or just an [array]
296 #if str($singtabop.user.general.aggfunc).strip() == 'None'
297 #set $pivot_aggfunc = 'None'
298 #end if
299 #if not($pivot_aggfunc)
300 #set $pivot_aggfunc = [i.strip() for i in str($singtabop.user.general.aggfunc).split(',')]
301 #if len($pivot_aggfunc)==1
302 #set $pivot_aggfunc = "'"+$pivot_aggfunc[0]+"'"
303 #end if
304 #end if
305
275 "PIVOT": { 306 "PIVOT": {
276 "pivot_index": $pivot_index, 307 "pivot_index": $pivot_index,
277 "pivot_column": $pivot_column, 308 "pivot_columns": $pivot_columns,
278 "pivot_values": $pivot_values, 309 "pivot_values": $pivot_values,
310 #if $pivot_aggfunc == 'None':
311 "pivot_aggfunc": {
312 #for $i, $s in enumerate($singtabop.user.general.colfun_map)
313 #echo 16*' ' + "'" + str($s.column) + "'" + ' : ['
314 #echo ','.join([ "'%s'" % $t.aggfunc for $j, $t in enumerate($s.functions) ])
315 #echo '],\n'
316 #end for
317 }
318 #else
319 "pivot_aggfunc": $pivot_aggfunc
320 #end if
279 }, 321 },
322
280 #elif str($singtabop.user.general.use) == 'custom': 323 #elif str($singtabop.user.general.use) == 'custom':
281 #set $custom_func = str($singtabop.user.general.fulltable_custom_expr).strip() 324 #set $custom_func = str($singtabop.user.general.fulltable_custom_expr).strip()
282 "fulltable_customop": '$custom_func', 325 "fulltable_customop": '$custom_func',
283
284 #end if 326 #end if
285 }, 327 },
286 #end if 328 #end if
287 } 329 }
288 330
445 <expand macro="validator_index_identifiers" /> 487 <expand macro="validator_index_identifiers" />
446 </param> 488 </param>
447 </when> 489 </when>
448 <when value="pivot" > 490 <when value="pivot" >
449 <param name="index" type="text" value="" 491 <param name="index" type="text" value=""
450 label="Index" 492 label="Index"
451 help="Name of the column to use as new index" > 493 help="Name of the column to use as new index" >
452 <expand macro="validator_text" /> 494 <expand macro="validator_text" />
453 </param> 495 </param>
454 <param name="column" type="text" value="" 496 <param name="column" type="text" value=""
455 label="Column" 497 label="Column"
456 help="Name of the column to use to generate the columns of the new table from" > 498 help="Name of the column to use to generate the columns of the new table from.
499 Cannot be used in conjunction with the Column-Function Mapping parameter."
500 optional="true">
457 <expand macro="validator_text_required" /> 501 <expand macro="validator_text_required" />
458 </param> 502 </param>
459 <param name="values" type="text" value="" 503 <param name="values" type="text" value=""
460 label="Values" 504 label="Values"
461 help="Names of the columns to use for populating the cells of the new table. Leave blank to use all." > 505 help="Names of the columns to use for populating the cells of the new table. Leave blank to use all." >
462 <expand macro="validator_index_identifiers" /> 506 <expand macro="validator_index_identifiers" />
463 </param> 507 </param>
508 <param name="aggfunc" type="select" optional="true"
509 label="Aggregator Function"
510 help="The function used to aggregate the values for each unique index.
511 Cannot be used with the Column-Function Mapping parameter below.
512 By default this value is np.mean. Leave blank for default behaviour.
513 See Example 10 for more information on its usage." >
514 <expand macro="select_vectorops">
515 <option value="all">All</option>
516 <option value="any">Any</option>
517 </expand>
518 </param>
519 <repeat name="colfun_map" title="Column-Function Mapping" min="0">
520 <param name="column" type="text" label="Value Column"
521 help="Either a numeric index, or a value column name." />
522 <repeat name="functions" title="Aggregator Function" min="0" >
523 <!-- if zero, then this defaults to np.mean -->
524 <param name="aggfunc" type="select" label="Function"
525 help="The function used to aggregate the values for each unique index.
526 By default this is np.mean. See Example 11 for more information on its usage." >
527 <expand macro="select_vectorops">
528 <option value="all">All</option>
529 <option value="any">Any</option>
530 </expand>
531 </param>
532 </repeat>
533 </repeat>
464 </when> 534 </when>
465 <when value="custom" > 535 <when value="custom" >
466 <param name="fulltable_custom_expr" type="text" 536 <param name="fulltable_custom_expr" type="text"
467 label="Custom expression on 'table', along 'axis' (0 or 1)" 537 label="Custom expression on 'table', along 'axis' (0 or 1)"
468 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. "> 538 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. ">
469 <expand macro="validator_functiondef" /> 539 <expand macro="validator_functiondef" />
470 </param> 540 </param>
471 </when> 541 </when>
472 </conditional> 542 </conditional>
473 </when> 543 </when>
1293 <param name="element_op" value="All" /> 1363 <param name="element_op" value="All" />
1294 </conditional> 1364 </conditional>
1295 </conditional> 1365 </conditional>
1296 </conditional> 1366 </conditional>
1297 </test> 1367 </test>
1368 <test expect_num_outputs="1" >
1369 <!-- Pivot aggregator operations -->
1370 <conditional name="singtabop" >
1371 <param name="use_type" value="single" />
1372 <param name="input" value="pivot.tsv" />
1373 <param name="col_row_names" value="has_col_names,has_row_names" />
1374 <conditional name="user" >
1375 <param name="mode" value="fulltable" />
1376 <conditional name="general" >
1377 <param name="use" value="pivot" />
1378 <param name="index" value="Position" />
1379 <repeat name="colfun_map" >
1380 <param name="column" value="Age" />
1381 <repeat name="functions"><param name="aggfunc" value="mean" /></repeat>
1382 </repeat>
1383 <repeat name="colfun_map" >
1384 <param name="column" value="Random" />
1385 <repeat name="functions"><param name="aggfunc" value="mean" /></repeat>
1386 <repeat name="functions"><param name="aggfunc" value="std" /></repeat>
1387 </repeat>
1388 </conditional>
1389 </conditional>
1390 </conditional>
1391 <output name="table" >
1392 <assert_contents>
1393 <has_n_columns n="4" />
1394 <has_line_matching expression="^Manager\s+34.3\d+\s+0.325\d+\s+0.306\d+" />
1395 <has_line_matching expression="^Programmer\s+32.3\d+\s+0.423\d+\s+0.477\d+" />
1396 </assert_contents>
1397 </output>
1398 </test>
1399 <test expect_num_outputs="1" >
1400 <!-- Pivot table operations from PR 3480 -->
1401 <conditional name="singtabop" >
1402 <param name="use_type" value="single" />
1403 <param name="input" value="table1.tsv" />
1404 <param name="col_row_names" value="has_col_names" />
1405 <conditional name="user" >
1406 <param name="mode" value="fulltable" />
1407 <conditional name="general" >
1408 <param name="use" value="pivot" />
1409 <param name="index" value="A" />
1410 <param name="column" value="C" />
1411 <param name="values" value="D" />
1412 <param name="aggfunc" value="max" />
1413 </conditional>
1414 </conditional>
1415 </conditional>
1416 <output name="table" >
1417 <assert_contents>
1418 <has_text_matching expression="bar\t7\t6" />
1419 </assert_contents>
1420 </output>
1421 </test>
1298 </tests> 1422 </tests>
1299 <help><![CDATA[ 1423 <help><![CDATA[
1300 Table Compute 1424 Table Compute
1301 ------------- 1425 -------------
1302 1426
1775 g2 chr3 chr3 chr9 1899 g2 chr3 chr3 chr9
1776 g3 4 8 12 1900 g3 4 8 12
1777 g4 chr81 chr6 chr3 1901 g4 chr81 chr6 chr3
1778 === ===== ===== ===== 1902 === ===== ===== =====
1779 1903
1904
1905 Example 10: Pivot Table with unified Aggregator
1906 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1907
1908 For an input table of:
1909
1910 === === ===== === ===
1911 A B C D E
1912 === === ===== === ===
1913 foo one small 1 2
1914 foo one large 2 4
1915 foo one large 2 5
1916 foo two small 3 5
1917 foo two small 3 6
1918 bar one large 4 6
1919 bar one small 5 8
1920 bar two small 6 9
1921 bar two large 7 9
1922 === === ===== === ===
1923
1924 we 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:
1925
1926 === == ==
1927 C l s
1928 A
1929 === == ==
1930 bar 7 6
1931 foo 2 3
1932 === == ==
1933
1934 In 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* → ``A``
1943 * *Column* → ``C``
1944 * *Values* → ``D``
1945 * *Aggregator Function* → ``max``
1946
1947
1948 Example 11: Pivot Table with custom Aggregrator
1949 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1950
1951 For an input table of:
1952
1953
1954 ==== ========== =========== === ========
1955 Name Position City Age Random
1956 ==== ========== =========== === ========
1957 Mary Manager Boston 34 0.678577
1958 Josh Programmer New York 37 0.973168
1959 Jon Manager Chicago 29 0.146668
1960 Lucy Manager Los Angeles 40 0.150120
1961 Jane Programmer Chicago 29 0.112769
1962 Sue Programmer Boston 31 0.185198
1963 ==== ========== =========== === ========
1964
1965 we 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
1966
1967 ========== ========= ======== ========
1968 Position Age Random Random
1969 . mean mean std
1970 ========== ========= ======== ========
1971 Manager 34.333333 0.325122 0.306106
1972 Programmer 32.333333 0.423712 0.477219
1973 ========== ========= ======== ========
1974
1975 In Galaxy we would select the following:
1976
1977 * *Input Single or Multiple Tables* → **Single Table**
1978 * *Column names on first row?* → **Yes**
1979 * *Row names on first column?* → **Yes**
1980 * *Type of table operation* → **Perform a Full Table Operation**
1981
1982 * *Operation* → **Pivot**
1983 * *Index* → ``Position``
1984 * *Column-Function Mapping*
1985
1986 * *Value Column* → ``Age``
1987
1988 * *Function* → ``mean``
1989
1990 * *Value Column* → ``Random``
1991
1992 * *Function* → ``mean``
1993 * *Function* → ``std``
1994
1995
1996 This splits the matrix using "foo" and "bar" using only the values from "baz". Header values
1997 may contain extra information.
1998
1999
2000
1780 ]]></help> 2001 ]]></help>
1781 <citations></citations> 2002 <citations></citations>
1782 </tool> 2003 </tool>