Mercurial > repos > bgruening > text_processing
view sort.xml @ 1:a4ad586d1403 draft
Uploaded
author | bgruening |
---|---|
date | Thu, 05 Sep 2013 11:42:27 -0400 |
parents | ec66f9d90ef0 |
children | 7068d1548234 |
line wrap: on
line source
<tool id="unixtools_sort_header_tool" name="Sort" version="0.1.1"> <description>data in ascending or descending order</description> <requirements> <requirement type="package" version="8.21">gnu_coreutils</requirement> <requirement type="package" version="4.2.2-sandbox">gnu_sed</requirement> </requirements> <command interpreter="sh"> #if int($header) > 0: (sed -u '${header}'q && sort $unique $ignore_case --stable -t ' ' #for $key in $sortkeys '-k ${key.column}${key.order}${key.style},${key.column}' #end for ) < '${infile}' > '${outfile}' #else: (sort $unique $ignore_case --stable -t ' ' #for $key in $sortkeys '-k ${key.column}${key.order}${key.style},${key.column}' #end for ) < '${infile}' > '${outfile}' #end if </command> <inputs> <param format="txt" name="infile" type="data" label="Sort Query" /> <param name="header" type="integer" size="5" value="0" label="Number of header lines" help="These will be ignored during sort."> <validator type="in_range" message="Negative values are not allowed." min="0"/> </param> <repeat name="sortkeys" title="Column selections" min="1"> <param name="column" label="on column" type="data_column" data_ref="infile" accept_default="true" /> <param name="order" type="select" display="radio" label="in"> <option value="">Ascending order</option> <option value="r">Descending order</option> </param> <param name="style" type="select" display="radio" label="Flavor"> <option value="n">Fast numeric sort ([-n])</option> <option value="g">General numeric sort ( scientific notation [-g])</option> <option value="V">Natural/Version sort ([-V]) </option> <option value="">Alphabetical sort</option> <option value="h">Human-readable numbers (-h)</option> <option value="R">Random order</option> </param> </repeat> <param name="unique" type="boolean" checked="false" truevalue="--unique" falsevalue="" label="Output unique values" help="Print only unique values (based on sorted key columns. See help section for details." /> <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." /> </inputs> <outputs> <data format="input" name="outfile" metadata_source="infile"/> </outputs> <tests> <!-- anyone knows how to write tests with repeat tags --> <test> <param name="infile" value="sort_in1.bed"/> <param name="column" value="1"/> <param name="style" value=""/> <param name="order" value="ASC"/> <param name="other_column" value="3"/> <param name="other_style" value="n"/> <param name="other_order" value="r"/> <output name="out_file1" file="sort_out1.bed"/> </test> <test> <param name="infile" value="sort_in1.bed"/> <param name="column" value="1"/> <param name="style" value=""/> <param name="order" value="ASC"/> <param name="other_column" value="3"/> <param name="other_style" value="n"/> <param name="other_order" value=""/> <output name="out_file1" file="sort_out2.bed"/> </test> <test> <param name="infile" value="sort_in2.bed"/> <param name="column" value="5"/> <param name="style" value="g"/> <param name="order" value=""/> <output name="out_file1" file="sort_out3.bed"/> </test> </tests> <help> **What it does** This tool sorts an input file. ----- **Sorting Styles** * **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). * **General Numeric**: sort by numeric values. Handles all numeric notations (including scientific notation). Slower than *fast numeric*, so use only when necessary. * **Natural Sort**: Sort in 'natural' order (natural to humans, not to computers). See example below. * **Alphabetical sort**: Sort in strict alphabetical order. See example below. * **Human-readable numbers**: Sort human readble numbers (e.g. 1G > 2M > 3K > 400) * **Random order**: return lines in random order. ------ **Example - Header line** **Input file** (note first line is a header line, should not be sorted):: Fruit Color Price Banana Yellow 4.1 Avocado Green 8.0 Apple Red 3.0 Melon Green 6.1 **Sorting** by **numeric order** on column **3**, with **header**, will return:: Fruit Color Price Apple Red 3.0 Banana Yellow 4.1 Melon Green 6.1 Avocado Green 8.0 ----- **Example - Natural vs. Alphabetical sorting** Given the following list:: chr4 chr13 chr1 chr10 chr20 chr2 **Alphabetical sort** would produce the following sorted list:: chr1 chr10 chr13 chr2 chr20 chr4 **Natural Sort** would produce the following sorted list:: chr1 chr2 chr4 chr10 chr13 chr20 .. class:: infomark 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. ----- *sort-header* is was written by A. Gordon ( gordon at cshl dot edu ) </help> </tool>