<tool id="makeflow_bwa" name="Makeflow-BWA" version="1.0.0">
<description> A Distributed version of BWA using Makeflow</description>
<command interpreter="python">
    makeflow_bwa_wrapper.py

    --user_id=$__user_id__
    --pwfile=${GALAXY_DATA_INDEX_DIR}/mypwfile
	--ref=$reference
	--num_seq=$num_seq

    --fastq=$paired.input1
    #if $paired.sPaired == "paired":
     --rfastq=$paired.input2
    #end if

    --output_SAM=$SAM_File
    #if $Makeflow_Log:
	--output_log=$Makeflow_Log
    #end if
    #if $Work_Queue_Log:
	--wq_log=$Work_Queue_Log
    #end if
    #if $Debug_Log:
	--output_dblog=$Debug_Log
    #end if
    --algoalign=$check_alignalgo.alignalgo
    --index-a=$algorithm

    #if $check_alignalgo.alignalgo=="bwa_backtrack":
      --aln-k=$check_alignalgo.maxEditDistSeed
		#if $check_alignalgo.params.source_select != "pre_set":
			--aln-t=$check_alignalgo.params.numThreads
			--aln-m=$check_alignalgo.params.maxEditDistSeed
			--aln-n=$check_alignalgo.params.maxEditDist
			--aln-o=$check_alignalgo.params.maxGapOpens
			--aln-e=$check_alignalgo.params.maxGapExtens
			--aln-d=$check_alignalgo.params.disallowLongDel
			--aln-i=$check_alignalgo.params.disallowIndel
			--aln-l=$check_alignalgo.params.seed
			--aln-M=$check_alignalgo.params.mismatchPenalty
			--aln-O=$check_alignalgo.params.gapOpenPenalty
			--aln-E=$check_alignalgo.params.gapExtensPenalty
		--aln-R=$check_alignalgo.params.suboptAlign
		--aln-N=$check_alignalgo.params.noIterSearch
		--samse-n=$check_alignalgo.params.outputTopN
		--sampe-n=$check_alignalgo.params.outputTopN
		--sampe-a=$check_alignalgo.params.maxInsertSize
		--sampe-o=$check_alignalgo.params.maxOccurPairing
	#end if
    #end if

    #if $check_alignalgo.alignalgo=="bwa_sw":
	#if $check_alignalgo.checkparams_bwasw.useparam=="full":
			--bwasw-t=$check_alignalgo.checkparams_bwasw.threads
		--bwasw-a=$check_alignalgo.checkparams_bwasw.matchscore
		--bwasw-b=$check_alignalgo.checkparams_bwasw.mismatchpenalty
		--bwasw-q=$check_alignalgo.checkparams_bwasw.gapopen
		--bwasw-r=$check_alignalgo.checkparams_bwasw.gapextension
		--bwasw-w=$check_alignalgo.checkparams_bwasw.bandwidth
		--bwasw-m=$check_alignalgo.checkparams_bwasw.minthreshold
		--bwasw-c=$check_alignalgo.checkparams_bwasw.coeff
		--bwasw-z=$check_alignalgo.checkparams_bwasw.heuristics
		--bwasw-s=$check_alignalgo.checkparams_bwasw.interval
		--bwasw-N=$check_alignalgo.checkparams_bwasw.minseed
	#end if
    #end if

    #if $check_alignalgo.alignalgo=="bwa_mem":
	#if $check_alignalgo.checkparams_bwamem.param_bwamem=="full":
			--mem-t=$check_alignalgo.checkparams_bwamem.numthread
			--mem-k=$check_alignalgo.checkparams_bwamem.minseedlen
		--mem-w=$check_alignalgo.checkparams_bwamem.bwidth
		--mem-d=$check_alignalgo.checkparams_bwamem.offdiagonal
		--mem-r=$check_alignalgo.checkparams_bwamem.reseed
		--mem-c=$check_alignalgo.checkparams_bwamem.discardmem
		--mem-A=$check_alignalgo.checkparams_bwamem.matchingscore
		--mem-B=$check_alignalgo.checkparams_bwamem.mismatch_penalty
		--mem-O=$check_alignalgo.checkparams_bwamem.gopenalty
		--mem-E=$check_alignalgo.checkparams_bwamem.gepenalty
		--mem-L=$check_alignalgo.checkparams_bwamem.cpenalty
		--mem-U=$check_alignalgo.checkparams_bwamem.upreadpenalty
		--mem-T=$check_alignalgo.checkparams_bwamem.dontop
	#end if
    #end if


</command>
<inputs>
	<param name="reference" format="fasta" type="data" label="Select Reference Genome:" />
	<param name="num_seq" type="integer" value="100000" label="Select Number of Sequences per Partition" />

	<param name="algorithm" type="select" label="Select an Indexing Algorithm" help="IS algorithm works on databses 2GB or less, and is linear-time. BWT-SW algorithm works on database 10MB and larger, and trades speed for memory.">
		<option value="is">IS</option>
		<option value="bwtsw">BWT-SW</option>
	</param>

	<conditional name="paired">
		<param name="sPaired" type="select" label="Single-End or Paired-End Reads">
			<option value="single">Single-end</option>
			<option value="paired">Paired-end</option>
		</param>
		<when value="single">
			<param format="fastq" name="input1" type="data" label="FASTQ file" />
		</when>
		<when value="paired">
			<param format="fastq" name="input1" type="data" label="Forward FASTQ file" />
			<param format="fastq" name="input2" type="data" label="Reverse FASTQ file" />
		</when>
	</conditional>


	<conditional name="check_alignalgo">
		<param name="alignalgo" type="select" label="Select an Alignment Algorithm" help="BWA-Backtrack is designed for Illumina sequence reads up to 100bp. BWA-SW and BWA-MEM are for longer sequences ranged from 70bp to 1Mbp. BWA-MEM is generally recommended for high-quality queries as it is faster and more accurate.">
			<option value="bwa_backtrack">BWA-Backtrack</option>
			<option value="bwa_sw">BWA-SW</option>
			<option value="bwa_mem">BWA-MEM</option>
		</param>

		<when value="bwa_sw">
			<conditional name="checkparams_bwasw">
				<param name="useparam" type="select" label="Other options" help="Select other flags and their values">
					<option value="pre_set">Default setting</option>
					<option value="full">View list</option>
				</param>
				<when value="pre_set" />
				<when value="full">
					<param name="threads" type="integer" value="1" label="-t" help="Number of threads in multi-threading mode" />
					<param name="matchscore" type="integer" value="1" label="-a" help="Score of a match" />
					<param name="mismatchpenalty" type="integer" value="3" label="-b" help="Mismatch penalty" />
					<param name="gapopen" type="integer" value="5" label="-q" help="Gap open penalty" />
					<param name="gapextension" type="integer" value="2" label="-r" help="Gap extension penalty" />
					<param name="bandwidth" type="integer" value="33" label="-w" help="Band width in the banded alignment" />
					<param name="minthreshold" type="integer" value="37" label="-T" help="Minimum score threshold divided by a" />
					<param name="coeff" type="float" value="5.5" label="-c" help="Coefficient for threshold adjustment according to query length" />
					<param name="heuristics" type="integer" value="1" label="-z" help="Z-best heuristics" />
					<param name="interval" type="integer" value="3" label="-s" help="Maximum SA interval size for initiating a seed" />
					<param name="minseed" type="integer" value="1" label="-N" help="Minimum number of seeds supporting the resultant alignment to skip reverse alignment" />
				</when>
			</conditional>
		</when>

		<when value="bwa_backtrack">
				<param name="maxEditDistSeed" type="integer" value="2" label="-k" help="Maximum edit distance in the seed" />
			<conditional name="params">
				<param name="source_select" type="select" label="Other options" help="Select other flags and their values">
					<option value="pre_set">Default setting</option>
					<option value="full">View list</option>
				</param>
				<when value="pre_set" />
				<when value="full">
					<param name="numThreads" type="integer" value="1" label="-t" help="Number of threads, in multi-threading mode" />
					<param name="maxEditDist" type="float" value="0.04" label="-n" help="Maximum edit distance OR Fraction of missing alignmentsi (given 2% uniform base error rate)" />
					<param name="maxGapOpens" type="integer" value="1" label="-o" help="Maximum number of gap opens" />
					<param name="maxGapExtens" type="integer" value="-1" label="-e" help="Maximum number of gap extensions help=" />
					<param name="disallowLongDel" type="integer" value="16" label="-d" help="Disallow long deletion within [value] towards the 3'-end" />
					<param name="disallowIndel" type="integer" value="5" label="-i" help="Disallow insertion/deletion within [value] bp towards the end" />
					<param name="seed" type="integer" value="-1" label="-l" help="Number of first subsequences to take as seed" />
					<param name="mismatchPenalty" type="integer" value="3" label="-M" help="Mismatch penalty" />
            ptions.numthread

					<param name="gapOpenPenalty" type="integer" value="11" label="-O" help="Gap open penalty"/>
					<param name="gapExtensPenalty" type="integer" value="4" label="-E" help="Gap extension penalty" />
					<param name="colorSpaceRev" type="select" label="Reverse query but don't compement it" help="Reverse query for all alignment in color space">
						<option value="false">Don't reverse query</option>
						<option value="true">Reverse query</option>
					</param>
					<param name="suboptAlign" type="boolean" truevalue="true" falsevalue="false" checked="no" label="-R" help="Proceed with suboptimal alignments even if the top hit is a repeat" />
					<param name="noIterSearch" type="boolean" truevalue="true" falsevalue="false" checked="no" label="-N" help="Disable iterative search" />
					<param name="outputTopN" type="integer" value="-1" label="Output top [value] hits" help="For single-end reads only. Enter -1 to disable outputting multiple hits" />
					<param name="maxInsertSize" type="integer" value="500" label="Maximum insert size for a read pair to be considered as being mapped properly" help="For paired-end reads only. Only used when there are not enough good alignment to infer the distribution of insert sizes" />
					<param name="maxOccurPairing" type="integer" value="100000" label="Maximum occurrences of a read for pairing" help="For paired-end reads only. A read with more occurrences will be treated as a single-end read. Reducing this parameter helps faster pairing" />
				</when>
			</conditional>
		</when>

		<when value="bwa_mem">
			<conditional name="checkparams_bwamem">
				<param name="param_bwamem" type="select" label="Other options" help="Select other flags and their values">
					<option value="pre_set">Default setting</option>
					<option value="full">View list</option>
				</param>
				<when value="pre_set" />
				<when value="full">
					<param name="numthread" type="integer" value="1" label="-t" help="Number of threads, in multi-threading mode" />
					<param name="minseedlen" type="integer" value="19" label="-k" help="Minimum seed length" />
					<param name="bwidth" type="integer" value="100" label="-w" help="Band width" />
					<param name="offdiagonal" type="integer" value="100" label="-d" help="Off-diagonal X-dropoff (Z-dropoff)" />
					<param name="reseed" type="float" value="1.5" label="-r" help="Trigger re-seeding for a MEM longer than minSeedlen*FLOAT" />
					<param name="discardmem" type="integer" value="10000" label="-c" help="Discard a MEM if it has more than 'value' occurence in the genome" />
					<param name="matchingscore" type="integer" value="1" label="-A" help="Matching score" />
					<param name="mismatch_penalty" type="integer" value="4" label="-B" help="Mismatch penalty" />
					<param name="gopenalty" type="integer" value="6" label="-O" help="Gap open penalty" />
					<param name="gepenalty" type="integer" value="1" label="-E" help="Gap extension penalty" />
					<param name="cpenalty" type="integer" value="5" label="-L" help="Clipping penalty" />
					<param name="upreadpenalty" type="integer" value="9" label="-U" help="Penalty for an unpaired read pair" />
					<param name="dontop" type="integer" value="30" label="-T" help="Donot output alignment with score lower than this value" />
				</when>
			</conditional>
		</when>
	</conditional>
	<param name="log_outputs" type="select" label="Select Optional Outputs" display="checkboxes" multiple="true">
		<option value="mklog">Makeflow Log</option>
		<option value="wqlog">Work Queue Log</option>
		<option value="dblog">Debug Log</option>
	</param>
</inputs>


<outputs>
	<data format="sam" name="SAM_File" label="BWA-MF SAM File">
<!--#		<actions>
#			<action type="metadata" name="dbkey">
#				<option type="from_param" name="referencen" param_attribute="dbkey" />
#			</action>
#		</actions> -->
	</data>
    <data format="mklog" name="Makeflow_Log" label="BWA-MF Makeflow Log">
		<filter>"mklog" in log_outputs</filter>
    </data>
    <data format="text" name="Work_Queue_Log" label="BWA-MF Work Queue Log">
		<filter>"wqlog" in log_outputs</filter>
    </data>
    <data format="text" name="Debug_Log" label="BWA-MF Debug Log">
		<filter>"dblog" in log_outputs</filter>
    </data>
</outputs>
<help>

**What it does**

**BWA** is a high performance sequence aligner that succeeds MAQ. It is based on BWT-SW but uses a completely different algorithm, and it is aimed toward short read alignments. It is fast--it can map the human genome in only 15-25 minutes. Heng Li of the Sanger Institute wrote the majority of the code, with contributions by Chi-Kwong Wong at the University of Hong Kong, Nong Ge at Sun Yat-Sen University, and Yuta Mori.

------

**Input formats**

BWA accepts files in FASTQ format.

------

**Outputs**

The output is in SAM format, and has the following columns::

  1  QNAME  -  Query (pair) NAME
  2  FLAG   -  bitwise FLAG
  3  RNAME  -  Reference sequence NAME
  4  POS    -  1-based leftmost POSition/coordinate of clipped sequence
  5  MAPQ   -  MAPping Quality (Phred-scaled)
  6  CIGAR  -  extended CIGAR string
  7  MRNM   -  Mate Reference sequence NaMe ('=' if same as RNAME)
  8  MPOS   -  1-based Mate POSition
  9  ISIZE  -  Inferred insert SIZE
  10 SEQ    -  query SEQuence on the same strand as the reference
  11 QUAL   -  query QUALity (ASCII-33 gives the Phred base quality)
  12 OPT    -  variable OPTional fields in the format TAG:VTYPE:VALU

The flags are as follows::

  Flag    -  Description
  0x0001  -  the read is paired in sequencing
  0x0002  -  the read is mapped in a proper pair
  0x0004  -  the query sequence itself is unmapped
  0x0008  -  the mate is unmapped
  0x0010  -  strand of the query (1 for reverse)
  0x0020  -  strand of the mate
  0x0040  -  the read is the first read in a pair
  0x0080  -  the read is the second read in a pair
  0x0100  -  the alignment is not primary

It looks like this (scroll sideways to see the entire example)::

  QNAME FLAG RNAME POS MAPQ CIAGR MRNM MPOS ISIZE SEQ QUAL OPT
  HWI-EAS91_1_30788AAXX:1:1:1761:343 4 * 0 0 * * 0 0 AAAAAAANNAAAAAAAAAAAAAAAAAAAAAAAAAAACNNANNGAGTNGNNNNNNNGCTTCCCACAGNNCTGG hhhhhhh;;hhhhhhhhhhh^hOhhhhghhhfhhhgh;;h;;hhhh;h;;;;;;;hhhhhhghhhh;;Phhh
  HWI-EAS91_1_30788AAXX:1:1:1578:331 4 * 0 0 * * 0 0 GTATAGANNAATAAGAAAAAAAAAAATGAAGACTTTCNNANNTCTGNANNNNNNNTCTTTTTTCAGNNGTAG hhhhhhh;;hhhhhhhhhhhhhhhhhhhhhhhhhhhh;;h;;hhhh;h;;;;;;;hhhhhhhhhhh;;hhVh

-------

**BWA Settings**

All of the options have a default value. You can change any of them. All of the options in BWA have been implemented here.

------

**BWA parameter list**

This is an exhaustive list of BWA options:

For **aln**::

  -n NUM  Maximum edit distance if the value is INT, or the fraction of missing
          alignments given 2% uniform base error rate if FLOAT. In the latter
          case, the maximum edit distance is automatically chosen for different
          read lengths. [0.04]
  -o INT  Maximum number of gap opens [1]
  -e INT  Maximum number of gap extensions, -1 for k-difference mode
          (disallowing long gaps) [-1]
  -d INT  Disallow a long deletion within INT bp towards the 3'-end [16]
  -i INT  Disallow an indel within INT bp towards the ends [5]
  -l INT  Take the first INT subsequence as seed. If INT is larger than the
          query sequence, seeding will be disabled. For long reads, this option
          is typically ranged from 25 to 35 for '-k 2'. [inf]
  -k INT  Maximum edit distance in the seed [2]
  -t INT  Number of threads (multi-threading mode) [1]
  -M INT  Mismatch penalty. BWA will not search for suboptimal hits with a score
          lower than (bestScore-misMsc). [3]
  -O INT  Gap open penalty [11]
  -E INT  Gap extension penalty [4]
  -c      Reverse query but not complement it, which is required for alignment
          in the color space.
  -R      Proceed with suboptimal alignments even if the top hit is a repeat. By
          default, BWA only searches for suboptimal alignments if the top hit is
          unique. Using this option has no effect on accuracy for single-end
          reads. It is mainly designed for improving the alignment accuracy of
          paired-end reads. However, the pairing procedure will be slowed down,
          especially for very short reads (~32bp).
  -N      Disable iterative search. All hits with no more than maxDiff
          differences will be found. This mode is much slower than the default.

For **samse**::

  -n INT  Output up to INT top hits. Value -1 to disable outputting multiple
          hits. [-1]

For **sampe**::

  -a INT  Maximum insert size for a read pair to be considered as being mapped
          properly. Since 0.4.5, this option is only used when there are not
          enough good alignment to infer the distribution of insert sizes. [500]
  -o INT  Maximum occurrences of a read for pairing. A read with more
          occurrences will be treated as a single-end read. Reducing this
          parameter helps faster pairing. [100000]


</help>
</tool>
