changeset 0:d4412c04d7b1 draft

Uploaded v0.0.1 (as tested previously on the Test Tool Shed)
author peterjc
date Wed, 20 Nov 2013 12:27:33 -0500
parents
children 8945bad80f4a
files test-data/ex1.bam test-data/ex1.idxstats.tabular tools/samtools_idxstats/README.rst tools/samtools_idxstats/samtools_idxstats.py tools/samtools_idxstats/samtools_idxstats.xml tools/samtools_idxstats/tool_dependencies.xml
diffstat 6 files changed, 246 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file test-data/ex1.bam has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/ex1.idxstats.tabular	Wed Nov 20 12:27:33 2013 -0500
@@ -0,0 +1,3 @@
+chr1	1575	1446	18
+chr2	1584	1789	17
+*	0	0	0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/samtools_idxstats/README.rst	Wed Nov 20 12:27:33 2013 -0500
@@ -0,0 +1,100 @@
+Galaxy wrapper for samtools idxstats
+====================================
+
+This wrapper is copyright 2013 by Peter Cock, The James Hutton Institute
+(formerly SCRI, Scottish Crop Research Institute), UK. All rights reserved.
+See the licence text below.
+
+This is a wrapper for part of the command line samtools suite, v0.1.19
+
+This wrapper is available from the Galaxy Tool Shed at:
+http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats
+
+
+Automated Installation
+======================
+
+This should be straightforward, Galaxy should automatically download and install
+samtools 0.1.19 if required.
+
+
+Manual Installation
+===================
+
+This expects samtools to be on the $PATH, and was tested using v0.1.19.
+
+To install the wrapper copy or move the following files under the Galaxy tools
+folder, e.g. in a ``tools/samtools_idxstats`` folder:
+
+* samtools_idxstats.xml (the Galaxy tool definition)
+* samtools_idxstats.py (the Python wrapper script)
+* README.rst (this file)
+
+You will also need to modify the ``tools_conf.xml`` file to tell Galaxy to offer
+the tool. Just add the line, perhaps under the NGS tools section::
+
+  <tool file="samtools_idxstats/samtools_idxstats.xml" />
+
+If you wish to run the unit tests, also add this to tools_conf.xml.sample
+and move/copy the test-data files under Galaxy's test-data folder. Then::
+
+    $ ./run_functional_tests.sh -id samtools_idxstats
+
+That's it.
+
+
+History
+=======
+
+======= ======================================================================
+Version Changes
+------- ----------------------------------------------------------------------
+v0.0.1  - Initial public release
+======= ======================================================================
+
+
+Developers
+==========
+
+Development is one this GitHub repository:
+https://github.com/peterjc/pico_galaxy/tree/master/tools/samtools_idxstats
+
+For making the "Galaxy Tool Shed" http://toolshed.g2.bx.psu.edu/ tarball use
+the following command from the Galaxy root folder::
+
+    $ tar -czf samtools_idxstats.tar.gz tools/samtools_idxstats/README.rst tools/samtools_idxstats/samtools_idxstats.xml tools/samtools_idxstats/samtools_idxstats.py tools/samtools_idxstats/tool_dependencies.xml test-data/ex1.bam test-data/ex1.idxstats.tabular
+
+Check this worked::
+
+    $ tar -tzf samtools_idxstats.tar.gz
+    tools/samtools_idxstats/README.rst
+    tools/samtools_idxstats/samtools_idxstats.xml
+    tools/samtools_idxstats/samtools_idxstats.py
+    tools/samtools_idxstats/tool_dependencies.xml
+    test-data/ex1.bam
+    test-data/ex1.idxstats.tabular
+
+
+Licence (MIT)
+=============
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+NOTE: This is the licence for the Galaxy Wrapper only.
+samtools is available and licenced separately.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/samtools_idxstats/samtools_idxstats.py	Wed Nov 20 12:27:33 2013 -0500
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+"""Wrapper for "samtools idxstats" for use in Galaxy.
+
+This script takes exactly three command line arguments:
+ * Input BAM filename
+ * Input BAI filename (via Galaxy metadata)
+ * Output tabular filename
+
+This messes about with the filenames to make samtools happy, then
+runs "samtools idxstats" and captures the output to the desired
+tabular file.
+"""
+import sys
+import os
+import subprocess
+import tempfile
+
+if "-v" in sys.argv or "--version" in sys.argv:
+    #Galaxy seems to invert the order of the two lines
+    print "(Galaxy wrapper v0.0.1)"
+    cmd = "samtools 2>&1 | grep -i ^Version"
+    sys.exit(os.system(cmd))
+
+def stop_err(msg, error_level=1):
+   """Print error message to stdout and quit with given error level."""
+   sys.stderr.write("%s\n" % msg)
+   sys.exit(error_level)
+
+if len(sys.argv) != 4:
+   stop_err("Require three arguments: BAM, BAI, tabular filenames")
+
+bam_filename, bai_filename, tabular_filename = sys.argv[1:]
+
+if not os.path.isfile(bam_filename):
+    stop_err("Input BAM file not found: %s" % bam_filename)
+if not os.path.isfile(bai_filename):
+    if bai_filename == "None":
+        stop_err("Error: Galaxy did not index your BAM file")
+    stop_err("Input BAI file not found: %s" % bai_filename)
+
+#Assign sensible names with real extensions, and setup symlinks:
+tmp_dir = tempfile.mkdtemp()
+bam_file = os.path.join(tmp_dir, "temp.bam")
+bai_file = os.path.join(tmp_dir, "temp.bam.bai")
+os.symlink(os.path.abspath(bam_filename), bam_file)
+os.symlink(os.path.abspath(bai_filename), bai_file)
+assert os.path.isfile(bam_file), bam_file
+assert os.path.isfile(bai_file), bai_file
+assert os.path.isfile(bam_file + ".bai"), bam_file
+
+#Run samtools idxstats:
+cmd = "samtools idxstats %s > %s" % (bam_file, tabular_filename)
+return_code = os.system(cmd)
+
+#Remove the temp symlinks:
+os.remove(bam_file)
+os.remove(bai_file)
+os.rmdir(tmp_dir)
+
+if return_code:
+    stop_err("Return code %i from command:\n%s" % (return_code, cmd))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/samtools_idxstats/samtools_idxstats.xml	Wed Nov 20 12:27:33 2013 -0500
@@ -0,0 +1,76 @@
+<tool id="samtools_idxstats" name="BAM mapping statistics" version="0.0.1">
+    <description>samtools idxstats</description>
+    <requirements>
+        <requirement type="binary">samtools</requirement>
+        <requirement type="package" version="0.1.19">samtools</requirement>
+    </requirements>
+    <version_command interpreter="python">samtools_idxstats.py --version</version_command>
+    <command interpreter="python">samtools_idxstats.py "$input_bam" "${input_bam.metadata.bam_index}" "$out_tabular"</command>
+    <inputs>
+        <param name="input_bam" type="data" format="bam" label="Input BAM file" />
+    </inputs>
+    <outputs>
+        <data name="out_tabular" format="tabular" label="$input_bam.name (idxstats)" />
+    </outputs>
+    <stdio>
+        <!-- Assume anything other than zero is an error -->
+        <exit_code range="1:" />
+        <exit_code range=":-1" />
+    </stdio>
+    <tests>
+        <test>
+            <param name="input_bam" value="ex1.bam" ftype="bam" />
+            <output name="out_tabular" file="ex1.idxstats.tabular" ftype="tabular" />
+        </test>
+    </tests>
+    <help>
+**What it does**
+
+This tool runs the ``samtools idxstats`` command in the SAMtools toolkit.
+
+Input is a sorted and indexed BAM file, the output is tabular with
+four columns (one row per reference sequence plus a final line for
+unmapped reads):
+
+====== =================================================================================
+Column Description
+------ ---------------------------------------------------------------------------------
+     1 Reference sequence identifier
+     2 Reference sequence length
+     3 Number of mapped reads
+     4 Number of placed but unmapped reads (typically unmapped partners of mapped reads)
+====== =================================================================================
+
+Example output from a *de novo* assembly:
+
+========== ====== ====== =====
+contig_1   170035  98397     0
+contig_2   403835 199564     0
+contig_3   553102 288189     0
+...           ...    ...   ...
+contig_603    653     50     0
+contig_604    214      6     0
+\*              0      0 50320
+========== ====== ====== =====
+
+In this example there were 604 contigs, each with one line in the output table,
+plus the final row (labelled with an asterisk) representing 50320 unmapped reads.
+In this BAM file, the final column was otherwise zero.
+
+
+**Citation**
+
+If you use this Galaxy tool in work leading to a scientific publication please
+cite:
+
+Heng Li et al (2009). The Sequence Alignment/Map format and SAMtools.
+Bioinformatics 25(16), 2078-9.
+http://dx.doi.org/10.1093/bioinformatics/btp352
+
+Peter J.A. Cock (2013), Galaxy wrapper for the samtools idxstats command
+http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats
+
+This wrapper is available to install into other Galaxy Instances via the Galaxy
+Tool Shed at http://toolshed.g2.bx.psu.edu/view/peterjc/samtools_idxstats
+    </help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/samtools_idxstats/tool_dependencies.xml	Wed Nov 20 12:27:33 2013 -0500
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<tool_dependency>
+    <package name="samtools" version="0.1.19">
+        <repository changeset_revision="00e17a794a2e" name="package_samtools_0_1_19" owner="iuc" toolshed="http://toolshed.g2.bx.psu.edu" />
+    </package>
+</tool_dependency>