view cut.xml @ 1:a4ad586d1403 draft

Uploaded
author bgruening
date Thu, 05 Sep 2013 11:42:27 -0400
parents ec66f9d90ef0
children fc862d5bccaf
line wrap: on
line source

<tool id="unixtools_cut_tool" name="Cut" version="0.1.1">
    <description>columns from a table</description>
    <requirements>
        <requirement type="package" version="8.21">gnu_coreutils</requirement>
    </requirements>
    <command>
        cut -d"${delimiter}" ${complement} ${cut_element} '${list}' '${input}' &gt; '${output}'
    </command>

    <inputs>
        <param format="txt" name="input" type="data" label="file to cut" />
        <param name="complement" type="select" label="Operation">
            <option value="">Keep</option>
            <option value="--complement">Discard</option>
        </param>

        <param name="delimiter" type="select" label="Delimited by">
          <option value="">Tab</option>
          <option value=" ">Whitespace</option>
          <option value=".">Dot</option>
          <option value=",">Comma</option>
          <option value="-">Dash</option>
          <option value="_">Underscore</option>
          <option value="|">Pipe</option>
        </param>

        <param name="cut_element" type="select" label="Cut by">
            <option value="-f">fields</option>
            <option value="-c">characters</option>
            <option value="-b">bytes</option>
        </param>

        <param name="list" type="text" size="20" value="" label="List of Fields/Characters/Bytes" help="These will be kept/discarded (depending on 'operation'). &lt;BR /&gt; Examples: 1,3,4 or 2-5">
            <sanitizer>
                <valid initial="string.printable">
                    <remove value="&apos;"/>
                </valid>
            </sanitizer>
        </param>
    </inputs>
    <outputs>
        <!--<data format="tabular" name="output" />-->
        <!-- WIP, not sure that will work with the complement option -->
        <data format="tabular" name="output">
          <actions>
            <conditional name="cut_element">
              <when value="-f">
                <conditional name="delimiter">
                  <when value="T">
                    <conditional name="input">
                      <when datatype_isinstance="interval">
                            <action type="format" default="tabular">
                                <option type="from_param" name="list" column="0" offset="0"> <!-- chromCol is 1-->

                                    <filter type="insert_column" column="0" value="interval"/>
                                    <filter type="insert_column" ref="list" /> <!-- startCol -->
                                    <filter type="insert_column" ref="list" /> <!-- endCol -->

                                    <filter type="multiple_splitter" column="1" separator=","/>
                                    <filter type="column_strip" column="1"/> <!-- get rid of all external whitespace -->
                                    <filter type="string_function" column="1" name="lower" />
                                    <filter type="param_value" column="1" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                    <filter type="column_strip" column="1" strip="c"/> <!-- get rid of c's  -->
                                    <filter type="boolean" column="1" cast="int" />

                                    <filter type="multiple_splitter" column="2" separator=","/>
                                    <filter type="column_strip" column="2"/> <!-- get rid of all external whitespace -->
                                    <filter type="string_function" column="2" name="lower" />
                                    <filter type="param_value" column="2" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                    <filter type="column_strip" column="2" strip="c"/> <!-- get rid of c's  -->
                                    <filter type="boolean" column="2" cast="int" />

                                    <filter type="multiple_splitter" column="3" separator=","/>
                                    <filter type="column_strip" column="3"/> <!-- get rid of all external whitespace -->
                                    <filter type="string_function" column="3" name="lower" />
                                    <filter type="param_value" column="3" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                    <filter type="column_strip" column="3" strip="c"/> <!-- get rid of c's  -->
                                    <filter type="boolean" column="3" cast="int" />

                                    <filter type="metadata_value" ref="input" name="chromCol" column="1" />
                                    <filter type="metadata_value" ref="input" name="startCol" column="2" />
                                    <filter type="metadata_value" ref="input" name="endCol" column="3" />

                                </option>
                            </action>
                        
                        <conditional name="output">
                          <when datatype_isinstance="interval">
                            <action type="metadata" name="chromCol">
                              <option type="from_param" name="list" column="0" offset="0"> <!-- chromCol is 0-->
                                <filter type="multiple_splitter" column="0" separator=","/>
                                <filter type="column_strip" column="0"/> <!-- get rid of all external whitespace -->
                                <filter type="string_function" column="0" name="lower" />
                                <filter type="param_value" column="0" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                <filter type="column_strip" column="0" strip="c"/> <!-- get rid of c's  -->
                                <filter type="insert_column" value="1" iterate="True" column="0"/>
                                <filter type="boolean" column="1" cast="int" /> 
                                <filter type="metadata_value" ref="input" name="chromCol" column="1" />
                              </option>
                            </action>
                            
                            <action type="metadata" name="startCol">
                              <option type="from_param" name="list" column="0" offset="0"> <!-- startCol is 0-->
                                <filter type="multiple_splitter" column="0" separator=","/>
                                <filter type="column_strip" column="0"/> <!-- get rid of all external whitespace -->
                                <filter type="string_function" column="0" name="lower" />
                                <filter type="param_value" column="0" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                <filter type="column_strip" column="0" strip="c"/> <!-- get rid of c's  -->
                                <filter type="insert_column" value="1" iterate="True" column="0"/>
                                <filter type="boolean" column="1" cast="int" />
                                <filter type="metadata_value" ref="input" name="startCol" column="1" />
                              </option>
                            </action>
                            
                            <action type="metadata" name="endCol">
                              <option type="from_param" name="list" column="0" offset="0"> <!-- endCol is 0-->
                                <filter type="multiple_splitter" column="0" separator=","/>
                                <filter type="column_strip" column="0"/> <!-- get rid of all external whitespace -->
                                <filter type="string_function" column="0" name="lower" />
                                <filter type="param_value" column="0" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                <filter type="column_strip" column="0" strip="c"/> <!-- get rid of c's  -->
                                <filter type="insert_column" value="1" iterate="True" column="0"/>
                                <filter type="boolean" column="1" cast="int" />
                                <filter type="metadata_value" ref="input" name="endCol" column="1" />
                              </option>
                            </action>
                          
                            <action type="metadata" name="nameCol" default="0">
                              <option type="from_param" name="list" column="0" offset="0"> <!-- nameCol is 0-->
                                <filter type="multiple_splitter" column="0" separator=","/>
                                <filter type="column_strip" column="0"/> <!-- get rid of all external whitespace -->
                                <filter type="string_function" column="0" name="lower" />
                                <filter type="param_value" column="0" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                <filter type="column_strip" column="0" strip="c"/> <!-- get rid of c's  -->
                                <filter type="insert_column" value="1" iterate="True" column="0"/>
                                <filter type="boolean" column="1" cast="int" />
                                <filter type="metadata_value" ref="input" name="nameCol" column="1" />
                              </option>
                            </action>
                          
                            <action type="metadata" name="strandCol" default="0">
                              <option type="from_param" name="list" column="0" offset="0"> <!-- strandCol is 0-->
                                <filter type="multiple_splitter" column="0" separator=","/>
                                <filter type="column_strip" column="0"/> <!-- get rid of all external whitespace -->
                                <filter type="string_function" column="0" name="lower" />
                                <filter type="param_value" column="0" value="^c\d{1,}$" compare="re_search" keep="True"/>
                                <filter type="column_strip" column="0" strip="c"/> <!-- get rid of c's  -->
                                <filter type="insert_column" value="1" iterate="True" column="0"/>
                                <filter type="boolean" column="1" cast="int" />
                                <filter type="metadata_value" ref="input" name="strandCol" column="1" />
                              </option>
                            </action>  
                          </when>
                        </conditional>
                        
                      </when>
                    </conditional>
                  </when>
                </conditional>
              </when>
            </conditional>
          </actions>
        </data>
    </outputs>
    <tests>
        <test>
            <param name="list" value="1,4,2,3"/>
            <param name="delimiter" value="T"/>
            <param name="input" value="1.bed"/>
            <output name="output" file="eq-cut.dat"/>
        </test>
        <test>
            <param name="list" value="1,4,2-3" />
            <param name="delimiter" value="T" />
            <param name="input" value="1.bed" />
            <output name="output" file="eq-cut.dat" />
        </test>
    </tests>

    <help>

**What it does**

This tool runs the **cut** unix command, which extract or delete columns from a file.

-----

Field List Example:

**1,3,7** - Cut specific fields/characters.

**3-**    - Cut from the third field/character to the end of the line.

**2-5**   - Cut from the second to the fifth field/character.

**-8**    - Cut from the first to the eight field/characters.


Input Example::

    fruit	color	price	weight
    apple	red	1.4	0.5
    orange	orange	1.5	0.3
    banana	yellow	0.9	0.3


Output Example ( **Keeping fields 1,3,4** )::

    fruit	price	weight
    apple	1.4	0.5
    orange	1.5	0.3
    banana	0.9	0.3

Output Example ( **Discarding field 2** )::

    fruit	price	weight
    apple	1.4	0.5
    orange	1.5	0.3
    banana	0.9	0.3

Output Example ( **Keeping 3 characters** )::

    fru
    app
    ora
    ban

  </help>
</tool>