4
|
1 <tool id="tp_sort_header_tool" name="Sort" version="@BASE_VERSION@.0">
|
1
|
2 <description>data in ascending or descending order</description>
|
4
|
3 <macros>
|
|
4 <import>macros.xml</import>
|
|
5 </macros>
|
|
6 <expand macro="requirements">
|
0
|
7 <requirement type="package" version="4.2.2-sandbox">gnu_sed</requirement>
|
4
|
8 </expand>
|
|
9 <version_command>sort --version | head -n 1</version_command>
|
|
10 <command>
|
|
11 <![CDATA[
|
|
12 (
|
|
13 #if int($header) > 0:
|
|
14 sed -u '${header}'q &&
|
|
15 #end if
|
0
|
16
|
4
|
17 sort $unique $ignore_case --stable -t ' '
|
0
|
18
|
4
|
19 #for $key in $sortkeys:
|
|
20 -k '${key.column}${key.order}${key.style},${key.column}'
|
|
21 #end for
|
0
|
22
|
4
|
23 ) < '${infile}' > '${outfile}'
|
|
24 ]]>
|
0
|
25 </command>
|
|
26 <inputs>
|
4
|
27 <param format="tabular" name="infile" type="data" label="Sort Query" />
|
|
28 <param name="header" type="integer" size="5" value="0"
|
|
29 label="Number of header lines" help="These will be ignored during sort.">
|
0
|
30 <validator type="in_range" message="Negative values are not allowed." min="0"/>
|
|
31 </param>
|
|
32
|
1
|
33 <repeat name="sortkeys" title="Column selections" min="1">
|
0
|
34 <param name="column" label="on column" type="data_column" data_ref="infile" accept_default="true" />
|
|
35 <param name="order" type="select" display="radio" label="in">
|
|
36 <option value="">Ascending order</option>
|
|
37 <option value="r">Descending order</option>
|
|
38 </param>
|
|
39 <param name="style" type="select" display="radio" label="Flavor">
|
4
|
40 <option value="n">Fast numeric sort (-n)</option>
|
|
41 <option value="g">General numeric sort ( scientific notation -g)</option>
|
|
42 <option value="V">Natural/Version sort (-V) </option>
|
0
|
43 <option value="">Alphabetical sort</option>
|
|
44 <option value="h">Human-readable numbers (-h)</option>
|
4
|
45 <option value="R">Random order (-R)</option>
|
0
|
46 </param>
|
|
47 </repeat>
|
1
|
48
|
|
49 <param name="unique" type="boolean" checked="false" truevalue="--unique" falsevalue=""
|
4
|
50 label="Output unique values" help="Print only unique values, based on sorted key columns. See help section for details. (--unique)" />
|
|
51 <param name="ignore_case" type="boolean" checked="false" truevalue="-i" falsevalue=""
|
|
52 label="Ignore case" help="Sort and Join key column values regardless of upper/lower case letters. (-i)" />
|
1
|
53
|
0
|
54 </inputs>
|
|
55 <outputs>
|
|
56 <data format="input" name="outfile" metadata_source="infile"/>
|
|
57 </outputs>
|
1
|
58 <tests>
|
|
59 <test>
|
|
60 <param name="infile" value="sort_in1.bed"/>
|
4
|
61 <param name="header" value="3"/>
|
|
62 <repeat name="sortkeys">
|
|
63 <param name="column" value="1"/>
|
|
64 <param name="style" value=""/>
|
|
65 <param name="order" value=""/>
|
|
66 </repeat>
|
|
67 <repeat name="sortkeys">
|
|
68 <param name="column" value="3"/>
|
|
69 <param name="style" value="n"/>
|
|
70 <param name="order" value="r"/>
|
|
71 </repeat>
|
|
72 <output name="outfile" file="sort_result1.bed"/>
|
1
|
73 </test>
|
|
74 <test>
|
|
75 <param name="infile" value="sort_in1.bed"/>
|
4
|
76 <param name="header" value="3"/>
|
|
77 <repeat name="sortkeys">
|
|
78 <param name="column" value="1"/>
|
|
79 <param name="style" value=""/>
|
|
80 <param name="order" value=""/>
|
|
81 </repeat>
|
|
82 <repeat name="sortkeys">
|
|
83 <param name="column" value="3"/>
|
|
84 <param name="style" value="n"/>
|
|
85 <param name="order" value=""/>
|
|
86 </repeat>
|
|
87 <output name="outfile" file="sort_result2.bed"/>
|
1
|
88 </test>
|
|
89 <test>
|
|
90 <param name="infile" value="sort_in2.bed"/>
|
4
|
91 <repeat name="sortkeys">
|
|
92 <param name="column" value="5"/>
|
|
93 <param name="style" value="g"/>
|
|
94 <param name="order" value=""/>
|
|
95 </repeat>
|
|
96 <output name="outfile" file="sort_result3.bed"/>
|
1
|
97 </test>
|
|
98 </tests>
|
0
|
99 <help>
|
4
|
100 <![CDATA[
|
0
|
101 **What it does**
|
|
102
|
|
103 This tool sorts an input file.
|
|
104
|
|
105 -----
|
|
106
|
|
107 **Sorting Styles**
|
|
108
|
|
109 * **Fast Numeric**: sort by numeric values. Handles integer values (e.g. 43, 134) and decimal-point values (e.g. 3.14). *Does not* handle scientific notation (e.g. -2.32e2).
|
|
110 * **General Numeric**: sort by numeric values. Handles all numeric notations (including scientific notation). Slower than *fast numeric*, so use only when necessary.
|
|
111 * **Natural Sort**: Sort in 'natural' order (natural to humans, not to computers). See example below.
|
|
112 * **Alphabetical sort**: Sort in strict alphabetical order. See example below.
|
|
113 * **Human-readable numbers**: Sort human readble numbers (e.g. 1G > 2M > 3K > 400)
|
|
114 * **Random order**: return lines in random order.
|
|
115
|
|
116 ------
|
|
117
|
|
118 **Example - Header line**
|
|
119
|
|
120 **Input file** (note first line is a header line, should not be sorted)::
|
|
121
|
|
122 Fruit Color Price
|
|
123 Banana Yellow 4.1
|
|
124 Avocado Green 8.0
|
|
125 Apple Red 3.0
|
|
126 Melon Green 6.1
|
|
127
|
|
128 **Sorting** by **numeric order** on column **3**, with **header**, will return::
|
|
129
|
|
130 Fruit Color Price
|
|
131 Apple Red 3.0
|
|
132 Banana Yellow 4.1
|
|
133 Melon Green 6.1
|
|
134 Avocado Green 8.0
|
|
135
|
|
136
|
|
137 -----
|
|
138
|
|
139 **Example - Natural vs. Alphabetical sorting**
|
|
140
|
|
141 Given the following list::
|
|
142
|
|
143 chr4
|
|
144 chr13
|
|
145 chr1
|
|
146 chr10
|
|
147 chr20
|
|
148 chr2
|
|
149
|
|
150 **Alphabetical sort** would produce the following sorted list::
|
|
151
|
|
152 chr1
|
|
153 chr10
|
|
154 chr13
|
|
155 chr2
|
|
156 chr20
|
|
157 chr4
|
|
158
|
|
159 **Natural Sort** would produce the following sorted list::
|
|
160
|
|
161 chr1
|
|
162 chr2
|
|
163 chr4
|
|
164 chr10
|
|
165 chr13
|
|
166 chr20
|
|
167
|
|
168
|
|
169 .. class:: infomark
|
|
170
|
|
171 If you're planning to use the file with another tool that expected sorted files (such as *join*), you should use the **Alphabetical sort**, not the **Natural Sort**. Natural sort order is easier for humans, but is unnatural for computer programs.
|
|
172
|
4
|
173 @REFERENCES@
|
|
174 ]]>
|
0
|
175 </help>
|
|
176 </tool>
|