changeset 1:b50d7228b678 draft

Uploaded
author mvdbeek
date Sun, 29 Mar 2015 10:25:36 -0400
parents 64064dccdb11
children 316124e85b8d
files sRbowtie.py sRbowtie.xml test-data/297_reference.fa test-data/input.fa test-data/input.fastq test-data/output.bam test-data/output2.bam test-data/sRbowtie.fa test-data/sRbowtie.out tool_dependencies.xml
diffstat 10 files changed, 419 insertions(+), 246 deletions(-) [+]
line wrap: on
line diff
--- a/sRbowtie.py	Mon Nov 03 10:24:38 2014 -0500
+++ b/sRbowtie.py	Sun Mar 29 10:25:36 2015 -0400
@@ -5,119 +5,185 @@
 # current rev: for bowtie __norc, move from --supress 2,6,7,8 to --supress 6,7,8. Future Parser must be updated to take into account this standardisation
 # Christophe Antoniewski <drosofff@gmail.com>
 
-import sys, os, subprocess, tempfile, shutil, argparse
+import sys
+import os
+import subprocess
+import tempfile
+import shutil
+import argparse
+
 
 def Parser():
-  the_parser = argparse.ArgumentParser(description="bowtie wrapper for small fasta reads")
-  the_parser.add_argument('--input', action="store", type=str, help="input fasta file")
-  the_parser.add_argument('--method', action="store", type=str, help="RNA, unique, multiple, k_option, n_option, a_option")
-  the_parser.add_argument('--v-mismatches', dest="v_mismatches", action="store", type=str, help="number of mismatches allowed for the alignments")
-  the_parser.add_argument('--output-format', dest="output_format", action="store", type=str, help="tabular, sam, bam")
-  the_parser.add_argument('--output',  action="store", type=str, help="output file path")
-  the_parser.add_argument('--index-from', dest="index_from", action="store", type=str, help="indexed or history")
-  the_parser.add_argument('--index-source', dest="index_source", action="store", type=str, help="file path to the index source")
-  the_parser.add_argument('--aligned', action="store", type=str, help="aligned read file path, maybe None")
-  the_parser.add_argument('--unaligned', action="store", type=str, help="unaligned read file path, maybe None")
-  the_parser.add_argument('--num-threads', dest="num_threads", action="store", type=str, help="number of bowtie threads")
-  args = the_parser.parse_args()
-  return args
+    the_parser = argparse.ArgumentParser(
+        description="bowtie wrapper for small fasta reads")
+    the_parser.add_argument(
+        '--input', action="store", type=str, help="input file")
+    the_parser.add_argument(
+        '--input-format', dest="input_format", action="store", type=str, help="fasta or fastq")
+    the_parser.add_argument('--method', action="store", type=str,
+                            help="RNA, unique, multiple, k_option, n_option, a_option")
+    the_parser.add_argument('--v-mismatches', dest="v_mismatches", action="store",
+                            type=str, help="number of mismatches allowed for the alignments")
+    the_parser.add_argument(
+        '--output-format', dest="output_format", action="store", type=str, help="tabular, sam, bam")
+    the_parser.add_argument(
+        '--output', action="store", type=str, help="output file path")
+    the_parser.add_argument(
+        '--index-from', dest="index_from", action="store", type=str, help="indexed or history")
+    the_parser.add_argument('--index-source', dest="index_source",
+                            action="store", type=str, help="file path to the index source")
+    the_parser.add_argument(
+        '--aligned', action="store", type=str, help="aligned read file path, maybe None")
+    the_parser.add_argument('--unaligned', action="store",
+                            type=str, help="unaligned read file path, maybe None")
+    the_parser.add_argument('--num-threads', dest="num_threads",
+                            action="store", type=str, help="number of bowtie threads")
+    args = the_parser.parse_args()
+    return args
 
-def stop_err( msg ):
-    sys.stderr.write( '%s\n' % msg )
+
+def stop_err(msg):
+    sys.stderr.write('%s\n' % msg)
     sys.exit()
 
-def bowtieCommandLiner (alignment_method="RNA", v_mis="1", out_type="tabular", aligned="None", unaligned="None", input="path", index="path", output="path", pslots="4"):
-    if alignment_method=="RNA":
-        x = "-v %s -M 1 --best --strata -p %s --norc --suppress 6,7,8" % (v_mis, pslots)
-    elif alignment_method=="unique":
-        x =  "-v %s -m 1 -p %s --suppress 6,7,8" % (v_mis, pslots)
-    elif  alignment_method=="multiple":
-        x = "-v %s -M 1 --best --strata -p %s --suppress 6,7,8" % (v_mis, pslots)
-    elif alignment_method=="k_option":
+
+def bowtieCommandLiner(alignment_method="RNA", v_mis="1", out_type="tabular",
+                       aligned="None", unaligned="None", input_format="fasta", input="path",
+                       index="path", output="path", pslots="4"):
+    if input_format == "fasta":
+        input_format = "-f"
+    elif input_format == "fastq":
+        input_format = "-q"
+    else:
+        raise Exception('input format must be one of fasta or fastq')
+    if alignment_method == "RNA":
+        x = "-v %s -M 1 --best --strata -p %s --norc --suppress 6,7,8" % (
+            v_mis, pslots)
+    elif alignment_method == "unique":
+        x = "-v %s -m 1 -p %s --suppress 6,7,8" % (v_mis, pslots)
+    elif alignment_method == "multiple":
+        x = "-v %s -M 1 --best --strata -p %s --suppress 6,7,8" % (
+            v_mis, pslots)
+    elif alignment_method == "k_option":
         x = "-v %s -k 1 --best -p %s --suppress 6,7,8" % (v_mis, pslots)
-    elif alignment_method=="n_option":
+    elif alignment_method == "n_option":
         x = "-n %s -M 1 --best -p %s --suppress 6,7,8" % (v_mis, pslots)
-    elif alignment_method=="a_option":
+    elif alignment_method == "a_option":
         x = "-v %s -a --best -p %s --suppress 6,7,8" % (v_mis, pslots)
-    if aligned == "None" and unaligned == "None": fasta_command = ""
-    elif aligned != "None" and unaligned == "None": fasta_command= " --al %s" % aligned
-    elif aligned == "None" and unaligned != "None": fasta_command = " --un %s" % unaligned
-    else: fasta_command = " --al %s --un %s" % (aligned, unaligned)
+    if aligned == "None" and unaligned == "None":
+        fasta_command = ""
+    elif aligned != "None" and unaligned == "None":
+        fasta_command = " --al %s" % aligned
+    elif aligned == "None" and unaligned != "None":
+        fasta_command = " --un %s" % unaligned
+    else:
+        fasta_command = " --al %s --un %s" % (aligned, unaligned)
     x = x + fasta_command
     if out_type == "tabular":
-        return "bowtie %s %s -f %s > %s" % (x, index, input, output)
-    elif out_type=="sam":
-        return "bowtie %s -S %s -f %s > %s" % (x, index, input, output)
-    elif out_type=="bam":
-        return "bowtie %s -S %s -f %s |samtools view -bS - > %s" % (x, index, input, output)
+        return "bowtie %s %s %s %s > %s" % (x, index, input_format, input, output)
+    elif out_type == "sam":
+        return "bowtie %s -S %s %s %s > %s" % (x, index, input_format, input, output)
+    elif out_type == "bam":
+        return "bowtie %s -S %s %s %s |samtools view -bS - > %s" % (
+            x, index, input_format, input, output)
+
 
 def bowtie_squash(fasta):
-  tmp_index_dir = tempfile.mkdtemp() # make temp directory for bowtie indexes
-  ref_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir )
-  ref_file_name = ref_file.name
-  ref_file.close() # by default, delete the temporary file, but ref_file.name is now stored in ref_file_name
-  os.symlink( fasta, ref_file_name ) # symlink between the fasta source file and the deleted ref_file name
-  cmd1 = 'bowtie-build -f %s %s' % (ref_file_name, ref_file_name ) # bowtie command line, which will work after changing dir (cwd=tmp_index_dir)
-  try:
-    FNULL = open(os.devnull, 'w')
-    tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name # a path string for a temp file in tmp_index_dir. Just a string
-    tmp_stderr = open( tmp, 'wb' ) # creates and open a file handler pointing to the temp file
-    proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=FNULL, stdout=FNULL ) # both stderr and stdout of bowtie-build are redirected in  dev/null
-    returncode = proc.wait()
-    tmp_stderr.close()
-    FNULL.close()
-    sys.stdout.write(cmd1 + "\n")
-  except Exception, e:
-    # clean up temp dir
-    if os.path.exists( tmp_index_dir ):
-      shutil.rmtree( tmp_index_dir )
-      stop_err( 'Error indexing reference sequence\n' + str( e ) )
-  # no Cleaning if no Exception, tmp_index_dir has to be cleaned after bowtie_alignment()
-  index_full_path = os.path.join(tmp_index_dir, ref_file_name) # bowtie fashion path without extention
-  return tmp_index_dir, index_full_path  
-  
+    # make temp directory for bowtie indexes
+    tmp_index_dir = tempfile.mkdtemp()
+    ref_file = tempfile.NamedTemporaryFile(dir=tmp_index_dir)
+    ref_file_name = ref_file.name
+    # by default, delete the temporary file, but ref_file.name is now stored
+    # in ref_file_name
+    ref_file.close()
+    # symlink between the fasta source file and the deleted ref_file name
+    os.symlink(fasta, ref_file_name)
+    # bowtie command line, which will work after changing dir
+    # (cwd=tmp_index_dir)
+    cmd1 = 'bowtie-build -f %s %s' % (ref_file_name, ref_file_name)
+    try:
+        FNULL = open(os.devnull, 'w')
+        # a path string for a temp file in tmp_index_dir. Just a string
+        tmp = tempfile.NamedTemporaryFile(dir=tmp_index_dir).name
+        # creates and open a file handler pointing to the temp file
+        tmp_stderr = open(tmp, 'wb')
+        # both stderr and stdout of bowtie-build are redirected in  dev/null
+        proc = subprocess.Popen(
+            args=cmd1, shell=True, cwd=tmp_index_dir, stderr=FNULL, stdout=FNULL)
+        returncode = proc.wait()
+        tmp_stderr.close()
+        FNULL.close()
+        sys.stdout.write(cmd1 + "\n")
+    except Exception as e:
+        # clean up temp dir
+        if os.path.exists(tmp_index_dir):
+            shutil.rmtree(tmp_index_dir)
+            stop_err('Error indexing reference sequence\n' + str(e))
+    # no Cleaning if no Exception, tmp_index_dir has to be cleaned after
+    # bowtie_alignment()
+    # bowtie fashion path without extention
+    index_full_path = os.path.join(tmp_index_dir, ref_file_name)
+    return tmp_index_dir, index_full_path
+
+
 def bowtie_alignment(command_line, flyPreIndexed=''):
-  # make temp directory just for stderr
-  tmp_index_dir = tempfile.mkdtemp()
-  tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
-  tmp_stderr = open( tmp, 'wb' )
-  # conditional statement for sorted bam generation viewable in Trackster
-  if "samtools" in command_line:
-    target_file = command_line.split()[-1] # recover the final output file name
-    path_to_unsortedBam = os.path.join(tmp_index_dir, "unsorted.bam")
-    path_to_sortedBam = os.path.join(tmp_index_dir, "unsorted.bam.sorted")
-    first_command_line = " ".join(command_line.split()[:-3]) + " -o " + path_to_unsortedBam + " - "
-    # example: bowtie -v 0 -M 1 --best --strata -p 12 --suppress 6,7,8 -S /home/galaxy/galaxy-dist/bowtie/Dmel/dmel-all-chromosome-r5.49 -f /home/galaxy/galaxy-dist/database/files/003/dataset_3460.dat |samtools view -bS -o /tmp/tmp_PgMT0/unsorted.bam -
-    second_command_line = "samtools sort  %s %s" % (path_to_unsortedBam, path_to_sortedBam) # generates an "unsorted.bam.sorted.bam file", NOT an "unsorted.bam.sorted" file
-    p = subprocess.Popen(args=first_command_line, cwd=tmp_index_dir, shell=True, stderr=tmp_stderr.fileno()) # fileno() method return the file descriptor number of tmp_stderr
-    returncode = p.wait()
-    sys.stdout.write("%s\n" % first_command_line + str(returncode))
-    p = subprocess.Popen(args=second_command_line, cwd=tmp_index_dir, shell=True, stderr=tmp_stderr.fileno())
-    returncode = p.wait()
-    sys.stdout.write("\n%s\n" % second_command_line + str(returncode))
-    if os.path.isfile(path_to_sortedBam + ".bam"):
-      shutil.copy2(path_to_sortedBam + ".bam", target_file)
-  else:
-    p = subprocess.Popen(args=command_line, shell=True, stderr=tmp_stderr.fileno())
-    returncode = p.wait()
-    sys.stdout.write(command_line + "\n")
-  tmp_stderr.close()
-  ## cleaning if the index was created in the fly
-  if os.path.exists( flyPreIndexed ):
-    shutil.rmtree( flyPreIndexed )
-  # cleaning tmp files and directories
-  if os.path.exists( tmp_index_dir ):
-    shutil.rmtree( tmp_index_dir )
-  return
+    # make temp directory just for stderr
+    tmp_index_dir = tempfile.mkdtemp()
+    tmp = tempfile.NamedTemporaryFile(dir=tmp_index_dir).name
+    tmp_stderr = open(tmp, 'wb')
+    # conditional statement for sorted bam generation viewable in Trackster
+    if "samtools" in command_line:
+        # recover the final output file name
+        target_file = command_line.split()[-1]
+        path_to_unsortedBam = os.path.join(tmp_index_dir, "unsorted.bam")
+        path_to_sortedBam = os.path.join(tmp_index_dir, "unsorted.bam.sorted")
+        first_command_line = " ".join(
+            command_line.split()[:-3]) + " -o " + path_to_unsortedBam + " - "
+        # example: bowtie -v 0 -M 1 --best --strata -p 12 --suppress 6,7,8 -S
+        # /home/galaxy/galaxy-dist/bowtie/Dmel/dmel-all-chromosome-r5.49 -f
+        # /home/galaxy/galaxy-dist/database/files/003/dataset_3460.dat
+        # |samtools view -bS -o /tmp/tmp_PgMT0/unsorted.bam -
+        # generates an "unsorted.bam.sorted.bam file", NOT an
+        # "unsorted.bam.sorted" file
+        second_command_line = "samtools sort  %s %s" % (
+            path_to_unsortedBam, path_to_sortedBam)
+        # fileno() method return the file descriptor number of tmp_stderr
+        p = subprocess.Popen(
+            args=first_command_line, cwd=tmp_index_dir, shell=True, stderr=tmp_stderr.fileno())
+        returncode = p.wait()
+        sys.stdout.write("%s\n" % first_command_line + str(returncode))
+        p = subprocess.Popen(
+            args=second_command_line, cwd=tmp_index_dir, shell=True, stderr=tmp_stderr.fileno())
+        returncode = p.wait()
+        sys.stdout.write("\n%s\n" % second_command_line + str(returncode))
+        if os.path.isfile(path_to_sortedBam + ".bam"):
+            shutil.copy2(path_to_sortedBam + ".bam", target_file)
+    else:
+        p = subprocess.Popen(
+            args=command_line, shell=True, stderr=tmp_stderr.fileno())
+        returncode = p.wait()
+        sys.stdout.write(command_line + "\n")
+    tmp_stderr.close()
+    # cleaning if the index was created in the fly
+    if os.path.exists(flyPreIndexed):
+        shutil.rmtree(flyPreIndexed)
+    # cleaning tmp files and directories
+    if os.path.exists(tmp_index_dir):
+        shutil.rmtree(tmp_index_dir)
+    return
+
 
 def __main__():
-  args = Parser()
-  F = open (args.output, "w")
-  if args.index_from == "history":
-    tmp_dir, index_path = bowtie_squash(args.index_source)
-  else:
-    tmp_dir, index_path = "dummy/dymmy", args.index_source
-  command_line = bowtieCommandLiner(args.method, args.v_mismatches, args.output_format, args.aligned, args.unaligned, args.input, index_path, args.output, args.num_threads)
-  bowtie_alignment(command_line, flyPreIndexed=tmp_dir)
-  F.close()
-if __name__=="__main__": __main__()
+    args = Parser()
+    F = open(args.output, "w")
+    if args.index_from == "history":
+        tmp_dir, index_path = bowtie_squash(args.index_source)
+    else:
+        tmp_dir, index_path = "dummy/dymmy", args.index_source
+    command_line = bowtieCommandLiner(args.method, args.v_mismatches, args.output_format,
+                                      args.aligned, args.unaligned, args.input_format, args.input, 
+                                      index_path, args.output, args.num_threads)
+    bowtie_alignment(command_line, flyPreIndexed=tmp_dir)
+    F.close()
+if __name__ == "__main__":
+    __main__()
--- a/sRbowtie.xml	Mon Nov 03 10:24:38 2014 -0500
+++ b/sRbowtie.xml	Sun Mar 29 10:25:36 2015 -0400
@@ -1,11 +1,11 @@
 <tool id="bowtieForSmallRNA" name="sRbowtie" version="1.1.0">
-  <description>for FASTA small reads</description>
-  <requirements>
-	<requirement type="package" version="0.12.7">bowtie</requirement>
+    <description>for FASTA small reads</description>
+    <requirements>
+        <requirement type="package" version="0.12.7">bowtie</requirement>
         <requirement type="package" version="0.1.18">samtools</requirement>
-  </requirements>
-  <parallelism method="basic"></parallelism>
-  <command interpreter="python"> sRbowtie.py --input $input
+    </requirements>
+    <command interpreter="python"> sRbowtie.py --input $input
+                                             --input-format $input.extension
                                              --method $method
                                              --v-mismatches $v_mismatches
                                              --output-format $output_format
@@ -22,101 +22,102 @@
                                              --unaligned $unaligned
                                              --num-threads \${GALAXY_SLOTS:-4} ## number of processors to be handled by bowtie
   </command>
-  <inputs>
-      <param name="input" type="data" format="fasta" label="Input fasta file: reads clipped from their adapter" help="Only with clipped, raw fasta files"/>
-<!-- which method will be used --> 
-      <param name="method" type="select" label="What kind of matching do you want to do?" help="bowtie parameters adjusted to the type of matching. RNA option match to only one strand">
-        <option value="RNA">Match on sense strand RNA reference index, multiple mappers randomly matched at a single position</option>
-        <option value="unique">Match unique mappers on DNA reference index</option>
-        <option value="multiple" selected="true">Match on DNA, multiple mappers randomly matched at a single position</option>
-        <option value="k_option">Match on DNA as fast as possible, without taking care of mapping issues (for raw annotation of reads)</option>
-        <option value="n_option">Match on DNA - RNAseq mode (-n bowtie option)</option>
-        <option value="a_option">Match and report all valid alignments</option>
-      </param>
-<!-- END of which method will be used -->
-    <param name="v_mismatches" type="select" label="Number of mismatches allowed" help="specify the -v bowtie option">
-        <option value="0">0</option>
-        <option value="1" selected="true">1</option>
-        <option value="2">2</option>
-        <option value="3">3</option>
-    </param>
-<!-- bowtie index selection -->
-    <conditional name="refGenomeSource">
-      <param name="genomeSource" type="select" label="Will you select a reference genome from your history or use a built-in index?" help="Built-ins were indexed using default options">
-        <option value="indexed">Use a built-in index</option>
-        <option value="history">Use one from the history</option>
-      </param>
-      <when value="indexed">
-        <param name="index" type="select" label="Select a DNA reference index" help="if your genome of interest is not listed - contact GED team">
-          <options from_data_table="bowtie_indexes">
-      <!--      <filter type="sort_by" column="2" />
-            <validator type="no_options" message="No indexes are available" /> -->
+    <inputs>
+        <param format="fasta, fastq" help="Only with clipped, raw fasta files" label="Input fasta file: reads clipped from their adapter" name="input" type="data" />
+        <param help="bowtie parameters adjusted to the type of matching. RNA option match to only one strand" label="What kind of matching do you want to do?" name="method" type="select">
+            <option value="RNA">Match on sense strand RNA reference index, multiple mappers randomly matched at a single position</option>
+            <option value="unique">Match unique mappers on DNA reference index</option>
+            <option selected="true" value="multiple">Match on DNA, multiple mappers randomly matched at a single position</option>
+            <option value="k_option">Match on DNA as fast as possible, without taking care of mapping issues (for raw annotation of reads)</option>
+            <option value="n_option">Match on DNA - RNAseq mode (-n bowtie option)</option>
+            <option value="a_option">Match and report all valid alignments</option>
+        </param>
+        <param help="specify the -v bowtie option" label="Number of mismatches allowed" name="v_mismatches" type="select">
+            <option value="0">0</option>
+            <option selected="true" value="1">1</option>
+            <option value="2">2</option>
+            <option value="3">3</option>
+        </param>
+        <conditional name="refGenomeSource">
+            <param help="Built-ins were indexed using default options" label="Will you select a reference genome from your history or use a built-in index?" name="genomeSource" type="select">
+                <option value="indexed">Use a built-in index</option>
+                <option value="history">Use one from the history</option>
+            </param>
+            <when value="indexed">
+                <param help="if your genome of interest is not listed - contact GED team" label="Select a DNA reference index" name="index" type="select">
+                    <options from_data_table="bowtie_indexes">
+      
           </options>
+                </param>
+            </when>
+            <when value="history">
+                <param format="fasta" label="Select a fasta file, to serve as index reference" name="ownFile" type="data" />
+            </when>
+        </conditional>
+        <param help="Note that the BAM will be viewable in trackster only if you choose a full genome referenced for Trackster usage. see the doc below" label="Select output format" name="output_format" type="select">
+            <option select="true" value="tabular">tabular</option>
+            <option value="sam">sam</option>
+            <option value="bam">bam</option>
+        </param>
+        <param help="to get aligned and unaligned reads in fasta format" label="additional fasta output" name="additional_fasta" type="select">
+            <option select="true" value="No">No</option>
+            <option value="al">aligned</option>
+            <option value="unal">unaligned</option>
+            <option value="al_and_unal">both aligned and unaligned</option>
         </param>
-      </when>
-      <when value="history">
-        <param name="ownFile" type="data" format="fasta" label="Select a fasta file, to serve as index reference" />
-      </when>
-    </conditional>
-<!-- END bowtie index selection -->
-       <param name="output_format" type="select" label="Select output format" help="Note that the BAM will be viewable in trackster only if you choose a full genome referenced for Trackster usage. see the doc below">
-          <option value="tabular" select="true">tabular</option>
-          <option value="sam">sam</option>
-          <option value="bam">bam</option>
-       </param>
-       <param name="additional_fasta" type="select" label="additional fasta output" help="to get aligned and unaligned reads in fasta format">
-          <option value="No" select="true">No</option>
-          <option value="al">aligned</option>
-          <option value="unal">unaligned</option>
-          <option value="al_and_unal">both aligned and unaligned</option>
-       </param>
-   </inputs>
-   <outputs>
-   <data format="tabular" name="output" label="Bowtie Output">
-        <change_format>
-            <when input="output_format" value="sam" format="sam" />
-            <when input="output_format" value="bam" format="bam" />
-        </change_format>
-<!-- Set metadata based on reference genome -->
-      <actions>
-        <conditional name="refGenomeSource.genomeSource">
-          <when value="indexed">
-            <action type="metadata" name="dbkey">
-              <option type="from_data_table" name="bowtie_indexes" column="1" offset="0">
-                <filter type="param_value" column="0" value="#" compare="startswith" keep="False"/>
-                <filter type="param_value" ref="refGenomeSource.index" column="0"/>
-              </option>
-            </action>
-          </when>
-          <when value="history">
-            <action type="metadata" name="dbkey">
-              <option type="from_param" name="refGenomeSource.ownFile" param_attribute="dbkey" />
-            </action>
-          </when>
-        </conditional>
-      </actions>
-   </data>
-   <data format="fasta" name="aligned" label="Matched reads">
-	<filter>additional_fasta == "al" or additional_fasta == "al_and_unal"</filter>
-   </data>
-   <data format="fasta" name="unaligned" label ="Unmatched reads">
-        <filter>additional_fasta == "unal" or additional_fasta == "al_and_unal"</filter>
-   </data>
-   </outputs>
-
-    <test>
-      <param name="genomeSource" value="indexed" />
-      <param name="index" value="/home/galaxy/galaxy-dist/bowtie/Dmel/dmel-all-chromosome-r5.49" />
-      <param name="method" value="multiple" />
-      <param name="input" ftype="fasta" value="sRbowtie.fa" />
-      <param name="v_mismatches" value="1" />
-      <param name="output_format" value="tabular" />
-      <output name="output" ftype="tabular" value="sRbowtie.out" />
-      <output name="aligned" value="None" />
-      <output name="unaligned" value="None" />
-    </test>
-
-  <help>
+    </inputs>
+    <outputs>
+        <data format="tabular" label="Bowtie Output" name="output">
+            <change_format>
+                <when format="sam" input="output_format" value="sam" />
+                <when format="bam" input="output_format" value="bam" />
+            </change_format>
+            <actions>
+                <conditional name="refGenomeSource.genomeSource">
+                    <when value="indexed">
+                        <action name="dbkey" type="metadata">
+                            <option column="1" name="bowtie_indexes" offset="0" type="from_data_table">
+                                <filter column="0" compare="startswith" keep="False" type="param_value" value="#" />
+                                <filter column="0" ref="refGenomeSource.index" type="param_value" />
+                            </option>
+                        </action>
+                    </when>
+                    <when value="history">
+                        <action name="dbkey" type="metadata">
+                            <option name="refGenomeSource.ownFile" param_attribute="dbkey" type="from_param" />
+                        </action>
+                    </when>
+                </conditional>
+            </actions>
+        </data>
+        <data format="fasta" label="Matched reads" name="aligned">
+            <filter>additional_fasta == "al" or additional_fasta == "al_and_unal"</filter>
+        </data>
+        <data format="fasta" label="Unmatched reads" name="unaligned">
+            <filter>additional_fasta == "unal" or additional_fasta == "al_and_unal"</filter>
+        </data>
+    </outputs>
+    <tests>
+        <test>
+            <param name="genomeSource" value="history" />
+            <param ftype="fasta" name="ownFile" value="297_reference.fa" />
+            <param name="method" value="unique" />
+            <param ftype="fasta" name="input" value="input.fa" />
+            <param name="v_mismatches" value="1" />
+            <param name="output_format" value="bam" />
+            <output file="output.bam" ftype="bam" lines_diff="4" name="output" />
+        </test>
+        <test>
+            <param name="genomeSource" value="history" />
+            <param ftype="fasta" name="ownFile" value="297_reference.fa" />
+            <param name="method" value="unique" />
+            <param ftype="fastq" name="input" value="input.fastq" />
+            <param name="v_mismatches" value="1" />
+            <param name="output_format" value="bam" />
+            <output file="output2.bam" ftype="bam" lines_diff="4" name="output" />
+        </test>
+    </tests>
+    <help>
 
 **What it does**
 
@@ -209,4 +210,7 @@
 **Matched and unmatched fasta reads can be retrieved, for further analyses**
 
   </help>
+    <citations>
+        <citation type="doi">10.1186/gb-2009-10-3-r25</citation>
+    </citations>
 </tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/297_reference.fa	Sun Mar 29 10:25:36 2015 -0400
@@ -0,0 +1,118 @@
+>FBgn0000005_297
+AGTGACGTATTTGGGTGGTCCAAACCAGCCACTTCCATTATTTCAAAGAAATCAGTAATG
+CACTCTAGTAATTTTCCATAACTGTATCCCAGCTGCGCAGACTCGTTTATCTTTTGCAGC
+GCAGCGTTCTTTGTAAACATCCTAAAGACCTGCCTAAGCAGATTTGACTGCCCTCTTTCA
+ACGCTACCTAATCTTAAGAACCCAAGAGCGAGGCTCTCCCGAAATACAAATATTGTTCAA
+ATACTGAGGCTTCTCCTCAATCCAATTTGCATTTGATTTTTAGTCTTAAGCTGAGATCCA
+AAGAATAAAGTCGTGAAACTATTTCTCCTAAAAACTATTTTTTATTTCTTGGCGTTGTCC
+TTAGTCAACTGACGGGACATTAGTTCGACTCATAAATAAAACAACAATTTTACTGGCGCA
+GTCGGTAGGATACAAAAGTATCCGAAAAAAAAGAACCTTCGAATGGAAAATAAGTTAAAT
+TTTATAGTCCTGTGCTCGAAACATCTCCCAAAATAAATTCGTGAAAACTCTTCAACTTCA
+ATTATAATTCCAATTCGGTTATCCAATAATAAGTGGAAGTGAAATACGAAACAAAAATAT
+TAAGTCCAAAGGCAACTAAGTTTTAAAACCAACATATAAAAATAAAAAATTAAAACAATA
+TAGAATTTTAATAATACAACACAAAAATTTACAAAACAAAAAAACAAACAAGTGAAACTA
+GAAAGCTTAAAAATAATAATAACATTGAATCCGAAACAAAACAAAAAAATAAAACACAAA
+AGTTAAAAATTTTACAATAAAAATGTCACAACCAATTATTGCGCTGAGCGACATAAACCT
+TGCCGAAGCCCGTCGGCAGCTTAAAGACATTATGCCATTCAAGGGTGATCCAGAAACCCT
+TCACACCTTTATCAGCAGAGTGGATTACGTAATTTCGCTCTACCAAACAAATGATGTCCG
+ACAACAGAGGATTCTACTGGGAGCCATCGAAAGGAACTTGGACGGACAAATTACACGATC
+TTTGGGACTTCCGAACGTCGAAGATTGGCCTACCCTTAAAGCAAGACTCATCGCGGAATT
+TAAAATTCAAACACCAAACTACAAACTTCTGGAGAACTTCAGGGAGACACCATACAGAGG
+AAGCCTAAGAGCATTCTGCGAAGAAGCGGAGAGACGACGTCAATTACTAATTTCGAAACT
+ACACCTGGAAGGTAACCAATCGGATTTTCTTATTTATATTCAGGGTATTAAAGAATCTAT
+TAAGATACTGATAAGGAAACTACCAATACAATTATTCACTATTTTAGCCCATCACGATAT
+TACAGACTTAAGATCCTTAATTACCATTGCACAAAATGAGGGAATTTATGAAGAACACAT
+TAATTTTGAATTTTATGAAAAACCAGAATATCGTAATAAAAATTCAAATTCTAACCAGAA
+TTCGAAAACACAAAAATTCAATACAAATGTTCAAACTCAAAATCGACCAAGTTACTCACA
+ATATTCCCAACCCTTCCAACCTAATTTTAATCAATACATTCAACCATTTAGACCTAGCTA
+TACACAGCAGATAACTAACAACCCACCCATGTGGCACGCACCTAATTATTTCAGACCCAA
+CCAATACATAAACCCACAACCCATTATTCAAAAAAATCATTTCCAACAATATCCCAACAA
+AGCCCAATTTCCCCAAACAACGCATTTTAGAGGAAATACATACCCTCGACTACAACAACC
+CTCTACATATAAAAATACTAACTTCCCGATTACTAAACGACTAAGACCATCGGACAGTGA
+ACAAACTAAAATGTCTATTGACGAAATTAGATTCCAAGACGCGCATGAATTCGAACAAGT
+CCAACCTAATTATTACGAGCAACAGTATTTTAACCAAAATCAATACAATCCGTATCAAAA
+TCATAGCTTCATTAATGAAGGGCAACAACAAGTTCAATTTGTACAAATTAATAACAAACA
+AAACCAAAATAATTCTGAACTAAACGAAAATTTTCGGTTAACAGTTCCGGAAAATACGAA
+TACATAAAAATAGTATACAAAGGGCGTTCATACAAATGCCTTCTAGACACAGGATCAACA
+ATTAATATGATCAATGAAAATATATTTTGTCTTCCCATTCAAAATAGTAGATGTGAAGTT
+TTAACATCAAATGGCCCTATTACCTTGAACGACTTGATTATGTTACCCAGAAATAGTATT
+TTCAAAAAAACCGAACCATTTTATGTGCACAGATTTTCTAATAATTACGATATGCTAATT
+GGCAGAAAATTGTTGAAAAATGCTCAATCAGTTATTAATTACAAAAATGATACAGTTACC
+CTTTTTGATCAAACATACAAATTAATTACTTCAGAATCCGAAAGAAACCAAAATTTGTAT
+ATCCAAAGGACACCAGAATCAATTGCAAGCTCAGATCAGGAATCAATAAAAAAATTAGAT
+TTTTCACAGTTTCGATTAGATCACCTAAATCAGGAGGAAACTTTTAAGTTAAAAGGCTTG
+TTAAATAAATTTAGAAATCTTGAATATAAGGAGGGAGAGAAATTAACATTTACAAATACA
+ATTAAACACGTACTAAATACAACACATAACTCCCCAATTTATTCGAAACAATACCCACTT
+GCGCAAACACACGAAATCGAAGTAGAAAACCAAGTACAGGAAATGCTGAATCAGGGATTA
+ATTAGGGAAAGTAATTCTCCATACAATAGTCCTACTTGGGTCGTACCAAAGAAACCGGAT
+GCTTCTGGTGCAAATAAGTACAGGGTAGTAATTGATTATAGAAAGCTAAATGAAATAACC
+ATACCTGACAGATATCCAATTCCAAATATGGACGAAATTCTTGGCAAACTGGGTAAATGC
+CAATATTTTACAACGATCGATCTGGCAAAGGGATTTCATCAAATAGAAATGGACGAAGAA
+TCAATTTCTAAAACTGCATTCTCCACAAAAAGCGGTCATTACGAATACCTTCGAATGCCA
+TTTGGCCTTAGGAATGCACCCGCTACTTTTCAAAGGTGCATGAATAATATCCTTCGACCG
+TTGCTTAACAAACACTGTTTGGTGTATCTGGATGATATTATAATTTTTTCAACATCCCTT
+ACAGAACATTTAAATTCAATACAATTAGTTTTTACAAAGCTTGCAGATGCAAATTTAAAA
+TTGCAACTAGACAAATGTGAGTTCTTAAAAAAGGAAGCTAACTTTCTTGGTCACATAGTT
+ACCCCTGATGGTATTAAACCAAATCCTATTAAAGTTAAAGCCATAGTTTCATACCCAATT
+CCGACAAAAGATAAAGAGATAAGAGCTTTCCTTGGATTAACAGGTTATTATCGCAAATTT
+ATTCCAAATTACGCAGACATAGCAAAACCCATGACCAGCTGCTTAAAAAAAAGGACAAAG
+ATAGATACACAAAAACTTGAGTACATAGAGGCATTCGAAAAACTTAAGGCTTTGATAATT
+CGTGACCCAATTTTACAATTACCTGATTTTGAAAAGAAATTTGTTTTAACCACAGATGCA
+AGTAACTTGGCCCTCGGGGCTGTCCTTTCTCAAAACGGTCATCCTATATCTTTTATTAGT
+AGAACACTTAACGATCACGAATTAAATTACAGTGCTATCGAAAAAGAATTACTTGCCATA
+GTTTGGGCCACAAAAACTTTTCGACATTATTTACTAGGACGACAATTTCTCATTGCCAGT
+GACCATCAACCTCTTAGATGGCTTCATAACTTAAAGGAACCAGGTGCTAAGTTAGAAAGA
+TGGAGAGTTAGATTAAGCGAATACCAATTTAAAATAGATTATATTAAAGGGAAAGAAAAT
+TCAGTTGCCGATGCATTATCAAGAATTAAAATTGAAGAAAATCATCATAGTGAAGCTACT
+CAACATAGTGCAGAAGAGGACAATAGCAACCTTATTCATTTAACAGAAAAACCAATAAAT
+TATTTCAAAAAACAAATAATCTTTATTAAATCCGATAAAAATAAAGTAGAGCATTCAAAA
+ATATTCGGTAACTCCATTACCACAATTCAATATGACGTAATGACACTTGAAAAGGCCAAA
+CAAATTTTACTCGATCACTTTATCCATAGAAACATTACCATTTATATTGAGAGCGATGTA
+GATTTTGAAATCGTTCAAAGAGCACACATAGAAATTGTTAATACCACCTACACAAAAGTA
+ATTCGCAGTCTTTTCCTATTAAAGAACGTTGGTTCATACGCCGAATTCAAAGAAATCATA
+CTTCAATCACATGAAAAACTTTTACACCCTGGTATACAGAAAATGACAAAATTATTTAAA
+GAAAATCACTTCTTTCCAAATAGCCAACTATTAATTCAGAATATAATAAACGAATGCAAC
+ATATGCAATTTGGCCAAAACAGAACATAGAAACACCAAAATGCCTTTAAAAATCACACCC
+AACCCGGAACATTGCCGAGAAAAATTTGTAGTAGATATTTATTCATCTGAGGGAAAACAT
+TACATCAGTTGCATTGATATTTATTCTAAATTCGCTACACTTGAGCAAATTAAAACTAAG
+GATTGGATAGAATGCAGAAACGCATTAATGCGCATTTTTAATCAACTAGGAAAACCCAAA
+TTATTAAAGGCAGACAGAGACGGAGCTTTCTCCAGTTTAGCTTTAAAGCGATGGCTTGAA
+GAAGAAGAAGTCGAATTACAGCTCAATACAGCAAAAAACGGAGTAGCAGACGTCGAAAGA
+TTACACAAAACAATAAATGAAAAAATTCGTATAATCAATTCATCTGATGATGAAGAAGTA
+AAATTAAGCAAGATAGAAACAATCCTCTACACATACAACCAAAAAATTAAACATGACACT
+ACTGGACAGAGACCTGCTCAAATTTTCTTATACGCTGGGCATCCCATATTAGACACTCAA
+AAAATTAAAGAGAAGAAAATAGAGAAAATAAATGAAGACAGACGGGAATTTAATATTGAC
+ACTAATTACAGAAAAGGTCCACTACAGAAAGGCAAATTAGAAAACCCATTTAAACCAACC
+AAAAATGTAGAACAGACAGACCCTGACCATTACAAAATCACTAATAGAAATAGAGTTACG
+CACTACTACAAAACACAATTCAAAAAACAAAAGAAAAATAATAAACTCTCAATTTCACAG
+GCACCTGGTACCCGATAACACTATTGTTTATACTGATCACAGCTGTTCATGGACAACAAA
+TTCAAATTAATAATATTGACACCAACCACGGATATCTCCTTTTTTCTGATAAGCCAGTAC
+AGATACCATCCTCCTTTGAACATCACTCCTTAAAAATCAATTTAACTGAAATAGACATCG
+TGGTTGACTATTTTGAGCAAAGACTACGAACCGATTACCATGCACCCCAGATCAATTTTT
+TATACAATAAAATAAAAAGAGAACTAGCCAGAATAACCCTGAAACATAGAAACAAACGGG
+GTTTTATTAACATTGTGGGTTCAGGTTTTAAATACCTATTTGGAACACTAGATGAAAATG
+ATCGAGTCGAAATACAGAAAAAACTTGAAATCAACGTCCATAACTCAGTAAAATTACATG
+AACTCAACGACGCCATACGATTGATAAATGACGGAATGCAAAAAATACAGAATTATGAAA
+ATAACCACACCATCATTGACAGTCTTTTGTTCGAACTAATGCAGTTTACGGAATACATAG
+AAGATTTGGAAATGGCTATGCAGCTTTCCAGACTTGGACTGTTTAACCCCAAATTACTAA
+ACTACGACAAACTTGAAAATGTGAACAGCCAAAACATTTTGAACATTAAAACATCCACTT
+GGATTAACTACAATGATAACCAAGTATTAATCATATCCCACATACCCATTTACCTTTCAC
+TAATAAGCACAATTAAAATAATTCCTTACCCAGACTCCAACGGCTATCAGCTAGATTACA
+CAGACACACAATCATATTTTGAAAAAGAAAATAAAGTTTATAATACCGAAAATAAAGAAG
+TAAAAAATGAATGTGTCACCAATATTATTAAACACTTAAATCCAATTTGTAATTTTAAGC
+CAGTACACACGAACGAAATAATAAAATACATAGAACCAAACACAATTGTAACTTGGAACT
+TAACCCAAACAATTCTTAACCAAAATTGCCAAAATTCAATTAATAAAATAAAAATAGAAG
+GAAACAAAATGATAAGAGTAACGCAATGCAAAATAGAAATCAATAATATAAATTTTAGTG
+AAACTCTGTTAGAACCAGAAATAGATTTGACACCACTATACACACCACTTAATATAACAA
+AAATAAAAATTGTAAAACACAACGACATTATTGAGATGATTTCAGAGAACAATATTACAC
+TTTACATACAAATGATCATTGTAATAATCGCACTAATTTTGTTGTACTCATATTTAAGAT
+ATGTATCATTTAAACCATTTATGATGTTGTATGCAAAACTTAAAATAAGAAAAAATCAAA
+ATCAAAACACACCACAACAAACAGAAATAGAAGAAATTCCATTTCCCACACTATATCCAT
+CAATCCCAGCCCAAGTATAGGCTTCTCTTTAAGGGAAGGGGAGTGACGTATTTGGGTGGT
+CCAAACCAGCCACTTCCATTATTTCAAAGAAATCAGTAATGCACTCTAGTAATTTTCCAT
+AACTGTATCCCAGCTGCGCAGACTCGTTTATCTTTTGCAGCGCAGCGTTCTTTGTAAACA
+TCCTAAAGACCTGCCTAAGCAGATTTGACTGCCCTCTTTCAACGCTACCTAATCTTAAGA
+ACCCAAGAGCGAGGCTCTCCCGAAATACAAATATTGTTCAAATACTGAGGCTTCTCCTCA
+ATCCAATTTGCATTTGATTTTTAGTCTTAAGCTGAGATCCAAAGAATAAAGTCGTGAAAC
+TATTTCTCCTAAAAACTATTTTTTATTTCTTGGCGTTGTCCTTAGTCAACTGACGGGACA
+TTAGTTCGACTCATAAATAAAACAACAATTTTACT
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input.fa	Sun Mar 29 10:25:36 2015 -0400
@@ -0,0 +1,10 @@
+>1
+CATTCTGCGAAGAAGC
+>2
+GGAGAGACGACGTCAATTACT
+>3
+AATTTCGAAACTACACCTGGAAGGTAACCA
+>4
+ATCGGATTTTCTTATTTATATTCAGGGTATTAAAGAATCTAT
+>5
+TAAGATACTGATAAGGAAACTACCAATA
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input.fastq	Sun Mar 29 10:25:36 2015 -0400
@@ -0,0 +1,20 @@
+@HTW-1
+CATTCTGCGAAGAAGC
++
+HHHHHHHHHHHHHHHH
+@HTW-2
+GGAGAGACGACGTCAATTACT
++
+HHHHHHHHHHHHHHHHHHHHH
+@HTW-3
+AATTTCGAAACTACACCTGGAAGGTAACCA
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
+@HTW-4
+ATCGGATTTTCTTATTTATATTCAGGGTATTAAAGAATCTAT
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
+@HTW-5
+TAAGATACTGATAAGGAAACTACCAATA
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHH
Binary file test-data/output.bam has changed
Binary file test-data/output2.bam has changed
--- a/test-data/sRbowtie.fa	Mon Nov 03 10:24:38 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
->1
-GTATTGTAAGTGGCAGAGTGGC
->2
-TGGAATGTAAAGAAGTATGGAG
->3
-GTGGGGAGTTTGGATGGGGCGGCA
->4
-AATGGCACTGGAAGAATTCACGG
->5
-GTACGGACAAGGGGAATC
->6
-TTGGGTTCTGGGGGGAGTATGG
->7
-GTGGGGAGTTTCGCTGGGGCGGCA
->8
-TAAGGGTCGGGTAGTGAGGGC
->9
-AGCTGGGACTGAGGACTG
->10
-AGCTGGGACTGAGGACTGC
->11
-AAGGGTCGGGTAGTGAGG
->12
-GTCGGGTAGTGAGGGCCTT
->13
-TGGTGGGGCTTGGAACAATTGGAGGGC
->14
-TGACGGAAGGGCACCACC
->15
-TGGAATGTAAAGAAGTATGGAG
->16
-TTGGGTTCTGGGGGGAGT
->17
-TCAGGTGGGGAGTTTGGCTGGGGCGGCACA
->18
-TTGGGTATAGGGGCGAAAGA
->19
-AGCGGGCGTGCTTGTGGAC
->20
-GTCGAATTTGGGTATAGGGGC
--- a/test-data/sRbowtie.out	Mon Nov 03 10:24:38 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-2	+	2L	20487495	TGGAATGTAAAGAAGTATGGAG
-4	-	2L	11953463	CCGTGAATTCTTCCAGTGCCATT
-15	+	2L	20487495	TGGAATGTAAAGAAGTATGGAG
-14	-	Uextra	7115665	GGTGGTGCCCTTCCGTCA
-18	+	Uextra	7726410	TTGGGTATAGGGGCGAAAGA
--- a/tool_dependencies.xml	Mon Nov 03 10:24:38 2014 -0500
+++ b/tool_dependencies.xml	Sun Mar 29 10:25:36 2015 -0400
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <tool_dependency>
   <package name="bowtie" version="0.12.7">
-      <repository changeset_revision="f54826948b0b" name="package_bowtie_0_12_7" owner="devteam" toolshed="https://testtoolshed.g2.bx.psu.edu" />
+      <repository changeset_revision="f0faa5eea2eb" name="package_bowtie_0_12_7" owner="devteam" toolshed="https://testtoolshed.g2.bx.psu.edu" />
     </package>
     <package name="samtools" version="0.1.18">
       <repository changeset_revision="c0f72bdba484" name="package_samtools_0_1_18" owner="devteam" toolshed="https://testtoolshed.g2.bx.psu.edu" />