view samtool_filter2.xml @ 6:dc6ff68ea5e8 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/samtool_filter2 commit a97efd3ee05c6e27ff8294f66ea975445966d9c4
author devteam
date Thu, 05 Oct 2017 10:31:42 -0400
parents b7aa423007bf
children 56c31114ad4a
line wrap: on
line source

<tool id="samtool_filter2" name="Filter SAM or BAM, output SAM or BAM" version="1.1.2">
  <description>files on FLAG MAPQ RG LN or by region</description>
  <requirements>
    <requirement type="package" version="1.2">samtools</requirement>
  </requirements>
  <stdio>
    <exit_code range="1:" />
  </stdio>
  <command>
<![CDATA[
##set up input files, regions requires input.bam and input.bai
#if $input1.is_of_type('bam')
  #set $input = 'input.bam'
  ln -s '$input1' $input &&
  ln -s '$input1.metadata.bam_index' input.bai &&
#elif $input1.is_of_type('sam')
  #set $input = 'input.sam'
  ln -s '$input1' $input &&
#end if
samtools view $possibly_select_inverse '$output1' $header

  #if $input1.is_of_type('sam')
   -S
  #end if

  #if str($outputtype) == 'bam'
      -b
  #end if

  #if str($mapq)
   -q $mapq
  #end if
  #if $flag.filter == 'yes'
   #if str($flag.reqBits) != 'None'
     #set $reqs = str($flag.reqBits).split(',')
     #set $reqFlag = 0
     #for $xn in $reqs:
       #set $reqFlag += int($xn, 16)
     #end for
     -f $hex($reqFlag)
   #end if
   #if str($flag.skipBits) != 'None'
     #set $skips = str($flag.skipBits).split(',')
     #set $skipFlag = 0
     #for $xn in $skips:
       #set $skipFlag += int(xn,16)
     #end for
     -F $hex($skipFlag)
   #end if
  #end if
  #if str($read_group).strip()
    -r '$read_group'
  #end if
  #if str($library).strip()
    -l '$library'
  #end if
  #if $bed_file
    -L '$bed_file'
  #end if
  $input
  #if str($regions).strip() and $input1.is_of_type('bam')
    #for region in str($regions).split():
      '$region'
    #end for
  #end if
  ## need to redirect stderr message so galaxy does not think this failed
  2>&1
]]>
  </command>
  <inputs>
    <param name="input1" type="data" format="sam,bam" label="SAM or BAM file to filter" />
    <param name="header" type="select" label="Header in output">
      <option value="-h">Include Header</option>
      <option value="">Exclude Header</option>
      <option value="-H">Only the Header</option>
    </param>
    <param name="mapq" type="integer" value="" optional="true" label="Minimum MAPQ quality score" help="(-q)">
      <validator type="in_range" message="The MAPQ quality score can't be negative" min="0"/>
    </param>
    <conditional name="flag">
      <param name="filter" type="select" label="Filter on bitwise flag">
        <option value="no">no</option>
        <option value="yes">yes</option>
      </param>
      <when value="no"/>
      <when value="yes">
        <param name="reqBits" type="select" multiple="true" display="checkboxes" label="Only output alignments with all of these flag bits set" help="(-f)">
          <option value="0x0001">Read is paired</option>
          <option value="0x0002">Read is mapped in a proper pair</option>
          <option value="0x0004">The read is unmapped</option>
          <option value="0x0008">The mate is unmapped</option>
          <option value="0x0010">Read strand</option>
          <option value="0x0020">Mate strand</option>
          <option value="0x0040">Read is the first in a pair</option>
          <option value="0x0080">Read is the second in a pair</option>
          <option value="0x0100">The alignment or this read is not primary</option>
          <option value="0x0200">The read fails platform/vendor quality checks</option>
          <option value="0x0400">The read is a PCR or optical duplicate</option>
          <option value="0x0800">Supplementary alignment</option>
        </param>
        <param name="skipBits" type="select" multiple="true" display="checkboxes" label="Skip alignments with any of these flag bits set" help="(-F)">
          <option value="0x0001">Read is paired</option>
          <option value="0x0002">Read is mapped in a proper pair</option>
          <option value="0x0004">The read is unmapped</option>
          <option value="0x0008">The mate is unmapped</option>
          <option value="0x0010">Read strand</option>
          <option value="0x0020">Mate strand</option>
          <option value="0x0040">Read is the first in a pair</option>
          <option value="0x0080">Read is the second in a pair</option>
          <option value="0x0100">The alignment or this read is not primary</option>
          <option value="0x0200">The read fails platform/vendor quality checks</option>
          <option value="0x0400">The read is a PCR or optical duplicate</option>
          <option value="0x0800">Supplementary alignment</option>
        </param>
      </when>
    </conditional>
    <param name="library" type="text" value="" label="Select alignments from Library"
           help="(-l) Requires headers in the input SAM or BAM, otherwise no alignments will be output"/>
    <param name="read_group" type="text" value="" label="Select alignments from Read Group"
           help="(-r) Requires headers in the input SAM or BAM, otherwise no alignments will be output"/>
    <param name="bed_file" type="data" format="bed" optional="true" label="Output alignments overlapping the regions in the BED FILE" help="(-L)"/>
    <param name="possibly_select_inverse" checked="false" label="Use inverse selection" type="boolean" truevalue="-U" falsevalue="-o" help="Select the opposite of the listed chromosomes" />
    <param name="regions" type="text" value="" label="Select regions (only used when the input is in BAM format)"
           help="region should be presented in one of the following formats: `chr1', `chr2:1,000' and `chr3:1000-2,000'"/>
    <param name="outputtype" type="select" label="Select the output format">
        <option value="bam">BAM (-b)</option>
        <option value="sam">SAM</option>
    </param>
  </inputs>
  <outputs>
    <data name="output1" format="sam" label="${tool.name} on ${on_string}: ${outputtype}">
      <change_format>
        <when input="outputtype" value="bam" format="bam" />
      </change_format>
    </data>
  </outputs>
  <tests>
    <test>
      <param name="input1" value="bam_to_sam_in2.sam" ftype="sam" />
      <param name="header" value=""/>
      <param name="filter" value="yes"/>
      <param name="reqBits" value="0x0080"/>
      <param name="outputtype" value="sam"/>
      <output name="output1">
       <assert_contents>
         <has_text text="141" />
         <not_has_text text="77" />
       </assert_contents>
      </output>
    </test>
    <test>
      <param name="input1" value="bam_to_sam_in2.sam" ftype="sam" />
      <param name="header" value=""/>
      <param name="filter" value="no"/>
      <param name="read_group" value="rg1"/>
      <param name="outputtype" value="sam"/>
      <output name="output1">
       <assert_contents>
         <has_text text="rg1" />
         <not_has_text text="rg2" />
       </assert_contents>
      </output>
    </test>
    <test>
      <param name="input1" value="bam_to_sam_in1.sam" ftype="sam" />
      <param name="header" value=""/>
      <param name="filter" value="yes"/>
      <param name="skipBits" value="0x0008"/>
      <param name="mapq" value="250"/>
      <param name="outputtype" value="sam"/>
      <output name="output1">
       <assert_contents>
         <has_text text="both_reads_align_clip_marked" />
         <not_has_text text="both_reads_present_only_first_aligns" />
       </assert_contents>
      </output>
    </test>
  </tests>
  <help>
**What it does**

This tool uses the samtools view command in SAMtools_ toolkit to filter a SAM or BAM file on the MAPQ (mapping quality), FLAG bits, Read Group, Library, or region.

**Input**

Input is either a SAM or BAM file.

**Output**

The output file will be SAM or BAM (depending on the chosen option), filtered by the selected options.

**Options**

Filtering by read group or library requires headers in the input SAM or BAM file.

If regions are specified, only alignments overlapping the specified regions will be output.  An alignment may be given multiple times if it is overlapping several regions.
A region can be presented, for example, in the following format::

  chr2	(the whole chr2)
  chr2:1000000	 (region starting from 1,000,000bp)
  chr2:1,000,000-2,000,000	(region between 1,000,000 and 2,000,000bp including the end points).

Note:  The coordinate is 1-based.

Multiple regions may be specified, separated by a space character::

  chr2:1000000-2000000 chr2:1,000,000-2,000,000 chrX



.. _SAMtools: http://www.htslib.org/

  </help>
</tool>