Source code

Download source archive ↓

upstream-extended/iuc/tools/datamash/datamash-transpose.xml

1<tool id="datamash_transpose" name="Transpose" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
2    <description>rows/columns in a tabular file</description>
3    <macros>
4        <import>macros.xml</import>
5        <token name="@VERSION_SUFFIX@">1</token>
6    </macros>
7    <edam_topics>
8        <edam_topic>topic_3570</edam_topic> <!-- Pure math / linear algebra -->
9    </edam_topics>
10    <edam_operations>
11         <!-- <edam_operation>operation_1234</edam_operation> -->
12    </edam_operations>
13    <expand macro="requirements">
14        <requirement type="package" version="9.5">coreutils</requirement>
15    </expand>
16    <expand macro="stdio"/>
17    <command><![CDATA[
18        #import os
19        #set file_size_MB = $in_file.get_size() / (1024 * 1024)
20        #set size_threshold_MB = 1024
21        #if $file_size_MB <= $size_threshold_MB:
22            datamash transpose @FIELD_SEPARATOR@ < $in_file > $out_file
23        #else:
24            ## Input matrix is very big: divide and conquer
25            ## If the input file is very big, datamash runs out of memory (much earlier than file size ~ available RAM.
26            ## Split into managable chunks of row vectors, transpose the chunks and juxtapose column vector chunks.
27            #set num_chunks = 1 + int(file_size_MB/size_threshold_MB)
28            echo Huge matrix detected, processing in $num_chunks chunks. &&
29            split -n l/$num_chunks $in_file split_input_ &&
30            for chunk in \$(ls split_input*); do
31                datamash transpose @FIELD_SEPARATOR@ < \$chunk > \${chunk}_transposed;
32            done &&
33            paste split_input_*_transposed > $out_file
34        #end if
35    ]]></command>
36    <expand macro="inputs_outputs"/>
37    <tests>
38        <test expect_num_outputs="1">
39            <param name="in_file" value="datamash_transpose_input.txt"/>
40            <output file="datamash_transpose_output.txt" name="out_file"/>
41        </test>
42        <!-- Test for transposing an extremely big input matrix
43         Disabled to keep the repository size reasonable.
44        For testing, manually download a pathological in- and output from:
45        https://usegalaxy.eu/u/tunc/h/very-big-scrna-matrix
46        -->
47        <!--
48        <test>
49            <param name="in_file" value="big.tabular"/>
50            <output file="transposed_big.tabular" name="out_file"/>
51        </test>
52        -->
53        <!-- transpose(transpose(A)) = A -->
54        <!--
55        <test>
56            <param name="in_file" value="transposed_big.tabular"/>
57            <output file="big.tabular" name="out_file"/>
58        </test>
59        -->
60    </tests>
61    <help>
62<![CDATA[
63@HELP_HEADER@
64
65**Syntax**
66
67This tools transposes (swaps) rows/columns in a tabular input file.
68
69-----
70
71**Example**
72
73Input file::
74
75    Genes   NOX1  DcP  HH
76    Sample  A1    A2   B3
77    Counts  514   542  490
78
79Output file::
80
81    Genes  Sample  Counts
82    NOX1   A1      514
83    DcP    A2      542
84    HH     B3      490
85
86@HELP_FOOTER@
87]]>
88    </help>
89    <expand macro="citation"/>
90</tool>