view samtools_merge.xml @ 1:8890e2d4c068 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/samtools/samtools_merge commit 0f75269223c0821c6c82acf98fde947d0f816f2b"
author iuc
date Tue, 28 Sep 2021 16:14:52 +0000
parents 740ce0a18f0d
children b40e2d865d52
line wrap: on
line source

<tool id="samtools_merge" name="Samtools merge" version="@TOOL_VERSION@" profile="@PROFILE@">
    <description>merge multiple sorted alignment files</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <expand macro="stdio"/>
    <expand macro="version_command"/>
    <command><![CDATA[
@ADDTHREADS@
## prepare input (sort sam, link other), determine input ordering
## and check for consistent input ordering
#set sortby=''
#for $i, $bam in enumerate( $bamfiles ):
    #if $bam.is_of_type('sam', 'cram', ):
        samtools sort
        -@ \$addthreads -m \${GALAXY_MEMORY_MB:-768}M -T "\${TMPDIR:-.}"
        -O sam
        -o ${i}.sam
        '$bam' &&
    #else:
        ln -s '$bam' ${i}.sam &&
    #end if
    #if ($sortby=='coord' or $sortby=='') and $bam.is_of_type('sam','bam','cram'):
        #set sortby='coord'
    #else if ($sortby=='name' or $sortby=='') and $bam.is_of_type('qname_sorted.bam', 'qname_input_sorted.bam'):
        #set $sortby='name'
    #else:
        >&2 echo "inconsistently sorted input" &&
        exit 1 &&
    #end if
#end for
#if $bed_file
    #for $i, $bam in enumerate( $bamfiles ):
        samtools index ${i}.sam &&
    #end for
#end if
samtools merge
-@ \$addthreads
-s $seed
## TODO force overwrite seems necessay (but I do not understand why ...)
-f
## Galaxy provides only default compression
## #if $compression == 'levelone'
##     -1
## #else if $compression == 'uncompressed'
##     -u
## #end if
#if str($headerbam) != 'None'
    -h '$headerbam'
#end if
#if $sortby=='name'
    -n
#end if
## TODO since galaxy can't represent this as data type at the moment this option is unsupported
## -t TAG    The input alignments have been sorted by the value of TAG, then by either position or name (if -n is given).
#if str($region) != ''
    -R '$region'
#end if
## Attach an RG tag to each alignment. The tag value is inferred from file names.
## -r
## TODO -r makes no sense with the link names, is there some data set metadata (tags,...) that could be used?
#if $bed_file:
    -L '$bed_file'
#end if
$idrg
$idpg
$output
#for $i, $bam in enumerate( $bamfiles ):
    ${i}.sam
#end for
    ]]></command>
    <inputs>
        <param name="bamfiles" type="data" format="sam,bam,cram" multiple="true" optional="false" label="Alignments in BAM format" help="Sets of aligned reads." />
        <param name="bed_file" type="data" optional="true" format="bed" label="Merge only reads overlapping the specified regions in the BED file" />
        <param name="region" type="text" optional="true" argument="-n" label="Merge files in a region" help="Merge files in the specified region indicated by a string" />
        <param name="headerbam" type="data" format="sam,bam" argument="-h" multiple="false" optional="true" label="File to take @headers from" help="Use the lines of FILE as `@' headers to be copied to out.bam, replacing any header lines that would otherwise be copied from in1.bam. (FILE is actually in SAM format, though any alignment records it may contain are ignored.)" />
        <param name="idrg" type="boolean" argument="-c" truevalue="-c" falsevalue="" checked="false" label="Make @RG headers unique" help="When several input files contain @RG headers with the same ID, emit only one of them (namely, the header line from the first file we find that ID in) to the merged output file. Combining these similar headers is usually the right thing to do when the files being merged originated from the same file. Without -c, all @RG headers appear in the output file, with random suffices added to their IDs where necessary to differentiate them." />
        <param name="idpg" type="boolean" argument="-p" truevalue="-p" falsevalue="" checked="false" label="Make @PG headers unique" help="Similarly, for each @PG ID in the set of files to merge, use the @PG line of the first file we find that ID in rather than adding a suffix to differentiate similar IDs." />
        <param name="seed" type="integer" argument="-s" value="1" label="random seed" />
        <!-- compression options are not accessible in galaxy
        <param name="compression" type="select" label="Advanced compression options" help="Select advanced compression options">
            <option value="default" selected="true">default</option>
            <option value="levelone">Use zlib compression level 1</option>
            <option value="uncompressed">Uncompressed output</option>
        </param>-->
    </inputs>
    <outputs>
        <data name="output" format="bam" />
    </outputs>
    <tests>
        <!--tests and data extracted from
             https://github.com/samtools/samtools/blob/9ce8c64493f7ea3fa69bc5c1ac980b1a8e3dcf1f/test/test.pl
             https://github.com/samtools/samtools/tree/develop/test/merge -->
        <!-- Merge 1 - Standard 3 file SAM merge all presented on the command line (only checks for similar size, because generated header info differs) -->
        <test>
            <param name="bamfiles" value="test_input_1_a.sam,test_input_1_b.sam,test_input_1_c.sam" />
            <output name="output" file="1.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!-- Merge 2 - Standard 3 file BAM merge all files presented on the command line -->
        <test>
            <param name="bamfiles" value="test_input_1_a.bam,test_input_1_b.bam,test_input_1_c.bam" />
            <output name="output" file="2.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!-- Merge 3 - 1 file BAM merge with file presented on the command line -->
        <test>
            <param name="bamfiles" value="test_input_1_b.bam" />
            <output name="output" file="3.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!--Merge 4 - merge all presented on the command line, combine PG and RG rather than dedup -->
        <test>
            <param name="bamfiles" value="test_input_1_a.bam,test_input_1_b.bam" />
            <param name="idrg" value="-c" />
            <param name="idpg" value="-p" />
            <output name="output" file="4.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!-- Merge 5 - ID and SN with regex in them (probably not necessary for the galaxy tool because just different input) -->
        <test>
            <param name="bamfiles" value="test_input_1_a_regex.sam,test_input_1_b_regex.sam" />
            <output name="output" file="5.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!-- Merge 6 - Merging with bedfile -->
        <test>
            <param name="bamfiles" value="test_input_1_a.bam,test_input_1_b.bam,test_input_1_c.bam" />
            <param name="bed" value="yes" />
            <param name="bed_file" value="test_input_1_a.bed" />
            <output name="output" file="6.merge.expected.bam" ftype="bam" lines_diff="16" />
        </test>
        <!--Merge - 3 file SAM merge all presented on the command line override IDs to file names (not implemented in tool) -->
        <!-- Sort inputs by PG, then merge (not implemented, since -t not supported in the tool) -->
        <!-- Sort inputs by PG, then merge (name sorted) (not implemented, since -t not supported in the tool) -->
    </tests>
    <help>
**What it does**
Merge multiple sorted alignment files, producing a single sorted output file that contains all the input records and maintains the existing sort order.

If a file to take @headers from is specified the @SQ headers of input files will be merged into the specified header, otherwise they will be merged into a composite header created from the input headers. If in the process of merging @SQ lines for coordinate sorted input files, a conflict arises as to the order (for example input1.bam has @SQ for a,b,c and input2.bam has b,a,c) then the resulting output file will need to be re-sorted back into coordinate order.

Unless the @PG/@RG headers are made unique when merging @RG and @PG records into the output header then any IDs found to be duplicates of existing IDs in the output header will have a suffix appended to them to differentiate them from similar header records from other files and the read records will be updated to reflect this.
    </help>
    <expand macro="citations"/>
</tool>