changeset 10:9a4c773fb90d draft

Uploaded
author jbrayet
date Wed, 25 Nov 2015 03:23:37 -0500
parents 96f453b29673
children 707978902d54
files samtools_slice_bam.xml
diffstat 1 files changed, 123 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/samtools_slice_bam.xml	Wed Nov 25 03:23:37 2015 -0500
@@ -0,0 +1,123 @@
+<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**
+
+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**.
+
+This tool is based on ``samtools view`` command. 
+
+@no-chrom-options@
+
+]]>
+  </help>
+    <expand macro="citations"></expand>
+</tool>