Mercurial > repos > bgruening > text_processing
comparison sort.xml @ 0:ec66f9d90ef0 draft
initial uploaded
| author | bgruening |
|---|---|
| date | Thu, 05 Sep 2013 04:58:21 -0400 |
| parents | |
| children | a4ad586d1403 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ec66f9d90ef0 |
|---|---|
| 1 <tool id="unixtools_sort_header_tool" name="Sort" version="0.1.1"> | |
| 2 <requirements> | |
| 3 <requirement type="package" version="8.21">gnu_coreutils</requirement> | |
| 4 <requirement type="package" version="4.2.2-sandbox">gnu_sed</requirement> | |
| 5 </requirements> | |
| 6 <command interpreter="sh"> | |
| 7 #if int($header) > 0: | |
| 8 (sed -u '${header}'q && sort $unique $ignore_case --stable -t ' ' | |
| 9 | |
| 10 #for $key in $sortkeys | |
| 11 '-k ${key.column}${key.order}${key.style},${key.column}' | |
| 12 #end for | |
| 13 | |
| 14 ) < '${infile}' > '${outfile}' | |
| 15 #else: | |
| 16 (sort $unique $ignore_case --stable -t ' ' | |
| 17 | |
| 18 #for $key in $sortkeys | |
| 19 '-k ${key.column}${key.order}${key.style},${key.column}' | |
| 20 #end for | |
| 21 | |
| 22 ) < '${infile}' > '${outfile}' | |
| 23 #end if | |
| 24 </command> | |
| 25 | |
| 26 <inputs> | |
| 27 <param format="txt" name="infile" type="data" label="Sort Query" /> | |
| 28 <param name="header" type="integer" size="5" value="1" label="Number of header lines" help="These will be ignored during sort."> | |
| 29 <validator type="in_range" message="Negative values are not allowed." min="0"/> | |
| 30 </param> | |
| 31 | |
| 32 <param name="unique" type="boolean" checked="false" truevalue="--unique" falsevalue="" | |
| 33 label="Output unique values" help="Print only unique values (based on sorted key columns. See help section for details." /> | |
| 34 | |
| 35 <param name="ignore_case" type="boolean" checked="false" truevalue="-i" falsevalue="" label="Ignore case" help="Sort and Join key column values regardless of upper/lower case letters." /> | |
| 36 | |
| 37 <repeat name="sortkeys" title="sort key"> | |
| 38 <param name="column" label="on column" type="data_column" data_ref="infile" accept_default="true" /> | |
| 39 <param name="order" type="select" display="radio" label="in"> | |
| 40 <option value="">Ascending order</option> | |
| 41 <option value="r">Descending order</option> | |
| 42 </param> | |
| 43 <param name="style" type="select" display="radio" label="Flavor"> | |
| 44 <option value="n">Fast numeric sort ([-n])</option> | |
| 45 <option value="g">General numeric sort ( scientific notation [-g])</option> | |
| 46 <option value="V">Natural/Version sort ([-V]) </option> | |
| 47 <option value="">Alphabetical sort</option> | |
| 48 <option value="h">Human-readable numbers (-h)</option> | |
| 49 <option value="R">Random order</option> | |
| 50 </param> | |
| 51 </repeat> | |
| 52 </inputs> | |
| 53 <tests> | |
| 54 </tests> | |
| 55 <outputs> | |
| 56 <data format="input" name="outfile" metadata_source="infile"/> | |
| 57 </outputs> | |
| 58 <help> | |
| 59 | |
| 60 **What it does** | |
| 61 | |
| 62 This tool sorts an input file. | |
| 63 | |
| 64 ----- | |
| 65 | |
| 66 **Sorting Styles** | |
| 67 | |
| 68 * **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). | |
| 69 * **General Numeric**: sort by numeric values. Handles all numeric notations (including scientific notation). Slower than *fast numeric*, so use only when necessary. | |
| 70 * **Natural Sort**: Sort in 'natural' order (natural to humans, not to computers). See example below. | |
| 71 * **Alphabetical sort**: Sort in strict alphabetical order. See example below. | |
| 72 * **Human-readable numbers**: Sort human readble numbers (e.g. 1G > 2M > 3K > 400) | |
| 73 * **Random order**: return lines in random order. | |
| 74 | |
| 75 ------ | |
| 76 | |
| 77 **Example - Header line** | |
| 78 | |
| 79 **Input file** (note first line is a header line, should not be sorted):: | |
| 80 | |
| 81 Fruit Color Price | |
| 82 Banana Yellow 4.1 | |
| 83 Avocado Green 8.0 | |
| 84 Apple Red 3.0 | |
| 85 Melon Green 6.1 | |
| 86 | |
| 87 **Sorting** by **numeric order** on column **3**, with **header**, will return:: | |
| 88 | |
| 89 Fruit Color Price | |
| 90 Apple Red 3.0 | |
| 91 Banana Yellow 4.1 | |
| 92 Melon Green 6.1 | |
| 93 Avocado Green 8.0 | |
| 94 | |
| 95 | |
| 96 ----- | |
| 97 | |
| 98 **Example - Natural vs. Alphabetical sorting** | |
| 99 | |
| 100 Given the following list:: | |
| 101 | |
| 102 chr4 | |
| 103 chr13 | |
| 104 chr1 | |
| 105 chr10 | |
| 106 chr20 | |
| 107 chr2 | |
| 108 | |
| 109 **Alphabetical sort** would produce the following sorted list:: | |
| 110 | |
| 111 chr1 | |
| 112 chr10 | |
| 113 chr13 | |
| 114 chr2 | |
| 115 chr20 | |
| 116 chr4 | |
| 117 | |
| 118 **Natural Sort** would produce the following sorted list:: | |
| 119 | |
| 120 chr1 | |
| 121 chr2 | |
| 122 chr4 | |
| 123 chr10 | |
| 124 chr13 | |
| 125 chr20 | |
| 126 | |
| 127 | |
| 128 .. class:: infomark | |
| 129 | |
| 130 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. | |
| 131 | |
| 132 ----- | |
| 133 | |
| 134 *sort-header* is was written by A. Gordon ( gordon at cshl dot edu ) | |
| 135 | |
| 136 </help> | |
| 137 </tool> |
