view samtools_sort_genome/samtools_sort.xml @ 1:cdb826d5314b draft

Uploaded
author jackcurragh
date Fri, 27 May 2022 10:13:32 +0000
parents 76a4f74f3c09
children e25b7da5ecaa
line wrap: on
line source

<tool id="samtools_sort" name="Samtools Sort" version="2.0.4" profile="@PROFILE@">
    <description>Sort Alignment Files (SAM/BAM)</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <expand macro="stdio"/>
    <expand macro="version_command"/>
    <command><![CDATA[
        @ADDTHREADS@
	@ADDMEMORY@
        samtools sort
            -@ \$addthreads
            -m \$addmemory"M"
            ###if str(compression):
            ##    -l '$compression'
            ###end if
            $prim_key_cond.prim_key_select
            #if $prim_key_cond.prim_key_select == '-t':
                $prim_key_cond.tag
                $prim_key_cond.sec_key_select
            #end if
            $minhash
            -O bam
            -T "\${TMPDIR:-.}"
            '${input1}'
             > '${output1}'
    ]]></command>
    <inputs>
        <param name="input1" type="data" format="sam,unsorted.bam,cram" label="BAM File" />
        <conditional name="prim_key_cond">
            <param name="prim_key_select" type="select" label="Primary sort key">
                <option value="" selected="True">coordinate</option>
                <option value="-n">name (-n)</option>
                <option value="-t">tag (-t)</option>
            </param>
            <when value=""/>
            <when value="-n"/>
            <when value="-t">
                <param name="tag" type="text" optional="false" argument="-t" label="Alignment tag"/>
                <param name="sec_key_select" type="select" label="Secondary sort key">
                    <option value="">coordinate</option>
                    <option value="-n">name (-n)</option>
                </param>
           </when>
        </conditional>
        <param name="minhash" type="boolean" argument="-M" truevalue="-M" falsevalue="" checked="false" label="Minhash collation" help="Use minimiser for clustering unaligned/unplaced reads."/>
        <!--<param name="compression" type="integer" argument="-l" optional="True" min="0" max="9" label="compression level" help="0 (uncompressed) to 9 (best)"/>-->
    </inputs>
    <outputs>
       <data name="output1" format="bam">
            <change_format>
                <when input="prim_key_cond.prim_key_select" value="" format="bam" />
                <when input="prim_key_cond.prim_key_select" value="-n" format="qname_sorted.bam" />
                <when input="prim_key_cond.prim_key_select" value="-t" format="unsorted.bam" />
            </change_format>
        </data>
    </outputs>
    <tests>
        <!-- tests from https://github.com/samtools/samtools/blob/9ce8c64493f7ea3fa69bc5c1ac980b1a8e3dcf1f/test/test.pl#L2464 -->
        <!-- 1) # Pos sort -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <output name="output1" file="pos.sort.expected.bam" ftype="bam" lines_diff="4" />
        </test>
    	<!-- test_cmd($opts, out=>"sort/pos.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads}  $$opts{path}/dat/test_input_1_a.bam -O SAM -o -"); -->
        <!-- 2) # Name sort -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-n"/>
            </conditional>
            <output name="output1" file="name.sort.expected.bam" ftype="qname_sorted.bam" lines_diff="4"/>
        </test>
	    <!-- test_cmd($opts, out=>"sort/name.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads} -n  $$opts{path}/dat/test_input_1_a.bam -O SAM -o -");-->
        <!-- 3) # Tag sort (RG) (considers output and name sorted) -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-t"/>
                <param name="tag" value="RG"/>
            </conditional>
            <output name="output1" file="tag.rg.sort.expected.bam" ftype="unsorted.bam" lines_diff="4"/>
        </test>
        <!--test_cmd($opts, out=>"sort/tag.rg.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads} -t RG  $$opts{path}/dat/test_input_1_a.bam -O SAM -o -");-->
        <!-- 4) # Tag sort (RG); secondary by name -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-t"/>
                <param name="tag" value="RG"/>
                <param name="sec_key_select" value="-n"/>
            </conditional>
            <output name="output1" file="tag.rg.n.sort.expected.bam" ftype="unsorted.bam" lines_diff="4"/>
        </test>
        <!--test_cmd($opts, out=>"sort/tag.rg.n.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads} -n -t RG  $$opts{path}/dat/test_input_1_a.bam -O SAM -o -");-->
        <!-- 5) # Tag sort (AS) -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-t"/>
                <param name="tag" value="AS"/>
                <param name="sec_key_select" value=""/>
            </conditional>
            <output name="output1" file="tag.as.sort.expected.bam" ftype="unsorted.bam" lines_diff="4"/>
        </test>
        <!--test_cmd($opts, out=>"sort/tag.as.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads} -t AS $$opts{path}/dat/test_input_1_d.sam -O SAM -o -");-->
        <!-- 6) # Tag sort (FI) -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-t"/>
                <param name="tag" value="FI"/>
            </conditional>
            <output name="output1" file="tag.fi.sort.expected.bam" ftype="unsorted.bam" lines_diff="4"/>
        </test>
        <!--test_cmd($opts, out=>"sort/tag.fi.sort.expected.sam", cmd=>"$$opts{bin}/samtools sort${threads} -t FI $$opts{path}/dat/test_input_1_d.sam -O SAM -o -");-->
        <!-- 7) tests from old version -->
        <test>
            <param name="input1" value="1.bam" ftype="bam" />
            <output name="output1" file="1_sort.bam" ftype="bam" sort="True" lines_diff="4"/>
        </test>
        <test>
            <param name="input1" value="1.bam" ftype="bam" />
            <conditional name="prim_key_cond">
                <param name="prim_key_select" value="-n"/>
            </conditional>
            <output name="output1" file="1_sort_read_names.bam" ftype="qname_sorted.bam" lines_diff="4"/>
        </test>
        <!-- 8) test minhash sorting -->
        <test>
            <param name="input1" value="test_input_1_a.bam" ftype="bam" />
            <param name="minhash" value="true" />
            <output name="output1" file="minhash.expected.bam" ftype="bam" lines_diff="4" />
        </test>
    </tests>
    <help>
**What it does**

Sort alignments by leftmost coordinates, or by read name when -n is used.
An appropriate @HD-SO sort order header tag will be added or an existing
one updated if necessary.

**Ordering Rules**

The following rules are used for ordering records.

If option -t is in use, records are first sorted by the value of the given
alignment tag, and then by position or name (if using -n). For example, “-t RG”
will make read group the primary sort key. The rules for ordering by tag are:

- Records that do not have the tag are sorted before ones that do.
- If the types of the tags are different, they will be sorted so that single
  character tags (type A) come before array tags (type B), then string tags
  (types H and Z), then numeric tags (types f and i).
- Numeric tags (types f and i) are compared by value. Note that comparisons of
  floating-point values are subject to issues of rounding and precision.
- String tags (types H and Z) are compared based on the binary contents of the
  tag using the C strcmp(3) function.
- Character tags (type A) are compared by binary character value.
- No attempt is made to compare tags of other types — notably type B array values will not be compared.

When the -n option is present, records are sorted by name. Names are compared so as to give a “natural” ordering — i.e. sections consisting of digits are compared numerically while all other sections are compared based on their binary representation. This means “a1” will come before “b1” and “a9” will come before “a10”. Records with the same name will be ordered according to the values of the READ1 and READ2 flags (see flags).

When the -n option is not present, reads are sorted by reference (according to the order of the @SQ header records), then by position in the reference, and then by the REVERSE flag.

This has now been removed. The previous out.prefix argument (and -f option, if any) should be changed to an appropriate combination of -T PREFIX and -o FILE. The previous -o option should be removed, as output defaults to standard output.

When the -M (minash collation) option is present, then samtools sort groups unmapped reads with similar sequence together. This can sometimes significantly reduce the file size.

    </help>
    <expand macro="citations"/>
</tool>