diff samtools_slice_bam.xml @ 2:2b474ebbfc7d draft

Uploaded
author devteam
date Tue, 21 Apr 2015 17:37:49 -0400
parents 74a8d2d60258
children a4a10c7924d1
line wrap: on
line diff
--- a/samtools_slice_bam.xml	Thu Mar 27 15:28:06 2014 -0400
+++ b/samtools_slice_bam.xml	Tue Apr 21 17:37:49 2015 -0400
@@ -1,40 +1,123 @@
-<tool id="samtools_slice_bam" name="Slice BAM" version="0.0.2">
-  <description>by provided regions</description>
-  <requirements>
-      <requirement type="package" version="0.1.19">samtools</requirement>
-  </requirements>
-  <command interpreter="python">samtools_slice_bam.py
-    "${input_bam}"
-    "${input_bam.metadata.bam_index}"
-    "${input_interval}"
-    "${output_bam}"
-  </command>
-  <inputs>
-    <param name="input_bam" type="data" format="bam" label="BAM file" />
-    <param name="input_interval" type="data" format="bed" label="BED file" />
-  </inputs>
-  <outputs>
-    <data format="bam" name="output_bam"/>
-  </outputs>
-  <tests>
-      <test>
-          <param name="input_bam" value="gatk/fake_phiX_reads_1.bam" ftype="bam" />
-          <param name="input_interval" value="gatk/fake_phiX_variant_locations.bed" ftype="bed" />
-          <output name="output_bam" file="gatk/fake_phiX_reads_1.bam" ftype="bam" />
-      </test>
-  </tests>
-  <help>
+<tool id="samtools_slice_bam" name="Slice" version="2.0">
+  <description>BAM by genomic regions</description>
+  <macros>
+    <import>macros.xml</import>
+  </macros>
+  <!-- <code file="samtools_slice_options.py"/> -->
+  <expand macro="requirements"></expand>
+  <expand macro="stdio"></expand>
+  <expand macro="version_command"></expand>
+    <command>
+<![CDATA[
+    ln -s "${input_bam}" temp_input.bam &&
+    ln -s "${input_bam.metadata.bam_index}" temp_input.bam.bai &&
+
+    #if str($slice_method.slice_method_selector) == "bed":
+    
+        samtools view -@ \${GALAXY_SLOTS:-1} -b -L "${input_interval}" -o unsorted_output.bam temp_input.bam && 
+
+    #elif str($slice_method.slice_method_selector) == "chr":
+
+        samtools view -@ \${GALAXY_SLOTS:-1} -b -o unsorted_output.bam temp_input.bam 
+        ${ ' '.join( map( lambda x:'"%s"' % ( x ), str( $slice_method.refs ).split(",") ) ) } &&
+
+    #elif str($slice_method.slice_method_selector) == "man":
+
+        samtools view -@ \${GALAXY_SLOTS:-1} -b -o unsorted_output.bam temp_input.bam 
+
+        #for $region in $slice_method.regions:
+            "${region.chrom}:${region.start}-${region.end}"
+        #end for
+
+        &&
+
+    #end if
+
+    samtools sort -O bam -T sorted -@ \${GALAXY_SLOTS:-1} -o "${output_bam}" unsorted_output.bam
+]]>
+    </command>
+    <inputs>
+        <param name="input_bam" format="bam" label="Select BAM dataset to slice" type="data" />
+        <conditional name="slice_method">
+            <param name="slice_method_selector" type="select" label="How do you want to slice your dataset?">
+                <option value="bed">using a list of intervals from a BED dataset</option>
+                <option value="chr">by chromosomes/contigs present in the BAM dataset</option>
+                <option value="man">by chromosomes/contigs and coordinates</option>
+            </param>
+            <when value="bed">
+                <param format="bed" label="BED file" name="input_interval" type="data" help="BED datasets can be obtained using &quot;Get Data -> UCSC Main&quot; datasource."/>
+            </when>
+            <when value="chr">
+                <param name="refs" type="select" optional="False" multiple="True" label="Select references (chromosomes and contigs) you would like to restrict bam to" help="Click and type in the box above to see options. You can select multiple entries. If &quot;No options available&quot; is displayed, you need to re-detect metadata on the input dataset. See help section below.">
+
+                    <!-- The options tagset below extracts reference names from bam file metadata -->
+                    <!-- This will not work with bed files with old style metadata. However this  -->
+                    <!-- Can be easily fixed by re-deceting metadata on a bam dataset by clicking -->
+                    <!-- The pencil icon and settind datatype to "bam"                            -->
+                    <!-- This change has been commited in the following pull request:             -->
+                    <!-- https://github.com/galaxyproject/galaxy/pull/107                         -->
+
+                    <options>
+                        <filter type="data_meta" ref="input_bam" key="reference_names" />
+                    </options>
+                </param>
+            </when>
+            <when value="man">
+                <repeat name="regions" title="Regions" min="1">
+                    <param name="chrom" type="select" optional="False" label="Select references (chromosomes and contigs) you would like to restrict bam to" help="Select chromosome/contig from the list. If &quot;No options available&quot; is displayed, you need to re-detect metadata on the input dataset. See help section below.">
+
+                        <!-- See comments above -->
+
+                        <options>
+                            <filter type="data_meta" ref="input_bam" key="reference_names" />
+                        </options>
+                    </param>
+                    <param name="start" type="integer" min="1" value="0" label="Enter START coordinate (1-based)"/>
+                    <param name="end" type="integer" min="1" value="100" label="Enter END coordinate"/>
+                </repeat>
+
+
+            </when>
+        </conditional>
+
+    </inputs>
+    <outputs>
+        <data format="bam" name="output_bam" />
+    </outputs>
+    <tests>
+        <test>
+            <param ftype="bam" name="input_bam" value="bam-slice-input.bam" />
+            <param name="slice_method_selector" value="bed"/>
+            <param ftype="bed" name="input_interval" value="bam-slice.bed" />
+            <output file="bam-slice-test1.bam" ftype="bam" name="output_bam" />
+        </test>
+        <test>
+            <param ftype="bam" name="input_bam" value="bam-slice-input.bam" />
+            <param name="slice_method_selector" value="chr"/>
+            <param name="refs" value="chrM" />
+            <output file="bam-slice-test2.bam" ftype="bam" name="output_bam" />
+        </test>
+        <test>
+            <param ftype="bam" name="input_bam" value="bam-slice-input.bam" />
+            <param name="slice_method_selector" value="man"/>
+            <param name="chrom" value="chrM" />
+            <param name="start" value="1" />
+            <param name="end" value="1000" />
+            <output file="bam-slice-test3.bam" ftype="bam" name="output_bam" />
+        </test>
+    </tests>
+    <help>
+<![CDATA[
+
 **What it does**
 
- Accepts an input BAM file and an input BED file and creates an output BAM file containing only those alignments that overlap the provided BED intervals.
+Allows to restrict (slice) input BAM dataset to a list of intervals defined in a BED file, individual chromosomes, or manually set list of coordinates. BED datasets can be obtained from **Get Data -> UCSC Main**.
 
-------
-
-**Citation**
+This tool is based on ``samtools view`` command. 
 
-For the underlying tool, please cite `Li H, Handsaker B, Wysoker A, Fennell T, Ruan J, Homer N, Marth G, Abecasis G, Durbin R; 1000 Genome Project Data Processing Subgroup. The Sequence Alignment/Map format and SAMtools. Bioinformatics. 2009 Aug 15;25(16):2078-9. &lt;http://www.ncbi.nlm.nih.gov/pubmed/19505943&gt;`_
+@no-chrom-options@
 
-If you use this tool in Galaxy, please cite Blankenberg D, et al. *In preparation.*
-
+]]>
   </help>
+    <expand macro="citations"></expand>
 </tool>